// Copyright 2020-2026 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");

using Shouldly;

namespace ZB.MOM.NatsNet.Server.Tests.JetStream;

public sealed class JetStreamErrorsGeneratedConstructorsTests
{
    [Fact]
    public void ConstructorSurface_Group01()
    {
        JsApiErrors.NewJSAccountResourcesExceededError().ErrCode.ShouldBe(JsApiErrors.AccountResourcesExceeded.ErrCode);
        JsApiErrors.NewJSAtomicPublishContainsDuplicateMessageError().ErrCode.ShouldBe(JsApiErrors.AtomicPublishContainsDuplicateMessage.ErrCode);
        JsApiErrors.NewJSAtomicPublishDisabledError().ErrCode.ShouldBe(JsApiErrors.AtomicPublishDisabled.ErrCode);
        JsApiErrors.NewJSAtomicPublishIncompleteBatchError().ErrCode.ShouldBe(JsApiErrors.AtomicPublishIncompleteBatch.ErrCode);
        JsApiErrors.NewJSAtomicPublishInvalidBatchCommitError().ErrCode.ShouldBe(JsApiErrors.AtomicPublishInvalidBatchCommit.ErrCode);
        JsApiErrors.NewJSAtomicPublishInvalidBatchIDError().ErrCode.ShouldBe(JsApiErrors.AtomicPublishInvalidBatchID.ErrCode);
        JsApiErrors.NewJSAtomicPublishMissingSeqError().ErrCode.ShouldBe(JsApiErrors.AtomicPublishMissingSeq.ErrCode);
        JsApiErrors.NewJSBadRequestError().ErrCode.ShouldBe(JsApiErrors.BadRequest.ErrCode);
        JsApiErrors.NewJSClusterIncompleteError().ErrCode.ShouldBe(JsApiErrors.ClusterIncomplete.ErrCode);
        JsApiErrors.NewJSClusterNotActiveError().ErrCode.ShouldBe(JsApiErrors.ClusterNotActive.ErrCode);
        JsApiErrors.NewJSClusterNotAssignedError().ErrCode.ShouldBe(JsApiErrors.ClusterNotAssigned.ErrCode);
        JsApiErrors.NewJSClusterNotAvailError().ErrCode.ShouldBe(JsApiErrors.ClusterNotAvail.ErrCode);
        JsApiErrors.NewJSClusterNotLeaderError().ErrCode.ShouldBe(JsApiErrors.ClusterNotLeader.ErrCode);
        JsApiErrors.NewJSClusterPeerNotMemberError().ErrCode.ShouldBe(JsApiErrors.ClusterPeerNotMember.ErrCode);

        JsApiErrors.NewJSAtomicPublishTooLargeBatchError(512).Description.ShouldBe("atomic publish batch is too large: 512");
        JsApiErrors.NewJSAtomicPublishUnsupportedHeaderBatchError("Nats-Msg-Id").Description.ShouldBe("atomic publish unsupported header used: Nats-Msg-Id");
        JsApiErrors.NewJSClusterNoPeersError(new InvalidOperationException("no peers")).Description.ShouldBe("no peers");

        var expected = new JsApiError { Code = 499, ErrCode = 9090, Description = "override" };
        var fromOverride = JsApiErrors.NewJSAccountResourcesExceededError(JsApiErrors.Unless(expected));
        fromOverride.Code.ShouldBe(expected.Code);
        fromOverride.ErrCode.ShouldBe(expected.ErrCode);
        fromOverride.Description.ShouldBe(expected.Description);
        ReferenceEquals(fromOverride, expected).ShouldBeFalse();
    }

