"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Device = void 0;
const DeviceSchemas_1 = require("../../schemas/device/DeviceSchemas");
class Device {
    constructor(values) {
        Object.assign(this, values);
    }
    isValid() {
        return (0, DeviceSchemas_1.schema)(this.type).isValid(this);
    }
    validate() {
        return (0, DeviceSchemas_1.schema)(this.type).validate(this);
    }
    get payload() {
        if (this.remote)
            return this.remote;
        if (this.plugin)
            return this.plugin;
        if (this.play)
            return this.play;
        if (this.say)
            return this.say;
        if (this.client)
            return this.client;
        if (this.teams)
            return this.teams;
        if (this.sipExtension)
            return this.sipExtension;
        if (this.sipGateway)
            return this.sipGateway;
        if (this.aniRouter)
            return this.aniRouter;
        if (this.dnisRouter)
            return this.dnisRouter;
        if (this.startRoute)
            return this.startRoute;
        if (this.regexRoute)
            return this.regexRoute;
        if (this.numberPlan)
            return this.numberPlan;
        if (this.zoneRouter)
            return this.zoneRouter;
        if (this.huntGroup)
            return this.huntGroup;
        if (this.timeRangeRoute)
            return this.timeRangeRoute;
        if (this.dayOfWeekRoute)
            return this.dayOfWeekRoute;
        if (this.dateRangeRoute)
            return this.dateRangeRoute;
        if (this.script)
            return this.script;
        if (this.queue)
            return this.queue;
        return null;
    }
    get connects() {
        const arr = [];
        if (this.payload) {
            const { connectTo, onMatch, onError, onTransfer, onBusy, onNoAnswer, onFail, onComplete } = this.payload;
            if (connectTo)
                arr.push({ type: 'connectTo', connect: connectTo });
            if (onMatch)
                arr.push({ type: 'onMatch', connect: onMatch });
            if (onError)
                arr.push({ type: 'onError', connect: onError });
            if (onTransfer)
                arr.push({ type: 'onTransfer', connect: onTransfer });
            if (onBusy)
                arr.push({ type: 'onBusy', connect: onBusy });
            if (onNoAnswer)
                arr.push({ type: 'onNoAnswer', connect: onNoAnswer });
            if (onFail)
                arr.push({ type: 'onFail', connect: onFail });
            if (onComplete)
                arr.push({ type: 'onComplete', connect: onComplete });
        }
        return arr;
    }
}
exports.Device = Device;
