using InABox.Core;

namespace InABox.Database
{
    public delegate void LogEvent(LogType type, string message);

    public interface IProvider
    {
        string URL { get; set; }
        Type[] Types { get; set; }

        Dictionary<string, Type> GetSchema();
        void CreateSchema(params Type[] types);
        void UpgradeSchema(params Type[] types);
        void SaveSchema(Dictionary<string, Type> schema);
        void ForceRecreateViews();

        void Start();

        IEnumerable<object[]> List<T>(Filter<T>? filter = null, Columns<T>? columns = null, SortOrder<T>? sort = null) where T : Entity, new();
        
        CoreTable Query<T>(Filter<T>? filter = null, Columns<T>? columns = null, SortOrder<T>? sort = null, int top = int.MaxValue, bool log = false, bool distinct = false) where T : Entity, new();
        
        /// <summary>
        /// Same as <see cref="Query{T}(Filter{T}, Columns{T}, SortOrder{T}, int, bool)"/>, but only for deleted items
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="deletion"></param>
        /// <param name="filter"></param>
        /// <param name="columns"></param>
        /// <param name="sort"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        CoreTable QueryDeleted<T>(Deletion deletion, Filter<T>? filter = null, Columns<T>? columns = null, SortOrder<T>? sort = null, int top = int.MaxValue, bool deleted = false) where T : Entity, new();

        T[] Load<T>(Filter<T>? filter = null, SortOrder<T>? sort = null) where T : Entity, new();

        void Save<T>(T entity) where T : Entity;
        void Save<T>(IEnumerable<T> entities) where T : Entity;

        void Delete<T>(T entity, string userID) where T : Entity, new();
        void Delete<T>(IEnumerable<T> entities, string userID) where T : Entity, new();

        void Purge<T>(T entity) where T : Entity;
        void Purge<T>(IEnumerable<T> entities) where T : Entity;

        void Purge(Deletion deletion);
        void Recover(Deletion deletion);

        List<Type> GetDeletionTypes(Deletion deletion);

        event LogEvent OnLog;
    }
}