# pepipost
#
# This file was automatically generated by APIMATIC v2.0 (
# https://apimatic.io ).

module Pepipost
  # SubaccountsUpdateSubaccountController
  class SubaccountsUpdateSubaccountController < BaseController
    @instance = SubaccountsUpdateSubaccountController.new

    class << self
      attr_accessor :instance
    end

    def instance
      self.class.instance
    end

    # lets you update credentials and credit type of a subaccount.
    # @param [UpdateSubaccount] body Required parameter: Update sub account
    # @return Object response from the API call
    def create_subaccounts_update_subaccount_post(body)
      # Prepare query url.
      _path_url = '/subaccounts/updateSubaccount'
      _query_builder = Configuration.base_uri.dup
      _query_builder << _path_url
      _query_url = APIHelper.clean_url _query_builder
      # Prepare headers.
      _headers = {
        'content-type' => 'application/json; charset=utf-8'
      }
      # Prepare and execute HttpRequest.
      _request = @http_client.post(
        _query_url,
        headers: _headers,
        parameters: body.to_json
      )
      CustomHeaderAuth.apply(_request)
      _context = execute_request(_request)
      # Validate response against endpoint and global error codes.
      if _context.response.status_code == 400
        raise APIException.new(
          'API Response',
          _context
        )
      elsif _context.response.status_code == 401
        raise APIException.new(
          'API Response',
          _context
        )
      elsif _context.response.status_code == 403
        raise APIException.new(
          'API Response',
          _context
        )
      elsif _context.response.status_code == 405
        raise APIException.new(
          'Invalid input',
          _context
        )
      end
      validate_response(_context)
      # Return appropriate response type.
      _context.response.raw_body
    end
  end
end
