protected function generateModel(array $parameters, $dir, $document)
    {
        $this->renderFile(
            'model/Model.php.twig',
            $dir . '/Model/' . $document . '.php',
            $parameters
        );
        $this->renderFile(
            'model/schema.json.twig',
            $dir . '/Resources/config/schema/' . $document . '.json',
            $parameters
        );

        // embedded versions
        $this->renderFile(
            'model/Model.php.twig',
            $dir . '/Model/' . $document . 'Embedded.php',
            array_merge($parameters, ['document' => $document.'Embedded'])
        );
        $this->renderFile(
            'model/schema.json.twig',
            $dir . '/Resources/config/schema/' . $document . 'Embedded.json',
            array_merge($parameters, ['document' => $document.'Embedded'])
        );

        $bundleParts = explode('\\', $parameters['base']);
        $shortName = strtolower($bundleParts[0]);
        $shortBundle = strtolower(substr($bundleParts[1], 0, -6));
        $paramName = implode('.', array($shortName, $shortBundle, 'model', strtolower($parameters['document'])));
        $repoName = implode('.', array($shortName, $shortBundle, 'repository', strtolower($parameters['document'])));

        $this->addParameter($parameters['base'] . 'Model\\' . $parameters['document'], $paramName . '.class');

        // normal service
        $this->addService(
            $paramName,
            'graviton.rest.model',
            array(
                [
                    'method' => 'setRepository',
                    'service' => $repoName
                ],
            ),
            null
        );

        // embedded service
        $this->addParameter(
            $parameters['base'] . 'Model\\' . $parameters['document'] . 'Embedded',
            $paramName . 'embedded.class'
        );

        $this->addService(
            $paramName . 'embedded',
            'graviton.rest.model',
            array(
                [
                    'method' => 'setRepository',
                    'service' => $repoName . 'embedded'
                ],
            ),
            null
        );
    }