import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import { IsEnum, IsInt, IsString, IsBoolean, IsUrl, Min, IsOptional, IsDateString } from 'class-validator'
import { Transform } from 'class-transformer'
import { Platform } from '@/domain/enums/platform.enum'

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

  @ApiProperty({ description: '版本号', example: 101 })
  @IsInt()
  @Min(1)
  versionCode: number

  @ApiProperty({ description: '版本名称', example: '1.0.1' })
  @IsString()
  versionName: string

  @ApiProperty({ description: '构建号', example: '202512021200' })
  @IsString()
  buildNumber: string

  @ApiProperty({ description: 'APK/IPA下载地址', example: 'https://example.com/app-v1.0.1.apk' })
  @IsUrl()
  downloadUrl: string

  @ApiProperty({ description: '文件大小(字节)', example: 52428800 })
  @IsString()
  fileSize: string

  @ApiProperty({ description: '文件SHA-256校验和' })
  @IsString()
  fileSha256: string

  @ApiProperty({ description: '更新日志' })
  @IsString()
  changelog: string

  @ApiProperty({ description: '是否强制更新', default: false })
  @IsBoolean()
  isForceUpdate: boolean

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

  @ApiPropertyOptional({ description: '发布日期', example: '2025-12-02T10:00:00Z' })
  @IsOptional()
  @IsDateString()
  releaseDate?: string
}
