using Microsoft.EntityFrameworkCore;
using MiGu.DB.Abstractions.Providers;
using MiGu.DB.Kernel.Context;

namespace MiGu.DB.Kernel.Providers;

public sealed class SqliteProviderSetup : IDbProviderSetup
{
    public string Name => "sqlite";
    public string MigrationsAssemblyName => typeof(MiGuDbContext).Assembly.GetName().Name!;
    public string MigrationsNamespace => "MiGu.DB.Migrations.Sqlite";

    public void Configure(DbContextOptionsBuilder builder, string connectionString)
        => builder.UseSqlite(connectionString, o => o.MigrationsAssembly(MigrationsAssemblyName)
            .MigrationsHistoryTable("__EFMigrationsHistory"));
}

public sealed class MySqlProviderSetup : IDbProviderSetup
{
    public string Name => "mysql";
    public string MigrationsAssemblyName => typeof(MiGuDbContext).Assembly.GetName().Name!;
    public string MigrationsNamespace => "MiGu.DB.Migrations.MySql";

    public void Configure(DbContextOptionsBuilder builder, string connectionString)
        => builder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString),
            o => o.MigrationsAssembly(MigrationsAssemblyName));
}

public sealed class NpgsqlProviderSetup : IDbProviderSetup
{
    public string Name => "npgsql";
    public string MigrationsAssemblyName => typeof(MiGuDbContext).Assembly.GetName().Name!;
    public string MigrationsNamespace => "MiGu.DB.Migrations.Npgsql";

    public void Configure(DbContextOptionsBuilder builder, string connectionString)
        => builder.UseNpgsql(connectionString, o => o.MigrationsAssembly(MigrationsAssemblyName));
}

public sealed class SqlServerProviderSetup : IDbProviderSetup
{
    public string Name => "sqlserver";
    public string MigrationsAssemblyName => typeof(MiGuDbContext).Assembly.GetName().Name!;
    public string MigrationsNamespace => "MiGu.DB.Migrations.SqlServer";

    public void Configure(DbContextOptionsBuilder builder, string connectionString)
        => builder.UseSqlServer(connectionString, o => o.MigrationsAssembly(MigrationsAssemblyName));
}
