using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GreenTree.Nachtragsmanagement.Web.Models.Appendix
{
    public class InvoiceDataModel
    {
        public int Id { get; set; }
        public int? CustomNumber { get; set; }
        public decimal? Value { get; set; }
        public DateTime? DateTime { get; set; }
        public int? AppendixId { get; set; }

        public static InvoiceDataModel FromInvoice(Core.Domain.Invoice.Invoice invoiceEntity, bool newWhenIsNull)
        {
            if (invoiceEntity == null && newWhenIsNull)
                return new InvoiceDataModel
                {
                    Id = -1
                };

            if (invoiceEntity == null && !newWhenIsNull)
                throw new ArgumentNullException("invoiceEntity", "Cannot create InvoiceDataModel from NULL invoice entity.");

            return new InvoiceDataModel
            {
                Id = invoiceEntity.Id,
                AppendixId = invoiceEntity.AppendixId,
                CustomNumber = invoiceEntity.CustomNumber,
                DateTime = invoiceEntity.Date,
                Value = invoiceEntity.Value
            };
        }

        public Core.Domain.Invoice.Invoice ToInvoice()
        {
            return new Core.Domain.Invoice.Invoice
            {
                Id = this.Id,
                AppendixId = this.AppendixId.Value,
                CustomNumber = this.CustomNumber.Value,
                Date = this.DateTime.Value,
                Value = this.Value.Value
            };
        }
    }
}