    [Fact]
    public void ConstructorSurface_Group02()
    {
        JsApiErrors.NewJSClusterRequiredError().ErrCode.ShouldBe(JsApiErrors.ClusterRequired.ErrCode);
        JsApiErrors.NewJSClusterServerMemberChangeInflightError().ErrCode.ShouldBe(JsApiErrors.ClusterServerMemberChangeInflight.ErrCode);
        JsApiErrors.NewJSClusterServerNotMemberError().ErrCode.ShouldBe(JsApiErrors.ClusterServerNotMember.ErrCode);
        JsApiErrors.NewJSClusterTagsError().ErrCode.ShouldBe(JsApiErrors.ClusterTags.ErrCode);
        JsApiErrors.NewJSClusterUnSupportFeatureError().ErrCode.ShouldBe(JsApiErrors.ClusterUnSupportFeature.ErrCode);
        JsApiErrors.NewJSConsumerAckPolicyInvalidError().ErrCode.ShouldBe(JsApiErrors.ConsumerAckPolicyInvalid.ErrCode);
        JsApiErrors.NewJSConsumerAckWaitNegativeError().ErrCode.ShouldBe(JsApiErrors.ConsumerAckWaitNegative.ErrCode);
        JsApiErrors.NewJSConsumerAlreadyExistsError().ErrCode.ShouldBe(JsApiErrors.ConsumerAlreadyExists.ErrCode);
        JsApiErrors.NewJSConsumerBackOffNegativeError().ErrCode.ShouldBe(JsApiErrors.ConsumerBackOffNegative.ErrCode);
        JsApiErrors.NewJSConsumerBadDurableNameError().ErrCode.ShouldBe(JsApiErrors.ConsumerBadDurableName.ErrCode);
        JsApiErrors.NewJSConsumerConfigRequiredError().ErrCode.ShouldBe(JsApiErrors.ConsumerConfigRequired.ErrCode);
        JsApiErrors.NewJSConsumerCreateDurableAndNameMismatchError().ErrCode.ShouldBe(JsApiErrors.ConsumerCreateDurableAndNameMismatch.ErrCode);
        JsApiErrors.NewJSConsumerCreateFilterSubjectMismatchError().ErrCode.ShouldBe(JsApiErrors.ConsumerCreateFilterSubjectMismatch.ErrCode);
        JsApiErrors.NewJSConsumerDeliverCycleError().ErrCode.ShouldBe(JsApiErrors.ConsumerDeliverCycle.ErrCode);
        JsApiErrors.NewJSConsumerDeliverToWildcardsError().ErrCode.ShouldBe(JsApiErrors.ConsumerDeliverToWildcards.ErrCode);
        JsApiErrors.NewJSConsumerDirectRequiresEphemeralError().ErrCode.ShouldBe(JsApiErrors.ConsumerDirectRequiresEphemeral.ErrCode);
        JsApiErrors.NewJSConsumerDirectRequiresPushError().ErrCode.ShouldBe(JsApiErrors.ConsumerDirectRequiresPush.ErrCode);
        JsApiErrors.NewJSConsumerDoesNotExistError().ErrCode.ShouldBe(JsApiErrors.ConsumerDoesNotExist.ErrCode);

        JsApiErrors.NewJSConsumerCreateError(new InvalidOperationException("create failed")).Description.ShouldBe("create failed");
        JsApiErrors.NewJSConsumerDescriptionTooLongError(1024).Description.ShouldBe("consumer description is too long, maximum allowed is 1024");

        var expected = new JsApiError { Code = 498, ErrCode = 9091, Description = "override-2" };
        var fromOverride = JsApiErrors.NewJSClusterRequiredError(JsApiErrors.Unless(expected));
        fromOverride.Code.ShouldBe(expected.Code);
        fromOverride.ErrCode.ShouldBe(expected.ErrCode);
        fromOverride.Description.ShouldBe(expected.Description);
        ReferenceEquals(fromOverride, expected).ShouldBeFalse();
    }

    [Fact]
    public void ConstructorSurface_Group03()
    {
        JsApiErrors.NewJSConsumerDuplicateFilterSubjectsError().ErrCode.ShouldBe(JsApiErrors.ConsumerDuplicateFilterSubjects.ErrCode);
        JsApiErrors.NewJSConsumerDurableNameNotInSubjectError().ErrCode.ShouldBe(JsApiErrors.ConsumerDurableNameNotInSubject.ErrCode);
        JsApiErrors.NewJSConsumerDurableNameNotMatchSubjectError().ErrCode.ShouldBe(JsApiErrors.ConsumerDurableNameNotMatchSubject.ErrCode);
        JsApiErrors.NewJSConsumerDurableNameNotSetError().ErrCode.ShouldBe(JsApiErrors.ConsumerDurableNameNotSet.ErrCode);
        JsApiErrors.NewJSConsumerEmptyFilterError().ErrCode.ShouldBe(JsApiErrors.ConsumerEmptyFilter.ErrCode);
        JsApiErrors.NewJSConsumerEmptyGroupNameError().ErrCode.ShouldBe(JsApiErrors.ConsumerEmptyGroupName.ErrCode);
        JsApiErrors.NewJSConsumerEphemeralWithDurableInSubjectError().ErrCode.ShouldBe(JsApiErrors.ConsumerEphemeralWithDurableInSubject.ErrCode);
        JsApiErrors.NewJSConsumerEphemeralWithDurableNameError().ErrCode.ShouldBe(JsApiErrors.ConsumerEphemeralWithDurableName.ErrCode);
        JsApiErrors.NewJSConsumerExistingActiveError().ErrCode.ShouldBe(JsApiErrors.ConsumerExistingActive.ErrCode);
        JsApiErrors.NewJSConsumerFCRequiresPushError().ErrCode.ShouldBe(JsApiErrors.ConsumerFCRequiresPush.ErrCode);
        JsApiErrors.NewJSConsumerFilterNotSubsetError().ErrCode.ShouldBe(JsApiErrors.ConsumerFilterNotSubset.ErrCode);
        JsApiErrors.NewJSConsumerHBRequiresPushError().ErrCode.ShouldBe(JsApiErrors.ConsumerHBRequiresPush.ErrCode);
        JsApiErrors.NewJSConsumerInvalidDeliverSubjectError().ErrCode.ShouldBe(JsApiErrors.ConsumerInvalidDeliverSubject.ErrCode);
        JsApiErrors.NewJSConsumerInvalidGroupNameError().ErrCode.ShouldBe(JsApiErrors.ConsumerInvalidGroupName.ErrCode);
        JsApiErrors.NewJSConsumerInvalidPriorityGroupError().ErrCode.ShouldBe(JsApiErrors.ConsumerInvalidPriorityGroup.ErrCode);
        JsApiErrors.NewJSConsumerMaxDeliverBackoffError().ErrCode.ShouldBe(JsApiErrors.ConsumerMaxDeliverBackoff.ErrCode);

        JsApiErrors.NewJSConsumerInactiveThresholdExcessError(777).Description.ShouldBe("consumer inactive threshold exceeds system limit of 777");
        JsApiErrors.NewJSConsumerInvalidPolicyError(new InvalidOperationException("invalid policy")).Description.ShouldBe("invalid policy");
        JsApiErrors.NewJSConsumerInvalidResetError(new InvalidOperationException("bad reset")).Description.ShouldBe("invalid reset: bad reset");
        JsApiErrors.NewJSConsumerInvalidSamplingError(new InvalidOperationException("bad sampling")).Description.ShouldBe("failed to parse consumer sampling configuration: bad sampling");

        var expected = new JsApiError { Code = 497, ErrCode = 9092, Description = "override-3" };
        var fromOverride = JsApiErrors.NewJSConsumerDuplicateFilterSubjectsError(JsApiErrors.Unless(expected));
        fromOverride.Code.ShouldBe(expected.Code);
        fromOverride.ErrCode.ShouldBe(expected.ErrCode);
        fromOverride.Description.ShouldBe(expected.Description);
        ReferenceEquals(fromOverride, expected).ShouldBeFalse();
    }

