using System;

namespace ExtensiblePortfolioSite.SDK.Git
{
    /// <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 URL, out IRepository? Repository);

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

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