// Copyright © Selmo Technology GmbH. All Rights Reserved

using Novus.Connectivity.Common;
using SelmoStudio.Hmi.Server.Shared.Components.Chart;
using SelmoStudio.Hmi.Server.Service;
using System;

namespace SelmoStudio.Hmi.Server.SelmoHmi.DataRecords.Service
{
    public class HistoryDataService : IHistoryDataService
    {
        public Task<List<GraphDataSet>> GetData(DateTimeOffset from, DateTimeOffset to,
            params IProcessValueInfo[] processvalues)
        {
            return CreateTestData();
        }

        #region Test Data

        private async Task<List<GraphDataSet>> CreateTestData()
        {
            List<GraphDataSet> datasets = new List<GraphDataSet>();

            //var yesterday = DateTimeOffset.Now.AddDays(-1);
            var yesterday = DateTimeOffset.Now;

            datasets.Add(CreateTestDataSet("Test Value 1", yesterday));
            //datasets.Add(CreateTestDataSet("Test Value 2", yesterday));
            //datasets.Add(CreateTestDataSet("Test Value 3", yesterday));

            return datasets;
        }

        private GraphDataSet CreateTestDataSet(string nameValue, DateTimeOffset startDate)
        {
            Random random = new();

            var data = new List<GraphData>();

            for (var j = 0; j < 50; j++)
            {
                data.Add(new GraphData
                {
                    Timestamp = startDate.AddSeconds(j),
                    Value = random.NextDouble() * 10
                });
            }

            GraphDataSet dataSet = new GraphDataSet()
            {
                Name = nameValue,
                Data = data
            };
            return dataSet;
        }

        #endregion Test Data
    }
}