namespace Groceries.Data; using System.Text.Json.Serialization; public class Transaction { [JsonConstructor] public Transaction(Guid id, DateTime createdAt, Guid storeId) { Id = id; CreatedAt = createdAt; StoreId = storeId; } public Transaction(DateTime createdAt, Guid storeId) : this(default, createdAt, storeId) { } public Guid Id { get; init; } public DateTime CreatedAt { get; init; } public Guid StoreId { get; init; } public ICollection Items { get; init; } = new List(); public ICollection Promotions { get; init; } = new List(); public Store? Store { get; init; } public decimal Total => Items.Sum(item => item.Price * item.Quantity) - Promotions.Sum(promotion => promotion.Amount); }