package $omPojoPackage;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.asyrinx.brownie.core.lang.PropertyUtils;
import org.asyrinx.brownie.core.util.Captionable;

/** 
 * 
#if( $omDaoPersistance == "hibernate" )
 * 
 * @hibernate.class
 * table="${table.getName()}"
#end
#if ($addTimeStamp)
 * generated by joey-gen on $now
#end
 */
#if ($table.isAbstract())
    #set ($abstract = "abstract")
#end
public $!abstract class $table.JavaName extends ${basePrefix}${table.JavaName} implements Captionable {

	/**
	 * @see org.asyrinx.brownie.core.util.Captionable#getCaption()
	 */
	public String getCaption() {
		#if($table.getCaptionPropertyObj())
			return get${stringUtils.capitalize( $table.getCaptionPropertyObj().getJavaName() )}();
		#else
			return String.valueOf(getPrimaryKey());
		#end
	}

## ---------------------- Property ---------------------- 
#foreach ( $prop in $table.getProperties() )
	#if ( $prop.getEnum() )
		#set ( $enum = $prop.getEnum() )
	public $prop.getType() get$stringUtils.capitalize( $prop.getName() )() {
		return ${enum.getName()}.get(this.get${stringUtils.capitalize( $prop.getColumn().getJavaName() )}() );
	}

	public void set$stringUtils.capitalize( $prop.getName() )($prop.getType() value) {
		this.set${stringUtils.capitalize( ${prop.getColumn().getJavaName()} )}( value.as${stringUtils.capitalize( $enum.getValueType() )}() );
	}

	#else
		#if ( $prop.getValueToGet() )
	public $prop.getType() get$stringUtils.capitalize( $prop.getName() )() {
		return PropertyUtils.getPropertyAs$stringUtils.capitalize( $prop.getType() )( this, "$prop.getValueToGet()" );
	}
		#end
	#end

#end
## ---------------------- Property ---------------------- 

## ---------------------- Format ---------------------- 
#foreach ( $prop in $table.getAllProperties() )
	#if( $prop.getFormat() )
		#set( $format = $prop.getFormat() )
	public static final ${format.getClassName()} FORMAT_$prop.getName().toUpperCase() = new ${format.getClassName()}( "$format.getFormat()" );
	#end
#end
## ---------------------- Format ---------------------- 

## ---------------------- Referred Objects ( referred foreignKey ) ---------------------- 
#foreach ( $ref in $table.getReferrers() )
	#set( $refTable = ${ref.getTable()} )
	#set( $refPropNameLow = $ref.getPropertyNameInReferred() )
	#set( $refPropName = ${stringUtils.capitalize( $refPropNameLow )} )
	#set( $paramNameLow = ${ref.getPropertyNameInReferred( false )} )
	#set( $paramName = ${stringUtils.capitalize( $paramNameLow )} )	
	/**
	 * Add a ${refTable.getJavaName()} to the List of ${refPropName}.
	 * @param $paramNameLow New ${refTable.getJavaName()} to be added to the List of ${refPropName}
	 * @see ${omPojoPackage}.${basePrefix}${table.JavaName}#add${omPojoPackage}(${package}.${refTable.getJavaName()})
	 */
	public void add${paramName}(${refTable.getJavaName()} $paramNameLow) {
		super.add${paramName}($paramNameLow);
		${paramNameLow}.set${stringUtils.capitalize( $ref.getPropertyNameInLocal() )} (this);
	}

	/**
	 * remove a ${refTable.getJavaName()} to the List of ${refPropName}.
	 * @param $paramNameLow ${refTable.getJavaName()} to be removed to the List of ${refPropName}
	 * @see ${omPojoPackage}.${basePrefix}${table.JavaName}#remove${paramName}(${omPojoPackage}.${refTable.getJavaName()})
	 */
	public void remove${paramName}(${refTable.getJavaName()} $paramNameLow) {
		super.remove${paramName}($paramNameLow);
		${paramNameLow}.set${stringUtils.capitalize( $ref.getPropertyNameInLocal() )} (null);
	}
	
#end    
## ---------------------- Referred Objects ( referred foreignKey ) ---------------------- 

}
