package vn.azteam.tpf.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;

import org.springframework.data.elasticsearch.annotations.Document;
import java.io.Serializable;
import java.time.Instant;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;

/**
 * A TBGuideline.
 */
@Entity
@Table(name = "tb_guideline")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "smf_tbguideline")
public class TBGuideline implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "code")
    private String code;

    @Column(name = "name")
    private String name;

    @Column(name = "duration")
    private Integer duration;

    @Column(name = "description")
    private String description;

    @Column(name = "created_date")
    private Instant createdDate;

    @Column(name = "modified_date")
    private Instant modifiedDate;

    @Column(name = "deleted_date")
    private Instant deletedDate;

    @ManyToOne(fetch=FetchType.LAZY)
    @JsonIgnoreProperties("")
    @JoinColumn(name = "created_by")
    private TBDetailUser createdBy;

    @ManyToOne(fetch=FetchType.LAZY)
    @JsonIgnoreProperties("")
    @JoinColumn(name = "modified_by")
    private TBDetailUser modifiedBy;

    @ManyToOne(fetch=FetchType.LAZY)
    @JsonIgnoreProperties("")
    @JoinColumn(name = "deleted_by")
    private TBDetailUser deletedBy;

    @ManyToOne
    @JsonIgnoreProperties("")
    private TBCustomer tbCustomer;

    @ManyToMany
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    @JoinTable(name = "tb_supplies_has_guideline",
        joinColumns = @JoinColumn(name = "tb_guidelines_id"),
        inverseJoinColumns = @JoinColumn(name = "tb_supplies_id"))
    private Set<TBSupplies> tbSupplies = new HashSet<>();

    // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
    public Long getId() {
        return id;
    }

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

    public String getDescription() {
        return description;
    }

    public TBGuideline description(String description) {
        this.description = description;
        return this;
    }

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

    public Instant getCreatedDate() {
        return createdDate;
    }

    public TBGuideline createdDate(Instant createdDate) {
        this.createdDate = createdDate;
        return this;
    }

    public void setCreatedDate(Instant createdDate) {
        this.createdDate = createdDate;
    }

    public Instant getModifiedDate() {
        return modifiedDate;
    }

    public TBGuideline modifiedDate(Instant modifiedDate) {
        this.modifiedDate = modifiedDate;
        return this;
    }

    public void setModifiedDate(Instant modifiedDate) {
        this.modifiedDate = modifiedDate;
    }

    public Instant getDeletedDate() {
        return deletedDate;
    }

    public TBGuideline deletedDate(Instant deletedDate) {
        this.deletedDate = deletedDate;
        return this;
    }

    public void setDeletedDate(Instant deletedDate) {
        this.deletedDate = deletedDate;
    }

    public TBDetailUser getCreatedBy() {
        return createdBy;
    }

    public TBGuideline createdBy(TBDetailUser tBDetailUser) {
        this.createdBy = tBDetailUser;
        return this;
    }

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

    public TBDetailUser getModifiedBy() {
        return modifiedBy;
    }

    public TBGuideline modifiedBy(TBDetailUser tBDetailUser) {
        this.modifiedBy = tBDetailUser;
        return this;
    }

    public void setModifiedBy(TBDetailUser tBDetailUser) {
        this.modifiedBy = tBDetailUser;
    }

    public TBDetailUser getDeletedBy() {
        return deletedBy;
    }

    public TBGuideline deletedBy(TBDetailUser tBDetailUser) {
        this.deletedBy = tBDetailUser;
        return this;
    }

    public void setDeletedBy(TBDetailUser tBDetailUser) {
        this.deletedBy = tBDetailUser;
    }

    public TBCustomer getTbCustomer() {
        return tbCustomer;
    }

    public TBGuideline tbCustomer(TBCustomer tBCustomer) {
        this.tbCustomer = tBCustomer;
        return this;
    }

    public void setTbCustomer(TBCustomer tBCustomer) {
        this.tbCustomer = tBCustomer;
    }

    public Set<TBSupplies> getTbSupplies() {
        return tbSupplies;
    }

    public TBGuideline tbSupplies(Set<TBSupplies> tBSupplies) {
        this.tbSupplies = tBSupplies;
        return this;
    }

    public TBGuideline addTbSupplies(TBSupplies tBSupplies) {
        this.tbSupplies.add(tBSupplies);
        tBSupplies.getTbGuidelines().add(this);
        return this;
    }

    public TBGuideline removeTbSupplies(TBSupplies tBSupplies) {
        this.tbSupplies.remove(tBSupplies);
        tBSupplies.getTbGuidelines().remove(this);
        return this;
    }

    public void setTbSupplies(Set<TBSupplies> tBSupplies) {
        this.tbSupplies = tBSupplies;
    }

    public Integer getDuration() {
        return duration;
    }

    public void setDuration(Integer duration) {
        this.duration = duration;
    }
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

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


    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        TBGuideline tBGuideline = (TBGuideline) o;
        if (tBGuideline.getId() == null || getId() == null) {
            return false;
        }
        return Objects.equals(getId(), tBGuideline.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getId());
    }

    @Override
    public String toString() {
        return "TBGuideline{" +
            "id=" + getId() +
            ", description='" + getDescription() + "'" +
            ", createdDate='" + getCreatedDate() + "'" +
            ", modifiedDate='" + getModifiedDate() + "'" +
            ", deletedDate='" + getDeletedDate() + "'" +
            "}";
    }
}
