package com.ningdatech.carapi.qrcode.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.driver.model.vo.ResArchivalInfoSearchListVO;
import com.ningdatech.carapi.qrcode.manage.QrcodeManage;
import com.ningdatech.carapi.qrcode.model.dto.GetOnVehicleDTO;
import com.ningdatech.carapi.qrcode.model.dto.VehicleGetOnPageQuery;
import com.ningdatech.carapi.qrcode.model.vo.GetOnVehicleVO;
import com.ningdatech.carapi.user.util.LoginUserUtil;
import com.ningdatech.log.annotation.WebLog;
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;

/**
 * <p>
 * 前端控制器
 * 二维码相关
 * </p>
 *
 * @author PoffyZhang
 * @since 2022-09-30
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/qrcode")
@Api(value = "Qrcode", tags = "二维码")
@RequiredArgsConstructor
public class QrcodeController {

    private final QrcodeManage qrcodeManage;

    @ApiOperation(value = "获取当前登录驾驶员信息", notes = "获取当前登录驾驶员信息")
    @GetMapping("/driver-logined")
    @WebLog
    public ResArchivalInfoSearchListVO queryLoginedDriver() {
        return qrcodeManage.queryLoginedDriver();
    }

    @ApiOperation(value = "扫码上车", notes = "扫码上车")
    @PostMapping("/get-on-vehicle")
    @WebLog
    public GetOnVehicleVO getOnVehicle(@Valid @RequestBody GetOnVehicleDTO getOnVehicleDTO) {
        return qrcodeManage.getOnVehicle(getOnVehicleDTO, LoginUserUtil.getUserId());
    }

    @ApiOperation(value = "上车记录列表查询", notes = "上车记录列表查询")
    @GetMapping("/get-on-list")
    public PageVo<GetOnVehicleVO> getOnList(@Valid @ModelAttribute VehicleGetOnPageQuery vehicleArchivesPageQuery) {
        return qrcodeManage.getOnList(vehicleArchivesPageQuery);
    }
}
