// Copyright © Selmo Technology GmbH. All Rights Reserved

using Newtonsoft.Json;
using SelmoStudio.Hmi.Server.ProcessValue.Services;
using static SelmoStudio.Hmi.Server.SelmoHmi.Shared.TestImpl.TestValuesForDemo;

namespace SelmoStudio.Hmi.Server.Service
{
    public class ProcessValueLoadService : IProcessValueLoadService
    {
        internal static List<TestProcessValueInfo> LoadProzessValues(string name)
        {
            string selmoValue = $"./Values/{name}.json";
            if (!File.Exists(selmoValue))
            {
                return new();
            }

            string selmoValueString = File.ReadAllText(selmoValue);
            List<TestProcessValueInfo> prozessValues = JsonConvert.DeserializeObject<List<TestProcessValueInfo>>(selmoValueString)!;
            return prozessValues;
        }

        internal static List<TestProcessValueInfo> GetProcessValuesForSequence(string id)
        {
            string selmoParam = $"./SelmoHmi/Parameters/{id}.json";
            string selmoParamString = File.ReadAllText(selmoParam);
            List<TestProcessValueInfo> prozessValues = JsonConvert.DeserializeObject<List<TestProcessValueInfo>>(selmoParamString)!;
            return prozessValues;
        }
    }
}