package cn.iocoder.yudao.module.asset.controller.admin.prepare;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.asset.controller.admin.prepare.vo.*;
import cn.iocoder.yudao.module.asset.dal.dataobject.prepare.VehiclePrepareDO;
import cn.iocoder.yudao.module.asset.service.prepare.VehiclePrepareService;
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.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 备车管理")
@RestController
@RequestMapping("/asset/vehicle-prepare")
@Validated
public class VehiclePrepareController {

    @Resource
    private VehiclePrepareService vehiclePrepareService;

    @PostMapping("/create")
    @Operation(summary = "创建备车记录")
    @PreAuthorize("@ss.hasPermission('asset:vehicle-prepare:create')")
    public CommonResult<Long> createVehiclePrepare(@Valid @RequestBody VehiclePrepareSaveReqVO createReqVO) {
        return success(vehiclePrepareService.createVehiclePrepare(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新备车记录")
    @PreAuthorize("@ss.hasPermission('asset:vehicle-prepare:update')")
    public CommonResult<Boolean> updateVehiclePrepare(@Valid @RequestBody VehiclePrepareSaveReqVO updateReqVO) {
        vehiclePrepareService.updateVehiclePrepare(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除备车记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('asset:vehicle-prepare:delete')")
    public CommonResult<Boolean> deleteVehiclePrepare(@RequestParam("id") Long id) {
        vehiclePrepareService.deleteVehiclePrepare(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得备车记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('asset:vehicle-prepare:query')")
    public CommonResult<VehiclePrepareRespVO> getVehiclePrepare(@RequestParam("id") Long id) {
        VehiclePrepareDO prepare = vehiclePrepareService.getVehiclePrepare(id);
        return success(BeanUtils.toBean(prepare, VehiclePrepareRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得备车记录分页")
    @PreAuthorize("@ss.hasPermission('asset:vehicle-prepare:query')")
    public CommonResult<PageResult<VehiclePrepareRespVO>> getVehiclePreparePage(@Valid VehiclePreparePageReqVO pageReqVO) {
        PageResult<VehiclePrepareDO> pageResult = vehiclePrepareService.getVehiclePreparePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, VehiclePrepareRespVO.class));
    }

    @PutMapping("/complete")
    @Operation(summary = "完成备车")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('asset:vehicle-prepare:update')")
    public CommonResult<Boolean> completeVehiclePrepare(@RequestParam("id") Long id) {
        vehiclePrepareService.completeVehiclePrepare(id);
        return success(true);
    }

}
