package org.richfaces.realworld.util;

import java.util.Date;

import javax.faces.event.ActionEvent;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Comment;
import org.richfaces.realworld.domain.Image;
import org.richfaces.realworld.domain.User;
import org.richfaces.realworld.tree.TreeActionManager;

@Name("modalPanelHelper")
@Scope(ScopeType.SESSION)
public class ModalPanelHelper {
	
	private String caption;
	
	private String actionName;
	
	@In(create=true, required=true) @Out
	private Album album;
	
	@In(create=true, required=true) @Out
	private Image image;
	
	@In(create=true, required=true)
	private TreeActionManager treeActionManager;

	@In(create=true, required=true) @Out
	private Comment comment;

	public String getCaption() {
		return caption;
	}

	public void setCaption(String caption) {
		this.caption = caption;
	}

	public String getActionName() {
		return actionName;
	}

	public void setActionName(String actionName) {
		this.actionName = actionName;
	}

	public void initModalPanelData( String actionName, String caption, Album album){
		this.caption = caption;
		this.actionName = actionName;
		if(null != album){
			this.album = album;
		}else{
			this.album = new Album();
		}
	}
	
	public void initModalPanelData( String actionName, String caption, Image image){
		this.caption = caption;
		this.actionName = actionName;
		if(null != image){
			this.image = image;
		}else{
			this.image = new Image();
		}
	}
	
	public void initModalPanelData( String actionName, String caption, Comment comment, User user, Image image){
		this.caption = caption;
		this.actionName = actionName;
		if(null != comment){
			this.comment = comment;
		}else{
			this.comment = new Comment();
			this.comment.setAuthor(user);
			this.comment.setImage(image);
			this.comment.setDate(new Date());
		}
	}
	
	public void addAlbum(ActionEvent event){
		treeActionManager.addAlbum();
	}
	
	public void editAlbum(ActionEvent event){
		treeActionManager.editAlbum(this.album);
	}
	
	public void deleteAlbum(ActionEvent event){
		treeActionManager.deleteAlbum(this.album);
	}
	
	public void deleteImage(ActionEvent event){
		treeActionManager.deleteImage(this.image);
	}
	
	public void editComment(ActionEvent event){
		treeActionManager.editComment(this.comment);
	}
	
	public void addComment(ActionEvent event){
		treeActionManager.addComment(this.comment);
	}
	
	public void editImage(ActionEvent event){
		treeActionManager.editImage(this.image);
	}
}
