RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Models/Packhouse/Site/FreshPackPackrunSummaryModel.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 FreshPack Packrun Summary
 * 
 * @class
 * @hideconstructor
 * @extends BaseModel
 */
class FreshPackPackrunSummaryModel extends BaseModel
{
    /**
     * FreshPackPackrunSummaryModel Constructor
     * 
     * @protected
     * @param {number} siteId The Site ID associated with this FreshPack Packrun Summary
     */
    constructor(siteId)
    {
        super();
        
        /**
         * The FreshPack Packrun Summary ID
         * 
         * @type {string}
         * @public
         */
        this.id = "";
        
        /**
         * The Packing Line ID this Summary is associated with
         * 
         * @type {string}
         * @public
         */
        this.packingLineId = "";
        
        /**
         * The Packrun ID this Summary is associated with
         * 
         * @type {string}
         * @public
         */
        this.packrunId = "";
        
        /**
         * When this Summary was Created
         * 
         * @type {Date}
         * @public
         */
        this.createdTimestamp = new Date();
        
        /**
         * The Time Batch this Summary is associated with
         * 
         * @type {?string}
         * @public
         */
        this.timeBatchId = null;
        
        /**
         * An Array of Tray Summary Data Objects for all Sizes and Class Types
         * 
         * @type {Array<{classType: string, fruitSize: ?string, trayCount: number, averageTrayWeight: number, weight: number}>}
         * @public
         */
        this.traySummaries = [];
        
        /**
         * An Array of Clearance Summary Data Objects for all Sizes
         * 
         * @type {Array<{fruitSize: ?string, tasteBand: ?string, maturityProtocol: ?string, harvestProtocol: ?string, clearanceDate: ?Date, kiwiStartDate: ?Date, trayEstimate: ?number, protocolADate: ?Date, protocolBDate: ?Date, protocolCDate: ?Date, protocolNDate: ?Date, useNIRPacking: ?boolean}>}
         * @public
         */
        this.clearanceSummaries = [];
        
        /**
         * Whether the FreshPack Packrun Summary has been deleted
         * 
         * @type {boolean}
         * @public
         */
        this.deleted = false;
        
        /**
         * When the FreshPack Packrun Summary was last updated
         * 
         * @type {Date}
         * @public
         */
        this.updateTimestamp = new Date();
        
        /**
         * The Site ID associated with this FreshPack Packrun Summary
         * 
         * @type {number}
         * @public
         */
        this.siteId = siteId;
    }

