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

namespace DatabaseEditor.BL.Filters.Conditions
{
    public class StringCondition<T> : PropertyCondition<T>
    {
        public StringCondition(LogicOperator logicOperator, string propertyName, StringOperator @operator, string text) 
            : base(logicOperator, propertyName, text.ToLower())
        {
            Operator = @operator;
        }

        public StringOperator Operator { get; }

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

        public override string Predicate
        {
            get
            {
                switch (Operator)
                {
                    case StringOperator.Equals:
                        return $"{PropertyName} == \"{PropertyValue}\"";
                    case StringOperator.NotEquals:
                        return $"{PropertyName} != \"{PropertyValue}\"";
                    case StringOperator.Contains:
                        return $"{PropertyName}.Contains(\"{PropertyValue}\")";
                    case StringOperator.StartsWith:
                        return $"{PropertyName}.StartsWith(\"{PropertyValue}\")";
                    default:
                        return String.Empty;
                }
            }
        }
    }
}
