import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import { IsString, IsInt, IsBoolean, IsOptional, Min, IsEnum, IsDateString } from 'class-validator'
import { Transform, Type } from 'class-transformer'
import { Platform } from '../../../domain/version-management'

export class UploadVersionDto {
  @ApiProperty({ description: '平台', enum: ['ANDROID', 'IOS', 'android', 'ios'] })
  @IsEnum(Platform)
  @Transform(({ value }) => value?.toUpperCase())
  platform: Platform

  @ApiPropertyOptional({ description: '版本号 (可选，可从APK/IPA自动检测)' })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  versionCode?: number

  @ApiPropertyOptional({ description: '版本名称 (可选，可从APK/IPA自动检测)' })
  @IsOptional()
  @IsString()
  versionName?: string

  @ApiPropertyOptional({ description: '构建号 (可选)' })
  @IsOptional()
  @IsString()
  buildNumber?: string

  @ApiPropertyOptional({ description: '更新日志' })
  @IsOptional()
  @IsString()
  changelog?: string

  @ApiProperty({ description: '是否强制更新', default: false })
  @Transform(({ value }) => value === 'true' || value === true)
  @IsBoolean()
  isForceUpdate: boolean

  @ApiPropertyOptional({ description: '最低操作系统版本' })
  @IsOptional()
  @IsString()
  minOsVersion?: string

  @ApiPropertyOptional({ description: '发布日期' })
  @IsOptional()
  @IsDateString()
  releaseDate?: string
}
