import { objectId } from '@jig-software/zod-bson';
import { z } from 'zod';

export const Config = z.object({
  _id: objectId(),
  clientId: z.string(),
  publicKey: z.string(),
  privateKey: z.string(),
  cookieSecret: z.string(),
  setCookiesToken: z.boolean(),
  acceptRegistration: z.boolean(),
  acceptedHosts: z.array(z.string()),
  autoActivateUser: z.boolean(),
  emailServer: z
    .object({
      host: z.string(),
      port: z.number(),
      secure: z.boolean(),
      auth: z.object({
        user: z.string(),
        pass: z.string(),
      }),
      tls: z
        .object({
          serverName: z.string(),
          rejectUnauthorized: z.boolean(),
        })
        .partial()
        .optional(),
    })
    .optional(),
  totpLifeTime: z.number(),
  passwordRequirements: z
    .object({
      forbidOldPassword: z.number(),
      minimumLength: z.number(),
      shouldContainCapitalLetters: z.boolean(),
      shouldContainSmallLetters: z.boolean(),
      shouldContainNumbers: z.boolean(),
      shouldContainSpecialCharacters: z.boolean(),
      maxAge: z.number(),
    })
    .partial()
    .optional(),
  lockPeriods: z.array(z.number()),
});
export type Config = z.infer<typeof Config>;
