package com.tmdworldwide.projectmanager.db;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;
import java.io.Serializable;

@Entity
@Table(name="workflow_master_item")
public class WorkflowMasterItem implements Serializable {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="workflow_master_item_id")
	private Integer id;

	@Column(nullable = false)
	private String name;

	@Column(nullable = false)
	@Lob
	private String description;

	@Column(nullable = false)
	private Integer position;

	// TODO figure out what the heck mappedBy actually does
	@ManyToMany
	private Set<Role> roles;

	@ManyToOne
	@JoinColumn(name = "success_item_id")
	private WorkflowMasterItem successItem;

	@ManyToOne
	@JoinColumn(name = "fail_item_id")
	private WorkflowMasterItem failItem;

	private int duration;

	@ManyToOne
	@JoinColumn(name = "duration_type_id")
	private DurationType durationType;

	@ManyToOne
	@JoinColumn(name = "workflow_item_type_id")
	private WorkflowItemType workflowItemType;

	@ManyToOne
	@JoinColumn(name = "workflow_master_id", nullable = false, insertable=false, updatable=false)
	private WorkflowMaster workflowMaster;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="created_timestamp")
	private Date createdTimestamp;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "created_user_id", nullable = false)
	private User createdBy;

	@Temporal(TemporalType.TIMESTAMP)
	@Version
	@Column(name="updated_timestamp")
	private Date updatedTimestamp;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "updated_user_id", nullable = false)
	private User updatedBy;

	@Column(columnDefinition="bool default 't'")
	private boolean active;

	public Integer getId() {
		return id;
	}

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

	public String getName() {
		return name;
	}

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

	public String getDescription() {
		return description;
	}

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

	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	public WorkflowMasterItem getSuccessItem() {
		return successItem;
	}

	public void setSuccessItem(WorkflowMasterItem successItem) {
		this.successItem = successItem;
	}

	public WorkflowMasterItem getFailItem() {
		return failItem;
	}

	public void setFailItem(WorkflowMasterItem failItem) {
		this.failItem = failItem;
	}

	public Date getCreatedTimestamp() {
		return createdTimestamp;
	}

	public void setCreatedTimestamp(Date createdTimestamp) {
		this.createdTimestamp = createdTimestamp;
	}

	public User getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(User createdBy) {
		this.createdBy = createdBy;
	}

	public Date getUpdatedTimestamp() {
		return updatedTimestamp;
	}

	public void setUpdatedTimestamp(Date updatedTimestamp) {
		this.updatedTimestamp = updatedTimestamp;
	}

	public User getUpdatedBy() {
		return updatedBy;
	}

	public void setUpdatedBy(User updatedBy) {
		this.updatedBy = updatedBy;
	}

	public WorkflowMaster getWorkflowMaster() {
		return workflowMaster;
	}

	public void setWorkflowMaster(WorkflowMaster workflowMaster) {
		this.workflowMaster = workflowMaster;
	}

	public Integer getPosition() {
		return position;
	}

	public void setPosition(Integer position) {
		this.position = position;
	}

	public WorkflowItemType getWorkflowItemType() {
		return workflowItemType;
	}

	public void setWorkflowItemType(WorkflowItemType workflowItemType) {
		this.workflowItemType = workflowItemType;
	}

	public DurationType getDurationType() {
		return durationType;
	}

	public void setDurationType(DurationType durationType) {
		this.durationType = durationType;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }
}
