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

export class UpdateSettingDto {
  @ApiProperty({ description: 'The setting value (always stored as string)' })
  @IsString()
  value: string;

  @ApiPropertyOptional({ description: 'Human-readable description of the setting' })
  @IsString()
  @IsOptional()
  description?: string;

  @ApiPropertyOptional({
    description: 'Value type for parsing: string, number, boolean, json',
    enum: ['string', 'number', 'boolean', 'json'],
  })
  @IsString()
  @IsOptional()
  valueType?: string;

  @ApiPropertyOptional({ description: 'Whether the value should be encrypted at rest' })
  @IsBoolean()
  @IsOptional()
  isSecret?: boolean;
}

export class BulkUpdateSettingsDto {
  @ApiProperty({
    type: 'array',
    items: {
      type: 'object',
      properties: {
        key: { type: 'string' },
        value: { type: 'string' },
        category: { type: 'string' },
        description: { type: 'string' },
        valueType: { type: 'string' },
        isSecret: { type: 'boolean' },
      },
      required: ['key', 'value'],
    },
    description: 'Array of settings to upsert in one transaction',
  })
  settings: Array<{
    key: string;
    value: string;
    category?: string;
    description?: string;
    valueType?: string;
    isSecret?: boolean;
  }>;
}
