var Backbone = require('backbone');
var Globals = require('../globals');
var Mutators = require('Backbone.Mutators');

var ItemWithDetails = Backbone.Model.extend({

    urlRoot: Globals.ApiUrl + '/item',
    mutators: {
        pricePerUnit: function() {
            var unitsInPack = this.get('units_in_pack');
            if (unitsInPack == undefined || unitsInPack <= 1) return "";
            unitsInPack = parseFloat(unitsInPack).toFixed(0);
            var price = parseFloat(this.get('list_price')).toFixed(2)
            var pricePerUnit = (price / unitsInPack).toFixed(2);
            var descriptionSuffix = this.get('unit').description_suffix;
            return Globals.FormatCurrency(pricePerUnit); 
        }
    },
    defaults : {
        brand: {}
    }

});

module.exports = ItemWithDetails;
