import { IsInt, IsOptional, Min, Max } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiPropertyOptional } from '@nestjs/swagger';

/**
 * Whitelisted, typed body for `PATCH /config`. Config is persisted as string key/values, but every
 * known key is a positive integer (durations, hour windows, throttle limits/TTLs). Values arrive as
 * strings from the backoffice form; `@Type(() => Number)` coerces them so the numeric/range checks
 * apply (M-3 — the endpoint previously stored any raw string, e.g. `seat_hold_duration_minutes: -1`).
 * Unknown keys are stripped by the global whitelisting ValidationPipe.
 */
export class UpdateSystemConfigDto {
  @ApiPropertyOptional({ example: 5, description: 'Seat-hold duration in minutes (1..60)' })
  @IsOptional() @Type(() => Number) @IsInt() @Min(1) @Max(60)
  seat_hold_duration_minutes?: number;

  @ApiPropertyOptional({ example: 2 })
  @IsOptional() @Type(() => Number) @IsInt() @Min(0)
  hold_cutoff_hours_before_departure?: number;

  @ApiPropertyOptional({ example: 4 })
  @IsOptional() @Type(() => Number) @IsInt() @Min(0)
  boarding_window_hours_before_departure?: number;

  @ApiPropertyOptional({ example: 5 })
  @IsOptional() @Type(() => Number) @IsInt() @Min(1)
  throttle_auth_limit?: number;

  @ApiPropertyOptional({ example: 60000 })
  @IsOptional() @Type(() => Number) @IsInt() @Min(1)
  throttle_auth_ttl_ms?: number;

  @ApiPropertyOptional({ example: 20 })
  @IsOptional() @Type(() => Number) @IsInt() @Min(1)
  throttle_strict_limit?: number;

  @ApiPropertyOptional({ example: 60000 })
  @IsOptional() @Type(() => Number) @IsInt() @Min(1)
  throttle_strict_ttl_ms?: number;

  @ApiPropertyOptional({ example: 100 })
  @IsOptional() @Type(() => Number) @IsInt() @Min(1)
  throttle_default_limit?: number;

  @ApiPropertyOptional({ example: 60000 })
  @IsOptional() @Type(() => Number) @IsInt() @Min(1)
  throttle_default_ttl_ms?: number;
}
