package com.ningdatech.carapi.open.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.archives.aop.AuditVehicle;
import com.ningdatech.carapi.car.vehicle.model.dto.VehicleArchivesPageQuery;
import com.ningdatech.carapi.car.vehicle.model.dto.VehicleArchivesQueryDTO;
import com.ningdatech.carapi.archives.manage.ArchivesManage;
import com.ningdatech.carapi.car.vehicle.manage.VehicleManage;
import com.ningdatech.carapi.car.vehicle.model.vo.VehicleBaseVO;
import com.ningdatech.carapi.car.vehicle.service.IVehicleBaseInfoService;
import com.ningdatech.carapi.qrcode.model.vo.GetOnVehicleVO;
import com.ningdatech.carapi.safe.model.vo.NdVehicleAccidentAnalysisVO;
import com.ningdatech.carapi.safe.model.vo.NdVehicleAccidentDeadVO;
import com.ningdatech.carapi.safe.model.vo.NdVehicleAccidentVO;
import com.ningdatech.carapi.safe.model.vo.NdVehicleViolationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author PoffyZhang
 * @since 2022-10-09
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/open/api/archives/vehicle")
@Api(value = "archives", tags = "车辆管理-档案管理")
@RequiredArgsConstructor
public class OpenApiVehicleArchivesController {

    private final VehicleManage vehicleManage;
    private final IVehicleBaseInfoService vehicleBaseInfoService;
    private final ArchivesManage archivesManage;

    @ApiOperation(value = "车辆档案列表查询", notes = "车辆档案列表查询")
    @GetMapping("/archivesList")
    public PageVo<VehicleBaseVO> queryArchivesList(@Valid @ModelAttribute VehicleArchivesPageQuery vehicleArchivesPageQuery) {
        return vehicleManage.queryArchivesListOpen(vehicleArchivesPageQuery);
    }

    /**
     * 查询车辆基本信息
     *
     * @param id 主键id
     * @return 查询结果
     */
    @ApiOperation(value = "查询车辆基本信息", notes = "查询车辆基本信息")
    @GetMapping("/baseInfo")
    public VehicleArchivesQueryDTO getDetails(@Valid @RequestParam Long id) {
        return vehicleManage.getDetails(id);
    }

    /**
     * 查询车辆违章记录档案
     *
     * @param carPlate,violationType
     * @return
     */
    @ApiOperation(value = "查询车辆违章记录档案", notes = "查询车辆违章记录档案")
    @GetMapping("/violation")
    @AuditVehicle
    public List<NdVehicleViolationVO> getViolation(@Valid @RequestParam String carPlate, @Valid @RequestParam Integer violationType) {
        return archivesManage.getViolation(carPlate,violationType);
    }

    /**
     * 查询车辆事故记录档案
     * @param carPlate,violationType
     * @return
     */
    @ApiOperation(value = "查询车辆事故记录档案", notes = "查询车辆事故记录档案")
    @GetMapping("/accident-vehicle")
    @AuditVehicle
    public List<NdVehicleAccidentVO> getAccidentVehicle(@Valid @RequestParam String carPlate) {
        return archivesManage.getAccidentVehicleOpen(carPlate);
    }

    /**
     * 查询车辆死亡事故记录档案
     *
     * @param carPlate,violationType
     * @return
     */
    @ApiOperation(value = "查询车辆死亡事故记录档案", notes = "查询车辆死亡事故记录档案")
    @GetMapping("/accident-dead")
    @AuditVehicle
    public List<NdVehicleAccidentDeadVO> getAccidentDead(@Valid @RequestParam String carPlate) {
        return archivesManage.getAccidentDeadOpen(carPlate);
    }

    /**
     * 查询车辆事故分析记录档案
     *
     * @param carPlate,violationType
     * @return
     */
    @ApiOperation(value = "查询车辆事故分析记录档案", notes = "查询车辆事故分析记录档案")
    @GetMapping("/accident-analysis")
    @AuditVehicle
    public List<NdVehicleAccidentAnalysisVO> getAccidentAnalysis(@Valid @RequestParam String carPlate) {
        return archivesManage.getAccidentAnalysisOpen(carPlate);
    }

    /**
     * 查询车辆上车记录
     *
     * @param driverId
     * @return
     */
    @ApiOperation(value = "查询车辆上车记录-驾驶员ID", notes = "查询车辆上车记录")
    @GetMapping("/get-driver-on-car-list")
    public List<GetOnVehicleVO> getOnCarDriver(@Valid @RequestParam String driverId) {
        return archivesManage.getOnCarDriver(driverId);
    }
}
