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.elderlycare.ElderlyCareServiceRecordPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlycare.ElderlyCareServiceRecordRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.elderlycare.ElderlyCareServiceRecordSaveReqVO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyCareServiceRecordService;
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;

/**
 * 管理后台 - 长者照护计划 Controller
 *
 * @author 系统管理员
 */
@Tag(name = "管理后台 - 长者照护计划")
@RestController
@RequestMapping("/elderly-care-service-record")
@Validated
public class ElderlyCareServiceRecordController {

    @Resource
    private ElderlyCareServiceRecordService elderlyCareServiceRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建长者照护计划")
    public CommonResult<Long> create(@Valid @RequestBody ElderlyCareServiceRecordSaveReqVO createReqVO) {
        // tenantId 可由前端传；不传则默认当前租户
        if (createReqVO.getTenantId() == null) {
            createReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        return success(elderlyCareServiceRecordService.createElderlyCareServiceRecord(createReqVO));
    }

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

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

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

    @GetMapping("/page")
    @Operation(summary = "获得长者照护计划分页")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyCareServiceRecordRespVO>> page(@Valid ElderlyCareServiceRecordPageReqVO pageReqVO) {
        // tenantId 可由前端传；不传则默认当前租户
        if (pageReqVO.getTenantId() == null) {
            pageReqVO.setTenantId(TenantContextHolder.getTenantId());
        }
        return success(elderlyCareServiceRecordService.getElderlyCareServiceRecordPage(pageReqVO));
    }
}