lib/wolf_core/application/integrations/client_api_operations.rb



module WolfCore
  module Integrations
    module ClientApiOperations
      include WolfCore::HttpOperations

      def fetch_client!(wolf_token:, client_id:, tenant:, wolf_platform_url:, error_message:)
        response = safe_http_get(
          headers: { "Authorization" => "Bearer #{wolf_token}" },
          url: "#{wolf_platform_url}/api/v2/companies/#{client_id}",
          query: { tenant: tenant },
          error_message: error_message
        )
        response_body = response.body
        response_body.dig("data", "table", "company")
      end

      def fetch_client(wolf_token:, client_id:, tenant:, wolf_platform_url:)
        parsed_http_get(
          headers: { "Authorization" => "Bearer #{wolf_token}" },
          url: "#{wolf_platform_url}/api/v2/companies/#{client_id}",
          query: { tenant: tenant }
        )
      end

      def create_client!(wolf_token:, client:, tenant:, wolf_platform_url:, error_message:)
        safe_http_post(
          headers: { "Authorization" => "Bearer #{wolf_token}" },
          query: { tenant: tenant },
          url: "#{wolf_platform_url}/api/v2/companies",
          body: client,
          error_message: error_message
        )
      end

      def create_client(wolf_token:, client:, tenant:, wolf_platform_url:)
        parsed_http_post(
          headers: { "Authorization" => "Bearer #{wolf_token}" },
          query: { tenant: tenant },
          url: "#{wolf_platform_url}/api/v2/companies",
          body: client
        )
      end

      def update_client!(wolf_token:, client:, tenant:, wolf_platform_url:, error_message:, client_id:)
        safe_http_put(
          headers: { "Authorization" => "Bearer #{wolf_token}" },
          query: { tenant: tenant },
          url: "#{wolf_platform_url}/api/v2/companies/#{client_id}",
          body: client,
          error_message: error_message
        )
      end

      def update_client(wolf_token:, client:, tenant:, wolf_platform_url:, client_id:)
        parsed_http_put(
          headers: { "Authorization" => "Bearer #{wolf_token}" },
          query: { tenant: tenant },
          url: "#{wolf_platform_url}/api/v2/companies/#{client_id}",
          body: client
        )
      end
    end
  end
end