using Hotline.Repository.SqlSugar.DataPermissions;
using Hotline.Settings;
using Hotline.Share.Tools;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XF.Domain.Dependency;

namespace Hotline.Repository.SqlSugar.System;
public class SystemLogRepository : BaseRepository<SystemLog>, ISystemLogRepository, IScopeDependency
{
    public SystemLogRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder) : base(uow, dataPermissionFilterBuilder)
    {
    }

    public async Task AddAsync(string name, string executeParam = "", string remark = "", string executeUrl = "", int status = 0)
    {
        try
        {
            var entity = new SystemLog
            {
                Name = name,
                ExecuteParam = executeParam,
                ExecuteUrl = executeUrl,
                Remark = remark,
                Status = status
            };
            if (executeUrl.IsNullOrEmpty())
            {
                try
                {
                    entity.ExecuteUrl = new StackTrace().GetFrame(1).GetMethod().Name;
                }
                catch { }
            }
            await AddAsync(entity);
        }
        catch
        {
            // ignore
        }
    }
}
