﻿using System;

namespace Einstein.DataAccess
{

	[AttributeUsage(AttributeTargets.Property, AllowMultiple = true, Inherited = true)]
	public class ForeignKeyAttribute : Attribute
	{
		public ForeignKeyAttribute(Type referencedType, string referencedProperty)
		{
			if (referencedType == null)
				throw new ArgumentNullException("referencedType");
			if (string.IsNullOrWhiteSpace(referencedProperty))
				throw new ArgumentNullException("referencedProperty");
			if (referencedType.GetProperty(referencedProperty) == null)
				throw new ArgumentException(string.Format("'{0}' does not exist on for type '{1}'", referencedProperty, referencedType.FullName));
			_referencedType = referencedType;
			_referencedProperty = referencedProperty;
		}

		private readonly Type _referencedType;
		private readonly string _referencedProperty;

		public Type ReferencedType { get { return _referencedType; } }
		public string ReferencedProperty { get { return _referencedProperty; } }
	}
}
