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

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.nursing.vo.SpecialNursingPlanPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.nursing.vo.SpecialNursingPlanRespVO;
import cn.iocoder.yudao.module.system.controller.admin.nursing.vo.SpecialNursingPlanSaveReqVO;
import cn.iocoder.yudao.module.system.service.nursing.SpecialNursingPlanService;
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("/nursing/special-plan")
@Validated
public class SpecialNursingPlanController {

    @Resource
    private SpecialNursingPlanService specialNursingPlanService;

    @PostMapping("/create")
    @Operation(summary = "创建特殊照护计划")
    public CommonResult<Long> create(@Valid @RequestBody SpecialNursingPlanSaveReqVO createReqVO) {
        if (createReqVO.getTenantId() == null) {
            createReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        return success(specialNursingPlanService.create(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新特殊照护计划")
    @TenantIgnore
    public CommonResult<Boolean> update(@Valid @RequestBody SpecialNursingPlanSaveReqVO updateReqVO) {
        if (updateReqVO.getTenantId() == null) {
            updateReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        specialNursingPlanService.update(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除特殊照护计划")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        specialNursingPlanService.delete(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得特殊照护计划详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @TenantIgnore
    public CommonResult<SpecialNursingPlanRespVO> get(@RequestParam("id") Long id) {
        return success(specialNursingPlanService.get(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得特殊照护计划分页")
    @TenantIgnore
    public CommonResult<PageResult<SpecialNursingPlanRespVO>> page(@Valid SpecialNursingPlanPageReqVO pageReqVO) {
        if (pageReqVO.getTenantIds() == null) {
            pageReqVO.setTenantIds(new Long[]{TenantContextHolder.getTenantId()});
        }
        return success(specialNursingPlanService.getPage(pageReqVO));
    }
}

