"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InternalError = exports.AuthError = exports.TestingError = exports.CompilerError = exports.NotFoundError = exports.ValidationError = exports.getSolution = void 0;
const console_1 = require("./console");
const solutions = {
    "install-jest": {
        gif: "",
        video: "",
        message: "You need to install jest",
    },
};
const uknown = {
    video: "https://www.youtube.com/watch?v=gD1Sa99GiE4",
    message: "Uknown internal error",
    slug: "uknown",
    gif: "https://github.com/breatheco-de/breathecode-cli/blob/master/docs/errors/uknown.gif?raw=true",
};
const getSolution = (slug) => {
    if (!slug) {
        console_1.default.debug("Getting solution templates from the learnpack repository");
    }
    else {
        console_1.default.debug(`Getting solution for ${slug}`, solutions);
    }
    return typeof solutions[slug || ""] === "undefined" || !slug ?
        uknown :
        solutions[slug];
};
exports.getSolution = getSolution;
const ValidationError = (error) => {
    const message = error.message || error;
    const _err = new Error(message);
    _err.status = 400;
    _err.type = "validation-error";
    const sol = (0, exports.getSolution)(error.slug);
    _err.video = sol.video;
    _err.gif = sol.gif;
    _err.message = typeof message === "string" ? message : sol.message;
    return _err;
};
exports.ValidationError = ValidationError;
const NotFoundError = (error) => {
    const message = error.message || error;
    const _err = new Error(message);
    _err.status = 400;
    _err.type = "not-found-error";
    const sol = (0, exports.getSolution)(error.slug);
    _err.video = sol.video;
    _err.gif = sol.gif;
    _err.message = typeof message === "string" ? message : sol.message;
    return _err;
};
exports.NotFoundError = NotFoundError;
const CompilerError = (error) => {
    const message = error.message || error;
    const _err = new Error(message);
    _err.status = 400;
    _err.type = "compiler-error";
    const sol = (0, exports.getSolution)(error.slug);
    _err.video = sol.video;
    _err.gif = sol.gif;
    _err.message = typeof message === "string" ? message : sol.message;
    return _err;
};
exports.CompilerError = CompilerError;
const TestingError = (error) => {
    const message = error.message || error;
    const _err = new Error(message);
    _err.status = 400;
    _err.type = "testing-error";
    return _err;
};
exports.TestingError = TestingError;
const AuthError = (error) => {
    const message = error.message || error;
    const _err = new Error(message);
    _err.status = 403;
    _err.type = "auth-error";
    return _err;
};
exports.AuthError = AuthError;
const InternalError = (error) => {
    const message = error.message || error;
    const _err = new Error(message);
    _err.status = 500;
    _err.type = "internal-error";
    const sol = (0, exports.getSolution)(error.slug);
    _err.video = sol.video;
    _err.gif = sol.gif;
    _err.message = typeof message === "string" ? message : sol.message;
    return _err;
};
exports.InternalError = InternalError;
(0, exports.getSolution)();
exports.default = {
    ValidationError: exports.ValidationError,
    CompilerError: exports.CompilerError,
    TestingError: exports.TestingError,
    NotFoundError: exports.NotFoundError,
    InternalError: exports.InternalError,
    AuthError: exports.AuthError,
};
