import { oauthConfig } from './oauth';
import { isGoogleAuthEnabled, isLinkedInAuthEnabled } from './authOAuth';

export const EMAIL_PROVIDER_PRESETS = {
  platform: {
    label: 'Platform default',
    description: 'Send using the application mail server',
    smtpHost: null as string | null,
    smtpPort: 587,
  },
  gmail: {
    label: 'Gmail / Google Workspace',
    description: 'Use smtp.gmail.com with an app password',
    smtpHost: 'smtp.gmail.com',
    smtpPort: 587,
  },
  outlook: {
    label: 'Microsoft Outlook / Office 365',
    description: 'Use smtp.office365.com with your account',
    smtpHost: 'smtp.office365.com',
    smtpPort: 587,
  },
  yahoo: {
    label: 'Yahoo Mail',
    description: 'Use smtp.mail.yahoo.com with an app password',
    smtpHost: 'smtp.mail.yahoo.com',
    smtpPort: 587,
  },
  sendgrid: {
    label: 'SendGrid',
    description: 'Use smtp.sendgrid.net with an API key as password',
    smtpHost: 'smtp.sendgrid.net',
    smtpPort: 587,
  },
  smtp: {
    label: 'Custom SMTP',
    description: 'Configure your own SMTP server',
    smtpHost: null,
    smtpPort: 587,
  },
} as const;

export type EmailProviderKey = keyof typeof EMAIL_PROVIDER_PRESETS;

export function getPublicAppConfig() {
  return {
    oauth: {
      google: Boolean(oauthConfig.google.clientId),
      microsoft: Boolean(oauthConfig.microsoft.clientId),
    },
    authOAuth: {
      google: isGoogleAuthEnabled(),
      linkedin: isLinkedInAuthEnabled(),
    },
    emailProviders: Object.entries(EMAIL_PROVIDER_PRESETS).map(([id, preset]) => ({
      id,
      label: preset.label,
      description: preset.description,
      smtpHost: preset.smtpHost,
      smtpPort: preset.smtpPort,
    })),
  };
}
