using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExtensiblePortfolioSite.SDK.Git
{
    /// <summary>
    /// Git Providers marked withi this attribute will be auto-imported at startup!
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
    public sealed class GitProviderAttribute : Attribute
    {
        /// <summary>
        /// The Service which this GitProvider is for
        /// </summary>
        public String WebSite { get; }

        /// <inheritdoc cref="GitProviderAttribute"/>
        /// <param name="WebSite">The Service which this GitProvider is for</param>
        public GitProviderAttribute(String WebSite)
        {
            this.WebSite = WebSite;
        }
    }

    /// <summary>
    /// a Git Provider
    /// </summary>
    public interface IGitProvider
    {
        /// <summary>
        /// Get a Git Object by its Reference String
        /// </summary>
        /// <param name="Reference">Reference String</param>
        public IGitObject GetByReference(GitReference Reference);

        /// <summary>
        /// Get a Repository by its Website URL
        /// </summary>
        /// <param name="Repository">Repsoitory URL</param>
        /// <returns></returns>
        public IRepository GetRepositoryByURL(Uri Repository) =>
            TryGetRepositoryByURL(Repository, out IRepository? repository)
                ? repository!
                : throw new GitObjectNotFoundException(GitReferenceKind.User, Repository);

        /// <summary>
        /// Attempts to Get a User Profile by its Website URL
        /// </summary>
        public Boolean TryGetRepositoryByURL(Uri UserProfile, out IRepository? Repository);

        /// <summary>
        /// Get a User Profile by its Website URL
        /// </summary>
        public IUser GetUserByURL(Uri UserProfile) =>
            TryGetUserByURL(UserProfile, out IUser? user)
                ? user!
                : throw new GitObjectNotFoundException(GitReferenceKind.User, UserProfile);

        /// <summary>
        /// Attempts to Get a User Profile by its Website URL
        /// </summary>
        public Boolean TryGetUserByURL(Uri UserProfile, out IUser? User);
    }
}
