import moment from "moment-timezone";
import { z } from "zod";

const zodId = z
  .string()
  .refine((value) => /^\d{7,20}$/.test(value), "Invalid ID supplied");
export const zodBigIntId = zodId.transform((value) => BigInt(value));

export const zodTpMessages = z.object({
  enabled: z.boolean(),
  channelId: zodId.nullable(),
  rolesEnabled: z.boolean(),
  isAvailableRoleId: zodId.nullable(),
  wantsToBeNotifieRoledId: zodId.nullable(),
  messageIds: z.object({
    "0": zodId.nullable(),
    "1": zodId.nullable(),
    "2": zodId.nullable(),
    "3": zodId.nullable(),
    "4": zodId.nullable(),
    "5": zodId.nullable(),
    "6": zodId.nullable(),
  }),
});

export const zodMatch = z.object({
  match: z.object({
    channelId: zodId,
    createrId: zodId,
    messageId: zodId,
    roleId: zodId,
    matchType: z.string(),
    opponentName: z.string(),
    utc_ts: z.string().datetime(),
  }),
  timezone: z
    .string()
    .refine(
      (value) => moment.tz.names().includes(value),
      "Unknown timezone supplied",
    ),
});
