using FreeSql;
using System;
using System.Collections.Generic;

namespace Binance.TradeRobot.Business.Extensions
{
    public static class FreeSqlExtension
    {
        public static ISelect<T1, T2, T3> WithLock<T1, T2, T3>(this ISelect<T1, T2, T3> that, SqlServerLock lockType = SqlServerLock.NoLock, Dictionary<Type, bool> rule = null) where T2 : class where T3 : class
        {
            return rule == null ?
                                 that.AsAlias((type, old) => $"{old} With({lockType})") :
                                 that.AsAlias((type, old) => rule.TryGetValue(type, out var trybool) && trybool ? $"{old} With({lockType.ToString()})" : old);
        }

    }
}