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.ElderlyMedicalRecordPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyMedicalRecordDO;
import cn.iocoder.yudao.module.system.service.biz.ElderlyMedicalRecordService;
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 java.util.Objects;


@Tag(name = "管理后台 - 长者体检报告记录")
@RestController
@RequestMapping("/elderlyMedicalRecord")
public class ElderlyMedicalRecordController {


    @Resource
    private ElderlyMedicalRecordService elderlyMedicalRecordService;


    @PostMapping("/save")
    @Operation(summary = "长者体检报告新增")
    @TenantIgnore
    public CommonResult<Boolean> save(@RequestBody ElderlyMedicalRecordDO elderlyMedicalRecord){
        elderlyMedicalRecord.setTenantId(elderlyMedicalRecord.getTenantId() == null ? TenantContextHolder.getTenantId() : elderlyMedicalRecord.getTenantId());
        elderlyMedicalRecordService.save(elderlyMedicalRecord);
        return CommonResult.success(true);
    }

    @GetMapping("/queryPage")
    @Operation(summary = "长者体检报告列表")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyMedicalRecordDO>> queryPage(ElderlyMedicalRecordPageReqVO pageReqVO){
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<ElderlyMedicalRecordDO> pageResult = elderlyMedicalRecordService.queryPage(pageReqVO);
        return CommonResult.success(pageResult);
    }


    @GetMapping("/getDetailById")
    @Operation(summary = "长者体检报报告详情")
    @Parameter(name = "id", description = "体检报告ID", required = true, example = "1024")
    public CommonResult<ElderlyMedicalRecordDO> getDetailById(@RequestParam("id") Long id){
        return CommonResult.success(elderlyMedicalRecordService.getDetailById(id));
    }

    @GetMapping("/getLastRecord")
    @Operation(summary = "获取长者最新体检报告")
    @Parameter(name = "elderId", description = "长者ID", required = true, example = "1024")
    public CommonResult<ElderlyMedicalRecordDO> getLastRecord(@RequestParam("elderId") Long elderId){
        return CommonResult.success(elderlyMedicalRecordService.getLastRecord(elderId));
    }


    @DeleteMapping("/delete")
    @Operation(summary = "删除长者体检报告")
    @Parameter(name = "id", description = "体检报告ID", required = true, example = "1024")
    public CommonResult<Boolean> delete(@RequestParam("id") Long id){
        elderlyMedicalRecordService.delete(id);
        return CommonResult.success(true);
    }


    @PostMapping("/edit")
    @Operation(summary = "长者体检报告修改")
    public CommonResult<Boolean> edit(@RequestBody ElderlyMedicalRecordDO elderlyMedicalRecord){
        elderlyMedicalRecordService.edit(elderlyMedicalRecord);
        return CommonResult.success(true);
    }
}
