/**
 * License Agreement.
 *
 *  JBoss RichFaces - Ajax4jsf Component Library
 *
 * Copyright (C) 2007  Exadel, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */
/*
 * Image.java
 * Last modified by: $Author: amarkhel $
 * $Revision: 12550 $	$Date: 2009-02-03 18:00:20 +0200 (Tue, 03 Feb 2009) $
 */
package org.richfaces.realworld.domain;

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

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.NotNull;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Role;

@NamedQueries({
   @NamedQuery(
        name = "image-camera",
        query = "select distinct i.cameraModel from Image i"
   )
   }
)
/**
 * Class for representing Image Entity
 *  EJB3 Entity Bean
 * 
 * @author Andrey Markhel
 */

@Entity
@Name("image")
@Table(name = "Images")
@Role(name="selectedImage", scope = ScopeType.CONVERSATION)
public class Image implements Serializable {

    private static final long serialVersionUID = -7042878411608396483L;

    @Id
    @GeneratedValue
    @Column(name = "IMAGE_ID")
    private Long id = null;

    @Column(length = 255, nullable = false)
    @NotNull
	@NotEmpty
    @Length(min=3)
    private String name;

    @Column(length = 1024, nullable = false)
    @NotNull
	@NotEmpty
    @Length(min=3)
    private String path;
    
    @Column(length = 255)
    private String cameraModel;
    
    private int height;
    
    private double size;
    
    private int width;
    
    @Temporal(TemporalType.TIMESTAMP)
    private Date uploaded; 
    
    @Column(length = 1024)
    @NotNull
	@NotEmpty
    @Length(min=3)
    private String description;
    
    @Transient
    private String albumName;
    
    @Temporal(TemporalType.TIMESTAMP)
    private Date created;

    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="IMG_ALBUM_ID",
    referencedColumnName="ALBUM_ID")
    private Album album;
    
    @ManyToMany
    @JoinTable(
        name = "SHARED_IMAGES",
        joinColumns =        @JoinColumn(name = "IMAGE_ID"),
        inverseJoinColumns = @JoinColumn(name = "USER_ID")
    )
    private List<User> sharedOwners = new ArrayList<User>();

	// ********************** Accessor Methods ********************** //

    /**
	 * Getter for property id
	 * 
	 * @return id of image
	 */
    public Long getId() {
        return id;
    }

    /**
	 * Getter for property name
	 * 
	 * @return name of image
	 */
    public String getName() {
        return name;
    }

	/**
	 * Setter for property name
	 * 
	 * @param name - name of image
	 */
    public void setName(String name) {
        this.name = name;
    }

    public List<User> getSharedOwners() {
		return sharedOwners;
	}

	public void setSharedOwners(List<User> sharedOwners) {
		this.sharedOwners = sharedOwners;
	}
	
	/**
	 * Getter for property description
	 * 
	 * @return description of image
	 */
    public String getDescription() {
        return description;
    }

	/**
	 * Setter for property description
	 * 
	 * @param description - description of image
	 */
    public void setDescription(String description) {
        this.description = description;
    }

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}
	
	public Album getAlbum() {
		return album;
	}

	public void setAlbum(Album album) {
		this.album = album;
	}

	public String getAlbumName() {
		if(null == albumName && this.getAlbum() != null){
			albumName = this.getAlbum().getName();
		}
		return albumName;
	}

	public String getCameraModel() {
		return cameraModel;
	}

	public void setCameraModel(String cameraModel) {
		this.cameraModel = cameraModel;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public double getSize() {
		return size;
	}

	public void setSize(double size) {
		this.size = size;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public Date getUploaded() {
		return uploaded;
	}

	public void setUploaded(Date uploaded) {
		this.uploaded = uploaded;
	}

}
