package cn.iocoder.yudao.module.bpm.controller.admin.business;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.bpm.controller.admin.business.vo.*;
import cn.iocoder.yudao.module.system.api.bpm.vo.CheckInCreateReqVO;
import cn.iocoder.yudao.module.system.api.bpm.vo.ElderlyChangeRecordReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;
import cn.iocoder.yudao.module.bpm.service.business.BpmElderlApplyService;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;


/**
 * @Author: jinyd
 * @CreateTime: 2024/8/6  9:44
 * @Description: 长着业务表单
 * @Version: 4.0
 */
@Tag(name = "管理后台 - 业务表单审批流程")
@RestController
@RequestMapping("/bpm/elderly")
@Validated
public class BpmElderlyController {

    @Resource
    private BpmElderlApplyService elderlApplyService;

    @PostMapping("/create")
    @PreAuthorize("@ss.hasAnyPermissions('check-in-request:add', 'check-in-request:edit', 'check-in-request:relaunch_t')")
    @Operation(summary = "创建请求申请")
    @TenantIgnore
    public CommonResult<Long> createLeave(@Valid @RequestBody BpmApplyAccommodationCreateReqVO createReqVO) {
        createReqVO.setTenantId(createReqVO.getTenantId() == null ? TenantContextHolder.getTenantId() : createReqVO.getTenantId());
        return success(elderlApplyService.createApplyAccommodation(getLoginUserId(),
                SecurityFrameworkUtils.getLoginUserNickname(), createReqVO));
    }

    @PostMapping("/retreatCreate")
    @PreAuthorize("@ss.hasAnyPermissions('check-out:add', 'check-out:relaunch')")
    @Operation(summary = "创建退住请求申请")
    @TenantIgnore
    public CommonResult<Long> retreatCreate(@Valid @RequestBody BpmApplyRetreatCreateReqVO createReqVO) {
        return success(elderlApplyService.createApplyRetreat(getLoginUserId(), createReqVO));
    }

    @PostMapping("/bedChangeCreate")
    @PreAuthorize("@ss.hasAnyPermissions('bed-change:add', 'bed-change:relaunch')")
    @Operation(summary = "创建床位变更")
    @TenantIgnore
    public CommonResult<Long> bedChangeCreate(@Valid @RequestBody BedChangeRecordCreateReqVO createReqVO) {
        return success(elderlApplyService.bedChangeCreate(getLoginUserId(), createReqVO));
    }

    @PostMapping("/nurseChangeCreate")
    @PreAuthorize("@ss.hasAnyPermissions('nurse-change:add', 'nurse-change:relaunch')")
    @Operation(summary = "创建护理变更")
    @TenantIgnore
    public CommonResult<Long> nurseChangeCreate(@Valid @RequestBody NurseChangeRecordCreateReqVO createReqVO) {
        return success(elderlApplyService.nurseChangeCreate(getLoginUserId(), createReqVO));
    }

    @PostMapping("/cateringChangeCreate")
    @PreAuthorize("@ss.hasAnyPermissions('changes:food:add', 'changes:food:relaunch')")
    @Operation(summary = "创建餐饮变更")
    @TenantIgnore
    public CommonResult<Long> cateringChangeCreate(@Valid @RequestBody CateringChangeRecordCreateReqVO createReqVO) {
        return success(elderlApplyService.cateringChangeCreate(getLoginUserId(), createReqVO));
    }

    @PostMapping("/priceChangeCreate")
    @PreAuthorize("@ss.hasAnyPermissions('price-change:add', 'price-change:relaunch')")
    @Operation(summary = "创建价格变更")
    @TenantIgnore
    public CommonResult<Long> priceChangeCreate(@Valid @RequestBody PriceChangeRecordCreateReqVO createReqVO) {
        return success(elderlApplyService.priceChangeCreate(getLoginUserId(), createReqVO));
    }

    @PostMapping("/transferChangeCreate")
    @PreAuthorize("@ss.hasAnyPermissions('changes:hospital:add', 'changes:hospital:relaunch')")
    @Operation(summary = "创建转院变更")
    @TenantIgnore
    public CommonResult<Long> transferChangeCreate(@Valid @RequestBody TransferChangeRecordCreateReqVO createReqVO) {
        return success(elderlApplyService.transferChangeCreate(getLoginUserId(), createReqVO));
    }

    @PostMapping("/checkInCreate")
//    @PreAuthorize("@ss.hasAnyPermissions('check-in:check', 'check-in:relaunch_t')")
    @Operation(summary = "创建办理入住")
    @TenantIgnore
    @PermitAll
    public CommonResult<Long> checkInCreate(@Valid @RequestBody CheckInCreateReqVO createReqVO) {
        return success(elderlApplyService.checkInCreate(getLoginUserId(), createReqVO));
    }


}
