/* ************************************************************************
#
#  DivConq
#
#  http://divconq.com/
#
#  Copyright:
#    Copyright 2012 eTimeline, LLC. All rights reserved.
#
#  License:
#    See the license.txt file in the project's top-level directory for details.
#
#  Authors:
#    * Andy White
#
************************************************************************ */
package divconq.db.common;

import org.joda.time.DateTime;

import divconq.db.IDatabaseManager;
import divconq.db.UpdateRequest;
import divconq.struct.FieldStruct;
import divconq.struct.RecordStruct;

/**
 * Bypass authentication and just start a session for a given user.
 * 
 * @author Andy
 *
 */
public class StartSessionRequest extends UpdateRequest {
	protected String id = null;
	protected String name = null;
	
	/**
	 * @param v user id used in query
	 */
	public void setUserId(String v) {
		this.id = v;
	}
	
	/**
	 * @param v user name used in query
	 */
	public void setUserName(String v) {
		this.name = v;
	}
	
	/**
	 * Start session for user.  To start using a user name,
	 * see "setUserName".
	 */
	public StartSessionRequest() {
		super("dcStartSession");
	}
	
	/**
	 * Start session for user.
	 * 
	 * @param id of user
	 */
	public StartSessionRequest(String id) {
		super("dcStartSession");
		this.id = id;
	}
	
	/* (non-Javadoc)
	 * @see divconq.db.IDatabaseRequest#getDatabaseParams()
	 */
	@Override
	public RecordStruct getDatabaseParams(IDatabaseManager dbm) {
		return new RecordStruct(
				new FieldStruct("At", new DateTime()),
				new FieldStruct("UserName", (this.name != null) ? this.name.trim().toLowerCase() : null),
				new FieldStruct("UserId", this.id)
		);
	}
}
