package cn.iocoder.yudao.module.system.controller.admin.nursing;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.NurseGroupRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.NurseGroupSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.NurseGroupDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.nursing.NurseGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 护理分组")
@RestController
@RequestMapping("/nurse/nurseGroup")
@Validated
public class NurseGroupController {

    @Resource
    private NurseGroupService nurseGroupService;


    @PostMapping("/createNurseGroup")
    @Operation(summary = "创建护理分组")
    public CommonResult<Long> createNurseGroup(@Valid @RequestBody NurseGroupSaveReqVO createReqVO) {
        return success(nurseGroupService.createNurseGroup(createReqVO));
    }


    @PutMapping("/updateNurseGroup")
    @Operation(summary = "更新护理分组")
    public CommonResult<Boolean> updateNurseGroup(@Valid @RequestBody NurseGroupSaveReqVO updateReqVO) {
        nurseGroupService.updateNurseGroup(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除护理分组")
    @Parameter(name = "id", description = "护理组ID", required = true)
    public CommonResult<Boolean> deleteNurseGroup(@RequestParam("id") Long id) {
        nurseGroupService.deleteNurseGroup(id);
        return success(true);
    }

    @GetMapping("/getNurseGroup")
    @Operation(summary = "获得护理分组")
    @Parameter(name = "id", description = "护理组ID", required = true, example = "1024")
    public CommonResult<NurseGroupRespVO> getNurseGroup(@RequestParam("id") Long id) {
        return success(nurseGroupService.getNurseGroup(id));
    }


    @GetMapping("/getListByName")
    @Operation(summary = "根据名称获取护理组列表")
    public CommonResult<List<NurseGroupDO>> getListByName(@RequestParam("nurseGroupName") String nurseGroupName) {
        return success(nurseGroupService.getListByName(nurseGroupName));
    }


    @GetMapping("/getNurseGroupByElderId")
    @Operation(summary = "根据长者Id查询护理分组护理人员")
    public CommonResult<List<AdminUserDO>> getNurseGroupByElderId(@RequestParam("elderId") Long elderId){
        return success(nurseGroupService.getNurseGroupByElderId(elderId));
    }

//
//    @GetMapping("/page")
//    @Operation(summary = "获得护理分组分页")
//    @PreAuthorize("@ss.hasPermission('nurse:group:query')")
//    public CommonResult<PageResult<GroupRespVO>> getGroupPage(@Valid GroupPageReqVO pageReqVO) {
//        PageResult<GroupDO> pageResult = groupService.getGroupPage(pageReqVO);
//        return success(BeanUtils.toBean(pageResult, GroupRespVO.class));
//    }
//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出护理分组 Excel")
//    @PreAuthorize("@ss.hasPermission('nurse:group:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportGroupExcel(@Valid GroupPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<GroupDO> list = groupService.getGroupPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "护理分组.xls", "数据", GroupRespVO.class,
//                        BeanUtils.toBean(list, GroupRespVO.class));
//    }

}