import Offer from './offer';
import MenuItem from './menu-item';

export enum OutletType {
    FOOD = 'FOOD',
    SHOP = 'SHOP',
};

class Outlet {
    id: string;
    image_url?: string;
    name: string;
    description: string;
    offers: Array<string>;
    tags: Array<string>;
    menu_items: Array<string>;
    outlet_type: OutletType;
    is_bookmarked: boolean;
    rating: number;

    constructor(initializationObject: any) {
        if (!initializationObject.hasOwnProperty('id')) {
            throw new Error('Missing ID');
        }

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

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

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

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

        if (!initializationObject.hasOwnProperty('menu_items')) {
            throw new Error('Missing Menu Items');
        }

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

        if (!initializationObject.hasOwnProperty('is_bookmarked')) {
            throw new Error('Missing Bookmarked flag');
        }

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

        this.id = initializationObject.id;
        this.name = initializationObject.name;
        this.description = initializationObject.description;
        this.offers = initializationObject.offers;
        this.tags = initializationObject.tags;
        this.menu_items = initializationObject.menu_items;
        this.outlet_type = initializationObject.outlet_type;
        this.is_bookmarked = initializationObject.is_bookmarked;
        this.rating = initializationObject.rating;

        if (initializationObject.hasOwnProperty('image_url')) {
            this.image_url = initializationObject.image_url;
        }
    }
}

export interface IOutlet {
    id: string;
    image_url?: string;
    name: string;
    description: string;
    offers: Array<Offer>;
    tags: Array<string>;
    menu_items: Array<MenuItem>;
    outlet_type: OutletType;
    is_bookmarked: boolean;
    rating: number;
};

export default Outlet;
