package `in`.techware.carrefour.viewModels

import `in`.techware.carrefour.model.MenuBean
import `in`.techware.carrefour.model.StockTakeBean
import android.arch.lifecycle.ViewModel

/**
 * Created by Jemsheer K D on 27 July, 2018.
 * Package `in`.techware.carrefour.viewModels
 * Project Carrefour
 */
class StockTakeViewModel : ViewModel() {

    var zoneType: String = ""
    var barcode: String = ""
    var isQuantityEnabled: Boolean = true
    var quantity: Float = 1F

    var selectedMenuBean: MenuBean? = null
    var selectedSubMenuBean: MenuBean? = null

    var lastEntry: StockTakeBean? = null
    var isModifyEnabled: Boolean = false
    var modifiedID: Long = 0

    var stockTakeList: ArrayList<StockTakeBean> = ArrayList()

    fun setData(bean: StockTakeBean) {

        zoneType = bean.zoneType
        barcode = bean.barcode
        isQuantityEnabled = bean.isQuantityEnabled
        quantity = bean.quantity

        lastEntry = null
    }

    fun generateStockTakeBean(): StockTakeBean {
        var stockTakeBean = StockTakeBean()

        stockTakeBean.zoneType = zoneType
        stockTakeBean.barcode = barcode
        stockTakeBean.isQuantityEnabled = isQuantityEnabled
        stockTakeBean.quantity = quantity

        return stockTakeBean
    }

    fun isDataCollected(): Boolean {
        return (zoneType != "" && barcode != "" && quantity != 0F)

    }

    fun clearStockTake() {
        barcode = ""
//        isQuantityEnabled = true
        quantity = 1F
    }

    fun indexOf(stockTakeBean: StockTakeBean): Int {
        for (bean in stockTakeList) {
            if (bean.id == stockTakeBean.id) {
                return stockTakeList.indexOf(bean)
            }
        }
        return -1
    }

    fun lastIndex(): Int {
        return stockTakeList.size - 1
    }
}