import { IsOptional, IsString, IsUUID } from 'class-validator';
import { PaginationDto } from '../../../common/dto/pagination.dto';

/**
 * Audit Log list query. Extends PaginationDto so page/limit get the
 * ValidationPipe's number transform (`@Type(() => Number)`) + whitelist.
 *
 * Why this matters: the controller previously typed the query as an
 * intersection `PaginationDto & { ... }`. TypeScript's emitDecoratorMetadata
 * serialises an intersection as `Object`, so the ValidationPipe skipped it
 * entirely — page/limit stayed STRINGS in the response's pagination meta,
 * the FE's strict numeric meta check then dropped the meta, the whole
 * response collapsed to a bare array, and the Audit Log page rendered
 * "0 results" despite data existing. A real DTO class restores the
 * transform (and properly validates the filter params). (2026-10-10)
 */
export class AuditQueryDto extends PaginationDto {
  /** entity table name, e.g. 'booking', 'query', 'booking_transport_item'. */
  @IsOptional()
  @IsString()
  entity_type?: string;

  /** action, e.g. 'created' | 'updated' | 'deleted' | 'assigned' | ... */
  @IsOptional()
  @IsString()
  action?: string;

  /** filter by the acting user's id. */
  @IsOptional()
  @IsUUID()
  performed_by?: string;

  /** inclusive date-range start (YYYY-MM-DD). */
  @IsOptional()
  @IsString()
  from?: string;

  /** inclusive date-range end (YYYY-MM-DD). */
  @IsOptional()
  @IsString()
  to?: string;
}
