import { z } from "zod/v4";
import { LIMITS } from "@/lib/limits";

export const loginSchema = z.object({
  email: z
    .string()
    .trim()
    .min(1, "Email harus diisi")
    .pipe(z.email("Email tidak valid")),
  password: z
    .string()
    .min(6, "Password minimal 6 karakter")
    .max(LIMITS.MAX_PASSWORD_LENGTH, "Password terlalu panjang"),
});

export const registerSchema = z.object({
  name: z
    .string()
    .trim()
    .min(2, "Nama minimal 2 karakter")
    .max(LIMITS.MAX_NAME_LENGTH, `Nama maksimal ${LIMITS.MAX_NAME_LENGTH} karakter`),
  email: z
    .string()
    .trim()
    .min(1, "Email harus diisi")
    .pipe(z.email("Email tidak valid")),
  password: z
    .string()
    .min(6, "Password minimal 6 karakter")
    .max(LIMITS.MAX_PASSWORD_LENGTH, "Password terlalu panjang (maks. 72 karakter)"),
  confirmPassword: z.string(),
  acceptedTermsAndPrivacy: z.literal(true, {
    error: "Kamu harus menyetujui Syarat & Ketentuan dan Kebijakan Privasi",
  }),
}).refine((data) => data.password === data.confirmPassword, {
  message: "Password tidak cocok",
  path: ["confirmPassword"],
});

export type LoginInput = z.infer<typeof loginSchema>;
export type RegisterInput = z.infer<typeof registerSchema>;
