using e_suite.API.Common.exceptions;
using e_suite.Database.Audit;
using eSuite.Core.Miscellaneous;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;

namespace eSuite.API.UnitTests.Controllers.OrganisationControllerUnitTests;

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

    [Test]
    public void ShouldReturnBadRequest()
    {
        //Arrange
        var exceptionText = "Organisation with this id does not exist.";

        var organisationId = new GeneralIdRef
        {
            Guid = new Guid("b793674e-e798-4f26-8c16-fdfc94c95194")
        };

        _organisationManagerMock.Setup(x => x.DeleteOrganisation(It.IsAny<AuditUserDetails>(), organisationId, true, It.IsAny<CancellationToken>())).Throws(new NotFoundException(exceptionText));

        //Assert
        Assert.ThrowsAsync<NotFoundException>(async () =>
        {
            //Act
            var actualResult = await _organisationController.DeleteOrganisation(organisationId);
        });
    }

    [Test]
    public async Task DeleteOrganisation_WhenCalledWithGoodParameters_ReturnsCalledModuleAndReturnsOK()
    {
        //Arrange
        var organisationId = new GeneralIdRef
        {
            Guid = new Guid("3e8965fa-7a35-429a-95be-10fd47cae43b")
        };

        //Act
        var actualResult = await _organisationController.DeleteOrganisation(organisationId);

        //Assert
        _organisationManagerMock.Verify(x => x.DeleteOrganisation(It.IsAny<AuditUserDetails>(), organisationId, true, It.IsAny<CancellationToken>()), Times.Once());

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

        Assert.That(objectResult?.StatusCode, Is.EqualTo(200));
    }
}