using Microsoft.Extensions.DependencyInjection;
using NetworkResurrector.Agent.Application.Services;
using NetworkResurrector.Agent.Application.Services.Abstractions;
using NetworkResurrector.Agent.Application.Services.Linux;
using NetworkResurrector.Agent.Application.Services.Windows;
using System;
using System.Runtime.InteropServices;

namespace NetworkResurrector.Agent.Application
{
    public static class DependencyInjectionExtensions
    {
        public static void AddApplicationServices(this IServiceCollection services)
        {
            services.AddSingleton<IParamProvider, ParamProvider>();
            services.AddSingleton<IValidationService, ValidationService>();

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                services.AddSingleton<ICliService, CmdService>();
                services.AddSingleton<IPowerService, WindowsPowerService>();
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                services.AddSingleton<ICliService, BashService>();
                services.AddSingleton<IPowerService, LinuxPowerService>();
            }
            else throw new Exception("Cannot register power services. Unknown operating system.");
        }
    }
}
