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 TBDetailUser.
 */
@Entity
@Table(name = "tb_detail_user")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "smf_tbdetailuser")
public class TBDetailUser implements Serializable {

    private static final long serialVersionUID = 1L;

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

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

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

    @Column(name = "birthday")
    private Instant birthday;

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

    @ManyToOne
    @JsonIgnoreProperties("")
    private TBRole tbRole;

    @ManyToOne
    @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
    private TBCustomer tbCustomer;

    @ManyToOne
    @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
    private TBAddress tbAddress;

    @JsonIgnore
    @OneToOne
    @MapsId
    private User user;

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

    @ManyToMany(mappedBy = "tbDetailUsers")
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    @JsonIgnore
    private Set<TBCrop> tbCrops = 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 getFullName() {
        return fullName;
    }

    public TBDetailUser fullName(String fullName) {
        this.fullName = fullName;
        return this;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getPhone() {
        return phone;
    }

    public TBDetailUser phone(String phone) {
        this.phone = phone;
        return this;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public Instant getBirthday() {
        return birthday;
    }

    public TBDetailUser birthday(Instant birthday) {
        this.birthday = birthday;
        return this;
    }

    public void setBirthday(Instant birthday) {
        this.birthday = birthday;
    }

    public Integer getGender() {
        return gender;
    }

    public TBDetailUser gender(Integer gender) {
        this.gender = gender;
        return this;
    }

    public void setGender(Integer gender) {
        this.gender = gender;
    }

    public TBRole getTbRole() {
        return tbRole;
    }

    public TBDetailUser tbRole(TBRole tBRole) {
        this.tbRole = tBRole;
        return this;
    }

    public void setTbRole(TBRole tBRole) {
        this.tbRole = tBRole;
    }

    public TBCustomer getTbCustomer() {
        return tbCustomer;
    }

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

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

    public TBAddress getTbAddress() {
        return tbAddress;
    }

    public TBDetailUser tbAddress(TBAddress tBAddress) {
        this.tbAddress = tBAddress;
        return this;
    }

    public void setTbAddress(TBAddress tBAddress) {
        this.tbAddress = tBAddress;
    }

    public String getFcmToken() {
        return fcmToken;
    }

    public TBDetailUser fcmToken(String fcmToken) {
        this.fcmToken = fcmToken;
        return this;
    }

    public void setFcmToken(String fcmToken) {
        this.fcmToken = fcmToken;
    }

    public User getUser() {
        return user;
    }

    public TBDetailUser user(User user) {
        this.user = user;
        return this;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Set<TBCrop> getTbCrops() {
        return tbCrops;
    }

    public TBDetailUser tbCrops(Set<TBCrop> tBCrops) {
        this.tbCrops = tBCrops;
        return this;
    }

    public TBDetailUser addTbCrop(TBCrop tBCrop) {
        this.tbCrops.add(tBCrop);
        tBCrop.getTbDetailUsers().add(this);
        return this;
    }

    public TBDetailUser removeTbCrop(TBCrop tBCrop) {
        this.tbCrops.remove(tBCrop);
        tBCrop.getTbDetailUsers().remove(this);
        return this;
    }

    public void setTbCrops(Set<TBCrop> tBCrops) {
        this.tbCrops = tBCrops;
    }
    // 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;
        }
        TBDetailUser tBDetailUser = (TBDetailUser) o;
        if (tBDetailUser.getId() == null || getId() == null) {
            return false;
        }
        return Objects.equals(getId(), tBDetailUser.getId());
    }

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

    @Override
    public String toString() {
        return "TBDetailUser{" +
            "id=" + getId() +
            ", fullName='" + getFullName() + "'" +
            ", phone='" + getPhone() + "'" +
            ", birthday='" + getBirthday() + "'" +
            ", gender=" + getGender() +
            ", fcmToken=" + getFcmToken() +
            "}";
    }
}
