<?php

declare(strict_types=1);

namespace App\Http\Resources;

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

/** @mixin \App\Models\SupportTicket */
class TicketResource extends JsonResource
{
    /**
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'reference' => $this->ticket_reference,
            'subject' => $this->subject,
            'status' => $this->status,
            'priority' => $this->priority,
            'department' => $this->department,
            'last_reply_at' => $this->last_reply_at?->toIso8601String(),
            'created_at' => $this->created_at?->toIso8601String(),
            'replies' => TicketReplyResource::collection($this->whenLoaded('replies')),
        ];
    }
}
