# encoding: utf-8
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.

module Azure::CognitiveServices::Face::V1_0
  #
  # An API for face detection, verification, and identification.
  #
  class PersonGroupPerson
    include MsRestAzure

    #
    # Creates and initializes a new instance of the PersonGroupPerson class.
    # @param client service class for accessing basic functionality.
    #
    def initialize(client)
      @client = client
    end

    # @return [FaceClient] reference to the FaceClient
    attr_reader :client

    #
    # Create a new person in a specified person group.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param name [String] User defined name, maximum length is 128.
    # @param user_data [String] User specified data. Length should not exceed 16KB.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Person] operation results.
    #
    def create(person_group_id, name:nil, user_data:nil, custom_headers:nil)
      response = create_async(person_group_id, name:name, user_data:user_data, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Create a new person in a specified person group.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param name [String] User defined name, maximum length is 128.
    # @param user_data [String] User specified data. Length should not exceed 16KB.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def create_with_http_info(person_group_id, name:nil, user_data:nil, custom_headers:nil)
      create_async(person_group_id, name:name, user_data:user_data, custom_headers:custom_headers).value!
    end

    #
    # Create a new person in a specified person group.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param name [String] User defined name, maximum length is 128.
    # @param user_data [String] User specified data. Length should not exceed 16KB.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def create_async(person_group_id, name:nil, user_data:nil, custom_headers:nil)
      fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
      fail ArgumentError, 'person_group_id is nil' if person_group_id.nil?
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'MaxLength': '64'" if !person_group_id.nil? && person_group_id.length > 64
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !person_group_id.nil? && person_group_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
      fail ArgumentError, "'name' should satisfy the constraint - 'MaxLength': '128'" if !name.nil? && name.length > 128
      fail ArgumentError, "'user_data' should satisfy the constraint - 'MaxLength': '16384'" if !user_data.nil? && user_data.length > 16384

      body = NameAndUserDataContract.new
      unless name.nil? && user_data.nil?
        body.name = name
        body.user_data = user_data
      end

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

      # Serialize Request
      request_mapper = Azure::CognitiveServices::Face::V1_0::Models::NameAndUserDataContract.mapper()
      request_content = @client.serialize(request_mapper,  body)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'persongroups/{personGroupId}/persons'

      request_url = @base_url || @client.base_url
    request_url = request_url.gsub('{Endpoint}', @client.endpoint)

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'personGroupId' => person_group_id},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:post, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::CognitiveServices::Face::V1_0::Models::Person.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # List all persons in a person group, and retrieve person information
    # (including personId, name, userData and persistedFaceIds of registered faces
    # of the person).
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param start [String] Starting person id to return (used to list a range of
    # persons).
    # @param top [Integer] Number of persons to return starting with the person id
    # indicated by the 'start' parameter.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array] operation results.
    #
    def list(person_group_id, start:nil, top:nil, custom_headers:nil)
      response = list_async(person_group_id, start:start, top:top, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List all persons in a person group, and retrieve person information
    # (including personId, name, userData and persistedFaceIds of registered faces
    # of the person).
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param start [String] Starting person id to return (used to list a range of
    # persons).
    # @param top [Integer] Number of persons to return starting with the person id
    # indicated by the 'start' parameter.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def list_with_http_info(person_group_id, start:nil, top:nil, custom_headers:nil)
      list_async(person_group_id, start:start, top:top, custom_headers:custom_headers).value!
    end

    #
    # List all persons in a person group, and retrieve person information
    # (including personId, name, userData and persistedFaceIds of registered faces
    # of the person).
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param start [String] Starting person id to return (used to list a range of
    # persons).
    # @param top [Integer] Number of persons to return starting with the person id
    # indicated by the 'start' parameter.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def list_async(person_group_id, start:nil, top:nil, custom_headers:nil)
      fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
      fail ArgumentError, 'person_group_id is nil' if person_group_id.nil?
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'MaxLength': '64'" if !person_group_id.nil? && person_group_id.length > 64
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !person_group_id.nil? && person_group_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
      fail ArgumentError, "'top' should satisfy the constraint - 'InclusiveMaximum': '1000'" if !top.nil? && top > 1000
      fail ArgumentError, "'top' should satisfy the constraint - 'InclusiveMinimum': '1'" if !top.nil? && top < 1


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'persongroups/{personGroupId}/persons'

      request_url = @base_url || @client.base_url
    request_url = request_url.gsub('{Endpoint}', @client.endpoint)

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'personGroupId' => person_group_id},
          query_params: {'start' => start,'top' => top},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = {
              client_side_validation: true,
              required: false,
              serialized_name: 'parsed_response',
              type: {
                name: 'Sequence',
                element: {
                    client_side_validation: true,
                    required: false,
                    serialized_name: 'PersonElementType',
                    type: {
                      name: 'Composite',
                      class_name: 'Person'
                    }
                }
              }
            }
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Delete an existing person from a person group. The persistedFaceId, userData,
    # person name and face feature in the person entry will all be deleted.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def delete(person_group_id, person_id, custom_headers:nil)
      response = delete_async(person_group_id, person_id, custom_headers:custom_headers).value!
      nil
    end

    #
    # Delete an existing person from a person group. The persistedFaceId, userData,
    # person name and face feature in the person entry will all be deleted.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def delete_with_http_info(person_group_id, person_id, custom_headers:nil)
      delete_async(person_group_id, person_id, custom_headers:custom_headers).value!
    end

    #
    # Delete an existing person from a person group. The persistedFaceId, userData,
    # person name and face feature in the person entry will all be deleted.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def delete_async(person_group_id, person_id, custom_headers:nil)
      fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
      fail ArgumentError, 'person_group_id is nil' if person_group_id.nil?
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'MaxLength': '64'" if !person_group_id.nil? && person_group_id.length > 64
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !person_group_id.nil? && person_group_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
      fail ArgumentError, 'person_id is nil' if person_id.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'persongroups/{personGroupId}/persons/{personId}'

      request_url = @base_url || @client.base_url
    request_url = request_url.gsub('{Endpoint}', @client.endpoint)

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'personGroupId' => person_group_id,'personId' => person_id},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:delete, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

        result
      end

      promise.execute
    end

    #
    # Retrieve a person's information, including registered persisted faces, name
    # and userData.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Person] operation results.
    #
    def get(person_group_id, person_id, custom_headers:nil)
      response = get_async(person_group_id, person_id, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Retrieve a person's information, including registered persisted faces, name
    # and userData.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def get_with_http_info(person_group_id, person_id, custom_headers:nil)
      get_async(person_group_id, person_id, custom_headers:custom_headers).value!
    end

    #
    # Retrieve a person's information, including registered persisted faces, name
    # and userData.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def get_async(person_group_id, person_id, custom_headers:nil)
      fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
      fail ArgumentError, 'person_group_id is nil' if person_group_id.nil?
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'MaxLength': '64'" if !person_group_id.nil? && person_group_id.length > 64
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !person_group_id.nil? && person_group_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
      fail ArgumentError, 'person_id is nil' if person_id.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'persongroups/{personGroupId}/persons/{personId}'

      request_url = @base_url || @client.base_url
    request_url = request_url.gsub('{Endpoint}', @client.endpoint)

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'personGroupId' => person_group_id,'personId' => person_id},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::CognitiveServices::Face::V1_0::Models::Person.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Update name or userData of a person.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param name [String] User defined name, maximum length is 128.
    # @param user_data [String] User specified data. Length should not exceed 16KB.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def update(person_group_id, person_id, name:nil, user_data:nil, custom_headers:nil)
      response = update_async(person_group_id, person_id, name:name, user_data:user_data, custom_headers:custom_headers).value!
      nil
    end

    #
    # Update name or userData of a person.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param name [String] User defined name, maximum length is 128.
    # @param user_data [String] User specified data. Length should not exceed 16KB.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def update_with_http_info(person_group_id, person_id, name:nil, user_data:nil, custom_headers:nil)
      update_async(person_group_id, person_id, name:name, user_data:user_data, custom_headers:custom_headers).value!
    end

    #
    # Update name or userData of a person.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param name [String] User defined name, maximum length is 128.
    # @param user_data [String] User specified data. Length should not exceed 16KB.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def update_async(person_group_id, person_id, name:nil, user_data:nil, custom_headers:nil)
      fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
      fail ArgumentError, 'person_group_id is nil' if person_group_id.nil?
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'MaxLength': '64'" if !person_group_id.nil? && person_group_id.length > 64
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !person_group_id.nil? && person_group_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
      fail ArgumentError, 'person_id is nil' if person_id.nil?
      fail ArgumentError, "'name' should satisfy the constraint - 'MaxLength': '128'" if !name.nil? && name.length > 128
      fail ArgumentError, "'user_data' should satisfy the constraint - 'MaxLength': '16384'" if !user_data.nil? && user_data.length > 16384

      body = NameAndUserDataContract.new
      unless name.nil? && user_data.nil?
        body.name = name
        body.user_data = user_data
      end

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

      # Serialize Request
      request_mapper = Azure::CognitiveServices::Face::V1_0::Models::NameAndUserDataContract.mapper()
      request_content = @client.serialize(request_mapper,  body)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'persongroups/{personGroupId}/persons/{personId}'

      request_url = @base_url || @client.base_url
    request_url = request_url.gsub('{Endpoint}', @client.endpoint)

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'personGroupId' => person_group_id,'personId' => person_id},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:patch, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

        result
      end

      promise.execute
    end

    #
    # Delete a face from a person in a person group by specified personGroupId,
    # personId and persistedFaceId.
    # <br /> Adding/deleting faces to/from a same person will be processed
    # sequentially. Adding/deleting faces to/from different persons are processed
    # in parallel.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param persisted_face_id Id referencing a particular persistedFaceId of an
    # existing face.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def delete_face(person_group_id, person_id, persisted_face_id, custom_headers:nil)
      response = delete_face_async(person_group_id, person_id, persisted_face_id, custom_headers:custom_headers).value!
      nil
    end

    #
    # Delete a face from a person in a person group by specified personGroupId,
    # personId and persistedFaceId.
    # <br /> Adding/deleting faces to/from a same person will be processed
    # sequentially. Adding/deleting faces to/from different persons are processed
    # in parallel.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param persisted_face_id Id referencing a particular persistedFaceId of an
    # existing face.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def delete_face_with_http_info(person_group_id, person_id, persisted_face_id, custom_headers:nil)
      delete_face_async(person_group_id, person_id, persisted_face_id, custom_headers:custom_headers).value!
    end

    #
    # Delete a face from a person in a person group by specified personGroupId,
    # personId and persistedFaceId.
    # <br /> Adding/deleting faces to/from a same person will be processed
    # sequentially. Adding/deleting faces to/from different persons are processed
    # in parallel.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param persisted_face_id Id referencing a particular persistedFaceId of an
    # existing face.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def delete_face_async(person_group_id, person_id, persisted_face_id, custom_headers:nil)
      fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
      fail ArgumentError, 'person_group_id is nil' if person_group_id.nil?
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'MaxLength': '64'" if !person_group_id.nil? && person_group_id.length > 64
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !person_group_id.nil? && person_group_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
      fail ArgumentError, 'person_id is nil' if person_id.nil?
      fail ArgumentError, 'persisted_face_id is nil' if persisted_face_id.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'persongroups/{personGroupId}/persons/{personId}/persistedfaces/{persistedFaceId}'

      request_url = @base_url || @client.base_url
    request_url = request_url.gsub('{Endpoint}', @client.endpoint)

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'personGroupId' => person_group_id,'personId' => person_id,'persistedFaceId' => persisted_face_id},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:delete, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

        result
      end

      promise.execute
    end

    #
    # Retrieve information about a persisted face (specified by persistedFaceId,
    # personId and its belonging personGroupId).
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param persisted_face_id Id referencing a particular persistedFaceId of an
    # existing face.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [PersistedFace] operation results.
    #
    def get_face(person_group_id, person_id, persisted_face_id, custom_headers:nil)
      response = get_face_async(person_group_id, person_id, persisted_face_id, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Retrieve information about a persisted face (specified by persistedFaceId,
    # personId and its belonging personGroupId).
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param persisted_face_id Id referencing a particular persistedFaceId of an
    # existing face.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def get_face_with_http_info(person_group_id, person_id, persisted_face_id, custom_headers:nil)
      get_face_async(person_group_id, person_id, persisted_face_id, custom_headers:custom_headers).value!
    end

    #
    # Retrieve information about a persisted face (specified by persistedFaceId,
    # personId and its belonging personGroupId).
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param persisted_face_id Id referencing a particular persistedFaceId of an
    # existing face.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def get_face_async(person_group_id, person_id, persisted_face_id, custom_headers:nil)
      fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
      fail ArgumentError, 'person_group_id is nil' if person_group_id.nil?
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'MaxLength': '64'" if !person_group_id.nil? && person_group_id.length > 64
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !person_group_id.nil? && person_group_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
      fail ArgumentError, 'person_id is nil' if person_id.nil?
      fail ArgumentError, 'persisted_face_id is nil' if persisted_face_id.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = 'persongroups/{personGroupId}/persons/{personId}/persistedfaces/{persistedFaceId}'

      request_url = @base_url || @client.base_url
    request_url = request_url.gsub('{Endpoint}', @client.endpoint)

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'personGroupId' => person_group_id,'personId' => person_id,'persistedFaceId' => persisted_face_id},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::CognitiveServices::Face::V1_0::Models::PersistedFace.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Add a face to a person into a person group for face identification or
    # verification. To deal with an image contains multiple faces, input face can
    # be specified as an image with a targetFace rectangle. It returns a
    # persistedFaceId representing the added face. No image will be stored. Only
    # the extracted face feature will be stored on server until [PersonGroup
    # PersonFace -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e),
    # [PersonGroup Person -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
    # or [PersonGroup -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
    # is called.
    # <br /> Note persistedFaceId is different from faceId generated by [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
    # * Higher face image quality means better recognition precision. Please
    # consider high-quality faces: frontal, clear, and face size is 200x200 pixels
    # (100 pixels between eyes) or bigger.
    # * Each person entry can hold up to 248 faces.
    # * JPEG, PNG, GIF (the first frame), and BMP format are supported. The allowed
    # image file size is from 1KB to 6MB.
    # * "targetFace" rectangle should contain one face. Zero or multiple faces will
    # be regarded as an error. If the provided "targetFace" rectangle is not
    # returned from [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
    # there’s no guarantee to detect and add the face successfully.
    # * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose, or
    # large occlusions will cause failures.
    # * Adding/deleting faces to/from a same person will be processed sequentially.
    # Adding/deleting faces to/from different persons are processed in parallel.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param persisted_face_id Id referencing a particular persistedFaceId of an
    # existing face.
    # @param user_data [String] User-provided data attached to the face. The size
    # limit is 1KB.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def update_face(person_group_id, person_id, persisted_face_id, user_data:nil, custom_headers:nil)
      response = update_face_async(person_group_id, person_id, persisted_face_id, user_data:user_data, custom_headers:custom_headers).value!
      nil
    end

    #
    # Add a face to a person into a person group for face identification or
    # verification. To deal with an image contains multiple faces, input face can
    # be specified as an image with a targetFace rectangle. It returns a
    # persistedFaceId representing the added face. No image will be stored. Only
    # the extracted face feature will be stored on server until [PersonGroup
    # PersonFace -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e),
    # [PersonGroup Person -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
    # or [PersonGroup -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
    # is called.
    # <br /> Note persistedFaceId is different from faceId generated by [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
    # * Higher face image quality means better recognition precision. Please
    # consider high-quality faces: frontal, clear, and face size is 200x200 pixels
    # (100 pixels between eyes) or bigger.
    # * Each person entry can hold up to 248 faces.
    # * JPEG, PNG, GIF (the first frame), and BMP format are supported. The allowed
    # image file size is from 1KB to 6MB.
    # * "targetFace" rectangle should contain one face. Zero or multiple faces will
    # be regarded as an error. If the provided "targetFace" rectangle is not
    # returned from [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
    # there’s no guarantee to detect and add the face successfully.
    # * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose, or
    # large occlusions will cause failures.
    # * Adding/deleting faces to/from a same person will be processed sequentially.
    # Adding/deleting faces to/from different persons are processed in parallel.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param persisted_face_id Id referencing a particular persistedFaceId of an
    # existing face.
    # @param user_data [String] User-provided data attached to the face. The size
    # limit is 1KB.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def update_face_with_http_info(person_group_id, person_id, persisted_face_id, user_data:nil, custom_headers:nil)
      update_face_async(person_group_id, person_id, persisted_face_id, user_data:user_data, custom_headers:custom_headers).value!
    end

    #
    # Add a face to a person into a person group for face identification or
    # verification. To deal with an image contains multiple faces, input face can
    # be specified as an image with a targetFace rectangle. It returns a
    # persistedFaceId representing the added face. No image will be stored. Only
    # the extracted face feature will be stored on server until [PersonGroup
    # PersonFace -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e),
    # [PersonGroup Person -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
    # or [PersonGroup -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
    # is called.
    # <br /> Note persistedFaceId is different from faceId generated by [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
    # * Higher face image quality means better recognition precision. Please
    # consider high-quality faces: frontal, clear, and face size is 200x200 pixels
    # (100 pixels between eyes) or bigger.
    # * Each person entry can hold up to 248 faces.
    # * JPEG, PNG, GIF (the first frame), and BMP format are supported. The allowed
    # image file size is from 1KB to 6MB.
    # * "targetFace" rectangle should contain one face. Zero or multiple faces will
    # be regarded as an error. If the provided "targetFace" rectangle is not
    # returned from [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
    # there’s no guarantee to detect and add the face successfully.
    # * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose, or
    # large occlusions will cause failures.
    # * Adding/deleting faces to/from a same person will be processed sequentially.
    # Adding/deleting faces to/from different persons are processed in parallel.
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param persisted_face_id Id referencing a particular persistedFaceId of an
    # existing face.
    # @param user_data [String] User-provided data attached to the face. The size
    # limit is 1KB.
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def update_face_async(person_group_id, person_id, persisted_face_id, user_data:nil, custom_headers:nil)
      fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
      fail ArgumentError, 'person_group_id is nil' if person_group_id.nil?
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'MaxLength': '64'" if !person_group_id.nil? && person_group_id.length > 64
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !person_group_id.nil? && person_group_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
      fail ArgumentError, 'person_id is nil' if person_id.nil?
      fail ArgumentError, 'persisted_face_id is nil' if persisted_face_id.nil?
      fail ArgumentError, "'user_data' should satisfy the constraint - 'MaxLength': '1024'" if !user_data.nil? && user_data.length > 1024

      body = UpdateFaceRequest.new
      unless user_data.nil?
        body.user_data = user_data
      end

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

      # Serialize Request
      request_mapper = Azure::CognitiveServices::Face::V1_0::Models::UpdateFaceRequest.mapper()
      request_content = @client.serialize(request_mapper,  body)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'persongroups/{personGroupId}/persons/{personId}/persistedfaces/{persistedFaceId}'

      request_url = @base_url || @client.base_url
    request_url = request_url.gsub('{Endpoint}', @client.endpoint)

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'personGroupId' => person_group_id,'personId' => person_id,'persistedFaceId' => persisted_face_id},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:patch, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

        result
      end

      promise.execute
    end

    #
    # Add a face to a person into a person group for face identification or
    # verification. To deal with an image contains multiple faces, input face can
    # be specified as an image with a targetFace rectangle. It returns a
    # persistedFaceId representing the added face. No image will be stored. Only
    # the extracted face feature will be stored on server until [PersonGroup
    # PersonFace -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e),
    # [PersonGroup Person -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
    # or [PersonGroup -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
    # is called.
    # <br /> Note persistedFaceId is different from faceId generated by [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
    # *   Higher face image quality means better recognition precision. Please
    # consider high-quality faces: frontal, clear, and face size is 200x200 pixels
    # (100 pixels between eyes) or bigger.
    # *   Each person entry can hold up to 248 faces.
    # *   JPEG, PNG, GIF (the first frame), and BMP format are supported. The
    # allowed image file size is from 1KB to 6MB.
    # *   "targetFace" rectangle should contain one face. Zero or multiple faces
    # will be regarded as an error. If the provided "targetFace" rectangle is not
    # returned from [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
    # there’s no guarantee to detect and add the face successfully.
    # *   Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
    # or large occlusions will cause failures.
    # *   Adding/deleting faces to/from a same person will be processed
    # sequentially. Adding/deleting faces to/from different persons are processed
    # in parallel.
    # * The minimum detectable face size is 36x36 pixels in an image no larger than
    # 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels will
    # need a proportionally larger minimum face size.
    # * Different 'detectionModel' values can be provided. To use and compare
    # different detection models, please refer to [How to specify a detection
    # model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model)
    # | Model | Recommended use-case(s) |
    # | ---------- | -------- |
    # | 'detection_01': | The default detection model for [PersonGroup Person - Add
    # Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b).
    # Recommend for near frontal face detection. For scenarios with exceptionally
    # large angle (head-pose) faces, occluded faces or wrong image orientation, the
    # faces in such cases may not be detected. |
    # | 'detection_02': | Detection model released in 2019 May with improved
    # accuracy especially on small, side and blurry faces. |
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param url [String] Publicly reachable URL of an image
    # @param user_data [String] User-specified data about the face for any purpose.
    # The maximum length is 1KB.
    # @param target_face [Array<Integer>] A face rectangle to specify the target
    # face to be added to a person in the format of
    # "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there
    # is more than one face in the image, targetFace is required to specify which
    # face to add. No targetFace means there is only one face detected in the
    # entire image.
    # @param detection_model [DetectionModel] Name of detection model. Detection
    # model is used to detect faces in the submitted image. A detection model name
    # can be provided when performing Face - Detect or (Large)FaceList - Add Face
    # or (Large)PersonGroup - Add Face. The default value is 'detection_01', if
    # another model is needed, please explicitly specify it. Possible values
    # include: 'detection_01', 'detection_02'
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [PersistedFace] operation results.
    #
    def add_face_from_url(person_group_id, person_id, url, user_data:nil, target_face:nil, detection_model:nil, custom_headers:nil)
      response = add_face_from_url_async(person_group_id, person_id, url, user_data:user_data, target_face:target_face, detection_model:detection_model, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Add a face to a person into a person group for face identification or
    # verification. To deal with an image contains multiple faces, input face can
    # be specified as an image with a targetFace rectangle. It returns a
    # persistedFaceId representing the added face. No image will be stored. Only
    # the extracted face feature will be stored on server until [PersonGroup
    # PersonFace -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e),
    # [PersonGroup Person -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
    # or [PersonGroup -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
    # is called.
    # <br /> Note persistedFaceId is different from faceId generated by [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
    # *   Higher face image quality means better recognition precision. Please
    # consider high-quality faces: frontal, clear, and face size is 200x200 pixels
    # (100 pixels between eyes) or bigger.
    # *   Each person entry can hold up to 248 faces.
    # *   JPEG, PNG, GIF (the first frame), and BMP format are supported. The
    # allowed image file size is from 1KB to 6MB.
    # *   "targetFace" rectangle should contain one face. Zero or multiple faces
    # will be regarded as an error. If the provided "targetFace" rectangle is not
    # returned from [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
    # there’s no guarantee to detect and add the face successfully.
    # *   Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
    # or large occlusions will cause failures.
    # *   Adding/deleting faces to/from a same person will be processed
    # sequentially. Adding/deleting faces to/from different persons are processed
    # in parallel.
    # * The minimum detectable face size is 36x36 pixels in an image no larger than
    # 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels will
    # need a proportionally larger minimum face size.
    # * Different 'detectionModel' values can be provided. To use and compare
    # different detection models, please refer to [How to specify a detection
    # model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model)
    # | Model | Recommended use-case(s) |
    # | ---------- | -------- |
    # | 'detection_01': | The default detection model for [PersonGroup Person - Add
    # Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b).
    # Recommend for near frontal face detection. For scenarios with exceptionally
    # large angle (head-pose) faces, occluded faces or wrong image orientation, the
    # faces in such cases may not be detected. |
    # | 'detection_02': | Detection model released in 2019 May with improved
    # accuracy especially on small, side and blurry faces. |
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param url [String] Publicly reachable URL of an image
    # @param user_data [String] User-specified data about the face for any purpose.
    # The maximum length is 1KB.
    # @param target_face [Array<Integer>] A face rectangle to specify the target
    # face to be added to a person in the format of
    # "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there
    # is more than one face in the image, targetFace is required to specify which
    # face to add. No targetFace means there is only one face detected in the
    # entire image.
    # @param detection_model [DetectionModel] Name of detection model. Detection
    # model is used to detect faces in the submitted image. A detection model name
    # can be provided when performing Face - Detect or (Large)FaceList - Add Face
    # or (Large)PersonGroup - Add Face. The default value is 'detection_01', if
    # another model is needed, please explicitly specify it. Possible values
    # include: 'detection_01', 'detection_02'
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def add_face_from_url_with_http_info(person_group_id, person_id, url, user_data:nil, target_face:nil, detection_model:nil, custom_headers:nil)
      add_face_from_url_async(person_group_id, person_id, url, user_data:user_data, target_face:target_face, detection_model:detection_model, custom_headers:custom_headers).value!
    end

    #
    # Add a face to a person into a person group for face identification or
    # verification. To deal with an image contains multiple faces, input face can
    # be specified as an image with a targetFace rectangle. It returns a
    # persistedFaceId representing the added face. No image will be stored. Only
    # the extracted face feature will be stored on server until [PersonGroup
    # PersonFace -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e),
    # [PersonGroup Person -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
    # or [PersonGroup -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
    # is called.
    # <br /> Note persistedFaceId is different from faceId generated by [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
    # *   Higher face image quality means better recognition precision. Please
    # consider high-quality faces: frontal, clear, and face size is 200x200 pixels
    # (100 pixels between eyes) or bigger.
    # *   Each person entry can hold up to 248 faces.
    # *   JPEG, PNG, GIF (the first frame), and BMP format are supported. The
    # allowed image file size is from 1KB to 6MB.
    # *   "targetFace" rectangle should contain one face. Zero or multiple faces
    # will be regarded as an error. If the provided "targetFace" rectangle is not
    # returned from [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
    # there’s no guarantee to detect and add the face successfully.
    # *   Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
    # or large occlusions will cause failures.
    # *   Adding/deleting faces to/from a same person will be processed
    # sequentially. Adding/deleting faces to/from different persons are processed
    # in parallel.
    # * The minimum detectable face size is 36x36 pixels in an image no larger than
    # 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels will
    # need a proportionally larger minimum face size.
    # * Different 'detectionModel' values can be provided. To use and compare
    # different detection models, please refer to [How to specify a detection
    # model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model)
    # | Model | Recommended use-case(s) |
    # | ---------- | -------- |
    # | 'detection_01': | The default detection model for [PersonGroup Person - Add
    # Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b).
    # Recommend for near frontal face detection. For scenarios with exceptionally
    # large angle (head-pose) faces, occluded faces or wrong image orientation, the
    # faces in such cases may not be detected. |
    # | 'detection_02': | Detection model released in 2019 May with improved
    # accuracy especially on small, side and blurry faces. |
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param url [String] Publicly reachable URL of an image
    # @param user_data [String] User-specified data about the face for any purpose.
    # The maximum length is 1KB.
    # @param target_face [Array<Integer>] A face rectangle to specify the target
    # face to be added to a person in the format of
    # "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there
    # is more than one face in the image, targetFace is required to specify which
    # face to add. No targetFace means there is only one face detected in the
    # entire image.
    # @param detection_model [DetectionModel] Name of detection model. Detection
    # model is used to detect faces in the submitted image. A detection model name
    # can be provided when performing Face - Detect or (Large)FaceList - Add Face
    # or (Large)PersonGroup - Add Face. The default value is 'detection_01', if
    # another model is needed, please explicitly specify it. Possible values
    # include: 'detection_01', 'detection_02'
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def add_face_from_url_async(person_group_id, person_id, url, user_data:nil, target_face:nil, detection_model:nil, custom_headers:nil)
      fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
      fail ArgumentError, 'person_group_id is nil' if person_group_id.nil?
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'MaxLength': '64'" if !person_group_id.nil? && person_group_id.length > 64
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !person_group_id.nil? && person_group_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
      fail ArgumentError, 'person_id is nil' if person_id.nil?
      fail ArgumentError, "'user_data' should satisfy the constraint - 'MaxLength': '1024'" if !user_data.nil? && user_data.length > 1024
      fail ArgumentError, 'url is nil' if url.nil?

      image_url = ImageUrl.new
      unless url.nil?
        image_url.url = url
      end

      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

      # Serialize Request
      request_mapper = Azure::CognitiveServices::Face::V1_0::Models::ImageUrl.mapper()
      request_content = @client.serialize(request_mapper,  image_url)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'persongroups/{personGroupId}/persons/{personId}/persistedfaces'

      request_url = @base_url || @client.base_url
    request_url = request_url.gsub('{Endpoint}', @client.endpoint)

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'personGroupId' => person_group_id,'personId' => person_id},
          query_params: {'userData' => user_data,'targetFace' => target_face.nil? ? nil : target_face.join(','),'detectionModel' => detection_model},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:post, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::CognitiveServices::Face::V1_0::Models::PersistedFace.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

    #
    # Add a face to a person into a person group for face identification or
    # verification. To deal with an image contains multiple faces, input face can
    # be specified as an image with a targetFace rectangle. It returns a
    # persistedFaceId representing the added face. No image will be stored. Only
    # the extracted face feature will be stored on server until [PersonGroup
    # PersonFace -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e),
    # [PersonGroup Person -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
    # or [PersonGroup -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
    # is called.
    # <br /> Note persistedFaceId is different from faceId generated by [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
    # *   Higher face image quality means better recognition precision. Please
    # consider high-quality faces: frontal, clear, and face size is 200x200 pixels
    # (100 pixels between eyes) or bigger.
    # *   Each person entry can hold up to 248 faces.
    # *   JPEG, PNG, GIF (the first frame), and BMP format are supported. The
    # allowed image file size is from 1KB to 6MB.
    # *   "targetFace" rectangle should contain one face. Zero or multiple faces
    # will be regarded as an error. If the provided "targetFace" rectangle is not
    # returned from [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
    # there’s no guarantee to detect and add the face successfully.
    # *   Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
    # or large occlusions will cause failures.
    # *   Adding/deleting faces to/from a same person will be processed
    # sequentially. Adding/deleting faces to/from different persons are processed
    # in parallel.
    # * The minimum detectable face size is 36x36 pixels in an image no larger than
    # 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels will
    # need a proportionally larger minimum face size.
    # * Different 'detectionModel' values can be provided. To use and compare
    # different detection models, please refer to [How to specify a detection
    # model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model)
    # | Model | Recommended use-case(s) |
    # | ---------- | -------- |
    # | 'detection_01': | The default detection model for [PersonGroup Person - Add
    # Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b).
    # Recommend for near frontal face detection. For scenarios with exceptionally
    # large angle (head-pose) faces, occluded faces or wrong image orientation, the
    # faces in such cases may not be detected. |
    # | 'detection_02': | Detection model released in 2019 May with improved
    # accuracy especially on small, side and blurry faces. |
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param image An image stream.
    # @param user_data [String] User-specified data about the face for any purpose.
    # The maximum length is 1KB.
    # @param target_face [Array<Integer>] A face rectangle to specify the target
    # face to be added to a person in the format of
    # "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there
    # is more than one face in the image, targetFace is required to specify which
    # face to add. No targetFace means there is only one face detected in the
    # entire image.
    # @param detection_model [DetectionModel] Name of detection model. Detection
    # model is used to detect faces in the submitted image. A detection model name
    # can be provided when performing Face - Detect or (Large)FaceList - Add Face
    # or (Large)PersonGroup - Add Face. The default value is 'detection_01', if
    # another model is needed, please explicitly specify it. Possible values
    # include: 'detection_01', 'detection_02'
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [PersistedFace] operation results.
    #
    def add_face_from_stream(person_group_id, person_id, image, user_data:nil, target_face:nil, detection_model:nil, custom_headers:nil)
      response = add_face_from_stream_async(person_group_id, person_id, image, user_data:user_data, target_face:target_face, detection_model:detection_model, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Add a face to a person into a person group for face identification or
    # verification. To deal with an image contains multiple faces, input face can
    # be specified as an image with a targetFace rectangle. It returns a
    # persistedFaceId representing the added face. No image will be stored. Only
    # the extracted face feature will be stored on server until [PersonGroup
    # PersonFace -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e),
    # [PersonGroup Person -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
    # or [PersonGroup -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
    # is called.
    # <br /> Note persistedFaceId is different from faceId generated by [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
    # *   Higher face image quality means better recognition precision. Please
    # consider high-quality faces: frontal, clear, and face size is 200x200 pixels
    # (100 pixels between eyes) or bigger.
    # *   Each person entry can hold up to 248 faces.
    # *   JPEG, PNG, GIF (the first frame), and BMP format are supported. The
    # allowed image file size is from 1KB to 6MB.
    # *   "targetFace" rectangle should contain one face. Zero or multiple faces
    # will be regarded as an error. If the provided "targetFace" rectangle is not
    # returned from [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
    # there’s no guarantee to detect and add the face successfully.
    # *   Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
    # or large occlusions will cause failures.
    # *   Adding/deleting faces to/from a same person will be processed
    # sequentially. Adding/deleting faces to/from different persons are processed
    # in parallel.
    # * The minimum detectable face size is 36x36 pixels in an image no larger than
    # 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels will
    # need a proportionally larger minimum face size.
    # * Different 'detectionModel' values can be provided. To use and compare
    # different detection models, please refer to [How to specify a detection
    # model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model)
    # | Model | Recommended use-case(s) |
    # | ---------- | -------- |
    # | 'detection_01': | The default detection model for [PersonGroup Person - Add
    # Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b).
    # Recommend for near frontal face detection. For scenarios with exceptionally
    # large angle (head-pose) faces, occluded faces or wrong image orientation, the
    # faces in such cases may not be detected. |
    # | 'detection_02': | Detection model released in 2019 May with improved
    # accuracy especially on small, side and blurry faces. |
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param image An image stream.
    # @param user_data [String] User-specified data about the face for any purpose.
    # The maximum length is 1KB.
    # @param target_face [Array<Integer>] A face rectangle to specify the target
    # face to be added to a person in the format of
    # "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there
    # is more than one face in the image, targetFace is required to specify which
    # face to add. No targetFace means there is only one face detected in the
    # entire image.
    # @param detection_model [DetectionModel] Name of detection model. Detection
    # model is used to detect faces in the submitted image. A detection model name
    # can be provided when performing Face - Detect or (Large)FaceList - Add Face
    # or (Large)PersonGroup - Add Face. The default value is 'detection_01', if
    # another model is needed, please explicitly specify it. Possible values
    # include: 'detection_01', 'detection_02'
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def add_face_from_stream_with_http_info(person_group_id, person_id, image, user_data:nil, target_face:nil, detection_model:nil, custom_headers:nil)
      add_face_from_stream_async(person_group_id, person_id, image, user_data:user_data, target_face:target_face, detection_model:detection_model, custom_headers:custom_headers).value!
    end

    #
    # Add a face to a person into a person group for face identification or
    # verification. To deal with an image contains multiple faces, input face can
    # be specified as an image with a targetFace rectangle. It returns a
    # persistedFaceId representing the added face. No image will be stored. Only
    # the extracted face feature will be stored on server until [PersonGroup
    # PersonFace -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e),
    # [PersonGroup Person -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d)
    # or [PersonGroup -
    # Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245)
    # is called.
    # <br /> Note persistedFaceId is different from faceId generated by [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236).
    # *   Higher face image quality means better recognition precision. Please
    # consider high-quality faces: frontal, clear, and face size is 200x200 pixels
    # (100 pixels between eyes) or bigger.
    # *   Each person entry can hold up to 248 faces.
    # *   JPEG, PNG, GIF (the first frame), and BMP format are supported. The
    # allowed image file size is from 1KB to 6MB.
    # *   "targetFace" rectangle should contain one face. Zero or multiple faces
    # will be regarded as an error. If the provided "targetFace" rectangle is not
    # returned from [Face -
    # Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236),
    # there’s no guarantee to detect and add the face successfully.
    # *   Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose,
    # or large occlusions will cause failures.
    # *   Adding/deleting faces to/from a same person will be processed
    # sequentially. Adding/deleting faces to/from different persons are processed
    # in parallel.
    # * The minimum detectable face size is 36x36 pixels in an image no larger than
    # 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels will
    # need a proportionally larger minimum face size.
    # * Different 'detectionModel' values can be provided. To use and compare
    # different detection models, please refer to [How to specify a detection
    # model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detection-model)
    # | Model | Recommended use-case(s) |
    # | ---------- | -------- |
    # | 'detection_01': | The default detection model for [PersonGroup Person - Add
    # Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b).
    # Recommend for near frontal face detection. For scenarios with exceptionally
    # large angle (head-pose) faces, occluded faces or wrong image orientation, the
    # faces in such cases may not be detected. |
    # | 'detection_02': | Detection model released in 2019 May with improved
    # accuracy especially on small, side and blurry faces. |
    #
    # @param person_group_id [String] Id referencing a particular person group.
    # @param person_id Id referencing a particular person.
    # @param image An image stream.
    # @param user_data [String] User-specified data about the face for any purpose.
    # The maximum length is 1KB.
    # @param target_face [Array<Integer>] A face rectangle to specify the target
    # face to be added to a person in the format of
    # "targetFace=left,top,width,height". E.g. "targetFace=10,10,100,100". If there
    # is more than one face in the image, targetFace is required to specify which
    # face to add. No targetFace means there is only one face detected in the
    # entire image.
    # @param detection_model [DetectionModel] Name of detection model. Detection
    # model is used to detect faces in the submitted image. A detection model name
    # can be provided when performing Face - Detect or (Large)FaceList - Add Face
    # or (Large)PersonGroup - Add Face. The default value is 'detection_01', if
    # another model is needed, please explicitly specify it. Possible values
    # include: 'detection_01', 'detection_02'
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def add_face_from_stream_async(person_group_id, person_id, image, user_data:nil, target_face:nil, detection_model:nil, custom_headers:nil)
      fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
      fail ArgumentError, 'person_group_id is nil' if person_group_id.nil?
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'MaxLength': '64'" if !person_group_id.nil? && person_group_id.length > 64
      fail ArgumentError, "'person_group_id' should satisfy the constraint - 'Pattern': '^[a-z0-9-_]+$'" if !person_group_id.nil? && person_group_id.match(Regexp.new('^^[a-z0-9-_]+$$')).nil?
      fail ArgumentError, 'person_id is nil' if person_id.nil?
      fail ArgumentError, "'user_data' should satisfy the constraint - 'MaxLength': '1024'" if !user_data.nil? && user_data.length > 1024
      fail ArgumentError, 'image is nil' if image.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/octet-stream'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

      # Serialize Request
      request_mapper = {
        client_side_validation: true,
        required: true,
        serialized_name: 'Image',
        type: {
          name: 'Stream'
        }
      }
      request_content = @client.serialize(request_mapper,  image)

      path_template = 'persongroups/{personGroupId}/persons/{personId}/persistedfaces'

      request_url = @base_url || @client.base_url
    request_url = request_url.gsub('{Endpoint}', @client.endpoint)

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'personGroupId' => person_group_id,'personId' => person_id},
          query_params: {'userData' => user_data,'targetFace' => target_face.nil? ? nil : target_face.join(','),'detectionModel' => detection_model},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:post, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::CognitiveServices::Face::V1_0::Models::PersistedFace.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

  end
end
