package com.sw.mes.sap.dto.jip;

import com.sw.mes.core.utils.DateUtil;

import java.util.*;

public class JipResultGenerator {
    private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";


    /**
     * 成功 返回自定义状态码与提示语
     *
     * <pre>
     * 示例
     * @param category MT_WORK_ORDER_RETURN
     * @param type WORK_ORDER_RETURN
     * {
     *     "MT_WORK_ORDER_RETURN": {
     *         "WORK_ORDER_RETURN": [
     *             {
     *                 "RESULT_FILENAME": null,
     *                 "RESULT_TABLE": null,
     *                 "RESULT_MSG": "Mfg Order \"56002369\" updated on 11/25/2023 5:59:03 PM",
     *                 "RESULT_CODE": "1"
     *             }
     *         ]
     *     }
     * }
     * </pre>
     * @return
     */
    public static Map<String,Object> generatorProductionOrderResult(String category,String type,List<JipProductionOrderResult> results) {
        Map<String,Object> result = new HashMap<>();
        Map<String,Object> categoryObj = new HashMap<>();
        Map<String,Object> typeObj = new HashMap<>();
        typeObj.put(type,results);
        categoryObj.put(category,typeObj);
        result.put(category,categoryObj);
        return result;
    }


    /**
     * <pre>
     * {
     *     "ET_RETURN": {
     *         "code": 1,
     *         "message": "工单【30801032】不存在在制工序，能关单！"
     *     },
     *     "ES_BC_INFO": {
     *         "IFID": "ECP-GJMES-GETMOSTA00",
     *         "UUID": "E059A7F1-25D6-4362-80CD-EB13AD2F4321",
     *         "MSGID": "ECP00063578950",
     *         "RESEND_ID": "001",
     *         "BUSTYP": "查询",
     *         "IFNAME": "获取MES工单状态",
     *         "SEND_DT": "20231219163932",
     *         "SENDER": "晶硅MES",
     *         "RECEIVER": "ECP",
     *         "TYPE": "S",
     *         "MSG": "工单【30801032】不存在在制工序，能关单！"
     *     }
     * }
     * </pre>
     */
    public static Map<String,Object> generatorOrderStateResult(JipOrderStateResult retrunInfo,JipISBCINFO header) {
        Map<String,Object> result = new HashMap<>();
        result.put("ET_RETURN",retrunInfo);

        JipECBCINFO rHreader = new JipECBCINFO();
        rHreader.setIFID(header.getIFID());
        rHreader.setMSGID(header.getMSGID());
        rHreader.setRESEND_ID(header.getRESEND_ID());
        rHreader.setBUSTYP(header.getBUSTYP());
        rHreader.setIFNAME(header.getIFNAME());
        rHreader.setSENDER(header.getSENDER());
        rHreader.setRECEIVER(header.getRECEIVER());
        rHreader.setUUID(UUID.randomUUID().toString().replace("-", ""));
        rHreader.setSEND_DT(DateUtil.formatDate(new Date(),DateUtil.longFormats));
        rHreader.setTYPE(retrunInfo.getCode()==1?"S":"E");
        rHreader.setMSG(retrunInfo.getMessage());
        result.put("ES_BC_INFO",rHreader);

        return result;
    }
    
    
    
    /**
     * <pre>
     * {
     *     "ET_DATA": {
     *         "WERKS": "5041",
	            "AUFNR": "71000613",
	            "STATUS": true,
	            "MSG": "71000613工单可关单",
	            "INMAKE": 821.310,
	            "REPNUM": 12101.000,
	            "NOREPNUM": 172.100,
	            "TCRATIO": 99.99
     *     },
     *     "ES_BC_INFO": {
     *         "IFID": "ECP-GJMES-GETMOSTA00",
     *         "UUID": "E059A7F1-25D6-4362-80CD-EB13AD2F4321",
     *         "MSGID": "ECP00063578950",
     *         "RESEND_ID": "001",
     *         "BUSTYP": "查询",
     *         "IFNAME": "获取MES工单状态",
     *         "SEND_DT": "20231219163932",
     *         "SENDER": "晶硅MES",
     *         "RECEIVER": "ECP",
     *         "TYPE": "S",
     *         "MSG": "工单【30801032】不存在在制工序，能关单！"
     *     }
     * }
     * </pre>
     */
    public static Map<String,Object> generatorVerifyWorkOrderStateResult(JipCloseOrderVerifyResult retrunInfo,JipISBCINFO header) {
        Map<String,Object> result = new HashMap<>();
        result.put("ET_DATA",retrunInfo);

        JipECBCINFO rHreader = new JipECBCINFO();
        rHreader.setIFID(header.getIFID());
        rHreader.setMSGID(header.getMSGID());
        rHreader.setRESEND_ID(header.getRESEND_ID());
        rHreader.setBUSTYP(header.getBUSTYP());
        rHreader.setIFNAME(header.getIFNAME());
        rHreader.setSENDER(header.getSENDER());
        rHreader.setRECEIVER(header.getRECEIVER());
        rHreader.setUUID(UUID.randomUUID().toString().replace("-", ""));
        rHreader.setSEND_DT(DateUtil.formatDate(new Date(),DateUtil.longFormats));
        rHreader.setTYPE(retrunInfo.getStatus()?"S":"E");
        rHreader.setMSG(retrunInfo.getMsg());
        result.put("ES_BC_INFO",rHreader);

        return result;
    }




}
