const Scene = require('Scene');
const Options = require('Options');
const Camera = require('Camera');
const Instance = require('Instance');
const Group = require('Group');

module.exports.command = {
    name: 'tutorial_create_empty_scene',
    description: 'Creates a valid but empty scene ready for adding objects and lighting.',
    groups: ['tutorial', 'javascript'],
    arguments: {
        scene_name: {
            description: 'The name to use when storing the created scene in the database. '
                + 'Other element names will be derived from this name as well.',
            type: 'String'
        }
    },
    returns: {
        type: 'Map',
        description: 'Map containing the database names of the options, camera, camera instance and rootgroup.'
    },
    execute: function({scene_name}) {
        // Create all of the needed database elements
        const scene = new Scene(scene_name, true);
        const options = new Options(`${scene_name}_opt`, true);
        const camera = new Camera(`${scene_name}_cam`, true);
        const camera_instance = new Instance(`${scene_name}_cam_inst`, true);
        const rootgroup = new Group(`${scene_name}_root`, true);

        // Attach the camera to its instance
        camera_instance.item = camera;

        // Attach the camera instance to the rootgroup
        rootgroup.attach(camera_instance);

        // Set default filtering to Gauss with a radius of 1.5 pixels
        options.attributes.set('filter', 2, 'Sint32');
        options.attributes.set('radius', 1.5, 'Float32');

        // Set the needed elements onto the scene
        scene.options = options;
        scene.camera_instance = camera_instance;
        scene.root_group = rootgroup;

        // Return the details of our configured scene
        return {
            rootgroup: rootgroup.name,
            options: options.name,
            camera: camera.name,
            camera_instance: camera_instance.name
        };
    }
};
