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

namespace eSuite.API.UnitTests.Controllers.SequenceManagerControllerUnitTests;

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

    [Test]
    public async Task ShouldReturnOk()
    {
        // Arrange
        var sequences = new List<ReadSequence> {
            new()
            {
                Guid = new Guid("001ca58e-6738-4a24-9114-c9d7d515fac1"),
                Id = 1,
                Name = "First sequence"
            },
            new()
            {
                Guid = new Guid("4bfc0d4c-4c39-4513-a9d0-d70d3de3c4a9"),
                Id = 2,
                Name = "Second sequence"
            },
            new()
            {
                Guid = new Guid("3f816357-dc8e-4a1e-aa5d-3bd5b0c60ffe"),
                Id = 3,
                Name = "Third sequence"
            }
        }.BuildMock();

        var paginatedData = new PaginatedData<ReadSequence>
        {
            Count = sequences.Count(),
            Page = 1,
            PageSize = 10,
            Data = sequences
        };

        _sequenceManagerMock.Setup(x => x.GetSequences(It.IsAny<Paging>(), It.IsAny<CancellationToken>())).ReturnsAsync(paginatedData);
        var paging = new Paging();

        // Act
        var actualResult = await _sequenceController.GetSequences(paging);

        // 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<ReadSequence>)));

        var listResult = objectResult.Value as PaginatedData<ReadSequence>;
        Assert.That(listResult, Is.Not.Null);
        Assert.That(listResult!.Count, Is.EqualTo(3));
        Assert.That(listResult!.Page, Is.EqualTo(1));
        Assert.That(listResult!.PageSize, Is.EqualTo(10));
        Assert.That(listResult!.TotalPages, Is.EqualTo(1));
        Assert.That(listResult!.Data.Count, Is.EqualTo(3));
    }
}