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.elderlyassessperceptioncommunication.ElderlyAssessPerceptionCommunicationPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlyassessperceptioncommunication.ElderlyAssessPerceptionCommunicationRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlyassessperceptioncommunication.ElderlyAssessPerceptionCommunicationSaveReqVO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyAssessPerceptionCommunicationService;
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-perception-communication")
@Validated
public class ElderlyAssessPerceptionCommunicationController {

    @Resource
    private ElderlyAssessPerceptionCommunicationService elderlyAssessPerceptionCommunicationService;

    @PostMapping("/create")
    @Operation(summary = "创建感知与沟通能力评估")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyAssessPerceptionCommunicationSaveReqVO createReqVO) {
        if (createReqVO.getTenantId() == null) {
            createReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        return success(elderlyAssessPerceptionCommunicationService.create(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新感知与沟通能力评估")
    @TenantIgnore
    public CommonResult<Boolean> update(@Valid @RequestBody ElderlyAssessPerceptionCommunicationSaveReqVO updateReqVO) {
        if (updateReqVO.getTenantId() == null) {
            updateReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        elderlyAssessPerceptionCommunicationService.update(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除感知与沟通能力评估")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        elderlyAssessPerceptionCommunicationService.delete(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得感知与沟通能力评估详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @TenantIgnore
    public CommonResult<ElderlyAssessPerceptionCommunicationRespVO> get(@RequestParam("id") Long id) {
        return success(elderlyAssessPerceptionCommunicationService.get(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得感知与沟通能力评估分页")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyAssessPerceptionCommunicationRespVO>> page(@Valid ElderlyAssessPerceptionCommunicationPageReqVO pageReqVO) {
        if (pageReqVO.getTenantIds() == null) {
            pageReqVO.setTenantIds(new Long[]{TenantContextHolder.getTenantId()});
        }
        return success(elderlyAssessPerceptionCommunicationService.getPage(pageReqVO));
    }
}
