|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Trophy\Types; |
| 4 | + |
| 5 | +use Trophy\Core\Json\JsonSerializableType; |
| 6 | +use Trophy\Traits\BaseAchievementResponse; |
| 7 | +use Trophy\Core\Json\JsonProperty; |
| 8 | +use DateTime; |
| 9 | + |
| 10 | +class MetricAchievementResponse extends JsonSerializableType |
| 11 | +{ |
| 12 | + use BaseAchievementResponse; |
| 13 | + |
| 14 | + /** |
| 15 | + * @var string $trigger The trigger of the achievement, in this case always 'metric'. |
| 16 | + */ |
| 17 | + #[JsonProperty('trigger')] |
| 18 | + public string $trigger; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var string $metricId The ID of the metric associated with this achievement, if any. |
| 22 | + */ |
| 23 | + #[JsonProperty('metricId')] |
| 24 | + public string $metricId; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var float $metricValue The value of the metric required to complete the achievement, if this achievement is associated with a metric. |
| 28 | + */ |
| 29 | + #[JsonProperty('metricValue')] |
| 30 | + public float $metricValue; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var string $metricName The name of the metric associated with this achievement, if any. |
| 34 | + */ |
| 35 | + #[JsonProperty('metricName')] |
| 36 | + public string $metricName; |
| 37 | + |
| 38 | + /** |
| 39 | + * @param array{ |
| 40 | + * trigger: string, |
| 41 | + * metricId: string, |
| 42 | + * metricValue: float, |
| 43 | + * metricName: string, |
| 44 | + * id: string, |
| 45 | + * name: string, |
| 46 | + * badgeUrl?: ?string, |
| 47 | + * key?: ?string, |
| 48 | + * achievedAt?: ?DateTime, |
| 49 | + * } $values |
| 50 | + */ |
| 51 | + public function __construct( |
| 52 | + array $values, |
| 53 | + ) { |
| 54 | + $this->trigger = $values['trigger']; |
| 55 | + $this->metricId = $values['metricId']; |
| 56 | + $this->metricValue = $values['metricValue']; |
| 57 | + $this->metricName = $values['metricName']; |
| 58 | + $this->id = $values['id']; |
| 59 | + $this->name = $values['name']; |
| 60 | + $this->badgeUrl = $values['badgeUrl'] ?? null; |
| 61 | + $this->key = $values['key'] ?? null; |
| 62 | + $this->achievedAt = $values['achievedAt'] ?? null; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @return string |
| 67 | + */ |
| 68 | + public function __toString(): string |
| 69 | + { |
| 70 | + return $this->toJson(); |
| 71 | + } |
| 72 | +} |
0 commit comments