# 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?
        # 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?
        # 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. All stored person data, and
    # face features in the person entry will 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. All stored person data, and
    # face features in the person entry will 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. All stored person data, and
    # face features in the person entry will 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
      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?
        # 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
      end

      promise.execute
    end

    #
    # Delete a face from a person. Relative feature for the persisted face will
    # also be deleted.
    #
    # @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. Relative feature for the persisted face will
    # also be deleted.
    #
    # @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. Relative feature for the persisted face will
    # also be deleted.
    #
    # @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
      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?
        # 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

    #
    # Update a person persisted face's userData field.
    #
    # @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

    #
    # Update a person persisted face's userData field.
    #
    # @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

    #
    # Update a person persisted face's userData field.
    #
    # @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
      end

      promise.execute
    end

    #
    # Add a representative face to a person for identification. The input face is
    # specified as an image with a targetFace rectangle.
    #
    # @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 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, custom_headers:nil)
      response = add_face_from_url_async(person_group_id, person_id, url, user_data:user_data, target_face:target_face, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Add a representative face to a person for identification. The input face is
    # specified as an image with a targetFace rectangle.
    #
    # @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 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, custom_headers:nil)
      add_face_from_url_async(person_group_id, person_id, url, user_data:user_data, target_face:target_face, custom_headers:custom_headers).value!
    end

    #
    # Add a representative face to a person for identification. The input face is
    # specified as an image with a targetFace rectangle.
    #
    # @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 [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, 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(',')},
          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?
        # 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 representative face to a person for identification. The input face is
    # specified as an image with a targetFace rectangle.
    #
    # @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 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, custom_headers:nil)
      response = add_face_from_stream_async(person_group_id, person_id, image, user_data:user_data, target_face:target_face, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Add a representative face to a person for identification. The input face is
    # specified as an image with a targetFace rectangle.
    #
    # @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 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, custom_headers:nil)
      add_face_from_stream_async(person_group_id, person_id, image, user_data:user_data, target_face:target_face, custom_headers:custom_headers).value!
    end

    #
    # Add a representative face to a person for identification. The input face is
    # specified as an image with a targetFace rectangle.
    #
    # @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 [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, 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(',')},
          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?
        # 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
