using System;
using DatabaseEditor.BL.Filters.Operators;

namespace DatabaseEditor.BL.Filters.Conditions
{
    public class IntegerCondition<T> : PropertyCondition<T>
    {
        public IntegerCondition(LogicOperator logicOperator, string propertyName, IntegerOperator @operator, int value)
            : base(logicOperator, propertyName, value)
        {
            Operator = @operator;
        }

        public IntegerOperator Operator { get; }

        public override string OperatorText => Operator.ToString();

        public override string Predicate
        {
            get
            {
                switch (Operator)
                {
                    case IntegerOperator.Equals:
                        return $"{PropertyName} == {PropertyValue}";
                    case IntegerOperator.NotEquals:
                        return $"{PropertyName} != {PropertyValue}";
                    case IntegerOperator.IsGreaterThan:
                        return $"{PropertyName} > {PropertyValue}";
                    case IntegerOperator.IsLowerThan:
                        return $"{PropertyName} < {PropertyValue}";
                    case IntegerOperator.IsGreaterOrEqualThan:
                        return $"{PropertyName} >= {PropertyValue}";
                    case IntegerOperator.IsLowerOrEqualThan:
                        return $"{PropertyName} <= {PropertyValue}";
                    case IntegerOperator.StartsWith:
                        return $"{PropertyName}.ToString().StartsWith(\"{PropertyValue}\")";
                    default:
                        return String.Empty;
                }
            }
        }
    }
}