package `in`.techware.carrefour.viewModels

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

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

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


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

    var itemListList: ArrayList<ItemListBean> = ArrayList()

    fun setData(bean: ItemListBean) {

        barcode = bean.barcode
        quantity = bean.quantity

        lastEntry = null
    }

    fun generateItemListBean(): ItemListBean {
        var itemListBean = ItemListBean()

        itemListBean.barcode = barcode
        itemListBean.quantity = quantity

        return itemListBean
    }

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

    }

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

    fun indexOf(itemListBean: ItemListBean): Int {
        for (bean in itemListList) {
            if (bean.barcode == itemListBean.barcode) {
                return itemListList.indexOf(bean)
            }
        }
        return -1
    }

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