import { z } from "zod";
import { DEFAULT_EMPTY_STATUS_ID } from "../../utils/constants";
const currentDate = new Date()


export const projectDefault = {
  name: "",
  shortName: "",
  contactPerson: "",
  projectAddress: "",
  startDate: currentDate.toISOString().split("T")[0],
  endDate: currentDate.toISOString().split("T")[0],
  projectStatusId: DEFAULT_EMPTY_STATUS_ID,
  // promoterId: "",
  // pmcId: "",
};


export const projectSchema = z
  .object({
    name: z.string().min(1, { message: "Project Name is required" }),
    shortName: z.string().optional(),
    contactPerson: z
      .string()
      .min(1, { message: "Contact Person Name is required" })
      .regex(/^[A-Za-z\s]+$/, {
        message: "Contact Person must contain only letters",
      }),
    projectAddress: z
      .string()
      .min(1, { message: "Address is required" })
      .max(500, "Address must not exceed 150 characters"),
    startDate: z
      .string()
      .min(1, { message: "Start Date is required" })
      .default(projectDefault),
    endDate: z
      .string()
      .min(1, { message: "End Date is required" })
      .default(projectDefault),
    projectStatusId: z.string().min(1, { message: "Status is required" }),
    // promoterId: z.string().min(1, { message: "Promoter is required" }),
    // pmcId: z.string().min(1, { message: "PMC is required" }),
  })
  .refine(
    (data) => {
      const start = new Date(data.startDate);
      const end = new Date(data.endDate);
      return end >= start;
    },
    {
      path: ["endDate"],
      message: "End Date must be greater than Start Date",
    }
  );




