using foodmarket.Application.Common.Tenancy;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace foodmarket.Infrastructure.Persistence;

internal class DesignTimeAppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
    public AppDbContext CreateDbContext(string[] args)
    {
        var opts = new DbContextOptionsBuilder<AppDbContext>()
            .UseNpgsql("Host=localhost;Port=5432;Database=food_market;Username=nns;Password=")
            .UseOpenIddict()
            .Options;
        return new AppDbContext(opts, new DesignTimeTenantContext());
    }

    private sealed class DesignTimeTenantContext : ITenantContext
    {
        public Guid? OrganizationId => null;
        public bool IsAuthenticated => false;
        public bool IsSuperAdmin => true;
        public bool IsTenantOverride => false;
    }
}
