<?php

namespace App\Http\Resources\Api\V1;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class SessionResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'session_date' => $this->session_date?->format('Y-m-d'),
            'start_time' => $this->start_time,
            'end_time' => $this->end_time,
            'status' => $this->status?->value ?? $this->status,
            'group' => $this->whenLoaded('group', fn () => [
                'id' => $this->group->id,
                'name_ar' => $this->group->name_ar,
                'program_name_ar' => $this->group->program?->name_ar,
                'activity_name_ar' => $this->group->program?->activity?->name_ar,
            ]),
            'facility' => $this->whenLoaded('facility', fn () => [
                'id' => $this->facility->id,
                'name_ar' => $this->facility->name_ar,
            ]),
        ];
    }
}
