<?php

namespace App\Http\Resources;

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

class AppointmentResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'patient' => [
                'id' => $this->patient->id,
                'name' => $this->patient->fullName(),
                'phone' => $this->patient->phone,
            ],
            'therapist' => [
                'id' => $this->user->id,
                'name' => $this->user->name,
            ],
            'appointment_date' => $this->appointment_date->format('Y-m-d'),
            'appointment_time' => $this->appointment_date->format('H:i'),
            'duration_minutes' => $this->duration_minutes,
            'end_time' => $this->appointment_date->copy()->addMinutes($this->duration_minutes)->format('H:i'),
            'status' => $this->status,
            'notes' => $this->notes,
            'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
        ];
    }
}
