namespace NpgsqlRest;
///
/// A named caching policy that an endpoint can opt into via the @cache_profile comment annotation.
/// Profiles let you maintain multiple distinct caching policies (different backends, expirations, key shapes,
/// or bypass conditions) within a single application.
///
/// At the C# / library level a is fully configured: its is an
/// instance you provide. The NpgsqlRestClient configuration layer reads JSON profiles
/// (with a "Type" string and optional "Enabled": true) and constructs profile instances on your behalf.
/// The core library itself stays interface-only and does not know about Memory/Redis/Hybrid backends — it just
/// stores the resolved .
///
/// Profile resolution at startup:
/// - Each endpoint with @cache_profile name looks up name in .
/// - Unknown names cause startup to fail with a single error listing all unresolved references and the offending endpoints.
/// - Endpoints without @cache_profile use (the root cache).
///
public class CacheProfile
{
///
/// The cache backend instance for this profile. Required.
///
/// The library does not interpret beyond calling Get/AddOrUpdate/Remove.
/// In the client app, the same instance is reused for every profile of the same
/// "Type" — one Memory cache, one Redis connection, one HybridCache singleton at most.
///
public IRoutineCache Cache { get; set; } = null!;
///
/// Default expiration for entries written under this profile. null means entries never expire (matches
/// today's @cached behavior when no @cache_expires is set).
///
/// An endpoint's @cache_expires <interval> annotation overrides this value.
///
public TimeSpan? Expiration { get; set; }
///
/// Default cache-key parameter list for endpoints using this profile when their @cached annotation
/// does not specify any. Three semantics:
///
/// - null (or property omitted): use ALL routine parameters as the cache key — same as today's bare @cached.
/// - [] (empty array): use NO parameters — one cache entry per endpoint URL, regardless of inputs.
/// - ["p1", "p2"]: use only these named parameters as the cache key.
///
/// The endpoint's @cached p1, p2 annotation overrides this list; if both the annotation and the profile
/// specify parameters, the annotation wins.
///
public string[]? Parameters { get; set; }
///
/// Optional list of conditional rules evaluated against the resolved parameter values at request time.
/// Each rule combines a name, a
/// condition (scalar or array), and an action — either bypass the cache ()
/// or override the entry's TTL ().
///
/// Rules are evaluated in declaration order; the first match wins. No match → fall through to the profile's
/// (or annotation's) default . Use this for:
/// - Skip-on-condition (e.g. "if `to` is null, fetch fresh")
/// - Tiered TTLs ("if `tier=free`, cache 5 min; if `tier=pro`, no cache")
/// - Status-aware caching ("if `status=draft`, cache 30 sec; if `status=published`, cache 1 hour")
///
/// Each rule's Parameter must be in the cache-key parameter list (via profile's
/// or the endpoint's @cached annotation), otherwise different rule-evaluations would share the same cache
/// entry and produce confusing results. Rules whose Parameter isn't in the cache key are dropped with a startup
/// Warning.
///
public CacheWhenRule[]? When { get; set; }
}