package com.yc.ship.module.trade.enums;

import com.yc.ship.framework.common.core.IntArrayValuable;
import lombok.Getter;

import java.util.Arrays;


@Getter
public enum ContractStatusEnum implements IntArrayValuable {

    SIGNING(0, "签订中"),
    SIGNED(1, "已签订"),
    CANCELLING(2, "作废中"),
    CANCELED(3, "已作废"),

    FAIL(4, "签署失败");

    private final String name;
    private final Integer value;
    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ContractStatusEnum::getValue).toArray();

    @Override
    public int[] array() {
        return ARRAYS;
    }

    ContractStatusEnum(Integer status, String name) {
        this.value = status;
        this.name = name;
    }

    public static ContractStatusEnum callBackStateTransform(Integer state) {
        if (state == null){
            return SIGNING;
        }
        switch (state) {
            case 1:
            case 4:{
                return SIGNING;
            }
            case 2:{
                return SIGNED;
            }
            case 3:{
                return CANCELED;
            }
            case 5:{
                return CANCELLING;
            }

            default: return SIGNING;
        }
    }

    public static ContractStatusEnum queryStateTransform(Integer state) {
        if (state == null){
            return SIGNING;
        }
        switch (state) {
            case 1:
            case 2:
            case 6:
            case 9:
            case 10:{
                return SIGNING;
            }
            case 3:{
                return SIGNED;
            }
            case 5:
            case 8:{
                return CANCELED;
            }
            case 4:
            case 11:{
                return CANCELLING;
            }

            default: return SIGNING;
        }
    }
}