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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.asset.controller.admin.inspection.vo.InspectionRecordDetailVO;
import cn.iocoder.yudao.module.asset.controller.admin.inspection.vo.InspectionRecordItemUpdateReqVO;
import cn.iocoder.yudao.module.asset.service.inspection.InspectionRecordService;
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;

/**
 * 验车记录 Controller
 *
 * @author 芋道源码
 */
@Tag(name = "管理后台 - 验车记录管理")
@RestController
@RequestMapping("/asset/inspection-record")
@Validated
public class InspectionRecordController {

    @Resource
    private InspectionRecordService inspectionRecordService;

    @GetMapping("/get")
    @Operation(summary = "获得验车记录详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('asset:inspection-record:query')")
    public CommonResult<InspectionRecordDetailVO> getRecordDetail(@RequestParam("id") Long id) {
        return success(inspectionRecordService.getRecordDetail(id));
    }

    @PutMapping("/update-item")
    @Operation(summary = "更新验车记录检查项")
    @PreAuthorize("@ss.hasPermission('asset:inspection-record:update')")
    public CommonResult<Boolean> updateRecordItem(@Valid @RequestBody InspectionRecordItemUpdateReqVO updateReqVO) {
        inspectionRecordService.updateRecordItem(updateReqVO);
        return success(true);
    }

    @PostMapping("/complete")
    @Operation(summary = "完成验车记录")
    @Parameter(name = "id", description = "记录ID", required = true, example = "1")
    @Parameter(name = "inspectorName", description = "检查人", required = true, example = "张三")
    @PreAuthorize("@ss.hasPermission('asset:inspection-record:update')")
    public CommonResult<Boolean> completeRecord(@RequestParam("id") Long id,
                                                 @RequestParam("inspectorName") String inspectorName) {
        inspectionRecordService.completeRecord(id, inspectorName);
        return success(true);
    }

}
