import {
  IsString,
  IsOptional,
  IsBoolean,
  IsInt,
  IsObject,
  IsEnum,
  Min,
  Max,
} from 'class-validator';
import {
  SegmentConditionGroup,
  SegmentUsageType,
} from '../../../domain/entities/audience-segment.entity';

/**
 * 创建人群包
 */
export class CreateSegmentDto {
  @IsString()
  name: string;

  @IsOptional()
  @IsString()
  description?: string;

  @IsObject()
  conditions: SegmentConditionGroup;

  @IsOptional()
  @IsEnum(SegmentUsageType)
  usageType?: SegmentUsageType;
}

/**
 * 更新人群包
 */
export class UpdateSegmentDto {
  @IsOptional()
  @IsString()
  name?: string;

  @IsOptional()
  @IsString()
  description?: string | null;

  @IsOptional()
  @IsObject()
  conditions?: SegmentConditionGroup;

  @IsOptional()
  @IsEnum(SegmentUsageType)
  usageType?: SegmentUsageType;

  @IsOptional()
  @IsBoolean()
  isEnabled?: boolean;
}

/**
 * 查询人群包列表
 */
export class ListSegmentsDto {
  @IsOptional()
  @IsEnum(SegmentUsageType)
  usageType?: SegmentUsageType;

  @IsOptional()
  @IsBoolean()
  isEnabled?: boolean;

  @IsOptional()
  @IsInt()
  @Min(1)
  @Max(100)
  limit?: number;

  @IsOptional()
  @IsInt()
  @Min(0)
  offset?: number;
}

/**
 * 测试用户是否匹配人群包
 */
export class TestSegmentDto {
  @IsString()
  accountSequence: string;
}

/**
 * 预估人群包用户数
 */
export class EstimateSegmentDto {
  @IsObject()
  conditions: SegmentConditionGroup;
}

/**
 * 获取人群包用户列表
 */
export class GetSegmentUsersDto {
  @IsOptional()
  @IsInt()
  @Min(1)
  @Max(100)
  limit?: number;

  @IsOptional()
  @IsInt()
  @Min(0)
  offset?: number;
}
