using adas_core.Domain.Enums;
using adas_core.Domain.Models;
using adas_core.Domain.Models.DTO;
using adas_core.Domain.Models.Masters;
using adas_core.Domain.Models.MongoModels;
using MongoDB.Bson;

namespace adas_core.Application.Services.Interfaces;

public interface IDischargeService : IApiRequestService
{
    /// <summary>
    /// Asynchronously retrieves a discharge record by its unique identifier, returning null if no matching discharge is found.
    /// </summary>
    /// <param name="dischargeId">The unique identifier of the discharge to look up.</param>
    /// <returns>A task that represents the asynchronous operation, containing the <see cref="Discharge"/> if found, or null when no record matches the provided identifier.</returns>
    Task<Discharge?> GetDischargeByIdAsync(ObjectId dischargeId);
    /// <summary>
    /// Asynchronously counts the number of discharge records associated with the specified unit.
    /// </summary>
    /// <param name="unitId">The identifier of the unit whose discharges should be counted.</param>
    /// <returns>A task that represents the asynchronous operation, containing the total number of discharges for the specified unit.</returns>
    Task<long> CountDischargesByUnitId(ObjectId unitId);
    /// <summary>
    /// Asynchronously deletes a discharge record identified by the specified identifier.
    /// </summary>
    /// <param name="dischargeId">The unique identifier of the discharge to delete.</param>
    Task DeleteDischargeByIdAsync(ObjectId dischargeId);
    /// <summary>
    /// Asynchronously deletes the specified discharge record.
    /// </summary>
    /// <param name="discharge">The discharge entity to be removed.</param>
    Task DeleteDischargeAsync(Discharge discharge);
    /// <summary>
    /// Asynchronously updates an existing discharge record in the data store.
    /// </summary>
    /// <param name="discharge">The <see cref="Discharge"/> entity containing the updated information to persist.</param>
    Task UpdateDischargeAsync(Discharge discharge);
    /// <summary>
    /// Asynchronously retrieves a collection of discharge records.
    /// </summary>
    /// <returns>A task that represents the asynchronous operation. The task result contains an enumerable collection of <see cref="Discharge"/> objects.</returns>
    Task<IEnumerable<Discharge>> GetDischargesAsync();
    /// <summary>
    /// Inserts a new discharge record into the data store. Returns the inserted <see cref="Discharge"/> entity, or <see langword="null"/> if the record could not be created.
    /// </summary>
    /// <param name="discharge">The <see cref="Discharge"/> entity containing the data to be inserted.</param>
    /// <returns>A <see cref="Task{T}"/> that resolves to the inserted <see cref="Discharge"/>, or <see langword="null"/> when the insertion does not produce a result.</returns>
    Task<Discharge?> InsertDischarge(Discharge discharge);
    /// <summary>
    /// Retrieves the discharge record associated with the specified patient location, returning null if no matching discharge is found.
    /// </summary>
    /// <param name="location">The patient location used to look up the discharge record.</param>
    /// <returns>A task that represents the asynchronous operation. The task result contains the matching <see cref="Discharge"/> if found, or null if no discharge is associated with the specified location.</returns>
    Task<Discharge?> GetDischargeByLocation(PatientLocation location);
    /// <summary>
    /// Retrieves the discharge record associated with the specified patient identifier.
    /// </summary>
    /// <param name="patientId">The unique identifier of the patient whose discharge record is being requested.</param>
    /// <returns>A <see cref="Task{Discharge}"/> that resolves to the matching <see cref="Discharge"/> if found; otherwise, <c>null</c>.</returns>
    Task<Discharge?> GetDischargeByPatientId(ObjectId patientId);
    /// <summary>
    /// Retrieves a discharge record associated with the specified point of care location identifier.
    /// </summary>
    /// <param name="location">The ObjectId of the point of care location used to look up the discharge.</param>
    /// <returns>A task that represents the asynchronous operation. The task result contains the matching <see cref="Discharge"/> if found, or <c>null</c> if no discharge exists for the specified point of care location.</returns>
    Task<Discharge?> GetDischargeByPointOfCareId(ObjectId location);
    /// <summary>
    /// Retrieves the discharge associated with the specified point of care location, returning localized data for the requested locale.
    /// Returns null when no matching discharge is found.
    /// </summary>
    /// <param name="location">The identifier of the point of care location whose discharge should be retrieved.</param>
    /// <param name="dataLocale">The locale used to determine the language of the returned discharge data.</param>
    /// <returns>A task containing the matching <see cref="Discharge"/>, or null if no discharge exists for the given location.</returns>
    Task<Discharge?> GetDischargeByPointOfCareIdWithLocale(ObjectId location, LocaleEnum dataLocale);
    /// <summary>
    /// Sends a broadcast notification for the specified discharge based on the given operation type.
    /// </summary>
    /// <param name="discharge">The discharge entity to be included in the broadcast.</param>
    /// <param name="operation">The type of operation (e.g., create, update, delete) that determines the broadcast context.</param>
    void SendDischargeBroadcast(Discharge discharge, OperationType operation);
    /// <summary>
    /// Updates a patient master list item change using the provided update options, applying the change across the specified unit list and master list type.
    /// </summary>
    /// <param name="opt">The update options describing the change to apply to the patient master list item.</param>
    /// <param name="unitList">The collection of units to which the master list item change should be applied.</param>
    /// <param name="typeName">The name of the master list type that identifies which list the item belongs to.</param>
    Task UpdatePatientMasterListItemChange(UpdateOptionMasterListDto opt, IEnumerable<Unit> unitList, string typeName);
    /// <summary>
    /// Deletes the specified patient master list item associated with the given option list and units.
    /// </summary>
    /// <param name="opt">The option list containing the patient master list item to delete.</param>
    /// <param name="unitList">The collection of units associated with the item to be deleted.</param>
    /// <param name="typeName">The name of the type used to identify the patient master list item.</param>
    /// <returns>A task that represents the asynchronous delete operation.</returns>
    Task DeletePatientMasterListItem(OptionList opt, IEnumerable<Unit> unitList, string typeName);
    /// <summary>
    /// Deletes discharge records associated with the specified unit identifier.
    /// </summary>
    /// <param name="unitId">The unique identifier of the unit whose discharge records should be removed.</param>
    Task DeleteDischargesByUnitId(ObjectId unitId);
}