"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRampServiceProviders = exports.isCurrencyInCatalog = exports.getCryptoCurrencyIds = void 0;
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
const uniq_1 = __importDefault(require("lodash/uniq"));
/** Flatten all providers' currencies into a single array */
function getCryptoCurrencyIds(entries) {
    if (!entries || (0, isEmpty_1.default)(entries)) {
        return null;
    }
    return (0, uniq_1.default)(Object.values(entries).flat());
}
exports.getCryptoCurrencyIds = getCryptoCurrencyIds;
function isCurrencyInCatalog(currencyId, catalog, status) {
    if (!catalog || (0, isEmpty_1.default)(catalog[status])) {
        return false;
    }
    const currencies = getCryptoCurrencyIds(catalog[status]);
    return !currencies ? false : currencies.includes(currencyId);
}
exports.isCurrencyInCatalog = isCurrencyInCatalog;
/** Get the array of providers in the catalog that support the given currency */
function getRampServiceProviders(currencyId, catalog) {
    if (!catalog || (0, isEmpty_1.default)(catalog)) {
        return null;
    }
    const providers = Object.keys(catalog).filter(provider => catalog[provider].includes(currencyId));
    return providers;
}
exports.getRampServiceProviders = getRampServiceProviders;
//# sourceMappingURL=helpers.js.map