using adas_core.Domain.Models.AppSettings;
using adas_core.Domain.Models.MongoModels;
using adas_core.Infrastructure.Repositories;
using Microsoft.Extensions.Options;
using MongoDB.Bson;
using Options = Microsoft.Extensions.Options.Options;

namespace adas_core.Test.Repositories;

[TestFixture]
[Category("Integration")]
public class ServiceConfigRepositoryTest
{
    [OneTimeSetUp]
    public async Task Init()
    {
        _optionsApiSettings = Options.Create(_apiSettings);

        var serviceConfig = new ServiceConfig
        {
            Id = _id,
            StrId = Id.ToString()
        };

        await IntegrationDb.Database.DropCollectionAsync("service_config");
        await IntegrationDb.Database.CreateCollectionAsync("service_config");

        _repository = new ServiceConfigRepository(_optionsApiSettings, IntegrationDb.Database);

        await _repository.InsertOneAsync(serviceConfig);
    }

    private ServiceConfigRepository _repository;

    private readonly ApiSettings _apiSettings = new()
    {
        ServiceConfig = "service_config"
    };

    private IOptions<ApiSettings> _optionsApiSettings;

    private readonly ObjectId _id = ObjectId.GenerateNewId();
    private static readonly ObjectId Id = ObjectId.GenerateNewId();


    [Test]
    public async Task FindById_Find_string()
    {
        var result = await _repository.FindById(Id.ToString());

        Assert.That(result, Is.Not.Null);
        Assert.That(result!.StrId, Is.EqualTo(Id.ToString()));
    }

    [Test]
    public async Task FindById_Find_ObjectId()
    {
        var result = await _repository.FindById(_id);

        Assert.That(result, Is.Not.Null);
        Assert.That(result!.Id, Is.EqualTo(_id));
    }
}