import type {Player, Server} from "../types/data.ts";
import {PlayerSchema, ServerSchema} from "../types/data.ts";
import {fetchWithToken} from "./repo.ts";

export class DataRepo {
    constructor(private token: string) {}

    public async getServer(): Promise<Server> {
        return await fetchWithToken(this.token, "/data/server").then(value => value.json()).then(ServerSchema.parse);
    }

    public async getMe(): Promise<Player> {
        return await fetchWithToken(this.token, "/data/me").then(value => value.json()).then(PlayerSchema.parse);
    }
}