import Offer from '../models/offer';
import { CoOrdinates } from '../shared/common-types';
import { IOutlet } from '../models/outlet';

export default class Mall {
    id: string;
    name: string;
    is_bookmarked: boolean;
    is_archived: boolean;
    image_url?: string;
    description: string;
    offers: Array<string>;
    outlets: Array<string>;
    rating: number;
    distance: number;
    location: CoOrdinates;
    address: string;


    constructor(initializationObject: any) {
        if (!initializationObject.hasOwnProperty('id')) {
            throw new Error('Missing id');
        }
        if (!initializationObject.hasOwnProperty('name')) {
            throw new Error('Missing name');
        }
        if (!initializationObject.hasOwnProperty('is_bookmarked')) {
            throw new Error('Missing is_bookmarked');
        }
        if (!initializationObject.hasOwnProperty('is_archived')) {
            throw new Error('Missing is_archived');
        }
        if (!initializationObject.hasOwnProperty('description')) {
            throw new Error('Missing description');
        }
        if (!initializationObject.hasOwnProperty('offers')) {
            throw new Error('Missing offers');
        }
        if (!initializationObject.hasOwnProperty('outlets')) {
            throw new Error('Missing outlets');
        }
        if (!initializationObject.hasOwnProperty('rating')) {
            throw new Error('Missing rating');
        }
        if (!initializationObject.hasOwnProperty('distance')) {
            throw new Error('Missing distance');
        }
        if (!initializationObject.hasOwnProperty('location')) {
            throw new Error('Missing location');
        }
        if (!initializationObject.hasOwnProperty('address')) {
            throw new Error('Missing address');
        }

        this.id = initializationObject.id;
        this.name = initializationObject.name;
        this.is_bookmarked = initializationObject.is_bookmarked;
        this.is_archived = initializationObject.is_archived;
        this.description = initializationObject.description;
        this.offers = initializationObject.offers;
        this.outlets = initializationObject.outlets;
        this.rating = initializationObject.rating;
        this.distance = initializationObject.distance;
        this.location = initializationObject.location;
        this.address = initializationObject.address;

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

export interface IMall {
    id: string;
    name: string;
    is_bookmarked: boolean;
    is_archived: boolean;
    image_url?: string;
    description: string;
    offers: Array<Offer>;
    outlets: Array<IOutlet>;
    rating: number;
    distance: number;
    location: CoOrdinates;
    address: string;
}
