# Channel Access Token API
# This document describes Channel Access Token API.
#
# The version of the OpenAPI document: 0.0.1
#
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
# https://openapi-generator.tech
# Do not edit the class manually.

require 'json'

require 'line/bot/v2/http_client'
require 'line/bot/v2/reserved_words'
require 'line/bot/v2/utils'

module Line
  module Bot
    module V2
      module ChannelAccessToken
        class ApiClient
          # Initializes a new {Line::Bot::V2::ChannelAccessToken::ApiClient} instance.
          #
          # @param base_url [String] The base URL for requests (optional).
          #   Defaults to 'https://api.line.me' if none is provided.
          #   You can override this for testing or to use a mock server.
          # @param http_options [Hash] HTTP options (same as Net::HTTP options).
          #   See: https://docs.ruby-lang.org/en/3.4/Net/HTTP.html to understand the options.
          #
          # @example
          #   @client ||= Line::Bot::V2::ChannelAccessToken::ApiClient.new(
          #     http_options: {
          #       open_timeout: 5,
          #       read_timeout: 5,
          #     }
          #   )
          def initialize(base_url: nil, http_options: {})
            @http_client = HttpClient.new(
              base_url: base_url || 'https://api.line.me',
              http_options: http_options
            )
          end

          # Gets all valid channel access token key IDs.
          # This requests to <code>GET https://api.line.me/oauth2/v2.1/tokens/kid</code>
          # This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
          #
          # @param client_assertion_type [String] `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
          # @param client_assertion [String] A JSON Web Token (JWT) (opens new window)the client needs to create and sign with the private key.
          # @see https://developers.line.biz/en/reference/messaging-api/#get-all-valid-channel-access-token-key-ids-v2-1
          # @return [Array(Line::Bot::V2::ChannelAccessToken::ChannelAccessTokenKeyIdsResponse, Integer, Hash{String => String})] when HTTP status code is 200
          # @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
          def gets_all_valid_channel_access_token_key_ids_with_http_info( # steep:ignore MethodBodyTypeMismatch 
            client_assertion_type:, 
            client_assertion:
          )
            path = "/oauth2/v2.1/tokens/kid"
            query_params = {
              "client_assertion_type": client_assertion_type,
              "client_assertion": client_assertion
            }.compact

            response = @http_client.get(
              path: path,
              query_params: query_params,
            )

            case response.code.to_i
            when 200
              json = Line::Bot::V2::Utils.deep_underscore(JSON.parse(response.body))
              json.transform_keys! do |key|
                Line::Bot::V2::RESERVED_WORDS.include?(key) ? "_#{key}".to_sym : key
              end
              response_body = Line::Bot::V2::ChannelAccessToken::ChannelAccessTokenKeyIdsResponse.create(json) # steep:ignore InsufficientKeywordArguments
              [response_body, 200, response.each_header.to_h]
            else
              [response.body, response.code.to_i, response.each_header.to_h]
            end
          end

          # Gets all valid channel access token key IDs.
          # This requests to <code>GET https://api.line.me/oauth2/v2.1/tokens/kid</code>
          # When you want to get HTTP status code or response headers, use {#gets_all_valid_channel_access_token_key_ids_with_http_info} instead of this.
          #
          # @param client_assertion_type [String] `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
          # @param client_assertion [String] A JSON Web Token (JWT) (opens new window)the client needs to create and sign with the private key.
          # @see https://developers.line.biz/en/reference/messaging-api/#get-all-valid-channel-access-token-key-ids-v2-1
          # @return [Line::Bot::V2::ChannelAccessToken::ChannelAccessTokenKeyIdsResponse] when HTTP status code is 200
          # @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
          def gets_all_valid_channel_access_token_key_ids(
            client_assertion_type:,
            client_assertion:
          )
            response_body, _status_code, _headers = gets_all_valid_channel_access_token_key_ids_with_http_info(
              client_assertion_type: client_assertion_type,
              client_assertion: client_assertion
            )

            response_body
          end

          # Issue short-lived channel access token
          # This requests to <code>POST https://api.line.me/v2/oauth/accessToken</code>
          # This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
          #
          # @param grant_type [String] `client_credentials`
          # @param client_id [String] Channel ID.
          # @param client_secret [String] Channel secret.
          # @see https://developers.line.biz/en/reference/messaging-api/#issue-shortlived-channel-access-token
          # @return [Array(Line::Bot::V2::ChannelAccessToken::IssueShortLivedChannelAccessTokenResponse, Integer, Hash{String => String})] when HTTP status code is 200
          # @return [Array(Line::Bot::V2::ChannelAccessToken::ErrorResponse, Integer, Hash{String => String})] when HTTP status code is 400
          # @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
          def issue_channel_token_with_http_info( # steep:ignore MethodBodyTypeMismatch 
            grant_type:, 
            client_id:, 
            client_secret:
          )
            path = "/v2/oauth/accessToken"

            form_params = {
              "grant_type": grant_type,
              "client_id": client_id,
              "client_secret": client_secret
            }.compact

            response = @http_client.post_form(
              path: path,
              form_params: form_params,
            )

            case response.code.to_i
            when 200
              json = Line::Bot::V2::Utils.deep_underscore(JSON.parse(response.body))
              json.transform_keys! do |key|
                Line::Bot::V2::RESERVED_WORDS.include?(key) ? "_#{key}".to_sym : key
              end
              response_body = Line::Bot::V2::ChannelAccessToken::IssueShortLivedChannelAccessTokenResponse.create(json) # steep:ignore InsufficientKeywordArguments
              [response_body, 200, response.each_header.to_h]
            when 400
              json = Line::Bot::V2::Utils.deep_underscore(JSON.parse(response.body))
              json.transform_keys! do |key|
                Line::Bot::V2::RESERVED_WORDS.include?(key) ? "_#{key}".to_sym : key
              end
              response_body = Line::Bot::V2::ChannelAccessToken::ErrorResponse.create(json) # steep:ignore InsufficientKeywordArguments
              [response_body, 400, response.each_header.to_h]
            else
              [response.body, response.code.to_i, response.each_header.to_h]
            end
          end

          # Issue short-lived channel access token
          # This requests to <code>POST https://api.line.me/v2/oauth/accessToken</code>
          # When you want to get HTTP status code or response headers, use {#issue_channel_token_with_http_info} instead of this.
          #
          # @param grant_type [String] `client_credentials`
          # @param client_id [String] Channel ID.
          # @param client_secret [String] Channel secret.
          # @see https://developers.line.biz/en/reference/messaging-api/#issue-shortlived-channel-access-token
          # @return [Line::Bot::V2::ChannelAccessToken::IssueShortLivedChannelAccessTokenResponse] when HTTP status code is 200
          # @return [Line::Bot::V2::ChannelAccessToken::ErrorResponse] when HTTP status code is 400
          # @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
          def issue_channel_token(
            grant_type:,
            client_id:,
            client_secret:
          )
            response_body, _status_code, _headers = issue_channel_token_with_http_info(
              grant_type: grant_type,
              client_id: client_id,
              client_secret: client_secret
            )

            response_body
          end

          # Issues a channel access token that allows you to specify a desired expiration date. This method lets you use JWT assertion for authentication.
          # This requests to <code>POST https://api.line.me/oauth2/v2.1/token</code>
          # This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
          #
          # @param grant_type [String] client_credentials
          # @param client_assertion_type [String] urn:ietf:params:oauth:client-assertion-type:jwt-bearer
          # @param client_assertion [String] A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
          # @see https://developers.line.biz/en/reference/messaging-api/#issue-channel-access-token-v2-1
          # @return [Array(Line::Bot::V2::ChannelAccessToken::IssueChannelAccessTokenResponse, Integer, Hash{String => String})] when HTTP status code is 200
          # @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
          def issue_channel_token_by_jwt_with_http_info( # steep:ignore MethodBodyTypeMismatch 
            grant_type:, 
            client_assertion_type:, 
            client_assertion:
          )
            path = "/oauth2/v2.1/token"

            form_params = {
              "grant_type": grant_type,
              "client_assertion_type": client_assertion_type,
              "client_assertion": client_assertion
            }.compact

            response = @http_client.post_form(
              path: path,
              form_params: form_params,
            )

            case response.code.to_i
            when 200
              json = Line::Bot::V2::Utils.deep_underscore(JSON.parse(response.body))
              json.transform_keys! do |key|
                Line::Bot::V2::RESERVED_WORDS.include?(key) ? "_#{key}".to_sym : key
              end
              response_body = Line::Bot::V2::ChannelAccessToken::IssueChannelAccessTokenResponse.create(json) # steep:ignore InsufficientKeywordArguments
              [response_body, 200, response.each_header.to_h]
            else
              [response.body, response.code.to_i, response.each_header.to_h]
            end
          end

          # Issues a channel access token that allows you to specify a desired expiration date. This method lets you use JWT assertion for authentication.
          # This requests to <code>POST https://api.line.me/oauth2/v2.1/token</code>
          # When you want to get HTTP status code or response headers, use {#issue_channel_token_by_jwt_with_http_info} instead of this.
          #
          # @param grant_type [String] client_credentials
          # @param client_assertion_type [String] urn:ietf:params:oauth:client-assertion-type:jwt-bearer
          # @param client_assertion [String] A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
          # @see https://developers.line.biz/en/reference/messaging-api/#issue-channel-access-token-v2-1
          # @return [Line::Bot::V2::ChannelAccessToken::IssueChannelAccessTokenResponse] when HTTP status code is 200
          # @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
          def issue_channel_token_by_jwt(
            grant_type:,
            client_assertion_type:,
            client_assertion:
          )
            response_body, _status_code, _headers = issue_channel_token_by_jwt_with_http_info(
              grant_type: grant_type,
              client_assertion_type: client_assertion_type,
              client_assertion: client_assertion
            )

            response_body
          end

          # Issues a new stateless channel access token, which doesn't have max active token limit unlike the other token types. The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires. 
          # This requests to <code>POST https://api.line.me/oauth2/v3/token</code>
          # This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
          #
          # @param grant_type [String, nil] `client_credentials`
          # @param client_assertion_type [String, nil] URL-encoded value of `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
          # @param client_assertion [String, nil] A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
          # @param client_id [String, nil] Channel ID.
          # @param client_secret [String, nil] Channel secret.
          # @see https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token
          # @return [Array(Line::Bot::V2::ChannelAccessToken::IssueStatelessChannelAccessTokenResponse, Integer, Hash{String => String})] when HTTP status code is 200
          # @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
          def issue_stateless_channel_token_with_http_info( # steep:ignore MethodBodyTypeMismatch 
            grant_type: nil, 
            client_assertion_type: nil, 
            client_assertion: nil, 
            client_id: nil, 
            client_secret: nil
          )
            path = "/oauth2/v3/token"

            form_params = {
              "grant_type": grant_type,
              "client_assertion_type": client_assertion_type,
              "client_assertion": client_assertion,
              "client_id": client_id,
              "client_secret": client_secret
            }.compact

            response = @http_client.post_form(
              path: path,
              form_params: form_params,
            )

            case response.code.to_i
            when 200
              json = Line::Bot::V2::Utils.deep_underscore(JSON.parse(response.body))
              json.transform_keys! do |key|
                Line::Bot::V2::RESERVED_WORDS.include?(key) ? "_#{key}".to_sym : key
              end
              response_body = Line::Bot::V2::ChannelAccessToken::IssueStatelessChannelAccessTokenResponse.create(json) # steep:ignore InsufficientKeywordArguments
              [response_body, 200, response.each_header.to_h]
            else
              [response.body, response.code.to_i, response.each_header.to_h]
            end
          end

          # Issues a new stateless channel access token, which doesn't have max active token limit unlike the other token types. The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires. 
          # This requests to <code>POST https://api.line.me/oauth2/v3/token</code>
          # When you want to get HTTP status code or response headers, use {#issue_stateless_channel_token_with_http_info} instead of this.
          #
          # @param grant_type [String, nil] `client_credentials`
          # @param client_assertion_type [String, nil] URL-encoded value of `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
          # @param client_assertion [String, nil] A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
          # @param client_id [String, nil] Channel ID.
          # @param client_secret [String, nil] Channel secret.
          # @see https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token
          # @return [Line::Bot::V2::ChannelAccessToken::IssueStatelessChannelAccessTokenResponse] when HTTP status code is 200
          # @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
          def issue_stateless_channel_token(
            grant_type: nil,
            client_assertion_type: nil,
            client_assertion: nil,
            client_id: nil,
            client_secret: nil
          )
            response_body, _status_code, _headers = issue_stateless_channel_token_with_http_info(
              grant_type: grant_type,
              client_assertion_type: client_assertion_type,
              client_assertion: client_assertion,
              client_id: client_id,
              client_secret: client_secret
            )

            response_body
          end

          # Revoke short-lived or long-lived channel access token
          # This requests to <code>POST https://api.line.me/v2/oauth/revoke</code>
          # This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
          #
          # @param access_token [String] Channel access token
          # @see https://developers.line.biz/en/reference/messaging-api/#revoke-longlived-or-shortlived-channel-access-token
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 200
          # @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
          def revoke_channel_token_with_http_info( # steep:ignore MethodBodyTypeMismatch 
            access_token:
          )
            path = "/v2/oauth/revoke"

            form_params = {
              "access_token": access_token
            }.compact

            response = @http_client.post_form(
              path: path,
              form_params: form_params,
            )

            case response.code.to_i
            when 200
              [response.body, 200, response.each_header.to_h]
            else
              [response.body, response.code.to_i, response.each_header.to_h]
            end
          end

          # Revoke short-lived or long-lived channel access token
          # This requests to <code>POST https://api.line.me/v2/oauth/revoke</code>
          # When you want to get HTTP status code or response headers, use {#revoke_channel_token_with_http_info} instead of this.
          #
          # @param access_token [String] Channel access token
          # @see https://developers.line.biz/en/reference/messaging-api/#revoke-longlived-or-shortlived-channel-access-token
          # @return [String, nil] when HTTP status code is 200
          # @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
          def revoke_channel_token(
            access_token:
          )
            response_body, _status_code, _headers = revoke_channel_token_with_http_info(
              access_token: access_token
            )

            response_body
          end

          # Revoke channel access token v2.1
          # This requests to <code>POST https://api.line.me/oauth2/v2.1/revoke</code>
          # This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
          #
          # @param client_id [String] Channel ID
          # @param client_secret [String] Channel Secret
          # @param access_token [String] Channel access token
          # @see https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token-v2-1
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 200
          # @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
          def revoke_channel_token_by_jwt_with_http_info( # steep:ignore MethodBodyTypeMismatch 
            client_id:, 
            client_secret:, 
            access_token:
          )
            path = "/oauth2/v2.1/revoke"

            form_params = {
              "client_id": client_id,
              "client_secret": client_secret,
              "access_token": access_token
            }.compact

            response = @http_client.post_form(
              path: path,
              form_params: form_params,
            )

            case response.code.to_i
            when 200
              [response.body, 200, response.each_header.to_h]
            else
              [response.body, response.code.to_i, response.each_header.to_h]
            end
          end

          # Revoke channel access token v2.1
          # This requests to <code>POST https://api.line.me/oauth2/v2.1/revoke</code>
          # When you want to get HTTP status code or response headers, use {#revoke_channel_token_by_jwt_with_http_info} instead of this.
          #
          # @param client_id [String] Channel ID
          # @param client_secret [String] Channel Secret
          # @param access_token [String] Channel access token
          # @see https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token-v2-1
          # @return [String, nil] when HTTP status code is 200
          # @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
          def revoke_channel_token_by_jwt(
            client_id:,
            client_secret:,
            access_token:
          )
            response_body, _status_code, _headers = revoke_channel_token_by_jwt_with_http_info(
              client_id: client_id,
              client_secret: client_secret,
              access_token: access_token
            )

            response_body
          end

          # Verify the validity of short-lived and long-lived channel access tokens
          # This requests to <code>POST https://api.line.me/v2/oauth/verify</code>
          # This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
          #
          # @param access_token [String] A short-lived or long-lived channel access token.
          # @see https://developers.line.biz/en/reference/messaging-api/#verify-channel-access-token
          # @return [Array(Line::Bot::V2::ChannelAccessToken::VerifyChannelAccessTokenResponse, Integer, Hash{String => String})] when HTTP status code is 200
          # @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
          def verify_channel_token_with_http_info( # steep:ignore MethodBodyTypeMismatch 
            access_token:
          )
            path = "/v2/oauth/verify"

            form_params = {
              "access_token": access_token
            }.compact

            response = @http_client.post_form(
              path: path,
              form_params: form_params,
            )

            case response.code.to_i
            when 200
              json = Line::Bot::V2::Utils.deep_underscore(JSON.parse(response.body))
              json.transform_keys! do |key|
                Line::Bot::V2::RESERVED_WORDS.include?(key) ? "_#{key}".to_sym : key
              end
              response_body = Line::Bot::V2::ChannelAccessToken::VerifyChannelAccessTokenResponse.create(json) # steep:ignore InsufficientKeywordArguments
              [response_body, 200, response.each_header.to_h]
            else
              [response.body, response.code.to_i, response.each_header.to_h]
            end
          end

          # Verify the validity of short-lived and long-lived channel access tokens
          # This requests to <code>POST https://api.line.me/v2/oauth/verify</code>
          # When you want to get HTTP status code or response headers, use {#verify_channel_token_with_http_info} instead of this.
          #
          # @param access_token [String] A short-lived or long-lived channel access token.
          # @see https://developers.line.biz/en/reference/messaging-api/#verify-channel-access-token
          # @return [Line::Bot::V2::ChannelAccessToken::VerifyChannelAccessTokenResponse] when HTTP status code is 200
          # @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
          def verify_channel_token(
            access_token:
          )
            response_body, _status_code, _headers = verify_channel_token_with_http_info(
              access_token: access_token
            )

            response_body
          end

          # You can verify whether a Channel access token with a user-specified expiration (Channel Access Token v2.1) is valid.
          # This requests to <code>GET https://api.line.me/oauth2/v2.1/verify</code>
          # This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
          #
          # @param access_token [String] Channel access token with a user-specified expiration (Channel Access Token v2.1).
          # @see https://developers.line.biz/en/reference/messaging-api/#verify-channel-access-token-v2-1
          # @return [Array(Line::Bot::V2::ChannelAccessToken::VerifyChannelAccessTokenResponse, Integer, Hash{String => String})] when HTTP status code is 200
          # @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
          def verify_channel_token_by_jwt_with_http_info( # steep:ignore MethodBodyTypeMismatch 
            access_token:
          )
            path = "/oauth2/v2.1/verify"
            query_params = {
              "access_token": access_token
            }.compact

            response = @http_client.get(
              path: path,
              query_params: query_params,
            )

            case response.code.to_i
            when 200
              json = Line::Bot::V2::Utils.deep_underscore(JSON.parse(response.body))
              json.transform_keys! do |key|
                Line::Bot::V2::RESERVED_WORDS.include?(key) ? "_#{key}".to_sym : key
              end
              response_body = Line::Bot::V2::ChannelAccessToken::VerifyChannelAccessTokenResponse.create(json) # steep:ignore InsufficientKeywordArguments
              [response_body, 200, response.each_header.to_h]
            else
              [response.body, response.code.to_i, response.each_header.to_h]
            end
          end

          # You can verify whether a Channel access token with a user-specified expiration (Channel Access Token v2.1) is valid.
          # This requests to <code>GET https://api.line.me/oauth2/v2.1/verify</code>
          # When you want to get HTTP status code or response headers, use {#verify_channel_token_by_jwt_with_http_info} instead of this.
          #
          # @param access_token [String] Channel access token with a user-specified expiration (Channel Access Token v2.1).
          # @see https://developers.line.biz/en/reference/messaging-api/#verify-channel-access-token-v2-1
          # @return [Line::Bot::V2::ChannelAccessToken::VerifyChannelAccessTokenResponse] when HTTP status code is 200
          # @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
          def verify_channel_token_by_jwt(
            access_token:
          )
            response_body, _status_code, _headers = verify_channel_token_by_jwt_with_http_info(
              access_token: access_token
            )

            response_body
          end
        end
      end
    end
  end
end
