using adas_core.Application.Repositories.Interfaces;
using adas_core.Application.Services.Interfaces;
using adas_core.Domain.Enums;
using adas_core.Domain.Models.AppSettings;
using adas_core.Domain.Models.MongoModels;
using adas_core.module.LightBeacons.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using MongoDB.Bson;
using Moq;
using Options = Microsoft.Extensions.Options.Options;

namespace adas_core.Test.Services;

[TestFixture]
public class LightBeaconServiceTest
{
    /// <summary>
    /// Initializes the test fixture by creating mock instances of the service's dependencies
    /// and instantiating the <see cref="LightBeaconService"/> under test with those mocks.
    /// This setup runs before each test to ensure a clean, isolated test environment.
    /// </summary>
    [SetUp]
        public void Setup()
        {
            _optionsApiSettings = Options.Create(_apiSettings);
            _pocService = new Mock<IPointOfCareService>();
            _clientMessageService = new Mock<IClientMessageService>();
            _subscribersService = new Mock<ISubscribersService>();
            _logger = new Mock<ILogger<LightBeaconService>>();
            _lightBeaconRepository = new Mock<ILightBeaconRepository>();
    
            _lightBeaconService = new LightBeaconService(
                _optionsApiSettings,
                _logger.Object,
                _clientMessageService.Object,
                _subscribersService.Object,
                _pocService.Object,
                _lightBeaconRepository.Object
            );
        }

    private LightBeaconService _lightBeaconService = null!;

    private readonly ApiSettings _apiSettings = new()
    {
        BalizaUrl = "http://localhost/info.html",
        BalizaPassword = "password"
    };

    private IOptions<ApiSettings> _optionsApiSettings = null!;

    private Mock<ILogger<LightBeaconService>> _logger = null!;
    private Mock<IPointOfCareService> _pocService = null!;
    private Mock<IClientMessageService> _clientMessageService = null!;
    private Mock<ISubscribersService> _subscribersService = null!;
    private Mock<ILightBeaconRepository> _lightBeaconRepository = null!;

    /// <summary>
    /// Integration test that verifies the light beacon service returns <see cref="LightBeaconColor.Off"/> for a given point of care when the patient has no associated beacon color.
    /// </summary>
    [Ignore("Integration test")]
        [Test]
        public async Task GetBeaconColor()
        {
            var patient = new Patient
            {
                UnitId = ObjectId.GenerateNewId(),
                PointOfCareId = ObjectId.GenerateNewId()
            };
    
    
            var color = await _lightBeaconService.GetColor(patient.PointOfCareId.Value);
    
            Assert.That(color, Is.EqualTo(
                LightBeaconColor.Off));
        }
}