using System;
using System.Linq;
using System.Windows.Media;

namespace BS.Shared.DataContracts.Compact
{
    public partial class CompactCustomerDC : IFilterableDC, IInvoiceRecipient
    {
        public string AddressString
        {
            get
            {
                string address = this.Street;
                if (address != null && address.Length > 0)
                {
                    address += ", ";
                }

                return address + this.PostalCode + " " + this.Town;
            }
        }

        public string DateOfBirthString
        {
            get
            {
                if (this.DateOfBirth != null)
                {
                    return "*" + this.DateOfBirth.Value.ToShortDateString();
                }

                return null;
            }
        }

        public decimal? DefaultAmount
        {
            get
            {
                return this.EquityContribution;
            }
        }

        public string DetailDescription
        {
            get
            {
                return this.ToString();
            }
        }

        public string FilterRelevants
        {
            get
            {
                string lResult = this.FirstName + " " + this.LastName + " ";
                if (this.CostBearerReferenceNumbers != null)
                {
                    lResult += string.Join(" ", this.CostBearerReferenceNumbers.Values.ToArray());
                }

                return lResult;
            }
        }

        public string FullName
        {
            get
            {
                return this.FirstName + " " + this.LastName;
            }
        }

        public string IconPath
        {
            get
            {
                return @"..\Ressources\Icons\UserHomeMaleDisabled.png";
            }
        }

        public string InvoiceAddressString
        {
            get
            {
                return this.Street + Environment.NewLine + this.PostalCode + " " + this.Town;
            }
        }

        public bool IsArchived
        {
            get { return ActivationType == ActivationTypeId.Archived; }
        }

	    public bool IsDeleted
	    {
		    get { return ActivationType == ActivationTypeId.Deleted; }
	    }

        public string Name
        {
            get
            {
                return this.FullName;
            }
        }

        public long? Oid
        {
            get
            {
                return this.CustomerOid;
            }
        }


        public SolidColorBrush FilterableBrush { get { return new SolidColorBrush(Colors.Transparent); } }

        public string SimpleDescription
        {
            get
            {
                if (!String.IsNullOrEmpty(CustomerAlias))
                {
                    return String.Format("{0} ({1})", ToString(), CustomerAlias);
                }

                return ToString();
            }
        }

        public bool SupportsActivationType
        {
            get
            {
                return true;
            }
        }

        public long Version
        {
            get
            {
                return this.CustomerVersion;
            }

            set
            {
                this.CustomerVersion = value;
            }
        }

        public override bool Equals(object obj)
        {
            if (obj is CompactCustomerDC)
            {
                return this.CustomerOid == ((CompactCustomerDC)obj).CustomerOid;
            }

            return false;
        }

        public override int GetHashCode()
        {
            return this.GetType().Name.GetHashCode() ^ this.CustomerOid.GetHashCode();
        }

        public override string ToString()
        {
	        if (String.IsNullOrEmpty(this.LastName))
		        return this.FirstName;
			if (String.IsNullOrEmpty(this.FirstName))
				return this.LastName;
            return this.LastName + ", " + this.FirstName;
        }

        public string LastNameFirstName
        {
            get { return ToString(); }
        }

        
    }
}