package org.well.well.util;

import net.sf.json.JSONObject;
import org.well.well.base.AbstractResponse;
import org.well.well.base.DeviceTypeEnum;
import org.well.well.resp.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 设备响应消息解析
 * Created by lenovo on 2018/1/8.
 */

public class ResponseResolver {

    private static Map<String, AbstractResponse> abstractResponseHashMap = new HashMap<String, AbstractResponse>();

    static {
        abstractResponseHashMap.put(DeviceTypeEnum.Liquid.name(), new LiquidResponse());
        abstractResponseHashMap.put(DeviceTypeEnum.Well.name(), new WellResponse());
        abstractResponseHashMap.put(DeviceTypeEnum.Concentrator.name(), new ConcentratorResponse());
        abstractResponseHashMap.put(DeviceTypeEnum.Methane.name(), new MethaneResponse());
//        abstractResponseHashMap.put(DeviceTypeEnum.WasteGas.name(), new WasteGasResponse());
//        abstractResponseHashMap.put(DeviceTypeEnum.TempHumi.name(), new TempHumiResponse());
//        abstractResponseHashMap.put(DeviceTypeEnum.Dig.name(), new NoiseDigResponse());
        abstractResponseHashMap.put(DeviceTypeEnum.NoiseDig.name(), new NoiseDigResponse());
//        abstractResponseHashMap.put(DeviceTypeEnum.Locator.name(), new LocatorResponse());
        abstractResponseHashMap.put(DeviceTypeEnum.LG.name(), new LGResponse());
    }


    //event的具体处理
    public static AbstractResponse makeResponse(String content) {
        JSONObject json = JSONObject.fromObject(content);
        if (null == json) return null;
        AbstractResponse response = abstractResponseHashMap.get(json.get("devType").toString());
        return response;
    }

}
