package com.gingersoft.gsa.cloud.base.utils;

import android.content.Context;
import android.text.TextUtils;

import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.ui.bean.mode.LoginBean;

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

/**
 * 作者：ELEGANT_BIN
 * 版本：1.6.0
 * 创建日期：2020-03-12
 * 修订历史：2020-03-12
 * 描述：
 */
public class RestaurantInfoUtils {

    public static List<LoginBean.DataBean.UserBean.BrandsBean> getBrandList(Context context) {
        String brandRestaurantInfos = GsaCloudApplication.getBrandRestaurantInfos(context);
        if (!TextUtils.isEmpty(brandRestaurantInfos)) {
            List<LoginBean.DataBean.UserBean.BrandsBean> brandsBeans = JsonUtils.parseArray(brandRestaurantInfos, LoginBean.DataBean.UserBean.BrandsBean.class);
            return brandsBeans;
        }
        return new ArrayList<>();
    }

    public static int getRestaurantSize(Context context) {
        int size = 0;
        List<LoginBean.DataBean.UserBean.BrandsBean> brandsBeans = getBrandList(context);
        for (int i = 0; i < getBrandList(context).size(); i++) {
            if (brandsBeans.get(i).getRestaurants() != null)
                size += brandsBeans.get(i).getRestaurants().size();
        }
        return size;
    }

    public static LoginBean.DataBean.UserBean.BrandsBean getOnlyBrand(List<LoginBean.DataBean.UserBean.BrandsBean> brands) {
        for (int i = 0; i < brands.size(); i++) {
            if (brands.get(i).getRestaurants() != null) {
                for (int j = 0; j < brands.get(i).getRestaurants().size(); j++) {
                    return brands.get(i);
                }
            }
        }
        return null;
    }

    public static LoginBean.DataBean.UserBean.BrandsBean.RestaurantsBean getOnlyRestaurant(List<LoginBean.DataBean.UserBean.BrandsBean> brands) {
        for (int i = 0; i < brands.size(); i++) {
            if (brands.get(i).getRestaurants() != null) {
                for (int j = 0; j < brands.get(i).getRestaurants().size(); j++) {
                    return brands.get(i).getRestaurants().get(j);
                }
            }
        }
        return null;
    }

    public static LoginBean.DataBean.UserBean.BrandsBean getBrandByRestaurantId(List<LoginBean.DataBean.UserBean.BrandsBean> brands, int restaurantId) {
        for (int i = 0; i < brands.size(); i++) {
            if (brands.get(i).getRestaurants() != null) {
                for (int j = 0; j < brands.get(i).getRestaurants().size(); j++) {
                    if (brands.get(i).getRestaurants().get(j).getRestaurantId() == restaurantId) {
                        return brands.get(i);
                    }
                }
            }
        }
        return null;
    }
}
