#include "commodityservice.h"

#include "commodity-odb.hxx"

CommodityService::CommodityService()
{

}

QList<QSharedPointer<ShopItem> > CommodityService::shopItems()
{
    QList<QSharedPointer<ShopItem> > ret;

    foreach (QSharedPointer<CommodityData> data, all()) {
        ret.append(qSharedPointerDynamicCast<ShopItem, CommodityData>(data));
    }

    return ret;
}

void CommodityService::addedToVoucher(int itemId, int countAdded)
{
    QSharedPointer<CommodityData> commodity = loadById(itemId);

    if (!commodity.isNull())
    {
        commodity->setCount(commodity->count() - countAdded);
    }

    update(commodity);
}
