import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsBoolean, IsIn, IsOptional, IsString } from 'class-validator';

export class StartVerificationDto {
  @ApiPropertyOptional({
    enum: ['LOGIN', 'PURCHASE'],
    default: 'PURCHASE',
    description: 'Reason for verification.',
  })
  @IsOptional()
  @IsIn(['LOGIN', 'PURCHASE'])
  purpose?: 'LOGIN' | 'PURCHASE';

  @ApiPropertyOptional({
    description:
      'Booking the verification should attach to (PURCHASE flow). If omitted, the session is anchored only to the user.',
  })
  @IsOptional()
  @IsString()
  bookingId?: string;

  @ApiPropertyOptional({
    description:
      'When true and the user is logged in, copy faydaVerified=true / faydaSub onto their User record after verification.',
  })
  @IsOptional()
  @IsBoolean()
  saveToAccount?: boolean;

  @ApiPropertyOptional({
    enum: ['WEB', 'MOBILE'],
    default: 'WEB',
    description:
      'Client platform. Decides where /callback redirects on completion: a web https URL (WEB) or a custom-scheme deep link the Flutter app intercepts (MOBILE).',
  })
  @IsOptional()
  @IsIn(['WEB', 'MOBILE'])
  platform?: 'WEB' | 'MOBILE';
}

export class CompleteVerificationResultDto {
  @ApiProperty({ enum: ['LOGIN', 'PURCHASE'] })
  purpose: 'LOGIN' | 'PURCHASE';

  @ApiProperty() verified: boolean;

  @ApiPropertyOptional({ description: 'JWT (LOGIN flow only).' })
  token?: string;

  @ApiPropertyOptional({
    description: 'Authenticated user summary (LOGIN flow only; same shape as /auth/login).',
  })
  user?: {
    id: string;
    email: string;
    role: string;
    passengerId?: string;
    agentId?: string;
  };

  @ApiPropertyOptional({
    description: 'Verified full name from Fayda (PURCHASE flow).',
  })
  fullName?: string;
}

export class VerifaydaCallbackDto {
  @ApiPropertyOptional() @IsOptional() @IsString() code?: string;
  @ApiPropertyOptional() @IsOptional() @IsString() state?: string;
  @ApiPropertyOptional() @IsOptional() @IsString() error?: string;
  @ApiPropertyOptional() @IsOptional() @IsString() error_description?: string;
}

export class VerificationStatusDto {
  @ApiProperty() verified: boolean;
  @ApiPropertyOptional() verifiedAt?: Date;
  @ApiPropertyOptional() fullName?: string;
}
