-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathQuote.cs
executable file
·31 lines (22 loc) · 1.32 KB
/
Quote.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Text.Json.Serialization;
using MyCompany.ECommerce.Sales.Commons;
using MyCompany.ECommerce.Sales.Products;
using P3Model.Annotations.Domain.DDD;
namespace MyCompany.ECommerce.Sales.Pricing;
[DddValueObject]
[method: JsonConstructor]
public readonly struct Quote(ProductAmount productAmount, Money price) : IEquatable<Quote>
{
public ProductAmount ProductAmount { get; } = productAmount;
public Money Price { get; } = price;
public static Quote For(ProductAmount productAmount, Money price) => new(productAmount, price);
internal Quote Apply<TPriceModifier>(TPriceModifier priceModifier)
where TPriceModifier : struct, PriceModifier => new(ProductAmount, priceModifier.ApplyOn(Price));
internal Quote Apply(QuoteModifier quoteModifier) => quoteModifier.ApplyOn(this);
public Quote ChangePrice(Money newPrice) => new(ProductAmount, newPrice);
public static Quote operator +(Quote x, Quote y) => For(x.ProductAmount + y.ProductAmount, x.Price + y.Price);
public bool Equals(Quote other) => (ProductAmount, Price).Equals((other.ProductAmount, other.Price));
public override bool Equals(object? obj) => obj is Quote other && Equals(other);
public override int GetHashCode() => (ProductAmount, Price).GetHashCode();
public override string ToString() => $"{ProductAmount} - {Price}";
}