using System;

namespace StreamBuddy.PluginInterface
{
    /// <summary>
    /// Defines an author for a plugin, can be used multiple times for multiple authors
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public class AuthorAttribute : Attribute
    {
        /// <summary>
        /// The name of the author.
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// An email address where the author can be reached.
        /// </summary>
        public string Email { get; set; }
        /// <summary>
        /// A webpage for the author
        /// </summary>
        public string Webpage { get; set; }

        public override string ToString()
        {
            string ret = "";
            if (!string.IsNullOrEmpty(Name))
            {
                ret += Name;

                if (!string.IsNullOrEmpty(Email))
                    ret += " (";
            }

            if (!string.IsNullOrEmpty(Email))
            {
                ret += Email;

                if (!string.IsNullOrEmpty(Name))
                    ret += ")";
            }

            if (!string.IsNullOrEmpty(Webpage))
            {
                if (!string.IsNullOrEmpty(Name) || !string.IsNullOrEmpty(Email))
                    ret += " - ";
                ret += Webpage;
            }

            return ret;
        }
    }

    /// <summary>
    /// Defines required attributes for a plugin
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class PluginAttribute : Attribute
    {
        /// <summary>
        /// The name of the plugin.
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// A short description of the plugin.
        /// </summary>
        public string Description { get; set; }
        /// <summary>
        /// A list of dependent plugins that must exist and be loaded for this plugin to work.
        /// </summary>
        public string[] Dependencies { get; set; }

        /// <summary>
        /// Creates a new instance of the <seealso cref="PluginAttribute"/> class.
        /// </summary>
        /// <param name="Name">The name of the plugin.</param>
        public PluginAttribute(string Name)
        {
            this.Name = Name;
        }
    }

    /// <summary>
    /// Defines functions every plugin must implement.
    /// </summary>
    public interface IPlugin
    {
        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="PluginService">A <seealso cref="IPluginService"/> interface holding features for communicating with the bot and other plugins.</param>
        void Init(IPluginService PluginService);

        /// <summary>
        /// Called when the plugin is to be enabled.
        /// </summary>
        void Enable();
        /// <summary>
        /// Called when the plugin is to be disabled.
        /// </summary>
        void Disable();
        /// <summary>
        /// Called when all the data for the plugin is to be purged.
        /// </summary>
        void Purge();
    }
}
