package in.techware.carrefour.util.menuUtils;

import android.text.TextUtils;

import java.util.ArrayList;
import java.util.Arrays;

import in.techware.carrefour.R;
import in.techware.carrefour.config.Config;
import in.techware.carrefour.model.AppSettingsBean;
import in.techware.carrefour.model.MenuBean;
import in.techware.carrefour.model.MenuListBean;
import in.techware.carrefour.util.AppConstants;

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

    public static final String CODE_WASTE = "1";
    public static final String CODE_LABEL_SURVEY = "2";
    public static final String CODE_STOCK_TAKE = "3";
    public static final String CODE_PRINT_LABELS = "4";
    public static final String CODE_MIN_STOCK = "5";
    public static final String CODE_FACING = "6";
    public static final String CODE_PROMOTION = "7";
    public static final String CODE_OUT_OF_STOCK = "8";
    public static final String CODE_TRANSFORM_QUANTITY = "9";
    public static final String CODE_ITEM_LIST = "10";
    public static final String CODE_INTERNAL_SALES = "11";
    public static final String CODE_INTERNAL_SALES_CORRECT = "12";
    public static final String CODE_RESTORE = "13";
    public static final String CODE_EXIT = "14";


    public static MenuListBean getAllMenu() {
        MenuListBean menuListBean = BaseMenuUtil.getAllMenu(R.array.menu_it);
        AppSettingsBean appSettingsBean = Config.getInstance().getAppSettingsBean();
        String str = appSettingsBean.getItFunctions().replace(" ", "");
        String[] stringList = TextUtils.split(str, ",");
        ArrayList<String> list = new ArrayList<>(Arrays.asList(stringList));
        try {
            menuListBean.getMenus().remove(menuListBean.getMenuFromID(CODE_RESTORE));
            for (int i = 0; i < menuListBean.getMenus().size() - 1; i++) {
                if (!list.contains(menuListBean.getMenus().get(i).getCode())) {
                    menuListBean.getMenus().remove(i);
                    i--;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return menuListBean;
    }

    public static String getFileName(MenuBean menuBean, int labelType) {
        switch (menuBean.getCode()) {
            case ITRestoreMenuUtil.CODE_WASTE:
                return Config.getInstance().getAppSettingsBean().getWasteFilePrefix();
            case ITRestoreMenuUtil.CODE_LABEL_SURVEY:
                return Config.getInstance().getAppSettingsBean().getLabelSurveyFilePrefix();
            case ITRestoreMenuUtil.CODE_STOCK_TAKE:
                return Config.getInstance().getAppSettingsBean().getStockTakeFilePrefix();
            case ITRestoreMenuUtil.CODE_PRINT_LABELS:
                if (labelType == AppConstants.LABEL_TYPE_SHELF_LABEL) {
                    return Config.getInstance().getAppSettingsBean().getShelfLabelFilePrefix();
                } else if (labelType == AppConstants.LABEL_TYPE_IT_LABEL) {
                    return Config.getInstance().getAppSettingsBean().getItLabelFilePrefix();
                } else {
                    return Config.getInstance().getAppSettingsBean().getInventoryLabelFilePrefix();
                }
            case ITRestoreMenuUtil.CODE_MIN_STOCK:
                return Config.getInstance().getAppSettingsBean().getMinimumStockFilePrefix();
            case ITRestoreMenuUtil.CODE_FACING:
                return Config.getInstance().getAppSettingsBean().getFacingFilePrefix();
            case ITRestoreMenuUtil.CODE_PROMOTION:
                return Config.getInstance().getAppSettingsBean().getPromotionFilePrefix();
            case ITRestoreMenuUtil.CODE_OUT_OF_STOCK:
                return Config.getInstance().getAppSettingsBean().getOutOfStockFilePrefix();
            case ITRestoreMenuUtil.CODE_TRANSFORM_QUANTITY:
                return Config.getInstance().getAppSettingsBean().getTransformationQTYPrefix();
            case ITRestoreMenuUtil.CODE_ITEM_LIST:
                return Config.getInstance().getAppSettingsBean().getItemListFilePrefix();
            case ITRestoreMenuUtil.CODE_INTERNAL_SALES:
                return Config.getInstance().getAppSettingsBean().getTransferFilePrefix();
            case ITRestoreMenuUtil.CODE_INTERNAL_SALES_CORRECT:
                return Config.getInstance().getAppSettingsBean().getTransferCorrectionFilePrefix();
            case ITRestoreMenuUtil.CODE_EXIT:
            case ITRestoreMenuUtil.CODE_RESTORE:
            default:
                return "";
        }
    }

}
