using adas_core.Domain.Enums;
using Newtonsoft.Json;

namespace adas_core.Domain.Models.Recording;

/// <summary>
/// Represents a data container for recording-related information.
/// </summary>
public class RecordingData
{
    public Patient? Patient { get; set; }
    public int RoomId { get; set; }
    public DateTime? StartRecordingTime { get; set; }
    public DateTime? StopRecordingTime { get; set; }
    public DateTime? EventTime { get; set; }
    public AlarmEnum.Type? AlarmType { get; set; }
    public AlarmEnum.Severity Severity { get; set; } = AlarmEnum.Severity.None;
    public string? AlarmDescription { get; set; }
    public string? AlarmName { get; set; }
    public string Store { get; set; } = string.Empty;
    public int Retry { get; set; }
    public string Status { get; set; } = string.Empty;

    /// <summary>
    /// Generates a unique store identifier by combining the RoomId with the current timestamp formatted as yyyyMMdd-HHmmss, and assigns it to the Store property.
    /// </summary>
    /// <returns>A formatted store identifier string in the pattern "RoomId_yyyyMMdd-HHmmss".</returns>
    public string GenerateStore()
        {
            return Store = $"{RoomId}_{DateTime.Now:yyyyMMdd-HHmmss}";
        }

    /// <summary>
    /// Returns a compact JSON representation of the current object. If JSON serialization fails for any reason, falls back to the base <see cref="object.ToString"/> implementation.
    /// </summary>
    /// <returns>A JSON string produced by <see cref="JsonConvert.SerializeObject(object, Formatting)"/> with <see cref="Formatting.None"/>, or the result of the base <see cref="object.ToString"/> when serialization throws.</returns>
    public override string ToString()
        {
            try
            {
                return JsonConvert.SerializeObject(this, Formatting.None);
            }
            catch
            {
                return base.ToString()!;
            }
        }
}