using System.Linq.Expressions;

namespace ThingsGateway.SqlSugar
{
    public class CoalesceResolveItems : MethodCallExpressionResolve
    {
        public CoalesceResolveItems(ExpressionParameter parameter) : base(parameter)
        {
            string name = "IsNull";
            var express = base.Expression as BinaryExpression;
            var args = new List<Expression>() {
                express.Left,
                express.Right
            };
            var isLeft = parameter.IsLeft;
            MethodCallExpressionModel model = new MethodCallExpressionModel();
            model.Args = new List<MethodCallExpressionArgs>();
            switch (this.Context.ResolveType)
            {
                case ResolveExpressType.WhereSingle:
                case ResolveExpressType.WhereMultiple:
                    if (name == "GetSelfAndAutoFill") { throw new SqlSugarException("SqlFunc.GetSelfAndAutoFill can only be used in Select."); }
                    base.Where(parameter, isLeft, name, args, model);
                    break;
                case ResolveExpressType.SelectSingle:
                case ResolveExpressType.SelectMultiple:
                case ResolveExpressType.Update:
                    base.Select(parameter, isLeft, name, args, model);
                    break;
                case ResolveExpressType.FieldSingle:
                case ResolveExpressType.FieldMultiple:
                    base.Field(parameter, isLeft, name, args, model);
                    break;
                default:
                    break;
            }
        }
    }
}
