<?php

namespace App\Http\Resources\Api\V1;

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

class EnrollmentResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'status' => $this->status?->value ?? $this->status,
            'enrolled_at' => $this->created_at?->format('Y-m-d'),
            '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,
                ],
                'schedule' => $this->group->schedules?->map(fn ($s) => [
                    'day_of_week' => $s->day_of_week,
                    'start_time' => $s->start_time,
                    'end_time' => $s->end_time,
                ]) ?? [],
            ]),
        ];
    }
}
