import POGOProtos from 'pogo-protos';

import { AjaxRequest } from 'api/AjaxRequest';

import { IConfig } from 'app/models/Config';
import { ILeaguePokemon } from 'app/models/League';
import { IPokemon } from 'app/models/Pokemon';

interface IPokemonService {
    getConfig() : Promise<IConfig>;
    getPokemonList() : Promise<Array<IPokemon>>;
    getPokemonLeagueStats(pokemonId : POGOProtos.Enums.PokemonId, form : POGOProtos.Enums.Form) : Promise<ILeaguePokemon>;
}

export class PokemonService implements IPokemonService {
    private AjaxRequest : AjaxRequest;

    constructor() {
        this.AjaxRequest = new AjaxRequest(XMLHttpRequest);
    }

    public async getConfig() {
        const queryParameters = {
        };

        const response : IConfig = await this.AjaxRequest.ajaxGet('/dist/db/config.json', queryParameters);
        return response;
    }

    public async getPokemonList() {
        const queryParameters = {
        };

        const response : Array<IPokemon> = await this.AjaxRequest.ajaxGet('/dist/db/order.json', queryParameters);
        return response;
    }

    public async getPokemonLeagueStats(pokemonId : POGOProtos.Enums.PokemonId, form : POGOProtos.Enums.Form) {
        const fileName = form === POGOProtos.Enums.Form.FORM_UNSET ? POGOProtos.Enums.PokemonId[pokemonId] : POGOProtos.Enums.Form[form];

        const queryParameters = {
        };

        const response : ILeaguePokemon = await this.AjaxRequest.ajaxGet(`/dist/db/${ fileName }.json`, queryParameters);
        return response;
    }
}
