<?php

declare(strict_types=1);

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

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

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

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

    /**
     * @param \App\Models\Pouzivatel\Pouzivatel $pouzivatel
     *
     * @return array
     */
    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,
            ],
        ];
    }

    /**
     * @param \App\Models\Pouzivatel\Pouzivatel $pouzivatel
     *
     * @return \League\Fractal\Resource\Item
     */
    public function includePracovisko(Pouzivatel $pouzivatel): Item
    {
        return $this->item($pouzivatel->pracovisko, new PracoviskoTransformer(), 'pracovisko');
    }
}
