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.module.system.controller.admin.biz.vo.*;
import cn.iocoder.yudao.module.system.controller.admin.nursing.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.NursingInspectionDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.NursingLogDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.NursingLogRecordDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.NursingLogRemarksDO;
import cn.iocoder.yudao.module.system.service.nursing.NursingLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import org.springframework.web.bind.annotation.*;

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

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;
import java.util.Map;

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


@Tag(name = "管理后台 - 护理日志")
@RestController
@RequestMapping("/elderly/nursingLog")
@Validated
public class NursingLogController {

    @Resource
    private NursingLogService nursingLogService;

    @PostMapping("/supplementNursingLog")
    @Operation(summary = "补录护理日志")
    public CommonResult<Boolean> supplementNursingLog(@Valid @RequestBody NursingLogSaveReqVO createReqVO) {
        nursingLogService.supplementNursingLog(createReqVO);
        return success(true);
    }

    //
//    @PutMapping("/update")
//    @Operation(summary = "更新护理日志")
//    @PreAuthorize("@ss.hasPermission('elderly:nursing-log:update')")
//    public CommonResult<Boolean> updateNursingLog(@Valid @RequestBody NursingLogSaveReqVO updateReqVO) {
//        nursingLogService.updateNursingLog(updateReqVO);
//        return success(true);
//    }
//
//    @DeleteMapping("/delete")
//    @Operation(summary = "删除护理日志")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('elderly:nursing-log:delete')")
//    public CommonResult<Boolean> deleteNursingLog(@RequestParam("id") Long id) {
//        nursingLogService.deleteNursingLog(id);
//        return success(true);
//    }
//
    @GetMapping("/getNursingLogByTime")
    @Operation(summary = "获取护理日志(按时间查询)")
    @Parameters({@Parameter(name = "id", description = "护理日志ID", required = true, example = "1024"),
            @Parameter(name = "type", description = "护理计划类型")})
    public CommonResult<Map<String, List<NursingLogRecordRespVO>>> getNursingLogByTime(@RequestParam("id") Long id, @RequestParam(value = "type", required = false) Integer type) {
        Map<String, List<NursingLogRecordRespVO>> dataMap = nursingLogService.getNursingLogByTime(id, type);
        return success(dataMap);
    }


    @GetMapping("/getNursingLogByItem")
    @Operation(summary = "获取护理日志（按项目查询）")
    public CommonResult<List<Map<String, Object>>> getNursingLogByItem(@RequestParam("id") Long id
            , @RequestParam(value = "type", required = false) Integer type
            , @RequestParam(value = "caregiverName", required = false) String caregiverName
            , @RequestParam(value = "nurseItemName", required = false) String nurseItemName) {
        return success(nursingLogService.getNursingLogByItem(id, type, caregiverName, nurseItemName));
    }


    @GetMapping("/getDetails")
    @Operation(summary = "补录详情")
    @Parameters({@Parameter(name = "elderId", description = "长者ID", required = true, example = "1024"),
            @Parameter(name = "type", description = "护理计划类型")})
    public CommonResult<List<NursingPlanItemRespVO>> getDetails(@RequestParam("elderId") Long elderId,
                                                                @RequestParam(value = "type", required = false) Integer type
            , @RequestParam("nursingLogId") Long nursingLogId) {
        return success(nursingLogService.getDetails(elderId, type,nursingLogId));
    }

    @GetMapping("/page")
    @Operation(summary = "获得护理日志分页")
    public CommonResult<PageResult<NursingLogDO>> getNursingLogPage(@Valid NursingLogPageReqVO pageReqVO) {
        PageResult<NursingLogDO> pageResult = nursingLogService.getNursingLogPage(pageReqVO);
        return success(pageResult);
    }


    @PostMapping("/mobile/addNurseLogDetail")
    @Operation(summary = "移动端-移动端新增护理日志")
    public CommonResult<Boolean> addNurseLogDetail(@RequestBody NursingLogRecordDO nursingLogRecordDO) {
        nursingLogService.addNurseLogDetail(nursingLogRecordDO);
        return success(true);
    }


    @PostMapping("/mobile/addNursingRemarks")
    @Operation(summary = "移动端-增加护理日志备注记录")
    public CommonResult<Boolean> addNursingRemarks(@RequestBody NursingLogRemarksDO logRemarksDO) {
        nursingLogService.addNursingRemarks(logRemarksDO);
        return success(true);
    }


    @GetMapping("/mobile/getNursingRemarks")
    @Operation(summary = "移动端-获取护理日志备注记录")
    @Parameter(name = "nursingLogId", description = "护理日志ID", required = true, example = "1024")
    public CommonResult<List<NursingLogRemarksDO>> getNursingRemarks(@RequestParam("nursingLogId") Long nursingLogId) {
        return success(nursingLogService.getNursingRemarks(nursingLogId));
    }


    @GetMapping("/mobile/getMobileNursingLog")
    @Operation(summary = "移动端-获取护理日志")
    public CommonResult<List<NursingLogDO>> getMobileNursingLog(@RequestParam(value = "elderName", required = false) String elderName, @RequestParam(value = "bedId", required = false) Long bedId) {
        return success(nursingLogService.getMobileNursingLog(elderName, bedId));
    }


    @GetMapping("/mobile/getNursingRecordList")
    @Operation(summary = "移动端-护理记录列表")
    @Parameter(name = "nursingLogId", description = "护理日志ID", required = true, example = "1024")
    public CommonResult<List<NursingLogRecordDO>> getNursingRecordList(@RequestParam("nursingLogId") Long nursingLogId) {
        return success(nursingLogService.getNursingRecordList(nursingLogId));
    }

    @GetMapping("/getNursingItemPlanList")
    @Operation(summary = "移动端-护理计划列表")
    @Parameter(name = "nursingLogId", description = "护理日志ID", required = true, example = "1024")
    public CommonResult<Map<String, List<NursingPlanItemRespVO>>> getNursingItemPlanList(@RequestParam("nursingLogId") Long nursingLogId) {
        return success(nursingLogService.getNursingItemPlanList(nursingLogId));
    }





//    @GetMapping("/export-excel")
//    @Operation(summary = "导出护理日志 Excel")
//    @PreAuthorize("@ss.hasPermission('elderly:nursing-log:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportNursingLogExcel(@Valid NursingLogPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<NursingLogDO> list = nursingLogService.getNursingLogPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "护理日志.xls", "数据", NursingLogRespVO.class,
//                        BeanUtils.toBean(list, NursingLogRespVO.class));
//    }

}