# LIFF server API
# LIFF Server API.
#
# The version of the OpenAPI document: 1.0.0
#
# 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 Liff
        class ApiClient
          # Initializes a new {Line::Bot::V2::Liff::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 channel_access_token [String] The channel access token for authorization.
          # @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::Liff::ApiClient.new(
          #     channel_access_token: "YOUR_CHANNEL_ACCESS_TOKEN",
          #     http_options: {
          #       open_timeout: 5,
          #       read_timeout: 5,
          #     }
          #   )
          def initialize(base_url: nil, channel_access_token:, http_options: {})
            @http_client = HttpClient.new(
              base_url: base_url || 'https://api.line.me',
              http_headers: {
                Authorization: "Bearer #{channel_access_token}"
              },
              http_options: http_options
            )
          end

          # Adding the LIFF app to a channel
          # This requests to <code>POST https://api.line.me/liff/v1/apps</code>
          # This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
          #
          # @param add_liff_app_request [AddLiffAppRequest] 
          # @see https://developers.line.biz/en/reference/liff-server/#add-liff-app
          # @return [Array(Line::Bot::V2::Liff::AddLiffAppResponse, Integer, Hash{String => String})] when HTTP status code is 200
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 400
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 401
          # @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
          def add_liff_app_with_http_info( # steep:ignore MethodBodyTypeMismatch 
            add_liff_app_request:
          )
            path = "/liff/v1/apps"

            response = @http_client.post(
              path: path,
              body_params: add_liff_app_request,
            )

            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::Liff::AddLiffAppResponse.create(json) # steep:ignore InsufficientKeywordArguments
              [response_body, 200, response.each_header.to_h]
            when 400
              [response.body, 400, response.each_header.to_h]
            when 401
              [response.body, 401, response.each_header.to_h]
            else
              [response.body, response.code.to_i, response.each_header.to_h]
            end
          end

          # Adding the LIFF app to a channel
          # This requests to <code>POST https://api.line.me/liff/v1/apps</code>
          # When you want to get HTTP status code or response headers, use {#add_liff_app_with_http_info} instead of this.
          #
          # @param add_liff_app_request [AddLiffAppRequest] 
          # @see https://developers.line.biz/en/reference/liff-server/#add-liff-app
          # @return [Line::Bot::V2::Liff::AddLiffAppResponse] when HTTP status code is 200
          # @return [String, nil] when HTTP status code is 400
          # @return [String, nil] when HTTP status code is 401
          # @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
          def add_liff_app(
            add_liff_app_request:
          )
            response_body, _status_code, _headers = add_liff_app_with_http_info(
              add_liff_app_request: add_liff_app_request
            )

            response_body
          end

          # Deletes a LIFF app from a channel. 
          # This requests to <code>DELETE https://api.line.me/liff/v1/apps/{liffId}</code>
          # This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
          #
          # @param liff_id [String] ID of the LIFF app to be updated
          # @see https://developers.line.biz/en/reference/liff-server/#delete-liff-app
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 200
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 401
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 404
          # @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
          def delete_liff_app_with_http_info( # steep:ignore MethodBodyTypeMismatch 
            liff_id:
          )
            path = "/liff/v1/apps/{liffId}"
              .gsub(/{liffId}/, liff_id.to_s)

            response = @http_client.delete(
              path: path,
            )

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

          # Deletes a LIFF app from a channel. 
          # This requests to <code>DELETE https://api.line.me/liff/v1/apps/{liffId}</code>
          # When you want to get HTTP status code or response headers, use {#delete_liff_app_with_http_info} instead of this.
          #
          # @param liff_id [String] ID of the LIFF app to be updated
          # @see https://developers.line.biz/en/reference/liff-server/#delete-liff-app
          # @return [String, nil] when HTTP status code is 200
          # @return [String, nil] when HTTP status code is 401
          # @return [String, nil] when HTTP status code is 404
          # @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
          def delete_liff_app(
            liff_id:
          )
            response_body, _status_code, _headers = delete_liff_app_with_http_info(
              liff_id: liff_id
            )

            response_body
          end

          # Gets information on all the LIFF apps added to the channel.
          # This requests to <code>GET https://api.line.me/liff/v1/apps</code>
          # This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
          #
          # @see https://developers.line.biz/en/reference/liff-server/#get-all-liff-apps
          # @return [Array(Line::Bot::V2::Liff::GetAllLiffAppsResponse, Integer, Hash{String => String})] when HTTP status code is 200
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 401
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 404
          # @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
          def get_all_liff_apps_with_http_info( # steep:ignore MethodBodyTypeMismatch
          )
            path = "/liff/v1/apps"

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

            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::Liff::GetAllLiffAppsResponse.create(json) # steep:ignore InsufficientKeywordArguments
              [response_body, 200, response.each_header.to_h]
            when 401
              [response.body, 401, response.each_header.to_h]
            when 404
              [response.body, 404, response.each_header.to_h]
            else
              [response.body, response.code.to_i, response.each_header.to_h]
            end
          end

          # Gets information on all the LIFF apps added to the channel.
          # This requests to <code>GET https://api.line.me/liff/v1/apps</code>
          # When you want to get HTTP status code or response headers, use {#get_all_liff_apps_with_http_info} instead of this.
          #
          # @see https://developers.line.biz/en/reference/liff-server/#get-all-liff-apps
          # @return [Line::Bot::V2::Liff::GetAllLiffAppsResponse] when HTTP status code is 200
          # @return [String, nil] when HTTP status code is 401
          # @return [String, nil] when HTTP status code is 404
          # @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
          def get_all_liff_apps(
          )
            response_body, _status_code, _headers = get_all_liff_apps_with_http_info(
            )

            response_body
          end

          # Update LIFF app settings
          # This requests to <code>PUT https://api.line.me/liff/v1/apps/{liffId}</code>
          # This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.
          #
          # @param liff_id [String] ID of the LIFF app to be updated
          # @param update_liff_app_request [UpdateLiffAppRequest] 
          # @see https://developers.line.biz/en/reference/liff-server/#update-liff-app
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 200
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 400
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 401
          # @return [Array((String|nil), Integer, Hash{String => String})] when HTTP status code is 404
          # @return [Array((String|nil), Integer, Hash{String => String})] when other HTTP status code is returned. String is HTTP response body itself.
          def update_liff_app_with_http_info( # steep:ignore MethodBodyTypeMismatch 
            liff_id:, 
            update_liff_app_request:
          )
            path = "/liff/v1/apps/{liffId}"
              .gsub(/{liffId}/, liff_id.to_s)

            response = @http_client.put(
              path: path,
              body_params: update_liff_app_request,
            )

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

          # Update LIFF app settings
          # This requests to <code>PUT https://api.line.me/liff/v1/apps/{liffId}</code>
          # When you want to get HTTP status code or response headers, use {#update_liff_app_with_http_info} instead of this.
          #
          # @param liff_id [String] ID of the LIFF app to be updated
          # @param update_liff_app_request [UpdateLiffAppRequest] 
          # @see https://developers.line.biz/en/reference/liff-server/#update-liff-app
          # @return [String, nil] when HTTP status code is 200
          # @return [String, nil] when HTTP status code is 400
          # @return [String, nil] when HTTP status code is 401
          # @return [String, nil] when HTTP status code is 404
          # @return [String, nil] when other HTTP status code is returned. This String is HTTP response body itself.
          def update_liff_app(
            liff_id:,
            update_liff_app_request:
          )
            response_body, _status_code, _headers = update_liff_app_with_http_info(
              liff_id: liff_id,
              update_liff_app_request: update_liff_app_request
            )

            response_body
          end
        end
      end
    end
  end
end
