using e_suite.API.Common.exceptions;
using e_suite.Database.Core.Tables.Sequences;
using eSuite.Core.Miscellaneous;
using NUnit.Framework;
using SequenceManager.UnitTests.Helpers;

namespace SequenceManager.UnitTests;

[TestFixture]
public class GetSequenceUnitTests : SequenceManagerTestBase
{
    [SetUp]
    public override async Task Setup()
    {
        await base.Setup();
    }

    [Test]
    public void GetSequence_WhenSequenceDoesNotExist_ThrowsException()
    {
        //Arrange
        var generalRefId = new GeneralIdRef
        {
            Guid = Guid.NewGuid(),
        };

        //Act * Assert
        Assert.ThrowsAsync<NotFoundException>( async () => await SequenceManager.GetSequence(generalRefId, default) );
    }

    [Test]
    public void GetSequence_WhenSequenceIsDeleted_ThrowsException()
    {
        //Arrange
        var testGuid = new Guid("{77F925CD-C521-45D3-B8AE-00F621071989}");

        SequenceManagerRepository.Sequences.Add(new Sequence
            {
                Guid = testGuid,
                Id = 1,
                Deleted = true,
                Name = "Test Sequence"
            }
        );

        var generalRefId = new GeneralIdRef
        {
            Guid = testGuid,
        };

        //Act * Assert
        Assert.ThrowsAsync<NotFoundException>(async () => await SequenceManager.GetSequence(generalRefId, default));
    }

    [Test]
    public async Task GetSequence_WhenSequenceExists_ReturnsSequenceModel()
    {
        //Arrange
        var testGuid = new Guid("{77F925CD-C521-45D3-B8AE-00F621071989}");

        SequenceManagerRepository.Sequences.Add( new Sequence
            {
                Guid = testGuid,
                Id = 1,
                Deleted = false,
                Name = "Test Sequence"
            }
            );

        var generalRefId = new GeneralIdRef
        {
            Guid = testGuid,
        };

        //Act
        var result = await SequenceManager.GetSequence(generalRefId, default);

        //Assert
        Assert.That(result, Is.Not.Null);
        Assert.That(result.Name, Is.EqualTo("Test Sequence"));
    }
}