<?php

namespace App\Transformers\Objects;

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

class ObjectPropertiesGroupTransformer extends TransformerAbstract {
    protected NirObject $object;

    public function __construct(NirObject $object) {
        $this->object = $object;
    }

    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 ObjectPropertyTransformer($this->object));
    }


}
