public function definition(string $resource, int $version = null) : ResourceDefinition
    {
        $version = $version ?? $this->version;

        if (str_contains($resource, '.')) {
            list($resource, $related) = explode('.', $resource);
            $definition = $this->definition($resource, $version);

            $relatedDefinition = $definition->relations->filter(function (ResourceDefinition $definition) use ($related, $version) {
                return $definition->version === $version && $definition->resource === $related;
            });

	        if($relatedDefinition->isEmpty())
		        throw ResourceNotDefinedException::resource($resource, 'version ' . $version);

            return $relatedDefinition->first();
        }

        $found = $this->definitions->filter(function (ResourceDefinition $definition) use ($resource, $version) {
            return $definition->version === $version && $definition->resource === $resource;
        });

        if ($found->isEmpty()) {
            throw ResourceNotDefinedException::resource($resource, 'version ' . $version);
        }

        return $found->first();
    }