"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IccRoleApi = void 0;
const XHR_1 = require("./XHR");
const AuthenticationProvider_1 = require("../../icc-x-api/auth/AuthenticationProvider");
const Role_1 = require("../model/Role");
const IccRestApiPath_1 = require("./IccRestApiPath");
class IccRoleApi {
    constructor(host, headers, authenticationProvider, fetchImpl) {
        this.host = (0, IccRestApiPath_1.iccRestApiPath)(host);
        this.headers = Object.keys(headers).map((k) => new XHR_1.XHR.Header(k, headers[k]));
        this.authenticationProvider = !!authenticationProvider ? authenticationProvider : new AuthenticationProvider_1.NoAuthenticationProvider();
        this.fetchImpl = fetchImpl;
    }
    handleError(e) {
        throw e;
    }
    /**
     *
     * @summary Gets all roles
     */
    getRoles() {
        return __awaiter(this, void 0, void 0, function* () {
            const _url = this.host + `/role` + '?ts=' + new Date().getTime();
            let headers = this.headers;
            return XHR_1.XHR.sendCommand('GET', _url, headers, null, this.fetchImpl, undefined, this.authenticationProvider.getAuthService())
                .then((doc) => doc.body.map((it) => new Role_1.Role(it)))
                .catch((err) => this.handleError(err));
        });
    }
}
exports.IccRoleApi = IccRoleApi;
//# sourceMappingURL=IccRoleApi.js.map