using Health.Application.HealthArchives;

namespace Health.Infrastructure.HealthArchives;

public sealed class EfHealthArchiveRepository(AppDbContext db) : IHealthArchiveRepository
{
    private readonly AppDbContext _db = db;

    public Task<HealthArchive?> GetByUserIdAsync(Guid userId, CancellationToken ct) =>
        _db.HealthArchives
            .Include(a => a.Surgeries)
            .FirstOrDefaultAsync(a => a.UserId == userId, ct);

    public async Task AddAsync(HealthArchive archive, CancellationToken ct) =>
        await _db.HealthArchives.AddAsync(archive, ct);

    public Task SaveChangesAsync(CancellationToken ct) =>
        _db.SaveChangesAsync(ct);
}
