import { IsEmail, IsNotEmpty, IsString, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty } from '@nestjs/swagger';

export class NameDto {
  @ApiProperty({ example: 'ቀለሙ ቀጸላ' })
  @IsString()
  am: string;

  @ApiProperty({ example: 'Kelemu Ketsela' })
  @IsString()
  en: string;
}

export class RegisterDto {
  // Accepts an email OR a phone number. When a passenger signs up without an email,
  // the portal passes the phone number here (and as `username`) — the IAM only requires
  // a non-empty string, so a phone value is a valid account identifier. Kept as
  // @IsString/@IsNotEmpty (not @IsEmail) so that phone-as-email passes the ValidationPipe.
  @ApiProperty({ example: 'kelemu@email.com', description: 'Email or, when the user has no email, their phone number' })
  @IsString()
  @IsNotEmpty()
  email: string;

  @ApiProperty({ example: 'kelemu.ketsela' })
  @IsString()
  username: string;

  @ApiProperty({ example: '+251912345678' })
  @IsString()
  phoneNumber: string;

  @ApiProperty({ type: NameDto })
  @ValidateNested()
  @Type(() => NameDto)
  name: NameDto;
}

export class ResendRegistrationCodeDto {
  @ApiProperty({ example: 'kelemu@email.com' })
  @IsEmail()
  email: string;

  @ApiProperty({ example: '+251912345678' })
  @IsString()
  phoneNumber: string;
}

export class LoginDto {
  // Accepts an email OR a phone number in the same field. Passengers who registered
  // without an email log in with their phone number, which the IAM matches. Kept as
  // @IsString/@IsNotEmpty (not @IsEmail) so a phone value passes the ValidationPipe.
  @ApiProperty({ example: 'kelemu@email.com', description: 'Email or phone number' })
  @IsString()
  @IsNotEmpty()
  email: string;

  @ApiProperty({ example: 'password123', format: 'password' })
  @IsString()
  password: string;
}

export class FaydaRequestPasswordSetupDto {
  @ApiProperty({ example: '+251911234567', description: 'Phone number of the Fayda-verified account' })
  @IsString()
  phoneNumber: string;
}

export class FaydaVerifyAndLoginDto {
  @ApiProperty({ example: '+251911234567' })
  @IsString()
  phoneNumber: string;

  @ApiProperty({ example: '123456', description: '6-digit OTP received via SMS' })
  @IsString()
  otp: string;
}
