using System;
using System.Collections.Generic;
namespace AfterHours.Economy
{
/// Eine Position einer Großhandelsbestellung.
[Serializable]
public struct OrderLine
{
public int ProductId;
public int Quantity;
public float UnitPrice;
public float LineTotal => Quantity * UnitPrice;
}
/// Bestellung beim Großhandel. Wird nur serverseitig gehalten.
public sealed class PurchaseOrder
{
private readonly List _lines = new();
public IReadOnlyList Lines => _lines;
/// Spielzeit in Sekunden, zu der die Lieferung eintrifft.
public float DeliveryTime { get; set; }
public bool Delivered { get; set; }
public void Add(int productId, int quantity, float unitPrice)
{
if (quantity <= 0) return;
_lines.Add(new OrderLine { ProductId = productId, Quantity = quantity, UnitPrice = unitPrice });
}
public float Total()
{
float sum = 0f;
foreach (var line in _lines) sum += line.LineTotal;
return sum;
}
}
}