package com.gyee.runeconomy.config;


import com.gyee.runeconomy.dto.FiveLoss.AnnotationTool;
import com.gyee.runeconomy.dto.FiveLoss.FixedVo;
import com.gyee.runeconomy.dto.result.PowerPointData;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.stereotype.Component;

import java.io.File;

import java.util.List;
import java.util.stream.Collectors;

@Data
@Component
@ConfigurationProperties(prefix = "gyee")
public class GyeeConfig {

    public File jarF = null;

    {
        ApplicationHome h = new ApplicationHome(getClass());
        jarF = h.getSource();
    }

    /**
     * 数据适配器网址
     **/
    @Value("${db.url1}")
    private String AdapterfdUrl;
    @Value("${db.url1}")
    private String AdaptergfUrl;
    @Value("${db.url1}")
    private String TaosUrl;
    /**
     * 数据准备保存路径(原始数据)
     **/
    @Value("${powerCurveFitting.prepare}")
    private String filePathPrepare;
    /**
     * 数据处理保存路径(处理后的数据)
     **/
    @Value("${powerCurveFitting.process}")
    private String filePathProcess;
    /**
     * 数据拟合保存路径(拟合后的数据)
     **/
    @Value("${powerCurveFitting.fitting}")
    private String filePathFitting;
    /** 配置文件路径 **/
    @Value("${powerCurveFitting.file-path-power}")
    private String filePathPower;
    /**
     * 数据压缩下载
     **/
    private String filePathDownload;
    /**
     * 功率曲线拟合测点
     **/
    private String points;

    /**
     * 数据是否离线执行
     **/
    private boolean offLine;

//    public List<String> getPoints() {
//        if (null == points) {
//            return Collections.emptyList();
//        } else {
//            return Arrays.asList(points.split(","));
//        }
//    }

    public List<String> getPoints() {
        return getUniformCodes();
    }

    private List<String> getUniformCodes(){
        List<FixedVo> fxList = AnnotationTool.getFixedVoList(PowerPointData.class);
        List<String> codes = fxList.stream().filter(f -> !StringUtils.isEmpty(f.getUniformCode()))
                .map(d -> d.getUniformCode()).collect(Collectors.toList());

        return codes;
    }

    public String getFilePathPower() {
        return jarF.getParentFile().getAbsolutePath() + File.separator + filePathPower;
    }

    public void setFilePathPower(String filePathPower) {
        this.filePathPower = filePathPower;
    }

    public String getFilePathPrepare() {
        return jarF.getParentFile().getAbsolutePath() + File.separator +  filePathPrepare;
    }

    public void setFilePathPrepare(String filePathPrepare) {
        this.filePathPrepare = filePathPrepare;
    }

    public String getFilePathProcess() {
        return jarF.getParentFile().getAbsolutePath() + File.separator + filePathProcess;
    }

    public void setFilePathProcess(String filePathProcess) {
        this.filePathProcess = filePathProcess;
    }

    public String getFilePathFitting() {
        return jarF.getParentFile().getAbsolutePath() + File.separator + filePathFitting;
    }

    public void setFilePathFitting(String filePathFitting) {
        this.filePathFitting = filePathFitting;
    }

    public String getFilePathDownload() {
        return jarF.getParentFile().getAbsolutePath() + "\\" + filePathDownload;
    }

    public void setFilePathDownload(String filePathDownload) {
        this.filePathDownload = filePathDownload;
    }
}