using e_suite.Database.Core.Tables.Forms;
using e_suite.Utilities.Pagination;
using NUnit.Framework;

namespace e_suite.Modules.FormsManagerUnitTests.FormsManagerUnitTests;

public class GetAllFormsUnitTests : FormsManagerUnitTestBase
{

    [SetUp]
    public async Task SetUp()
    {
        await base.Setup();
    }

    [Test]
    public async Task GetAllForms_NormalConditions_ReturnsCollection()
    {
        //Arrange
        var formGuidOne = Guid.NewGuid();
        var formGuidTwo = Guid.NewGuid();
        var form = new FormTemplate
        {
            Guid = formGuidOne,
            Deleted = false,
            Id = 1,
            Name = "TestOne",
        };
        var formVersion = new FormTemplateVersion
        {
            Deleted = false,
            FormDefinition = "testtttOne",
            Id = 1,
            Guid = Guid.NewGuid(),
            TemplateId = 1,
            Template = form
        };
        var formTwo = new FormTemplate
        {
            Guid = formGuidTwo,
            Deleted = false,
            Id = 2,
            Name = "TestTwo",
        };
        var formVersionTwo = new FormTemplateVersion
        {
            Deleted = false,
            FormDefinition = "testtttTwo",
            Id = 1,
            Guid = Guid.NewGuid(),
            TemplateId = 2,
            Template = formTwo
        };
        form.Versions = new List<FormTemplateVersion> { formVersion };
        formTwo.Versions = new List<FormTemplateVersion> { formVersionTwo };
        _fakeformRepository.FormTemplates.AddRange(new FormTemplate[] { form, formTwo });
        _fakeformRepository.FormTemplateVersions.AddRange(new FormTemplateVersion[] { formVersion, formVersionTwo });

        var paging = new Paging
        {
            SortKey = "name"
        };

        //Act
        var res = await _formManager.GetFormTemplatesAsync(paging, default);

        //Assert
        Assert.Multiple(() =>
        {
            Assert.That(res, Is.Not.Null);
            Assert.That(res.Count, Is.EqualTo(2));
            Assert.That(res.Data.Any(f => f.Guid == formGuidOne));
            Assert.That(res.Data.Any(f => f.Guid == formGuidTwo));
        });
    }

    [Test]
    public async Task GetAllForms_NoData_RturnsEmptyList()
    {
        //Arrange
        var paging = new Paging
        {
            SortKey = "name"
        };

        //Act
        var res = await _formManager.GetFormTemplatesAsync(paging, default);

        //Assert
        Assert.Multiple(() =>
        {
            Assert.That(res, Is.Not.Null);
            Assert.That(res.Count, Is.EqualTo(0));
        });
    }
}