package org.neo4j.tutor.security;

import org.neo4j.api.core.EmbeddedNeo;
import org.neo4j.api.core.Node;

public class FileFactory
{
	private static FileFactory factory = new FileFactory();
	private EmbeddedNeo neo;
	
	private FileFactory()
	{
	}
	
	public static FileFactory getFactory()
	{
		return factory;
	}

	// Simple dependency injection
	public void injectNeo( EmbeddedNeo neo )
	{
		this.neo = neo;
	}
	
	// Accessor for neo factory
	private EmbeddedNeo getNeo()
	{
		return this.neo;
	}
	
	public File createNewFile( String name )
	{
		if ( name == null )
		{
			throw new IllegalArgumentException( "Null name" );
		}
		// --- TODO
		// --- create node to represent the new file  ---
		// --- set the name of the file using File.NAME key ---
		// --- create the File wrapping the node and return it---
		Node fileNode = this.getNeo().createNode();
		fileNode.setProperty( File.NAME, name );
		
		return new File( fileNode );
	}
}
