#nullable enable
using Baya.Application.Models.Common;
using Baya.Application.Models.Reviews;
using Baya.Domain.Entities.Identity;
using Baya.Domain.Entities.Reviews;

namespace Baya.Application.Contracts.Persistence;

/// <summary>
/// The <c>patient_care_records</c> store — patient-scoped clinical notes, encrypted at rest. Reads return the
/// ciphertext; the handler decrypts only after the strict clinical access check passes. Access facts (patient
/// ownership, a nurse's qualifying booking) are answered here so the handler can gate before touching the body.
/// </summary>
public interface IPatientCareRecordRepository
{
    Task AddAsync(PatientCareRecord record, CancellationToken cancellationToken);

    /// <summary>The patient's owning <c>customer_profiles.id</c>, or null if the patient does not exist — the
    /// tenancy anchor for the owning-customer access branch.</summary>
    Task<long?> GetPatientOwnerCustomerIdAsync(long patientId, CancellationToken cancellationToken);

    /// <summary>True if the nurse has a booking for the patient that reached a confirmed (or later) state — the
    /// gate for both writing and reading that patient's clinical history. A nurse never assigned is denied.</summary>
    Task<bool> NurseHasQualifyingBookingForPatientAsync(long nurseProfileId, long patientId, CancellationToken cancellationToken);

    /// <summary>Patient-scoped longitudinal history, paginated, newest first — <b>ciphertext</b> bodies; the
    /// handler decrypts post-check.</summary>
    Task<PagedResult<CareRecordCipherRow>> GetPatientHistoryAsync(long patientId, int page, int pageSize, CancellationToken cancellationToken);

    /// <summary>The tracked family-owned care plan for a patient (for read + upsert). Null when none exists yet.</summary>
    Task<PatientCarePlan?> GetCarePlanAsync(long patientId, CancellationToken cancellationToken);

    /// <summary>Adds a new family-owned care plan (first PUT for a patient).</summary>
    Task AddCarePlanAsync(PatientCarePlan plan, CancellationToken cancellationToken);
}
