"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getItem = exports.getQuest = exports.getQuests = exports.getGatherNode = exports.getGatherNodes = exports.GatherNodeType = exports.getData = void 0;
const axios_1 = __importDefault(require("axios"));
const axios = axios_1.default.create({
    baseURL: "https://garlandtools.cn/"
});
const dataCache = {
    time: null,
    cache: null
};
async function getData(useCache = true, refreshDuration = 2 * 60 * 60 * 1000) {
    if (!dataCache.time || !dataCache.cache || new Date().getTime() - dataCache.time.getTime() > refreshDuration) {
        const result = await axios.request({
            method: "GET",
            url: "/db/doc/core/chs/3/data.json"
        });
        dataCache.time = new Date();
        dataCache.cache = result.data;
    }
    return dataCache.cache;
}
exports.getData = getData;
var GatherNodeType;
(function (GatherNodeType) {
    GatherNodeType[GatherNodeType["DEPOSIT"] = 0] = "DEPOSIT";
    GatherNodeType[GatherNodeType["OUTCROP"] = 1] = "OUTCROP";
    GatherNodeType[GatherNodeType["TREE"] = 2] = "TREE";
    GatherNodeType[GatherNodeType["VEGETATION"] = 3] = "VEGETATION"; // 草场
})(GatherNodeType = exports.GatherNodeType || (exports.GatherNodeType = {}));
async function getGatherNodes() {
    const result = await axios.request({
        method: "GET",
        url: "/db/doc/browse/chs/2/node.json"
    });
    return result.data.browse;
}
exports.getGatherNodes = getGatherNodes;
async function getGatherNode(id) {
    const result = await axios.request({
        method: "GET",
        url: `/db/doc/node/chs/2/${id}.json`
    });
    return result.data;
}
exports.getGatherNode = getGatherNode;
async function getQuests() {
    const result = await axios.request({
        method: "GET",
        url: "/db/doc/browse/chs/2/quest.json"
    });
    return result.data.browse;
}
exports.getQuests = getQuests;
async function getQuest(id) {
    const result = await axios.request({
        method: "GET",
        url: `/db/doc/quest/chs/2/${id}.json`
    });
    return result.data;
}
exports.getQuest = getQuest;
async function getItem(id) {
    const result = await axios.request({
        method: "GET",
        url: `/db/doc/item/chs/3/${id}.json`
    });
    return result.data;
}
exports.getItem = getItem;
