# 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::Labservices::Mgmt::V2018_10_15
  #
  # The Managed Labs Client.
  #
  class GlobalUsers
    include MsRestAzure

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

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

    #
    # Gets the virtual machine details
    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @param expand [String] Specify the $expand query. Example:
    # 'properties($expand=environment)'
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [GetEnvironmentResponse] operation results.
    #
    def get_environment(user_name, environment_operations_payload, expand:nil, custom_headers:nil)
      response = get_environment_async(user_name, environment_operations_payload, expand:expand, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the virtual machine details
    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @param expand [String] Specify the $expand query. Example:
    # 'properties($expand=environment)'
    # @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_environment_with_http_info(user_name, environment_operations_payload, expand:nil, custom_headers:nil)
      get_environment_async(user_name, environment_operations_payload, expand:expand, custom_headers:custom_headers).value!
    end

    #
    # Gets the virtual machine details
    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @param expand [String] Specify the $expand query. Example:
    # 'properties($expand=environment)'
    # @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_environment_async(user_name, environment_operations_payload, expand:nil, custom_headers:nil)
      fail ArgumentError, 'user_name is nil' if user_name.nil?
      fail ArgumentError, 'environment_operations_payload is nil' if environment_operations_payload.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.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?

      # Serialize Request
      request_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::EnvironmentOperationsPayload.mapper()
      request_content = @client.serialize(request_mapper,  environment_operations_payload)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'providers/Microsoft.LabServices/users/{userName}/getEnvironment'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'userName' => user_name},
          query_params: {'$expand' => expand,'api-version' => @client.api_version},
          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 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?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::GetEnvironmentResponse.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

    #
    # Get batch operation status
    #
    # @param user_name [String] The name of the user.
    # @param operation_batch_status_payload [OperationBatchStatusPayload] Payload
    # to get the status of an operation
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [OperationBatchStatusResponse] operation results.
    #
    def get_operation_batch_status(user_name, operation_batch_status_payload, custom_headers:nil)
      response = get_operation_batch_status_async(user_name, operation_batch_status_payload, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get batch operation status
    #
    # @param user_name [String] The name of the user.
    # @param operation_batch_status_payload [OperationBatchStatusPayload] Payload
    # to get the status of an operation
    # @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_operation_batch_status_with_http_info(user_name, operation_batch_status_payload, custom_headers:nil)
      get_operation_batch_status_async(user_name, operation_batch_status_payload, custom_headers:custom_headers).value!
    end

    #
    # Get batch operation status
    #
    # @param user_name [String] The name of the user.
    # @param operation_batch_status_payload [OperationBatchStatusPayload] Payload
    # to get the status of an operation
    # @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_operation_batch_status_async(user_name, operation_batch_status_payload, custom_headers:nil)
      fail ArgumentError, 'user_name is nil' if user_name.nil?
      fail ArgumentError, 'operation_batch_status_payload is nil' if operation_batch_status_payload.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.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?

      # Serialize Request
      request_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::OperationBatchStatusPayload.mapper()
      request_content = @client.serialize(request_mapper,  operation_batch_status_payload)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'providers/Microsoft.LabServices/users/{userName}/getOperationBatchStatus'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'userName' => user_name},
          query_params: {'api-version' => @client.api_version},
          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 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?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::OperationBatchStatusResponse.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

    #
    # Gets the status of long running operation
    #
    # @param user_name [String] The name of the user.
    # @param operation_status_payload [OperationStatusPayload] Payload to get the
    # status of an operation
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [OperationStatusResponse] operation results.
    #
    def get_operation_status(user_name, operation_status_payload, custom_headers:nil)
      response = get_operation_status_async(user_name, operation_status_payload, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the status of long running operation
    #
    # @param user_name [String] The name of the user.
    # @param operation_status_payload [OperationStatusPayload] Payload to get the
    # status of an operation
    # @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_operation_status_with_http_info(user_name, operation_status_payload, custom_headers:nil)
      get_operation_status_async(user_name, operation_status_payload, custom_headers:custom_headers).value!
    end

    #
    # Gets the status of long running operation
    #
    # @param user_name [String] The name of the user.
    # @param operation_status_payload [OperationStatusPayload] Payload to get the
    # status of an operation
    # @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_operation_status_async(user_name, operation_status_payload, custom_headers:nil)
      fail ArgumentError, 'user_name is nil' if user_name.nil?
      fail ArgumentError, 'operation_status_payload is nil' if operation_status_payload.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.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?

      # Serialize Request
      request_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::OperationStatusPayload.mapper()
      request_content = @client.serialize(request_mapper,  operation_status_payload)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'providers/Microsoft.LabServices/users/{userName}/getOperationStatus'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'userName' => user_name},
          query_params: {'api-version' => @client.api_version},
          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 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?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::OperationStatusResponse.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

    #
    # Get personal preferences for a user
    #
    # @param user_name [String] The name of the user.
    # @param personal_preferences_operations_payload
    # [PersonalPreferencesOperationsPayload] Represents payload for any Environment
    # operations like get, start, stop, connect
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [GetPersonalPreferencesResponse] operation results.
    #
    def get_personal_preferences(user_name, personal_preferences_operations_payload, custom_headers:nil)
      response = get_personal_preferences_async(user_name, personal_preferences_operations_payload, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get personal preferences for a user
    #
    # @param user_name [String] The name of the user.
    # @param personal_preferences_operations_payload
    # [PersonalPreferencesOperationsPayload] Represents payload for any Environment
    # operations like get, start, stop, connect
    # @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_personal_preferences_with_http_info(user_name, personal_preferences_operations_payload, custom_headers:nil)
      get_personal_preferences_async(user_name, personal_preferences_operations_payload, custom_headers:custom_headers).value!
    end

    #
    # Get personal preferences for a user
    #
    # @param user_name [String] The name of the user.
    # @param personal_preferences_operations_payload
    # [PersonalPreferencesOperationsPayload] Represents payload for any Environment
    # operations like get, start, stop, connect
    # @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_personal_preferences_async(user_name, personal_preferences_operations_payload, custom_headers:nil)
      fail ArgumentError, 'user_name is nil' if user_name.nil?
      fail ArgumentError, 'personal_preferences_operations_payload is nil' if personal_preferences_operations_payload.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.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?

      # Serialize Request
      request_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::PersonalPreferencesOperationsPayload.mapper()
      request_content = @client.serialize(request_mapper,  personal_preferences_operations_payload)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'providers/Microsoft.LabServices/users/{userName}/getPersonalPreferences'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'userName' => user_name},
          query_params: {'api-version' => @client.api_version},
          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 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?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::GetPersonalPreferencesResponse.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 Environments for the user
    #
    # @param user_name [String] The name of the user.
    # @param list_environments_payload [ListEnvironmentsPayload] Represents the
    # payload to list environments owned by a user
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ListEnvironmentsResponse] operation results.
    #
    def list_environments(user_name, list_environments_payload, custom_headers:nil)
      response = list_environments_async(user_name, list_environments_payload, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List Environments for the user
    #
    # @param user_name [String] The name of the user.
    # @param list_environments_payload [ListEnvironmentsPayload] Represents the
    # payload to list environments owned by a user
    # @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_environments_with_http_info(user_name, list_environments_payload, custom_headers:nil)
      list_environments_async(user_name, list_environments_payload, custom_headers:custom_headers).value!
    end

    #
    # List Environments for the user
    #
    # @param user_name [String] The name of the user.
    # @param list_environments_payload [ListEnvironmentsPayload] Represents the
    # payload to list environments owned by a user
    # @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_environments_async(user_name, list_environments_payload, custom_headers:nil)
      fail ArgumentError, 'user_name is nil' if user_name.nil?
      fail ArgumentError, 'list_environments_payload is nil' if list_environments_payload.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.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?

      # Serialize Request
      request_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::ListEnvironmentsPayload.mapper()
      request_content = @client.serialize(request_mapper,  list_environments_payload)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'providers/Microsoft.LabServices/users/{userName}/listEnvironments'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'userName' => user_name},
          query_params: {'api-version' => @client.api_version},
          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 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?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::ListEnvironmentsResponse.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 labs for the user.
    #
    # @param user_name [String] The name of the user.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ListLabsResponse] operation results.
    #
    def list_labs(user_name, custom_headers:nil)
      response = list_labs_async(user_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List labs for the user.
    #
    # @param user_name [String] The name of the user.
    # @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_labs_with_http_info(user_name, custom_headers:nil)
      list_labs_async(user_name, custom_headers:custom_headers).value!
    end

    #
    # List labs for the user.
    #
    # @param user_name [String] The name of the user.
    # @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_labs_async(user_name, custom_headers:nil)
      fail ArgumentError, 'user_name is nil' if user_name.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.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 = 'providers/Microsoft.LabServices/users/{userName}/listLabs'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'userName' => user_name},
          query_params: {'api-version' => @client.api_version},
          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 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?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::ListLabsResponse.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

    #
    # Register a user to a managed lab
    #
    # @param user_name [String] The name of the user.
    # @param register_payload [RegisterPayload] Represents payload for Register
    # action.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def register(user_name, register_payload, custom_headers:nil)
      response = register_async(user_name, register_payload, custom_headers:custom_headers).value!
      nil
    end

    #
    # Register a user to a managed lab
    #
    # @param user_name [String] The name of the user.
    # @param register_payload [RegisterPayload] Represents payload for Register
    # action.
    # @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 register_with_http_info(user_name, register_payload, custom_headers:nil)
      register_async(user_name, register_payload, custom_headers:custom_headers).value!
    end

    #
    # Register a user to a managed lab
    #
    # @param user_name [String] The name of the user.
    # @param register_payload [RegisterPayload] Represents payload for Register
    # action.
    # @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 register_async(user_name, register_payload, custom_headers:nil)
      fail ArgumentError, 'user_name is nil' if user_name.nil?
      fail ArgumentError, 'register_payload is nil' if register_payload.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.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?

      # Serialize Request
      request_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::RegisterPayload.mapper()
      request_content = @client.serialize(request_mapper,  register_payload)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'providers/Microsoft.LabServices/users/{userName}/register'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'userName' => user_name},
          query_params: {'api-version' => @client.api_version},
          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 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

    #
    # Resets the user password on an environment This operation can take a while to
    # complete
    #
    # @param user_name [String] The name of the user.
    # @param reset_password_payload [ResetPasswordPayload] Represents the payload
    # for resetting passwords.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    def reset_password(user_name, reset_password_payload, custom_headers:nil)
      response = reset_password_async(user_name, reset_password_payload, custom_headers:custom_headers).value!
      nil
    end

    #
    # @param user_name [String] The name of the user.
    # @param reset_password_payload [ResetPasswordPayload] Represents the payload
    # for resetting passwords.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Concurrent::Promise] promise which provides async access to http
    # response.
    #
    def reset_password_async(user_name, reset_password_payload, custom_headers:nil)
      # Send request
      promise = begin_reset_password_async(user_name, reset_password_payload, custom_headers:custom_headers)

      promise = promise.then do |response|
        # Defining deserialization method.
        deserialize_method = lambda do |parsed_response|
        end

        # Waiting for response.
        @client.get_long_running_operation_result(response, deserialize_method)
      end

      promise
    end

    #
    # Starts an environment by starting all resources inside the environment. This
    # operation can take a while to complete
    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    def start_environment(user_name, environment_operations_payload, custom_headers:nil)
      response = start_environment_async(user_name, environment_operations_payload, custom_headers:custom_headers).value!
      nil
    end

    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Concurrent::Promise] promise which provides async access to http
    # response.
    #
    def start_environment_async(user_name, environment_operations_payload, custom_headers:nil)
      # Send request
      promise = begin_start_environment_async(user_name, environment_operations_payload, custom_headers:custom_headers)

      promise = promise.then do |response|
        # Defining deserialization method.
        deserialize_method = lambda do |parsed_response|
        end

        # Waiting for response.
        @client.get_long_running_operation_result(response, deserialize_method)
      end

      promise
    end

    #
    # Stops an environment by stopping all resources inside the environment This
    # operation can take a while to complete
    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    def stop_environment(user_name, environment_operations_payload, custom_headers:nil)
      response = stop_environment_async(user_name, environment_operations_payload, custom_headers:custom_headers).value!
      nil
    end

    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Concurrent::Promise] promise which provides async access to http
    # response.
    #
    def stop_environment_async(user_name, environment_operations_payload, custom_headers:nil)
      # Send request
      promise = begin_stop_environment_async(user_name, environment_operations_payload, custom_headers:custom_headers)

      promise = promise.then do |response|
        # Defining deserialization method.
        deserialize_method = lambda do |parsed_response|
        end

        # Waiting for response.
        @client.get_long_running_operation_result(response, deserialize_method)
      end

      promise
    end

    #
    # Resets the user password on an environment This operation can take a while to
    # complete
    #
    # @param user_name [String] The name of the user.
    # @param reset_password_payload [ResetPasswordPayload] Represents the payload
    # for resetting passwords.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def begin_reset_password(user_name, reset_password_payload, custom_headers:nil)
      response = begin_reset_password_async(user_name, reset_password_payload, custom_headers:custom_headers).value!
      nil
    end

    #
    # Resets the user password on an environment This operation can take a while to
    # complete
    #
    # @param user_name [String] The name of the user.
    # @param reset_password_payload [ResetPasswordPayload] Represents the payload
    # for resetting passwords.
    # @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 begin_reset_password_with_http_info(user_name, reset_password_payload, custom_headers:nil)
      begin_reset_password_async(user_name, reset_password_payload, custom_headers:custom_headers).value!
    end

    #
    # Resets the user password on an environment This operation can take a while to
    # complete
    #
    # @param user_name [String] The name of the user.
    # @param reset_password_payload [ResetPasswordPayload] Represents the payload
    # for resetting passwords.
    # @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 begin_reset_password_async(user_name, reset_password_payload, custom_headers:nil)
      fail ArgumentError, 'user_name is nil' if user_name.nil?
      fail ArgumentError, 'reset_password_payload is nil' if reset_password_payload.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.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?

      # Serialize Request
      request_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::ResetPasswordPayload.mapper()
      request_content = @client.serialize(request_mapper,  reset_password_payload)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'providers/Microsoft.LabServices/users/{userName}/resetPassword'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'userName' => user_name},
          query_params: {'api-version' => @client.api_version},
          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 || status_code == 202
          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

    #
    # Starts an environment by starting all resources inside the environment. This
    # operation can take a while to complete
    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def begin_start_environment(user_name, environment_operations_payload, custom_headers:nil)
      response = begin_start_environment_async(user_name, environment_operations_payload, custom_headers:custom_headers).value!
      nil
    end

    #
    # Starts an environment by starting all resources inside the environment. This
    # operation can take a while to complete
    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @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 begin_start_environment_with_http_info(user_name, environment_operations_payload, custom_headers:nil)
      begin_start_environment_async(user_name, environment_operations_payload, custom_headers:custom_headers).value!
    end

    #
    # Starts an environment by starting all resources inside the environment. This
    # operation can take a while to complete
    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @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 begin_start_environment_async(user_name, environment_operations_payload, custom_headers:nil)
      fail ArgumentError, 'user_name is nil' if user_name.nil?
      fail ArgumentError, 'environment_operations_payload is nil' if environment_operations_payload.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.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?

      # Serialize Request
      request_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::EnvironmentOperationsPayload.mapper()
      request_content = @client.serialize(request_mapper,  environment_operations_payload)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'providers/Microsoft.LabServices/users/{userName}/startEnvironment'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'userName' => user_name},
          query_params: {'api-version' => @client.api_version},
          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 || status_code == 202
          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

    #
    # Stops an environment by stopping all resources inside the environment This
    # operation can take a while to complete
    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def begin_stop_environment(user_name, environment_operations_payload, custom_headers:nil)
      response = begin_stop_environment_async(user_name, environment_operations_payload, custom_headers:custom_headers).value!
      nil
    end

    #
    # Stops an environment by stopping all resources inside the environment This
    # operation can take a while to complete
    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @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 begin_stop_environment_with_http_info(user_name, environment_operations_payload, custom_headers:nil)
      begin_stop_environment_async(user_name, environment_operations_payload, custom_headers:custom_headers).value!
    end

    #
    # Stops an environment by stopping all resources inside the environment This
    # operation can take a while to complete
    #
    # @param user_name [String] The name of the user.
    # @param environment_operations_payload [EnvironmentOperationsPayload]
    # Represents payload for any Environment operations like get, start, stop,
    # connect
    # @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 begin_stop_environment_async(user_name, environment_operations_payload, custom_headers:nil)
      fail ArgumentError, 'user_name is nil' if user_name.nil?
      fail ArgumentError, 'environment_operations_payload is nil' if environment_operations_payload.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.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?

      # Serialize Request
      request_mapper = Azure::Labservices::Mgmt::V2018_10_15::Models::EnvironmentOperationsPayload.mapper()
      request_content = @client.serialize(request_mapper,  environment_operations_payload)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'providers/Microsoft.LabServices/users/{userName}/stopEnvironment'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'userName' => user_name},
          query_params: {'api-version' => @client.api_version},
          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 || status_code == 202
          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

  end
end
