import api from './api';

export type SetupStatus = {
  requires_setup: boolean;
};

export type SetupInitializePayload = {
  admin_email: string;
  admin_password: string;
  first_name?: string;
  last_name?: string;
  jwt_secret?: string;
  club_id?: string;
  club_type?: string;
  club_name?: string;
  club_logo_url?: string;
  club_url?: string;
  frontpage_style?: 'unified' | 'magazine' | 'pro' | 'edge';
  primary_color?: string;
  secondary_color?: string;
  accent_color?: string;
  background_color?: string;
  text_color?: string;
  font_heading?: string;
  font_body?: string;
  // social & gallery (optional)
  facebook_url?: string;
  instagram_url?: string;
  youtube_url?: string;
  gallery_url?: string;
  gallery_label?: string;
  // location/contact info (optional)
  contact_address?: string;
  contact_city?: string;
  contact_zip?: string;
  contact_country?: string;
  contact_phone?: string;
  contact_email?: string;
  location_latitude?: number;
  location_longitude?: number;
  map_style?: string;
  map_zoom_level?: number;
  smtp?: {
    host?: string;
    port?: number;
    username?: string;
    password?: string;
    from?: string;
    use_tls?: boolean;
  } | null;
};

export const getSetupStatus = async (): Promise<SetupStatus> => {
  const res = await api.get('/setup/status');
  return res.data;
};

export const initializeSetup = async (payload: SetupInitializePayload): Promise<{ message: string }> => {
  const res = await api.post('/setup/initialize', payload, { timeout: 30000 });
  return res.data;
};

export type SMTPValidationPayload = {
  host: string;
  port: number;
  username?: string;
  password?: string;
  from?: string;
  use_tls?: boolean;
};

export const validateSMTP = async (payload: SMTPValidationPayload): Promise<{ ok: boolean; message?: string; error?: string }> => {
  const res = await api.post('/setup/validate-smtp', payload, { timeout: 30000 });
  return res.data;
};
