﻿using System.Collections.Generic;
using OGDC.Silverlight.Toolkit.Services.Services;
using nRoute.Services;
using nRoute.Components.Composition;

namespace OGDC.Silverlight.Toolkit.Services.Implementations.Services
{
    [MapService(typeof(IClipboardService), Lifetime=InstanceLifetime.Singleton)]
    public class ClipboardService : IClipboardService
    {
        private Dictionary<ClipboardSections, object> _clipboard;

        public ClipboardService()
        {
            _clipboard = new Dictionary<ClipboardSections, object>();
        }

        public T Paste<T>()
        {
            return Paste<T>(ClipboardSections.General);
        }

        public T Paste<T>(ClipboardSections section)
        {
            object o;

            var op = _clipboard.TryGetValue(section, out o);

            if (op)
                return (T)o;
            return default(T);
        }

        public void Copy<T>(T value)
        {
            Copy(ClipboardSections.General, value);
        }

        public void Copy<T>(ClipboardSections section, T value)
        {
            if (_clipboard.ContainsKey(section))
                _clipboard.Remove(section);

            _clipboard.Add(section, value);
        }
    }
}
