package com.base.track.model.dto.response;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

@Data
@Api("余量计算返回实体")
public class VisualDTO {


    @ApiModelProperty("卫星发射EIRP")
    private double eirp;

    @ApiModelProperty("载波频率 根据使用频段，X频段固定为8200，L频段为1700")
    private List<Double> f;

    @ApiModelProperty("WX轨道高度")
    private double h;

    @ApiModelProperty("地面天线仰角")
    private List<Double> elevation;

    @ApiModelProperty("星地距离")
    private List<Double> d;

    @ApiModelProperty("自由空间损耗")
    private List<Double> lpath;

    @ApiModelProperty("电离层损耗 默认1.0dB")
    private double l1 = 1.0;

    @ApiModelProperty("极化误差损耗 默认0.5dB")
    private double l2 = 0.5;

    @ApiModelProperty("雨衰 默认0.5dB")
    private double l3 = 0.5;

    @ApiModelProperty("其他损耗 默认2.0dB")
    private double l4 = 2.0;

    @ApiModelProperty("地面站GT")
    private List<Double> GT;

    @ApiModelProperty("天线口径 12 或者 5.2 ")
    private List<Double> antenna;

    @ApiModelProperty("玻尔兹曼常数K")
    private double K = -198.6;

    @ApiModelProperty("C/NO")
    private List<Double> Cno;

    @ApiModelProperty("信息速率")
    private double fb;

    @ApiModelProperty("Eb/N0")
    private List<Double> EbNo;

    @ApiModelProperty(" 编码增益")
    private double Gcoding = 7.00;

    @ApiModelProperty("解调门限")
    private double SNR = 11.50;

    public static double Re = 6378;


    public void setD(List<Double> elevations) {
        List<Double> dList = new LinkedList<>();
        elevations.stream().forEach(elevation -> {
                    /*星地距离计算*/
                    double elevationrad = Math.toRadians(Double.valueOf(elevation));
                    double d = Math.sqrt(Math.pow(Re, 2) * Math.pow(Math.sin(elevationrad), 2) + 2 * h * Re + Math.pow(h, 2)) - Re * Math.sin(elevationrad);
                    dList.add(d);
                }
        );
        this.d = dList;
    }

    public void setLpath(List<Double> fList, List<Double> dList) {
        List<Double> lpathList = new LinkedList();
        for (int i = 0; i < fList.size(); i++) {
            Double lpath = 20 * Math.log10(Double.valueOf(dList.get(i)) * Math.pow(10, 3)) + 20 * Math.log10(Double.valueOf(fList.get(i)) * Math.pow(10, 6))
                    + 20 * Math.log10((4 * Math.PI) / (3 * Math.pow(10, 8)));
            lpathList.add(lpath);
        }
        this.lpath = lpathList;
    }

    public void setCno(double eirpVal, List<Double> gtList, List<Double> lpathList) {
        List<Double> cnoList = new LinkedList();
        for (int i = 0; i < gtList.size(); i++) {
            Double cno = eirpVal + gtList.get(i) - lpathList.get(i) - l1 - l2 - l3 - l4 - getK();
            cnoList.add(cno);
        }
        this.Cno = cnoList;
    }

    public void setEbNo(List<Double> Cno) {
        List<Double> ebNoList = new LinkedList();
        for (int i = 0; i < Cno.size(); i++) {
            double EbNo = Cno.get(i) - 10 * Math.log10(fb);
            ebNoList.add(EbNo);
        }
        this.EbNo = ebNoList;
    }
}
