<?php

declare(strict_types=1);

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

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

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

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

    /**
     * @param \App\Models\Pracovisko\Pracovisko $pracovisko
     *
     * @return \League\Fractal\Resource\Collection
     */
    public function includePouzivatelia(Pracovisko $pracovisko): Collection
    {
        return $this->collection($pracovisko->pouzivatelia()->get(), new PouzivatelTransformer(), 'pouzivatel');
    }
}
