// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.health.insights.clinicalmatching;

import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceModifiedException;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.util.BinaryData;
import com.azure.core.util.polling.PollerFlux;
import com.azure.health.insights.clinicalmatching.implementation.ClinicalMatchingClientImpl;
import com.azure.health.insights.clinicalmatching.models.TrialMatcherData;
import com.azure.health.insights.clinicalmatching.models.TrialMatcherResult;

/** Initializes a new instance of the asynchronous ClinicalMatchingClient type. */
@ServiceClient(builder = ClinicalMatchingClientBuilder.class, isAsync = true)
public final class ClinicalMatchingAsyncClient {
    @Generated private final ClinicalMatchingClientImpl serviceClient;

    /**
     * Initializes an instance of ClinicalMatchingAsyncClient class.
     *
     * @param serviceClient the service client implementation.
     */
    @Generated
    ClinicalMatchingAsyncClient(ClinicalMatchingClientImpl serviceClient) {
        this.serviceClient = serviceClient;
    }

    /**
     * Create Trial Matcher job
     *
     * <p>Creates a Trial Matcher job with the given request body.
     *
     * <p><strong>Header Parameters</strong>
     *
     * <table border="1">
     *     <caption>Header Parameters</caption>
     *     <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
     *     <tr><td>repeatability-request-id</td><td>String</td><td>No</td><td>Repeatability request ID header</td></tr>
     *     <tr><td>repeatability-first-sent</td><td>String</td><td>No</td><td>Repeatability first sent header as HTTP-date</td></tr>
     * </table>
     *
     * You can add these to a request with {@link RequestOptions#addHeader}
     *
     * <p><strong>Request Body Schema</strong>
     *
     * <pre>{@code
     * {
     *     patients (Required): [
     *          (Required){
     *             id: String (Required)
     *             info (Optional): {
     *                 sex: String(female/male/unspecified) (Optional)
     *                 birthDate: LocalDate (Optional)
     *                 clinicalInfo (Optional): [
     *                      (Optional){
     *                         system: String (Required)
     *                         code: String (Required)
     *                         name: String (Optional)
     *                         value: String (Optional)
     *                     }
     *                 ]
     *             }
     *             data (Optional): [
     *                  (Optional){
     *                     type: String(note/fhirBundle/dicom/genomicSequencing) (Required)
     *                     clinicalType: String(consultation/dischargeSummary/historyAndPhysical/procedure/progress/imaging/laboratory/pathology) (Optional)
     *                     id: String (Required)
     *                     language: String (Optional)
     *                     createdDateTime: OffsetDateTime (Optional)
     *                     content (Required): {
     *                         sourceType: String(inline/reference) (Required)
     *                         value: String (Required)
     *                     }
     *                 }
     *             ]
     *         }
     *     ]
     *     configuration (Optional): {
     *         verbose: Boolean (Optional)
     *         includeEvidence: Boolean (Optional)
     *         clinicalTrials (Required): {
     *             customTrials (Optional): [
     *                  (Optional){
     *                     id: String (Required)
     *                     eligibilityCriteriaText: String (Optional)
     *                     demographics (Optional): {
     *                         acceptedSex: String(all/female/male) (Optional)
     *                         acceptedAgeRange (Optional): {
     *                             minimumAge (Optional): {
     *                                 unit: String(years/months/days) (Required)
     *                                 value: double (Required)
     *                             }
     *                             maximumAge (Optional): (recursive schema, see maximumAge above)
     *                         }
     *                     }
     *                     metadata (Required): {
     *                         phases (Optional): [
     *                             String(notApplicable/earlyPhase1/phase1/phase2/phase3/phase4) (Optional)
     *                         ]
     *                         studyType: String(interventional/observational/expandedAccess/patientRegistries) (Optional)
     *                         recruitmentStatus: String(unknownStatus/notYetRecruiting/recruiting/enrollingByInvitation) (Optional)
     *                         conditions (Required): [
     *                             String (Required)
     *                         ]
     *                         sponsors (Optional): [
     *                             String (Optional)
     *                         ]
     *                         contacts (Optional): [
     *                              (Optional){
     *                                 name: String (Optional)
     *                                 email: String (Optional)
     *                                 phone: String (Optional)
     *                             }
     *                         ]
     *                         facilities (Optional): [
     *                              (Optional){
     *                                 name: String (Required)
     *                                 city: String (Optional)
     *                                 state: String (Optional)
     *                                 countryOrRegion: String (Required)
     *                             }
     *                         ]
     *                     }
     *                 }
     *             ]
     *             registryFilters (Optional): [
     *                  (Optional){
     *                     conditions (Optional): [
     *                         String (Optional)
     *                     ]
     *                     studyTypes (Optional): [
     *                         String(interventional/observational/expandedAccess/patientRegistries) (Optional)
     *                     ]
     *                     recruitmentStatuses (Optional): [
     *                         String(unknownStatus/notYetRecruiting/recruiting/enrollingByInvitation) (Optional)
     *                     ]
     *                     sponsors (Optional): [
     *                         String (Optional)
     *                     ]
     *                     phases (Optional): [
     *                         String(notApplicable/earlyPhase1/phase1/phase2/phase3/phase4) (Optional)
     *                     ]
     *                     purposes (Optional): [
     *                         String(notApplicable/screening/diagnostic/prevention/healthServicesResearch/treatment/deviceFeasibility/supportiveCare/basicScience/other) (Optional)
     *                     ]
     *                     ids (Optional): [
     *                         String (Optional)
     *                     ]
     *                     sources (Optional): [
     *                         String(custom/clinicaltrials.gov) (Optional)
     *                     ]
     *                     facilityNames (Optional): [
     *                         String (Optional)
     *                     ]
     *                     facilityLocations (Optional): [
     *                          (Optional){
     *                             city: String (Optional)
     *                             state: String (Optional)
     *                             countryOrRegion: String (Required)
     *                         }
     *                     ]
     *                     facilityAreas (Optional): [
     *                          (Optional){
     *                             type: String(Feature) (Required)
     *                             geometry (Required): {
     *                                 type: String(Point) (Required)
     *                                 coordinates (Required): [
     *                                     double (Required)
     *                                 ]
     *                             }
     *                             properties (Required): {
     *                                 subType: String(Circle) (Required)
     *                                 radius: double (Required)
     *                             }
     *                         }
     *                     ]
     *                 }
     *             ]
     *         }
     *     }
     * }
     * }</pre>
     *
     * <p><strong>Response Body Schema</strong>
     *
     * <pre>{@code
     * {
     *     jobId: String (Required)
     *     createdDateTime: OffsetDateTime (Required)
     *     expirationDateTime: OffsetDateTime (Required)
     *     lastUpdateDateTime: OffsetDateTime (Required)
     *     status: String(notStarted/running/succeeded/failed/partiallyCompleted) (Required)
     *     errors (Optional): [
     *         ResponseError (Optional)
     *     ]
     *     results (Optional): {
     *         patients (Required): [
     *              (Required){
     *                 id: String (Required)
     *                 inferences (Required): [
     *                      (Required){
     *                         type: String(trialEligibility) (Required)
     *                         value: String (Required)
     *                         description: String (Optional)
     *                         confidenceScore: Double (Optional)
     *                         evidence (Optional): [
     *                              (Optional){
     *                                 eligibilityCriteriaEvidence: String (Optional)
     *                                 patientDataEvidence (Optional): {
     *                                     id: String (Required)
     *                                     text: String (Optional)
     *                                     offset: int (Required)
     *                                     length: int (Required)
     *                                 }
     *                                 patientInfoEvidence (Optional): {
     *                                     system: String (Required)
     *                                     code: String (Required)
     *                                     name: String (Optional)
     *                                     value: String (Optional)
     *                                 }
     *                                 importance: Double (Optional)
     *                             }
     *                         ]
     *                         id: String (Optional)
     *                         source: String(custom/clinicaltrials.gov) (Optional)
     *                         metadata (Optional): {
     *                             phases (Optional): [
     *                                 String(notApplicable/earlyPhase1/phase1/phase2/phase3/phase4) (Optional)
     *                             ]
     *                             studyType: String(interventional/observational/expandedAccess/patientRegistries) (Optional)
     *                             recruitmentStatus: String(unknownStatus/notYetRecruiting/recruiting/enrollingByInvitation) (Optional)
     *                             conditions (Required): [
     *                                 String (Required)
     *                             ]
     *                             sponsors (Optional): [
     *                                 String (Optional)
     *                             ]
     *                             contacts (Optional): [
     *                                  (Optional){
     *                                     name: String (Optional)
     *                                     email: String (Optional)
     *                                     phone: String (Optional)
     *                                 }
     *                             ]
     *                             facilities (Optional): [
     *                                  (Optional){
     *                                     name: String (Required)
     *                                     city: String (Optional)
     *                                     state: String (Optional)
     *                                     countryOrRegion: String (Required)
     *                                 }
     *                             ]
     *                         }
     *                     }
     *                 ]
     *                 neededClinicalInfo (Optional): [
     *                      (Optional){
     *                         system: String (Required)
     *                         code: String (Required)
     *                         name: String (Optional)
     *                         value: String (Optional)
     *                         semanticType: String (Optional)
     *                         category: String (Optional)
     *                     }
     *                 ]
     *             }
     *         ]
     *         modelVersion: String (Required)
     *         knowledgeGraphLastUpdateDate: LocalDate (Optional)
     *     }
     * }
     * }</pre>
     *
     * @param trialMatcherData The body of the Trial Matcher request.
     * @param requestOptions The options to configure the HTTP request before HTTP client sends it.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
     * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
     * @return the {@link PollerFlux} for polling of the response for the Trial Matcher request.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public PollerFlux<BinaryData, BinaryData> beginMatchTrials(
            BinaryData trialMatcherData, RequestOptions requestOptions) {
        return this.serviceClient.beginMatchTrialsAsync(trialMatcherData, requestOptions);
    }

    /**
     * Create Trial Matcher job
     *
     * <p>Creates a Trial Matcher job with the given request body.
     *
     * @param trialMatcherData The body of the Trial Matcher request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
     * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
     * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of the response for the Trial Matcher request.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public PollerFlux<TrialMatcherResult, TrialMatcherResult> beginMatchTrials(TrialMatcherData trialMatcherData) {
        // Generated convenience method for beginMatchTrialsWithModel
        RequestOptions requestOptions = new RequestOptions();
        return serviceClient.beginMatchTrialsWithModelAsync(BinaryData.fromObject(trialMatcherData), requestOptions);
    }
}
