RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Models/Packhouse/Site/MAFSizerBatchModel.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 MAF Sizer Batch
 * 
 * @class
 * @hideconstructor
 * @extends BaseModel
 */
class MAFSizerBatchModel extends BaseModel
{
    /**
     * MAFSizerBatchModel Constructor
     * 
     * @protected
     * @param {number} siteId The Site ID associated with this MAF Sizer Batch
     */
    constructor(siteId)
    {
        super();
        
        /**
         * The MAF Sizer Batch ID
         * 
         * @type {string}
         * @public
         */
        this.id = "";
        
        /**
         * The MAF Sizer ID this Batch is associated with
         * 
         * @type {string}
         * @public
         */
        this.mafSizerId = "";
        
        /**
         * The Numeric MAF Batch ID
         * 
         * @type {string}
         * @public
         */
        this.batchId = "";
        
        /**
         * When this Batch was Created
         * 
         * @type {Date}
         * @public
         */
        this.createdTimestamp = new Date();
        
        /**
         * The Batch Name
         * 
         * @type {?string}
         * @public
         */
        this.batchName = null;
        
        /**
         * The Grower Code
         * 
         * @type {?string}
         * @public
         */
        this.growerCode = null;
        
        /**
         * The Grower Name
         * 
         * @type {?string}
         * @public
         */
        this.growerName = null;
        
        /**
         * The Variety Code
         * 
         * @type {?string}
         * @public
         */
        this.varietyCode = null;
        
        /**
         * The Variety Name
         * 
         * @type {?string}
         * @public
         */
        this.varietyName = null;
        
        /**
         * The Total Weight Processed for this Batch
         * 
         * @type {number}
         * @public
         */
        this.totalWeight = 0;
        
        /**
         * The Packrun ID associated with this Batch
         * 
         * @type {?string}
         * @public
         */
        this.packrunId = null;
        
        /**
         * An Array of Summary Data Objects for each Article
         * 
         * @type {Array<{name: string, fruitCount: number, fruitWeight: number}>}
         * @public
         */
        this.articleSummaries = [];
        
        /**
         * An Array of Summary Data Objects for each Outlet
         * 
         * @type {Array<{number: number, fruitCount: number, fruitWeight: number}>}
         * @public
         */
        this.outletSummaries = [];
        
        /**
         * An Array of Summary Data Objects for each Fruit Size and Article
         * 
         * @type {Array<{articleName: string, fruitSize: string, fruitCount: number, fruitWeight: number}>}
         * @public
         */
        this.fruitSummaries = [];
        
        /**
         * Whether the MAF Sizer Batch has been deleted
         * 
         * @type {boolean}
         * @public
         */
        this.deleted = false;
        
        /**
         * When the MAF Sizer Batch was last updated
         * 
         * @type {Date}
         * @public
         */
        this.updateTimestamp = new Date();
        
        /**
         * The Site ID associated with this MAF Sizer Batch
         * 
         * @type {number}
         * @public
         */
        this.siteId = siteId;
    }

