/**
 * @ai-summary Request DTOs for platform feature
 * @ai-context Validation and type definitions for API requests
 */
import { z } from 'zod';

/**
 * VIN validation schema
 */
export const vinDecodeRequestSchema = z.object({
  vin: z.string()
    .length(17, 'VIN must be exactly 17 characters')
    .regex(/^[A-HJ-NPR-Z0-9]{17}$/, 'VIN contains invalid characters (cannot contain I, O, Q)')
    .transform(vin => vin.toUpperCase())
});

export type VINDecodeRequest = z.infer<typeof vinDecodeRequestSchema>;

/**
 * Year query parameter validation
 */
export const yearQuerySchema = z.object({
  year: z.coerce.number()
    .int('Year must be an integer')
    .min(1950, 'Year must be at least 1950')
    .max(2100, 'Year must be at most 2100')
});

export type YearQuery = z.infer<typeof yearQuerySchema>;

/**
 * Makes query parameters validation
 */
export const makesQuerySchema = yearQuerySchema;

export type MakesQuery = z.infer<typeof makesQuerySchema>;

/**
 * Models query parameters validation
 */
export const modelsQuerySchema = z.object({
  year: z.coerce.number()
    .int('Year must be an integer')
    .min(1950, 'Year must be at least 1950')
    .max(2100, 'Year must be at most 2100'),
  make: z.string()
    .min(1, 'Make is required')
    .max(100, 'Make must be less than 100 characters')
});

export type ModelsQuery = z.infer<typeof modelsQuerySchema>;

/**
 * Trims query parameters validation
 */
export const trimsQuerySchema = z.object({
  year: z.coerce.number()
    .int('Year must be an integer')
    .min(1950, 'Year must be at least 1950')
    .max(2100, 'Year must be at most 2100'),
  make: z.string()
    .min(1, 'Make is required')
    .max(100, 'Make must be less than 100 characters'),
  model: z.string()
    .min(1, 'Model is required')
    .max(100, 'Model must be less than 100 characters')
});

export type TrimsQuery = z.infer<typeof trimsQuerySchema>;

/**
 * Engines query parameters validation
 */
export const enginesQuerySchema = z.object({
  year: z.coerce.number()
    .int('Year must be an integer')
    .min(1950, 'Year must be at least 1950')
    .max(2100, 'Year must be at most 2100'),
  make: z.string()
    .min(1, 'Make is required')
    .max(100, 'Make must be less than 100 characters'),
  model: z.string()
    .min(1, 'Model is required')
    .max(100, 'Model must be less than 100 characters'),
  trim: z.string()
    .min(1, 'Trim is required')
    .max(100, 'Trim must be less than 100 characters')
});

export type EnginesQuery = z.infer<typeof enginesQuerySchema>;

/**
 * Transmissions query parameters validation
 */
export const transmissionsQuerySchema = z.object({
  year: z.coerce.number()
    .int('Year must be an integer')
    .min(1950, 'Year must be at least 1950')
    .max(2100, 'Year must be at most 2100'),
  make: z.string()
    .min(1, 'Make is required')
    .max(100, 'Make must be less than 100 characters'),
  model: z.string()
    .min(1, 'Model is required')
    .max(100, 'Model must be less than 100 characters'),
  trim: z.string()
    .min(1, 'Trim is required')
    .max(100, 'Trim must be less than 100 characters'),
  engine: z.string().optional()
});

export type TransmissionsQuery = z.infer<typeof transmissionsQuerySchema>;
