import { Type } from "class-transformer";
import { IsArray, IsIn, IsString, Matches, ValidateNested } from "class-validator";

export class CreatePageBlockDto {
  @IsString()
  key!: string;

  @IsString()
  label!: string;

  @IsIn(["text", "richtext", "image", "faq-selection"])
  type!: "text" | "richtext" | "image" | "faq-selection";

  @IsString()
  value!: string;
}

export class CreatePageDto {
  // Lowercase segments separated by single slashes, e.g. "blog/my-new-post"
  // — matches how every other page slug in this CMS is shaped (see
  // seed-content/*.ts) so grouping/routing conventions keep working.
  @IsString()
  @Matches(/^[a-z0-9]+(?:[-/][a-z0-9]+)*$/, {
    message: "Slug must be lowercase letters, numbers, and hyphens, with single slashes between segments.",
  })
  slug!: string;

  @IsString()
  title!: string;

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => CreatePageBlockDto)
  blocks!: CreatePageBlockDto[];
}
