import {UserDetails} from './userDetails';
import {SimilarReplay, SuspiciousScore} from './replays';
import {environment} from "../environments/environment";

export class TextReportService {

  static generateTextReportForUserScores(
    userDetails: UserDetails,
    suspiciousScores: SuspiciousScore[],
    similarReplays: SimilarReplay[],
  ) {
    const site = 'nise.stedos.dev';

    const detections: string[] = [];

    if (suspiciousScores.length > 0) {
      detections.push('Relax');
    }

    if (similarReplays.length > 0) {
      detections.push('Replay Stealing');
    }

    let report = `[osu!std] ${userDetails.username} | ${detections.join(', ')}\n\n`;
    report += `Profile: https://osu.ppy.sh/users/${userDetails.user_id}\n`;

    for (const suspiciousScore of suspiciousScores) {
      report += `\n\n${this.getRelaxReport(suspiciousScore)}\n`;
    }

    for (const similarReplay of similarReplays) {
      report += `\n\n${this.getStealingReport(similarReplay)}\n`;
    }

    report += `\n\nGenerated on ${site} - [${userDetails.username} profile](${environment.webUrl}/u/${userDetails.user_id})`;

    return report;
  }

  private static getRelaxReport(suspiciousScore: SuspiciousScore): string {
    return `[Replay on ${suspiciousScore.beatmap_title}](https://osu.ppy.sh/scores/osu/${suspiciousScore.replay_id})

cvUR: ${suspiciousScore.ur.toFixed(2)} according to Circleguard`;
  }

  private static getStealingReport(similarReplay: SimilarReplay): string {
    return `[${similarReplay.username_2}'s replay (cheated)](https://osu.ppy.sh/scores/osu/${similarReplay.replay_id_2})

[${similarReplay.username_1}'s replay (original)](https://osu.ppy.sh/scores/osu/${similarReplay.replay_id_1})

${similarReplay.similarity.toFixed(2)} similarity according to Circleguard`;
  }
}
