namespace adas_core.Domain.Models.Observations;

/// <summary>
/// Represents a complete observation as a specialized form of the <see cref="Observation"/> base class.
/// </summary>
public class FullObservation : Observation
{
    public DateTime LastObservationDate;

    public DateTime ObservationDate;
    public string? Text { get; set; }
    public required object Value { get; set; }
    public object? LastValue { get; set; }
    public double? Min { get; set; }
    public double? Max { get; set; }

    public double? MinAlert { get; set; }
    public double? MaxAlert { get; set; }

    public double? MinWarn { get; set; }
    public double? MaxWarn { get; set; }

    /// <summary>
    /// Creates a <see cref="FullObservation"/> from a list of <see cref="PatientObservation"/> records, using the first entry's data and, when available, the second entry's value and time as the last observation. Returns <c>null</c> when the provided list is empty.
    /// </summary>
    /// <param name="obs">The list of patient observations to convert; only the first two entries are used when present.</param>
    /// <returns>A <see cref="FullObservation"/> built from the first observation, or <c>null</c> if <paramref name="obs"/> contains no items.</returns>
    public static FullObservation? From(List<PatientObservation> obs)
        {
            if (obs.Count > 0)
                return new FullObservation
                {
                    Text = obs[0].Name,
                    Value = obs[0].Value,
                    Min = obs[0].Min,
                    Max = obs[0].Max,
                    ObservationDate = obs[0].Time,
                    LastValue = obs.Count > 1 ? obs[1].Value : null,
                    LastObservationDate = obs.Count > 1 ? obs[1].Time : DateTime.MinValue
                };
            return null;
        }
}