using adas_core.Domain.Models.Masters;
using adas_core.Domain.Models.MongoModels;
using adas_core.Domain.Models.Pumps;
using adas_core.Domain.Models.Recording;
using Newtonsoft.Json;

namespace adas_core.Domain.Models;

/// <summary>
/// Represents an API request, encapsulating the data and configuration needed to invoke a remote or web service endpoint.
/// </summary>
public class ApiRequest
{
    // SIU
    public PatientAppointment? Appointment;

    // SIU
    public List<PatientAppointment>? Appointments;

    // OMP
    public PatientTreatment? Treatment;

    public List<PatientTreatment>? Treatments;
    public string? TraceId { get; set; }

    public string? TraceMessageId { get; set; }

    public string? Type { get; set; }

    public string? PatientNumber { get; set; }

    public Person? Patient { get; set; }

    public string? PatientId { get; set; }

    public DateTime? AdmTime { get; set; }

    public DateTime? DisTime { get; set; }


    public PatientLocation? Location { get; set; }

    //Chat
    public ChatMessage? ChatMessage { get; set; }

    //Recording
    public RecordingData? Recording { get; set; }

    //SurgeryRoomAlert
    public PatientLocation? AlertLocationFrom { get; set; }

    public PatientLocation? AlertLocationTo { get; set; }

    // ADT
    public PatientLocation? OldLocation { get; set; }

    public Person? AttendingDoctor { get; set; }

    public string? OldPatientNumber { get; set; }


    // ORU
    public ObservationData? ObservationData { get; set; }

    public ObservationData? ObsertationData
    {
        get => ObservationData;
        set => ObservationData = value;
    }

    public List<PatientObservation>? Observations { get; set; }

    public PatientObservation? Observation { get; set; }

    public List<PatientObservationAlarm>? Alarms { get; set; }

    public List<PumpObservation>? PumpObservations { get; set; }

    public PumpObservation? PumpObservation { get; set; }

    //DG1
    public List<PatientDiagnosis>? Diagnosis { get; set; }

    // ALERTS

    public List<PatientRecordingAlert>? RecordingAlerts { get; set; }

    public PatientRecordingAlert? RecordingAlert { get; set; }


    public DateTime MessageTime { get; set; }

    public bool WaitResult { get; set; }

    //ICCA db sync
    public List<PatientIcca>? IccaPatients { get; set; }

    public string? Facility { get; set; }

    //NursePlan
    public Admission? Admission { get; set; }
    public Discharge? Discharge { get; set; }

    public MasterList? MasterList { get; set; }

    public Notice? Notice { get; set; }

    public bool RequestFromPanel { get; set; }

    /// <summary>
    /// Returns a JSON string representation of the current object using <see cref="JsonConvert.SerializeObject(object, Formatting)"/> with no formatting.
    /// If serialization fails, falls back to the result of <see cref="object.ToString()"/>.
    /// </summary>
    /// <returns>A JSON string representation of the object, or the base <see cref="object.ToString()"/> result if serialization throws an exception.</returns>
    public override string? ToString()
        {
            try
            {
                return JsonConvert.SerializeObject(this, Formatting.None);
            }
            catch
            {
                return base.ToString();
            }
        }
}