using InABox.Core;

namespace InABox.Database
{
    public interface IStore
    {
        bool IsSubStore { get; set; }

        Guid UserGuid { get; set; }
        string UserID { get; set; }

        Platform Platform { get; set; }
        string Version { get; set; }

        IProvider Provider { get; set; }

        Logger Logger { get; set; }
        
        Type Type { get; }
        
        // Called once at Database Startup to initialise caches etc
        void Init();
        
        CoreTable Query(IFilter? filter = null, IColumns? columns = null, ISortOrder? sort = null, CoreRange? range = null);
        
        void Save(Entity entity, string auditnote);
        void Save(IEnumerable<Entity> entities, string auditnote);
        void Delete(Entity entity, string auditnote);
        void Delete(IEnumerable<Entity> entities, string auditnote);

        public IStore<TEntity> FindSubStore<TEntity>() where TEntity : Entity, new();
    }

    public interface IStore<T> : IStore where T : Entity, new()
    {
        CoreTable Query(Filter<T>? filter = null, Columns<T>? columns = null, SortOrder<T>? sort = null, CoreRange? range = null);

        void Save(T entity, string auditnote);
        void Save(IEnumerable<T> entities, string auditnote);

        void Delete(T entity, string auditnote);
        void Delete(IEnumerable<T> entities, string auditnote);
    }
}