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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.asset.controller.admin.inspection.vo.*;
import cn.iocoder.yudao.module.asset.convert.inspection.InspectionConvert;
import cn.iocoder.yudao.module.asset.dal.dataobject.inspection.InspectionTemplateDO;
import cn.iocoder.yudao.module.asset.service.inspection.InspectionTemplateService;
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-template")
@Validated
public class InspectionTemplateController {

    @Resource
    private InspectionTemplateService inspectionTemplateService;

    @PostMapping("/create")
    @Operation(summary = "创建验车模板")
    @PreAuthorize("@ss.hasPermission('asset:inspection-template:create')")
    public CommonResult<Long> createTemplate(@Valid @RequestBody InspectionTemplateSaveReqVO createReqVO) {
        return success(inspectionTemplateService.createTemplate(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新验车模板")
    @PreAuthorize("@ss.hasPermission('asset:inspection-template:update')")
    public CommonResult<Boolean> updateTemplate(@Valid @RequestBody InspectionTemplateSaveReqVO updateReqVO) {
        inspectionTemplateService.updateTemplate(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除验车模板")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('asset:inspection-template:delete')")
    public CommonResult<Boolean> deleteTemplate(@RequestParam("id") Long id) {
        inspectionTemplateService.deleteTemplate(id);
        return success(true);
    }

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

    @GetMapping("/page")
    @Operation(summary = "获得验车模板分页")
    @PreAuthorize("@ss.hasPermission('asset:inspection-template:query')")
    public CommonResult<PageResult<InspectionTemplateRespVO>> getTemplatePage(@Valid InspectionTemplatePageReqVO pageReqVO) {
        PageResult<InspectionTemplateDO> pageResult = inspectionTemplateService.getTemplatePage(pageReqVO);
        return success(InspectionConvert.INSTANCE.convertPage(pageResult));
    }

}
