RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Models/Packhouse/Site/RejectBinModel.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
 * 
 * @class
 * @hideconstructor
 * @extends BaseModel
 */
class RejectBinModel extends BaseModel
{
    /**
     * RejectBinModel Constructor
     * 
     * @protected
     * @param {number} siteId The Site ID associated with this Reject Bin
     */
    constructor(siteId)
    {
        super();
        
        /**
         * The Reject Bin ID
         * 
         * @type {string}
         * @public
         */
        this.id = "";
        
        /**
         * The Reject Bin Scale ID this Reject Bin is associated with
         * 
         * @type {string}
         * @public
         */
        this.rejectBinScaleId = "";
        
        /**
         * When this Reject Bin was Created
         * 
         * @type {Date}
         * @public
         */
        this.createdTimestamp = new Date();
        
        /**
         * The Name of the Reject Bin Scale where this Bin was Created
         * 
         * @type {string}
         * @public
         */
        this.rejectBinScaleName = "";
        
        /**
         * The Tare Weight Captured by the Reject Bin Scale
         * 
         * @type {?number}
         * @public
         */
        this.tareWeight = null;
        
        /**
         * When this Reject Bin was Finalized (No new Weights)
         * 
         * @type {?Date}
         * @public
         */
        this.finalizedTimestamp = null;
        
        /**
         * The Multi-Grower Bins that will be submitted to FreshPack
         * 
         * @type {Array<{classType: string, binNumber: ?string, printBinCard: boolean, binNumberApi: ?{requestCount: number, requestTimestamp: ?Date, responseCode: ?number, responseMessage: ?string, completed: boolean}, binCardApi: ?{requestCount: number, requestTimestamp: ?Date, responseCode: ?number, responseMessage: ?string, completed: boolean}}>}
         * @public
         */
        this.freshPackMultiGrowerBins = [];
        
        /**
         * Whether the Reject Bin has been deleted
         * 
         * @type {boolean}
         * @public
         */
        this.deleted = false;
        
        /**
         * When the Reject Bin was last updated
         * 
         * @type {Date}
         * @public
         */
        this.updateTimestamp = new Date();
        
        /**
         * The Site ID associated with this Reject Bin
         * 
         * @type {number}
         * @public
         */
        this.siteId = siteId;
    }

