package cn.iocoder.yudao.module.system.controller.admin.biz;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlyfacilityequipmentcheck.ElderlyFacilityEquipmentCheckPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlyfacilityequipmentcheck.ElderlyFacilityEquipmentCheckRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlyfacilityequipmentcheck.ElderlyFacilityEquipmentCheckSaveReqVO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyFacilityEquipmentCheckService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

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

@Tag(name = "管理后台 - 设施设备检查记录")
@RestController
@RequestMapping("/elderly-facility-equipment-check")
@Validated
public class ElderlyFacilityEquipmentCheckController {

    @Resource
    private ElderlyFacilityEquipmentCheckService elderlyFacilityEquipmentCheckService;

    @PostMapping("/create")
    @Operation(summary = "创建设施设备检查记录")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyFacilityEquipmentCheckSaveReqVO createReqVO) {
        if (createReqVO.getTenantId() == null) {
            createReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        return success(elderlyFacilityEquipmentCheckService.create(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新设施设备检查记录")
    @TenantIgnore
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyFacilityEquipmentCheckSaveReqVO updateReqVO) {
        if (updateReqVO.getTenantId() == null) {
            updateReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        elderlyFacilityEquipmentCheckService.update(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除设施设备检查记录")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        elderlyFacilityEquipmentCheckService.delete(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得设施设备检查记录详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @TenantIgnore
    public CommonResult<ElderlyFacilityEquipmentCheckRespVO> get(@RequestParam("id") Long id) {
        return success(elderlyFacilityEquipmentCheckService.get(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得设施设备检查记录分页")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyFacilityEquipmentCheckRespVO>> page(@Valid ElderlyFacilityEquipmentCheckPageReqVO pageReqVO) {
        if (pageReqVO.getTenantIds() == null) {
            pageReqVO.setTenantIds(new Long[]{TenantContextHolder.getTenantId()});
        }
        return success(elderlyFacilityEquipmentCheckService.getPage(pageReqVO));
    }
}
