var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/// <reference path="./AbstractEvent.ts" />
/// <reference path="./IProductEvent.ts" />
/// <reference path="../context/ProductReference.ts" />
/// <reference path="../context/IProductReferenceConfigOptions.ts" />
/// <reference path="../../serialization/ISerializable.ts" />
var econda;
(function (econda) {
    var recengine;
    (function (recengine) {
        var event;
        (function (event) {
            var AbstractEvent = econda.recengine.event.AbstractEvent;
            var ProductReference = econda.recengine.context.ProductReference;
            /**
             * Event when visitor buys a product. If there are different product in cart, there will be one event for each product.
             * @class econda.recengine.event.ProductBuyEvent
             */
            var ProductBuyEvent = (function (_super) {
                __extends(ProductBuyEvent, _super);
                function ProductBuyEvent(cfg) {
                    _super.call(this);
                    /**
                     * Number of units of referenced product added to cart
                     * @cfg {Number} count
                     * @accessor
                     */
                    this._count = 1;
                    /**
                     * Reference to product viewed
                     * @cfg {econda.recengine.context.ProductReference}
                     * @accessor
                     */
                    this._product = null;
                    if (cfg instanceof ProductBuyEvent) {
                        return cfg;
                    }
                    this.initConfig(cfg);
                }
                ProductBuyEvent.prototype.getCount = function () {
                    return this._count;
                };
                ProductBuyEvent.prototype.setCount = function (count) {
                    this._count = +count;
                };
                ProductBuyEvent.prototype.getProduct = function () {
                    return this._product;
                };
                ProductBuyEvent.prototype.setProduct = function (productReference) {
                    this._product = new ProductReference(productReference);
                };
                ProductBuyEvent.prototype.getObjectData = function () {
                    return {
                        className: 'econda.recengine.event.ProductBuyEvent',
                        data: {
                            timestamp: this.getTimestamp(),
                            count: this._count,
                            product: this._product
                        }
                    };
                };
                ProductBuyEvent.prototype.setObjectData = function (data) {
                    if (typeof data === 'object' && data !== null) {
                        this.setTimestamp(data.timestamp);
                        this._count = data.count || 1;
                        this._product = data.product || null;
                    }
                };
                ProductBuyEvent.TYPE = 'product:buy';
                return ProductBuyEvent;
            }(AbstractEvent));
            event.ProductBuyEvent = ProductBuyEvent;
        })(event = recengine.event || (recengine.event = {}));
    })(recengine = econda.recengine || (econda.recengine = {}));
})(econda || (econda = {}));