'use strict';
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var RESTWebinar_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RESTWebinar = void 0;
const Utils_1 = require("../../common/Utils");
const GenericRESTService_1 = require("../GenericRESTService");
const ErrorCase = require('../../common/ErrorManager');
const util = require('util');
const LOG_ID = "REST/WEBINAR - ";
let RESTWebinar = RESTWebinar_1 = class RESTWebinar extends GenericRESTService_1.GenericRESTService {
    static getClassName() {
        return 'RESTWebinar';
    }
    getClassName() {
        return RESTWebinar_1.getClassName();
    }
    static getAccessorName() { return 'restwebinar'; }
    getAccessorName() { return RESTWebinar_1.getAccessorName(); }
    constructor(evtEmitter, _logger) {
        super(_logger, LOG_ID);
        this.setLogLevels(this);
        let that = this;
        that.evtEmitter = evtEmitter;
        that._logger = _logger;
    }
    start(http) {
        return new Promise((resolve) => {
            let that = this;
            that.http = http;
            resolve(undefined);
        });
    }
    stop() {
        return new Promise((resolve) => {
            let that = this;
            resolve(undefined);
        });
    }
    //region Webinar
    createWebinar(name, subject, waitingRoomStartDate, webinarStartDate, webinarEndDate, reminderDates, timeZone, register, approvalRegistrationMethod, passwordNeeded, isOrganizer, waitingRoomMultimediaURL, stageBackground, chatOption) {
        // POST  https://openrainbow.com/api/rainbow/webinar/v1.0/webinars
        let that = this;
        return new Promise(function (resolve, reject) {
            let url = "/api/rainbow/webinar/v1.0/webinars";
            /*let urlParamsTab : string[]= [];
            urlParamsTab.push(url);
            addParamToUrl(urlParamsTab, "companyId", companyId);
            addParamToUrl(urlParamsTab, "label", label);
            url = urlParamsTab[0];
            // */
            let data = { name,
                subject,
                waitingRoomStartDate,
                webinarStartDate,
                webinarEndDate,
                reminderDates,
                timeZone,
                register,
                approvalRegistrationMethod,
                passwordNeeded,
                isOrganizer,
                waitingRoomMultimediaURL,
                stageBackground,
                chatOption };
            (0, Utils_1.cleanEmptyMembersFromObject)(data);
            that._logger.log(that.INTERNAL, LOG_ID + "(createWebinar) args : ", data);
            that.http.post(url, that.getPostHeader(), JSON.stringify(data), undefined).then(function (json) {
                that._logger.log(that.DEBUG, LOG_ID + "(createWebinar) successfull");
                that._logger.log(that.INTERNAL, LOG_ID + "(createWebinar) REST leave bubble : ", json.data);
                resolve(json.data);
            }).catch(function (err) {
                that._logger.log(that.ERROR, LOG_ID, "(createWebinar) error.");
                that._logger.log(that.INTERNALERROR, LOG_ID, "(createWebinar) error : ", err);
                return reject(err);
            });
        });
    }
    updateWebinar(webinarId, name, subject, waitingRoomStartDate, webinarStartDate, webinarEndDate, reminderDates, timeZone, register, approvalRegistrationMethod, passwordNeeded, isOrganizer, waitingRoomMultimediaURL, stageBackground, chatOption) {
        // PUT  https://openrainbow.com/api/rainbow/webinar/v1.0/webinars/:webinarId
        let that = this;
        return new Promise(function (resolve, reject) {
            let url = "/api/rainbow/webinar/v1.0/webinars/" + webinarId;
            /*let urlParamsTab : string[]= [];
            urlParamsTab.push(url);
            addParamToUrl(urlParamsTab, "companyId", companyId);
            addParamToUrl(urlParamsTab, "label", label);
            url = urlParamsTab[0];
            // */
            let data = { name,
                subject,
                waitingRoomStartDate,
                webinarStartDate,
                webinarEndDate,
                reminderDates,
                timeZone,
                register,
                approvalRegistrationMethod,
                passwordNeeded,
                isOrganizer,
                waitingRoomMultimediaURL,
                stageBackground,
                chatOption };
            (0, Utils_1.cleanEmptyMembersFromObject)(data);
            if (Array.isArray(reminderDates) && reminderDates.length == 0) {
                delete data["reminderDates"];
            }
            that._logger.log(that.INTERNAL, LOG_ID + "(createWebinar) args : ", data);
            that.http.put(url, that.getPostHeader(), JSON.stringify(data), undefined).then(function (json) {
                that._logger.log(that.DEBUG, LOG_ID + "(createWebinar) successfull");
                that._logger.log(that.INTERNAL, LOG_ID + "(createWebinar) REST leave bubble : ", json.data);
                resolve(json.data);
            }).catch(function (err) {
                that._logger.log(that.ERROR, LOG_ID, "(createWebinar) error.");
                that._logger.log(that.INTERNALERROR, LOG_ID, "(createWebinar) error : ", err);
                return reject(err);
            });
        });
    }
    getWebinarData(webinarId) {
        // GET  https://openrainbow.com/api/rainbow/webinar/v1.0/webinars/:webinarId
        let that = this;
        return new Promise(function (resolve, reject) {
            let url = "/api/rainbow/webinar/v1.0/webinars/" + webinarId;
            /*let urlParamsTab: string[] = [];
            urlParamsTab.push(url);
            addParamToUrl(urlParamsTab, "role", role );
            url = urlParamsTab[0];
            // */
            that._logger.log(that.INTERNAL, LOG_ID + "(getWebinarData) REST url : ", url);
            that.http.get(url, that.getRequestHeader(), undefined).then((json) => {
                that._logger.log(that.DEBUG, LOG_ID + "(getWebinarData) successfull");
                that._logger.log(that.INTERNAL, LOG_ID + "(getWebinarData) REST result : ", json);
                resolve(json.data);
            }).catch(function (err) {
                that._logger.log(that.ERROR, LOG_ID, "(getWebinarData) error");
                that._logger.log(that.INTERNALERROR, LOG_ID, "(getWebinarData) error : ", err);
                return reject(err);
            });
        });
    }
    getWebinarsData(role) {
        // GET  https://openrainbow.com/api/rainbow/webinar/v1.0/webinars
        let that = this;
        return new Promise(function (resolve, reject) {
            let url = "/api/rainbow/webinar/v1.0/webinars/";
            let urlParamsTab = [];
            urlParamsTab.push(url);
            (0, Utils_1.addParamToUrl)(urlParamsTab, "role", role);
            url = urlParamsTab[0];
            that._logger.log(that.INTERNAL, LOG_ID + "(getWebinarsData) REST url : ", url);
            that.http.get(url, that.getRequestHeader(), undefined).then((json) => {
                that._logger.log(that.DEBUG, LOG_ID + "(getWebinarsData) successfull");
                that._logger.log(that.INTERNAL, LOG_ID + "(getWebinarsData) REST result : ", json);
                resolve(json);
            }).catch(function (err) {
                that._logger.log(that.ERROR, LOG_ID, "(getWebinarsData) error");
                that._logger.log(that.INTERNALERROR, LOG_ID, "(getWebinarsData) error : ", err);
                return reject(err);
            });
        });
    }
    warnWebinarModerators(webinarId) {
        // PUT  https://openrainbow.com/api/rainbow/webinar/v1.0/webinars/:webinarId/warn-moderators
        let that = this;
        return new Promise(function (resolve, reject) {
            let url = "/api/rainbow/webinar/v1.0/webinars/" + webinarId + "/warn-moderators";
            /*let urlParamsTab : string[]= [];
            urlParamsTab.push(url);
            addParamToUrl(urlParamsTab, "companyId", companyId);
            addParamToUrl(urlParamsTab, "label", label);
            url = urlParamsTab[0];
            // */
            let data = undefined;
            that._logger.log(that.INTERNAL, LOG_ID + "(warnWebinarModerators) args : ", data);
            that.http.put(url, that.getPostHeader(), data, undefined).then(function (json) {
                that._logger.log(that.DEBUG, LOG_ID + "(warnWebinarModerators) successfull");
                that._logger.log(that.INTERNAL, LOG_ID + "(warnWebinarModerators) REST leave bubble : ", json.data);
                resolve(json.data);
            }).catch(function (err) {
                that._logger.log(that.ERROR, LOG_ID, "(warnWebinarModerators) error.");
                that._logger.log(that.INTERNALERROR, LOG_ID, "(warnWebinarModerators) error : ", err);
                return reject(err);
            });
        });
    }
    publishAWebinarEvent(webinarId) {
        // PUT  https://openrainbow.com/api/rainbow/webinar/v1.0/webinars/:webinarId/publish
        let that = this;
        return new Promise(function (resolve, reject) {
            let url = "/api/rainbow/webinar/v1.0/webinars/" + webinarId + "/publish";
            /*let urlParamsTab : string[]= [];
            urlParamsTab.push(url);
            addParamToUrl(urlParamsTab, "companyId", companyId);
            addParamToUrl(urlParamsTab, "label", label);
            url = urlParamsTab[0];
            // */
            let data = undefined;
            that._logger.log(that.INTERNAL, LOG_ID + "(publishAWebinarEvent) args : ", data);
            that.http.put(url, that.getPostHeader(), data, undefined).then(function (json) {
                that._logger.log(that.DEBUG, LOG_ID + "(publishAWebinarEvent) successfull");
                that._logger.log(that.INTERNAL, LOG_ID + "(publishAWebinarEvent) REST leave bubble : ", json.data);
                resolve(json.data);
            }).catch(function (err) {
                that._logger.log(that.ERROR, LOG_ID, "(publishAWebinarEvent) error.");
                that._logger.log(that.INTERNALERROR, LOG_ID, "(publishAWebinarEvent) error : ", err);
                return reject(err);
            });
        });
    }
    deleteWebinar(webinarId) {
        // DELETE https://openrainbow.com/api/rainbow/webinar/v1.0/webinars/:webinarId     
        let that = this;
        return new Promise((resolve, reject) => {
            let url = "/api/rainbow/webinar/v1.0/webinars/" + webinarId;
            /*let urlParamsTab : string[]= [];
            urlParamsTab.push(url);
            addParamToUrl(urlParamsTab, "companyId", companyId);
            addParamToUrl(urlParamsTab, "tag", tag);
            url = urlParamsTab[0];
            // */
            that.http.delete(url, that.getRequestHeader())
                .then((response) => {
                that._logger.log(that.DEBUG, LOG_ID + "(deleteWebinar) (" + webinarId + ") -- success");
                resolve(response);
            })
                .catch((err) => {
                that._logger.log(that.ERROR, LOG_ID, "(deleteWebinar) (" + webinarId + ") -- failure -- ");
                that._logger.log(that.INTERNALERROR, LOG_ID, "(deleteWebinar) (" + webinarId + ") -- failure -- ", err.message);
                return reject(err);
            });
        });
    }
};
exports.RESTWebinar = RESTWebinar;
exports.RESTWebinar = RESTWebinar = RESTWebinar_1 = __decorate([
    (0, Utils_1.logEntryExit)(LOG_ID)
], RESTWebinar);
let restService = null;
module.exports.RESTWebinar = RESTWebinar;
//# sourceMappingURL=RESTWebinar.js.map