import { IsString, IsOptional, IsEnum, MaxLength, MinLength } from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class CreateSecretDto {
  @ApiProperty({ description: '密钥名', example: 'WECHAT_SECRET' })
  @IsString()
  @MinLength(1)
  @MaxLength(100)
  secretKey: string;

  @ApiProperty({ description: '密钥值（明文，服务端加密存储）' })
  @IsString()
  @MinLength(1)
  secretValue: string;

  @ApiPropertyOptional({ description: '说明', example: '微信小程序 Secret' })
  @IsString()
  @IsOptional()
  @MaxLength(200)
  description?: string;

  @ApiPropertyOptional({ description: '分组', example: 'wechat', default: 'default' })
  @IsString()
  @IsOptional()
  @MaxLength(50)
  groupName?: string;

  @ApiPropertyOptional({ description: '适用环境', enum: ['all', 'prod', 'test'], default: 'all' })
  @IsEnum(['all', 'prod', 'test'])
  @IsOptional()
  env?: string;
}

export class UpdateSecretDto {
  @ApiPropertyOptional({ description: '密钥值（明文，服务端加密存储）' })
  @IsString()
  @IsOptional()
  @MinLength(1)
  secretValue?: string;

  @ApiPropertyOptional({ description: '说明' })
  @IsString()
  @IsOptional()
  @MaxLength(200)
  description?: string;

  @ApiPropertyOptional({ description: '分组' })
  @IsString()
  @IsOptional()
  @MaxLength(50)
  groupName?: string;

  @ApiPropertyOptional({ description: '适用环境', enum: ['all', 'prod', 'test'] })
  @IsEnum(['all', 'prod', 'test'])
  @IsOptional()
  env?: string;
}

export class QuerySecretDto {
  @ApiPropertyOptional({ description: '按分组筛选' })
  @IsString()
  @IsOptional()
  groupName?: string;

  @ApiPropertyOptional({ description: '按环境筛选', enum: ['all', 'prod', 'test'] })
  @IsEnum(['all', 'prod', 'test'])
  @IsOptional()
  env?: string;
}
