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

/// <summary>
/// 日志库设计时工厂，供 EF CLI 使用。
/// </summary>
internal sealed class TakeoutLogsDesignTimeDbContextFactory
    : DesignTimeDbContextFactoryBase<TakeoutLogsDbContext>
{
    /// <summary>
    /// 初始化日志库设计时上下文工厂。
    /// </summary>
    public TakeoutLogsDesignTimeDbContextFactory()
        : base(DatabaseConstants.LogsDataSource, "TAKEOUTSAAS_LOGS_CONNECTION")
    {
    }

    /// <summary>
    /// 创建日志库 DbContext。
    /// </summary>
    /// <param name="options">上下文选项。</param>
    /// <param name="tenantProvider">租户提供器。</param>
    /// <param name="currentUserAccessor">当前用户访问器。</param>
    /// <returns>日志库上下文实例。</returns>
    protected override TakeoutLogsDbContext CreateContext(
        DbContextOptions<TakeoutLogsDbContext> options,
        ITenantProvider tenantProvider,
        ICurrentUserAccessor currentUserAccessor)
        => new(options, tenantProvider, currentUserAccessor);
}
