/**
 * PurchaseOrderConstruction DTOs - Data Transfer Objects para Ordenes de Compra Construccion
 *
 * Extension de ordenes de compra para proyectos de construccion.
 *
 * @module Purchase (MAI-004)
 */

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

/**
 * DTO para crear una nueva extension de orden de compra para construccion
 */
export class CreatePurchaseOrderConstructionDto {
  @IsUUID()
  purchaseOrderId: string;

  @IsOptional()
  @IsUUID()
  fraccionamientoId?: string;

  @IsOptional()
  @IsUUID()
  requisicionId?: string;

  @IsOptional()
  @IsString()
  @MaxLength(255)
  deliveryLocation?: string;

  @IsOptional()
  @IsString()
  @MaxLength(100)
  deliveryContact?: string;

  @IsOptional()
  @IsString()
  @MaxLength(20)
  deliveryPhone?: string;
}

/**
 * DTO para actualizar una orden de compra de construccion existente
 */
export class UpdatePurchaseOrderConstructionDto {
  @IsOptional()
  @IsUUID()
  fraccionamientoId?: string;

  @IsOptional()
  @IsUUID()
  requisicionId?: string;

  @IsOptional()
  @IsString()
  @MaxLength(255)
  deliveryLocation?: string;

  @IsOptional()
  @IsString()
  @MaxLength(100)
  deliveryContact?: string;

  @IsOptional()
  @IsString()
  @MaxLength(20)
  deliveryPhone?: string;
}

/**
 * DTO para registrar la recepcion de una orden de compra
 */
export class RegisterReceptionDto {
  @IsOptional()
  @IsUUID()
  receivedById?: string;

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

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

/**
 * DTO para filtrar ordenes de compra de construccion en listados
 */
export class PurchaseOrderConstructionFiltersDto {
  @IsOptional()
  @IsUUID()
  fraccionamientoId?: string;

  @IsOptional()
  @IsUUID()
  requisicionId?: string;

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

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

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

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

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

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

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

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

/**
 * DTO de respuesta para una orden de compra de construccion
 */
export class PurchaseOrderConstructionResponseDto {
  id: string;
  tenantId: string;
  purchaseOrderId: string;
  fraccionamientoId?: string;
  fraccionamiento?: {
    id: string;
    code: string;
    name: string;
  };
  requisicionId?: string;
  requisicion?: {
    id: string;
    code: string;
  };
  deliveryLocation?: string;
  deliveryContact?: string;
  deliveryPhone?: string;
  receivedById?: string;
  receivedBy?: {
    id: string;
    firstName: string;
    lastName: string;
  };
  receivedAt?: Date;
  qualityApproved?: boolean;
  qualityNotes?: string;
  createdAt: Date;
  createdById?: string;
  createdBy?: {
    id: string;
    firstName: string;
    lastName: string;
  };
  updatedAt: Date;
  updatedById?: string;
}