    /**
     * Create a new **FreshPackPackrunSummaryModel** 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 FreshPack Packrun Summary
     * @return {FreshPackPackrunSummaryModel}
     */
    static fromJSON(json, siteId)
    {
        let model = new FreshPackPackrunSummaryModel(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('packingLineId' in jsonObject)
        {
            model.packingLineId = (function(){
                if(typeof jsonObject['packingLineId'] !== 'string')
                {
                    return String(jsonObject['packingLineId']);
                }
        
                return jsonObject['packingLineId'];
            }());
        }
        
        if('packrunId' in jsonObject)
        {
            model.packrunId = (function(){
                if(typeof jsonObject['packrunId'] !== 'string')
                {
                    return String(jsonObject['packrunId']);
                }
        
                return jsonObject['packrunId'];
            }());
        }
        
        if('createdTimestamp' in jsonObject)
        {
            model.createdTimestamp = (function(){
                if(typeof jsonObject['createdTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['createdTimestamp']));
                }
        
                return new Date(jsonObject['createdTimestamp']);
            }());
        }
        
        if('timeBatchId' in jsonObject)
        {
            model.timeBatchId = (function(){
                if(jsonObject['timeBatchId'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['timeBatchId'] !== 'string')
                {
                    return String(jsonObject['timeBatchId']);
                }
        
                return jsonObject['timeBatchId'];
            }());
        }
        
        if('traySummaries' in jsonObject)
        {
            model.traySummaries = (function(){
                if(Array.isArray(jsonObject['traySummaries']) !== true)
                {
                    return [];
                }
        
                return jsonObject['traySummaries'].map((traySummariesItem) => {
                    return (function(){
                        let traySummariesItemObject = {};
                        
                        if(typeof traySummariesItem === 'object' && 'classType' in traySummariesItem)
                        {
                            traySummariesItemObject.classType = (function(){
                                if(typeof traySummariesItem.classType !== 'string')
                                {
                                    return String(traySummariesItem.classType);
                                }
        
                                return traySummariesItem.classType;
                            }());
                        }
                        else
                        {
                            traySummariesItemObject.classType = "";
                        }
                        
                        if(typeof traySummariesItem === 'object' && 'fruitSize' in traySummariesItem)
                        {
                            traySummariesItemObject.fruitSize = (function(){
                                if(traySummariesItem.fruitSize === null)
                                {
                                    return null;
                                }
        
                                if(typeof traySummariesItem.fruitSize !== 'string')
                                {
                                    return String(traySummariesItem.fruitSize);
                                }
        
                                return traySummariesItem.fruitSize;
                            }());
                        }
                        else
                        {
                            traySummariesItemObject.fruitSize = null;
                        }
                        
                        if(typeof traySummariesItem === 'object' && 'trayCount' in traySummariesItem)
                        {
                            traySummariesItemObject.trayCount = (function(){
                                if(typeof traySummariesItem.trayCount !== 'number')
                                {
                                    return Number(traySummariesItem.trayCount);
                                }
        
                                return traySummariesItem.trayCount;
                            }());
                        }
                        else
                        {
                            traySummariesItemObject.trayCount = 0;
                        }
                        
                        if(typeof traySummariesItem === 'object' && 'averageTrayWeight' in traySummariesItem)
                        {
                            traySummariesItemObject.averageTrayWeight = (function(){
                                if(typeof traySummariesItem.averageTrayWeight !== 'number')
                                {
                                    return Number(traySummariesItem.averageTrayWeight);
                                }
        
                                return traySummariesItem.averageTrayWeight;
                            }());
                        }
                        else
                        {
                            traySummariesItemObject.averageTrayWeight = 0;
                        }
                        
                        if(typeof traySummariesItem === 'object' && 'weight' in traySummariesItem)
                        {
                            traySummariesItemObject.weight = (function(){
                                if(typeof traySummariesItem.weight !== 'number')
                                {
                                    return Number(traySummariesItem.weight);
                                }
        
                                return traySummariesItem.weight;
                            }());
                        }
                        else
                        {
                            traySummariesItemObject.weight = 0;
                        }
        
                        return traySummariesItemObject;
                    }());
                });
            }());
        }
        
        if('clearanceSummaries' in jsonObject)
        {
            model.clearanceSummaries = (function(){
                if(Array.isArray(jsonObject['clearanceSummaries']) !== true)
                {
                    return [];
                }
        
                return jsonObject['clearanceSummaries'].map((clearanceSummariesItem) => {
                    return (function(){
                        let clearanceSummariesItemObject = {};
                        
                        if(typeof clearanceSummariesItem === 'object' && 'fruitSize' in clearanceSummariesItem)
                        {
                            clearanceSummariesItemObject.fruitSize = (function(){
                                if(clearanceSummariesItem.fruitSize === null)
                                {
                                    return null;
                                }
        
                                if(typeof clearanceSummariesItem.fruitSize !== 'string')
                                {
                                    return String(clearanceSummariesItem.fruitSize);
                                }
        
                                return clearanceSummariesItem.fruitSize;
                            }());
                        }
                        else
                        {
                            clearanceSummariesItemObject.fruitSize = null;
                        }
                        
                        if(typeof clearanceSummariesItem === 'object' && 'tasteBand' in clearanceSummariesItem)
                        {
                            clearanceSummariesItemObject.tasteBand = (function(){
                                if(clearanceSummariesItem.tasteBand === null)
                                {
                                    return null;
                                }
        
                                if(typeof clearanceSummariesItem.tasteBand !== 'string')
                                {
                                    return String(clearanceSummariesItem.tasteBand);
                                }
        
                                return clearanceSummariesItem.tasteBand;
                            }());
                        }
                        else
                        {
                            clearanceSummariesItemObject.tasteBand = null;
                        }
                        
                        if(typeof clearanceSummariesItem === 'object' && 'maturityProtocol' in clearanceSummariesItem)
                        {
                            clearanceSummariesItemObject.maturityProtocol = (function(){
                                if(clearanceSummariesItem.maturityProtocol === null)
                                {
                                    return null;
                                }
        
                                if(typeof clearanceSummariesItem.maturityProtocol !== 'string')
                                {
                                    return String(clearanceSummariesItem.maturityProtocol);
                                }
        
                                return clearanceSummariesItem.maturityProtocol;
                            }());
                        }
                        else
                        {
                            clearanceSummariesItemObject.maturityProtocol = null;
                        }
                        
                        if(typeof clearanceSummariesItem === 'object' && 'harvestProtocol' in clearanceSummariesItem)
                        {
                            clearanceSummariesItemObject.harvestProtocol = (function(){
                                if(clearanceSummariesItem.harvestProtocol === null)
                                {
                                    return null;
                                }
        
                                if(typeof clearanceSummariesItem.harvestProtocol !== 'string')
                                {
                                    return String(clearanceSummariesItem.harvestProtocol);
                                }
        
                                return clearanceSummariesItem.harvestProtocol;
                            }());
                        }
                        else
                        {
                            clearanceSummariesItemObject.harvestProtocol = null;
                        }
                        
                        if(typeof clearanceSummariesItem === 'object' && 'clearanceDate' in clearanceSummariesItem)
                        {
                            clearanceSummariesItemObject.clearanceDate = (function(){
                                if(clearanceSummariesItem.clearanceDate === null)
                                {
                                    return null;
                                }
        
                                if(typeof clearanceSummariesItem.clearanceDate !== 'string')
                                {
                                    return new Date(String(clearanceSummariesItem.clearanceDate));
                                }
        
                                return new Date(clearanceSummariesItem.clearanceDate);
                            }());
                        }
                        else
                        {
                            clearanceSummariesItemObject.clearanceDate = null;
                        }
                        
                        if(typeof clearanceSummariesItem === 'object' && 'kiwiStartDate' in clearanceSummariesItem)
                        {
                            clearanceSummariesItemObject.kiwiStartDate = (function(){
                                if(clearanceSummariesItem.kiwiStartDate === null)
                                {
                                    return null;
                                }
        
                                if(typeof clearanceSummariesItem.kiwiStartDate !== 'string')
                                {
                                    return new Date(String(clearanceSummariesItem.kiwiStartDate));
                                }
        
                                return new Date(clearanceSummariesItem.kiwiStartDate);
                            }());
                        }
                        else
                        {
                            clearanceSummariesItemObject.kiwiStartDate = null;
                        }
                        
                        if(typeof clearanceSummariesItem === 'object' && 'trayEstimate' in clearanceSummariesItem)
                        {
                            clearanceSummariesItemObject.trayEstimate = (function(){
                                if(clearanceSummariesItem.trayEstimate === null)
                                {
                                    return null;
                                }
        
                                if(typeof clearanceSummariesItem.trayEstimate !== 'number')
                                {
                                    return Number.isInteger(Number(clearanceSummariesItem.trayEstimate)) ? Number(clearanceSummariesItem.trayEstimate) : Math.floor(Number(clearanceSummariesItem.trayEstimate));
                                }
        
                                return Number.isInteger(clearanceSummariesItem.trayEstimate) ? clearanceSummariesItem.trayEstimate : Math.floor(clearanceSummariesItem.trayEstimate);
                            }());
                        }
                        else
                        {
                            clearanceSummariesItemObject.trayEstimate = null;
                        }
                        
                        if(typeof clearanceSummariesItem === 'object' && 'protocolADate' in clearanceSummariesItem)
                        {
                            clearanceSummariesItemObject.protocolADate = (function(){
                                if(clearanceSummariesItem.protocolADate === null)
                                {
                                    return null;
                                }
        
                                if(typeof clearanceSummariesItem.protocolADate !== 'string')
                                {
                                    return new Date(String(clearanceSummariesItem.protocolADate));
                                }
        
                                return new Date(clearanceSummariesItem.protocolADate);
                            }());
                        }
                        else
                        {
                            clearanceSummariesItemObject.protocolADate = null;
                        }
                        
                        if(typeof clearanceSummariesItem === 'object' && 'protocolBDate' in clearanceSummariesItem)
                        {
                            clearanceSummariesItemObject.protocolBDate = (function(){
                                if(clearanceSummariesItem.protocolBDate === null)
                                {
                                    return null;
                                }
        
                                if(typeof clearanceSummariesItem.protocolBDate !== 'string')
                                {
                                    return new Date(String(clearanceSummariesItem.protocolBDate));
                                }
        
                                return new Date(clearanceSummariesItem.protocolBDate);
                            }());
                        }
                        else
                        {
                            clearanceSummariesItemObject.protocolBDate = null;
                        }
                        
                        if(typeof clearanceSummariesItem === 'object' && 'protocolCDate' in clearanceSummariesItem)
                        {
                            clearanceSummariesItemObject.protocolCDate = (function(){
                                if(clearanceSummariesItem.protocolCDate === null)
                                {
                                    return null;
                                }
        
                                if(typeof clearanceSummariesItem.protocolCDate !== 'string')
                                {
                                    return new Date(String(clearanceSummariesItem.protocolCDate));
                                }
        
                                return new Date(clearanceSummariesItem.protocolCDate);
                            }());
                        }
                        else
                        {
                            clearanceSummariesItemObject.protocolCDate = null;
                        }
                        
                        if(typeof clearanceSummariesItem === 'object' && 'protocolNDate' in clearanceSummariesItem)
                        {
                            clearanceSummariesItemObject.protocolNDate = (function(){
                                if(clearanceSummariesItem.protocolNDate === null)
                                {
                                    return null;
                                }
        
                                if(typeof clearanceSummariesItem.protocolNDate !== 'string')
                                {
                                    return new Date(String(clearanceSummariesItem.protocolNDate));
                                }
        
                                return new Date(clearanceSummariesItem.protocolNDate);
                            }());
                        }
                        else
                        {
                            clearanceSummariesItemObject.protocolNDate = null;
                        }
                        
                        if(typeof clearanceSummariesItem === 'object' && 'useNIRPacking' in clearanceSummariesItem)
                        {
                            clearanceSummariesItemObject.useNIRPacking = (function(){
                                if(clearanceSummariesItem.useNIRPacking === null)
                                {
                                    return null;
                                }
        
                                if(typeof clearanceSummariesItem.useNIRPacking !== 'boolean')
                                {
                                    return Boolean(clearanceSummariesItem.useNIRPacking);
                                }
        
                                return clearanceSummariesItem.useNIRPacking;
                            }());
                        }
                        else
                        {
                            clearanceSummariesItemObject.useNIRPacking = null;
                        }
        
                        return clearanceSummariesItemObject;
                    }());
                });
            }());
        }
        
        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 FreshPackPackrunSummaryModel;