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

const WEEK_MONTH = ['week', 'month'] as const;
const WEEK_MONTH_YEAR = ['week', 'month', 'year'] as const;

export class TodaySummaryQueryDto {
  @ApiPropertyOptional({
    description: 'Start of the local day range (ISO 8601). Defaults to UTC midnight today.',
    example: '2026-07-10T00:00:00.000Z',
  })
  @IsOptional()
  @IsISO8601()
  from?: string;

  @ApiPropertyOptional({
    description: 'End of the local day range (ISO 8601, exclusive). Defaults to next UTC midnight.',
    example: '2026-07-11T00:00:00.000Z',
  })
  @IsOptional()
  @IsISO8601()
  to?: string;

  @ApiPropertyOptional({
    description:
      'Client UTC offset in minutes (same sign as Date.getTimezoneOffset negated). Used for hourly buckets.',
    example: 210,
  })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(-840)
  @Max(840)
  utcOffsetMinutes?: number;

  @ApiPropertyOptional({ enum: WEEK_MONTH })
  @IsOptional()
  @IsIn(WEEK_MONTH)
  appointmentsWeekPeriod?: 'week' | 'month';

  @ApiPropertyOptional({ enum: WEEK_MONTH })
  @IsOptional()
  @IsIn(WEEK_MONTH)
  appointmentsWeekMinePeriod?: 'week' | 'month';

  @ApiPropertyOptional({ enum: WEEK_MONTH })
  @IsOptional()
  @IsIn(WEEK_MONTH)
  labTaskActivityPeriod?: 'week' | 'month';

  @ApiPropertyOptional({ enum: WEEK_MONTH })
  @IsOptional()
  @IsIn(WEEK_MONTH)
  casesDuePeriod?: 'week' | 'month';

  @ApiPropertyOptional({ enum: WEEK_MONTH_YEAR })
  @IsOptional()
  @IsIn(WEEK_MONTH_YEAR)
  treatmentMixPeriod?: 'week' | 'month' | 'year';

  @ApiPropertyOptional({ enum: WEEK_MONTH_YEAR })
  @IsOptional()
  @IsIn(WEEK_MONTH_YEAR)
  casePartnersPeriod?: 'week' | 'month' | 'year';

  @ApiPropertyOptional({ enum: WEEK_MONTH_YEAR })
  @IsOptional()
  @IsIn(WEEK_MONTH_YEAR)
  efficiencyPeriod?: 'week' | 'month' | 'year';
}
