import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger"
import {
  IsNotEmpty,
  IsString,
  IsIn,
  IsInt,
  Min,
  IsOptional,
} from "class-validator"
import { Type } from "class-transformer"
import { messageKey } from "src/constants/message-keys"
import { validationMessage } from "src/utils/helpers"
import {
  SECTION_VALUES,
  NEXT_SCREEN_VALUES,
} from "src/constants/general-landing-page.constant"

export class CreateGeneralLandingPageDto {
  @ApiProperty({
    description: "Section (header or listing)",
    example: "listing",
  })
  @IsString()
  @IsNotEmpty({
    message: validationMessage(messageKey.field_required, {
      ":field": "section",
    }),
  })
  @IsIn(SECTION_VALUES, {
    message: validationMessage(messageKey.invalid, {
      ":field": "section",
    }),
  })
  section: string

  @ApiProperty({
    description: "Title",
    example: "Activate Abundance",
  })
  @IsString()
  @IsNotEmpty({
    message: validationMessage(messageKey.field_required, {
      ":field": "title",
    }),
  })
  title: string

  @ApiProperty({
    description: "Description",
    example: "Discover the path to abundance",
  })
  @IsString()
  @IsNotEmpty({
    message: validationMessage(messageKey.field_required, {
      ":field": "description",
    }),
  })
  description: string

  @ApiPropertyOptional({
    description: "Sort order (auto-assigned as 1, 2, 3 from the frontend)",
    example: 1,
  })
  @IsOptional()
  @Type(() => Number)
  @IsInt({
    message: validationMessage(messageKey.field_type_validation_error, {
      ":field": "sort_order",
      ":type": "integer",
    }),
  })
  @Min(1, {
    message: validationMessage(messageKey.positive_number, {
      ":field": "sort_order",
    }),
  })
  sort_order?: number

  @ApiPropertyOptional({
    description:
      "Next navigate screen (required for listing, optional for header)",
    example: "update_identity",
  })
  @IsOptional()
  @IsString()
  @IsIn(NEXT_SCREEN_VALUES, {
    message: validationMessage(messageKey.invalid, {
      ":field": "next_screen",
    }),
  })
  next_screen?: string
}
