import * as yup from "yup";
import { emailField } from "@/lib/validations/email";

export const signupSchema = yup.object({
  name: yup
    .string()
    .required("Full name is required")
    .trim()
    .min(2, "Name must be at least 2 characters")
    .test("no-html", "Name cannot contain HTML or script tags", (value) => !/<[^>]*>/.test(value ?? "")),
  email: emailField(),
  password: yup
    .string()
    .required("Password is required")
    .min(6, "Password must be at least 6 characters"),
  confirmPassword: yup
    .string()
    .required("Please confirm your password")
    .test("match", "Passwords do not match", function (value) {
      return !value || value === this.parent.password;
    }),
  agreeTerms: yup
    .boolean()
    .oneOf([true], "You must accept the Terms of Service and Privacy Policy")
    .required("You must accept the Terms of Service and Privacy Policy"),
});

export type SignupFormData = yup.InferType<typeof signupSchema>;
