RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Models/Packhouse/Site/RejectBinWeightModel.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 Reject Bin Weight
 * 
 * @class
 * @hideconstructor
 * @extends BaseModel
 */
class RejectBinWeightModel extends BaseModel
{
    /**
     * RejectBinWeightModel Constructor
     * 
     * @protected
     * @param {number} siteId The Site ID associated with this Reject Bin Weight
     */
    constructor(siteId)
    {
        super();
        
        /**
         * The Reject Bin Weight ID
         * 
         * @type {string}
         * @public
         */
        this.id = "";
        
        /**
         * The Reject Bin Scale ID this Reject Weight is associated with
         * 
         * @type {string}
         * @public
         */
        this.rejectBinScaleId = "";
        
        /**
         * The Reject Bin ID this Reject Weight is associated with
         * 
         * @type {string}
         * @public
         */
        this.rejectBinId = "";
        
        /**
         * When this Reject Bin Weight was Created
         * 
         * @type {Date}
         * @public
         */
        this.createdTimestamp = new Date();
        
        /**
         * The Packrun this Reject Weight is associated with
         * 
         * @type {?string}
         * @public
         */
        this.packrunId = null;
        
        /**
         * The Net Weight Captured by the Reject Bin Scale
         * 
         * @type {number}
         * @public
         */
        this.netWeight = 0;
        
        /**
         * The Source Weights that make up the Net Weight
         * 
         * @type {Array<{type: string, sortingTableId: string, sortingTableName: ?string, weights: Array<{classType: string, weight: number, fruitCount: ?number}>}|{type: string, beltName: ?string, weights: Array<{classType: string, weight: number, fruitCount: ?number}>}|{type: string, sizerId: string, sizerName: ?string, outletNumber: number, outletName: ?string, weights: Array<{classType: string, weight: number, fruitCount: ?number}>}|{type: string, mixedNames: string[], weights: Array<{classType: string, weight: number, fruitCount: ?number}>}>}
         * @public
         */
        this.sources = [];
        
        /**
         * The Multi-Grower Bin Weights that will be submitted to FreshPack
         * 
         * @type {Array<{classType: string, weight: number, weightApi: ?{requestCount: number, requestTimestamp: ?Date, responseCode: ?number, responseMessage: ?string, completed: boolean}}>}
         * @public
         */
        this.freshPackMultiGrowerBinWeights = [];
        
        /**
         * Whether the Reject Bin Weight has been deleted
         * 
         * @type {boolean}
         * @public
         */
        this.deleted = false;
        
        /**
         * When the Reject Bin Weight was last updated
         * 
         * @type {Date}
         * @public
         */
        this.updateTimestamp = new Date();
        
        /**
         * The Site ID associated with this Reject Bin Weight
         * 
         * @type {number}
         * @public
         */
        this.siteId = siteId;
    }

