package `in`.techware.carrefour.viewModels

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

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

    var barcode: String = ""
    var isQuantityEnabled: Boolean = true
    var quantity: Float = 1F
    var printerSelectedPosition: Int = -1
    var printerList: List<PrinterBean> = ArrayList()

    var labelType: Int = 0
    var printerBean: PrinterBean? = null
    var selectedMenuBean: MenuBean? = null
    var selectedSubMenuBean: MenuBean? = null



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

    var printLabelList: ArrayList<PrintLabelBean> = ArrayList()

    fun setData(bean: PrintLabelBean) {

        barcode = bean.barcode
        isQuantityEnabled = bean.isQuantityEnabled
        quantity = bean.quantity

        lastEntry = null
    }

    fun generatePrintLabelBean(): PrintLabelBean {
        var printLabelBean = PrintLabelBean()

        printLabelBean.printerLabel = if (printerBean != null) printerBean!!.label else ""
        printLabelBean.labelType = labelType
        printLabelBean.barcode = barcode
        printLabelBean.isQuantityEnabled = isQuantityEnabled
        printLabelBean.quantity = quantity

        return printLabelBean
    }

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

    }

    fun clearPrintLabel() {
        barcode = ""
//        isQuantityEnabled = true
        quantity = 1F
    }

    fun indexOf(printLabelBean: PrintLabelBean): Int {
        for (bean in printLabelList) {
            if (bean.id == printLabelBean.id) {
                return printLabelList.indexOf(bean)
            }
        }
        return -1
    }

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