
using Microsoft.EntityFrameworkCore;
using System.Runtime.InteropServices.Marshalling;

namespace OpenArchival.DataAccess;

public static class HomepageConfigurationSeeder
{
    public static async Task SeedHomepageConfig(IServiceProvider serviceProvider)
    {
        var contextFactory = serviceProvider.GetRequiredService<IDbContextFactory<ApplicationDbContext>>();
        await using var context = await contextFactory.CreateDbContextAsync();

        HomePageConfiguration? existingConfig = await context.HomePageConfiguration.FirstOrDefaultAsync();
        if (existingConfig == null)
        {
            var config = new HomePageConfiguration() { 
                Content = "<p>No homepage content configured</p>", 
                HomePageBanner = null, 
                SliderEntries = null 
            };

            context.HomePageConfiguration.Add(config);
            await context.SaveChangesAsync();

        }
    }
}
