import { IsUUID, IsString, IsDateString, IsNumber, IsOptional, IsEnum } from 'class-validator';
import { MaintenanceType, MaintenanceStatus } from '../entities/maintenance-schedule.entity';

export class CreateMaintenanceScheduleDto {
  @IsUUID()
  vehicleId!: string;

  @IsEnum(MaintenanceType)
  maintenanceType!: MaintenanceType;

  /** What is serviced — matched against the interval for auto-scheduling. */
  @IsOptional()
  @IsString()
  serviceItem?: string;

  @IsString()
  description!: string;

  @IsDateString()
  scheduledDate!: string;

  @IsOptional()
  @IsNumber()
  estimatedCost?: number;

  @IsOptional()
  @IsString()
  serviceProvider?: string;

  @IsOptional()
  @IsString()
  notes?: string;

  @IsOptional()
  @IsNumber()
  nextDueKm?: number;

  @IsOptional()
  @IsDateString()
  nextDueDate?: string;
}

export class CreateMaintenanceCostDto {
  @IsUUID()
  vehicleId!: string;

  @IsOptional()
  @IsUUID()
  maintenanceScheduleId?: string;

  @IsDateString()
  incurredDate!: string;

  @IsNumber()
  costAmount!: number;

  @IsString()
  costType!: string;

  @IsString()
  description!: string;

  @IsOptional()
  @IsString()
  serviceProvider?: string;

  @IsOptional()
  @IsString()
  invoiceNumber?: string;

  @IsOptional()
  @IsString()
  notes?: string;
}

export class UpdateMaintenanceScheduleDto {
  @IsOptional()
  @IsEnum(MaintenanceStatus)
  status?: MaintenanceStatus;

  @IsOptional()
  @IsDateString()
  completedDate?: string;

  @IsOptional()
  @IsNumber()
  actualCost?: number;

  /** Odometer at completion — drives KM-based auto-scheduling of the next service. */
  @IsOptional()
  @IsNumber()
  odometerReading?: number;

  @IsOptional()
  @IsString()
  notes?: string;
}

export class UpsertMaintenanceIntervalDto {
  @IsUUID()
  vehicleId!: string;

  @IsEnum(MaintenanceType)
  maintenanceType!: MaintenanceType;

  /** What is serviced — "oil change", "tires", … Distinguishes intervals of the same type. */
  @IsOptional()
  @IsString()
  serviceItem?: string;

  @IsOptional()
  @IsNumber()
  intervalKm?: number;

  @IsOptional()
  @IsNumber()
  intervalDays?: number;

  @IsOptional()
  @IsString()
  description?: string;
}
