using adas_core.Domain.Models;
using MongoDB.Bson;
using MongoDB.Driver;

namespace adas_core.Application.Repositories.Interfaces;

public interface IRecordingAlertRepository : IMongoRepository<PatientRecordingAlert>
{
    /// <summary>
    /// Retrieves an aggregated list of the most recent patient recording alerts for the specified patient.
    /// </summary>
    /// <param name="patientId">The unique identifier of the patient whose recent alerts are being retrieved.</param>
    /// <param name="num">The maximum number of recent observations to return.</param>
    /// <returns>A task that represents the asynchronous operation, containing a list of <see cref="PatientRecordingAlert"/> entries for the patient's last observations.</returns>
    Task<List<PatientRecordingAlert>> AggregatedPatientLastObservations(ObjectId patientId, int num);

    /// <summary>
    /// Retrieves the most recent observations of a specified type for a given patient.
    /// </summary>
    /// <param name="patientId">The unique identifier of the patient whose observations are queried.</param>
    /// <param name="name">The name of the observation to filter by.</param>
    /// <param name="num">The maximum number of recent observations to return. Defaults to 2.</param>
    /// <returns>A task that represents the asynchronous operation. The task result contains a list of <see cref="PatientRecordingAlert"/> entries representing the matching observations.</returns>
    Task<List<PatientRecordingAlert>> FindLastObservations(ObjectId patientId, string name, int num = 2);
    /// <summary>
    /// Asynchronously inserts a single <see cref="PatientRecordingAlert"/> into the underlying data store.
    /// </summary>
    /// <param name="patientRecordingAlert">The patient recording alert to be inserted.</param>
    new Task InsertOneAsync(PatientRecordingAlert patientRecordingAlert);
    /// <summary>
    /// Asynchronously deletes records older than the specified number of days, identified by the given name.
    /// </summary>
    /// <param name="name">The identifier or key used to locate the records to be evaluated for deletion.</param>
    /// <param name="value">The age threshold, in days, used to determine which records are considered older and eligible for deletion.</param>
    Task DeleteOlderDaysAsync(string name, int value);
    /// <summary>
    /// Asynchronously deletes a number record matching the specified name and value.
    /// </summary>
    /// <param name="name">The name associated with the number to delete.</param>
    /// <param name="value">The numeric value of the record to delete.</param>
    /// <returns>A task that represents the asynchronous delete operation.</returns>
    Task DeleteOlderNumberAsync(string name, int value);
    /// <summary>
    /// Asynchronously deletes records associated with the specified patient identifier.
    /// </summary>
    /// <param name="patientId">The unique <see cref="ObjectId"/> of the patient whose related records should be removed.</param>
    Task DeleteByPatientId(ObjectId patientId);
    /// <summary>
    /// Updates many records by replacing the specified <paramref name="oldId"/> with the new <paramref name="id"/> within the collection identified by <paramref name="nameId"/>.
    /// </summary>
    /// <param name="nameId">The name or identifier of the collection in which the update is performed.</param>
    /// <param name="id">The new ObjectId to assign to the matching records.</param>
    /// <param name="oldId">The existing ObjectId used to locate the records to be updated.</param>
    Task UpdateManyObjectId(string nameId, ObjectId id, ObjectId oldId);
    /// <summary>
    /// Asynchronously retrieves all patient recording alerts associated with the specified patient identifier.
    /// </summary>
    /// <param name="patientId">The unique identifier of the patient whose recording alerts are being queried.</param>
    /// <returns>A task that represents the asynchronous operation, containing an asynchronous cursor over the matching <see cref="PatientRecordingAlert"/> documents.</returns>
    Task<IAsyncCursor<PatientRecordingAlert>> FindByPatientIdAsync(ObjectId patientId);
}