package org.bdware.sc.bean;

import java.io.Serializable;

public enum ContractExecType implements Serializable {
    Sole, // 单点锚定合约
    RequestOnce, // 多点不同步合约
    ResponseOnce, // 多点不同步合约，超时的时候再请求一个, 直到获得一个response
    RequestAllResponseFirst,
    RequestAllResponseHalf,
    RequestAllResponseAll,
    Shading;//分片执行模式

    public static boolean needSeq(ContractExecType ct) {
        boolean res = true;
        switch (ct) {
            case Sole:
            case RequestOnce:
            case ResponseOnce:
                res = false;
                break;
            case RequestAllResponseAll:
            case RequestAllResponseFirst:
            case RequestAllResponseHalf:
            case Shading:
            default:
                break;
        }
        return res;
    }

    public static ContractExecType getContractTypeByInt(int i) {
        switch (i) {
            case 1:
                return RequestOnce;
            case 2:
                return ResponseOnce;
            case 3:
                return RequestAllResponseFirst;
            case 4:
                return RequestAllResponseHalf;
            case 5:
                return RequestAllResponseAll;
            case 6:
                return Shading;
            default:
                return Sole;
        }
    }

    public boolean needSeq() {
        boolean res = true;
        switch (this) {
            case Sole:
            case RequestOnce:
            case ResponseOnce:
                res = false;
                break;
            case RequestAllResponseAll:
            case RequestAllResponseFirst:
            case RequestAllResponseHalf:
            case Shading:
            default:
                break;
        }
        return res;
    }
}
