import { z } from 'zod';

export const DocumentTypeSchema = z.enum(['insurance', 'registration', 'manual']);
export type DocumentType = z.infer<typeof DocumentTypeSchema>;

// API response type (camelCase for frontend)
export interface DocumentRecord {
  id: string;
  userId: string;
  vehicleId: string;
  documentType: DocumentType;
  title: string;
  notes?: string | null;
  details?: Record<string, any> | null;
  storageBucket?: string | null;
  storageKey?: string | null;
  fileName?: string | null;
  contentType?: string | null;
  fileSize?: number | null;
  fileHash?: string | null;
  issuedDate?: string | null;
  expirationDate?: string | null;
  emailNotifications?: boolean;
  scanForMaintenance?: boolean;
  createdAt: string;
  updatedAt: string;
  deletedAt?: string | null;
}

// API request schemas (camelCase for frontend)
export const CreateDocumentBodySchema = z.object({
  vehicleId: z.string().uuid(),
  documentType: DocumentTypeSchema,
  title: z.string().min(1).max(200),
  notes: z.string().max(10000).optional(),
  details: z.record(z.any()).optional(),
  issuedDate: z.string().optional(),
  expirationDate: z.string().optional(),
  emailNotifications: z.boolean().optional(),
  scanForMaintenance: z.boolean().optional(),
});
export type CreateDocumentBody = z.infer<typeof CreateDocumentBodySchema>;

export const UpdateDocumentBodySchema = z.object({
  title: z.string().min(1).max(200).optional(),
  notes: z.string().max(10000).nullable().optional(),
  details: z.record(z.any()).optional(),
  issuedDate: z.string().nullable().optional(),
  expirationDate: z.string().nullable().optional(),
  emailNotifications: z.boolean().optional(),
  scanForMaintenance: z.boolean().optional(),
});
export type UpdateDocumentBody = z.infer<typeof UpdateDocumentBodySchema>;

