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

namespace eSuite.API.UnitTests.Controllers.AuditControllerUnitTests;

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

    [Test]
    public async Task Get_WhenCalled_ReturnsPagedData()
    {
        //Arrange
        var auditLogs = new List<AuditLogEntry>
        {
            new()
            {
                Id = 999,
                Comment = string.Empty,
                DisplayName = "Testy McTester"
            }
        };

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

        var logEntry = string.Empty;
        bool primaryOnly = false;

        _auditLogMock.Setup(x => x.GetAuditLogEntries(It.IsAny<Paging>(), It.IsAny<string?>(), It.IsAny<bool>(), It.IsAny<CancellationToken>())).ReturnsAsync(paginatedData);

        //Act
        var actualResult = await _auditController.Get(new Paging(), logEntry, primaryOnly, CancellationToken.None);

        //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<AuditLogEntry>)));
    }
}