import {
  AudienceSegmentEntity,
  SegmentConditionGroup,
  SegmentUsageType,
} from '../../../domain/entities/audience-segment.entity';

/**
 * 人群包响应
 */
export class SegmentResponseDto {
  id: string;
  name: string;
  description: string | null;
  conditions: SegmentConditionGroup;
  estimatedUsers: number | null;
  lastCalculated: string | null;
  usageType: SegmentUsageType;
  isEnabled: boolean;
  createdAt: string;
  updatedAt: string;
  createdBy: string;

  static fromEntity(entity: AudienceSegmentEntity): SegmentResponseDto {
    return {
      id: entity.id,
      name: entity.name,
      description: entity.description,
      conditions: entity.conditions,
      estimatedUsers: entity.estimatedUsers,
      lastCalculated: entity.lastCalculated?.toISOString() ?? null,
      usageType: entity.usageType,
      isEnabled: entity.isEnabled,
      createdAt: entity.createdAt.toISOString(),
      updatedAt: entity.updatedAt.toISOString(),
      createdBy: entity.createdBy,
    };
  }
}

/**
 * 人群包列表响应
 */
export class SegmentListResponseDto {
  items: SegmentResponseDto[];
  total: number;
}

/**
 * 人群包测试结果
 */
export class SegmentTestResultDto {
  segmentId: string;
  segmentName: string;
  accountSequence: string;
  matched: boolean;
}

/**
 * 人群包预估结果
 */
export class SegmentEstimateResultDto {
  estimatedUsers: number;
  sampleUsers: string[];
}

/**
 * 人群包用户列表
 */
export class SegmentUsersResponseDto {
  segmentId: string;
  users: string[];
  total: number;
}

/**
 * 用户匹配的人群包列表
 */
export class UserSegmentsResponseDto {
  accountSequence: string;
  segments: Array<{
    segmentId: string;
    segmentName: string;
    matched: boolean;
  }>;
}
