import { z } from 'zod';

export const notificationEmailJobSchema = z.object({
  type: z.enum(['email_verification', 'password_reset']),
  to: z.string().email(),
  subject: z.string(),
  template: z.string(),
  data: z.record(z.unknown()),
});

export type NotificationEmailJob = z.infer<typeof notificationEmailJobSchema>;

const smtpConfigSchema = z.object({
  SMTP_HOST: z.string().min(1).default('localhost'),
  SMTP_PORT: z.coerce.number().int().default(1025),
  SMTP_USER: z.string().optional(),
  SMTP_PASSWORD: z.string().optional(),
  SMTP_FROM: z.string().default('noreply@localhost'),
  SMTP_TLS: z
    .string()
    .optional()
    .transform((v) => v === 'true' || v === '1'),
  APP_NAME: z.string().default('HexaHost GameCloud'),
});

export type SmtpConfig = z.infer<typeof smtpConfigSchema>;

export function getSmtpConfig(): SmtpConfig {
  return smtpConfigSchema.parse({
    SMTP_HOST: process.env['SMTP_HOST'],
    SMTP_PORT: process.env['SMTP_PORT'],
    SMTP_USER: process.env['SMTP_USER'],
    SMTP_PASSWORD: process.env['SMTP_PASSWORD'],
    SMTP_FROM: process.env['SMTP_FROM'],
    SMTP_TLS: process.env['SMTP_TLS'],
    APP_NAME: process.env['APP_NAME'],
  });
}