    [Fact]
    public void ConstructorSurface_Group04()
    {
        JsApiErrors.NewJSConsumerMaxPendingAckPolicyRequiredError().ErrCode.ShouldBe(JsApiErrors.ConsumerMaxPendingAckPolicyRequired.ErrCode);
        JsApiErrors.NewJSConsumerMaxRequestBatchNegativeError().ErrCode.ShouldBe(JsApiErrors.ConsumerMaxRequestBatchNegative.ErrCode);
        JsApiErrors.NewJSConsumerMaxRequestExpiresTooSmallError().ErrCode.ShouldBe(JsApiErrors.ConsumerMaxRequestExpiresTooSmall.ErrCode);
        JsApiErrors.NewJSConsumerMaxWaitingNegativeError().ErrCode.ShouldBe(JsApiErrors.ConsumerMaxWaitingNegative.ErrCode);
        JsApiErrors.NewJSConsumerMultipleFiltersNotAllowedError().ErrCode.ShouldBe(JsApiErrors.ConsumerMultipleFiltersNotAllowed.ErrCode);
        JsApiErrors.NewJSConsumerNameContainsPathSeparatorsError().ErrCode.ShouldBe(JsApiErrors.ConsumerNameContainsPathSeparators.ErrCode);
        JsApiErrors.NewJSConsumerNameExistError().ErrCode.ShouldBe(JsApiErrors.ConsumerNameExist.ErrCode);
        JsApiErrors.NewJSConsumerNotFoundError().ErrCode.ShouldBe(JsApiErrors.ConsumerNotFound.ErrCode);
        JsApiErrors.NewJSConsumerOfflineError().ErrCode.ShouldBe(JsApiErrors.ConsumerOffline.ErrCode);
        JsApiErrors.NewJSConsumerOnMappedError().ErrCode.ShouldBe(JsApiErrors.ConsumerOnMapped.ErrCode);
        JsApiErrors.NewJSConsumerOverlappingSubjectFiltersError().ErrCode.ShouldBe(JsApiErrors.ConsumerOverlappingSubjectFilters.ErrCode);
        JsApiErrors.NewJSConsumerPinnedTTLWithoutPriorityPolicyNoneError().ErrCode.ShouldBe(JsApiErrors.ConsumerPinnedTTLWithoutPriorityPolicyNone.ErrCode);
        JsApiErrors.NewJSConsumerPriorityGroupWithPolicyNoneError().ErrCode.ShouldBe(JsApiErrors.ConsumerPriorityGroupWithPolicyNone.ErrCode);
        JsApiErrors.NewJSConsumerPriorityPolicyWithoutGroupError().ErrCode.ShouldBe(JsApiErrors.ConsumerPriorityPolicyWithoutGroup.ErrCode);
        JsApiErrors.NewJSConsumerPullNotDurableError().ErrCode.ShouldBe(JsApiErrors.ConsumerPullNotDurable.ErrCode);

        JsApiErrors.NewJSConsumerMaxPendingAckExcessError(250).Description.ShouldBe("consumer max ack pending exceeds system limit of 250");
        JsApiErrors.NewJSConsumerMaxRequestBatchExceededError(88).Description.ShouldBe("consumer max request batch exceeds server limit of 88");
        JsApiErrors.NewJSConsumerMetadataLengthError(4096).Description.ShouldBe("consumer metadata exceeds maximum size of 4096");
        JsApiErrors.NewJSConsumerNameTooLongError(33).Description.ShouldBe("consumer name is too long, maximum allowed is 33");
        JsApiErrors.NewJSConsumerOfflineReasonError(new InvalidOperationException("storage unavailable")).Description.ShouldBe("consumer is offline: storage unavailable");

        var expected = new JsApiError { Code = 496, ErrCode = 9093, Description = "override-4" };
        var fromOverride = JsApiErrors.NewJSConsumerPullNotDurableError(JsApiErrors.Unless(expected));
        fromOverride.Code.ShouldBe(expected.Code);
        fromOverride.ErrCode.ShouldBe(expected.ErrCode);
        fromOverride.Description.ShouldBe(expected.Description);
        ReferenceEquals(fromOverride, expected).ShouldBeFalse();
    }

