using NPin.Framework.SqlSugarCore.Abstractions;
using Volo.Abp.Uow;

namespace NPin.Framework.SqlSugarCore.Uow;

public class SqlSugarTransactionApi : ITransactionApi, ISupportsRollback
{
    private ISqlSugarDbContext _sqlSugarDbContext;

    public SqlSugarTransactionApi(ISqlSugarDbContext sqlSugarDbContext)
    {
        _sqlSugarDbContext = sqlSugarDbContext;
    }

    public ISqlSugarDbContext GetDbContext()
    {
        return _sqlSugarDbContext;
    }

    public void Dispose()
    {
    }

    public async Task CommitAsync(CancellationToken cancellationToken = default)
    {
        await _sqlSugarDbContext.SqlSugarClient.Ado.CommitTranAsync();
    }

    public async Task RollbackAsync(CancellationToken cancellationToken = default)
    {
        await _sqlSugarDbContext.SqlSugarClient.Ado.RollbackTranAsync();
    }
}