import type {FightStats, Ranking, UserStats} from "../types/stats.ts";
import {fetchWithToken} from "./repo.ts";
import {FightStatsSchema, RankingSchema, UserStatsSchema} from "../types/stats.ts";

export class StatsRepo {

    constructor(private token: string) {}

    public async getRankings(gamemode: string): Promise<Ranking> {
        return await fetchWithToken(this.token, `/stats/ranked/${gamemode}`).then(value => value.json()).then(RankingSchema.parse);
    }

    public async getFightStats(): Promise<FightStats> {
        return await fetchWithToken(this.token, `/stats/fights`).then(value => value.json()).then(FightStatsSchema.parse);
    }

    public async getUserStats(id: number): Promise<UserStats> {
        return await fetchWithToken(this.token, `/stats/user/${id}`).then(value => value.json()).then(UserStatsSchema.parse);
    }
}