import { z } from "zod";

export const platformSettingsSchema = z.object({
  appName: z
    .string()
    .trim()
    .min(1, "Application name is required.")
    .max(100, "Application name cannot exceed 100 characters."),

  email: z
    .string()
    .trim()
    .min(1, "Please enter your email address")
    .email("Please enter a valid email address (e.g. john@example.com)")
    .refine((email) => {
      const [, domain] = email.split("@");

      if (!domain) return false;

      const labels = domain.split(".");

      return labels.every(
        (label) =>
          label.length > 0 && !label.startsWith("-") && !label.endsWith("-"),
      );
    }, "Please enter a valid email address (e.g. john@example.com)"),

  mobileNumber: z.object({
    dialCode: z.string().min(1, "Dial code is required"),
    number: z
      .string()
      .min(10, "Mobile number cannot be less than 10 digits")
      .max(15, "Mobile number cannot be more than 15 digits"),
  }),

  currency: z
    .string()
    .trim()
    .min(1, "Currency is required.")
    .length(
      3,
      "Currency must be a valid 3-letter ISO code (e.g. USD, INR, EUR).",
    )
    .transform((value) => value.toUpperCase()),
});

export type PlatformSettingsFormValues = z.infer<typeof platformSettingsSchema>;
