using e_suite.Database.Audit;
using e_suite.Database.Audit.AuditEngine;
using e_suite.Database.Core;
using Microsoft.EntityFrameworkCore;
using Moq;

namespace e_suite.UnitTestCore;

public class FakeRepository : IRepository
{
    public async Task<T> TransactionAsync<T>(Func<Task<T>> action)
    {
        return await action();
    }

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

    protected static DbSet<T> GetQueryableMockDbSet<T>(List<T> sourceList) where T : class
    {
        var queryable = sourceList.AsQueryable();

        var dbSet = new Mock<DbSet<T>>();
        dbSet.As<IQueryable<T>>().Setup(m => m.Provider).Returns(queryable.Provider);
        dbSet.As<IQueryable<T>>().Setup(m => m.Expression).Returns(queryable.Expression);
        dbSet.As<IQueryable<T>>().Setup(m => m.ElementType).Returns(queryable.ElementType);
        dbSet.As<IQueryable<T>>().Setup(m => m.GetEnumerator()).Returns(() => queryable.GetEnumerator());
        dbSet.Setup(d => d.Add(It.IsAny<T>())).Callback<T>((s) => sourceList.Add(s));

        return dbSet.Object;
    }

    public Task<int> AddAdhocAuditEntry(AuditUserDetails auditUserDetails, AuditType auditType, Dictionary<string, Change> fields, CancellationToken cancellationToken)
    {
        throw new NotImplementedException();
    }
}