package com.gingersoft.supply_chain.mvp.content;

import com.gingersoft.supply_chain.mvp.bean.PurchaseFoodBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

/**
 * @author 宇航.
 * User: admin
 * Date: 2020/12/4
 * Time: 11:21
 * Use: 供應鏈購物車,需要緩存用戶選中的食品
 */
public class SupplyShoppingCart {
    /**
     * key為食品id
     * value為食品信息
     */
    private static List<PurchaseFoodBean> cartFoods;

    private static SupplyShoppingCart shoppingCart;

    private int goodsNumber = 0;

    public static SupplyShoppingCart getInstance() {
        if (shoppingCart == null) {
            shoppingCart = new SupplyShoppingCart();
        }
        return shoppingCart;
    }

    public List<PurchaseFoodBean> getCartFoods() {
        if (cartFoods == null) {
            cartFoods = new ArrayList<>();
        }
        if (cartFoods.size() != goodsNumber) {
            goodsNumber = cartFoods.size();
        }
        return cartFoods;
    }

    public void setCartFoods(List<PurchaseFoodBean> cartFoods) {
        SupplyShoppingCart.cartFoods = cartFoods;
    }
}
