RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Models/Site/AlarmGroupModel.js

/**
 * File Auto-Generated by the RICADO Gen 4 PHP API Project
 * 
 * Do Not Edit this File Manually!
 */

import BaseModel from '../../Models/BaseModel';

/**
 * Model Class for a Alarm Group
 * 
 * @class
 * @hideconstructor
 * @extends BaseModel
 */
class AlarmGroupModel extends BaseModel
{
    /**
     * AlarmGroupModel Constructor
     * 
     * @protected
     * @param {number} siteId The Site ID associated with this Alarm Group
     */
    constructor(siteId)
    {
        super();
        
        /**
         * The Alarm Group ID
         * 
         * @type {string}
         * @public
         */
        this.id = "";
        
        /**
         * The RTU this Alarm Group belongs to
         * 
         * @type {?number}
         * @public
         */
        this.rtuId = null;
        
        /**
         * The Alarm Group Name
         * 
         * @type {string}
         * @public
         */
        this.name = "";
        
        /**
         * The Boolean Point used to Reset this Alarm Group
         * 
         * @type {number}
         * @public
         */
        this.resetPoint = 0;
        
        /**
         * An Array of Points and the States to be Written when this Alarm Group is Reset
         * 
         * @type {Array<{point: number, value: boolean}>}
         * @public
         */
        this.externalResetPoints = [];
        
        /**
         * Whether the Alarm Group has been deleted
         * 
         * @type {boolean}
         * @public
         */
        this.deleted = false;
        
        /**
         * When the Alarm Group was last updated
         * 
         * @type {Date}
         * @public
         */
        this.updateTimestamp = new Date();
        
        /**
         * The Site ID associated with this Alarm Group
         * 
         * @type {number}
         * @public
         */
        this.siteId = siteId;
    }

    /**
     * Create a new **AlarmGroupModel** from a JSON Object or JSON String
     * 
     * @static
     * @public
     * @param {Object<string, any>|string} json A JSON Object or JSON String
     * @param {number} siteId The Site ID associated with this Alarm Group
     * @return {AlarmGroupModel}
     */
    static fromJSON(json, siteId)
    {
        let model = new AlarmGroupModel(siteId);
        
        /**
         * The JSON Object
         * 
         * @type {Object<string, any>}
         */
        let jsonObject = {};
        
        if(typeof json === 'string')
        {
            jsonObject = JSON.parse(json);
        }
        else if(typeof json === 'object')
        {
            jsonObject = json;
        }
        
        if('id' in jsonObject)
        {
            model.id = (function(){
                if(typeof jsonObject['id'] !== 'string')
                {
                    return String(jsonObject['id']);
                }
        
                return jsonObject['id'];
            }());
        }
        
        if('rtuId' in jsonObject)
        {
            model.rtuId = (function(){
                if(jsonObject['rtuId'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['rtuId'] !== 'number')
                {
                    return Number.isInteger(Number(jsonObject['rtuId'])) ? Number(jsonObject['rtuId']) : Math.floor(Number(jsonObject['rtuId']));
                }
        
                return Number.isInteger(jsonObject['rtuId']) ? jsonObject['rtuId'] : Math.floor(jsonObject['rtuId']);
            }());
        }
        
        if('name' in jsonObject)
        {
            model.name = (function(){
                if(typeof jsonObject['name'] !== 'string')
                {
                    return String(jsonObject['name']);
                }
        
                return jsonObject['name'];
            }());
        }
        
        if('resetPoint' in jsonObject)
        {
            model.resetPoint = (function(){
                if(typeof jsonObject['resetPoint'] !== 'number')
                {
                    return Number.isInteger(Number(jsonObject['resetPoint'])) ? Number(jsonObject['resetPoint']) : Math.floor(Number(jsonObject['resetPoint']));
                }
        
                return Number.isInteger(jsonObject['resetPoint']) ? jsonObject['resetPoint'] : Math.floor(jsonObject['resetPoint']);
            }());
        }
        
        if('externalResetPoints' in jsonObject)
        {
            model.externalResetPoints = (function(){
                if(Array.isArray(jsonObject['externalResetPoints']) !== true)
                {
                    return [];
                }
        
                return jsonObject['externalResetPoints'].map((externalResetPointsItem) => {
                    return (function(){
                        let externalResetPointsItemObject = {};
                        
                        if(typeof externalResetPointsItem === 'object' && 'point' in externalResetPointsItem)
                        {
                            externalResetPointsItemObject.point = (function(){
                                if(typeof externalResetPointsItem.point !== 'number')
                                {
                                    return Number.isInteger(Number(externalResetPointsItem.point)) ? Number(externalResetPointsItem.point) : Math.floor(Number(externalResetPointsItem.point));
                                }
        
                                return Number.isInteger(externalResetPointsItem.point) ? externalResetPointsItem.point : Math.floor(externalResetPointsItem.point);
                            }());
                        }
                        else
                        {
                            externalResetPointsItemObject.point = 0;
                        }
                        
                        if(typeof externalResetPointsItem === 'object' && 'value' in externalResetPointsItem)
                        {
                            externalResetPointsItemObject.value = (function(){
                                if(typeof externalResetPointsItem.value !== 'boolean')
                                {
                                    return Boolean(externalResetPointsItem.value);
                                }
        
                                return externalResetPointsItem.value;
                            }());
                        }
                        else
                        {
                            externalResetPointsItemObject.value = false;
                        }
        
                        return externalResetPointsItemObject;
                    }());
                });
            }());
        }
        
        if('deleted' in jsonObject)
        {
            model.deleted = (function(){
                if(typeof jsonObject['deleted'] !== 'boolean')
                {
                    return Boolean(jsonObject['deleted']);
                }
        
                return jsonObject['deleted'];
            }());
        }
        
        if('updateTimestamp' in jsonObject)
        {
            model.updateTimestamp = (function(){
                if(typeof jsonObject['updateTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['updateTimestamp']));
                }
        
                return new Date(jsonObject['updateTimestamp']);
            }());
        }
        
        return model;
    }
}

export default AlarmGroupModel;