package com.yeechart.dotMatrix.signage;

import java.util.*;

public class TypeCodeUtil {

    /************************************** 点阵图形成  **************************************/


    /**
     * 关机
     */
    public static final String CODE_OFF = "00";
    /**
     * 开机
     */
    public static final String CODE_ON = "01";
    /**
     * 左屏
     */
    public static final String CODE_LEFT = "00";
    /**
     * 右屏
     */
    public static final String CODE_RIGHT = "01";

    /**
     * 引导图
     */
    public static final String CODE_GUIDE = "00";
    /**
     * 业务图
     */
    public static final String CODE_BUSINESS = "01";
    /**
     * 自检图
     */
    public static final String CODE_SELF_TEST = "02";
    /**
     * 占位符 FF
     */
    public static final String CODE_FF = "FF";
    /**
     * 无状态 FE
     */
    public static final String CODE_FE = "FE";

    private static Map<Integer, Set<String>> typeCodeMap = new HashMap<>();

    /**
     * 将改变的下标 转换为对应的typeCode
     *
     * @param types
     * @return
     */
    public static Set<String> changTypeToTypeCode(List<Integer> types) {

        Set<String> typeCodeList = new HashSet<>();

        for (int type : types) {
            typeCodeList.addAll(typeToTypeCodeList(type));
        }

        return typeCodeList;
    }


    /**
     * 将改变的下标 转换为对应的typeCode列表
     *
     * @param type
     * @return
     */
    public static Set<String> typeToTypeCodeList(Integer type) {
        if (typeCodeMap.isEmpty()) {
            initTypeCodeMap();
        }

        return typeCodeMap.get(type);
    }

    public static void initTypeCodeMap() {

        int max = 1 + 36;//由 下标0 加上 Ter020201InfoVo中最大的type数
        // 现将原左屏图改为 状态6个+指针6个+图表三个 + 无状态和无指针


        for (int type = 0; type < max; type++) {
            Set<String> typeCodeList = new HashSet<>();
            //左右屏都需要更改的
            if (type == 20) {
                //左屏
//                for(int j = 0 ; j<6; j++){//6种状态
//                    typeCodeList.add(CODE_ON+CODE_LEFT+CODE_BUSINESS+"01"+"0"+j);//签到表
//                    typeCodeList.add(CODE_ON+CODE_LEFT+CODE_BUSINESS+"03"+"0"+j);//二合一表
//                }
                typeCodeList.add(CODE_ON + CODE_LEFT + CODE_BUSINESS + "01" + CODE_FF);//签到表
                typeCodeList.add(CODE_ON + CODE_LEFT + CODE_BUSINESS + "03" + CODE_FF);//二合一表

                //右屏
                typeCodeList.add(CODE_ON + CODE_RIGHT + CODE_BUSINESS + "00");
                typeCodeList.add(CODE_ON + CODE_RIGHT + CODE_BUSINESS + "01");

                typeCodeMap.put(type, typeCodeList);

                continue;
            }

            //左屏业务相关
            if (type == 0 || type == 29 || type == 30 ||
                    type == 19 || type == 36
            ) {//|| type == 4

                //状态历史数据
                //状态历史表
                if (type == 0 || type == 29 || type == 19) {

//                    for(int j = 0 ; j<6; j++){//6种状态
//                        typeCodeList.add(CODE_ON+CODE_LEFT+CODE_BUSINESS+"02"+"0"+j);//状态表
//                        typeCodeList.add(CODE_ON+CODE_LEFT+CODE_BUSINESS+"03"+"0"+j);//二合一表
//                    }
                    typeCodeList.add(CODE_ON + CODE_LEFT + CODE_BUSINESS + "02" + CODE_FF);//状态表
                    typeCodeList.add(CODE_ON + CODE_LEFT + CODE_BUSINESS + "03" + CODE_FF);//二合一表
                    typeCodeMap.put(type, typeCodeList);
                    if (type == 29) {
                        continue;
                    }

                }

                //签到历史数据 现为 工时历史数据
                if (type == 0 || type == 30) {

//                    for(int j = 0 ; j<6; j++){//6种状态
//                        typeCodeList.add(CODE_ON+CODE_LEFT+CODE_BUSINESS+"01"+"0"+j);//签到表
//                        typeCodeList.add(CODE_ON+CODE_LEFT+CODE_BUSINESS+"03"+"0"+j);//二合一表
//                    }
                    typeCodeList.add(CODE_ON + CODE_LEFT + CODE_BUSINESS + "01" + CODE_FF);//签到表
                    typeCodeList.add(CODE_ON + CODE_LEFT + CODE_BUSINESS + "03" + CODE_FF);//二合一表
                    typeCodeMap.put(type, typeCodeList);
                    if (type == 30) {
                        continue;
                    }

                }

                //状态
//                for(int i = 0 ; i < 4 ; i++){ //4种报表
//                    for(int j = 0 ; j<6; j++){//6种状态
//                        typeCodeList.add(CODE_ON+CODE_LEFT+CODE_BUSINESS+"0"+i+"0"+j);
//                    }
//                }

                for (int j = 0; j < 7; j++) {//6种状态 + 无状态


                    typeCodeList.add(CODE_ON + CODE_LEFT + CODE_BUSINESS + CODE_FF +
                            (j != 6 ? "0" + j : CODE_FE)
                    );
                    if (type != 36) {
                        //特殊处理图表0 指针款的状态
                        typeCodeList.add(CODE_ON + CODE_LEFT + CODE_BUSINESS + "00" +
                                (j != 6 ? "0" + j : CODE_FE)
                        );
                    }

                }

                if (type == 36) {
                    //关机左屏引导图
                    typeCodeList.add(CODE_OFF + CODE_LEFT + CODE_GUIDE);
                }
            }


            //右屏业务相关
            if (type == 0 || type == 1 || type == 2 //|| type == 5

                    || type == 9 || type == 10 || type == 11
                    || type == 12 || type == 13 || type == 14 || type == 15 || type == 16 || type == 17
                    || type == 18
                    || type == 23 || type == 24 || type == 25 || type == 26
                    || type == 21 || type == 22 || type == 31 || type == 32

            ) {//|| type == 5

                //只改了图表数据
                if (type == 32) {
                    typeCodeList.add(CODE_ON + CODE_RIGHT + CODE_BUSINESS + "00");//图表1
                    typeCodeMap.put(type, typeCodeList);
                    continue;
                }
                if (type == 31) {
                    typeCodeList.add(CODE_ON + CODE_RIGHT + CODE_BUSINESS + "01");//图表2
                    typeCodeMap.put(type, typeCodeList);
                    continue;
                }

                //引导图 已配网
                if (type == 0 || type == 1 || type == 2 || type == 9 || type == 10) {
                    typeCodeList.add(CODE_OFF + CODE_RIGHT + CODE_GUIDE + "01");

                }

                typeCodeList.add(CODE_ON + CODE_RIGHT + CODE_BUSINESS + "00");
                typeCodeList.add(CODE_ON + CODE_RIGHT + CODE_BUSINESS + "01");

            }


            //特殊处理
            if (type == 0) {
                //关机左屏引导图
                typeCodeList.add(CODE_OFF + CODE_LEFT + CODE_GUIDE);

                //关机右屏引导图未配网
                typeCodeList.add(CODE_OFF + CODE_RIGHT + CODE_GUIDE + "00");

            }

            typeCodeMap.put(type, typeCodeList);
        }

    }

}
