package cn.iocoder.yudao.module.app.car.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.app.car.entity.AppCarMain;
import cn.iocoder.yudao.module.app.car.service.AppCarMainService;
import cn.iocoder.yudao.module.app.car.vo.AppCarMainResVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "小程序 - 我的车辆")
@RestController
@RequestMapping("/userClient/base/myCar")
@Validated
public class AppCarMainController {

    @Autowired
    private AppCarMainService carMainService;

    /**
     * 创建车辆信息
     *
     * @param carMain
     * @return
     */
    @PostMapping("/create")
    @Operation(summary = "创建车辆信息")
//    @PreAuthorize("@ss.hasPermission('base:car-main:create')")
    public CommonResult<String> createCarMain(@RequestBody AppCarMain carMain) {
        return carMainService.createCarMain(carMain);
    }

    /**
     * 更新车辆信息
     *
     * @param carMain
     * @return
     */
    @PutMapping("/update")
    @Operation(summary = "更新车辆信息")
//    @PreAuthorize("@ss.hasPermission('base:car-main:update')")
    public CommonResult<String> updateCarMain(@RequestBody AppCarMain carMain) {
        return carMainService.updateCarMain(carMain);
    }

    /**
     * 删除车辆信息
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    @Operation(summary = "删除车辆信息")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('base:car-main:delete')")
    public CommonResult<String> deleteCarMain(@RequestParam("id") String id) {
        return carMainService.deleteCarMain(id);
    }

    /**
     * 根据当前用户获得车辆信息
     *
     * @return
     */
    @GetMapping("/get")
    @Operation(summary = "获得车辆信息")
//    @PreAuthorize("@ss.hasPermission('base:car-main:query')")
    public CommonResult<List<AppCarMainResVo>> getCarMain() {
        List<AppCarMainResVo> carMain = carMainService.getCarMain();
        return CommonResult.success(carMain);
    }


}