package org.sistema.hibernate.onetooneunidirannotations.models;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

/**
 * Port class represents a tcp/udp port
 * @author Eugenia Pérez Martínez
 * @email eugenia_perez@cuatrovientos.org
 */
@Entity
public class Port {
	
	@Id
	@GeneratedValue(generator = "gen")
	@GenericGenerator(name = "gen", strategy = "foreign", parameters =
	@Parameter(name = "property", value = "service"))
	private Long id;
	private Integer number;
	private String type;
	

	@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
	@PrimaryKeyJoinColumn
	private Service service;

	/**
	 * default constructor
	 */
	public Port () {
	}

	/**
	 * @param id
	 * @param number
	 * @param type
	 * @param service
	 */
	public Port(Long id, Integer number, String type, Service service) {
		this.id = id;
		this.number = number;
		this.type = type;
		this.service = service;
	}


	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}


	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}


	/**
	 * @return the number
	 */
	public Integer getNumber() {
		return number;
	}


	/**
	 * @param number the number to set
	 */
	public void setNumber(Integer number) {
		this.number = number;
	}


	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}


	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the service
	 */
	public Service getService() {
		return service;
	}

	/**
	 * @param service the service to set
	 */
	public void setService(Service service) {
		this.service = service;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Port [id=" + id + ", number=" + number + ", type=" + type
				+ ", service=" + service + "]";
	}
}
