"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.rankCard = rankCard;
const rank_1 = require("../composers/rank");
const errors_1 = require("../errors");
const discord_api_1 = require("../services/discord-api");
async function rankCard(userId, options) {
    if (!userId || typeof userId !== 'string') {
        throw new errors_1.KythiaArtsError(`TypeError: Invalid argument for rankCard()\nExpected string userId, got ${typeof userId === 'undefined' || !userId ? 'undefined' : typeof userId}`);
    }
    if (!options.botToken) {
        throw new errors_1.KythiaArtsError('A bot token is required. Pass it via options.botToken.');
    }
    try {
        const data = await (0, discord_api_1.fetchUserData)(userId, options.botToken);
        const buffer = await (0, rank_1.genPng)(data, options);
        return buffer;
    }
    catch (error) {
        if (error instanceof Error) {
            const msg = error.message.toLowerCase();
            if (msg.includes('source rejected') ||
                msg.includes('503') ||
                msg.includes('502') ||
                msg.includes('504') ||
                msg.includes('failed to load')) {
                throw new errors_1.KythiaArtsError('Error loading user assets, try again later');
            }
            throw new errors_1.KythiaArtsError(error.message);
        }
        throw new errors_1.KythiaArtsError('Unknown error occurred');
    }
}
exports.default = rankCard;
//# sourceMappingURL=rank.js.map