package com.fjhx.feign;

import com.fjhx.constants.ClientConstant;
import com.fjhx.params.ExampleResult;
import com.fjhx.params.JumpVo;
import org.springblade.core.tool.api.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * File Feign接口类
 */
@FeignClient(value = "service-flow")
public interface IFlowClient {

    String CREATE = ClientConstant.API_PREFIX + "/create";
    String GET_JUMP_VO = ClientConstant.API_PREFIX + "/getJumpVO";
    String JUMP = ClientConstant.API_PREFIX + "/jump";
    String ROLL_BACK = ClientConstant.API_PREFIX + "/rollBack";
    String WITHDRAW = ClientConstant.API_PREFIX + "/withdraw";
    String REVOKE = ClientConstant.API_PREFIX + "/revoke";
    String DELETE_BY_EXAMPLE_INFO_ID = ClientConstant.API_PREFIX + "/deleteByExampleInfoId";
    String GET_BUTTON_ID_BY_EXAMPLE_INFO_ID = ClientConstant.API_PREFIX + "/getButtonIdByExampleInfoId";

    /**
     * 创建流程
     *
     * @param flowLinkNo 绑定流程编号
     * @param code       流程编码
     * @param remarks    发起原因/处理意见
     * @param cacheData  缓存数据
     */
    @GetMapping(CREATE)
    R<ExampleResult> create(@RequestParam(value = "flowLinkNo", required = false) Long flowLinkNo,
                            @RequestParam(value = "code", required = false) String code,
                            @RequestParam(value = "nodeCode", required = false) String nodeCode,
                            @RequestParam(value = "title", required = false) String title,
                            @RequestParam(value = "remarks", required = false) String remarks,
                            @RequestParam(value = "cacheData", required = false) String cacheData);

    /**
     * 获取跳转参数
     *
     * @param buttonId 按钮id
     * @param nodeCode 节点编码
     * @return 按钮对象
     */
    @GetMapping(GET_JUMP_VO)
    R<JumpVo> getJumpVo(@RequestParam(value = "buttonId", required = false) Long buttonId,
                        @RequestParam(value = "nodeCode", required = false) String nodeCode);

    /**
     * 流程跳转
     */
    @PostMapping(JUMP)
    R<ExampleResult> jump(@RequestBody JumpVo jumpVo);

    /**
     * 异常回滚
     */
    @PostMapping(ROLL_BACK)
    void rollBack(@RequestBody ExampleResult result);

    /**
     * 撤回
     */
    @PostMapping(WITHDRAW)
    R withdraw(@RequestParam(value = "withdrawExampleInfoId", required = false) Long withdrawExampleInfoId,
               @RequestParam(value = "withdrawExampleDetailsId", required = false) Long withdrawExampleDetailsId);

    /**
     * 撤销
     */
    @PostMapping(REVOKE)
    R revoke(@RequestParam(value = "revokeExampleInfoId", required = false) Long revokeExampleInfoId);

    /**
     * 根据流程实例ID删除流程（伪删除）
     *
     * @param exampleInfoId 流程实例ID
     * @return
     */
    @PostMapping(DELETE_BY_EXAMPLE_INFO_ID)
    Boolean deleteByExampleInfoId(@RequestParam("exampleInfoId") Long exampleInfoId);

    /**
     * 获取当前节点对应的按钮ID
     *
     * @param exampleInfoId 流程实例ID
     * @return
     */
    @PostMapping(GET_BUTTON_ID_BY_EXAMPLE_INFO_ID)
    Long getButtonIdByExampleInfoId(@RequestParam("exampleInfoId") Long exampleInfoId);
}
