import { z } from "zod";

export const createLetterSchema = z.object({
  fileInfo: z.object({
    fileName: z.string(),
    contentType: z.string(),
    size: z.number(),
    originalname: z.string(),
  }),
  subject: z.string().min(1, "Subject is required"),
  letterNumber: z.string().min(1, "Letter number is required"),
  preferredLanguage: z.enum(["am", "en"], {
    required_error: "Preferred language is required",
  }),
});

// 👇 If you want TypeScript types derived from the Zod schema:
export type CreateLetterFormValues = z.infer<typeof createLetterSchema>;

export const createComplaintLetterSchema = z.object({
  fileInfo: z.object({
    fileName: z.string(),
    contentType: z.string(),
    size: z.number(),
    originalname: z.string(),
  }),
  subject: z.string().min(1, "Subject is required"),
  description: z.string().min(1, "Description is required"),
  recipient: z.string().optional(),
  letterNumber: z.string().optional(),
  preferredLanguage: z.enum(["am", "en"], {
    required_error: "Preferred language is required",
  }),
});

export type CreateComplaintLetterFormValues = z.infer<
  typeof createComplaintLetterSchema
>;

export const userSchema = z.object({
  email: z.string().email({ message: "Invalid email address" }),
  username: z
    .string()
    .min(3, { message: "Username must be at least 3 characters" }),
  phoneNumber: z
    .string()
    .min(10, { message: "Phone number must be at least 10 digits" }),
  userType: z.string().min(1, { message: "User type is required" }),
  name: z.object({
    am: z.string().min(1, { message: "Amharic name is required" }),
    en: z.string().min(1, { message: "English name is required" }),
  }),
});

export type UserFormValues = z.infer<typeof userSchema>;

export const defaultCreateLetterValues: CreateLetterFormValues = {
  fileInfo: {
    fileName: "",
    contentType: "",
    size: 0,
    originalname: "",
  },
  subject: "",
  letterNumber: "",
  preferredLanguage: "en",
};

export const defaultCreateComplaintLetterValues: CreateComplaintLetterFormValues =
  {
    fileInfo: {
      fileName: "",
      contentType: "",
      size: 0,
      originalname: "",
    },
    subject: "",
    description: "",
    recipient: "",
    letterNumber: "",
    preferredLanguage: "en",
  };

export const defaultUserValues: UserFormValues = {
  email: "",
  username: "",
  phoneNumber: "",
  userType: "",
  name: {
    am: "",
    en: "",
  },
};
