package `in`.techware.carrefour.viewModels

import `in`.techware.carrefour.model.OutOfStockBean
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 OutOfStockViewModel : ViewModel() {

    var barcode: String = ""

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


    var lastEntry: OutOfStockBean? = null
    var isModifyEnabled: Boolean = false
    var modifiedID: String = ""

    var outOfStockList: ArrayList<OutOfStockBean> = ArrayList()

    fun setData(bean: OutOfStockBean) {

        barcode = bean.barcode

        lastEntry = null
    }

    fun generateOutOfStockBean(): OutOfStockBean {
        var outOfStockBean = OutOfStockBean()

        outOfStockBean.barcode = barcode

        return outOfStockBean
    }

    fun isDataCollected(): Boolean {
        return (barcode != "")

    }

    fun clearOutOfStock() {
        barcode = ""
    }

    fun indexOf(outOfStockBean: OutOfStockBean): Int {
        for (bean in outOfStockList) {
            if (bean.barcode == outOfStockBean.barcode) {
                return outOfStockList.indexOf(bean)
            }
        }
        return -1
    }

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

}