package com.base.track.controller;


import com.base.api.client.SatelliteRpcService;
import com.base.api.client.StationRpcService;
import com.base.orbit.web.Result;
import com.base.task.cdlatch.aop.model.InstanceAop;
import com.base.task.cdlatch.aop.model.SubPointAop;
import com.base.track.model.dto.request.AstronomyRequestDTO;
import com.base.track.service.CalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Api(tags = "基础数据模块", description = "轨道计算基础数据模块接口")
@RestController

@RequestMapping("/api/calc")
public class CalcController {

    @Resource
    private CalService calcService;
    @Resource
    SatelliteRpcService infoBasisSatelliteRpcService;
    @Resource
    StationRpcService stationRpcService;


    @ApiOperation(value = "计算指定时间星历数据")
    @PostMapping(value = "/calcEph")
    public Result<String> calcEph(@RequestBody SubPointAop subPointAop) {
        calcService.calcEph(subPointAop);
        return Result.success("星历计算成功加入列队");
    }

    @ApiOperation(value = "计算指定时间星下点数据")
    @PostMapping(value = "/calcSubPoint")
    public Result<String> calcSubPoint(@RequestBody SubPointAop subPointAop) {
        calcService.calcSubPoint(subPointAop);
        return Result.success("星下点计算成功加入列队");
    }
    @ApiOperation(value = "推算瞬根")
    @PostMapping(value = "/calcInstance")
    public Result<String> calcInstance(@RequestBody InstanceAop instanceAop) {
        calcService.calcInstance(instanceAop);
        return Result.success("瞬根推算成功加入列队");
    }
    @ApiOperation(value = "计算指定时间地面站数据")
    @PostMapping(value = "/calcStation")
    public Result<String> calcStation(@RequestBody SubPointAop subPointAop) {

        List<String> stationIds = subPointAop.getStationIds();
        for (String stationId:stationIds) {
            List<String> station = new ArrayList<>();
            station.add(stationId);
            BeanUtils.copyProperties(subPointAop,SubPointAop.class);
            subPointAop.setStationIds(station);
            calcService.calcTrbut(subPointAop);
        }
        return Result.success("地面站计算成功加入列队");
    }
    @ApiOperation(value = "计算天文事件")
    @PostMapping(value = "/calcAstronomy")
    public Result<String> calcAstronomy(@RequestBody AstronomyRequestDTO astronomyRequest) {
        calcService.calcAstronomy(astronomyRequest.getSatelliteIds(), astronomyRequest.getStationIds(), astronomyRequest.getStartTime(), astronomyRequest.getEndTime());
        return Result.success("计算天文事件成功");
    }
}
