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" );
		}

		Node fileNode = this.getNeo().createNode();
		fileNode.setProperty( File.NAME, name );
		
		return new File( fileNode );
	}
}