    /**
     * Create a new **RejectBinWeightModel** 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 Reject Bin Weight
     * @return {RejectBinWeightModel}
     */
    static fromJSON(json, siteId)
    {
        let model = new RejectBinWeightModel(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('rejectBinScaleId' in jsonObject)
        {
            model.rejectBinScaleId = (function(){
                if(typeof jsonObject['rejectBinScaleId'] !== 'string')
                {
                    return String(jsonObject['rejectBinScaleId']);
                }
        
                return jsonObject['rejectBinScaleId'];
            }());
        }
        
        if('rejectBinId' in jsonObject)
        {
            model.rejectBinId = (function(){
                if(typeof jsonObject['rejectBinId'] !== 'string')
                {
                    return String(jsonObject['rejectBinId']);
                }
        
                return jsonObject['rejectBinId'];
            }());
        }
        
        if('createdTimestamp' in jsonObject)
        {
            model.createdTimestamp = (function(){
                if(typeof jsonObject['createdTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['createdTimestamp']));
                }
        
                return new Date(jsonObject['createdTimestamp']);
            }());
        }
        
        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('netWeight' in jsonObject)
        {
            model.netWeight = (function(){
                if(typeof jsonObject['netWeight'] !== 'number')
                {
                    return Number(jsonObject['netWeight']);
                }
        
                return jsonObject['netWeight'];
            }());
        }
        
        if('sources' in jsonObject)
        {
            model.sources = (function(){
                if(Array.isArray(jsonObject['sources']) !== true)
                {
                    return [];
                }
        
                return jsonObject['sources'].map((sourcesItem) => {
                    return (function(){
                        return sourcesItem;
                    }());
                });
            }());
        }
        
        if('freshPackMultiGrowerBinWeights' in jsonObject)
        {
            model.freshPackMultiGrowerBinWeights = (function(){
                if(Array.isArray(jsonObject['freshPackMultiGrowerBinWeights']) !== true)
                {
                    return [];
                }
        
                return jsonObject['freshPackMultiGrowerBinWeights'].map((freshPackMultiGrowerBinWeightsItem) => {
                    return (function(){
                        let freshPackMultiGrowerBinWeightsItemObject = {};
                        
                        if(typeof freshPackMultiGrowerBinWeightsItem === 'object' && 'classType' in freshPackMultiGrowerBinWeightsItem)
                        {
                            freshPackMultiGrowerBinWeightsItemObject.classType = (function(){
                                if(typeof freshPackMultiGrowerBinWeightsItem.classType !== 'string')
                                {
                                    return String(freshPackMultiGrowerBinWeightsItem.classType);
                                }
        
                                return freshPackMultiGrowerBinWeightsItem.classType;
                            }());
                        }
                        else
                        {
                            freshPackMultiGrowerBinWeightsItemObject.classType = "";
                        }
                        
                        if(typeof freshPackMultiGrowerBinWeightsItem === 'object' && 'weight' in freshPackMultiGrowerBinWeightsItem)
                        {
                            freshPackMultiGrowerBinWeightsItemObject.weight = (function(){
                                if(typeof freshPackMultiGrowerBinWeightsItem.weight !== 'number')
                                {
                                    return Number(freshPackMultiGrowerBinWeightsItem.weight);
                                }
        
                                return freshPackMultiGrowerBinWeightsItem.weight;
                            }());
                        }
                        else
                        {
                            freshPackMultiGrowerBinWeightsItemObject.weight = 0;
                        }
                        
                        if(typeof freshPackMultiGrowerBinWeightsItem === 'object' && 'weightApi' in freshPackMultiGrowerBinWeightsItem)
                        {
                            freshPackMultiGrowerBinWeightsItemObject.weightApi = (function(){
                                if(freshPackMultiGrowerBinWeightsItem.weightApi === null)
                                {
                                    return null;
                                }
        
                                let weightApiObject = {};
                                
                                if(typeof freshPackMultiGrowerBinWeightsItem.weightApi === 'object' && 'requestCount' in freshPackMultiGrowerBinWeightsItem.weightApi)
                                {
                                    weightApiObject.requestCount = (function(){
                                        if(typeof freshPackMultiGrowerBinWeightsItem.weightApi.requestCount !== 'number')
                                        {
                                            return Number.isInteger(Number(freshPackMultiGrowerBinWeightsItem.weightApi.requestCount)) ? Number(freshPackMultiGrowerBinWeightsItem.weightApi.requestCount) : Math.floor(Number(freshPackMultiGrowerBinWeightsItem.weightApi.requestCount));
                                        }
        
                                        return Number.isInteger(freshPackMultiGrowerBinWeightsItem.weightApi.requestCount) ? freshPackMultiGrowerBinWeightsItem.weightApi.requestCount : Math.floor(freshPackMultiGrowerBinWeightsItem.weightApi.requestCount);
                                    }());
                                }
                                else
                                {
                                    weightApiObject.requestCount = 0;
                                }
                                
                                if(typeof freshPackMultiGrowerBinWeightsItem.weightApi === 'object' && 'requestTimestamp' in freshPackMultiGrowerBinWeightsItem.weightApi)
                                {
                                    weightApiObject.requestTimestamp = (function(){
                                        if(freshPackMultiGrowerBinWeightsItem.weightApi.requestTimestamp === null)
                                        {
                                            return null;
                                        }
        
                                        if(typeof freshPackMultiGrowerBinWeightsItem.weightApi.requestTimestamp !== 'string')
                                        {
                                            return new Date(String(freshPackMultiGrowerBinWeightsItem.weightApi.requestTimestamp));
                                        }
        
                                        return new Date(freshPackMultiGrowerBinWeightsItem.weightApi.requestTimestamp);
                                    }());
                                }
                                else
                                {
                                    weightApiObject.requestTimestamp = null;
                                }
                                
                                if(typeof freshPackMultiGrowerBinWeightsItem.weightApi === 'object' && 'responseCode' in freshPackMultiGrowerBinWeightsItem.weightApi)
                                {
                                    weightApiObject.responseCode = (function(){
                                        if(freshPackMultiGrowerBinWeightsItem.weightApi.responseCode === null)
                                        {
                                            return null;
                                        }
        
                                        if(typeof freshPackMultiGrowerBinWeightsItem.weightApi.responseCode !== 'number')
                                        {
                                            return Number.isInteger(Number(freshPackMultiGrowerBinWeightsItem.weightApi.responseCode)) ? Number(freshPackMultiGrowerBinWeightsItem.weightApi.responseCode) : Math.floor(Number(freshPackMultiGrowerBinWeightsItem.weightApi.responseCode));
                                        }
        
                                        return Number.isInteger(freshPackMultiGrowerBinWeightsItem.weightApi.responseCode) ? freshPackMultiGrowerBinWeightsItem.weightApi.responseCode : Math.floor(freshPackMultiGrowerBinWeightsItem.weightApi.responseCode);
                                    }());
                                }
                                else
                                {
                                    weightApiObject.responseCode = null;
                                }
                                
                                if(typeof freshPackMultiGrowerBinWeightsItem.weightApi === 'object' && 'responseMessage' in freshPackMultiGrowerBinWeightsItem.weightApi)
                                {
                                    weightApiObject.responseMessage = (function(){
                                        if(freshPackMultiGrowerBinWeightsItem.weightApi.responseMessage === null)
                                        {
                                            return null;
                                        }
        
                                        if(typeof freshPackMultiGrowerBinWeightsItem.weightApi.responseMessage !== 'string')
                                        {
                                            return String(freshPackMultiGrowerBinWeightsItem.weightApi.responseMessage);
                                        }
        
                                        return freshPackMultiGrowerBinWeightsItem.weightApi.responseMessage;
                                    }());
                                }
                                else
                                {
                                    weightApiObject.responseMessage = null;
                                }
                                
                                if(typeof freshPackMultiGrowerBinWeightsItem.weightApi === 'object' && 'completed' in freshPackMultiGrowerBinWeightsItem.weightApi)
                                {
                                    weightApiObject.completed = (function(){
                                        if(typeof freshPackMultiGrowerBinWeightsItem.weightApi.completed !== 'boolean')
                                        {
                                            return Boolean(freshPackMultiGrowerBinWeightsItem.weightApi.completed);
                                        }
        
                                        return freshPackMultiGrowerBinWeightsItem.weightApi.completed;
                                    }());
                                }
                                else
                                {
                                    weightApiObject.completed = false;
                                }
        
                                return weightApiObject;
                            }());
                        }
                        else
                        {
                            freshPackMultiGrowerBinWeightsItemObject.weightApi = null;
                        }
        
                        return freshPackMultiGrowerBinWeightsItemObject;
                    }());
                });
            }());
        }
        
        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 RejectBinWeightModel;