using adas_core.Domain.Models.GroupedObservations;
using MongoDB.Bson;

namespace adas_core.Application.Services.Interfaces
{
    public interface ICacheService
    {
        //Métodos básicos
        void SetValue(string key, string value);
        string? GetValue(string key);
        Task<T?> GetObjectAsync<T>(string key, bool updateExpiration = true);
        Task SetObjectAsync<T>(string key, T obj, bool updateExpiration = true);
        Task<T?> GetObjectAsync<T>(string key, TimeSpan? ttlOverride, bool updateExpiration);
        Task SetObjectAsync<T>(string key, T obj, TimeSpan? ttlOverride, bool updateExpiration);
        Task DeleteObjectAsync(string key);
        Task<long> DeleteByPatternAsync(string pattern);
        void CleanCache();

        
        // Métodos para transparencia y gestión de locks
        
        // GetOrSet (string key)
        Task<string?> GetOrSetValueAsync(string key, Func<Task<string>> loader, TimeSpan? ttlOverride = null);
        Task<T> GetOrSetObjectAsync<T>(
            string key,
            Func<Task<T>> factory,
            TimeSpan? ttl = null,
            CancellationToken cancellationToken = default);
        
        // GetOrSet especializado para GroupedObservations
        Task<T> GetOrSetObjectAsync<T>(
            GroupedField groupedField,
            ObjectId patientId,
            Func<Task<T>> factory,
            TimeSpan? ttl = null,
            CancellationToken cancellationToken = default);

    }
}