module WolfCore::Integrations::ClientApiOperations

def create_client(wolf_token:, client:, tenant:, wolf_platform_url:)

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 create_client!(wolf_token:, client:, tenant:, wolf_platform_url:, error_message:)

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 fetch_client(wolf_token:, client_id:, tenant:, wolf_platform_url:)

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 fetch_client!(wolf_token:, client_id:, tenant:, wolf_platform_url:, error_message:)

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 update_client(wolf_token:, client:, tenant:, wolf_platform_url:, client_id:)

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

def update_client!(wolf_token:, client:, tenant:, wolf_platform_url:, error_message:, client_id:)

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