package com.spot.enums;

/**
 * 账户流水状态枚举
 *
 * @author jean
 * @date 2026-05-06
 */
public enum AccountRecordStatus {

    /**
     * 1 - 已完成
     */
    COMPLETED(1, "已完成"),

    /**
     * 2 - 待对账
     */
    PENDING_RECONCILE(2, "待对账");

    /** 状态码（数据库存储值） */
    private final Integer code;

    /** 状态描述（中文） */
    private final String description;

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

    public Integer getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据状态码获取枚举
     *
     * @param code 状态码
     * @return 枚举值
     */
    public static AccountRecordStatus fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (AccountRecordStatus status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("未知的账户流水状态码: " + code);
    }

    @Override
    public String toString() {
        return String.format("%s(%d)", description, code);
    }
}
