package `in`.techware.carrefour.viewModels

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

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

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


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

    var facingList: ArrayList<FacingBean> = ArrayList()

    fun setData(bean: FacingBean) {

        barcode = bean.barcode
        quantity = bean.quantity

        lastEntry = null
    }

    fun generateFacingBean(): FacingBean {
        var facingBean = FacingBean()

        facingBean.barcode = barcode
        facingBean.quantity = quantity

        return facingBean
    }

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

    }

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

    fun indexOf(facingBean: FacingBean): Int {
        for (bean in facingList) {
            if (bean.barcode == facingBean.barcode) {
                return facingList.indexOf(bean)
            }
        }
        return -1
    }

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