<!---
	$Id$
	
	Copyright 2007 Brian Ghidinelli (http://www.ghidinelli.com/)
	
	Licensed under the Apache License, Version 2.0 (the "License"); you 
	may not use this file except in compliance with the License. You may 
	obtain a copy of the License at:
	 
		http://www.apache.org/licenses/LICENSE-2.0
		 
	Unless required by applicable law or agreed to in writing, software 
	distributed under the License is distributed on an "AS IS" BASIS, 
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
	See the License for the specific language governing permissions and 
	limitations under the License.
--->
<cfcomponent name="token" output="false" hint="Object for holding remote data storage IDs (Braintree Vault, TrustCommerce Citadel and Authorize.net CIM)">
	<cfproperty name="id" type="string" default="" />


	<!---
	PROPERTIES
	--->
	<cfset variables.instance = structNew() />
	<cfset variables.instance.id = "" />

	<!---
	INITIALIZATION / CONFIGURATION
	--->
	<cffunction name="init" access="public" returntype="token" output="false">
		<cfargument name="id" type="any" required="false" default="" />

		<cfset setID(arguments.id) />

		<cfreturn this />
 	</cffunction>

	<!--- convenience boolean wrapper around validate() --->
	<cffunction name="getIsValid" access="public" returntype="boolean" output="false" hint="True/false the bank account is valid">
		<cfreturn arrayLen(validate()) EQ 0 />
	</cffunction>
	
	<!--- if we pass this successfully, we should be able to send it to the gateway safely --->
	<cffunction name="validate" access="public" returntype="any" output="false">
		<cfset var errors = arrayNew(1) />
		<cfset var thisError = structNew() />

		<!--- vault/customer ID (is optional, at least with braintree)
		<cfif (NOT len(trim(getID())))>
			<cfset thisError.field = "id" />
			<cfset thisError.type = "required" />
			<cfset thisError.message = "ID is required" />
			<cfset arrayAppend(errors, duplicate(thisError)) />
		</cfif>
		
		
		--->

		<cfreturn errors />
	</cffunction>


	<!---
	ACCESSORS
	--->
	<cffunction name="setID" access="public" returntype="any" output="false"><cfset variables.instance.id = arguments[1] /><cfreturn this /></cffunction>
	<cffunction name="getID" access="public" returntype="any" output="false"><cfreturn variables.instance.id /></cffunction>


	<!---
	DUMP
	--->
	<cffunction name="dump" access="public" output="true" return="void">
		<cfargument name="abort" type="boolean" default="false" />
		<cfdump var="#variables.instance#" />
		<cfif arguments.abort>
			<cfabort />
		</cfif>
	</cffunction>

	<!--- 	Date: 7/6/2008  Usage: return a copy of the internal values --->
	<cffunction name="getMemento" output="false" access="public" returntype="any" hint="return a copy of the internal values">
		<cfreturn duplicate(variables.instance) />		
	</cffunction>

</cfcomponent>
