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.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.BedPlanRecordEffectiveQueryReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.BedPlanRecordEffectiveRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.BedPlanRecordPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.BedPlanRecordRespVO;
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.BedPlanRecordSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.BedPlanRecordDO;
import cn.iocoder.yudao.module.system.service.biz.BedPlanRecordService;
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.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("/bed-plan-record")
@Validated
public class BedPlanRecordController {

    @Resource
    private BedPlanRecordService bedPlanRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建床位计划记录")
    public CommonResult<Integer> create(@Valid @RequestBody BedPlanRecordSaveReqVO createReqVO) {
        createReqVO.setTenantId(Objects.isNull(createReqVO.getTenantId())
                ? TenantContextHolder.getTenantId() : createReqVO.getTenantId());
        return success(bedPlanRecordService.createBedPlanRecord(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新床位计划记录")
    public CommonResult<Boolean> update(@Valid @RequestBody BedPlanRecordSaveReqVO updateReqVO) {
        updateReqVO.setTenantId(Objects.isNull(updateReqVO.getTenantId())
                ? TenantContextHolder.getTenantId() : updateReqVO.getTenantId());
        bedPlanRecordService.updateBedPlanRecord(updateReqVO);
        return success(Boolean.TRUE);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除床位计划记录")
    @Parameter(name = "id", description = "记录编号", required = true)
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        bedPlanRecordService.deleteBedPlanRecord(id);
        return success(Boolean.TRUE);
    }

    @GetMapping("/get")
    @Operation(summary = "获得床位计划记录")
    @Parameter(name = "id", description = "记录编号", required = true, example = "1024")
    public CommonResult<BedPlanRecordRespVO> get(@RequestParam("id") Long id) {
        BedPlanRecordDO record = bedPlanRecordService.getBedPlanRecord(id);
        return success(BeanUtils.toBean(record, BedPlanRecordRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得床位计划记录分页")
    public CommonResult<PageResult<BedPlanRecordRespVO>> getPage(@Valid BedPlanRecordPageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds())
                ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<BedPlanRecordDO> pageResult = bedPlanRecordService.getBedPlanRecordPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, BedPlanRecordRespVO.class));
    }

    @GetMapping("/effective-list")
    @Operation(summary = "查询生效期内床位计划记录")
    public CommonResult<List<BedPlanRecordEffectiveRespVO>> getEffectiveList(@Valid BedPlanRecordEffectiveQueryReqVO reqVO) {
        reqVO.setTenantIds(Objects.isNull(reqVO.getTenantIds())
                ? new Long[]{TenantContextHolder.getTenantId()} : reqVO.getTenantIds());
        List<BedPlanRecordEffectiveRespVO> list = bedPlanRecordService.getEffectiveList(reqVO);
        return success(list);
    }
}


