using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WebAPIBase.NetCore.BusinessCore
{
    public class Strategy
    {
        private ArrayList parameters = new ArrayList();

        private object m_Name;

        private string m_RelationFieldName;

        private StrategyType m_Type;

        public object Name => m_Name;

        public StrategyType Type
        {
            get
            {
                return m_Type;
            }
            set
            {
                m_Type = value;
            }
        }

        public string RelationFieldName
        {
            get
            {
                return m_RelationFieldName;
            }
            set
            {
                m_RelationFieldName = value;
            }
        }

        public Strategy(object name)
        {
            m_Name = name;
            m_Type = StrategyType.StringEqual;
            m_RelationFieldName = "";
        }

        public Strategy(object name, ArrayList pas)
        {
            m_Name = name;
            m_Type = StrategyType.StringEqual;
            m_RelationFieldName = "";
            parameters = pas;
        }

        public Strategy(object name, string param0)
        {
            m_Name = name;
            m_Type = StrategyType.StringEqual;
            m_RelationFieldName = "";
            parameters.Add(param0);
        }

        public Strategy(object name, string param0, string param1)
        {
            m_Name = name;
            m_Type = StrategyType.StringEqual;
            m_RelationFieldName = "";
            parameters.Add(param0);
            parameters.Add(param1);
        }

        public Strategy(object name, StrategyType type, string relationFieldName)
        {
            m_Name = name;
            m_Type = type;
            m_RelationFieldName = relationFieldName;
        }

        public Strategy(object name, StrategyType type, string relationFieldName, string param0)
        {
            m_Name = name;
            m_Type = type;
            m_RelationFieldName = relationFieldName;
            parameters.Add(param0);
        }

        public Strategy(object name, StrategyType type, string relationFieldName, ArrayList pas)
        {
            m_Name = name;
            m_Type = type;
            m_RelationFieldName = relationFieldName;
            parameters = pas;
        }

        public virtual void AddParameter(string parameterString)
        {
            parameters.Add(parameterString);
        }

        public virtual string GetParameter(int index)
        {
            if (index < 0 || index > parameters.Count)
            {
                throw new ApplicationException("索引越界");
            }
            if (Type == StrategyType.StringIn || Type == StrategyType.Other || Type == StrategyType.StringRange || Type == StrategyType.NumberIn)
            {
                return (string)parameters[index];
            }
            return (string)parameters[index];
        }

        public static string ReplaceSingleQuote(string s)
        {
            return s.Replace("'", "''");
        }

        public virtual void SetParameter(int index, string param)
        {
            parameters[index] = param;
        }

        public int GetParameterCount()
        {
            return parameters.Count;
        }

        public IEnumerator GetParameterEnumerator()
        {
            return parameters.GetEnumerator();
        }
    }
}
