/**
 * Platform OAuth Settings API
 */

import apiClient from './client';

export interface OAuthProviderConfig {
  enabled: boolean;
  client_id: string;
  client_secret: string;
  // Apple-specific fields
  team_id?: string;
  key_id?: string;
  // Microsoft-specific field
  tenant_id?: string;
}

export interface PlatformOAuthSettings {
  // Global setting
  oauth_allow_registration: boolean;

  // Provider configurations
  google: OAuthProviderConfig;
  apple: OAuthProviderConfig;
  facebook: OAuthProviderConfig;
  linkedin: OAuthProviderConfig;
  microsoft: OAuthProviderConfig;
  twitter: OAuthProviderConfig;
  twitch: OAuthProviderConfig;
}

export interface PlatformOAuthSettingsUpdate {
  oauth_allow_registration?: boolean;

  // Google
  oauth_google_enabled?: boolean;
  oauth_google_client_id?: string;
  oauth_google_client_secret?: string;

  // Apple
  oauth_apple_enabled?: boolean;
  oauth_apple_client_id?: string;
  oauth_apple_client_secret?: string;
  oauth_apple_team_id?: string;
  oauth_apple_key_id?: string;

  // Facebook
  oauth_facebook_enabled?: boolean;
  oauth_facebook_client_id?: string;
  oauth_facebook_client_secret?: string;

  // LinkedIn
  oauth_linkedin_enabled?: boolean;
  oauth_linkedin_client_id?: string;
  oauth_linkedin_client_secret?: string;

  // Microsoft
  oauth_microsoft_enabled?: boolean;
  oauth_microsoft_client_id?: string;
  oauth_microsoft_client_secret?: string;
  oauth_microsoft_tenant_id?: string;

  // Twitter (X)
  oauth_twitter_enabled?: boolean;
  oauth_twitter_client_id?: string;
  oauth_twitter_client_secret?: string;

  // Twitch
  oauth_twitch_enabled?: boolean;
  oauth_twitch_client_id?: string;
  oauth_twitch_client_secret?: string;
}

/**
 * Get platform OAuth settings
 */
export const getPlatformOAuthSettings = async (): Promise<PlatformOAuthSettings> => {
  const { data } = await apiClient.get('/api/platform/settings/oauth/');
  return data;
};

/**
 * Update platform OAuth settings
 */
export const updatePlatformOAuthSettings = async (
  settings: PlatformOAuthSettingsUpdate
): Promise<PlatformOAuthSettings> => {
  const { data } = await apiClient.post('/api/platform/settings/oauth/', settings);
  return data;
};
