using adas_core.Domain.Models.AppSettings;
using adas_core.Infrastructure.Services;
using EasyNetQ;
using EasyNetQ.SystemMessages;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Moq;

namespace adas_core.Test.Services;

[TestFixture]
public class PublisherServiceTest
{
    //private static readonly DateTime now = DateTime.Now;
    //private static readonly ObjectId patientId = ObjectId.GenerateNewId();

    /// <summary>
    /// Initializes the test environment for <see cref="PublisherService"/> by configuring RabbitMQ settings, creating a mocked logger, and instantiating the service under test.
    /// </summary>
    [SetUp]
        public void Setup()
        {
            //advancedBusMock = new Mock<IAdvancedBus>();
    
            _optionsRabbitMqSettings = Options.Create(_rabbitMqSettings);
    
            _logger = new Mock<ILogger<PublisherService>>();
    
            _publisherService = new PublisherService(
                _optionsRabbitMqSettings,
                _logger.Object);
        }

    private PublisherService _publisherService = null!;
    //private Mock<IAdvancedBus> advancedBusMock;

    private readonly RabbitMqSettings _rabbitMqSettings = new()
    {
        ObservationsQueue = "Observations"
    };

    private IOptions<RabbitMqSettings> _optionsRabbitMqSettings = null!;

    private Mock<ILogger<PublisherService>> _logger = null!;

    /// <summary>
    /// Verifies that the publisher service's SendMessage method returns a non-null result when sending a message to the observations queue.
    /// </summary>
    [Test]
        public void SendMessage_Return_true()
        {
            var newMessage = new Message<string>();
    
            var result = _publisherService.SendMessage(newMessage, _rabbitMqSettings.ObservationsQueue);
    
            Assert.That(result, Is.Not.Null);
        }

    /// <summary>
    /// Verifies that <c>SendMessageError</c> returns a non-null result when publishing a new <see cref="Message{Error}"/> to the observations queue.
    /// </summary>
    [Test]
        public void SendMessage_Error_Return_true()
        {
            var newMessage = new Message<Error>();
    
            var result = _publisherService.SendMessageError(newMessage, _rabbitMqSettings.ObservationsQueue);
    
            Assert.That(result, Is.Not.Null);
        }
}