import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
import {
  IsDateString,
  IsInt,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString,
  IsUUID,
  Max,
  MaxLength,
  Min,
} from 'class-validator';

export class CreateEtapaInmDto {
  @ApiProperty({ example: 'Torre A' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(100)
  nombre: string;

  @ApiPropertyOptional({ example: 1 })
  @IsOptional()
  @IsInt()
  @Min(0, { message: 'El orden no puede ser menor que 0' })
  orden?: number;

  @ApiPropertyOptional({ example: '2028-06-30' })
  @IsOptional()
  @IsDateString()
  fecha_entrega_estimada?: string;

  @ApiPropertyOptional({ example: '2028-07-15' })
  @IsOptional()
  @IsDateString()
  fecha_entrega_real?: string;

  @ApiPropertyOptional({ example: 35.5, description: 'Avance de obra en %.' })
  @IsOptional()
  @IsNumber({ maxDecimalPlaces: 2 })
  @Min(0, { message: 'El avance (%) no puede ser menor que 0' })
  @Max(100, { message: 'El avance (%) no puede ser mayor que 100' })
  pct_avance?: number;
}

export class UpdateEtapaInmDto extends PartialType(CreateEtapaInmDto) {}

export class CreateHitoDto {
  @ApiProperty({ example: 'Losa del piso 10' })
  @IsString()
  @IsNotEmpty()
  @MaxLength(150)
  nombre: string;

  @ApiPropertyOptional({ description: 'Etapa del mismo proyecto a la que pertenece.' })
  @IsOptional()
  @IsUUID()
  etapa_id?: string;

  @ApiPropertyOptional({ example: 3 })
  @IsOptional()
  @IsInt()
  @Min(0, { message: 'El orden no puede ser menor que 0' })
  orden?: number;

  @ApiPropertyOptional({ example: '2027-08-31' })
  @IsOptional()
  @IsDateString()
  fecha_estimada?: string;
}

export class UpdateHitoDto extends PartialType(CreateHitoDto) {}

export class CumplirHitoDto {
  @ApiPropertyOptional({ example: '2027-09-02', description: 'Por defecto, hoy.' })
  @IsOptional()
  @IsDateString()
  fecha_cumplido?: string;
}
