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.CustomFieldControllerUnitTest;

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

    [Test]
    public async Task GetFields_WhenCalled_ReturnsPagedData()
    {
        //Arrange
        var auditLogs = new List<CustomFieldDefinition>
        {
            new()
            {
                Guid = new Guid("e7b1cc1a-0325-46fa-8bff-fa168cfe8dd9"),
                Id = 999,
                Name = "Test custom field"
            }
        };

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


        _customFieldManagerMock!.Setup(x => x.GetFieldsAsync(It.IsAny<Paging>(), It.IsAny<CancellationToken>())).ReturnsAsync(paginatedData);

        //Act
        var actualResult = await _customFieldController.GetFields(new Paging(), 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<CustomFieldDefinition>)));
    }
}