"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseImg = parseImg;
exports.parsePng = parsePng;
exports.parseHex = parseHex;
exports.isString = isString;
exports.isNumber = isNumber;
const index_1 = require("../errors/index");
function parseImg(imgString) {
    if (!imgString || typeof imgString !== 'string') {
        throw new index_1.KythiaArtsError(`Invalid custom badge ('${imgString || undefined}') must be an image file 'png | jpg | jpeg | gif'`);
    }
    const URL = imgString.split('.');
    const imgType = URL[URL.length - 1];
    const imgCheck = /(jpg|jpeg|png|gif)/gi.test(imgType ?? '');
    if (!imgCheck) {
        throw new index_1.KythiaArtsError(`Invalid customBackground ('${imgString || undefined}') must be an image file 'png | jpg | jpeg | gif'`);
    }
    return imgString;
}
function parsePng(imgString) {
    if (!imgString || typeof imgString !== 'string') {
        throw new index_1.KythiaArtsError(`Invalid custom badge ('${imgString || undefined}') must be a png file`);
    }
    const URL = imgString.split('.');
    const imgType = URL[URL.length - 1];
    const imgCheck = /(png)/gi.test(imgType ?? '');
    if (!imgCheck) {
        throw new index_1.KythiaArtsError(`Invalid custom badge ('${imgString || undefined}') must be a png file`);
    }
    return imgString;
}
function parseHex(hexString) {
    const hexRegex = new RegExp(/^(#)?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$/);
    if (!hexRegex.test(hexString)) {
        throw new index_1.KythiaArtsError(`Invalid Hex Code ('${hexString || undefined}')`);
    }
    let normalizedHex = hexString;
    if (!hexString.includes('#') && !hexString.startsWith('#')) {
        normalizedHex = `#${hexString}`;
    }
    return normalizedHex;
}
function isString(param, type) {
    if (typeof param !== 'string') {
        throw new index_1.KythiaArtsError(`Invalid ${type} (${param || undefined}), must be a string`);
    }
    return param;
}
function isNumber(param, type) {
    if (typeof param !== 'number' || Number.isNaN(param)) {
        throw new index_1.KythiaArtsError(`Invalid ${type} (${param || undefined}), must be a number`);
    }
    return param;
}
//# sourceMappingURL=validation.js.map