package com.jiayue.ipp.idp.dto;

import cn.hutool.core.date.DateUtil;
import com.jiayue.ipp.common.data.entity.ForecastPowerShortTerm;
import com.jiayue.ipp.common.data.entity.ForecastPowerShortTermHis;
import com.jiayue.ipp.common.data.entity.ForecastPowerUltraShortTerm;
import com.jiayue.ipp.common.data.entity.ForecastPowerUltraShortTermHis;
import com.jiayue.ipp.idp.util.DateTypeConversionUtils;
import lombok.Data;
import org.apache.commons.lang.time.DateFormatUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: tl
 * @Date: 2023/7/11 10:27
 */
@Data
public class ForecastDataApiDto<T> {

    /**
     * 当前日期
     */
    private String date;

    /**
     * 场站编号
     */
    private String stationCode;

    /**
     * 预测厂家
     */
    private String manufacturer;

    /**
     * 提前预测点位
     */
    private String howLongAgo;

    /**
     * 预测数据
     */
    private List<ForecastData> forecastData;

    public void setForecastData(List<T> forecastDataList) {
        this.forecastData = new ArrayList<>();
        if (forecastDataList.size() > 0) {
            T t = forecastDataList.get(0);

            if (t instanceof ForecastPowerShortTerm) {
                List<ForecastPowerShortTerm> list = (List<ForecastPowerShortTerm>) forecastDataList;
                list.forEach(f -> {
                    ForecastData forecastData = new ForecastData();
                    forecastData.setPower(f.getFpValue().toString());
                    forecastData.setTime(DateUtil.format(f.getForecastTime(), "yyyy-MM-dd HH:mm"));
                    this.forecastData.add(forecastData);
                });
            }
            if (t instanceof ForecastPowerUltraShortTerm) {
                List<ForecastPowerUltraShortTerm> list = (List<ForecastPowerUltraShortTerm>) forecastDataList;
                list.forEach(f -> {
                    ForecastData forecastData = new ForecastData();
                    forecastData.setPower(f.getFpValue().toString());
                    forecastData.setTime(DateUtil.format(f.getForecastTime(), "yyyy-MM-dd HH:mm"));
                    this.forecastData.add(forecastData);
                });
            }
            if (t instanceof ForecastPowerShortTermHis) {
                List<ForecastPowerShortTermHis> list = (List<ForecastPowerShortTermHis>) forecastDataList;
                list.forEach(f -> {
                    ForecastData forecastData = new ForecastData();
                    forecastData.setPower(f.getAbleValue().toString());
                    forecastData.setTime(DateUtil.format(f.getForecastTime(), "yyyy-MM-dd HH:mm"));
                    this.forecastData.add(forecastData);
                });
            }
            if (t instanceof ForecastPowerUltraShortTermHis) {
                List<ForecastPowerUltraShortTermHis> list = (List<ForecastPowerUltraShortTermHis>) forecastDataList;
                list.forEach(f -> {
                    ForecastData forecastData = new ForecastData();
                    forecastData.setPower(f.getAbleValue().toString());
                    forecastData.setTime(DateUtil.format(f.getForecastTime(), "yyyy-MM-dd HH:mm"));
                    this.forecastData.add(forecastData);
                });
            }

            if (t instanceof ForecastData) {
                List<ForecastPowerUltraShortTermHis> list = (List<ForecastPowerUltraShortTermHis>) forecastDataList;
                this.forecastData = (List<ForecastData>) forecastDataList;
            }

        }


    }
}
