package in.techware.carrefour.util.menuUtils;

import android.util.Log;

import java.util.ArrayList;

import in.techware.carrefour.R;
import in.techware.carrefour.app.App;
import in.techware.carrefour.model.MenuBean;
import in.techware.carrefour.model.MenuListBean;

/**
 * Created by Jemsheer K D on 23 June, 2018.
 * Package in.techware.carrefour.util.menuUtils
 * Project Carrefour
 */
public class HomeMenuUtil {


    public static final String CODE_IT = "1";
    public static final String CODE_RECEIVE = "2";
    public static final String CODE_ELIE = "3";
    public static final String CODE_ORDERS = "4";
    public static final String CODE_INFO = "5";
    public static final String CODE_MERCHAND = "6";
    public static final String CODE_FOOD_BANK = "7";
    public static final String CODE_EXIT = "0";
    private static final String TAG = "HomeMenuUtil";


    public static MenuListBean getAllMenu() {
        MenuListBean menuListBean = new MenuListBean();
        ArrayList<MenuBean> menuList = new ArrayList<>();
        String[] stringList = App.getInstance().getResources().getStringArray(R.array.menu_home);

        for (String str : stringList) {
            MenuBean menuBean = new MenuBean();
            menuBean.setCode(getCode(str));
            menuBean.setTitle(str);
            menuBean.setId(getID(menuBean.getCode()));
            menuList.add(menuBean);
        }
        menuListBean.setMenus(menuList);
        return menuListBean;

    }

    private static String getCode(String menu) {
        int index = !menu.contains("-") ? menu.indexOf("-") : menu.indexOf("-");
        Log.i(TAG, "getCode: INDEX : "+index);
        return index == -1 ? menu : menu.substring(0, index);
    }

    private static String getID(String code) {
        switch (code) {
            case "0":
                return "0";
            case "1":
                return "1";
            case "2":
                return "2";
            case "3":
                return "4";
            case "4":
                return "8";
            case "5":
                return "16";
            case "6":
                return "32";
            case "7":
                return "64";
            default:
                return "0";
        }
    }

