using e_suite.API.Common.repository;
using e_suite.Database.Core;

namespace e_suite.Modules.ExceptionLogManager.Repository;

public class ExceptionLogRepository : RepositoryBase, IExceptionLogRepository
{
    public ExceptionLogRepository(IEsuiteDatabaseDbContext esuiteDatabaseDbContext) : base(esuiteDatabaseDbContext)
    {
    }

    public IQueryable<Database.Core.Tables.Diagnostics.ExceptionLog> GetExceptionLogs()
    {
        return DatabaseDbContext.ExceptionLogs;
    }

    public async Task<long> LogException(Database.Core.Tables.Diagnostics.ExceptionLog exception, CancellationToken cancellationToken)
    {
        await DatabaseDbContext.ExceptionLogs.AddAsync(exception, cancellationToken);
        await DatabaseDbContext.NoAuditSaveChangesAsync(cancellationToken);
        return exception.Id;
    }
}
