namespace adas_core.Domain.Models.AppSettings
{
///
/// Configuración Redis.
/// No contiene lógica de qué entidades usan Redis (eso está en CacheSettings).
/// Esta clase solo define:
/// - Conexión
/// - Cluster/Scalability
/// - SSL/password
/// - TTL global y por entidad
/// - Generación de claves CacheKeys
///
public class RedisSettings
{
// Conexión y networking
public string? ConnectionString { get; set; }
public bool EnableScalable { get; set; }
public bool Ssl { get; set; }
public string? Password { get; set; }
public IEnumerable Endpoints { get; set; } = [];
public string ChannelPrefix { get; set; } = "MedDisCore";
// TTL global y TTL específico por entidad
// (no determina si la entidad se cachea o no)
public int? ExpireKeyInSeconds { get; set; }
public TtlSettings Ttl { get; set; } = new();
// Submodelos
///
/// Represents a Redis server endpoint, typically used to encapsulate connection details such as host, port, and credentials required to connect to a Redis instance.
///
public class RedisEndpoint
{
public string Host { get; set; } = null!;
public int Port { get; set; }
}
// CacheKeys: claves estandarizadas y unificadas para todas las entidades
// Estas claves son fundamentales para:
///
/// Provides static cache key constants used throughout the application to ensure consistent key naming when storing and retrieving cached data.
///
public static class CacheKeys
{
// ----------------- Patients -----------------
///
/// Builds a formatted patient identifier by prefixing the provided patient ID with "patients:".
///
/// The unique identifier of the patient to be included in the formatted string.
/// A string in the format "patients:{patientId}" representing the patient resource key.
public static string Patient(string patientId)
=> $"patients:{patientId}";
// ----------------- ConfigDisplays -----------------
///
/// Builds a configuration key for a config display by combining the configDisplays namespace with the specified identifier.
///
/// The unique identifier of the config display to include in the key.
/// A formatted key string in the form configDisplays:{id} suitable for lookup or caching.
public static string ConfigDisplay(string id)
=> $"configDisplays:{id}";
///
/// Returns the configuration key representing the "all displays" setting, typically used to request or identify the display configuration for all available displays.
///
/// The string identifier "configDisplays:all" used to reference the all-displays configuration.
public static string ConfigDisplaysAll()
=> "configDisplays:all";
// ----------------- PumpObservations -----------------
///
/// Formats the specified observation identifier as a pump observation reference string by prefixing it with "pumpObs:".
///
/// The observation identifier to include in the formatted result.
/// A formatted string in the form "pumpObs:{obsId}".
public static string PumpObservation(string obsId)
=> $"pumpObs:{obsId}";
///
/// Builds a daily pump observation identifier by composing a prefixed key with the pump identifier and the date in yyyyMMdd format.
///
/// The unique identifier of the pump used in the composed key.
/// The observation date whose year, month, and day are formatted into the key.
/// A string in the form pumpObs:pump:{pumpId}:{yyyyMMdd} representing the daily pump observation key.
public static string PumpDaily(string pumpId, DateTime date)
=> $"pumpObs:pump:{pumpId}:{date:yyyyMMdd}";
// ----------------- Appointments -----------------
///
/// Builds an appointment resource identifier by combining the "appointments" prefix with the specified appointment ID.
///
/// The unique identifier of the appointment.
/// A formatted string in the form "appointments:{apptId}".
public static string Appointment(string apptId)
=> $"appointments:{apptId}";
///
/// Builds a cache key for retrieving a patient's appointments for a specific calendar day.
/// The key is composed of the patient identifier and the date formatted as yyyyMMdd.
///
/// The unique identifier of the patient whose appointments are being addressed.
/// The date for which the appointments are being requested.
/// A formatted cache key string combining the patient identifier and the day in yyyyMMdd format.
public static string AppointmentsByPatientDay(string patientId, DateTime date)
=> $"appointments:patient:{patientId}:{date:yyyyMMdd}";
///
/// Builds a deterministic cache key used to look up a patient's appointments for the month of the supplied date.
/// The key is composed of the patient identifier and the date formatted as yyyyMM.
///
/// The identifier of the patient whose appointments are being queried.
/// The date whose year and month determine the appointment period encoded in the key.
/// A formatted string in the form appointments:patient:{patientId}:{yyyyMM} suitable for use as a cache key.
public static string AppointmentsByPatientMonth(string patientId, DateTime date)
=> $"appointments:patient:{patientId}:{date:yyyyMM}";
// ----------------- GroupedObservations -----------------
///
/// Builds a formatted identifier string for grouped observations associated with a specific patient, typically used as a cache key or lookup token.
///
/// The unique identifier of the patient whose observations are being referenced.
/// The optional field used to group the observations; may be null.
/// A formatted string in the pattern "groupedObs:{groupedField}:patient:{patientId}".
public static string GroupedObservationsByPatient(string patientId, string? groupedField)
=> $"groupedObs:{groupedField}:patient:{patientId}";
///
/// Generates a formatted cache key for grouped observations scoped to a specific patient and day.
///
/// The unique identifier of the patient.
/// The field name used to group the observations.
/// The observation date, formatted as yyyyMMdd in the generated key.
/// A cache key string in the format groupedObs:{groupedField}:patient:{patientId}:{yyyyMMdd}.
public static string GroupedObservationsByPatientDay(string patientId, string groupedField, DateTime date)
=> $"groupedObs:{groupedField}:patient:{patientId}:{date:yyyyMMdd}";
///
/// Builds a cache key for grouped observations scoped to a specific patient and month, combining the grouping field, patient identifier, and the year-month portion of the provided date.
///
/// The identifier of the patient whose observations are being grouped.
/// The observation field used as the grouping criterion.
/// The date used to derive the month bucket (formatted as yyyyMM) for the cache key.
/// A formatted cache key string in the form groupedObs:{groupedField}:patient:{patientId}:{yyyyMM}.
public static string GroupedObservationsByPatientMonth(string patientId, string groupedField, DateTime date)
=> $"groupedObs:{groupedField}:patient:{patientId}:{date:yyyyMM}";
///
/// Generates a cache key for retrieving the most recent grouped observations for a specific patient.
///
/// The unique identifier of the patient whose observations are being queried.
/// The field used to group the observations.
/// The maximum number of latest observations to include in the cache key.
/// A formatted cache key string identifying the patient's latest grouped observations.
public static string GroupedObservationsLatest(string patientId, string groupedField, int take)
=> $"groupedObs:{groupedField}:patient:{patientId}:latest:{take}";
}
}
}