    /**
     * Create a new **MAFSizerBatchModel** 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 MAF Sizer Batch
     * @return {MAFSizerBatchModel}
     */
    static fromJSON(json, siteId)
    {
        let model = new MAFSizerBatchModel(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('mafSizerId' in jsonObject)
        {
            model.mafSizerId = (function(){
                if(typeof jsonObject['mafSizerId'] !== 'string')
                {
                    return String(jsonObject['mafSizerId']);
                }
        
                return jsonObject['mafSizerId'];
            }());
        }
        
        if('batchId' in jsonObject)
        {
            model.batchId = (function(){
                if(typeof jsonObject['batchId'] !== 'string')
                {
                    return String(jsonObject['batchId']);
                }
        
                return jsonObject['batchId'];
            }());
        }
        
        if('createdTimestamp' in jsonObject)
        {
            model.createdTimestamp = (function(){
                if(typeof jsonObject['createdTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['createdTimestamp']));
                }
        
                return new Date(jsonObject['createdTimestamp']);
            }());
        }
        
        if('batchName' in jsonObject)
        {
            model.batchName = (function(){
                if(jsonObject['batchName'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['batchName'] !== 'string')
                {
                    return String(jsonObject['batchName']);
                }
        
                return jsonObject['batchName'];
            }());
        }
        
        if('growerCode' in jsonObject)
        {
            model.growerCode = (function(){
                if(jsonObject['growerCode'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['growerCode'] !== 'string')
                {
                    return String(jsonObject['growerCode']);
                }
        
                return jsonObject['growerCode'];
            }());
        }
        
        if('growerName' in jsonObject)
        {
            model.growerName = (function(){
                if(jsonObject['growerName'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['growerName'] !== 'string')
                {
                    return String(jsonObject['growerName']);
                }
        
                return jsonObject['growerName'];
            }());
        }
        
        if('varietyCode' in jsonObject)
        {
            model.varietyCode = (function(){
                if(jsonObject['varietyCode'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['varietyCode'] !== 'string')
                {
                    return String(jsonObject['varietyCode']);
                }
        
                return jsonObject['varietyCode'];
            }());
        }
        
        if('varietyName' in jsonObject)
        {
            model.varietyName = (function(){
                if(jsonObject['varietyName'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['varietyName'] !== 'string')
                {
                    return String(jsonObject['varietyName']);
                }
        
                return jsonObject['varietyName'];
            }());
        }
        
        if('totalWeight' in jsonObject)
        {
            model.totalWeight = (function(){
                if(typeof jsonObject['totalWeight'] !== 'number')
                {
                    return Number(jsonObject['totalWeight']);
                }
        
                return jsonObject['totalWeight'];
            }());
        }
        
        if('packrunId' in jsonObject)
        {
            model.packrunId = (function(){
                if(jsonObject['packrunId'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['packrunId'] !== 'string')
                {
                    return String(jsonObject['packrunId']);
                }
        
                return jsonObject['packrunId'];
            }());
        }
        
        if('articleSummaries' in jsonObject)
        {
            model.articleSummaries = (function(){
                if(Array.isArray(jsonObject['articleSummaries']) !== true)
                {
                    return [];
                }
        
                return jsonObject['articleSummaries'].map((articleSummariesItem) => {
                    return (function(){
                        let articleSummariesItemObject = {};
                        
                        if(typeof articleSummariesItem === 'object' && 'name' in articleSummariesItem)
                        {
                            articleSummariesItemObject.name = (function(){
                                if(typeof articleSummariesItem.name !== 'string')
                                {
                                    return String(articleSummariesItem.name);
                                }
        
                                return articleSummariesItem.name;
                            }());
                        }
                        else
                        {
                            articleSummariesItemObject.name = "";
                        }
                        
                        if(typeof articleSummariesItem === 'object' && 'fruitCount' in articleSummariesItem)
                        {
                            articleSummariesItemObject.fruitCount = (function(){
                                if(typeof articleSummariesItem.fruitCount !== 'number')
                                {
                                    return Number.isInteger(Number(articleSummariesItem.fruitCount)) ? Number(articleSummariesItem.fruitCount) : Math.floor(Number(articleSummariesItem.fruitCount));
                                }
        
                                return Number.isInteger(articleSummariesItem.fruitCount) ? articleSummariesItem.fruitCount : Math.floor(articleSummariesItem.fruitCount);
                            }());
                        }
                        else
                        {
                            articleSummariesItemObject.fruitCount = 0;
                        }
                        
                        if(typeof articleSummariesItem === 'object' && 'fruitWeight' in articleSummariesItem)
                        {
                            articleSummariesItemObject.fruitWeight = (function(){
                                if(typeof articleSummariesItem.fruitWeight !== 'number')
                                {
                                    return Number(articleSummariesItem.fruitWeight);
                                }
        
                                return articleSummariesItem.fruitWeight;
                            }());
                        }
                        else
                        {
                            articleSummariesItemObject.fruitWeight = 0;
                        }
        
                        return articleSummariesItemObject;
                    }());
                });
            }());
        }
        
        if('outletSummaries' in jsonObject)
        {
            model.outletSummaries = (function(){
                if(Array.isArray(jsonObject['outletSummaries']) !== true)
                {
                    return [];
                }
        
                return jsonObject['outletSummaries'].map((outletSummariesItem) => {
                    return (function(){
                        let outletSummariesItemObject = {};
                        
                        if(typeof outletSummariesItem === 'object' && 'number' in outletSummariesItem)
                        {
                            outletSummariesItemObject.number = (function(){
                                if(typeof outletSummariesItem.number !== 'number')
                                {
                                    return Number.isInteger(Number(outletSummariesItem.number)) ? Number(outletSummariesItem.number) : Math.floor(Number(outletSummariesItem.number));
                                }
        
                                return Number.isInteger(outletSummariesItem.number) ? outletSummariesItem.number : Math.floor(outletSummariesItem.number);
                            }());
                        }
                        else
                        {
                            outletSummariesItemObject.number = 0;
                        }
                        
                        if(typeof outletSummariesItem === 'object' && 'fruitCount' in outletSummariesItem)
                        {
                            outletSummariesItemObject.fruitCount = (function(){
                                if(typeof outletSummariesItem.fruitCount !== 'number')
                                {
                                    return Number.isInteger(Number(outletSummariesItem.fruitCount)) ? Number(outletSummariesItem.fruitCount) : Math.floor(Number(outletSummariesItem.fruitCount));
                                }
        
                                return Number.isInteger(outletSummariesItem.fruitCount) ? outletSummariesItem.fruitCount : Math.floor(outletSummariesItem.fruitCount);
                            }());
                        }
                        else
                        {
                            outletSummariesItemObject.fruitCount = 0;
                        }
                        
                        if(typeof outletSummariesItem === 'object' && 'fruitWeight' in outletSummariesItem)
                        {
                            outletSummariesItemObject.fruitWeight = (function(){
                                if(typeof outletSummariesItem.fruitWeight !== 'number')
                                {
                                    return Number(outletSummariesItem.fruitWeight);
                                }
        
                                return outletSummariesItem.fruitWeight;
                            }());
                        }
                        else
                        {
                            outletSummariesItemObject.fruitWeight = 0;
                        }
        
                        return outletSummariesItemObject;
                    }());
                });
            }());
        }
        
        if('fruitSummaries' in jsonObject)
        {
            model.fruitSummaries = (function(){
                if(Array.isArray(jsonObject['fruitSummaries']) !== true)
                {
                    return [];
                }
        
                return jsonObject['fruitSummaries'].map((fruitSummariesItem) => {
                    return (function(){
                        let fruitSummariesItemObject = {};
                        
                        if(typeof fruitSummariesItem === 'object' && 'articleName' in fruitSummariesItem)
                        {
                            fruitSummariesItemObject.articleName = (function(){
                                if(typeof fruitSummariesItem.articleName !== 'string')
                                {
                                    return String(fruitSummariesItem.articleName);
                                }
        
                                return fruitSummariesItem.articleName;
                            }());
                        }
                        else
                        {
                            fruitSummariesItemObject.articleName = "";
                        }
                        
                        if(typeof fruitSummariesItem === 'object' && 'fruitSize' in fruitSummariesItem)
                        {
                            fruitSummariesItemObject.fruitSize = (function(){
                                if(typeof fruitSummariesItem.fruitSize !== 'string')
                                {
                                    return String(fruitSummariesItem.fruitSize);
                                }
        
                                return fruitSummariesItem.fruitSize;
                            }());
                        }
                        else
                        {
                            fruitSummariesItemObject.fruitSize = "";
                        }
                        
                        if(typeof fruitSummariesItem === 'object' && 'fruitCount' in fruitSummariesItem)
                        {
                            fruitSummariesItemObject.fruitCount = (function(){
                                if(typeof fruitSummariesItem.fruitCount !== 'number')
                                {
                                    return Number.isInteger(Number(fruitSummariesItem.fruitCount)) ? Number(fruitSummariesItem.fruitCount) : Math.floor(Number(fruitSummariesItem.fruitCount));
                                }
        
                                return Number.isInteger(fruitSummariesItem.fruitCount) ? fruitSummariesItem.fruitCount : Math.floor(fruitSummariesItem.fruitCount);
                            }());
                        }
                        else
                        {
                            fruitSummariesItemObject.fruitCount = 0;
                        }
                        
                        if(typeof fruitSummariesItem === 'object' && 'fruitWeight' in fruitSummariesItem)
                        {
                            fruitSummariesItemObject.fruitWeight = (function(){
                                if(typeof fruitSummariesItem.fruitWeight !== 'number')
                                {
                                    return Number(fruitSummariesItem.fruitWeight);
                                }
        
                                return fruitSummariesItem.fruitWeight;
                            }());
                        }
                        else
                        {
                            fruitSummariesItemObject.fruitWeight = 0;
                        }
        
                        return fruitSummariesItemObject;
                    }());
                });
            }());
        }
        
        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 MAFSizerBatchModel;