<?php

declare(strict_types=1);

namespace App\Http\Resources;

use App\Contracts\Resource;
use App\Models\PirepComment;
use Illuminate\Http\Request;

/**
 * @mixin PirepComment
 */
class PirepCommentResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  Request $request
     * @return array
     */
    #[\Override]
    public function toArray($request)
    {
        if (!$this->user) {
            return [];
        }

        $user = $this->user;

        return [
            'id'         => $this->id,
            'comment'    => $this->comment,
            'created_at' => $this->created_at,
            'user'       => [
                'id'       => $user->id,
                'pilot_id' => $user->pilot_id,
                'ident'    => $user->ident,
                'name'     => $user->name,
            ],
        ];
    }
}
