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.NursingShiftPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.nursing.vo.NursingShiftSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.NursingShiftDO;
import cn.iocoder.yudao.module.system.service.nursing.NursingShiftService;
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 java.util.Objects;

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


@Tag(name = "管理后台 - 护理班次")
@RestController
@RequestMapping("/nursing/nursingShift")
@Validated
public class NursingShiftController {

    @Resource
    private NursingShiftService nursingShiftService;


    @PostMapping("/create")
    @Operation(summary = "创建护理班次")
    @TenantIgnore
    public CommonResult<Boolean> createShift(@Valid @RequestBody NursingShiftSaveReqVO createReqVO) {
        createReqVO.setTenantId(createReqVO.getTenantId() == null ? TenantContextHolder.getTenantId() : createReqVO.getTenantId());
        nursingShiftService.createShift(createReqVO);
        return success(true);
    }

    @PutMapping("/update")
    @Operation(summary = "更新护理班次")
    public CommonResult<Boolean> updateShift(@Valid @RequestBody NursingShiftDO updateReqVO) {
        nursingShiftService.updateShift(updateReqVO);
        return success(true);
    }

    @PostMapping("/delete")
    @Operation(summary = "删除护理班次")
    public CommonResult<Boolean> deleteShift(@RequestBody Long[] ids) {
        nursingShiftService.deleteShift(ids);
        return success(true);
    }

    @GetMapping("/getNursingShift")
    @Operation(summary = "获得护理班次详情")
    @Parameter(name = "id", description = "班次记录ID", required = true, example = "1024")
    public CommonResult<NursingShiftDO> getNursingShift(@RequestParam("id") Long id) {
        return success(nursingShiftService.getNursingShift(id));
    }

    @GetMapping("/getNursingShiftPage")
    @Operation(summary = "获得护理班次分页")
    @TenantIgnore
    public CommonResult<PageResult<NursingShiftDO>> getNursingShiftPage(@Valid NursingShiftPageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<NursingShiftDO> pageResult = nursingShiftService.getNursingShiftPage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/getList")
    @Operation(summary = "查询班次列表")
    public CommonResult<List<NursingShiftDO>> getList() {
        return success(nursingShiftService.getList());
    }


}