import { z } from "zod"

const relationFieldSchema = z.object({ value: z.string(), label: z.string() }).nullable()

export const makeAndModelFormSchema = z.object({
    make: z.string().min(1, "Make is required").max(255, "Make cannot exceed 255 characters"),
    model: z.string().min(1, "Model is required").max(255, "Model cannot exceed 255 characters"),
    year: z
        .string()
        .min(1, "Year is required")
        .refine((v) => {
            const n = Number(v)
            return Number.isInteger(n) && n >= 1900 && n <= 2100
        }, "Year must be a whole number between 1900 and 2100"),
    sub_model: z.string().optional(),
    engine_size: z.string().optional(),
    drivetrain: z.string().optional(),
    shop_type: relationFieldSchema.refine((val) => !!val?.value, "Shop type is required"),
    body_type: relationFieldSchema,
    fuel_type: relationFieldSchema,
    transmission: relationFieldSchema,
    is_active: z.boolean().default(true),
})

export type MakeAndModelFormValues = z.infer<typeof makeAndModelFormSchema>
export { relationFieldSchema }
