/**
 * Pure domain service — calculates quality score from inputs.
 * No infrastructure dependencies.
 */
export class QualityScoreCalculator {
  /**
   * Quality Score = weighted average of:
   * - Review rating (40%) — avg rating normalized to 0-100
   * - Response time (30%) — inverse of avg response time, 0-100
   * - Lead conversion (20%) — conversion rate * 100
   * - Listing activity (10%) — active listings ratio * 100
   */
  static calculate(params: {
    avgRating: number; // 0-5
    totalReviews: number;
    responseTimeAvg: number | null; // seconds
    conversionRate: number; // 0-1
    activeListingRatio: number; // 0-1
  }): number {
    const ratingScore =
      params.totalReviews > 0 ? (params.avgRating / 5) * 100 : 50;
    const responseScore =
      params.responseTimeAvg !== null
        ? Math.max(0, 100 - (params.responseTimeAvg / 3600) * 100) // 1hr = 0
        : 50;
    const conversionScore = params.conversionRate * 100;
    const listingScore = params.activeListingRatio * 100;

    const score =
      ratingScore * 0.4 +
      responseScore * 0.3 +
      conversionScore * 0.2 +
      listingScore * 0.1;

    return Math.round(score * 10) / 10; // 1 decimal
  }
}
