package com.sckw.transport.controller;

import com.sckw.core.web.response.BaseResult;
import com.sckw.core.web.response.result.PageDataResult;
import com.sckw.transport.model.param.CurrentTaskTraceReq;
import com.sckw.transport.model.param.KwfTruckTraceReplayReq;
import com.sckw.transport.model.param.TruckInfoReq;
import com.sckw.transport.model.vo.CurrentTaskTraceReqVo;
import com.sckw.transport.model.vo.KwfTruckTraceReplayVo;
import com.sckw.transport.model.vo.TruckInfoVo;
import com.sckw.transport.model.vo.TruckSelectVo;
import com.sckw.transport.model.dto.TruckSelectReq;
import com.sckw.transport.model.dto.MapVehicleQueryReq;
import com.sckw.transport.model.vo.MapVehicleVo;
import com.sckw.transport.model.dto.VehicleExceptionQueryReq;
import com.sckw.transport.model.vo.VehicleExceptionVo;
import com.sckw.transport.model.dto.GenerateTraceReq;
import com.sckw.transport.service.kwfTruckTraceService;
import com.sckw.transport.service.VehicleExceptionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author cxf
 * @desc 车辆轨迹接口
 */
@RestController
@RequestMapping("/kwfTruckTrace")
@RequiredArgsConstructor
@Tag(name = "车辆轨迹相关接口")
public class KwfTruckTraceController {
    private final kwfTruckTraceService kwfTruckTraceService;
    private final VehicleExceptionService vehicleExceptionService;

    /**
     * 获取车辆实时位置信息
     */
    @PostMapping("/queryTruckInfo")
    @Operation(summary = "获取车辆实时位置信息")
    public BaseResult<TruckInfoVo> queryTruckInfo(@RequestBody TruckInfoReq req )  {
        TruckInfoVo truckInfoVo = kwfTruckTraceService.queryTruckInfo(req);
        return BaseResult.success(truckInfoVo);
    }

    /**
     * 查询当前任务的线路
     */
    @PostMapping("/queryCurrentTaskTrace")
    @Operation(summary = "查询当前任务的线路")
    public BaseResult<CurrentTaskTraceReqVo> queryCurrentTaskTrace(@Valid @RequestBody CurrentTaskTraceReq req )  {
        CurrentTaskTraceReqVo taskTrace = kwfTruckTraceService.queryCurrentTaskTrace(req);
        return BaseResult.success(taskTrace);
    }

    /**
     * 查询当前车辆的轨迹明细
     */
    @PostMapping("/queryCurrentTruckTrace")
    @Operation(summary = "查询当前车辆的轨迹明细")
    public BaseResult<CurrentTaskTraceReqVo> queryCurrentTruckTrace(@RequestBody CurrentTaskTraceReq req )  {
        CurrentTaskTraceReqVo taskTrace = kwfTruckTraceService.queryCurrentTruckTrace(req);
        return BaseResult.success(taskTrace);
    }


    /**
     * 轨迹回放
     */
    @PostMapping("/replay")
    @Operation(summary = "轨迹回放")
    public BaseResult<PageDataResult<KwfTruckTraceReplayVo>> findPage(@RequestBody @Valid KwfTruckTraceReplayReq req )  {

        return BaseResult.success( kwfTruckTraceService.findPage(req));
    }

    /**
     * 车辆下拉列表（支持多选、输入匹配）
     */
    @PostMapping("/truckSelect")
    @Operation(summary = "车辆下拉列表", description = "支持根据车牌号输入匹配，返回车牌号和定位状态")
    public BaseResult<List<TruckSelectVo>> getTruckSelectList(@RequestBody TruckSelectReq req) {
        return BaseResult.success(kwfTruckTraceService.getTruckSelectList(req));
    }

    /**
     * 分页查询地图车辆列表
     */
    @PostMapping("/mapVehicleList")
    @Operation(summary = "地图车辆列表", description = "分页查询地图中展示的进行中任务车辆信息")
    public BaseResult<PageDataResult<MapVehicleVo>> queryMapVehicleList(@RequestBody MapVehicleQueryReq req) {
        return BaseResult.success(kwfTruckTraceService.queryMapVehicleList(req));
    }

    /**
     * 分页查询车辆异常图片信息
     */
    @PostMapping("/exceptionList")
    @Operation(summary = "车辆异常列表", description = "根据运输企业ID、异常类型、车牌号、定位状态分页查询车辆异常图片信息")
    public BaseResult<PageDataResult<VehicleExceptionVo>> queryExceptionList(@RequestBody VehicleExceptionQueryReq req) {
        return BaseResult.success(vehicleExceptionService.queryExceptionList(req));
    }

    /**
     * 分页查询车辆异常图片信息
     */
    @PostMapping("/exceptionJkList")
    @Operation(summary = "车辆异常唯一车牌列表", description = "根据运输企业ID、异常类型、车牌号、定位状态分页查询车辆异常图片信息")
    public BaseResult<PageDataResult<VehicleExceptionVo>> exceptionJkList(@RequestBody VehicleExceptionQueryReq req) {
        return BaseResult.success(vehicleExceptionService.exceptionJkList(req));
    }


    /**
     * 生成车辆轨迹
     */
    @PostMapping("/generateTrace")
    @Operation(summary = "生成车辆轨迹", description = "根据日期、运单号、车牌号、当前位置生成车辆轨迹数据")
    public BaseResult<Void> generateTrace(@Valid @RequestBody GenerateTraceReq req) {
        kwfTruckTraceService.generateTrace(req);
        return BaseResult.success();
    }

}