package cn.axzo.workflow.starter;

import cn.axzo.workflow.common.annotation.InvokeMode;
import cn.axzo.workflow.common.enums.RpcInvokeModeEnum;
import cn.axzo.workflow.starter.api.WorkflowCoreService;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import static cn.axzo.workflow.common.enums.RpcInvokeModeEnum.ASYNC;

/**
 * Workflow Engine Starter Properties
 * <p>
 * 全量参数参考：META-INF/application.yaml.demo
 *
 * @author wangli
 * @since 2024/5/21 15:24
 */
@ConfigurationProperties(prefix = "workflow.engine.starter")
public class WorkflowEngineStarterProperties {
    /**
     * 是否可管理
     */
    private Boolean manageable = false;

    /**
     * <h3>该参数只针对<strong color=orange>非</strong>容器环境生效</h3>
     * 本地启动时,是否将本地的 MQ 消费者加入集群消费组
     * <pre>
     * 默认 false, 本地启动应用时, 将创建消息组名称中含有"debugging"的消费组.
     * 否则, 本地启动应用时, 消费者将加入容器环境, 进行集群消费.
     * </pre>
     */
    private Boolean joinContainerGroup = false;

    /**
     * WorkflowCoreService 类中所有方法未标记{@link InvokeMode}注解的方法调用时, 默认采用的模式
     *
     * <pre>
     * 如果是同步调用，则直接通过普通 FeignClient 进行调用,
     * 否则将通过 MQ 将 RPC 调用进行解耦
     * </pre>
     * <p>
     * 如果方法上有{@link InvokeMode}注解, 则以注解上的模式优先, 如果还想覆盖注解中的模式,
     * 则可以通过 {@link WorkflowCoreService#sync()}或{@link WorkflowCoreService#async()}方法进行覆盖
     */
    private RpcInvokeModeEnum invokeMode = ASYNC;

    /**
     * 监听流程引擎广播的处理器，异常后的重试相关策略及配置
     */
    @NestedConfigurationProperty
    private BroadcastListenerConfigurationProperties broadcast = new BroadcastListenerConfigurationProperties();

    public Boolean getManageable() {
        return manageable;
    }

    public void setManageable(Boolean manageable) {
        this.manageable = manageable;
    }

    public Boolean getJoinContainerGroup() {
        return joinContainerGroup;
    }

    public void setJoinContainerGroup(Boolean joinContainerGroup) {
        this.joinContainerGroup = joinContainerGroup;
    }

    public RpcInvokeModeEnum getInvokeMode() {
        return invokeMode;
    }

    public void setInvokeMode(RpcInvokeModeEnum invokeMode) {
        this.invokeMode = invokeMode;
    }

    public BroadcastListenerConfigurationProperties getBroadcast() {
        return broadcast;
    }

    public void setBroadcast(BroadcastListenerConfigurationProperties broadcast) {
        this.broadcast = broadcast;
    }
}
