package `in`.techware.carrefour.viewModels

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

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

    var barcode: String = ""

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


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

    var transformQuantityList: ArrayList<TransformQuantityBean> = ArrayList()

    fun setData(bean: TransformQuantityBean) {

        barcode = bean.barcode

        lastEntry = null
    }

    fun generateTransformQuantityBean(): TransformQuantityBean {
        var transformQuantityBean = TransformQuantityBean()

        transformQuantityBean.barcode = barcode

        return transformQuantityBean
    }

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

    }

    fun clearTransformQuantity() {
        barcode = ""
    }

    fun indexOf(transformQuantityBean: TransformQuantityBean): Int {
        for (bean in transformQuantityList) {
            if (bean.barcode == transformQuantityBean.barcode) {
                return transformQuantityList.indexOf(bean)
            }
        }
        return -1
    }

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