using e_suite.Database.Audit;
using e_suite.Database.Audit.AuditEngine;

namespace e_suite.Database.Core;

public class RepositoryBase : IRepository
{
    protected readonly IEsuiteDatabaseDbContext DatabaseDbContext;

    public RepositoryBase(IEsuiteDatabaseDbContext databaseDbContext)
    {
        DatabaseDbContext = databaseDbContext;
    }

    public async Task<T> TransactionAsync<T>(Func<Task<T>> func)
    {
        return await DatabaseDbContext.TransactionAsync(func);
    }

    public async Task TransactionAsync(Func<Task> action)
    {
        await DatabaseDbContext.TransactionAsync(action);
    }

    public async Task<int> AddAdhocAuditEntry(
        AuditUserDetails auditUserDetails,
        AuditType auditType,
        Dictionary<string, Change> fields,
        CancellationToken cancellationToken
    )
    {
        return await DatabaseDbContext.AddAdhocAuditEntry(auditUserDetails, auditType, fields, cancellationToken);
    }
}