import { IsString, IsArray, ValidateNested, IsOptional, IsEnum, IsDateString, IsBoolean } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Currency, IdDocumentType } from '@prisma/client';

export class GuestPassengerDto {
  @ApiProperty({ example: 'seat-id-uuid' }) 
  @IsString() seatId: string;

  @ApiProperty({ example: 'Abebe Kebede' }) 
  @IsString() passengerName: string;

  @ApiProperty({ example: '1990-05-15', description: 'Date of birth (YYYY-MM-DD) for age calculation' }) 
  @IsDateString() dateOfBirth: string;

  @ApiProperty({ example: 'NATIONAL_ID', enum: IdDocumentType, description: 'NATIONAL_ID for Ethiopians (Verifayda verified), PASSPORT for others' }) 
  @IsEnum(IdDocumentType) idDocumentType: IdDocumentType;

  @ApiPropertyOptional({ example: 'ET123456789', description: 'Ethiopian national ID - verified via Verifayda 2.0 (NOT stored)' }) 
  @IsOptional() @IsString() idDocumentNumber?: string;

  @ApiPropertyOptional({ example: 'P1234567', description: 'Passport number for non-Ethiopians' }) 
  @IsOptional() @IsString() passportNumber?: string;

  @ApiPropertyOptional({ example: 'Djibouti', description: 'Passport issuing country' }) 
  @IsOptional() @IsString() passportCountry?: string;

  @ApiPropertyOptional({ example: 'Ethiopian', description: 'Ethiopian (Verifayda), Djiboutian, Other' }) 
  @IsOptional() @IsString() nationality?: string;

  @ApiPropertyOptional({ example: '+251912345678', description: 'Contact phone number' }) 
  @IsOptional() @IsString() phone?: string;

  @ApiPropertyOptional({ example: 'abebe@email.com', description: 'Contact email' }) 
  @IsOptional() @IsString() email?: string;
}

export class CreateGuestBookingDto {
  @ApiProperty({ example: 'schedule-uuid' }) 
  @IsString() scheduleId: string;

  @ApiProperty({ example: 'hold-uuid' }) 
  @IsString() holdId: string;

  @ApiProperty({ example: 'station-uuid', description: 'Origin station UUID' }) 
  @IsString() originStationId: string;

  @ApiProperty({ example: 'station-uuid', description: 'Destination station UUID' }) 
  @IsString() destinationStationId: string;

  @ApiProperty({ type: [GuestPassengerDto], description: 'Array of passengers. First passenger details used for contact.' }) 
  @IsArray() @ValidateNested({ each: true }) @Type(() => GuestPassengerDto) passengers: GuestPassengerDto[];

  @ApiProperty({ example: 'seat-class-uuid', description: 'Seat class UUID' })
  @IsString() seatClassId: string;

  @ApiPropertyOptional({ example: 'WEEKEND15' }) 
  @IsOptional() @IsString() promoCode?: string;

  @ApiPropertyOptional({ example: 'ETB', enum: Currency, description: 'Display currency (ETB, DJF, USD)' }) 
  @IsOptional() @IsEnum(Currency) displayCurrency?: Currency;

  @ApiPropertyOptional({ example: true, description: 'Create account using first passenger details' }) 
  @IsOptional() @IsBoolean() createAccount?: boolean;

  @ApiPropertyOptional({ example: 'password123', description: 'Password if createAccount is true' }) 
  @IsOptional() @IsString() password?: string;

  @ApiPropertyOptional({ example: true, description: 'Save passenger details for future bookings (requires createAccount)' }) 
  @IsOptional() @IsBoolean() savePassengerDetails?: boolean;

  @ApiPropertyOptional({ example: 'device-uuid-12345', description: 'Device ID for local storage of passenger details' }) 
  @IsOptional() @IsString() deviceId?: string;
}

export class SavedPassengerProfileDto {
  @ApiProperty() passengerName: string;
  @ApiProperty() dateOfBirth: string;
  @ApiProperty({ enum: IdDocumentType }) idDocumentType: IdDocumentType;
  @ApiPropertyOptional() idDocumentNumber?: string;
  @ApiPropertyOptional() passportNumber?: string;
  @ApiPropertyOptional() passportCountry?: string;
  @ApiPropertyOptional() nationality?: string;
  @ApiPropertyOptional() phone?: string;
  @ApiPropertyOptional() email?: string;
}

export class GetSavedPassengersDto {
  @ApiPropertyOptional({ example: 'device-uuid-12345', description: 'Device ID to retrieve saved passengers' }) 
  @IsOptional() @IsString() deviceId?: string;
}
