import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsArray,
  IsBoolean,
  IsInt,
  IsOptional,
  IsString,
  Max,
  MaxLength,
  Min,
  ValidateNested,
} from 'class-validator';
import { PlanFeatureDto } from './plan-feature.dto';

export class CreatePlanDto {
  @ApiProperty({ example: 'PRO' })
  @IsString()
  @MaxLength(30)
  code!: string;

  @ApiProperty({ example: 'Basic' })
  @IsString()
  @MaxLength(80)
  name!: string;

  @ApiPropertyOptional({ example: 199 })
  @IsOptional()
  @IsInt()
  @Min(0)
  @Max(500000)
  priceMonthly?: number;

  @ApiPropertyOptional({ example: 'INR' })
  @IsOptional()
  @IsString()
  @MaxLength(6)
  currency?: string;

  @ApiPropertyOptional({
    example: true,
    description: 'If false, plan is hidden for public listing.',
  })
  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

  @ApiPropertyOptional({
    description: 'Array of feature key/value pairs.',
    example: [{ k: 'coupons', v: 'Unlimited' }],
  })
  @IsOptional()
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => PlanFeatureDto)
  features?: PlanFeatureDto[];
}
