RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Models/ApiAccountModel.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 API Account
 * 
 * @class
 * @hideconstructor
 * @extends BaseModel
 */
class ApiAccountModel extends BaseModel
{
    /**
     * ApiAccountModel Constructor
     * 
     * @protected
     */
    constructor()
    {
        super();
        
        /**
         * The API Account ID
         * 
         * @type {string}
         * @public
         */
        this.id = "";
        
        /**
         * API Key
         * 
         * @type {?string}
         * @public
         */
        this.key = null;
        
        /**
         * The API Account Name
         * 
         * @type {string}
         * @public
         */
        this.name = "";
        
        /**
         * The Company this API Account belongs to
         * 
         * @type {string}
         * @public
         */
        this.companyId = "";
        
        /**
         * The Policies that apply to this API Account
         * 
         * @type {string[]}
         * @public
         */
        this.policies = [];
        
        /**
         * Whether the API Account has been deleted
         * 
         * @type {boolean}
         * @public
         */
        this.deleted = false;
        
        /**
         * When the API Account was last updated
         * 
         * @type {Date}
         * @public
         */
        this.updateTimestamp = new Date();
    }

    /**
     * Create a new **ApiAccountModel** from a JSON Object or JSON String
     * 
     * @static
     * @public
     * @param {Object<string, any>|string} json A JSON Object or JSON String
     * @return {ApiAccountModel}
     */
    static fromJSON(json)
    {
        let model = new ApiAccountModel();
        
        /**
         * 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('key' in jsonObject)
        {
            model.key = (function(){
                if(jsonObject['key'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['key'] !== 'string')
                {
                    return String(jsonObject['key']);
                }
        
                return jsonObject['key'];
            }());
        }
        
        if('name' in jsonObject)
        {
            model.name = (function(){
                if(typeof jsonObject['name'] !== 'string')
                {
                    return String(jsonObject['name']);
                }
        
                return jsonObject['name'];
            }());
        }
        
        if('companyId' in jsonObject)
        {
            model.companyId = (function(){
                if(typeof jsonObject['companyId'] !== 'string')
                {
                    return String(jsonObject['companyId']);
                }
        
                return jsonObject['companyId'];
            }());
        }
        
        if('policies' in jsonObject)
        {
            model.policies = (function(){
                if(Array.isArray(jsonObject['policies']) !== true)
                {
                    return [];
                }
        
                return jsonObject['policies'].map((policiesItem) => {
                    return (function(){
                        if(typeof policiesItem !== 'string')
                        {
                            return String(policiesItem);
                        }
        
                        return policiesItem;
                    }());
                });
            }());
        }
        
        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 ApiAccountModel;