namespace Server.Model
{
    public class InvoiceModel
    {
        public bool DeletionAllowed { get; set; }
        
        public string? InvoiceId { get; set; }
        public DateTime IssueDate { get; set; } = DateTime.Today;

        public Address? Seller { get; set; }
        public Address? Customer { get; set; }

        public List<OrderItem> Items { get; set; } = new();
        public string? Comment { get; set; }

        public PaymentData? PaymentData { get; set; }
        
        public double TotalNetto => Items?.Sum(x => x.PriceNetto*x.Quantity) ?? 0d;
    }

    public class PaymentData
    {
        public string BankName { get; set; }
        public string Iban { get; set; }
        public string Bic { get; set; }
    }

    public class OrderItem
    {
        public string Name { get; set; }
        public double PriceNetto { get; set; }
        public double PriceBrutto
        {
            get
            {
                switch (TaxType)
                {
                    case TaxType.Tax19:
                    default:
                        return PriceNetto * 1.19;
                        break;
                    case TaxType.Tax7:
                        return PriceNetto *1.07;
                        break;
                }
            }
        }

        public double Quantity { get; set; } = 1d;
        public TaxType TaxType { get; set; } = TaxType.Tax19;
        public string? Description { get; set; }
    }

    public class Address
    {
        public RecordState State { get; set; }
        public string? Name { get; set; }
        public string? Name2 { get; set; }
        public string? Street { get; set; }
        public string? City { get; set; }
        public string? Zip { get; set; }
        public string? Email { get; set; }
        public string? Phone { get; set; }
        public string? Web { get; set; }
        public string? TaxId { get; set; }

        public override string ToString() => $"{Name} - {Street} - {Zip} {City}";
    }

    public enum TaxType
    {
        Tax19 = 19,
        Tax7 = 7
    }
}