// Path: app/src/main/java/org/clintonhealthaccess/lmis/app/models/reports/UtilizationValue.java
// @Getter
// @ToString
// public class UtilizationValue {
//     int day;
//     int value;
//     public UtilizationValue(int day, int value){
//         this.day = day;
//         this.value = value;
//     }
// }


import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.inject.Inject;
import org.clintonhealthaccess.lmis.app.models.Commodity;
import org.clintonhealthaccess.lmis.app.models.Loss;
import org.clintonhealthaccess.lmis.app.models.LossItem;
import org.clintonhealthaccess.lmis.app.models.LossItemDetail;
import org.clintonhealthaccess.lmis.app.models.reports.UtilizationValue;
import org.clintonhealthaccess.lmis.app.utils.DateUtil;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import android.content.Context;
    @Inject
    CommodityService commodityService;

    public void saveLoss(Loss loss) {
        GenericDao<Loss> lossDao = new GenericDao<>(Loss.class, context);
        lossDao.create(loss);
        saveLossItems(loss.getLossItems());
    }

    private void saveLossItems(List<LossItem> lossItems) {
        GenericDao<LossItem> lossItemDao = new GenericDao<>(LossItem.class, context);
        for (LossItem lossItem : lossItems) {
            lossItemDao.create(lossItem);
            saveLossItemDetails(lossItem.getLossItemDetails());
            adjustStockLevel(lossItem);
            snapshotService.add(lossItem);
        }
    }

    private void saveLossItemDetails(List<LossItemDetail> lossItemDetails) {
        GenericDao<LossItemDetail> lossItemDetailDao = new GenericDao<>(LossItemDetail.class, context);
        for (LossItemDetail lossItemDetail : lossItemDetails) {
            lossItemDetailDao.create(lossItemDetail);
        }
    }

    private void adjustStockLevel(LossItem lossItem) {
        stockService.reduceStockLevelFor(lossItem.getCommodity(), lossItem.getTotalLosses(), lossItem.created());
    }

// Path: app/src/main/java/org/clintonhealthaccess/lmis/app/models/reports/UtilizationValue.java
// @Getter
// @ToString
// public class UtilizationValue {
//     int day;
//     int value;
//     public UtilizationValue(int day, int value){
//         this.day = day;
//         this.value = value;
//     }
// }


// Path: app/src/main/java/org/clintonhealthaccess/lmis/app/services/LossService.java
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.inject.Inject;
import org.clintonhealthaccess.lmis.app.models.Commodity;
import org.clintonhealthaccess.lmis.app.models.Loss;
import org.clintonhealthaccess.lmis.app.models.LossItem;
import org.clintonhealthaccess.lmis.app.models.LossItemDetail;
import org.clintonhealthaccess.lmis.app.models.reports.UtilizationValue;
import org.clintonhealthaccess.lmis.app.utils.DateUtil;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import android.content.Context;

    @Inject
    CommodityService commodityService;

    public void saveLoss(Loss loss) {
        GenericDao<Loss> lossDao = new GenericDao<>(Loss.class, context);
        lossDao.create(loss);
        saveLossItems(loss.getLossItems());
    }

    private void saveLossItems(List<LossItem> lossItems) {
        GenericDao<LossItem> lossItemDao = new GenericDao<>(LossItem.class, context);
        for (LossItem lossItem : lossItems) {
            lossItemDao.create(lossItem);
            saveLossItemDetails(lossItem.getLossItemDetails());
            adjustStockLevel(lossItem);
            snapshotService.add(lossItem);
        }
    }

    private void saveLossItemDetails(List<LossItemDetail> lossItemDetails) {
        GenericDao<LossItemDetail> lossItemDetailDao = new GenericDao<>(LossItemDetail.class, context);
        for (LossItemDetail lossItemDetail : lossItemDetails) {
            lossItemDetailDao.create(lossItemDetail);
        }
    }

    private void adjustStockLevel(LossItem lossItem) {
        stockService.reduceStockLevelFor(lossItem.getCommodity(), lossItem.getTotalLosses(), lossItem.created());
    }

    public List<UtilizationValue> getLossesValues(Commodity commodity, Date startDate, Date endDate) {