using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

using BS.Shared.DataContracts.Compact;

namespace BS.Shared.DataContracts
{
    [DataContract]
    public partial class SupportConceptCostBearerRelDC : IDataContract
    {
        // [DataMember]
        // public decimal HourlyRate { get; set; }
        [DataMember]
        public List<SupportConceptApprovalPeriodDC> ApprovalPeriodList { get; set; }

        [DataMember]
        public DateTime? ApprovedEndDate { get; set; }

        //[DataMember]
        //public decimal? ApprovedFLS { get; set; }

        //[DataMember]
        //public decimal? ApprovedFLSTotal { get; set; }

        [DataMember]
        public DateTime? ApprovedStartDate { get; set; }

        [DataMember]
        public CompactOrganisationDC CostBearer { get; set; }

        [DataMember]
        public long? CostBearer2SupportConceptOid { get; set; }

        [DataMember]
        public long? CostBearer2SupportConceptVersion { get; set; }

        [DataMember]
        public CompactPersonDC CostBearerContactPerson { get; set; }

        [DataMember]
        public string CustomerReferenceNumber { get; set; }
        
        [DataMember]
        public string AuswahlBezeichnung { get; set; }

        [DataMember]
        public decimal? MonthlyPayment { get; set; }

        [DataMember]
        public bool NoRelationExists { get; set; }

        [DataMember]
        public string Notice { get; set; }

        [DataMember]
        public DateTime? RequestedEndDate { get; set; }

        [DataMember]
        public DateTime? RequestedStartDate { get; set; }

        [DataMember]
        public CostBearer2SupportConceptStatus Status { get; set; }

        [DataMember]
        public CompactSupportConceptDC SupportConcept { get; set; }
        

        public TimeSpan? GetApprovedDuration()
        {
            DateTime? start = this.ApprovedStartDate;
            DateTime? end = this.ApprovedEndDate;

            if (!start.HasValue)
                start = this.RequestedStartDate;
            if (!end.HasValue)
                end = this.RequestedEndDate;

            if (!start.HasValue || !end.HasValue)
            {
                return null;
            }
            TimeSpan ts = end.Value - start.Value;
            ts = ts.Add(new TimeSpan(1, 0, 0, 0));
            return ts;
        }
    }
}