using System;
using System.Collections.Generic;
using System.Drawing;
using InABox.Core;

namespace InABox.Clients
{
    
    
    public interface IClient
    {
        IValidationData Validate(string userid, string password, Guid session = default);
        IValidationData Validate(string pin, Guid session = default);
        IValidationData Validate(Guid session);

        CoreTable Query(object? filter = null, object? columns = null, object? sort = null);
        Entity[] Load(object? filter = null, object? sort = null);
        void Save(object entity, string auditnote);
        void Save(IEnumerable<object> entities, string auditnote);
        void Delete(object entity, string auditnote);
        void Delete(IList<object> entities, string auditnote);
        Dictionary<string, CoreTable> QueryMultiple(Dictionary<string, IQueryDef> queries);

        bool Check2FA(string code, Guid? session = null);

        /// <summary>
        /// Check if the server is running
        /// </summary>
        /// <returns><c>true</c> if the server is running</returns>
        bool Ping();
        
        /// <summary>
        /// Get general information about this server
        /// </summary>
        /// <returns>DatabaseInfo</returns>
        DatabaseInfo Info();

        IEnumerable<string> SupportedTypes();
        
        event LogEvent OnLog;

        bool IsConnected();

    }

    public interface IClient<TEntity> : IClient where TEntity : Entity, new()
    {
        CoreTable Query(Filter<TEntity>? filter = null, Columns<TEntity>? columns = null, SortOrder<TEntity>? sort = null);
        void Query(Filter<TEntity>? filter, Columns<TEntity>? columns, SortOrder<TEntity>? sort, Action<CoreTable?, Exception?> callback);

        TEntity[] Load(Filter<TEntity>? filter = null, SortOrder<TEntity>? sort = null);
        void Load(Filter<TEntity>? filter, SortOrder<TEntity>? sort, Action<TEntity[]?, Exception?> callback);

        void Save(TEntity entity, string auditnote);
        void Save(IEnumerable<TEntity> entities, string auditnote);
        void Save(TEntity entity, string auditnote, Action<TEntity, Exception?> callback);
        void Save(IEnumerable<TEntity> entity, string auditnote, Action<IEnumerable<TEntity>, Exception?> callback);

        void Delete(TEntity entity, string auditnote);
        void Delete(IList<TEntity> entities, string auditnote);
        void Delete(TEntity entity, string auditnote, Action<TEntity, Exception?> callback);
        void Delete(IList<TEntity> entity, string auditnote, Action<IList<TEntity>, Exception?> callback);
        
    }

}