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.App.Persistence;

/// <summary>
/// 设计时工厂，供 EF CLI 使用。
/// </summary>
internal sealed class TakeoutAppDesignTimeDbContextFactory
    : DesignTimeDbContextFactoryBase<TakeoutAppDbContext>
{
    /// <summary>
    /// 初始化业务库设计时上下文工厂。
    /// </summary>
    public TakeoutAppDesignTimeDbContextFactory()
        : base(DatabaseConstants.AppDataSource, "TAKEOUTSAAS_APP_CONNECTION")
    {
    }
    // 创建设计时上下文
    /// <summary>
    /// 创建设计时的业务库 DbContext。
    /// </summary>
    /// <param name="options">上下文选项。</param>
    /// <param name="tenantProvider">租户提供器。</param>
    /// <param name="currentUserAccessor">当前用户访问器。</param>
    /// <returns>业务库上下文实例。</returns>
    protected override TakeoutAppDbContext CreateContext(
        DbContextOptions<TakeoutAppDbContext> options,
        ITenantProvider tenantProvider,
        ICurrentUserAccessor currentUserAccessor)
        => new(options, tenantProvider, currentUserAccessor);
}