    [Fact]
    public void ConstructorSurface_Group05()
    {
        JsApiErrors.NewJSConsumerPullRequiresAckError().ErrCode.ShouldBe(JsApiErrors.ConsumerPullRequiresAck.ErrCode);
        JsApiErrors.NewJSConsumerPullWithRateLimitError().ErrCode.ShouldBe(JsApiErrors.ConsumerPullWithRateLimit.ErrCode);
        JsApiErrors.NewJSConsumerPushMaxWaitingError().ErrCode.ShouldBe(JsApiErrors.ConsumerPushMaxWaiting.ErrCode);
        JsApiErrors.NewJSConsumerPushWithPriorityGroupError().ErrCode.ShouldBe(JsApiErrors.ConsumerPushWithPriorityGroup.ErrCode);
        JsApiErrors.NewJSConsumerReplacementWithDifferentNameError().ErrCode.ShouldBe(JsApiErrors.ConsumerReplacementWithDifferentName.ErrCode);
        JsApiErrors.NewJSConsumerReplayPolicyInvalidError().ErrCode.ShouldBe(JsApiErrors.ConsumerReplayPolicyInvalid.ErrCode);
        JsApiErrors.NewJSConsumerReplicasExceedsStreamError().ErrCode.ShouldBe(JsApiErrors.ConsumerReplicasExceedsStream.ErrCode);
        JsApiErrors.NewJSConsumerReplicasShouldMatchStreamError().ErrCode.ShouldBe(JsApiErrors.ConsumerReplicasShouldMatchStream.ErrCode);
        JsApiErrors.NewJSConsumerSmallHeartbeatError().ErrCode.ShouldBe(JsApiErrors.ConsumerSmallHeartbeat.ErrCode);
        JsApiErrors.NewJSConsumerWQConsumerNotDeliverAllError().ErrCode.ShouldBe(JsApiErrors.ConsumerWQConsumerNotDeliverAll.ErrCode);
        JsApiErrors.NewJSConsumerWQConsumerNotUniqueError().ErrCode.ShouldBe(JsApiErrors.ConsumerWQConsumerNotUnique.ErrCode);
        JsApiErrors.NewJSConsumerWQMultipleUnfilteredError().ErrCode.ShouldBe(JsApiErrors.ConsumerWQMultipleUnfiltered.ErrCode);
        JsApiErrors.NewJSConsumerWQRequiresExplicitAckError().ErrCode.ShouldBe(JsApiErrors.ConsumerWQRequiresExplicitAck.ErrCode);
        JsApiErrors.NewJSConsumerWithFlowControlNeedsHeartbeatsError().ErrCode.ShouldBe(JsApiErrors.ConsumerWithFlowControlNeedsHeartbeats.ErrCode);
        JsApiErrors.NewJSInsufficientResourcesError().ErrCode.ShouldBe(JsApiErrors.InsufficientResources.ErrCode);
        JsApiErrors.NewJSMaximumConsumersLimitError().ErrCode.ShouldBe(JsApiErrors.MaximumConsumersLimit.ErrCode);
        JsApiErrors.NewJSMaximumStreamsLimitError().ErrCode.ShouldBe(JsApiErrors.MaximumStreamsLimit.ErrCode);
        JsApiErrors.NewJSMemoryResourcesExceededError().ErrCode.ShouldBe(JsApiErrors.MemoryResourcesExceeded.ErrCode);

        JsApiErrors.NewJSConsumerStoreFailedError(new InvalidOperationException("store failed")).Description.ShouldBe("error creating store for consumer: store failed");
        JsApiErrors.NewJSInvalidJSONError(new InvalidOperationException("malformed")).Description.ShouldBe("invalid JSON: malformed");

        var expected = new JsApiError { Code = 495, ErrCode = 9094, Description = "override-5" };
        var fromOverride = JsApiErrors.NewJSConsumerPullRequiresAckError(JsApiErrors.Unless(expected));
        fromOverride.Code.ShouldBe(expected.Code);
        fromOverride.ErrCode.ShouldBe(expected.ErrCode);
        fromOverride.Description.ShouldBe(expected.Description);
        ReferenceEquals(fromOverride, expected).ShouldBeFalse();
    }

