import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import { Platform } from '@/domain/enums/platform.enum'

export class VersionDto {
  @ApiProperty()
  id: string

  @ApiProperty({ enum: Platform })
  platform: Platform

  @ApiProperty()
  versionCode: number

  @ApiProperty()
  versionName: string

  @ApiProperty()
  buildNumber: string

  @ApiProperty()
  downloadUrl: string

  @ApiProperty()
  fileSize: string

  @ApiProperty()
  fileSha256: string

  @ApiProperty()
  changelog: string

  @ApiProperty()
  isForceUpdate: boolean

  @ApiProperty()
  isEnabled: boolean

  @ApiPropertyOptional()
  minOsVersion: string | null

  @ApiPropertyOptional()
  releaseDate: Date | null

  @ApiProperty()
  createdAt: Date

  @ApiProperty()
  updatedAt: Date
}

export class UpdateCheckResultDto {
  @ApiProperty({ description: '是否有更新' })
  hasUpdate: boolean

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

  @ApiPropertyOptional({ description: '最新版本信息' })
  latestVersion: {
    versionCode: number
    versionName: string
    downloadUrl: string
    fileSize: string
    fileSha256: string
    changelog: string
    minOsVersion: string | null
    releaseDate: Date | null
  } | null
}

// Mobile app compatible response format
export class MobileUpdateCheckResultDto {
  @ApiProperty({ description: '是否需要更新' })
  needUpdate: boolean

  @ApiPropertyOptional({ description: '版本号 (语义化版本)' })
  version?: string

  @ApiPropertyOptional({ description: '版本代码 (用于比较)' })
  versionCode?: number

  @ApiPropertyOptional({ description: 'APK下载地址' })
  downloadUrl?: string

  @ApiPropertyOptional({ description: '文件大小(字节)' })
  fileSize?: number

  @ApiPropertyOptional({ description: '友好的文件大小显示' })
  fileSizeFriendly?: string

  @ApiPropertyOptional({ description: 'SHA-256校验和' })
  sha256?: string

  @ApiPropertyOptional({ description: '是否强制更新' })
  forceUpdate?: boolean

  @ApiPropertyOptional({ description: '更新日志' })
  updateLog?: string

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