diff --git a/src/Enums/RoomStatus.php b/src/Enums/RoomStatus.php new file mode 100644 index 0000000..590b9f4 --- /dev/null +++ b/src/Enums/RoomStatus.php @@ -0,0 +1,15 @@ + + */ + public array $nomis; + + /** + * The shared notes attached to the room + * TSDoc String + */ + public string $note; + + /** + * Room constructor. + * + * @param array $nomis + * + * @throws \DateMalformedStringException + */ + public function __construct( + string $uuid, + string $name, + string|DateTimeImmutable $created, + string|DateTimeImmutable $updated, + string|RoomStatus $status, + bool $backchannelingEnabled, + array $nomis, + string $note, + ) { + $this->uuid = $uuid; + $this->name = $name; + $this->backchannelingEnabled = $backchannelingEnabled; + $this->note = $note; + + $this->status = $status instanceof RoomStatus + ? $status + : ( + RoomStatus::tryFrom($status) + ?? throw new InvalidArgumentException('This is not a valid status!') + ); + $this->created = $created instanceof DateTimeImmutable + ? $created + : new DateTimeImmutable($created); + + $this->updated = $updated instanceof DateTimeImmutable + ? $updated + : new DateTimeImmutable($updated); + + $this->nomis = array_map(fn(array $nomi): Nomi => Nomi::make($nomi), $nomis); + } + + /** @inheritDoc */ + public static function make(array $response): static + { + return new self( + uuid: $response['uuid'], + name: $response['name'], + created: $response['created'], + updated: $response['updated'], + status: $response['status'], + backchannelingEnabled: $response['backChannelingEnabled'], + nomis: $response['nomis'], + note: $response['note'], + ); + } + + /** @inheritDoc */ + public function toArray(): array + { + return [ + 'uuid' => $this->uuid, + 'name' => $this->name, + 'created' => $this->created->format(self::ISO8601), + 'updated' => $this->updated->format(self::ISO8601), + 'status' => $this->status->value, + 'backChannelingEnabled' => $this->backchannelingEnabled, + 'nomis' => array_map(fn(Nomi $nomi): array => $nomi->toArray(), $this->nomis), + 'note' => $this->note, + ]; + } +} diff --git a/tests/Unit/Resources/RoomTest.php b/tests/Unit/Resources/RoomTest.php new file mode 100644 index 0000000..413106b --- /dev/null +++ b/tests/Unit/Resources/RoomTest.php @@ -0,0 +1,26 @@ + $this->faker->uuid(), + 'name' => $this->faker->company(), + 'created' => (new DateTimeImmutable())->format(Room::ISO8601), + 'updated' => (new DateTimeImmutable())->format(Room::ISO8601), + 'status' => $this->faker->randomElement(RoomStatus::cases())->value, + 'backChannelingEnabled' => $this->faker->boolean(), + 'note' => $this->faker->realText(), + 'nomis' => [ + $this->nomi()->toArray(), + $this->nomi()->toArray(), + ], + ]; + + $room = Room::make($data); + + expect($room->toArray())->toEqual($data); +});