/**
 * BidCalendar DTOs - Data Transfer Objects para Calendario de Licitacion
 *
 * Eventos y fechas importantes del proceso de licitacion.
 *
 * @module Bidding (MAI-018)
 */

import {
  IsString,
  IsUUID,
  IsOptional,
  IsEnum,
  IsNumber,
  IsDateString,
  IsBoolean,
  MinLength,
  MaxLength,
  Min,
  Max,
} from 'class-validator';

/**
 * Tipo de evento en el calendario
 */
export enum CalendarEventType {
  SITE_VISIT = 'site_visit',
  CLARIFICATION_MEETING = 'clarification_meeting',
  SUBMISSION_DEADLINE = 'submission_deadline',
  TECHNICAL_OPENING = 'technical_opening',
  ECONOMIC_OPENING = 'economic_opening',
  AWARD_DATE = 'award_date',
  OTHER = 'other',
}

/**
 * DTO para crear un nuevo evento de calendario
 */
export class CreateBidCalendarDto {
  @IsUUID()
  tenderId: string;

  @IsEnum(CalendarEventType)
  eventType: CalendarEventType;

  @IsDateString()
  eventDate: string;

  @IsString()
  @MinLength(5)
  @MaxLength(255)
  description: string;

  @IsOptional()
  @IsNumber()
  @Min(0)
  @Max(30)
  alertDaysBefore?: number;

  @IsOptional()
  @IsString()
  notes?: string;
}

/**
 * DTO para actualizar un evento de calendario existente
 */
export class UpdateBidCalendarDto {
  @IsOptional()
  @IsEnum(CalendarEventType)
  eventType?: CalendarEventType;

  @IsOptional()
  @IsDateString()
  eventDate?: string;

  @IsOptional()
  @IsString()
  @MinLength(5)
  @MaxLength(255)
  description?: string;

  @IsOptional()
  @IsNumber()
  @Min(0)
  @Max(30)
  alertDaysBefore?: number;

  @IsOptional()
  @IsBoolean()
  alertSent?: boolean;

  @IsOptional()
  @IsString()
  notes?: string;
}

/**
 * DTO para marcar alerta como enviada
 */
export class MarkAlertSentDto {
  @IsOptional()
  @IsBoolean()
  alertSent?: boolean;
}

/**
 * DTO para filtrar eventos de calendario
 */
export class BidCalendarFiltersDto {
  @IsOptional()
  @IsUUID()
  tenderId?: string;

  @IsOptional()
  @IsEnum(CalendarEventType)
  eventType?: CalendarEventType;

  @IsOptional()
  @IsDateString()
  dateFrom?: string;

  @IsOptional()
  @IsDateString()
  dateTo?: string;

  @IsOptional()
  @IsBoolean()
  alertSent?: boolean;

  @IsOptional()
  @IsBoolean()
  pendingAlerts?: boolean;

  @IsOptional()
  @IsString()
  search?: string;

  @IsOptional()
  @IsNumber()
  @Min(1)
  page?: number;

  @IsOptional()
  @IsNumber()
  @Min(1)
  limit?: number;

  @IsOptional()
  @IsString()
  sortBy?: string;

  @IsOptional()
  @IsEnum(['ASC', 'DESC'])
  sortOrder?: 'ASC' | 'DESC';
}

/**
 * DTO de respuesta para un evento de calendario
 */
export class BidCalendarResponseDto {
  id: string;
  tenantId: string;
  tenderId: string;
  tender?: {
    id: string;
    number: string;
    title: string;
  };
  eventType: CalendarEventType;
  eventDate: Date;
  description: string;
  alertDaysBefore: number;
  alertSent: boolean;
  notes?: string;
  createdAt: Date;
  createdById?: string;
  createdBy?: {
    id: string;
    firstName: string;
    lastName: string;
  };
  updatedAt: Date;
  updatedById?: string;
}

/**
 * DTO para obtener eventos proximos que requieren alerta
 */
export class UpcomingEventsAlertDto {
  @IsOptional()
  @IsNumber()
  @Min(1)
  @Max(30)
  daysAhead?: number;

  @IsOptional()
  @IsEnum(CalendarEventType)
  eventType?: CalendarEventType;
}
