import { z } from "zod";

const TeamMemberCategoryEnum = z.enum(["Leadership", "Core Team"]);
const TeamMemberStatusEnum = z.enum(["Active", "Inactive"]);

const teamMemberBase = z.object({
  name: z.string().min(1, "Name is required").max(200, "Name is too long"),
  role: z.string().min(1, "Role is required").max(200, "Role is too long"),
  phd: z.string().optional().default(""),
  img: z.string().min(1, "Image URL is required"),
  category: TeamMemberCategoryEnum,
  order: z.number().int().default(0),
  status: TeamMemberStatusEnum.default("Active"),
});

const createTeamMemberSchema = teamMemberBase;
const updateTeamMemberSchema = teamMemberBase.partial();

function normalizeTeamMemberPayload(payload) {
  if (!payload || typeof payload !== "object") {
    return {};
  }
  
  const normalized = { ...payload };
  
  // Ensure order is a number
  if (normalized.order !== undefined) {
    normalized.order = parseInt(normalized.order) || 0;
  }
  
  return normalized;
}

export {
  TeamMemberCategoryEnum,
  TeamMemberStatusEnum,
  createTeamMemberSchema,
  updateTeamMemberSchema,
  normalizeTeamMemberPayload,
};

