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

import { PaginationQueryDto } from '../../../common/dto/pagination-query.dto';

export const BATCH_BOARD_STATUSES = [
  'DRAFT',
  'SCHEDULED',
  'DISPATCHED',
  'ARRIVED',
  'CANCELLED',
] as const;

export const BATCH_BOARD_SORT_FIELDS = [
  'createdAt',
  'scheduledDepartureDate',
  'trainNumber',
  'status',
] as const;
export type BatchBoardSortField = (typeof BATCH_BOARD_SORT_FIELDS)[number];

/**
 * Filters for the batch monitoring board list (import schedules, all statuses).
 * `page`/`pageSize`/`search`/`sortOrder` come from the shared
 * {@link PaginationQueryDto}; search matches train number, route yards,
 * stations, or locomotive code (case-insensitive).
 */
export class BatchBoardQueryDto extends PaginationQueryDto {
  @ApiPropertyOptional({
    description:
      'Comma-separated schedule statuses (DRAFT,SCHEDULED,DISPATCHED,ARRIVED,CANCELLED). Omit for all.',
    example: 'DISPATCHED,ARRIVED',
  })
  @IsOptional()
  @IsString()
  statuses?: string;

  @ApiPropertyOptional({ enum: ['OPEN', 'FULL', 'CLOSED'] })
  @IsOptional()
  @IsIn(['OPEN', 'FULL', 'CLOSED'])
  bookingWindowStatus?: 'OPEN' | 'FULL' | 'CLOSED';

  @ApiPropertyOptional({ description: 'Departure date lower bound (ISO 8601).' })
  @IsOptional()
  @IsISO8601()
  departureFrom?: string;

  @ApiPropertyOptional({ description: 'Departure date upper bound (ISO 8601).' })
  @IsOptional()
  @IsISO8601()
  departureTo?: string;

  @ApiPropertyOptional({ description: 'Created-at lower bound (ISO 8601).' })
  @IsOptional()
  @IsISO8601()
  createdFrom?: string;

  @ApiPropertyOptional({ description: 'Created-at upper bound (ISO 8601).' })
  @IsOptional()
  @IsISO8601()
  createdTo?: string;

  @ApiPropertyOptional({ enum: BATCH_BOARD_SORT_FIELDS, default: 'createdAt' })
  @IsOptional()
  @IsIn(BATCH_BOARD_SORT_FIELDS as unknown as string[])
  sortBy?: BatchBoardSortField;
}