    [Fact]
    public void ConstructorSurface_Group06()
    {
        JsApiErrors.NewJSMessageCounterBrokenError().ErrCode.ShouldBe(JsApiErrors.MessageCounterBroken.ErrCode);
        JsApiErrors.NewJSMessageIncrDisabledError().ErrCode.ShouldBe(JsApiErrors.MessageIncrDisabled.ErrCode);
        JsApiErrors.NewJSMessageIncrInvalidError().ErrCode.ShouldBe(JsApiErrors.MessageIncrInvalid.ErrCode);
        JsApiErrors.NewJSMessageIncrMissingError().ErrCode.ShouldBe(JsApiErrors.MessageIncrMissing.ErrCode);
        JsApiErrors.NewJSMessageIncrPayloadError().ErrCode.ShouldBe(JsApiErrors.MessageIncrPayload.ErrCode);
        JsApiErrors.NewJSMessageSchedulesDisabledError().ErrCode.ShouldBe(JsApiErrors.MessageSchedulesDisabled.ErrCode);
        JsApiErrors.NewJSMessageSchedulesPatternInvalidError().ErrCode.ShouldBe(JsApiErrors.MessageSchedulesPatternInvalid.ErrCode);
        JsApiErrors.NewJSMessageSchedulesRollupInvalidError().ErrCode.ShouldBe(JsApiErrors.MessageSchedulesRollupInvalid.ErrCode);
        JsApiErrors.NewJSMessageSchedulesSourceInvalidError().ErrCode.ShouldBe(JsApiErrors.MessageSchedulesSourceInvalid.ErrCode);
        JsApiErrors.NewJSMessageSchedulesTTLInvalidError().ErrCode.ShouldBe(JsApiErrors.MessageSchedulesTTLInvalid.ErrCode);
        JsApiErrors.NewJSMessageSchedulesTargetInvalidError().ErrCode.ShouldBe(JsApiErrors.MessageSchedulesTargetInvalid.ErrCode);
        JsApiErrors.NewJSMessageTTLDisabledError().ErrCode.ShouldBe(JsApiErrors.MessageTTLDisabled.ErrCode);
        JsApiErrors.NewJSMessageTTLInvalidError().ErrCode.ShouldBe(JsApiErrors.MessageTTLInvalid.ErrCode);
        JsApiErrors.NewJSMirrorInvalidStreamNameError().ErrCode.ShouldBe(JsApiErrors.MirrorInvalidStreamName.ErrCode);
        JsApiErrors.NewJSMirrorMaxMessageSizeTooBigError().ErrCode.ShouldBe(JsApiErrors.MirrorMaxMessageSizeTooBig.ErrCode);
        JsApiErrors.NewJSMirrorMultipleFiltersNotAllowedError().ErrCode.ShouldBe(JsApiErrors.MirrorMultipleFiltersNotAllowed.ErrCode);
        JsApiErrors.NewJSMirrorOverlappingSubjectFiltersError().ErrCode.ShouldBe(JsApiErrors.MirrorOverlappingSubjectFilters.ErrCode);

        JsApiErrors.NewJSMirrorConsumerSetupFailedError(new InvalidOperationException("setup failed")).Description.ShouldBe("setup failed");
        JsApiErrors.NewJSMirrorInvalidSubjectFilterError(new InvalidOperationException("invalid source")).Description.ShouldBe("mirror transform source: invalid source");
        JsApiErrors.NewJSMirrorInvalidTransformDestinationError(new InvalidOperationException("invalid destination")).Description.ShouldBe("mirror transform: invalid destination");

        var expected = new JsApiError { Code = 494, ErrCode = 9095, Description = "override-6" };
        var fromOverride = JsApiErrors.NewJSMessageCounterBrokenError(JsApiErrors.Unless(expected));
        fromOverride.Code.ShouldBe(expected.Code);
        fromOverride.ErrCode.ShouldBe(expected.ErrCode);
        fromOverride.Description.ShouldBe(expected.Description);
        ReferenceEquals(fromOverride, expected).ShouldBeFalse();
    }

