<?php

namespace App\Transformers\Users;

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

class RoleTransformer extends TransformerAbstract {
    protected array $defaultIncludes = [];
    protected array $availableIncludes = ['permissions'];


    public function transform(Role $model): array {
        return [
            'id' => $model->uuid,
            'name' => $model->name,
            'createdAt' => $model->created_at->toIso8601String(),
            'updatedAt' => $model->updated_at->toIso8601String()
        ];
    }

    public function includePermissions(Role $model): Collection {
        return $this->collection($model->permissions, new PermissionTransformer());
    }
}
