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.ElderlySpecialNursingLogListReqVO;
import cn.iocoder.yudao.module.system.controller.admin.nursing.vo.ElderlySpecialNursingLogPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.nursing.vo.ElderlySpecialNursingLogRespVO;
import cn.iocoder.yudao.module.system.controller.admin.nursing.vo.ElderlySpecialNursingLogSimpleRespVO;
import cn.iocoder.yudao.module.system.controller.admin.nursing.vo.SpecialNursingPlanCancelReqVO;
import cn.iocoder.yudao.module.system.controller.admin.nursing.vo.SpecialNursingPlanItemSaveReqVO;
import cn.iocoder.yudao.module.system.service.nursing.ElderlySpecialNursingLogService;
import io.swagger.v3.oas.annotations.Operation;
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 java.util.List;
import java.util.Objects;

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

@Tag(name = "管理后台 - 长者特殊护理计划执行日志")
@RestController
@RequestMapping("/nursing/special-nursing-log")
@Validated
public class ElderlySpecialNursingLogController {

    @Resource
    private ElderlySpecialNursingLogService elderlySpecialNursingLogService;

    @PutMapping("/cancel")
    @Operation(summary = "撤销特殊照护计划明细")
    @TenantIgnore
    public CommonResult<Boolean> cancel(@Valid @RequestBody SpecialNursingPlanCancelReqVO updateReqVO) {
        elderlySpecialNursingLogService.cancel(updateReqVO);
        return success(true);
    }

    @GetMapping("/page")
    @Operation(summary = "获得长者特殊护理计划执行日志分页")
    @TenantIgnore
    public CommonResult<PageResult<ElderlySpecialNursingLogSimpleRespVO>> getPage(@Valid ElderlySpecialNursingLogPageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds())
                ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        return success(elderlySpecialNursingLogService.getPage(pageReqVO));
    }

    @GetMapping("/list-by-elder-and-finish-time")
    @Operation(summary = "根据长者ID和完成日期范围查询执行日志")
    @TenantIgnore
    public CommonResult<List<ElderlySpecialNursingLogRespVO>> getListByElderIdAndFinishTime(@Valid ElderlySpecialNursingLogListReqVO listReqVO) {
        listReqVO.setTenantId(Objects.isNull(listReqVO.getTenantId())
                ? TenantContextHolder.getTenantId() : listReqVO.getTenantId());
        return success(elderlySpecialNursingLogService.getListByElderIdAndFinishTime(listReqVO));
    }
}
