package com.ff.base.enums;


import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * fypay支付状态
 *
 * @author liukang
 * @date 2024/10/22
 */
@Getter
@AllArgsConstructor
public enum FyPayStatus {

    PROCESSING(0, "PROCESSING", "待支付"),
    SUCCESS(1, "SUCCESS", "支付成功"),
    FAIL(2, "FAIL", "支付失败"),
    TIMEOUT(2, "TIMEOUT", "超时关闭"),
    EXCEPTION(2, "EXCEPTION", "发起支付异常"),
    CLOSE(2, "CLOSE", "手动关闭");

    private final Integer status;
    private final String code;
    private final String info;

    /**
     * 按code查找状态
     *
     * @param code 代码
     * @return {@link String }
     */
    public static Integer findStatusByCode(String code) {
        Optional<Integer> system = Stream.of(FyPayStatus.values())
                .filter(fyPayStatus -> fyPayStatus.getCode().equals(code))
                .map(FyPayStatus::getStatus)
                .findFirst();
        return system.orElse(null);
    }
}
