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

// Query parameters for GET /dashboard/working-group. Every filter is optional.
// When a filter is omitted, the dashboard counts every non-deleted issue
// across all working groups.
//
// Note: Express delivers query params as strings, so `@Type(() => Number)`
// is required to turn "2026" into the number 2026 before validation runs.
// The global ValidationPipe rejects any query param not listed here (400).
export class QueryDashboardSummaryDto {
  @ApiPropertyOptional({
    example: 2026,
    description: 'Only count issues created in this calendar year.',
  })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  // Bounds keep the year sane. Without them, something like year=99999 would
  // build an Invalid Date and crash the query with a 500 instead of a clean 400.
  @Min(2000)
  @Max(2100)
  year?: number;

  @ApiPropertyOptional({
    example: 4,
    description: 'Filter by issue status id.',
  })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  issueStatusId?: number;

  @ApiPropertyOptional({
    example: 'SOLVED',
    description:
      'Filter by status code (case-insensitive). Ignored when issueStatusId is also sent.',
  })
  @IsOptional()
  @IsString()
  @MaxLength(50)
  statusCode?: string;

  @ApiPropertyOptional({
    example: 5,
    description:
      'Filter to issues whose PRIMARY agency (agencyOrder = 1) is this stakeholder.',
  })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  primaryAgencyId?: number;

  @ApiPropertyOptional({
    example: 2,
    description: 'Filter by issue category id.',
  })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  categoryId?: number;

  @ApiPropertyOptional({
    example: 3,
    description:
      'Filter to issues owned by this working group (the issue owner stakeholder).',
  })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  workingGroupId?: number;
}
