using adas_core.Domain.Models.MongoModels;
using adas_core.Domain.Models.Pumps;
using MongoDB.Bson;
using Newtonsoft.Json;

namespace adas_core.Domain.Models;

/// <summary>
/// Represents a request payload for the administrative panel operations.
/// </summary>
public class AdmPanelRequest
{
    public string? Type { get; set; }

    public string? PatientNumber { get; set; }

    public Person? Patient { get; set; }

    public string? PatientId { get; set; }

    public string? Id { get; set; }

    public DateTime? AdmTime { get; set; }

    public DateTime? DisTime { get; set; }


    public PatientLocation? Location { get; set; }

    public ObjectId? PointOfCareId { get; set; }
    public ObjectId? UnitId { 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<PumpObservation>? PumpObservations { get; set; }

    public PumpObservation? PumpObservation { get; set; }


    public string SectionId { get; set; } = string.Empty;

    public string SectionItemGroup { get; set; } = string.Empty;

    public Box? SectionItemBoxUpdated { get; set; }

    public Dictionary<string, object>? SectionItems { get; set; }

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