<?php

namespace App\Http\Resources\Reimbursements;

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

class ReimbursementRecipientResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        $id = (int) ($this->resource['id'] ?? 0);
        $first = $this->resource['firstname'] ?? '';
        $last = $this->resource['lastname'] ?? '';
        $name = trim($first . ' ' . $last);

        return [
            'id' => $id,
            'firstname' => $first,
            'lastname' => $last,
            'name' => $name,
        ];
    }
}
