// Copyright © Selmo Technology GmbH. All Rights Reserved

using Novus.Connectivity.Common;
using SelmoStudio.Hmi.Common.SelmoProject.Ids;
using SelmoStudio.Hmi.Server.SelmoHmi.Model.Dtos;
using SelmoStudio.Hmi.Server.SelmoHmi.Shared.Mappers;

namespace SelmoStudio.Hmi.Server.SelmoHmi.Shared.Model
{
    public class WaitingForData
    {
        public WaitingForData(List<ZoneDto> zones)
        {
            // TODO get translation texts
            InitZoneInfo(zones);
        }

        private bool _zoneInfoInit = false;
        private Dictionary<SelmoHmiZoneId, string> _zoneInfo = new();

        private Dictionary<SelmoHmiZoneId, string> InitZoneInfo(List<ZoneDto> zones)
        {
            if (!_zoneInfoInit)
            {
                foreach (var zone in zones)
                {
                    if (string.IsNullOrEmpty(zone.HmiDisplayText))
                    {
                        _zoneInfo.Add(new(zone.Id.Guid), $"{zone.Name}");
                    }
                    else
                    {
                        _zoneInfo.Add(new(zone.Id.Guid), $"{zone.HmiDisplayText}");
                    }
                }

                _zoneInfoInit = true;
            }
            return _zoneInfo;
        }

        public List<string> GetWaitingForInfo(List<SelmoHmiWaitingForId> ids, List<(SelmoHmiZoneId, ProcessValueId)> _waitingForZoneId)
        {
            var allTexts = WaitingInfoText.Get(ids);

            foreach (var wf in _waitingForZoneId)
            {
                if (_zoneInfo.ContainsKey(wf.Item1))
                {
                    allTexts.Add(_zoneInfo[wf.Item1]);
                }
            }
            return allTexts;
        }
    }
}