    [Fact]
    public void ConstructorSurface_Group07()
    {
        JsApiErrors.NewJSMirrorWithAtomicPublishError().ErrCode.ShouldBe(JsApiErrors.MirrorWithAtomicPublish.ErrCode);
        JsApiErrors.NewJSMirrorWithCountersError().ErrCode.ShouldBe(JsApiErrors.MirrorWithCounters.ErrCode);
        JsApiErrors.NewJSMirrorWithFirstSeqError().ErrCode.ShouldBe(JsApiErrors.MirrorWithFirstSeq.ErrCode);
        JsApiErrors.NewJSMirrorWithMsgSchedulesError().ErrCode.ShouldBe(JsApiErrors.MirrorWithMsgSchedules.ErrCode);
        JsApiErrors.NewJSMirrorWithSourcesError().ErrCode.ShouldBe(JsApiErrors.MirrorWithSources.ErrCode);
        JsApiErrors.NewJSMirrorWithStartSeqAndTimeError().ErrCode.ShouldBe(JsApiErrors.MirrorWithStartSeqAndTime.ErrCode);
        JsApiErrors.NewJSMirrorWithSubjectFiltersError().ErrCode.ShouldBe(JsApiErrors.MirrorWithSubjectFilters.ErrCode);
        JsApiErrors.NewJSMirrorWithSubjectsError().ErrCode.ShouldBe(JsApiErrors.MirrorWithSubjects.ErrCode);
        JsApiErrors.NewJSNoAccountError().ErrCode.ShouldBe(JsApiErrors.NoAccount.ErrCode);
        JsApiErrors.NewJSNoLimitsError().ErrCode.ShouldBe(JsApiErrors.NoLimits.ErrCode);
        JsApiErrors.NewJSNoMessageFoundError().ErrCode.ShouldBe(JsApiErrors.NoMessageFound.ErrCode);
        JsApiErrors.NewJSNotEmptyRequestError().ErrCode.ShouldBe(JsApiErrors.NotEmptyRequest.ErrCode);
        JsApiErrors.NewJSNotEnabledError().ErrCode.ShouldBe(JsApiErrors.NotEnabled.ErrCode);
        JsApiErrors.NewJSNotEnabledForAccountError().ErrCode.ShouldBe(JsApiErrors.NotEnabledForAccount.ErrCode);
        JsApiErrors.NewJSPeerRemapError().ErrCode.ShouldBe(JsApiErrors.PeerRemap.ErrCode);
        JsApiErrors.NewJSReplicasCountCannotBeNegativeError().ErrCode.ShouldBe(JsApiErrors.ReplicasCountCannotBeNegative.ErrCode);
        JsApiErrors.NewJSRequiredApiLevelError().ErrCode.ShouldBe(JsApiErrors.RequiredApiLevel.ErrCode);

        JsApiErrors.NewJSPedanticError(new InvalidOperationException("strict")).Description.ShouldBe("pedantic mode: strict");
        JsApiErrors.NewJSRaftGeneralError(new InvalidOperationException("raft failure")).Description.ShouldBe("raft failure");
        JsApiErrors.NewJSRestoreSubscribeFailedError(new InvalidOperationException("subscribe failed"), "$JS.API.CONSUMER").Description.ShouldBe("JetStream unable to subscribe to restore snapshot $JS.API.CONSUMER: subscribe failed");

        var expected = new JsApiError { Code = 493, ErrCode = 9096, Description = "override-7" };
        var fromOverride = JsApiErrors.NewJSNoAccountError(JsApiErrors.Unless(expected));
        fromOverride.Code.ShouldBe(expected.Code);
        fromOverride.ErrCode.ShouldBe(expected.ErrCode);
        fromOverride.Description.ShouldBe(expected.Description);
        ReferenceEquals(fromOverride, expected).ShouldBeFalse();
    }

    [Fact]
    public void ConstructorSurface_Group08()
    {
        JsApiErrors.NewJSSnapshotDeliverSubjectInvalidError().ErrCode.ShouldBe(JsApiErrors.SnapshotDeliverSubjectInvalid.ErrCode);
        JsApiErrors.NewJSSourceDuplicateDetectedError().ErrCode.ShouldBe(JsApiErrors.SourceDuplicateDetected.ErrCode);
        JsApiErrors.NewJSSourceInvalidStreamNameError().ErrCode.ShouldBe(JsApiErrors.SourceInvalidStreamName.ErrCode);
        JsApiErrors.NewJSSourceMaxMessageSizeTooBigError().ErrCode.ShouldBe(JsApiErrors.SourceMaxMessageSizeTooBig.ErrCode);
        JsApiErrors.NewJSSourceMultipleFiltersNotAllowedError().ErrCode.ShouldBe(JsApiErrors.SourceMultipleFiltersNotAllowed.ErrCode);
        JsApiErrors.NewJSSourceOverlappingSubjectFiltersError().ErrCode.ShouldBe(JsApiErrors.SourceOverlappingSubjectFilters.ErrCode);
        JsApiErrors.NewJSSourceWithMsgSchedulesError().ErrCode.ShouldBe(JsApiErrors.SourceWithMsgSchedules.ErrCode);
        JsApiErrors.NewJSStorageResourcesExceededError().ErrCode.ShouldBe(JsApiErrors.StorageResourcesExceeded.ErrCode);
        JsApiErrors.NewJSStreamDuplicateMessageConflictError().ErrCode.ShouldBe(JsApiErrors.StreamDuplicateMessageConflict.ErrCode);
        JsApiErrors.NewJSStreamExpectedLastSeqPerSubjectInvalidError().ErrCode.ShouldBe(JsApiErrors.StreamExpectedLastSeqPerSubjectInvalid.ErrCode);
        JsApiErrors.NewJSStreamExpectedLastSeqPerSubjectNotReadyError().ErrCode.ShouldBe(JsApiErrors.StreamExpectedLastSeqPerSubjectNotReady.ErrCode);

        JsApiErrors.NewJSSequenceNotFoundError(9UL).Description.ShouldBe("sequence 9 not found");
        JsApiErrors.NewJSSourceConsumerSetupFailedError(new InvalidOperationException("source setup failed")).Description.ShouldBe("source setup failed");
        JsApiErrors.NewJSSourceInvalidSubjectFilterError(new InvalidOperationException("bad filter")).Description.ShouldBe("source transform source: bad filter");
        JsApiErrors.NewJSSourceInvalidTransformDestinationError(new InvalidOperationException("bad destination")).Description.ShouldBe("source transform: bad destination");
        JsApiErrors.NewJSStreamAssignmentError(new InvalidOperationException("assignment failed")).Description.ShouldBe("assignment failed");
        JsApiErrors.NewJSStreamCreateError(new InvalidOperationException("create failed")).Description.ShouldBe("create failed");
        JsApiErrors.NewJSStreamDeleteError(new InvalidOperationException("delete failed")).Description.ShouldBe("delete failed");
        JsApiErrors.NewJSStreamExternalApiOverlapError("api", "foo").Description.ShouldBe("stream external api prefix api must not overlap with foo");
        JsApiErrors.NewJSStreamExternalDelPrefixOverlapsError("dlv", "foo").Description.ShouldBe("stream external delivery prefix dlv overlaps with stream subject foo");

        var expected = new JsApiError { Code = 492, ErrCode = 9097, Description = "override-8" };
        var fromOverride = JsApiErrors.NewJSSnapshotDeliverSubjectInvalidError(JsApiErrors.Unless(expected));
        fromOverride.Code.ShouldBe(expected.Code);
        fromOverride.ErrCode.ShouldBe(expected.ErrCode);
        fromOverride.Description.ShouldBe(expected.Description);
        ReferenceEquals(fromOverride, expected).ShouldBeFalse();
    }

