import MenuItem from './menu-item';

export default class CartItem {
    menu_item: string;
    quantity: number;
    pickup_time: Date;
    outlet_id: string;
    mall_id: string;
    take_away: boolean;
    total_price: number;

    constructor(initializationObject: any) {
        if (!initializationObject.hasOwnProperty('menu_item')) {
            throw new Error('Missing Menu item');
        }

        if (!initializationObject.hasOwnProperty('quantity')) {
            throw new Error('Missing quantity');
        }

        if (!initializationObject.hasOwnProperty('pickup_time')) {
            throw new Error('Missing Pickup time');
        }

        if (!initializationObject.hasOwnProperty('outlet_id')) {
            throw new Error('Missing Outlet ID');
        }

        if (!initializationObject.hasOwnProperty('mall_id')) {
            throw new Error('Missing Mall ID');
        }

        if (!initializationObject.hasOwnProperty('take_away')) {
            throw new Error('Missing Parcel Flag');
        }
        this.menu_item = initializationObject.menu_item;
        this.quantity = initializationObject.quantity;
        this.pickup_time = initializationObject.pickup_time;
        this.outlet_id = initializationObject.outlet_id;
        this.mall_id = initializationObject.mall_id;
        this.take_away = initializationObject.take_away;
        this.total_price = initializationObject.total_price;
    }
}

export interface ICartItem {
    menu_item: MenuItem;
    quantity: number;
    pickup_time: Date;
    outlet_id: string;
    mall_id: string;
    take_away: boolean;
    total_price: number;
}
