File size: 727 Bytes
cf14c12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php

declare(strict_types=1);

namespace Plugin\Domain\ValueObjects;

use JsonSerializable;

class SupportChannel implements JsonSerializable
{
    public readonly SupportChannelType $type;
    public readonly Email|Url $value;

    public function __construct(
        string|SupportChannelType $type,
        string $value
    ) {
        $this->type = $type instanceof SupportChannelType
            ? $type : SupportChannelType::from($type);

        $this->value = $this->type == SupportChannelType::EMAIL
            ? new Email($value) : new Url($value);
    }

    public function jsonSerialize(): array
    {
        return [
            'type' => $this->type,
            'value' => $this->value
        ];
    }
}