package `in`.techware.carrefour.viewModels

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

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

    var barcode: String = ""
    var section: String = ""
    var price: Float = 0F

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

    var isPriceEnabled: Boolean = false

    var lastEntry: LabelSurveyBean? = null
    var isModifyEnabled: Boolean = false
    var modifiedID: Long = 0

    var labelSurveyList: ArrayList<LabelSurveyBean> = ArrayList()

    fun setData(bean: LabelSurveyBean) {

        barcode = bean.barcode
        section = bean.section
        price = bean.price

        lastEntry = null
    }

    fun generateLabelSurveyBean(): LabelSurveyBean {
        var labelSurveyBean = LabelSurveyBean()

        labelSurveyBean.barcode = barcode
        labelSurveyBean.section = section
        labelSurveyBean.price = price

        return labelSurveyBean
    }

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

    }

    fun clearLabelSurvey() {
//        section = ""
        barcode = ""
        price = 0F
    }

    fun indexOf(labelSurveyBean: LabelSurveyBean): Int {
        for (bean in labelSurveyList) {
            if (bean.id == labelSurveyBean.id) {
                return labelSurveyList.indexOf(bean)
            }
        }
        return -1
    }

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