<?php

declare(strict_types=1);

namespace App\Http\Controllers\API\V1\Auth\Transformers;

use App\Models\Pouzivatel\Pouzivatel;
use PHPOpenSourceSaver\Fractal\Resource\Item;
use PHPOpenSourceSaver\Fractal\TransformerAbstract;

/**
 * Class PouzivatelTransformer
 */
class PouzivatelTransformer extends TransformerAbstract
{
    /**
     * @var string[]
     */
    protected array $availableIncludes = [
        'pracovisko',
        'notifikacie',
    ];

    /**
     * @var string[]
     */
    protected array $defaultIncludes = [
        //        'pracovisko',
    ];

    public function transform(Pouzivatel $pouzivatel): array
    {
        return [
            'id' => $pouzivatel->hashId(),
            'login' => $pouzivatel->login,
            'meno' => $pouzivatel->cele_meno,
            'created_at' => $pouzivatel->created_at,
            'links' => [
                'self' => null,
            ],
        ];
    }

    public function includePracovisko(Pouzivatel $pouzivatel): Item
    {
        return $this->item($pouzivatel->pracovisko, new PracoviskoTransformer, 'pracovisko');
    }
}
