using JSMR.Infrastructure.Data;
using JSMR.Tests.Fixtures;

namespace JSMR.Tests.Search;

public abstract class SearchProviderFixture(MariaDbContainerFixture container) : IAsyncLifetime
{
    public AppDbContext? DbContext { get; private set; }

    public async ValueTask InitializeAsync()
    {
        DbContext = await MariaDbClone.CloneFromTemplateAsync(
            container.RootConnectionString,
            container.TemplateDbName,
            seed: SeedAsync);
    }

    protected abstract Task SeedAsync(AppDbContext context);

    public async ValueTask DisposeAsync()
    {
        if (DbContext is not null)
        {
            await DbContext.DisposeAsync();
        }

        GC.SuppressFinalize(this);
    }
}