<?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->date?->format('Y-m-d'),
            'status' => $this->status?->value ?? $this->status,
            'check_in_time' => $this->actual_check_in,
            'check_out_time' => $this->actual_check_out,
            '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,
            ]),
        ];
    }
}
