using System.Collections.Generic;

namespace Quadarax.Foundation.Core.Value
{
    public class ValidatorContext
    {
        private readonly IDictionary<string, object> _context = new Dictionary<string, object>();

        public ValidatorContext()
        {
        }
        public ValidatorContext(IEnumerable<KeyValuePair<string,object>> initialContext)
        {
            if (initialContext != null)
                foreach (var item in initialContext)
                {
                    _context.Add(item);    
                }
        }

        public TValue GetValue<TValue>(string key)
        {
            return (TValue) _context[key];
        }

        public void SetValue<TValue>(string key, TValue value)
        {
            if (!_context.TryAdd(key, value))
                _context[key] = value;
        }

        public bool Exists(string key)
        {
            return _context.ContainsKey(key);
        }
    }
}
