import { IsString, IsNotEmpty, IsOptional, IsEmail } from 'class-validator';
import { Transform } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class AppleLoginDto {
  @ApiProperty({ description: 'Apple identityToken (JWT)' })
  @IsString()
  @IsNotEmpty()
  identityToken: string;

  @ApiPropertyOptional({ description: 'Apple authorizationCode' })
  @IsOptional()
  @IsString()
  authorizationCode?: string;

  @ApiPropertyOptional({ description: 'Apple userIdentifier' })
  @IsOptional()
  @IsString()
  userIdentifier?: string;

  @ApiPropertyOptional({ description: 'Apple 返回的邮箱（仅首次返回）' })
  @Transform(({ value }) => (value === '' ? undefined : value))
  @IsOptional()
  @IsEmail()
  email?: string;

  @ApiPropertyOptional({ description: 'Apple 返回的姓名（仅首次返回）' })
  @IsOptional()
  fullName?: {
    givenName?: string;
    familyName?: string;
  };

  @ApiPropertyOptional({ description: 'Apple nonce（安全校验用）' })
  @Transform(({ value }) => (value === '' ? undefined : value))
  @IsOptional()
  @IsString()
  nonce?: string;
}
