package cn.edu.ecnu.stu.bookstore.pojo;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
public enum OrderStatus implements AbstractOrderStatus{
    WAIT_PAYMENT(0),
    WAIT_SEND(1),
    WAIT_RECEIVE(2),
    COMPLETED(3),
    CANCEL(4);

    private int value;

    public void setValue(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    @Override
    public void nextOrder() {
        if(value == CANCEL.value)
            return;
        value += 1;
    }

    @Override
    public void cancelOrder() {
        value = CANCEL.value;
    }

    public static OrderStatus getByValue(int val) {
        for(OrderStatus status : values()) {
            if(status.value == val)
                return status;
        }
        return null;
    }
}

interface AbstractOrderStatus {


    void nextOrder();

    void cancelOrder();


}
