class Product {
    constructor(sku, quantity, storeType) {
        this.sku = sku;
        this.quantity = quantity;
        this.storeType = storeType

    }
}

class PartnerCollection {

    static STORE_TYPE() {
        return 'GROCERY';
    }

    constructor(aCollection) {
        this.name = aCollection.name;
        this.products = aCollection.items.map(item => new Product(item.sku, item.quantity, PartnerCollection.STORE_TYPE()));

        this.init();
    }

    init() {
        window['productCollectionName'] = this.name;
        window['storeType'] = PartnerCollection.STORE_TYPE();
        let firstTile = $('.item-addToCart').first();
        let productsTilesList = [firstTile];
        let trigger = $('.cta-primary', firstTile).first();


    }

    addProductsToCart() {
        console.log(this.products);
        this.getData();
    }

    getData() {
        this.loadData(2).then(result => console.log(value));
    }


    loadData(param) {
        return new Promise((resolve, reject) =>
            $.ajax({
                url: 'http://localhost:8080/api/bank/account?bankId=' + param,
                type: 'GET',
                headers: {
                    'Accept-Language': window['acceptLanguage']
                },
                contentType: 'application/json; charset=utf-8',
                success: function (data) {
                    resolve(data);
                },
                error: function (jqXHR) {
                    reject(jqXHR)
                }
            })
        );
    }


}

var productsCollection = {
    id: 'collection1',
    items: [{
        sku: 'sku1',
        quantity: 8
    }]
};

$(document).ready(function () {
    if (typeof productsCollection !== 'undefined') {
        setTimeout(() => {
            let p = new PartnerCollection(productsCollection);
            p.addProductsToCart();
        });
    }
});