import { IsString, IsOptional, MinLength, MaxLength, Matches } from "class-validator";

// Slug validation regex - lowercase alphanumeric with hyphens
// eslint-disable-next-line security/detect-unsafe-regex
const SLUG_REGEX = /^[a-z0-9]+(-[a-z0-9]+)*$/;

/**
 * DTO for creating a new knowledge tag
 */
export class CreateTagDto {
  @IsString({ message: "name must be a string" })
  @MinLength(1, { message: "name must not be empty" })
  @MaxLength(100, { message: "name must not exceed 100 characters" })
  name!: string;

  @IsOptional()
  @IsString({ message: "slug must be a string" })
  @Matches(SLUG_REGEX, {
    message: "slug must be lowercase alphanumeric with hyphens",
  })
  slug?: string;

  @IsOptional()
  @IsString({ message: "color must be a string" })
  @Matches(/^#[0-9A-Fa-f]{6}$/, {
    message: "color must be a valid hex color (e.g., #FF5733)",
  })
  color?: string;

  @IsOptional()
  @IsString({ message: "description must be a string" })
  @MaxLength(500, { message: "description must not exceed 500 characters" })
  description?: string;
}
