using InABox.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InABox.Database;
public class DbConfigurationProvider<T> : IConfigurationProvider<T>
    where T : Entity, IRemotable, IPersistent, new()
{
    public string UserID { get; init; }

    public DbConfigurationProvider(string userID)
    {
        UserID = userID;
    }

    public void Delete(T entity, Action<Exception?>? callback = null)
    {
        DbFactory.NewProvider(Logger.Main).Delete(entity, UserID);
    }

    public T[] Load(Filter<T> filter)
    {
        return DbFactory.NewProvider(Logger.Main).Load(filter);
    }

    public CoreTable Query(Filter<T> filter, Columns<T> columns, SortOrder<T>? sort = null)
    {
        return DbFactory.NewProvider(Logger.Main).Query(filter, columns, sort);
    }

    public void Save(T entity)
    {
        DbFactory.NewProvider(Logger.Main).Save(entity);
    }

    public void Save(IEnumerable<T> entities)
    {
        DbFactory.NewProvider(Logger.Main).Save(entities);
    }
}
