package de.hsadmin.mods.pac;

import static javax.persistence.GenerationType.SEQUENCE;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.user.UnixUser;

@Entity(name = "INetAddresses")
@Table(name = "inet_addr")
@SequenceGenerator(name = "INetAddressesSeqGen", sequenceName = "inet_addr_inet_addr_id_seq")
public class INetAddress extends AbstractEntity implements Serializable {
	
	private static final long serialVersionUID = -5792279453911426607L;

	@Id
	@GeneratedValue(strategy = SEQUENCE, generator = "INetAddressesSeqGen")
	@Column(name = "inet_addr_id")
	private long id;

	@Column(name = "inet_addr", unique = true, length=-1)
	private String inetAddr;

	@Column(name = "description", columnDefinition = "character varying(100)")
	private String description;

	public INetAddress() {
	}

	public INetAddress(String inetAddr) {
		this.inetAddr = inetAddr;
	}

	public INetAddress(String inetAddr, String desc) {
		this(inetAddr);
		description = desc;
	}

	public static String createQueryFromStringKey(String humanKey) {
		return "inetAddr='" + humanKey + "'";
	}

	@Override
	public String createStringKey() {
		return getInetAddr();
	}

	@Override
	public long id() {
		return id;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getInetAddr() {
		return inetAddr;
	}

	public void setInetAddr(String inetAddr) {
		this.inetAddr = inetAddr;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Override
	public boolean isNew() {
		return id == 0;
	}

	@Override
	public UnixUser owningUser(EntityManager em) {
		return null; // TODO: kinda somebody like root needed
	}
}
