package com.dji.sample.map.controller;

import com.dji.sample.map.model.dto.FlightTaskDTO;
import com.dji.sample.map.model.dto.FlightTrackDTO;
import com.dji.sample.map.model.param.FlightTaskQueryParam;
import com.dji.sample.map.service.IFlightTrackTaskService;
import com.dji.sdk.common.HttpResultResponse;
import com.dji.sdk.common.PaginationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author sean
 * @version 1.9
 * @date 2024/7/23
 */

@RestController
@RequestMapping("${url.map.prefix}${url.map.version}/workspaces")
public class FlightTaskController {

    @Autowired
    private IFlightTrackTaskService flightTaskService;
    /**
     * 获取工作空间下的所有飞行任务（轨迹）信息
     * @param workspaceId
     * @return
     */
    @GetMapping("/{workspace_id}/flight-tasks")
    public HttpResultResponse<PaginationData<FlightTaskDTO>> getFlightTaskList(FlightTaskQueryParam flightTaskQueryParam,
                                                                        @RequestParam(defaultValue = "1") Long page,
                                                                        @RequestParam(name = "page_size", defaultValue = "10") Long pageSize,
                                                                        @PathVariable(name = "workspace_id") String workspaceId
    ) {
        PaginationData<FlightTaskDTO> taskList = flightTaskService.getFlightTasksPaginationByWorkspaceId(workspaceId, flightTaskQueryParam,page, pageSize);

        return HttpResultResponse.success(taskList);
    }

    /**
     * 获取飞行任务轨迹信息
     * @param workspaceId
     * @return
     */
    @GetMapping("/{workspace_id}/flight-task/{task_id}")
    public HttpResultResponse<List<FlightTrackDTO>> getFlightTaskTrackList(
                                                                        @PathVariable(name = "workspace_id") String workspaceId,
                                                                        @PathVariable(name = "task_id") String taskId
    ) {
        List<FlightTrackDTO> taskTrackList = flightTaskService.getFlightTrackByTaskId(taskId);

        return HttpResultResponse.success(taskTrackList);
    }
}
