using adas_core.Domain.Utils;

namespace adas_core.Domain.Models.Observations;

/// <summary>
/// Represents an observation that captures a double-precision floating-point measurement or value.
/// Inherits from the base <see cref="Observation"/> type, providing a specialized observation variant for numeric data of type <see cref="double"/>.
/// </summary>
public class DoubleObservation : Observation
{
    public double? Value { get; set; }
    public double? LastValue { get; set; }

    /// <summary>
    /// Creates a <see cref="DoubleObservation"/> from a list of <see cref="PatientObservation"/> instances, using the first element's value as the primary <c>Value</c> and the second element's value as the <c>LastValue</c> when available.
    /// </summary>
    /// <param name="obs">The list of patient observations to convert. At least one element is required to produce a result.</param>
    /// <returns>A <see cref="DoubleObservation"/> populated with the converted double values, or <c>null</c> if the list is empty.</returns>
    public static DoubleObservation? From(List<PatientObservation> obs)
        {
            if (obs.Count > 0)
            {
                var val = new DoubleObservation
                {
                    Value = obs[0].Value.ToDouble()
                };
                if (obs.Count > 1) val.LastValue = obs[1].Value.ToDouble();
                return val;
            }
    
            return null;
        }
}