import { ApiProperty } from "@nestjs/swagger"
import { Transform } from "class-transformer"
import { IsNotEmpty, IsString, Matches } from "class-validator"

export class CreateModuleDto {
  @ApiProperty({
    description: "The name of the module",
    example: "transport_management",
  })
  @IsString({ message: "Module name must be a string." })
  @IsNotEmpty({ message: "Module name cannot be empty." })
  @Transform(({ value }) => value.trim().toLowerCase())
  module_name: string

  @ApiProperty({
    description: "The type of the module",
    example: "transport_management",
  })
  @IsString({ message: "Module type must be a string." })
  @IsNotEmpty({ message: "Module type cannot be empty." })
  @Matches(/^(?!\d+$)[a-z0-9_]+$/, {
    message:
      "Module type must contain lowercase letters, numbers, or underscores only.",
  })
  @Transform(({ value }) => value.trim().toLowerCase().replace(/\s+/g, "_"))
  module_type: string

  @ApiProperty({
    description: "Indicates if the module has access",
    example: true,
  })
  @IsNotEmpty({ message: "Module access cannot be empty." })
  module_access: boolean
}
