/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 */
package org.apache.openmeetings.db.entity.server;

import com.github.openjson.JSONObject;

/**
 * This Class is marshaled as JSON-Object and stored as a String in the DB to
 * make it more easy to extend it
 *
 * @author sebastianwagner
 *
 */
public class RemoteSessionObject {
	private String username;
	private String firstname;
	private String lastname;
	private String pictureUrl;
	private String email;
	private String externalId;
	private String externalType;

	public RemoteSessionObject() {
		// def constructor
	}

	public RemoteSessionObject(String username, String firstname, String lastname, String pictureUrl, String email) {
		this(username, firstname, lastname, pictureUrl, email, "0", "");
	}

	/**
	 * @param username
	 *            - username
	 * @param firstname
	 *            - first name
	 * @param lastname
	 *            - last name
	 * @param pictureUrl
	 *            - picture url
	 * @param email
	 *            - email
	 * @param externalId
	 *            - external user id
	 * @param externalType
	 *            - external user type
	 *
	 *            06.09.2009 17:05:48 sebastianwagner
	 */
	public RemoteSessionObject(String username, String firstname, String lastname, String pictureUrl, String email,
			String externalId, String externalType) {
		this.username = username;
		this.firstname = firstname;
		this.lastname = lastname;
		this.pictureUrl = pictureUrl;
		this.email = email;
		this.externalId = externalId;
		this.externalType = externalType;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getPictureUrl() {
		return pictureUrl;
	}

	public void setPictureUrl(String pictureUrl) {
		this.pictureUrl = pictureUrl;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getExternalId() {
		return externalId;
	}

	public void setExternalId(String externalId) {
		this.externalId = externalId;
	}

	public String getExternalType() {
		return externalType;
	}

	public void setExternalType(String externalType) {
		this.externalType = externalType;
	}

	public static RemoteSessionObject fromString(String s) {
		JSONObject o = new JSONObject(s);
		RemoteSessionObject ro = new RemoteSessionObject();
		ro.username = o.optString("username");
		ro.firstname = o.optString("firstname");
		ro.lastname = o.optString("lastname");
		ro.pictureUrl = o.optString("pictureUrl");
		ro.email = o.optString("email");
		ro.externalId = o.getString("externalId");
		ro.externalType = o.getString("externalType");
		return ro;
	}

	@Override
	public String toString() {
		return new JSONObject(this).toString();
	}
}
