package vn.azteam.tpf.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.data.elasticsearch.annotations.Document;

import javax.persistence.*;
import java.io.Serializable;
import java.time.Instant;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * A TBCrop.
 */
@Entity
@Table(name = "tb_crop")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "smf_tbcrop")
public class TBCrop implements Serializable {

    private static final long serialVersionUID = 1L;

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

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

    @Column(name = "code", unique = true)
    private String code;

    @Column(name = "area_m2")
    private Double areaM2;

    @Column(name = "start_date")
    private Instant startDate;

    @Column(name = "end_date")
    private Instant endDate;

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

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

    @Column(name = "age_day_start_at")
    private Integer ageDayStartAt;

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

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

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

    @ManyToOne
    @JsonIgnoreProperties("")
    private TBCropType tbCropType;

    @ManyToOne
    @JsonIgnoreProperties("")
    private TBSupplies tbSupplies;

    @ManyToOne
    @JsonIgnoreProperties("")
    private TBGuideline tbGuideline;

    @ManyToOne
    @JsonIgnoreProperties("")
    private TBEntity tbEntity;

    @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;

    @ManyToMany
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    @JoinTable(name = "tb_assignment",
        joinColumns = @JoinColumn(name = "tb_crops_id"/*, referencedColumnName = "id"*/),
        inverseJoinColumns = @JoinColumn(name = "tb_detail_users_id"/*, referencedColumnName = "id"*/))
    private Set<TBDetailUser> tbDetailUsers = new HashSet<>();

    @OneToOne(mappedBy = "tbCrop", cascade = CascadeType.ALL)
    @PrimaryKeyJoinColumn
    private TBCode tbCode;

//    @ManyToMany
//    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
//    @JoinTable(name = "tb_crop_code",
//        joinColumns = @JoinColumn(name = "tb_crop_id"/*, referencedColumnName = "id"*/),
//        inverseJoinColumns = @JoinColumn(name = "tb_code_id"/*, referencedColumnName = "id"*/))
//    private Set<TBCode> tbCodes = 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 getQrCode() {
        return qrCode;
    }

    public TBCrop qrCode(String qrCode) {
        this.qrCode = qrCode;
        return this;
    }

    public void setQrCode(String qrCode) {
        this.qrCode = qrCode;
    }

    public TBCropType getTbCropType() {
        return tbCropType;
    }

    public TBCrop tbCropType(TBCropType tbCropType) {
        this.tbCropType = tbCropType;
        return this;
    }

    public String getCode() {
        return code;
    }

    public TBCrop code(String code) {
        this.code = code;
        return this;
    }

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

    public Double getAreaM2() {
        return areaM2;
    }

    public TBCrop areaM2(Double areaM2) {
        this.areaM2 = areaM2;
        return this;
    }

    public void setAreaM2(Double areaM2) {
        this.areaM2 = areaM2;
    }

    public void setTbCropType(TBCropType tbCropType) {
        this.tbCropType = tbCropType;
    }

    public Instant getStartDate() {
        return startDate;
    }

    public TBCrop startDate(Instant startDate) {
        this.startDate = startDate;
        return this;
    }

    public void setStartDate(Instant startDate) {
        this.startDate = startDate;
    }

    public Instant getEndDate() {
        return endDate;
    }

    public TBCrop endDate(Instant endDate) {
        this.endDate = endDate;
        return this;
    }

    public void setEndDate(Instant endDate) {
        this.endDate = endDate;
    }

    public String getStatus() {
        return status;
    }

    public TBCrop status(String status) {
        this.status = status;
        return this;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getDescription() {
        return description;
    }

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

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

    public Integer getAgeDayStartAt() {
        return ageDayStartAt;
    }

    public TBCrop ageDayStartAt(Integer ageDayStartAt) {
        this.ageDayStartAt = ageDayStartAt;
        return this;
    }

    public void setAgeDayStartAt(Integer ageDayStartAt) {
        this.ageDayStartAt = ageDayStartAt;
    }

    public Instant getCreatedDate() {
        return createdDate;
    }

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

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

    public Instant getModifiedDate() {
        return modifiedDate;
    }

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

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

    public Instant getDeletedDate() {
        return deletedDate;
    }

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

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

    public TBSupplies getTbSupplies() {
        return tbSupplies;
    }

    public TBCrop tbSupplies(TBSupplies tBSupplies) {
        this.tbSupplies = tBSupplies;
        return this;
    }

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

    public TBGuideline getTbGuideline() {
        return tbGuideline;
    }

    public TBCrop tbGuideline(TBGuideline tBGuideline) {
        this.tbGuideline = tBGuideline;
        return this;
    }

    public void setTbGuideline(TBGuideline tBGuideline) {
        this.tbGuideline = tBGuideline;
    }

    public TBEntity getTbEntity() {
        return tbEntity;
    }

    public TBCrop tbEntity(TBEntity tBEntity) {
        this.tbEntity = tBEntity;
        return this;
    }

    public void setTbEntity(TBEntity tBEntity) {
        this.tbEntity = tBEntity;
    }

    public TBDetailUser getCreatedBy() {
        return createdBy;
    }

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

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

    public TBDetailUser getModifiedBy() {
        return modifiedBy;
    }

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

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

    public TBDetailUser getDeletedBy() {
        return deletedBy;
    }

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

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

    public Set<TBDetailUser> getTbDetailUsers() {
        return tbDetailUsers;
    }

    public TBCrop tbDetailUsers(Set<TBDetailUser> tBDetailUsers) {
        this.tbDetailUsers = tBDetailUsers;
        return this;
    }

    public TBCrop addTbDetailUser(TBDetailUser tBDetailUser) {
        this.tbDetailUsers.add(tBDetailUser);
        tBDetailUser.getTbCrops().add(this);
        return this;
    }

    public TBCrop removeTbDetailUser(TBDetailUser tBDetailUser) {
        this.tbDetailUsers.remove(tBDetailUser);
        tBDetailUser.getTbCrops().remove(this);
        return this;
    }

    public void setTbDetailUsers(Set<TBDetailUser> tBDetailUsers) {
        this.tbDetailUsers = tBDetailUsers;
    }
    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove


    public TBCode getTbCode() {
        return tbCode;
    }

    public void setTbCode(TBCode tbCode) {
        this.tbCode = tbCode;
    }

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

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

    @Override
    public String toString() {
        return "TBCrop{" +
            "id=" + getId() +
            ", qrCode='" + getQrCode() + "'" +
            ", code='" + getCode() + "'" +
            ", areaM2='" + getAreaM2() + "'" +
            ", tbCropType=" + getTbCropType() +
            ", startDate='" + getStartDate() + "'" +
            ", endDate='" + getEndDate() + "'" +
            ", status='" + getStatus() + "'" +
            ", description='" + getDescription() + "'" +
            ", ageDayStartAt=" + getAgeDayStartAt() +
            ", createdDate='" + getCreatedDate() + "'" +
            ", modifiedDate='" + getModifiedDate() + "'" +
            ", deletedDate='" + getDeletedDate() + "'" +
            "}";
    }
}