    [Fact]
    public void ConstructorSurface_Group09()
    {
        JsApiErrors.NewJSStreamHeaderExceedsMaximumError().ErrCode.ShouldBe(JsApiErrors.StreamHeaderExceedsMaximum.ErrCode);
        JsApiErrors.NewJSStreamInfoMaxSubjectsError().ErrCode.ShouldBe(JsApiErrors.StreamInfoMaxSubjects.ErrCode);
        JsApiErrors.NewJSStreamInvalidError().ErrCode.ShouldBe(JsApiErrors.StreamInvalid.ErrCode);
        JsApiErrors.NewJSStreamMaxBytesRequiredError().ErrCode.ShouldBe(JsApiErrors.StreamMaxBytesRequired.ErrCode);
        JsApiErrors.NewJSStreamMaxStreamBytesExceededError().ErrCode.ShouldBe(JsApiErrors.StreamMaxStreamBytesExceeded.ErrCode);
        JsApiErrors.NewJSStreamMessageExceedsMaximumError().ErrCode.ShouldBe(JsApiErrors.StreamMessageExceedsMaximum.ErrCode);
        JsApiErrors.NewJSStreamMinLastSeqError().ErrCode.ShouldBe(JsApiErrors.StreamMinLastSeq.ErrCode);
        JsApiErrors.NewJSStreamMirrorNotUpdatableError().ErrCode.ShouldBe(JsApiErrors.StreamMirrorNotUpdatable.ErrCode);
        JsApiErrors.NewJSStreamMismatchError().ErrCode.ShouldBe(JsApiErrors.StreamMismatch.ErrCode);
        JsApiErrors.NewJSStreamMoveAndScaleError().ErrCode.ShouldBe(JsApiErrors.StreamMoveAndScale.ErrCode);
        JsApiErrors.NewJSStreamMoveNotInProgressError().ErrCode.ShouldBe(JsApiErrors.StreamMoveNotInProgress.ErrCode);
        JsApiErrors.NewJSStreamNameContainsPathSeparatorsError().ErrCode.ShouldBe(JsApiErrors.StreamNameContainsPathSeparators.ErrCode);
        JsApiErrors.NewJSStreamNameExistError().ErrCode.ShouldBe(JsApiErrors.StreamNameExist.ErrCode);
        JsApiErrors.NewJSStreamNameExistRestoreFailedError().ErrCode.ShouldBe(JsApiErrors.StreamNameExistRestoreFailed.ErrCode);

        JsApiErrors.NewJSStreamGeneralError(new InvalidOperationException("stream failed")).Description.ShouldBe("stream failed");
        JsApiErrors.NewJSStreamInvalidConfigError(new InvalidOperationException("invalid config")).Description.ShouldBe("invalid config");
        JsApiErrors.NewJSStreamInvalidExternalDeliverySubjError("api.*").Description.ShouldBe("stream external delivery prefix api.* must not contain wildcards");
        JsApiErrors.NewJSStreamLimitsError(new InvalidOperationException("limit error")).Description.ShouldBe("limit error");
        JsApiErrors.NewJSStreamMoveInProgressError("move-1").Description.ShouldBe("stream move already in progress: move-1");
        JsApiErrors.NewJSStreamMsgDeleteFailedError(new InvalidOperationException("delete failed")).Description.ShouldBe("delete failed");

        var expected = new JsApiError { Code = 491, ErrCode = 9098, Description = "override-9" };
        var fromOverride = JsApiErrors.NewJSStreamHeaderExceedsMaximumError(JsApiErrors.Unless(expected));
        fromOverride.Code.ShouldBe(expected.Code);
        fromOverride.ErrCode.ShouldBe(expected.ErrCode);
        fromOverride.Description.ShouldBe(expected.Description);
        ReferenceEquals(fromOverride, expected).ShouldBeFalse();
    }

