import {
  IsNotEmpty,
  IsArray,
  ValidateNested,
  IsString,
  IsOptional,
} from "class-validator"
import { Type } from "class-transformer"
import { ApiProperty } from "@nestjs/swagger"

export class TripAddOnDto {
  @ApiProperty({
    example: 5,
    required: false,
    description:
      "Primary key of trip_addons_pricing (send for update, omit for create)",
  })
  @IsOptional()
  id?: number

  @ApiProperty({ example: 1, description: "ID of the add-on" })
  @IsNotEmpty()
  addons_id: number

  @ApiProperty({ example: "20", description: "Price of the add-on" })
  @IsString()
  price: string

  @ApiProperty({ example: "2", description: "Quantity of the add-on" })
  @IsString()
  quantity: string

  @ApiProperty({
    example: "40",
    description: "Total price for this add-on (price × quantity)",
  })
  @IsString()
  total_price: string
}

export class TripAddOnsPricingDto {
  @ApiProperty({ example: 123, description: "ID of the trip" })
  @IsNotEmpty()
  trip_id: number

  @ApiProperty({
    type: [TripAddOnDto],
    description: "List of add-ons with pricing details",
    example: [
      {
        addons_id: 1,
        price: "20",
        quantity: "2",
        total_price: "40",
      },
      {
        addons_id: 3,
        price: "10",
        quantity: "1",
        total_price: "10",
      },
    ],
  })
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => TripAddOnDto)
  addons: TripAddOnDto[]
}
