<?php

namespace App\Transformers\Objects;

use App\Models\Objects\FieldsGroup;
use League\Fractal\Resource\Collection;
use League\Fractal\TransformerAbstract;

class FieldsGroupTransformer extends TransformerAbstract {
    protected array $defaultIncludes = [
    ];

    protected array $availableIncludes = [
        'fields'
    ];

    public function transform(FieldsGroup $model): array {
        return [
            'id' => $model->uuid,
            'name' => $model->name,
            'title' => $model->title,
            'hidden' => boolval($model->hidden),
            'dynamic' => $model->params['dynamic'] ?? null
        ];
    }

    public function includeFields(FieldsGroup $model): Collection {
        return $this->collection($model->fields, new FieldTransformer());
    }


}
