using System;
using System.Text;

namespace BS.Shared.DataContracts
{
    public partial class SupportConceptCostBearerRelDC
    {
        public string DateRangeString
        {
            get
            {
                DateTime? start = this.StartDate;
                DateTime? end = this.EndDate;

                StringBuilder sb = new StringBuilder();
                if (start != null)
                {
                    sb.Append(start.Value.ToShortDateString());
                }

                sb.Append(" - ");
                if (end != null)
                {
                    sb.Append(end.Value.ToShortDateString());
                }

                return sb.ToString();
            }
        }

        public DateTime? EndDate
        {
            get
            {
                DateTime? end = this.ApprovedEndDate;
                if (end == null)
                {
                    end = this.RequestedEndDate;
                }

                return end;
            }
        }

        public DateTime? StartDate
        {
            get
            {
                DateTime? start = this.ApprovedStartDate;
                if (start == null)
                {
                    start = this.RequestedStartDate;
                }

                return start;
            }
        }

        public override bool Equals(object obj)
        {
            if (obj is SupportConceptCostBearerRelDC)
            {
                var y = (SupportConceptCostBearerRelDC)obj;
                if (this.CostBearer2SupportConceptOid == null && y.CostBearer2SupportConceptOid == null)
                {
                    return this.GetHashCode() == y.GetHashCode();
                }

                if (this.CostBearer2SupportConceptOid != null && y.CostBearer2SupportConceptOid != null)
                {
                    return this.CostBearer2SupportConceptOid == y.CostBearer2SupportConceptOid;
                }
            }

            return false;
        }

        public override int GetHashCode()
        {
            return this.CostBearer2SupportConceptOid.HasValue ? this.GetType().Name.GetHashCode() ^ this.CostBearer2SupportConceptOid.GetHashCode() : base.GetHashCode();
        }

        public override string ToString()
        {
            return this.CostBearer.Name;
        }
    }
}