using System.Linq.Expressions;

namespace ORM;

public interface IORM : IDisposable
{
    bool Initialize(IOrmProvider? notify = null);
    bool Open(string connectionString, DbType dbType, bool isAutoConnection = true);
    bool CreateDataBase(string dbName);
    bool CreateTable<T>(string? tableName = null) where T : class, new();

    /// <summary>
    /// this Insert Function can insert a single class or IList<T> class
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="data"></param>
    /// <returns></returns>
    bool Insert<T>(T data) where T : class, new();

    /// <summary>
    /// this Insert Function can insert a single class or IList<T> class
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="data"></param>
    /// <returns></returns>
    bool Insert<T>(string tablename, T data) where T : class, new();
    Task<bool> Query<T>(Action<List<T>> results) where T : class, new();
    Task<bool> Query<T>(string tableName, Action<List<T>> results) where T : class, new();
    Task<bool> Query<T>(Expression<Func<T, bool>> expression, Action<List<T>> results) where T : class, new();
    Task<bool> Query<T>(string tableName, Expression<Func<T, bool>> expression, Action<List<T>> results) where T : class, new();

    bool Delete<T>(string tableName, Expression<Func<T, bool>> expression) where T : class, new();
}

public interface IOrmProvider
{
    void Log(string log, DateTime dateTime, LogLevel logLevel);
}

public enum LogLevel
{
    Info,
    Warning,
    Error,
    Fatal,
    Original
}

//Copy from SqlSugar def
public enum DbType
{
    MySql = 0,
    SqlServer = 1,
    Sqlite = 2,
    Oracle = 3,
    PostgreSQL = 4,
    Dm = 5,
    Kdbndp = 6,
    Oscar = 7,
    MySqlConnector = 8,
    Access = 9,
    OpenGauss = 10,
    QuestDB = 11,
    HG = 12,
    ClickHouse = 13,
    GBase = 14,
    Odbc = 15,
    OceanBaseForOracle = 16,
    TDengine = 17,
    GaussDB = 18,
    OceanBase = 19,
    Tidb = 20,
    Vastbase = 21,
    PolarDB = 22,
    Doris = 23,
    Xugu = 24,
    GoldenDB = 25,
    TDSQLForPGODBC = 26,
    TDSQL = 27,
    HANA = 28,
    DB2 = 29,
    Custom = 900
}