import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsString, MaxLength, MinLength } from 'class-validator';

// Trim incoming names so " General " and "General" are treated the same
// at validation time (uniqueness checks happen later in the service).
const trimString = ({ value }: { value: unknown }) =>
  typeof value === 'string' ? value.trim() : value;

export class CreateCategoryDto {
  @ApiProperty({
    example: 'Trade Policy',
    description: 'Human-readable category name. Must be unique.',
  })
  @Transform(trimString)
  @IsString()
  @MinLength(1)
  @MaxLength(100)
  name!: string;
}
