using adas_core.Domain.Enums;
using MongoDB.Bson;

namespace adas_core.Domain.Models;

public class GroupedObservation
{
    public ObjectId PatientId { get; set; }
    public string? Name { get; set; } = string.Empty;

    public string? Group { get; set; } = string.Empty;

    public List<GroupedObservationObs> Observations { get; set; } = [];


    public override string ToString()
    {
        List<string> items =
        [
            $"name: {Name}",
            $"observations: {Observations} "
        ];
        return "PatientObservation[" + string.Join(", ", items) + "]";
    }

    public class GroupedObservationObs
    {
        public string Name { get; set; } = string.Empty;

        public GroupedObservationObsValue? First { get; set; }

        public GroupedObservationObsValue? Last { get; set; }

        public GroupedObservationObsValue? Min { get; set; }

        public GroupedObservationObsValue? Max { get; set; }

        public object? MinAlert { get; set; }

        public object? MaxAlert { get; set; }

        public GroupedObservationObsValue? Average { get; set; }

        public GroupedObservationObsValue? Sum { get; set; }

        public GroupedObservationObsValue? Count { get; set; }

        public GroupedObservationObsValue? HalfHour { get; set; }

        public GroupedObservationObsValue? LastFilled { get; set; }

        public DateTime Time { get; set; }

        public int? Shift { get; set; }

        public DateTime ShiftDate { get; set; }

        public bool IsFilled { get; set; }

        public override string ToString()
        {
            List<string> items = [$"name: {Name}"];
            if (First != null) items.Add($"first; {First}");
            if (Last != null) items.Add($"last; {Last}");
            if (Min != null) items.Add($"min; {Min}");
            if (Max != null) items.Add($"max; {Max}");
            if (Average != null) items.Add($"average; {Average}");
            if (Sum != null) items.Add($"sum; {Sum}");
            if (Count != null) items.Add($"count; {Count}");
            if (HalfHour != null) items.Add($"halfhour; {HalfHour}");
            if (MinAlert != null) items.Add($"minAlert; {MinAlert}");
            if (MaxAlert != null) items.Add($"maxAlert; {MaxAlert}");
            items.Add($"time; {Time}");
            items.Add($"shiftDate; {ShiftDate}");
            if (Shift != null) items.Add($"shift; {Shift}");


            return "GroupedObservationObs[" + string.Join(", ", items) + "]";
        }
    }

    public class GroupedObservationObsValue(object value, DateTime? time, StatusEnum.Type type = StatusEnum.Type.Ok)
    {
        public StatusEnum.Type Type { get; set; } = type;

        public object Value { get; set; } = value;

        public DateTime? Time { get; set; } = time;


        public override string ToString()
        {
            return $"value: {Value}, time: {Time}, status: {Type}";
        }
    }
}