    private static String[] getMenuIDList(String type) {

        switch (type) {
            case "1":
                return new String[]{"1", "0"};
            case "2":
                return new String[]{"2", "0"};
            case "3":
                return new String[]{"1", "2", "0"};
            case "4":
                return new String[]{"4", "0"};
            case "5":
                return new String[]{"1", "4", "0"};
            case "6":
                return new String[]{"2", "4", "0"};
            case "7":
                return new String[]{"1", "2", "4", "0"};
            case "8":
                return new String[]{"8", "0"};
            case "9":
                return new String[]{"1", "8", "0"};
            case "10":
                return new String[]{"2", "8", "0"};
            case "11":
                return new String[]{"1", "2", "8", "0"};
            case "12":
                return new String[]{"4", "8", "0"};
            case "13":
                return new String[]{"1", "4", "8", "0"};
            case "14":
                return new String[]{"2", "4", "8", "0"};
            case "15":
                return new String[]{"1", "2", "4", "8", "0"};
            case "16":
                return new String[]{"16", "0"};
            case "17":
                return new String[]{"1", "16", "0"};
            case "18":
                return new String[]{"2", "16", "0"};
            case "19":
                return new String[]{"1", "2", "16", "0"};
            case "20":
                return new String[]{"4", "16", "0"};
            case "21":
                return new String[]{"1", "4", "16", "0"};
            case "22":
                return new String[]{"2", "4", "16", "0"};
            case "23":
                return new String[]{"1", "2", "4", "16", "0"};
            case "24":
                return new String[]{"8", "16", "0"};
            case "25":
                return new String[]{"1", "8", "16", "0"};
            case "26":
                return new String[]{"2", "8", "16", "0"};
            case "27":
                return new String[]{"1", "2", "8", "16", "0"};
            case "28":
                return new String[]{"4", "8", "16", "0"};
            case "29":
                return new String[]{"1", "4", "8", "16", "0"};
            case "30":
                return new String[]{"2", "4", "8", "16", "0"};
            case "31":
                return new String[]{"1", "2", "4", "8", "16", "0"};
            case "32":
                return new String[]{"32", "0"};
            case "33":
                return new String[]{"1", "32", "0"};
            case "34":
                return new String[]{"2", "32", "0"};
            case "35":
                return new String[]{"1", "2", "32", "0"};
            case "36":
                return new String[]{"4", "32", "0"};
            case "37":
                return new String[]{"1", "4", "32", "0"};
            case "38":
                return new String[]{"2", "4", "32", "0"};
            case "39":
                return new String[]{"1", "2", "4", "32", "0"};
            case "40":
                return new String[]{"8", "32", "0"};
            case "41":
                return new String[]{"1", "8", "32", "0"};
            case "42":
                return new String[]{"2", "8", "32", "0"};
            case "43":
                return new String[]{"1", "2", "8", "32", "0"};
            case "44":
                return new String[]{"4", "8", "32", "0"};
            case "45":
                return new String[]{"1", "4", "8", "32", "0"};
            case "46":
                return new String[]{"2", "4", "8", "32", "0"};
            case "47":
                return new String[]{"1", "2", "4", "8", "32", "0"};
            case "48":
                return new String[]{"16", "32", "0"};
            case "49":
                return new String[]{"1", "16", "32", "0"};
            case "50":
                return new String[]{"2", "16", "32", "0"};
            case "51":
                return new String[]{"1", "2", "16", "32", "0"};
            case "52":
                return new String[]{"4", "16", "32", "0"};
            case "53":
                return new String[]{"1", "4", "16", "32", "0"};
            case "54":
                return new String[]{"2", "4", "16", "32", "0"};
            case "55":
                return new String[]{"1", "2", "4", "16", "32", "0"};
            case "56":
                return new String[]{"8", "16", "32", "0"};
            case "57":
                return new String[]{"1", "8", "16", "32", "0"};
            case "58":
                return new String[]{"2", "8", "16", "32", "0"};
            case "59":
                return new String[]{"1", "2", "8", "16", "32", "0"};
            case "60":
                return new String[]{"4", "8", "16", "32", "0"};
            case "61":
                return new String[]{"1", "4", "8", "16", "32", "0"};
            case "62":
                return new String[]{"2", "4", "8", "16", "32", "0"};
            case "63":
                return new String[]{"1", "2", "4", "8", "16", "32", "0"};
            case "64":
                return new String[]{"64", "0"};
            case "65":
                return new String[]{"1", "64", "0"};
            case "66":
                return new String[]{"2", "64", "0"};
            case "67":
                return new String[]{"1", "2", "64", "0"};
            case "68":
                return new String[]{"4", "64", "0"};
            case "69":
                return new String[]{"1", "4", "64", "0"};
            case "70":
                return new String[]{"2", "4", "64", "0"};
            case "71":
                return new String[]{"1", "2", "4", "64", "0"};
            case "72":
                return new String[]{"8", "64", "0"};
            case "73":
                return new String[]{"1", "8", "64", "0"};
            case "74":
                return new String[]{"2", "8", "64", "0"};
            case "75":
                return new String[]{"1", "2", "8", "64", "0"};
            case "76":
                return new String[]{"4", "8", "64", "0"};
            case "77":
                return new String[]{"1", "4", "8", "64", "0"};
            case "78":
                return new String[]{"2", "4", "8", "64", "0"};
            case "79":
                return new String[]{"1", "2", "4", "8", "64", "0"};
            case "80":
                return new String[]{"16", "64", "0"};
            case "81":
                return new String[]{"1", "16", "64", "0"};
            case "82":
                return new String[]{"2", "16", "64", "0"};
            case "83":
                return new String[]{"1", "2", "16", "64", "0"};
            case "84":
                return new String[]{"4", "16", "64", "0"};
            case "85":
                return new String[]{"1", "4", "16", "64", "0"};
            case "86":
                return new String[]{"2", "4", "16", "64", "0"};
            case "87":
                return new String[]{"1", "2", "4", "16", "64", "0"};
            case "88":
                return new String[]{"8", "16", "64", "0"};
            case "89":
                return new String[]{"1", "8", "16", "64", "0"};
            case "90":
                return new String[]{"2", "8", "16", "64", "0"};
            case "91":
                return new String[]{"1", "2", "8", "16", "64", "0"};
            case "92":
                return new String[]{"4", "8", "16", "64", "0"};
            case "93":
                return new String[]{"1", "4", "8", "16", "64", "0"};
            case "94":
                return new String[]{"2", "4", "8", "16", "64", "0"};
            case "95":
                return new String[]{"1", "2", "4", "8", "16", "64", "0"};
            case "96":
                return new String[]{"32", "64", "0"};
            case "97":
                return new String[]{"1", "32", "64", "0"};
            case "98":
                return new String[]{"2", "32", "64", "0"};
            case "99":
                return new String[]{"1", "2", "32", "64", "0"};
            case "100":
                return new String[]{"4", "32", "64", "0"};
            case "101":
                return new String[]{"1", "4", "32", "64", "0"};
            case "102":
                return new String[]{"2", "4", "32", "64", "0"};
            case "103":
                return new String[]{"1", "2", "4", "32", "64", "0"};
            case "104":
                return new String[]{"8", "32", "64", "0"};
            case "105":
                return new String[]{"1", "8", "32", "64", "0"};
            case "106":
                return new String[]{"2", "8", "32", "64", "0"};
            case "107":
                return new String[]{"1", "2", "8", "32", "64", "0"};
            case "108":
                return new String[]{"4", "8", "32", "64", "0"};
            case "109":
                return new String[]{"1", "4", "8", "32", "64", "0"};
            case "110":
                return new String[]{"2", "4", "8", "32", "64", "0"};
            case "111":
                return new String[]{"1", "2", "4", "8", "32", "64", "0"};
            case "112":
                return new String[]{"16", "32", "64", "0"};
            case "113":
                return new String[]{"1", "16", "32", "64", "0"};
            case "114":
                return new String[]{"2", "16", "32", "64", "0"};
            case "115":
                return new String[]{"1", "2", "16", "32", "64", "0"};
            case "116":
                return new String[]{"4", "16", "32", "64", "0"};
            case "117":
                return new String[]{"1", "4", "16", "32", "64", "0"};
            case "118":
                return new String[]{"2", "4", "16", "32", "64", "0"};
            case "119":
                return new String[]{"1", "2", "4", "16", "32", "64", "0"};
            case "120":
                return new String[]{"8", "16", "32", "64", "0"};
            case "121":
                return new String[]{"1", "8", "16", "32", "64", "0"};
            case "122":
                return new String[]{"2", "8", "16", "32", "64", "0"};
            case "123":
                return new String[]{"1", "2", "8", "16", "32", "64", "0"};
            case "124":
                return new String[]{"4", "8", "16", "32", "64", "0"};
            case "125":
                return new String[]{"1", "4", "8", "16", "32", "64", "0"};
            case "126":
                return new String[]{"2", "4", "8", "16", "32", "64", "0"};
            case "127":
                return new String[]{"1", "2", "4", "8", "16", "32", "64", "0"};

            default:
                return new String[]{};
        }
    }

    public static MenuListBean getMenuList(String type) {

        MenuListBean allMenuList = getAllMenu();
        String[] idList = getMenuIDList(type);
        ArrayList<MenuBean> list = new ArrayList<>();
        for (String id : idList) {
            MenuBean bean = allMenuList.getMenuFromID(id);
            if (bean != null)
                list.add(bean);
        }
        MenuListBean menuListBean = new MenuListBean();
        menuListBean.setMenus(list);
        return allMenuList;
    }
}
