package com.tofly.gpsboot.custom.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.oauth.exception.ToflyDeniedException;
import com.tofly.pojo.car.cusom.CarUploadSearch;
import com.tofly.pojo.car.cusom.GpsCarSearch;
import com.tofly.gpsboot.custom.service.CustomCarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
@RequestMapping("/car")
@Api(tags="车辆信息获取接口")
public class CustomCarController {
    private final CustomCarService customCarService;

    @ApiOperation(value = "获取定位数据列表(车辆定位轨迹)")
    @GetMapping("/gpsCar")
    public ResultRespone getGpsCarList(Page page, GpsCarSearch gpsCarSearch) {
        if (gpsCarSearch.getStartTime() == null && gpsCarSearch.getEndTime() != null){
            throw new ToflyDeniedException("开始时间和结束时间需同时输入");
        }
        if (gpsCarSearch.getStartTime() != null && gpsCarSearch.getEndTime() == null){
            throw new ToflyDeniedException("开始时间和结束时间需同时输入");
        }
        return customCarService.getGpsCarList(page,gpsCarSearch);
    }

    @ApiOperation(value = "获取分段")
    @GetMapping("/getSection")
    public ResultRespone getSection(GpsCarSearch gpsCarSearch) {
        if (gpsCarSearch.getStartTime() == null && gpsCarSearch.getEndTime() != null){
            throw new ToflyDeniedException("开始时间和结束时间需同时输入");
        }
        if (gpsCarSearch.getStartTime() != null && gpsCarSearch.getEndTime() == null){
            throw new ToflyDeniedException("开始时间和结束时间需同时输入");
        }
        return ResultRespone.success(customCarService.getSection(gpsCarSearch));
    }

    @GetMapping("/listCarWatch" )
    @ApiOperation(value = "车辆监控状态列表")
    public ResultRespone ListCarWatch(Page page, @ModelAttribute CarUploadSearch carUploadSearch) {
        return ResultRespone.success(customCarService.listCarWatch(page,carUploadSearch));
    }
}
