import zod from "zod";

export const SignupSchema = zod.object({
  phoneNumber: zod
    .string()
    .min(1, "请输入手机号")
    .regex(/^1[3-9]\d{9}$/, "请输入正确的手机号码"),

  password: zod
    .string()
    .min(6, "密码至少6位")
    .max(20, "密码最多20位")
    .regex(/^(?=.*[a-z])(?=.*\d).+$/i, "密码必须包含字母和数字"),

  confirmPassword: zod
    .string()
    .min(1, "请确认密码"),

  realName: zod
    .string()
    .min(2, "请输入真实姓名")
    .max(10, "姓名长度不能超过10个字符"),

  idCard: zod
    .string()
    .min(1, "请输入身份证号码")
    .regex(
      /(^\d{15}$)|(^\d{18}$)|(^\d{17}([\dX])$)/i,
      "请输入正确的身份证号码",
    ),

  inviteCode: zod
    .string()
    .optional(),
}).refine(data => data.password === data.confirmPassword, {
  message: "两次输入的密码不一致",
  path: ["confirmPassword"],
});

export const LoginSchema = zod.object({
  phoneNumber: zod
    .string()
    .min(1, "请输入手机号")
    .regex(/^1[3-9]\d{9}$/, "请输入正确的手机号码"),

  password: zod
    .string()
    .min(6, "密码至少6位")
    .max(20, "密码最多20位"),
});
