package mobi.droidcloud.mgmt.model;

import static javax.persistence.FetchType.LAZY;
import static javax.persistence.GenerationType.IDENTITY;

import java.util.Collection;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "T_DOMAIN")
public class Domain {

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(nullable = false)
	private int id;
	@Basic
	private String name;
	@OneToMany(mappedBy = "domain")
	private Collection<DomainManaged> domainManaged;

	@Column(name = "parentDomainId", nullable=true)
	private Integer parentDomainId;

	@ManyToOne(fetch = LAZY, optional = true)
    @JoinColumn(name = "parentDomainId", nullable=true, insertable=false, updatable=false)
	private Domain parentDomain;
	
	@OneToMany(mappedBy = "parentDomain", fetch = LAZY)
	private Collection<Domain> subDomains;
	
	public int getId() {
		return id;
	}

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

	public void setName(String param) {
		this.name = param;
	}

	public String getName() {
		return name;
	}

	public Collection<DomainManaged> getDomainManaged() {
	    return domainManaged;
	}

	public void setDomainManaged(Collection<DomainManaged> param) {
	    this.domainManaged = param;
	}

	public Domain getParentDomain() {
	    return parentDomain;
	}

	public void setParentDomain(Domain param) {
	    this.parentDomain = param;
	}

	public Integer getParentDomainId() {
		System.out.println("***************** getparentDomainId ********************");
		System.out.println("returning parentDomainId -> " + (this.parentDomainId == null ? "null" : this.parentDomainId));
		return this.parentDomainId;
	}

	public void setParentDomainId(Integer parentDomainId) {
		System.out.println("***************** setparentDomainId() ********************");
		System.out.println("setting parentDomainId to " + (parentDomainId == null ? "null" : parentDomainId));
		this.parentDomainId = parentDomainId;
	}

	public Collection<Domain> getSubDomains() {
	    return subDomains;
	}

	public void setSubDomains(Collection<Domain> param) {
	    this.subDomains = param;
	}

}