import { IsString, IsNotEmpty, IsEnum, IsArray, ValidateNested, IsOptional, IsNumber } from 'class-validator';
import { Type } from 'class-transformer';
import { RuleAction, RuleConditionMetric, RuleConditionOperator } from '../entities/rule.entity';

class RuleConditionDto {
  @IsEnum(RuleConditionMetric)
  metric: RuleConditionMetric;

  @IsEnum(RuleConditionOperator)
  operator: RuleConditionOperator;

  @IsNumber()
  value: number;

  @IsString()
  @IsOptional()
  timeRange?: string = 'LAST_7_DAYS';
}

export class CreateRuleDto {
  @IsString()
  @IsNotEmpty()
  name: string;

  @IsEnum(RuleAction)
  action: RuleAction;

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => RuleConditionDto)
  conditions: RuleConditionDto[];

  @IsString()
  @IsNotEmpty()
  platform: 'meta' | 'tiktok' | 'google';

  @IsString()
  @IsOptional()
  targetId: string;

  @IsString()
  @IsNotEmpty()
  userId: string;

  @IsNotEmpty()
  @IsOptional()
  isActive?: boolean;
}
