<?php

declare(strict_types=1);

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

use App\Models\Pracovisko\Pracovisko;
use PHPOpenSourceSaver\Fractal\Resource\Collection;
use PHPOpenSourceSaver\Fractal\TransformerAbstract;

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

    public function transform(Pracovisko $pracovisko): array
    {
        return [
            'id' => $pracovisko->hashId(),
            'kod' => $pracovisko->kod,
            'nazov' => $pracovisko->nazov,
            'email' => $pracovisko->email,
            'created_at' => $pracovisko->created_at,
            'links' => [
                'self' => null,
            ],
        ];
    }

    public function includePouzivatelia(Pracovisko $pracovisko): Collection
    {
        return $this->collection($pracovisko->pouzivatelia()->get(), new PouzivatelTransformer, 'pouzivatel');
    }
}
