package com.base.plan.utils;


import com.base.api.client.PointRpcService;
import com.base.api.client.SatelliteRpcService;
import com.base.api.model.PointRpcDTO;
import com.base.api.model.PointTypeEnums;
import com.base.api.model.SatelliteRpcDTO;
import com.base.api.model.request.PointListRpcReqDTO;
import com.base.plan.constant.Constants;
import com.base.plan.model.dto.request.StripDTOListAddDTO;
import com.base.plan.model.input.SarInput;
import com.base.task.model.Task;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;


@Component
public class ReadTxtFileTool {


    @Resource
    SatelliteRpcService satelliteService;

    /**
     * 读取input文件构建Input对象
     *
     * @return
     */
    public SarInput getSarInputByFile(StripDTOListAddDTO req, Task task,List<PointRpcDTO> list1) {
        try {

            String TargetLon="";
            String TargetLat="";
            for (PointRpcDTO pointRpcDTO:list1){
                TargetLon=TargetLon+pointRpcDTO.getLongitude()+" ";
                TargetLat=TargetLat+pointRpcDTO.getLatitude()+" ";
            }
            List<String> satelliteCodes=new ArrayList<>();
            satelliteCodes.add(req.getSatelliteCode());
            List<SatelliteRpcDTO> satelliteRpcDTOList = satelliteService.listByIds(satelliteCodes);
            SarInput sarInput = new SarInput();
            sarInput.setSwathWidth1(req.getSwathWidth());
            sarInput.setSwathWidth2(req.getSwathWidth());
            sarInput.setAreaNum("4");
            sarInput.setMinRollAngle(satelliteRpcDTOList.get(0).getMinRollAngle());
            sarInput.setMaxRollAngle(satelliteRpcDTOList.get(0).getMaxRollAngle());
            sarInput.setTargetLon(TargetLon);
            sarInput.setTargetLat(TargetLat);
            sarInput.setFilePath(task.getResultDataSavePath());
            sarInput.setStripFileName("3021");
            sarInput.setPointFileName("3022");
            return sarInput;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


}
