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.common.util.object.BeanUtils;
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.ElderlyHealthRecordPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyHealthRecordDO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyHealthRecordService;
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.web.bind.annotation.*;

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

import java.util.Objects;

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


@Tag(name = "管理后台 - 健康档案信息")
@RestController
@RequestMapping("/elderlyHealthRecord")
public class ElderlyHealthRecordController {

    @Resource
    private ElderlyHealthRecordService elderlyHealthRecordService;


    @PostMapping("/add")
    @Operation(summary = "健康档案新增")
    @TenantIgnore
    public CommonResult<Boolean> add(@RequestBody ElderlyHealthRecordDO elderlyHealthRecordDO) {
        elderlyHealthRecordDO.setTenantId(elderlyHealthRecordDO.getTenantId() == null ? TenantContextHolder.getTenantId() : elderlyHealthRecordDO.getTenantId());
        elderlyHealthRecordService.add(elderlyHealthRecordDO);
        return success(true);
    }

    @PostMapping("/edit")
    @Operation(summary = "健康档案编辑")
    public CommonResult<Boolean> edit(@RequestBody ElderlyHealthRecordDO elderlyHealthRecordDO) {
        elderlyHealthRecordService.edit(elderlyHealthRecordDO);
        return success(true);
    }


    @GetMapping("/getElderHealthRecordById")
    @Operation(summary = "健康档案详情")
    @Parameter(name = "elderId", description = "长者ID", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<ElderlyHealthRecordDO> getElderHealthRecordByElderId(@RequestParam("elderId") Long elderId) {
        return success(elderlyHealthRecordService.getElderHealthRecordByElderId(elderId));
    }


    @DeleteMapping("/delete")
    @Operation(summary = "健康档案删除")
    @Parameter(name = "elderlyHealthRecordId", description = "健康档案ID", required = true, example = "1024")
    public CommonResult<Boolean> delete(@RequestParam("elderlyHealthRecordId") Long elderlyHealthRecordId) {
        elderlyHealthRecordService.delete(elderlyHealthRecordId);
        return success(true);
    }


    @GetMapping("/queryPage")
    @Operation(summary = "健康档案列表")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyHealthRecordDO>> queryPage(@Valid ElderlyHealthRecordPageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<ElderlyHealthRecordDO> pageResult = elderlyHealthRecordService.queryPage(pageReqVO);
        return success(pageResult);
    }

}
