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

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

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

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

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

  @ApiProperty({ description: '下载地址' })
  @IsString()
  downloadUrl: string

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

  @ApiProperty({ description: 'SHA256校验和' })
  @IsString()
  fileSha256: string

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

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

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

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