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.elderlyassessattackriskfactors.ElderlyAssessAttackRiskFactorsPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlyassessattackriskfactors.ElderlyAssessAttackRiskFactorsRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlyassessattackriskfactors.ElderlyAssessAttackRiskFactorsSaveReqVO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyAssessAttackRiskFactorsService;
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-assess-attack-risk-factors")
@Validated
public class ElderlyAssessAttackRiskFactorsController {

    @Resource
    private ElderlyAssessAttackRiskFactorsService elderlyAssessAttackRiskFactorsService;

    @PostMapping("/create")
    @Operation(summary = "创建攻击风险因素量表")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyAssessAttackRiskFactorsSaveReqVO createReqVO) {
        if (createReqVO.getTenantId() == null) {
            createReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        return success(elderlyAssessAttackRiskFactorsService.create(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新攻击风险因素量表")
    @TenantIgnore
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyAssessAttackRiskFactorsSaveReqVO updateReqVO) {
        if (updateReqVO.getTenantId() == null) {
            updateReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        elderlyAssessAttackRiskFactorsService.update(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除攻击风险因素量表")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        elderlyAssessAttackRiskFactorsService.delete(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得攻击风险因素量表详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @TenantIgnore
    public CommonResult<ElderlyAssessAttackRiskFactorsRespVO> get(@RequestParam("id") Long id) {
        return success(elderlyAssessAttackRiskFactorsService.get(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得攻击风险因素量表分页")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyAssessAttackRiskFactorsRespVO>> page(@Valid ElderlyAssessAttackRiskFactorsPageReqVO pageReqVO) {
        if (pageReqVO.getTenantIds() == null) {
            pageReqVO.setTenantIds(new Long[]{TenantContextHolder.getTenantId()});
        }
        return success(elderlyAssessAttackRiskFactorsService.getPage(pageReqVO));
    }
}
