class Offer {
    id: string;
    name: string;
    description: string;
    coupon_code: string;
    image_url?: string;

    constructor(initializationObject: any) {

        // Check if object has the required fields
        if (!initializationObject.hasOwnProperty('id')) {
            throw new Error('The offer needs a id');
        }

        if (!initializationObject.hasOwnProperty('name')) {
            throw new Error('The offer needs a name');
        }

        if (!initializationObject.hasOwnProperty('description')) {
            throw new Error('The offer needs a description');
        }

        if (!initializationObject.hasOwnProperty('coupon_code')) {
            throw new Error('The offer needs a coupon_code');
        }

        this.name = initializationObject.name;
        this.description = initializationObject.description;
        this.coupon_code = initializationObject.coupon_code;

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

export default Offer;
