import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNotEmpty, IsNumber, IsOptional, ValidateNested, IsArray, IsEnum, IsBoolean } from 'class-validator';
import { Type } from 'class-transformer';
import { Interval } from 'src/entities/plan.entity';
import { validationMessages } from 'src/messages/validation-messages';

class CreatePlanPermissionDto {
    @ApiProperty({
        description: 'Name of the feature included in the plan',
        example: 'Browse Influencer',
    })
    @IsNotEmpty({ message: validationMessages.plan.feature_name_required })
    feature_name: string;

    // @ApiProperty({
    //     description: 'Detailed description of the feature',
    //     example: 'Limited to the first 10 influencer results',
    // })
    // @IsNotEmpty({ message: validationMessages.plan.permission_description_required })
    // description?: string;

    @ApiProperty({
        description: 'Type of the permission or feature',
        example: 'browse_influencers',
    })
    @IsNotEmpty({ message: validationMessages.plan.permission_type_required })
    type: string;

    @ApiProperty({
        description: 'Usage or access limits for the feature',
        example: '100',
    })
    @IsNotEmpty({ message: validationMessages.plan.permission_limits_required })
    limits: number;

    @ApiProperty({
        description: 'Indicates if the entity is enabled',
        example: true,
    })
    // @IsBoolean({ message: 'is_enable must be a boolean value' })
    // is_enable: boolean;

    @ApiProperty({
        description: 'Time duration for the limits',
        example: '',
    })
    time_period?: string;

    // @ApiProperty({
    //     description: 'Types of time duration for the limits like hours,minutes,week,etc...',
    //     example: '',
    // })
    // time_period_type?: string;

    // @ApiProperty({
    //     description: 'Condition for feature usage,<=,>=,== etc...',
    //     example: '',
    // })
    // comparison_operators: string; TEST
}

export class CreatePlanDto {
    @ApiProperty({
        description: 'Name of the plan',
        example: 'Free Plan',
    })
    @IsNotEmpty({ message: validationMessages.plan.name_required })
    name: string;

    @ApiProperty({
        description: 'Detailed description of the plan',
        example: 'This plan is free and offers limited access to features.',
    })
    @IsNotEmpty({ message: validationMessages.plan.description_required })
    description?: string;

    @ApiProperty({
        description: 'Type of plan (e.g., free, premium)',
        example: 'free',
    })
    @IsNotEmpty({ message: validationMessages.plan.plan_type_required })
    plan_type: string;

    @ApiProperty({
        description: 'Price month_amount for the plan',
        example: 0.0,
    })
    @IsNotEmpty({ message: validationMessages.plan.amount_required })
    month_amount: number;

    @ApiProperty({
        description: 'Price month_amount for the plan',
        example: 0.0,
    })
    @IsNotEmpty({ message: validationMessages.plan.amount_required })
    year_amount: number;

    @ApiProperty({
        description: 'Currency for the plan',
        example: 'USD',
    })
    @IsNotEmpty({ message: validationMessages.plan.currency_required })
    currency: string;
    // TEST
    most_popular: boolean;
    trial_days: number;
    parent_plan_id: string;
    discount_label: string;

    @ApiProperty({
        description: 'Array of permissions associated with the plan',
        type: [CreatePlanPermissionDto],
    })
    @IsArray()
    @ValidateNested({ each: true })
    @Type(() => CreatePlanPermissionDto)
    @IsOptional()
    permissions?: CreatePlanPermissionDto[];
}
