package `in`.techware.carrefour.viewModels

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

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

    var gondolaSelectedPosition: Int = -1
    var gondola: String = ""
    var gondolaList: ArrayList<String> = ArrayList()
    var barcode: String = ""

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

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

    var promotionList: ArrayList<PromotionBean> = ArrayList()

    fun setData(bean: PromotionBean) {

        gondolaSelectedPosition = bean.gondolaSelectedPosition
        gondola = bean.gondola
        barcode = bean.barcode

        lastEntry = null
    }

    fun generatePromotionBean(): PromotionBean {
        var promotionBean = PromotionBean()

        promotionBean.gondolaSelectedPosition = gondolaSelectedPosition
        promotionBean.gondola = gondola
        promotionBean.barcode = barcode

        return promotionBean
    }

    fun isDataCollected(): Boolean {
        return (gondolaSelectedPosition != -1
                && gondola != "" && barcode != "" )
    }

    fun clearPromotion() {
        barcode = ""
//        isQuantityEnabled = true
    }

    fun indexOf(promotionBean: PromotionBean): Int {
        for (bean in promotionList) {
            if (bean.id == promotionBean.id) {
                return promotionList.indexOf(bean)
            }
        }
        return -1
    }

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

}