using EntKube.Identity.Domain;

namespace EntKube.Identity.Infrastructure;

/// <summary>
/// In-memory implementation of the tenant repository for local development.
/// Production will use EF Core with PostgreSQL.
/// </summary>
public class InMemoryTenantRepository : ITenantRepository
{
    private readonly List<Tenant> tenants = new();

    public Task<Tenant?> GetByIdAsync(Guid id, CancellationToken ct = default)
    {
        Tenant? tenant = tenants.FirstOrDefault(t => t.Id == id);
        return Task.FromResult(tenant);
    }

    public Task<Tenant?> GetBySlugAsync(string slug, CancellationToken ct = default)
    {
        Tenant? tenant = tenants.FirstOrDefault(t => t.Slug == slug);
        return Task.FromResult(tenant);
    }

    public Task<IReadOnlyList<Tenant>> GetAllAsync(CancellationToken ct = default)
    {
        IReadOnlyList<Tenant> result = tenants.AsReadOnly();
        return Task.FromResult(result);
    }

    public Task AddAsync(Tenant tenant, CancellationToken ct = default)
    {
        tenants.Add(tenant);
        return Task.CompletedTask;
    }

    public Task UpdateAsync(Tenant tenant, CancellationToken ct = default)
    {
        return Task.CompletedTask;
    }
}
