using e_suite.API.Common.models;
using e_suite.Utilities.Pagination;
using eSuite.Core.MailService;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;

namespace eSuite.API.UnitTests.Controllers.MailTemplatesControllerUnitTests;

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

    [Test]
    public async Task GetMailTemplateTypes_WhenCalled_ReturnsPagedData()
    {
        //Arrange
        var mailTemplateTypes = new List<MailTemplateType>
        {
            new()
            {
                MailType = MailType.PasswordReset,
                Description = "Password Reset"
            }
        };

        var paginatedData = new PaginatedData<MailTemplateType>
        {
            Count = mailTemplateTypes.Count,
            Data = mailTemplateTypes,
            Page = 1,
            PageSize = 10
        };

        var cancellationToken = CancellationToken.None;

        _mailTemplateManagerMock.Setup(x => x.GetMailTemplateTypes(It.IsAny<Paging>(), It.IsAny<CancellationToken>())).ReturnsAsync(paginatedData);

        //Act
        var actualResult = await _mailTemplatesController.GetMailTemplateTypes(new Paging(), cancellationToken);

        //Assert
        Assert.That(actualResult.GetType(), Is.EqualTo(typeof(OkObjectResult)));
        var objectResult = actualResult as OkObjectResult;

        Assert.That(objectResult?.StatusCode, Is.EqualTo(200));
        Assert.That(objectResult?.Value, Is.Not.Null);
        Assert.That(objectResult!.Value!.GetType, Is.EqualTo(typeof(PaginatedData<MailTemplateType>)));
    }
}