2021-10-08 16:23:45 +00:00
|
|
|
<?php
|
|
|
|
|
2023-08-20 15:24:56 +00:00
|
|
|
namespace App\Values;
|
2021-10-08 16:23:45 +00:00
|
|
|
|
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
2022-07-29 06:47:10 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2021-10-08 16:23:45 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2023-04-17 19:45:43 +00:00
|
|
|
use Webmozart\Assert\Assert;
|
2021-10-08 16:23:45 +00:00
|
|
|
|
|
|
|
final class SmartPlaylistRuleGroup implements Arrayable
|
|
|
|
{
|
2023-04-17 19:45:43 +00:00
|
|
|
private function __construct(public string $id, public Collection $rules)
|
2022-07-27 08:49:33 +00:00
|
|
|
{
|
2023-04-17 19:45:43 +00:00
|
|
|
Assert::uuid($id);
|
2022-07-27 08:49:33 +00:00
|
|
|
}
|
2021-10-08 16:23:45 +00:00
|
|
|
|
2024-01-04 21:51:32 +00:00
|
|
|
public static function make(array $array): self
|
2021-10-08 16:23:45 +00:00
|
|
|
{
|
2022-11-27 15:29:29 +00:00
|
|
|
return new self(
|
|
|
|
id: Arr::get($array, 'id'),
|
2024-01-12 14:41:02 +00:00
|
|
|
rules: collect(Arr::get($array, 'rules', []))->transform(
|
|
|
|
static function (array|SmartPlaylistRule $rule): SmartPlaylistRule {
|
|
|
|
return $rule instanceof SmartPlaylistRule ? $rule : SmartPlaylistRule::make($rule);
|
|
|
|
}
|
|
|
|
),
|
2022-11-27 15:29:29 +00:00
|
|
|
);
|
2021-10-10 18:05:51 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 16:23:45 +00:00
|
|
|
/** @return array<mixed> */
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $this->id,
|
|
|
|
'rules' => $this->rules->toArray(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|