import { t } from "i18next";
import { z } from "zod";

export const sendLetterSchema = z.object({
  fileInfo: z.object({
    fileName: z.string(),
    contentType: z.string(),
    size: z.number(),
    originalname: z.string(),
  }),
  receiverPositions: z.array(z.string()),
  receiverEmployeePositions: z.array(z.string()),
  preferredLanguage: z.enum(["am", "en"]),
  subject: z.string().min(1, { message: t("msg.subjectRequired") }),
  letterNumber: z.string().min(1, { message: t("msg.letterNoRequired") }),
  deliveredBy: z.string().min(1, { message: t("msg.deliveredByRequired") }),
  letterName: z.string().min(1, { message: t("msg.fileNameRequired") }),
  organizationName: z.object({
    am: z.string(),
    en: z.string(),
  }),
});

export type SendLetterFormValues = z.infer<typeof sendLetterSchema>;

export const editLetterSchema = z.object({
  fileInfo: z
    .object({
      fileName: z.string(),
      contentType: z.string(),
      size: z.number(),
      originalname: z.string(),
    })
    .optional(), // ✅ allow edit without providing file

  receiverPositions: z.array(z.string()).optional(),
  receiverEmployeePositions: z.array(z.string()).optional(),
  preferredLanguage: z.enum(["am", "en"]),
  subject: z.string().min(1, { message: t("msg.subjectRequired") }),
  letterNumber: z.string().min(1, { message: t("msg.letterNoRequired") }),
  deliveredBy: z.string().min(1, { message: t("msg.deliveredByRequired") }),
  letterName: z.string().min(1, { message: t("msg.fileNameRequired") }),
  organizationName: z.object({
    am: z.string(),
    en: z.string(),
  }),
});

export type EditLetterFormValues = z.infer<typeof editLetterSchema>;

export const defaultSendLetterValues: SendLetterFormValues = {
  fileInfo: {
    fileName: "",
    contentType: "",
    size: 0,
    originalname: "",
  },
  subject: "",
  receiverPositions: [],
  receiverEmployeePositions: [],
  letterNumber: "",
  organizationName: {
    am: "",
    en: "",
  },
  deliveredBy: "",
  preferredLanguage: "en",
  letterName: "",
};
