RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Models/Packhouse/Site/GrowingMethodModel.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 Growing Method
 * 
 * @class
 * @hideconstructor
 * @extends BaseModel
 */
class GrowingMethodModel extends BaseModel
{
    /**
     * GrowingMethodModel Constructor
     * 
     * @protected
     * @param {number} siteId The Site ID associated with this Growing Method
     */
    constructor(siteId)
    {
        super();
        
        /**
         * The Growing Method ID
         * 
         * @type {string}
         * @public
         */
        this.id = "";
        
        /**
         * The Growing Method Code
         * 
         * @type {string}
         * @public
         */
        this.code = "";
        
        /**
         * The Growing Method Name
         * 
         * @type {string}
         * @public
         */
        this.name = "";
        
        /**
         * The Growing Method Description
         * 
         * @type {string}
         * @public
         */
        this.description = "";
        
        /**
         * Whether the Growing Method has been deleted
         * 
         * @type {boolean}
         * @public
         */
        this.deleted = false;
        
        /**
         * When the Growing Method was last updated
         * 
         * @type {Date}
         * @public
         */
        this.updateTimestamp = new Date();
        
        /**
         * The Site ID associated with this Growing Method
         * 
         * @type {number}
         * @public
         */
        this.siteId = siteId;
    }

    /**
     * Create a new **GrowingMethodModel** 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 Growing Method
     * @return {GrowingMethodModel}
     */
    static fromJSON(json, siteId)
    {
        let model = new GrowingMethodModel(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('code' in jsonObject)
        {
            model.code = (function(){
                if(typeof jsonObject['code'] !== 'string')
                {
                    return String(jsonObject['code']);
                }
        
                return jsonObject['code'];
            }());
        }
        
        if('name' in jsonObject)
        {
            model.name = (function(){
                if(typeof jsonObject['name'] !== 'string')
                {
                    return String(jsonObject['name']);
                }
        
                return jsonObject['name'];
            }());
        }
        
        if('description' in jsonObject)
        {
            model.description = (function(){
                if(typeof jsonObject['description'] !== 'string')
                {
                    return String(jsonObject['description']);
                }
        
                return jsonObject['description'];
            }());
        }
        
        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 GrowingMethodModel;