    /**
     * Create a new **RejectBinModel** 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
     * @return {RejectBinModel}
     */
    static fromJSON(json, siteId)
    {
        let model = new RejectBinModel(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('createdTimestamp' in jsonObject)
        {
            model.createdTimestamp = (function(){
                if(typeof jsonObject['createdTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['createdTimestamp']));
                }
        
                return new Date(jsonObject['createdTimestamp']);
            }());
        }
        
        if('rejectBinScaleName' in jsonObject)
        {
            model.rejectBinScaleName = (function(){
                if(typeof jsonObject['rejectBinScaleName'] !== 'string')
                {
                    return String(jsonObject['rejectBinScaleName']);
                }
        
                return jsonObject['rejectBinScaleName'];
            }());
        }
        
        if('tareWeight' in jsonObject)
        {
            model.tareWeight = (function(){
                if(jsonObject['tareWeight'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['tareWeight'] !== 'number')
                {
                    return Number(jsonObject['tareWeight']);
                }
        
                return jsonObject['tareWeight'];
            }());
        }
        
        if('finalizedTimestamp' in jsonObject)
        {
            model.finalizedTimestamp = (function(){
                if(jsonObject['finalizedTimestamp'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['finalizedTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['finalizedTimestamp']));
                }
        
                return new Date(jsonObject['finalizedTimestamp']);
            }());
        }
        
        if('freshPackMultiGrowerBins' in jsonObject)
        {
            model.freshPackMultiGrowerBins = (function(){
                if(Array.isArray(jsonObject['freshPackMultiGrowerBins']) !== true)
                {
                    return [];
                }
        
                return jsonObject['freshPackMultiGrowerBins'].map((freshPackMultiGrowerBinsItem) => {
                    return (function(){
                        let freshPackMultiGrowerBinsItemObject = {};
                        
                        if(typeof freshPackMultiGrowerBinsItem === 'object' && 'classType' in freshPackMultiGrowerBinsItem)
                        {
                            freshPackMultiGrowerBinsItemObject.classType = (function(){
                                if(typeof freshPackMultiGrowerBinsItem.classType !== 'string')
                                {
                                    return String(freshPackMultiGrowerBinsItem.classType);
                                }
        
                                return freshPackMultiGrowerBinsItem.classType;
                            }());
                        }
                        else
                        {
                            freshPackMultiGrowerBinsItemObject.classType = "";
                        }
                        
                        if(typeof freshPackMultiGrowerBinsItem === 'object' && 'binNumber' in freshPackMultiGrowerBinsItem)
                        {
                            freshPackMultiGrowerBinsItemObject.binNumber = (function(){
                                if(freshPackMultiGrowerBinsItem.binNumber === null)
                                {
                                    return null;
                                }
        
                                if(typeof freshPackMultiGrowerBinsItem.binNumber !== 'string')
                                {
                                    return String(freshPackMultiGrowerBinsItem.binNumber);
                                }
        
                                return freshPackMultiGrowerBinsItem.binNumber;
                            }());
                        }
                        else
                        {
                            freshPackMultiGrowerBinsItemObject.binNumber = null;
                        }
                        
                        if(typeof freshPackMultiGrowerBinsItem === 'object' && 'printBinCard' in freshPackMultiGrowerBinsItem)
                        {
                            freshPackMultiGrowerBinsItemObject.printBinCard = (function(){
                                if(typeof freshPackMultiGrowerBinsItem.printBinCard !== 'boolean')
                                {
                                    return Boolean(freshPackMultiGrowerBinsItem.printBinCard);
                                }
        
                                return freshPackMultiGrowerBinsItem.printBinCard;
                            }());
                        }
                        else
                        {
                            freshPackMultiGrowerBinsItemObject.printBinCard = false;
                        }
                        
                        if(typeof freshPackMultiGrowerBinsItem === 'object' && 'binNumberApi' in freshPackMultiGrowerBinsItem)
                        {
                            freshPackMultiGrowerBinsItemObject.binNumberApi = (function(){
                                if(freshPackMultiGrowerBinsItem.binNumberApi === null)
                                {
                                    return null;
                                }
        
                                let binNumberApiObject = {};
                                
                                if(typeof freshPackMultiGrowerBinsItem.binNumberApi === 'object' && 'requestCount' in freshPackMultiGrowerBinsItem.binNumberApi)
                                {
                                    binNumberApiObject.requestCount = (function(){
                                        if(typeof freshPackMultiGrowerBinsItem.binNumberApi.requestCount !== 'number')
                                        {
                                            return Number.isInteger(Number(freshPackMultiGrowerBinsItem.binNumberApi.requestCount)) ? Number(freshPackMultiGrowerBinsItem.binNumberApi.requestCount) : Math.floor(Number(freshPackMultiGrowerBinsItem.binNumberApi.requestCount));
                                        }
        
                                        return Number.isInteger(freshPackMultiGrowerBinsItem.binNumberApi.requestCount) ? freshPackMultiGrowerBinsItem.binNumberApi.requestCount : Math.floor(freshPackMultiGrowerBinsItem.binNumberApi.requestCount);
                                    }());
                                }
                                else
                                {
                                    binNumberApiObject.requestCount = 0;
                                }
                                
                                if(typeof freshPackMultiGrowerBinsItem.binNumberApi === 'object' && 'requestTimestamp' in freshPackMultiGrowerBinsItem.binNumberApi)
                                {
                                    binNumberApiObject.requestTimestamp = (function(){
                                        if(freshPackMultiGrowerBinsItem.binNumberApi.requestTimestamp === null)
                                        {
                                            return null;
                                        }
        
                                        if(typeof freshPackMultiGrowerBinsItem.binNumberApi.requestTimestamp !== 'string')
                                        {
                                            return new Date(String(freshPackMultiGrowerBinsItem.binNumberApi.requestTimestamp));
                                        }
        
                                        return new Date(freshPackMultiGrowerBinsItem.binNumberApi.requestTimestamp);
                                    }());
                                }
                                else
                                {
                                    binNumberApiObject.requestTimestamp = null;
                                }
                                
                                if(typeof freshPackMultiGrowerBinsItem.binNumberApi === 'object' && 'responseCode' in freshPackMultiGrowerBinsItem.binNumberApi)
                                {
                                    binNumberApiObject.responseCode = (function(){
                                        if(freshPackMultiGrowerBinsItem.binNumberApi.responseCode === null)
                                        {
                                            return null;
                                        }
        
                                        if(typeof freshPackMultiGrowerBinsItem.binNumberApi.responseCode !== 'number')
                                        {
                                            return Number.isInteger(Number(freshPackMultiGrowerBinsItem.binNumberApi.responseCode)) ? Number(freshPackMultiGrowerBinsItem.binNumberApi.responseCode) : Math.floor(Number(freshPackMultiGrowerBinsItem.binNumberApi.responseCode));
                                        }
        
                                        return Number.isInteger(freshPackMultiGrowerBinsItem.binNumberApi.responseCode) ? freshPackMultiGrowerBinsItem.binNumberApi.responseCode : Math.floor(freshPackMultiGrowerBinsItem.binNumberApi.responseCode);
                                    }());
                                }
                                else
                                {
                                    binNumberApiObject.responseCode = null;
                                }
                                
                                if(typeof freshPackMultiGrowerBinsItem.binNumberApi === 'object' && 'responseMessage' in freshPackMultiGrowerBinsItem.binNumberApi)
                                {
                                    binNumberApiObject.responseMessage = (function(){
                                        if(freshPackMultiGrowerBinsItem.binNumberApi.responseMessage === null)
                                        {
                                            return null;
                                        }
        
                                        if(typeof freshPackMultiGrowerBinsItem.binNumberApi.responseMessage !== 'string')
                                        {
                                            return String(freshPackMultiGrowerBinsItem.binNumberApi.responseMessage);
                                        }
        
                                        return freshPackMultiGrowerBinsItem.binNumberApi.responseMessage;
                                    }());
                                }
                                else
                                {
                                    binNumberApiObject.responseMessage = null;
                                }
                                
                                if(typeof freshPackMultiGrowerBinsItem.binNumberApi === 'object' && 'completed' in freshPackMultiGrowerBinsItem.binNumberApi)
                                {
                                    binNumberApiObject.completed = (function(){
                                        if(typeof freshPackMultiGrowerBinsItem.binNumberApi.completed !== 'boolean')
                                        {
                                            return Boolean(freshPackMultiGrowerBinsItem.binNumberApi.completed);
                                        }
        
                                        return freshPackMultiGrowerBinsItem.binNumberApi.completed;
                                    }());
                                }
                                else
                                {
                                    binNumberApiObject.completed = false;
                                }
        
                                return binNumberApiObject;
                            }());
                        }
                        else
                        {
                            freshPackMultiGrowerBinsItemObject.binNumberApi = null;
                        }
                        
                        if(typeof freshPackMultiGrowerBinsItem === 'object' && 'binCardApi' in freshPackMultiGrowerBinsItem)
                        {
                            freshPackMultiGrowerBinsItemObject.binCardApi = (function(){
                                if(freshPackMultiGrowerBinsItem.binCardApi === null)
                                {
                                    return null;
                                }
        
                                let binCardApiObject = {};
                                
                                if(typeof freshPackMultiGrowerBinsItem.binCardApi === 'object' && 'requestCount' in freshPackMultiGrowerBinsItem.binCardApi)
                                {
                                    binCardApiObject.requestCount = (function(){
                                        if(typeof freshPackMultiGrowerBinsItem.binCardApi.requestCount !== 'number')
                                        {
                                            return Number.isInteger(Number(freshPackMultiGrowerBinsItem.binCardApi.requestCount)) ? Number(freshPackMultiGrowerBinsItem.binCardApi.requestCount) : Math.floor(Number(freshPackMultiGrowerBinsItem.binCardApi.requestCount));
                                        }
        
                                        return Number.isInteger(freshPackMultiGrowerBinsItem.binCardApi.requestCount) ? freshPackMultiGrowerBinsItem.binCardApi.requestCount : Math.floor(freshPackMultiGrowerBinsItem.binCardApi.requestCount);
                                    }());
                                }
                                else
                                {
                                    binCardApiObject.requestCount = 0;
                                }
                                
                                if(typeof freshPackMultiGrowerBinsItem.binCardApi === 'object' && 'requestTimestamp' in freshPackMultiGrowerBinsItem.binCardApi)
                                {
                                    binCardApiObject.requestTimestamp = (function(){
                                        if(freshPackMultiGrowerBinsItem.binCardApi.requestTimestamp === null)
                                        {
                                            return null;
                                        }
        
                                        if(typeof freshPackMultiGrowerBinsItem.binCardApi.requestTimestamp !== 'string')
                                        {
                                            return new Date(String(freshPackMultiGrowerBinsItem.binCardApi.requestTimestamp));
                                        }
        
                                        return new Date(freshPackMultiGrowerBinsItem.binCardApi.requestTimestamp);
                                    }());
                                }
                                else
                                {
                                    binCardApiObject.requestTimestamp = null;
                                }
                                
                                if(typeof freshPackMultiGrowerBinsItem.binCardApi === 'object' && 'responseCode' in freshPackMultiGrowerBinsItem.binCardApi)
                                {
                                    binCardApiObject.responseCode = (function(){
                                        if(freshPackMultiGrowerBinsItem.binCardApi.responseCode === null)
                                        {
                                            return null;
                                        }
        
                                        if(typeof freshPackMultiGrowerBinsItem.binCardApi.responseCode !== 'number')
                                        {
                                            return Number.isInteger(Number(freshPackMultiGrowerBinsItem.binCardApi.responseCode)) ? Number(freshPackMultiGrowerBinsItem.binCardApi.responseCode) : Math.floor(Number(freshPackMultiGrowerBinsItem.binCardApi.responseCode));
                                        }
        
                                        return Number.isInteger(freshPackMultiGrowerBinsItem.binCardApi.responseCode) ? freshPackMultiGrowerBinsItem.binCardApi.responseCode : Math.floor(freshPackMultiGrowerBinsItem.binCardApi.responseCode);
                                    }());
                                }
                                else
                                {
                                    binCardApiObject.responseCode = null;
                                }
                                
                                if(typeof freshPackMultiGrowerBinsItem.binCardApi === 'object' && 'responseMessage' in freshPackMultiGrowerBinsItem.binCardApi)
                                {
                                    binCardApiObject.responseMessage = (function(){
                                        if(freshPackMultiGrowerBinsItem.binCardApi.responseMessage === null)
                                        {
                                            return null;
                                        }
        
                                        if(typeof freshPackMultiGrowerBinsItem.binCardApi.responseMessage !== 'string')
                                        {
                                            return String(freshPackMultiGrowerBinsItem.binCardApi.responseMessage);
                                        }
        
                                        return freshPackMultiGrowerBinsItem.binCardApi.responseMessage;
                                    }());
                                }
                                else
                                {
                                    binCardApiObject.responseMessage = null;
                                }
                                
                                if(typeof freshPackMultiGrowerBinsItem.binCardApi === 'object' && 'completed' in freshPackMultiGrowerBinsItem.binCardApi)
                                {
                                    binCardApiObject.completed = (function(){
                                        if(typeof freshPackMultiGrowerBinsItem.binCardApi.completed !== 'boolean')
                                        {
                                            return Boolean(freshPackMultiGrowerBinsItem.binCardApi.completed);
                                        }
        
                                        return freshPackMultiGrowerBinsItem.binCardApi.completed;
                                    }());
                                }
                                else
                                {
                                    binCardApiObject.completed = false;
                                }
        
                                return binCardApiObject;
                            }());
                        }
                        else
                        {
                            freshPackMultiGrowerBinsItemObject.binCardApi = null;
                        }
        
                        return freshPackMultiGrowerBinsItemObject;
                    }());
                });
            }());
        }
        
        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 RejectBinModel;