using Microsoft.EntityFrameworkCore;
using TakeoutSaaS.Infrastructure.Common.Persistence.DesignTime;
using TakeoutSaaS.Shared.Abstractions.Constants;
using TakeoutSaaS.Shared.Abstractions.Security;
using TakeoutSaaS.Shared.Abstractions.Tenancy;

namespace TakeoutSaaS.Infrastructure.Identity.Persistence;

/// <summary>
/// 设计时 IdentityDbContext 工厂，供 EF Core CLI 生成迁移使用。
/// </summary>
internal sealed class IdentityDesignTimeDbContextFactory
    : DesignTimeDbContextFactoryBase<IdentityDbContext>
{
    /// <summary>
    /// 初始化 Identity 设计时上下文工厂。
    /// </summary>
    public IdentityDesignTimeDbContextFactory()
        : base(DatabaseConstants.IdentityDataSource, "TAKEOUTSAAS_IDENTITY_CONNECTION")
    {
    }
    // 创建设计时上下文实例
    /// <summary>
    /// 创建设计时的 IdentityDbContext。
    /// </summary>
    /// <param name="options">DbContext 配置。</param>
    /// <param name="tenantProvider">租户提供器。</param>
    /// <param name="currentUserAccessor">当前用户访问器。</param>
    /// <returns>IdentityDbContext 实例。</returns>
    protected override IdentityDbContext CreateContext(
        DbContextOptions<IdentityDbContext> options,
        ITenantProvider tenantProvider,
        ICurrentUserAccessor currentUserAccessor)
        => new(options, tenantProvider, currentUserAccessor);
}
