// Copyright © Selmo Technology GmbH. All Rights Reserved

using SelmoStudio.Hmi.Server.Alarms.Model;
using SelmoStudio.Hmi.Server.Alarms.Model.Dto;

namespace SelmoStudio.Hmi.Server.TestSetup
{
    internal class TestAlarmBuilder
    {
        private static int _totalNumberOfAlarms;

        private static IList<AlarmDto> _alarmDtos;

        internal TestAlarmBuilder(int totalNumber)
        {
            _alarmDtos = new List<AlarmDto>();
            _totalNumberOfAlarms = totalNumber;
        }

        internal IList<AlarmDto> Build()
        {
            for (var i = 1; i <= _totalNumberOfAlarms; i++)
            {
                _alarmDtos.Add(GetAlarmDto(i));
            }

            return _alarmDtos;
        }

        private AlarmDto GetAlarmDto(int errorNumber)
        {
            var id = Guid.NewGuid();

            AlarmDto alarmDto = new()
            {
                Id = new(id),
                Title = $"This is a long alarm title with the error number {errorNumber}",
                Message = $"This is the alarm object {id} with message number {errorNumber}",
                ErrorNo = errorNumber,
                Name = "Test error",
                Severity = RandomAlarmSeverity.Get(),
                Created = DateTimeOffset.Now,
            };

            return alarmDto;
        }
    }

    internal class RandomAlarmSeverity
    {
        internal static Severity Get()
        {
            var values = Enum.GetValues(typeof(Severity));
            var random = new Random();

            return (Severity)values.GetValue(random.Next(values.Length));
        }
    }
}