<?php

namespace App\Http\Resources\Api\V1;

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

class AttendanceResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'date' => $this->session?->session_date?->format('Y-m-d'),
            'status' => $this->status?->value ?? $this->status,
            'check_in_time' => $this->check_in_at,
            'check_out_time' => $this->check_out_at,
            'late_minutes' => $this->late_minutes,
            'notes' => $this->notes,
            'session' => $this->whenLoaded('session', fn () => [
                'id' => $this->session->id,
                'date' => $this->session->session_date?->format('Y-m-d'),
                'start_time' => $this->session->start_time,
                'group_name_ar' => $this->session->group?->name_ar,
                'program_name_ar' => $this->session->group?->program?->name_ar,
            ]),
        ];
    }
}
