using MiGu.DB.Kernel.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace MiGu.Server.Persistence;

/// <summary>兼容入口：转调 MiGu.DB Hosting，并注册本进程业务服务。</summary>
public static class PlatformPersistence
{
    public static IServiceCollection AddPlatformPersistence(this IServiceCollection services, IConfiguration configuration)
    {
        services.AddMiGuDb(configuration);

        services.AddScoped<Wms.WmsReferenceValidator>();
        services.AddScoped<Wms.WmsService>();
        services.AddScoped<Wms.WmsTransportRuleService>();
        services.AddScoped<Wms.WmsTransportPlanner>();
        services.AddScoped<Wms.WmsTransportTaskService>();
        services.AddScoped<Wms.IWmsDispatchAdapter, Wms.NoopWmsDispatchAdapter>();
        services.AddScoped<SimpleFields.SimpleFieldService>();
        services.AddScoped<Dashboard.DashboardShortcutService>();
        return services;
    }

    /// <summary>启动建库/迁移入口（内部即 MigrateMiGuDbAsync：Migrate + 基线 + DataMigrator）。</summary>
    public static Task EnsurePlatformDatabaseAsync(this IServiceProvider services)
        => services.MigrateMiGuDbAsync();
}
