package org.richfaces.realworld.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Begin;
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.jboss.seam.annotations.TransactionPropagationType;
import org.jboss.seam.annotations.Transactional;
import org.richfaces.realworld.domain.Album;
import org.richfaces.realworld.domain.Image;
import org.richfaces.realworld.domain.User;
import org.richfaces.realworld.service.IAlbumAction;
import org.richfaces.realworld.service.IUserAction;

@Name("friendHelper")
@Scope(ScopeType.CONVERSATION)
public class FriendHelper implements Serializable{

	@Out(required=false)
	private User selectedUser;
	
	@In(required=false) @Out(required=false)
	private Image selectedImage;

	@In(required=false)  @Out(required=false)
	private Album selectedAlbum;
	
	@In(create=true)
	private IAlbumAction albumAction;
	
	@In(required=false) @Out(required=false)
	private SelectedImageIndex selectedImageIndex;
	
	@In(required=false)
	ComboboxHelper comboboxHelper;
	
	public void chooseAlbum(User friend){
		selectedUser = friend;
		selectedAlbum = friend.getAlbumByName(comboboxHelper.getAlbumName());
		selectedImage = selectedAlbum.getImages().get(0);
		selectedImageIndex.setSelectedImageIndex(1);
	}
	
	public void chooseAlbum(Album album){
		selectedUser = album.getOwner();
		selectedAlbum = album;
		selectedImage = selectedAlbum.getImages().get(0);
		selectedImageIndex.setSelectedImageIndex(1);
	}
}
