<?php

namespace App\Transformers\Companies;

use App\Models\Companies\Department;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\Item;
use League\Fractal\TransformerAbstract;

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

    protected array $availableIncludes = [
        'company', 'parent', 'children', 'members'
    ];

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

    public function includeCompany(Department $model): ?Item {
        return $model->company ? $this->item($model->company, new CompanyTransformer()) : null;
    }

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

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

    public function includeMembers(Department $model): Collection {
        return $this->collection($model->members, new CompanyMemberTransformer());
    }

}