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

using BS.Shared.Core;

namespace BS.Shared.DataContracts
{
    [DataContract]
    public partial class InvoiceBaseDC : IDataContract
    {
        private List<ContactDC> _RecipientContactInformations;

        private List<ContactDC> _SenderContactInformations;

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

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

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

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

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

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

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

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

        [DataMember]
        public int? DunningLetterCount { get; set; }

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

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

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

        [DataMember]
        public List<InvoiceItemDC> InvoiceItems { get; set; }

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

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

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

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

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

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

        public string PeriodString
        {
            get
            {
                return this.AccountingPeriodStart.Value.ToShortDateString() + " - "
                       + this.AccountingPeriodEnd.Value.ToShortDateString();
            }
        }

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

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

        [DataMember]
        public List<ContactDC> RecipientContactInformations
        {
            get
            {
                if (this._RecipientContactInformations == null)
                {
                    this._RecipientContactInformations = new List<ContactDC>();
                }

                return this._RecipientContactInformations;
            }

            set
            {
                this._RecipientContactInformations = value;
            }
        }

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

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

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

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

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

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

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

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

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

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

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

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

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

        [DataMember]
        public List<ContactDC> SenderContactInformations
        {
            get
            {
                if (this._SenderContactInformations == null)
                {
                    this._SenderContactInformations = new List<ContactDC>();
                }

                return this._SenderContactInformations;
            }

            set
            {
                this._SenderContactInformations = value;
            }
        }

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

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

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

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

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

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

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

        [DataMember]
        public SupportConceptCostBearerRelDC SupportConceptCostBearerRelDc { get; set; }

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

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

        [DataMember]
        public InvoiceType Type { get; set; }

        public bool ContainsRecipientAddressData()
        {
            return !Utils.AreAllNullOrEmpty(this.RecipientStreet, this.RecipientPostCode, this.RecipientTown);
        }

        public bool ContainsSenderAddressData()
        {
            return !Utils.AreAllNullOrEmpty(this.SenderStreet, this.SenderPostCode, this.SenderTown);
        }
    }
}