using System.Text.Json.Nodes;
namespace NpgsqlRest;
///
/// One rule in a cache profile's list. Each rule combines:
///
/// - A name (a routine parameter to inspect at request time).
/// - A condition (scalar = exact match; array = OR over entries; JSON null matches .NET null/DBNull).
/// - An action: = true → bypass the cache (no read, no write); otherwise
/// is used to override the entry's TTL for this write.
///
/// In JSON config the action is expressed as a single "Then" field: the literal string "skip" sets
/// = true; a PostgreSQL interval (e.g. "30 seconds") sets .
///
/// Multiple rules are evaluated in declaration order; first match wins. No match → fall through to the profile's
/// (or annotation's) default .
///
/// Validation at startup: a rule whose name is not a real routine parameter, or which is
/// not part of the resolved cache-key parameter list, is dropped with a Warning. A rule with missing/invalid
/// "Then" JSON value is also dropped with a Warning.
///
public class CacheWhenRule
{
///
/// Routine parameter name to inspect (matches against either ActualName or ConvertedName).
///
public string Parameter { get; set; } = "";
///
/// Match condition. Scalar (single match) or JSON array (OR over entries). JSON null matches .NET null / DBNull.
/// String/number match is case-insensitive ordinal on the stringified parameter value.
///
public JsonNode? Value { get; set; }
///
/// When this rule matches at request time:
/// - true → bypass the cache entirely for this request (no read, no write).
/// - false → use as the entry's TTL when writing.
///
/// Set during config parsing based on the JSON "Then" value: "skip" → true; PG interval → false.
///
public bool Skip { get; set; }
///
/// Override TTL applied to writes that match this rule. Only used when is false.
/// Null = entry never expires (matches the existing CacheExpiresIn=null behavior).
///
public TimeSpan? ThenExpiration { get; set; }
}