public async Task DetectAndSetDocumentType()

in packages/ekyc-api/src/ekyc-api/Controllers/DocumentController.cs [119:155]


        public async Task<string> DetectAndSetDocumentType(string sessionId, string s3Key)
        {
            if (string.IsNullOrEmpty(sessionId))
                throw new ArgumentException("Session Id cannot be blank.");

            if (string.IsNullOrEmpty(s3Key))
                throw new ArgumentException("S3 key cannot be blank.");


            var sessionValid = await _sessionManager.SessionExistsAndIsValid(sessionId);

            if (!sessionValid) throw new ArgumentException($"Session ID {sessionId} does not exist or has expired.");

            s3Key = sessionId + "/" + s3Key;

            var documentTypeResponse = await _documentChecker.GetDocumentType(s3Key);

            if (documentTypeResponse == null || documentTypeResponse.Type == null)
                throw new Exception("No supported document types found for this image.");

            var config = new DynamoDBOperationConfig
            {
                OverrideTableName = Globals.SessionTableName
            };

            var item = await _dbContext.LoadAsync<SessionObject>(sessionId, config);

            if (item == null) throw new HttpStatusException(HttpStatusCode.InternalServerError, "Session not found.");

            item.documentType = documentTypeResponse.Type.ToString();

            item.documentBoundingBox = JsonSerializer.Serialize(documentTypeResponse.BoundingBox);

            await _dbContext.SaveAsync(item, config);

            return item.documentType;
        }