/
PriceChangesPolicies.cs
executable file
·35 lines (32 loc) · 1.21 KB
/
PriceChangesPolicies.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
32
33
34
35
using System;
using System.Threading.Tasks;
using MyCompany.ECommerce.Sales.Clients;
using P3Model.Annotations.Domain.StaticModel.DDD;
namespace MyCompany.ECommerce.Sales.Orders.PriceChanges
{
[DddFactory]
public class PriceChangesPolicies
{
private readonly AllowAnyPriceChanges _allowAny;
private readonly AllowPriceChangesIfTotalPriceIsLower _allowIfTotalPriceIsLower;
private readonly ClientRepository _clients;
public PriceChangesPolicies(AllowAnyPriceChanges allowAny,
AllowPriceChangesIfTotalPriceIsLower allowIfTotalPriceIsLower,
ClientRepository clients)
{
_allowAny = allowAny;
_allowIfTotalPriceIsLower = allowIfTotalPriceIsLower;
_clients = clients;
}
public async Task<PriceChangesPolicy> ChooseFor(ClientId clientId)
{
var clientStatus = await _clients.GetStatusFor(clientId);
return clientStatus switch
{
ClientStatus.Normal => _allowAny,
ClientStatus.Vip => _allowIfTotalPriceIsLower,
_ => throw new ArgumentOutOfRangeException(nameof(clientStatus), clientStatus, null)
};
}
}
}