import {
  ClassificationRuleEntity,
  RuleConditions,
} from '../../../domain/entities/classification-rule.entity';

/**
 * 规则响应
 */
export class RuleResponseDto {
  id: string;
  name: string;
  description: string | null;
  conditions: RuleConditions;
  isEnabled: boolean;
  linkedTagId: string | null;
  linkedTagCode: string | null;
  createdAt: string;
  updatedAt: string;

  static fromEntity(
    entity: ClassificationRuleEntity,
    linkedTag?: { tagId: string; tagCode: string } | null,
  ): RuleResponseDto {
    return {
      id: entity.id,
      name: entity.name,
      description: entity.description,
      conditions: entity.conditions,
      isEnabled: entity.isEnabled,
      linkedTagId: linkedTag?.tagId ?? null,
      linkedTagCode: linkedTag?.tagCode ?? null,
      createdAt: entity.createdAt.toISOString(),
      updatedAt: entity.updatedAt.toISOString(),
    };
  }
}

/**
 * 规则列表响应
 */
export class RuleListResponseDto {
  items: RuleResponseDto[];
  total: number;
}

/**
 * 规则测试结果响应
 */
export class RuleTestResultDto {
  ruleId: string;
  ruleName: string;
  accountSequence: string;
  matched: boolean;
  evaluatedConditions: Array<{
    field: string;
    operator: string;
    expectedValue: unknown;
    actualValue: unknown;
    matched: boolean;
  }>;
}

/**
 * 规则预估结果响应
 */
export class RuleEstimateResultDto {
  estimatedUsers: number;
  sampleUsers: string[];
}
