package com.jiayue.ipfcst.dataexchange.dataprocesser.datagainerhandler;

import com.jiayue.ipfcst.common.data.entity.ProtocolDataType;
import com.jiayue.ipfcst.common.data.entity.ProtocolSenderDataPoint;
import com.jiayue.ipfcst.dataexchange.dataprocesser.datagainerhandler.iml.ForecastDataGainer;
import com.jiayue.ipfcst.dataexchange.dataprocesser.datagainerhandler.iml.GetDataFromContainer;
import com.jiayue.ipfcst.dataexchange.dataprocesser.datagainerhandler.iml.PointDataCalculator;
import com.jiayue.ipfcst.dataexchange.dataprocesser.datagainerhandler.iml.WindTowerOrWeatherStationDataGainer;

/**
 * 数据生成器的构建类
 *
 * @author: xiuwei
 * @version: 3.0
 */
public class DataGainerBuilder {

  /**
   * 通过点位的数据来源生成不同的DataGainer
   * 就是一个派发功能
   *
   * @param protocolSenderDataPoint 转发点位
   * @return SenderDataGainer 转发点位的数据构造器
   */
  public static BaseDataGainer build(ProtocolSenderDataPoint protocolSenderDataPoint) {
    switch (protocolSenderDataPoint.getDataSource()) {
      case GATHER: {
        if (ProtocolDataType.A.equals(protocolSenderDataPoint.getProtocolPointType())) {
          return new GetDataFromContainer<Boolean>(NumOrBool.BOOL, protocolSenderDataPoint.getGatherPoint(), protocolSenderDataPoint.getMagnification());
        } else {
          GetDataFromContainer getDataFromContainer;
          try {
            getDataFromContainer=new WindTowerOrWeatherStationDataGainer(NumOrBool.NUM, protocolSenderDataPoint.getGatherPoint(), protocolSenderDataPoint.getMagnification());
          }catch (RuntimeException e){
            getDataFromContainer= new GetDataFromContainer<Boolean>(NumOrBool.NUM, protocolSenderDataPoint.getGatherPoint(), protocolSenderDataPoint.getMagnification());
          }
          return getDataFromContainer;
        }
      }
      case GENERATE: {
        if (ProtocolDataType.A.equals(protocolSenderDataPoint.getProtocolPointType())) {
          return new PointDataCalculator<Boolean>(NumOrBool.BOOL, protocolSenderDataPoint.getGenerationRegulation(), protocolSenderDataPoint.getMagnification());
        } else {
          return new PointDataCalculator<Number>(NumOrBool.NUM, protocolSenderDataPoint.getGenerationRegulation(), protocolSenderDataPoint.getMagnification());
        }
      }
      case FORECAST: {
        return new ForecastDataGainer(protocolSenderDataPoint.getForecastForSendAttribute(), protocolSenderDataPoint.getMagnification());
      }
      default:
        return null;
    }
  }
}
