<?php

namespace App\Http\Resources\Api;

use App\Enums\BookingStatusEnum;

class BookingResource extends BaseResource
{

    protected ?string $scope;

    public function __construct($resource, string $scope = 'default')
    {
        parent::__construct($resource);
        $this->scope = $scope;
    }

    public function toArray($request): array
    {
        return match($this->scope) {
            'default' => $this->defaultData(),
            'forShow' => $this->forShowData(),
            default => $this->defaultData(),
        };
    }
    protected function defaultData(): array
    {
        return [
            'id'                 => $this->id,
            'booking_reference'  => $this->booking_reference,
            'member'       => new MemberResource($this->whenLoaded('member')),
            'game'         => new GameResource($this->whenLoaded('game')),
            'court'        => new CourtResource($this->whenLoaded('court')),
            'booking_date'       => $this->booking_date,
            'start_time'         => $this->start_time,
            'end_time'           => $this->end_time,
            'players_count'      => $this->players_count,
            'status'             => $this->status,
            'status_label'       => BookingStatusEnum::label($this->status),
        ];
    }

    protected function forShowData(): array
    {
        $default = $this->defaultData();

        return array_merge($default, [
            'participants' => BookingParticipantResource::collection($this->whenLoaded('participants')),
            'booking_date_raw' => $this->booking_date,
        ]);
    }


}
