using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace Cryville.Crtr.Config {
	public interface IPropertyMasterAdapter {
		string DefaultCategory { get; }
		IEnumerable<IPropertyAdapter> GetProperties();
	}
	public class DefaultPropertyMasterAdapter : IPropertyMasterAdapter {
		readonly object _target;

		public DefaultPropertyMasterAdapter(object target) {
			if (target == null) throw new ArgumentNullException("target");
			_target = target;
		}

		public string DefaultCategory { get { return "miscellaneous"; } }

		public IEnumerable<IPropertyAdapter> GetProperties() {
			return _target.GetType().GetProperties().Where(p => {
				var attrs = p.GetCustomAttributes(typeof(BrowsableAttribute), true);
				if (attrs.Length == 0) return true;
				else return ((BrowsableAttribute)attrs.Single()).Browsable;
			}).Select(p => new DefaultPropertyAdapter(_target, p));
		}
	}
}
