using System.Collections.Generic;
using System.Text;

namespace Quadarax.Foundation.Core.Value
{
    public class ParameterizedString
    {
        private readonly string _parameterPrefix;
        private readonly string _parameterPostfix;
        private readonly string _initialString;
        private readonly IDictionary<string, string> _parameters;

        public ParameterizedString(string initialString,string parameterPrefix = "", string parameterPostfix = "")
        {
            _parameterPostfix = parameterPostfix;
            _parameterPrefix = parameterPrefix;

            _initialString = initialString;
            _parameters = new Dictionary<string, string>();
        }

        public bool AddParameter(string name, string value)
        {
            if(_parameters.ContainsKey(name))
            {
                return false;
            }
            _parameters.Add(name, value);
            return true;
        }

        public override string ToString()
        {
            var sb = new StringBuilder(_initialString);
            foreach (var key in _parameters.Keys)
            {
                sb.Replace(_parameterPrefix + key + _parameterPostfix, _parameters[key]);
            }
            return sb.ToString();
        }
    }
}
