-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pokemon.cs
60 lines (48 loc) · 2.12 KB
/
Pokemon.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
namespace Pokegraph.Domain.Pokemon;
public class Pokemon : AggregateRoot<PokemonNumber>
{
public string Name { get; private set; }
public decimal? CatchRate { get; private set; }
public bool IsLegendary { get; private set; }
public string? Avatar { get; private set; }
public PhysicalAttributes? PhysicalAttributes { get; private set; }
public GenderRatio? GenderRatio { get; private set; }
public PokemonType PrimaryType { get; private set; }
public PokemonType? SecondaryType { get; private set; }
public BaseStats BaseStats { get; private set; }
public PokemonNumber? EvolvesToNumber { get; private set; }
public virtual Pokemon? EvolvesTo { get; }
public virtual IReadOnlyCollection<Pokemon>? EvolvesFrom { get; }
public static Pokemon CatalogNew(PokemonData data)
{
return new Pokemon(data);
}
public void SetAttributes(PokemonData data)
{
EnsureValidState(data);
Number = PokemonNumber.From(data.Number);
Name = data.Name;
CatchRate = data.CatchRate;
IsLegendary = data.IsLegendary;
Avatar = data.Avatar;
PhysicalAttributes = PhysicalAttributes.From(data.Height, data.Weigth);
GenderRatio = GenderRatio.From(data.MaleRatio, data.FemaleRatio);
PrimaryType = PokemonType.From(data.PrimaryType);
BaseStats = BaseStats.From(data);
if (data.EvolvesToNumber.HasValue)
EvolvesToNumber = PokemonNumber.From(data.EvolvesToNumber.Value);
if (data.SecondaryType is not null)
SecondaryType = PokemonType.From(data.SecondaryType);
}
private void EnsureValidState(PokemonData data)
{
if (data is null)
throw new DomainException(nameof(data));
if (data.Number <= 0)
throw new DomainException("Pokemon's number must be valid.");
if (string.IsNullOrWhiteSpace(data.Name))
throw new DomainException("Pokemon's name cannot be null or whitespace.");
}
private Pokemon(PokemonData data) => SetAttributes(data);
private Pokemon() {}
}