import { z } from "zod";

export const registerSchema = z
  .object({
    nickname: z.string().min(2).max(20),
    name: z.string().min(1).max(50),
    phone: z
      .string()
      .regex(/^[0-9\-+]{9,15}$/)
      .transform((s) => s.replace(/[^0-9]/g, "")),
    birth: z
      .string()
      .refine((s) => !Number.isNaN(Date.parse(s)), { message: "Invalid date" }),
    password: z.string().min(8).max(100),
    confirmPassword: z.string().min(8).max(100),
    agreeTerms: z.literal(true, { errorMap: () => ({ message: "약관 동의 필요" }) }),
  })
  .refine((d) => d.password === d.confirmPassword, {
    message: "비밀번호가 일치하지 않습니다",
    path: ["confirmPassword"],
  });

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

export const loginSchema = z.object({
  nickname: z.string().min(2).max(20),
  password: z.string().min(8).max(100),
});

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


