<?php

namespace App\Transformers\Objects;

use App\Models\Objects\ObjectType;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\Item;
use League\Fractal\TransformerAbstract;

class ObjectTypeTransformer extends TransformerAbstract {
    protected array $defaultIncludes = [

    ];

    protected array $availableIncludes = [
        'parent', 'children', 'groups', 'objects'
    ];

    public function transform(ObjectType $model): array {
        return [
            'id' => $model->uuid,
            'name' => $model->name,
            'title' => $model->title
        ];
    }

    public function includeParent(ObjectType $model): ?Item {
        return $model->parent ? $this->item($model->parent, new ObjectTypeTransformer()) : null;
    }

    public function includeChildren(ObjectType $model): Collection {
        return $this->collection($model->children, new ObjectTypeTransformer());
    }

    public function includeGroups(ObjectType $model): Collection {
        return $this->collection($model->groups, new FieldsGroupTransformer());
    }

    public function includeObjects(ObjectType $model): Collection {
        return $this->collection($model->objects, new ObjectTransformer());
    }

}
