import { z } from "zod"

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

export const vehicleFormSchema = z.object({
    // ── Relations ──
    shop_type_id: relationFieldSchema.refine((val) => !!val?.value, "Shop type is required"),
    vehicle_body_type_id: relationFieldSchema.refine((val) => !!val?.value, "Vehicle body type is required"),
    vehicle_fuel_type_id: relationFieldSchema,
    vehicle_transmission_id: relationFieldSchema,
    vehicle_color_id: relationFieldSchema,
    customer_id: relationFieldSchema,
    // ── Vehicle identity ──
    make: z.string().min(1, "Make is required").max(50, "Make must be at most 50 characters"),
    model: z.string().min(1, "Model is required").max(50, "Model must be at most 50 characters"),
    year: z.string().optional(),
    sub_model: z.string().optional(),

    // ── License & identifiers ──
    license_plate: z.string().min(1, "License plate is required").max(50, "License plate must be at most 50 characters"),
    vin_number: z.string().optional(),

    // ── Technical specs ──
    engine_size: z.string().optional(),
    drivetrain: z.string().optional(),
    mileage: z.string().optional(),
    owners_number: z.string().optional(),

    // ── Notes ──
    note: z.string().optional(),

    // ── Insurance ──
    has_insurance: z.boolean().optional(),
    insurance_type: relationFieldSchema.optional(),

    // ── Image ──
    image: z.any().optional(),
})

export type VehicleFormValues = z.infer<typeof vehicleFormSchema>
