import { AxiosInstance } from 'axios'; import { HttpInstanceFactory } from '@/utils/HttpInstanceFactory'; import { IPlayer } from '@/interfaces/player.type'; export interface IConfig { id: number; attributes: { farm_amount: number; farming_time: number; admins: { data: IPlayer[] }; }; } export class ConfigApi { private static instance: ConfigApi | null = null; private httpInstance: AxiosInstance; private constructor(token: string, shouldUpdateInstance: boolean = false) { this.httpInstance = HttpInstanceFactory.getAuthorizedInstance(token); } public static getInstance(token: string, shouldUpdateInstance: boolean = false): ConfigApi { if (!shouldUpdateInstance && this.instance) { return this.instance; } this.instance = new ConfigApi(token); return this.instance; } async getConfig(): Promise<{ data: IConfig }> { return (await this.httpInstance.get<{ data: IConfig }>(`/config?populate=*`)).data; } }