﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Graphene.API.Service
{
    /// <summary>
    /// All events related to services
    /// </summary>
    public static class ServiceEvents
    {
        #region Handlers
        /// <summary>
        /// Used for handling service updates
        /// </summary>
        /// <param name="service">The service that is being updated</param>
        public delegate void ServiceUpdateHandler(Service service);
        #endregion

        #region Events
        /// <summary>
        /// Called when a service is loaded/initialized
        /// </summary>
        public static event ServiceUpdateHandler OnServiceLoad;
        /// <summary>
        /// Called when the service is unloaded/shutdown
        /// </summary>
        public static event ServiceUpdateHandler OnServiceUnload;

        /// <summary>
        /// Called when a service is started
        /// </summary>
        public static event ServiceUpdateHandler OnServiceStart;
        /// <summary>
        /// Called when a service is stopped
        /// </summary>
        public static event ServiceUpdateHandler OnServiceStop;
        /// <summary>
        /// Called when a service is being reloaded/restarted
        /// </summary>
        public static event ServiceUpdateHandler OnServiceReload;
        #endregion

        #region Functions
        internal static void RunServiceLoad(Service service) => OnServiceLoad?.Invoke(service);
        internal static void RunServiceUnload(Service service) => OnServiceUnload?.Invoke(service);

        internal static void RunServiceStart(Service service) => OnServiceStart?.Invoke(service);
        internal static void RunServiceStop(Service service) => OnServiceStop?.Invoke(service);
        internal static void RunServiceReload(Service service) => OnServiceReload?.Invoke(service);
        #endregion
    }
}
