package com.sqx.modules.driver.controller.app;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.driver.entity.Driver;
import com.sqx.modules.driver.service.DriverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Api(value = "司机-用户端", tags = {"司机-用户端"})
@RequestMapping("/app/driver")
public class AppDriverController {

    @Autowired
    private DriverService driverService;

    @Login
    @PostMapping("/insertDriver")
    @ApiOperation("提交司机资料认证")
    public Result insertDriver(@RequestBody Driver driver,@RequestAttribute Long userId){
        driver.setUserId(userId);
        return driverService.insertDriver(driver);
    }

    @Login
    @PostMapping("/updateDriver")
    @ApiOperation("修改司机资料")
    public Result updateDriver(@RequestBody Driver driver,@RequestAttribute Long userId){
        driver.setUserId(userId);
        if(driver.getIsCityOrders()!=null && driver.getIsCityOrders()==0){
            driver.setIsCityOrders(2);
        }
        if(driver.getIsProvinceOrders()!=null && driver.getIsProvinceOrders()==0){
            driver.setIsProvinceOrders(2);
        }
        return driverService.updateDriver(driver);
    }

    @Login
    @PostMapping("/deleteDriver")
    @ApiOperation("删除司机资料")
    public Result deleteDriver(Long driverId){
        return driverService.deleteDriver(driverId);
    }


    @GetMapping("/selectDriverByUserId")
    @ApiOperation("查询指定用户的司机信息")
    public Result selectDriverByUserId(Long userId){
        return Result.success().put("data",driverService.selectDriverByUserId(userId));
    }

    @GetMapping("/selectDriverList")
    @ApiOperation("查询司机列表")
    public Result selectDriverList(Integer page,Integer limit,String driverName,String userName,String phone,Integer status){
        return driverService.selectDriverList(page, limit, driverName, userName, phone, status);
    }




}