import {
  IsBoolean,
  IsDateString,
  IsIn,
  IsInt,
  IsOptional,
  IsString,
  IsUrl,
  MaxLength,
} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class CreateVersionDto {
  @ApiProperty({ enum: ['android', 'ios', 'ANDROID', 'IOS'] })
  @IsIn(['android', 'ios', 'ANDROID', 'IOS'])
  platform: string;

  @ApiProperty({ example: 10 })
  @IsInt()
  versionCode: number;

  @ApiProperty({ example: '1.2.0', maxLength: 32 })
  @IsString()
  @MaxLength(32)
  versionName: string;

  @ApiProperty({ example: '20250101.1', maxLength: 64 })
  @IsString()
  @MaxLength(64)
  buildNumber: string;

  @ApiProperty({ example: 'https://cdn.example.com/app-1.2.0.apk' })
  @IsUrl()
  downloadUrl: string;

  @ApiProperty({ example: '52428800' })
  @IsString()
  fileSize: string;

  @ApiProperty({ example: 'a1b2c3d4...', maxLength: 64 })
  @IsString()
  @MaxLength(64)
  fileSha256: string;

  @ApiProperty({ example: 'Bug fixes and performance improvements.' })
  @IsString()
  changelog: string;

  @ApiProperty({ example: false })
  @IsBoolean()
  isForceUpdate: boolean;

  @ApiPropertyOptional({ maxLength: 16 })
  @IsOptional()
  @IsString()
  @MaxLength(16)
  minOsVersion?: string;

  @ApiPropertyOptional({ example: '2025-06-01' })
  @IsOptional()
  @IsDateString()
  releaseDate?: string;
}

export class UpdateVersionDto {
  @ApiPropertyOptional({ example: '1.2.1', maxLength: 32 })
  @IsOptional()
  @IsString()
  @MaxLength(32)
  versionName?: string;

  @ApiPropertyOptional({ example: '20250102.1', maxLength: 64 })
  @IsOptional()
  @IsString()
  @MaxLength(64)
  buildNumber?: string;

  @ApiPropertyOptional({ example: 'https://cdn.example.com/app-1.2.1.apk' })
  @IsOptional()
  @IsUrl()
  downloadUrl?: string;

  @ApiPropertyOptional({ example: '52428800' })
  @IsOptional()
  @IsString()
  fileSize?: string;

  @ApiPropertyOptional({ example: 'a1b2c3d4...', maxLength: 64 })
  @IsOptional()
  @IsString()
  @MaxLength(64)
  fileSha256?: string;

  @ApiPropertyOptional({ example: 'Updated changelog.' })
  @IsOptional()
  @IsString()
  changelog?: string;

  @ApiPropertyOptional({ example: false })
  @IsOptional()
  @IsBoolean()
  isForceUpdate?: boolean;

  @ApiPropertyOptional({ maxLength: 16 })
  @IsOptional()
  @IsString()
  @MaxLength(16)
  minOsVersion?: string;

  @ApiPropertyOptional({ example: '2025-06-01' })
  @IsOptional()
  @IsDateString()
  releaseDate?: string;
}