    [Fact]
    public void ConstructorSurface_Group10()
    {
        JsApiErrors.NewJSStreamNotFoundError().ErrCode.ShouldBe(JsApiErrors.StreamNotFound.ErrCode);
        JsApiErrors.NewJSStreamNotMatchError().ErrCode.ShouldBe(JsApiErrors.StreamNotMatch.ErrCode);
        JsApiErrors.NewJSStreamOfflineError().ErrCode.ShouldBe(JsApiErrors.StreamOffline.ErrCode);
        JsApiErrors.NewJSStreamReplicasNotSupportedError().ErrCode.ShouldBe(JsApiErrors.StreamReplicasNotSupported.ErrCode);
        JsApiErrors.NewJSStreamReplicasNotUpdatableError().ErrCode.ShouldBe(JsApiErrors.StreamReplicasNotUpdatable.ErrCode);
        JsApiErrors.NewJSStreamSealedError().ErrCode.ShouldBe(JsApiErrors.StreamSealed.ErrCode);
        JsApiErrors.NewJSStreamSequenceNotMatchError().ErrCode.ShouldBe(JsApiErrors.StreamSequenceNotMatch.ErrCode);
        JsApiErrors.NewJSStreamSubjectOverlapError().ErrCode.ShouldBe(JsApiErrors.StreamSubjectOverlap.ErrCode);
        JsApiErrors.NewJSStreamTemplateNotFoundError().ErrCode.ShouldBe(JsApiErrors.StreamTemplateNotFound.ErrCode);
        JsApiErrors.NewJSStreamTooManyRequestsError().ErrCode.ShouldBe(JsApiErrors.StreamTooManyRequests.ErrCode);

        JsApiErrors.NewJSStreamOfflineReasonError(new InvalidOperationException("offline reason")).Description.ShouldBe("stream is offline: offline reason");
        JsApiErrors.NewJSStreamPurgeFailedError(new InvalidOperationException("purge failed")).Description.ShouldBe("purge failed");
        JsApiErrors.NewJSStreamRestoreError(new InvalidOperationException("restore failed")).Description.ShouldBe("restore failed: restore failed");
        JsApiErrors.NewJSStreamRollupFailedError(new InvalidOperationException("rollup failed")).Description.ShouldBe("rollup failed");
        JsApiErrors.NewJSStreamSnapshotError(new InvalidOperationException("snapshot failed")).Description.ShouldBe("snapshot failed: snapshot failed");
        JsApiErrors.NewJSStreamStoreFailedError(new InvalidOperationException("store failed")).Description.ShouldBe("store failed");
        JsApiErrors.NewJSStreamTemplateCreateError(new InvalidOperationException("template create failed")).Description.ShouldBe("template create failed");
        JsApiErrors.NewJSStreamTemplateDeleteError(new InvalidOperationException("template delete failed")).Description.ShouldBe("template delete failed");
        JsApiErrors.NewJSStreamTransformInvalidDestinationError(new InvalidOperationException("bad destination")).Description.ShouldBe("stream transform: bad destination");
        JsApiErrors.NewJSStreamTransformInvalidSourceError(new InvalidOperationException("bad source")).Description.ShouldBe("stream transform source: bad source");

        var expected = new JsApiError { Code = 490, ErrCode = 9099, Description = "override-10" };
        var fromOverride = JsApiErrors.NewJSStreamNotFoundError(JsApiErrors.Unless(expected));
        fromOverride.Code.ShouldBe(expected.Code);
        fromOverride.ErrCode.ShouldBe(expected.ErrCode);
        fromOverride.Description.ShouldBe(expected.Description);
        ReferenceEquals(fromOverride, expected).ShouldBeFalse();
    }

    [Fact]
    public void ConstructorSurface_Group11()
    {
        JsApiErrors.NewJSStreamWrongLastSequenceConstantError().ErrCode.ShouldBe(JsApiErrors.StreamWrongLastSequenceConstant.ErrCode);
        JsApiErrors.NewJSTempStorageFailedError().ErrCode.ShouldBe(JsApiErrors.TempStorageFailed.ErrCode);
        JsApiErrors.NewJSTemplateNameNotMatchSubjectError().ErrCode.ShouldBe(JsApiErrors.TemplateNameNotMatchSubject.ErrCode);

        JsApiErrors.NewJSStreamUpdateError(new InvalidOperationException("update failed")).Description.ShouldBe("update failed");
        JsApiErrors.NewJSStreamWrongLastMsgIDError("msg-42").Description.ShouldBe("wrong last msg ID: msg-42");
        JsApiErrors.NewJSStreamWrongLastSequenceError(42UL).Description.ShouldBe("wrong last sequence: 42");

        var expected = new JsApiError { Code = 489, ErrCode = 9100, Description = "override-11" };
        var fromOverride = JsApiErrors.NewJSTempStorageFailedError(JsApiErrors.Unless(expected));
        fromOverride.Code.ShouldBe(expected.Code);
        fromOverride.ErrCode.ShouldBe(expected.ErrCode);
        fromOverride.Description.ShouldBe(expected.Description);
        ReferenceEquals(fromOverride, expected).ShouldBeFalse();
    }
}
