namespace JiShe.CollectBus.Kafka.Internal;

public class SubscribeResult : ISubscribeAck
{
    /// <summary>
    ///     是否成功
    /// </summary>
    public bool Ack { get; set; }

    /// <summary>
    ///     消息
    /// </summary>
    public string? Msg { get; set; }


    /// <summary>
    ///     成功
    /// </summary>
    /// <param name="msg">消息</param>
    public SubscribeResult Success(string? msg = null)
    {
        Ack = true;
        Msg = msg;
        return this;
    }

    /// <summary>
    /// 失败
    /// </summary>
    /// <param name="msg"></param>
    /// <returns></returns>
    public SubscribeResult Fail(string? msg = null)
    {
        Msg = msg;
        Ack = false;
        return this;
    }
}

public static class SubscribeAck
{
    /// <summary>
    ///     成功
    /// </summary>
    /// <param name="msg">消息</param>
    /// <returns></returns>
    public static ISubscribeAck Success(string? msg = null)
    {
        return new SubscribeResult().Success(msg);
    }


    /// <summary>
    ///     失败
    /// </summary>
    /// <param name="msg">消息</param>
    /// <returns></returns>
    public static ISubscribeAck Fail(string? msg = null)
    {
        return new SubscribeResult().Fail(msg);
    }
}