namespace ZB.MOM.NatsNet.Server;

public sealed partial class NatsServer
{
    internal (StreamConfig Config, Exception? Error) CheckStreamCfg(StreamConfig config, Account? account, bool pedantic)
    {
        _ = account;
        _ = pedantic;

        if (config == null)
            return (new StreamConfig(), new ArgumentNullException(nameof(config)));

        var normalized = config.Clone();
        if (string.IsNullOrWhiteSpace(normalized.Name))
            return (normalized, new InvalidOperationException("stream name required"));

        if (normalized.Subjects == null || normalized.Subjects.Length == 0)
            normalized.Subjects = [$"{normalized.Name}.>"];

        if (normalized.MaxMsgSize < 0)
            return (normalized, new InvalidOperationException("max message size must be >= 0"));

        return (normalized, null);
    }
}
