"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSubscribers = void 0;
const tslib_1 = require("tslib");
const axios_1 = require("axios");
const helpers_1 = require("../helpers");
const constants_1 = require("../constants");
const getSubscribers = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
    const { channel, page = 1, limit = 10, category = null, setting = false, env = constants_1.default.ENV.PROD, } = options || {};
    try {
        if (channel == null || channel.length == 0) {
            throw new Error(`channel cannot be null or empty`);
        }
        if (page <= 0) {
            throw new Error("page must be greater than 0");
        }
        if (limit <= 0) {
            throw new Error("limit must be greater than 0");
        }
        if (limit > 30) {
            throw new Error("limit must be lesser than or equal to 30");
        }
        const _channel = yield (0, helpers_1.getCAIPAddress)(env, channel, 'Channel');
        const API_BASE_URL = (0, helpers_1.getAPIBaseUrls)(env);
        let apiEndpoint = `${API_BASE_URL}/v1/channels/${_channel}/subscribers?page=${page}&limit=${limit}&setting=${setting}`;
        if (category) {
            apiEndpoint = apiEndpoint + `&category=${category}`;
        }
        return yield axios_1.default.get(apiEndpoint)
            .then((response) => response.data)
            .catch((err) => {
            console.error(`[Push SDK] - API ${apiEndpoint}: `, err);
        });
    }
    catch (err) {
        console.error(`[Push SDK] - API  - Error - API send() -:  `, err);
        throw Error(`[Push SDK] - API  - Error - API send() -: ${err}`);
    }
});
exports.getSubscribers = getSubscribers;
//# sourceMappingURL=getSubscribers.js.map