package `in`.techware.carrefour.viewModels

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

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

    var barcode: String = ""
    var quantity: Float = 0F

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


    var lastEntry: MinStockBean? = null
    var isModifyEnabled: Boolean = false

    var minStockList: ArrayList<MinStockBean> = ArrayList()

    fun setData(bean: MinStockBean) {

        barcode = bean.barcode
        quantity = bean.quantity

        lastEntry = null
    }

    fun generateMinStockBean(): MinStockBean {
        var minStockBean = MinStockBean()

        minStockBean.barcode = barcode
        minStockBean.quantity = quantity

        return minStockBean
    }

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

    }

    fun clearMinStock() {
        barcode = ""
        quantity = 0F
    }

    fun indexOf(minStockBean: MinStockBean): Int {
        for (bean in minStockList) {
            if (bean.barcode == minStockBean.barcode) {
                return minStockList.indexOf(bean)
            }
        }
        return -1
    }

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