using ExtensiblePortfolioSite.SDK.Plugins;

using System;
using System.Collections.Generic;

namespace ExtensiblePortfolioSite.SDK.Git
{
    /// <summary>
    /// Git Manager for Getting Different Git Services
    /// </summary>
    public static class GitManager
    {
        private static readonly SortedDictionary<String, GitService> Providers = new();

        internal static GitService GetOrCreate(String Service)
        {
            if (Providers.TryGetValue(Service, out GitService? Git))
                return Git;

            lock(Providers)
            {
                if (Providers.TryGetValue(Service, out Git))
                    return Git;

                Git = new GitService(Service);
                Providers.Add(Service, Git);
                return Git;
            }
        }

        /// <summary>
        /// Get a Git Service Provider
        /// </summary>
        /// <param name="Service"></param>
        /// <exception cref="KeyNotFoundException"/>
        /// <returns></returns>
        public static GitService GetService(String Service) => Providers[Service];
    }
}
