package com.haha.common.enums;

import lombok.Getter;

@Getter
public enum PayScoreState {

    CREATED("CREATED", "已创建"),
    DOING("DOING", "进行中"),
    USER_PAYING("USER_PAYING", "用户支付中"),
    DONE("DONE", "已完成"),
    REVOKED("REVOKED", "已取消"),
    EXPIRED("EXPIRED", "已过期");

    private final String code;
    private final String description;

    PayScoreState(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public static PayScoreState fromCode(String code) {
        if (code == null) {
            return null;
        }
        for (PayScoreState state : values()) {
            if (state.code.equals(code)) {
                return state;
            }
        }
        return null;
    }

    public static boolean isFinished(String code) {
        return DONE.code.equals(code) || REVOKED.code.equals(code) || EXPIRED.code.equals(code);
    }

    public static boolean isPaying(String code) {
        return USER_PAYING.code.equals(code);
    }

    public static boolean isDone(String code) {
        return DONE.code.equals(code);
    }

    public static boolean isRevoked(String code) {
        return REVOKED.code.equals(code);
    }

    public static boolean isExpired(String code) {
        return EXPIRED.code.equals(code);
    }
}
