2024-01-01 11:40:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
|
|
|
|
use App\Values\QueueState;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
class QueueStateResource extends JsonResource
|
|
|
|
{
|
2024-01-25 16:21:26 +00:00
|
|
|
public const JSON_STRUCTURE = [
|
|
|
|
'songs' => [
|
|
|
|
SongResource::JSON_STRUCTURE,
|
|
|
|
],
|
|
|
|
'current_song',
|
|
|
|
'playback_position',
|
|
|
|
];
|
|
|
|
|
2024-04-18 14:36:28 +00:00
|
|
|
public function __construct(private readonly QueueState $state)
|
2024-01-01 11:40:21 +00:00
|
|
|
{
|
|
|
|
parent::__construct($state);
|
|
|
|
}
|
|
|
|
|
2024-05-31 05:40:34 +00:00
|
|
|
/** @inheritdoc */
|
2024-01-01 11:40:21 +00:00
|
|
|
public function toArray($request): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'type' => 'queue-states',
|
2024-05-31 05:40:34 +00:00
|
|
|
'songs' => SongResource::collection($this->state->playables),
|
|
|
|
'current_song' => $this->state->currentPlayable ? new SongResource($this->state->currentPlayable) : null,
|
2024-01-01 11:40:21 +00:00
|
|
|
'playback_position' => $this->state->playbackPosition,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|