import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
import { inm_indice_tipo } from '@prisma/client';
import { IsEnum, IsNumber, IsOptional, IsString, Matches, MaxLength, Min } from 'class-validator';

export class CreateIndiceDto {
  @ApiPropertyOptional({ enum: inm_indice_tipo, example: inm_indice_tipo.IPC_BCP })
  @IsOptional()
  @IsEnum(inm_indice_tipo)
  tipo?: inm_indice_tipo;

  @ApiProperty({ example: '2026-09', description: 'Mes del índice, AAAA-MM.' })
  @Matches(/^\d{4}-(0[1-9]|1[0-2])$/, { message: 'El período va como AAAA-MM, ej: 2026-09' })
  periodo: string;

  @ApiProperty({ example: 157.43 })
  @IsNumber({ maxDecimalPlaces: 6 })
  @Min(0.000001)
  valor: number;

  @ApiPropertyOptional({ example: 'BCP — Informe de inflación septiembre 2026' })
  @IsOptional()
  @IsString()
  @MaxLength(150)
  fuente?: string;
}

export class UpdateIndiceDto extends PartialType(CreateIndiceDto) {}
