#nullable enable
using Baya.Domain.Common;

namespace Baya.Domain.Entities.Reviews;

/// <summary>
/// A nurse-authored clinical note that accumulates into a <b>patient-scoped</b> longitudinal care history —
/// the scoping key is <see cref="PatientId"/>, <b>not</b> a booking. When a different nurse takes over they
/// read the prior history before accepting, so notes must never be siloed per visit; <see cref="BookingId"/>
/// is nullable provenance only (which visit produced the note).
/// <para>
/// The clinical body is <b>encrypted at rest</b>: <see cref="BodyEncrypted"/> holds the
/// <c>IFieldEncryptor</c>-produced ciphertext (never plaintext). There is deliberately no EF value converter
/// on this column — the handler encrypts on write and decrypts only after the strict clinical access check
/// passes on read, so no query can accidentally surface plaintext.
/// </para>
/// </summary>
public class PatientCareRecord : BaseEntity<long>
{
    /// <summary>The scoping key — the patient this note belongs to (tenancy is the patient's owning customer).</summary>
    public long PatientId { get; set; }

    /// <summary>Provenance only: the visit that produced the note. Nullable — a note is not booking-scoped.</summary>
    public long? BookingId { get; set; }

    /// <summary>The authoring nurse's <c>nurse_profiles.id</c>.</summary>
    public long NurseProfileId { get; set; }

    /// <summary>The clinical note, encrypted at rest via <c>IFieldEncryptor</c>. Never plaintext, never logged.</summary>
    public string BodyEncrypted { get; set; } = string.Empty;

    /// <summary>The nurse's ticked task checklist for this visit, as a JSON array of
    /// <c>{ label, done }</c> — structural provenance of what was done (rendered as chips in the history).
    /// NULL when the visit had no checklist.</summary>
    public string? TaskResultsJson { get; set; }

    /// <summary>When the note was recorded (UTC). Stored as <c>datetime2</c> so the history read can order by it
    /// on both SQL Server and the SQLite test provider (which cannot translate <c>DateTimeOffset</c> ordering).</summary>
    public DateTime RecordedAt { get; set; }

    public DateTimeOffset? DeletedAt { get; set; }
}
