// This is an automatically generated code sample. 
// To make this code sample work in your Oracle Cloud tenancy, 
// please replace the values for any parameters whose current values do not fit
// your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and 
// boolean, number, and enum parameters with values not fitting your use case).

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Oci.AidocumentService;
using Oci.Common;
using Oci.Common.Auth;

namespace Oci.Sdk.DotNet.Example.Aidocument
{
    public class AnalyzeDocumentExample
    {
        public static async Task Main()
        {
            // Create a request and dependent object(s).
			var analyzeDocumentDetails = new Oci.AidocumentService.Models.AnalyzeDocumentDetails
			{
				Features = new List<Oci.AidocumentService.Models.DocumentFeature>
				{
					new Oci.AidocumentService.Models.DocumentClassificationFeature
					{
						MaxResults = 577,
						ModelId = "ocid1.test.oc1..<unique_ID>EXAMPLE-modelId-Value",
						TenancyId = "ocid1.test.oc1..<unique_ID>EXAMPLE-tenancyId-Value"
					}
				},
				Document = new Oci.AidocumentService.Models.InlineDocumentDetails
				{
					// Create a byte array. This can be created in several different ways depending on your use case.
					// For example, use <see href="https://docs.microsoft.com/en-us/dotnet/api/system.io.file.readallbytes?view=netcore-3.1">File.ReadAllBytes(String)</see>,
					// or use <see href="https://docs.microsoft.com/en-us/dotnet/api/system.text.encoder?view=netcore-3.1">Encoder class</see>.
					Data = System.Text.Encoding.UTF8.GetBytes("some data"),
					PageRange = new List<string>
					{
						"EXAMPLE--Value"
					}
				},
				CompartmentId = "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
				OutputLocation = new Oci.AidocumentService.Models.OutputLocation
				{
					NamespaceName = "EXAMPLE-namespaceName-Value",
					BucketName = "EXAMPLE-bucketName-Value",
					Prefix = "EXAMPLE-prefix-Value"
				},
				Language = "EXAMPLE-language-Value",
				DocumentType = Oci.AidocumentService.Models.DocumentType.BankStatement,
				OcrData = new Oci.AidocumentService.Models.AnalyzeDocumentResult
				{
					DocumentMetadata = new Oci.AidocumentService.Models.DocumentMetadata
					{
						PageCount = 755,
						MimeType = "EXAMPLE-mimeType-Value"
					},
					Pages = new List<Oci.AidocumentService.Models.Page>
					{
						new Oci.AidocumentService.Models.Page
						{
							PageNumber = 751,
							Dimensions = new Oci.AidocumentService.Models.Dimensions
							{
								Width = 9476.382,
								Height = 9058.35,
								Unit = Oci.AidocumentService.Models.Dimensions.UnitEnum.Inch
							},
							DetectedDocumentTypes = new List<Oci.AidocumentService.Models.DetectedDocumentType>
							{
								new Oci.AidocumentService.Models.DetectedDocumentType
								{
									DocumentType = "EXAMPLE-documentType-Value",
									DocumentId = "ocid1.test.oc1..<unique_ID>EXAMPLE-documentId-Value",
									Confidence = (float)0.27862382
								}
							},
							DetectedLanguages = new List<Oci.AidocumentService.Models.DetectedLanguage>
							{
								new Oci.AidocumentService.Models.DetectedLanguage
								{
									Language = "EXAMPLE-language-Value",
									Confidence = (float)0.70111716
								}
							},
							Words = new List<Oci.AidocumentService.Models.Word>
							{
								new Oci.AidocumentService.Models.Word
								{
									Text = "EXAMPLE-text-Value",
									Confidence = (float)0.1852023,
									BoundingPolygon = new Oci.AidocumentService.Models.BoundingPolygon
									{
										NormalizedVertices = new List<Oci.AidocumentService.Models.NormalizedVertex>
										{
											new Oci.AidocumentService.Models.NormalizedVertex
											{
												X = 0.06136483,
												Y = 0.8453009
											}
										}
									}
								}
							},
							Lines = new List<Oci.AidocumentService.Models.Line>
							{
								new Oci.AidocumentService.Models.Line
								{
									Text = "EXAMPLE-text-Value",
									Confidence = (float)0.8138433,
									BoundingPolygon = new Oci.AidocumentService.Models.BoundingPolygon
									{
										NormalizedVertices = new List<Oci.AidocumentService.Models.NormalizedVertex>
										{
											new Oci.AidocumentService.Models.NormalizedVertex
											{
												X = 0.81444204,
												Y = 0.04667318
											}
										}
									},
									WordIndexes = new List<Int32>
									{
										789
									}
								}
							},
							Tables = new List<Oci.AidocumentService.Models.Table>
							{
								new Oci.AidocumentService.Models.Table
								{
									RowCount = 686,
									ColumnCount = 101,
									HeaderRows = new List<Oci.AidocumentService.Models.TableRow>
									{
										new Oci.AidocumentService.Models.TableRow
										{
											Cells = new List<Oci.AidocumentService.Models.Cell>
											{
												new Oci.AidocumentService.Models.Cell
												{
													Text = "EXAMPLE-text-Value",
													RowIndex = 279,
													ColumnIndex = 438,
													Confidence = (float)0.7697154,
													BoundingPolygon = new Oci.AidocumentService.Models.BoundingPolygon
													{
														NormalizedVertices = new List<Oci.AidocumentService.Models.NormalizedVertex>
														{
															new Oci.AidocumentService.Models.NormalizedVertex
															{
																X = 0.24262589,
																Y = 0.4627477
															}
														}
													},
													WordIndexes = new List<Int32>
													{
														719
													}
												}
											}
										}
									},
									Confidence = (float)0.31600523,
									BoundingPolygon = new Oci.AidocumentService.Models.BoundingPolygon
									{
										NormalizedVertices = new List<Oci.AidocumentService.Models.NormalizedVertex>
										{
											new Oci.AidocumentService.Models.NormalizedVertex
											{
												X = 0.7596075,
												Y = 0.7179757
											}
										}
									}
								}
							},
							DocumentFields = new List<Oci.AidocumentService.Models.DocumentField>
							{
								new Oci.AidocumentService.Models.DocumentField
								{
									FieldType = Oci.AidocumentService.Models.DocumentField.FieldTypeEnum.LineItem,
									FieldLabel = new Oci.AidocumentService.Models.FieldLabel
									{
										Name = "EXAMPLE-name-Value",
										Confidence = (float)0.8690598
									},
									FieldName = new Oci.AidocumentService.Models.FieldName
									{
										Name = "EXAMPLE-name-Value",
										Confidence = (float)0.9464296,
										BoundingPolygon = new Oci.AidocumentService.Models.BoundingPolygon
										{
											NormalizedVertices = new List<Oci.AidocumentService.Models.NormalizedVertex>
											{
												new Oci.AidocumentService.Models.NormalizedVertex
												{
													X = 0.61571825,
													Y = 0.493146
												}
											}
										},
										WordIndexes = new List<Int32>
										{
											927
										}
									},
									FieldValue = new Oci.AidocumentService.Models.ValuePhoneNumber
									{
										Value = "EXAMPLE-value-Value",
										Text = "EXAMPLE-text-Value",
										Confidence = (float)0.24744278,
										BoundingPolygon = new Oci.AidocumentService.Models.BoundingPolygon
										{
											NormalizedVertices = new List<Oci.AidocumentService.Models.NormalizedVertex>
											{
												new Oci.AidocumentService.Models.NormalizedVertex
												{
													X = 0.22640842,
													Y = 0.43084896
												}
											}
										},
										WordIndexes = new List<Int32>
										{
											793
										},
										NormalizedValue = "EXAMPLE-normalizedValue-Value",
										NormalizedConfidence = (float)0.6887123
									}
								}
							},
							Signatures = new List<Oci.AidocumentService.Models.Signature>
							{
								new Oci.AidocumentService.Models.Signature
								{
									Confidence = (float)0.19839245,
									BoundingPolygon = new Oci.AidocumentService.Models.BoundingPolygon
									{
										NormalizedVertices = new List<Oci.AidocumentService.Models.NormalizedVertex>
										{
											new Oci.AidocumentService.Models.NormalizedVertex
											{
												X = 0.51606256,
												Y = 0.7134767
											}
										}
									}
								}
							},
							BarCodes = new List<Oci.AidocumentService.Models.BarCode>
							{
								new Oci.AidocumentService.Models.BarCode
								{
									Confidence = (float)0.98994696,
									Value = "EXAMPLE-value-Value",
									CodeType = "EXAMPLE-codeType-Value",
									BoundingPolygon = new Oci.AidocumentService.Models.BoundingPolygon
									{
										NormalizedVertices = new List<Oci.AidocumentService.Models.NormalizedVertex>
										{
											new Oci.AidocumentService.Models.NormalizedVertex
											{
												X = 0.10585737,
												Y = 0.24653745
											}
										}
									}
								}
							},
							SelectionMarks = new List<Oci.AidocumentService.Models.SelectionMark>
							{
								new Oci.AidocumentService.Models.SelectionMark
								{
									State = Oci.AidocumentService.Models.SelectionMark.StateEnum.Unselected,
									Confidence = (float)0.49491704,
									BoundingPolygon = new Oci.AidocumentService.Models.BoundingPolygon
									{
										NormalizedVertices = new List<Oci.AidocumentService.Models.NormalizedVertex>
										{
											new Oci.AidocumentService.Models.NormalizedVertex
											{
												X = 0.48811555,
												Y = 0.77463
											}
										}
									}
								}
							}
						}
					},
					DetectedDocumentTypes = new List<Oci.AidocumentService.Models.DetectedDocumentType>
					{
						new Oci.AidocumentService.Models.DetectedDocumentType
						{
							DocumentType = "EXAMPLE-documentType-Value",
							DocumentId = "ocid1.test.oc1..<unique_ID>EXAMPLE-documentId-Value",
							Confidence = (float)0.17152697
						}
					},
					DetectedLanguages = new List<Oci.AidocumentService.Models.DetectedLanguage>
					{
						new Oci.AidocumentService.Models.DetectedLanguage
						{
							Language = "EXAMPLE-language-Value",
							Confidence = (float)0.7799864
						}
					},
					DocumentClassificationModelVersion = "EXAMPLE-documentClassificationModelVersion-Value",
					LanguageClassificationModelVersion = "EXAMPLE-languageClassificationModelVersion-Value",
					TextExtractionModelVersion = "EXAMPLE-textExtractionModelVersion-Value",
					KeyValueExtractionModelVersion = "EXAMPLE-keyValueExtractionModelVersion-Value",
					TableExtractionModelVersion = "EXAMPLE-tableExtractionModelVersion-Value",
					SignatureExtractionModelVersion = "EXAMPLE-signatureExtractionModelVersion-Value",
					BarCodeExtractionModelVersion = "EXAMPLE-barCodeExtractionModelVersion-Value",
					Errors = new List<Oci.AidocumentService.Models.ProcessingError>
					{
						new Oci.AidocumentService.Models.ProcessingError
						{
							Code = "EXAMPLE-code-Value",
							Message = "EXAMPLE-message-Value"
						}
					},
					// Create a byte array. This can be created in several different ways depending on your use case.
					// For example, use <see href="https://docs.microsoft.com/en-us/dotnet/api/system.io.file.readallbytes?view=netcore-3.1">File.ReadAllBytes(String)</see>,
					// or use <see href="https://docs.microsoft.com/en-us/dotnet/api/system.text.encoder?view=netcore-3.1">Encoder class</see>.
					SearchablePdf = System.Text.Encoding.UTF8.GetBytes("some data")
				}
			};
			var analyzeDocumentRequest = new Oci.AidocumentService.Requests.AnalyzeDocumentRequest
			{
				AnalyzeDocumentDetails = analyzeDocumentDetails,
				IfMatch = "EXAMPLE-ifMatch-Value",
				OpcRequestId = "ILYJ7ALH9WCS8HUHG7RV<unique_ID>"
			};

            // Create a default authentication provider that uses the DEFAULT
            // profile in the configuration file.
            // Refer to <see href="https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File>the public documentation</see> on how to prepare a configuration file. 
            var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
            try
            {
                // Create a service client and send the request.
				using (var client = new AIServiceDocumentClient(provider, new ClientConfiguration()))
				{
					var response = await client.AnalyzeDocument(analyzeDocumentRequest);
					// Retrieve value from the response.
					var documentMetadataValue = response.AnalyzeDocumentResult.DocumentMetadata;
				}
            }
            catch (Exception e)
            {
                Console.WriteLine($"AnalyzeDocument Failed with {e.Message}");
                throw e;
            }
        }

    }
}