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 org.springframework.data.elasticsearch.annotations.Document;

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

@Entity
@Table(name = "tb_code")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "smf_tbcode")
public class TBCode implements Serializable {

    private static final long serialVersionUID = 1L;

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

    @JsonIgnore
    @OneToOne
    @MapsId
    @JoinColumn(name = "tb_crop_id")
    private TBCrop tbCrop;

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

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

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

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

    @Column(name = "status")
    @Enumerated(value = EnumType.STRING)
    private TBCodeStatusEnum status = TBCodeStatusEnum.NEW;

    @Column(name = "expired_date")
    private Instant expiredDate;

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

    @OneToMany(mappedBy = "tbCode", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
    @OrderBy("id ASC")
    private Set<TBCodeDetails> tbCodeDetails = new HashSet<>();


    public Long getId() {
        return id;
    }

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

    public String getCode() {
        return code;
    }

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

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public String getDescription() {
        return description;
    }

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

    public String getPathImage() {
        return pathImage;
    }

    public void setPathImage(String pathImage) {
        this.pathImage = pathImage;
    }

    public TBCodeStatusEnum getStatus() {
        return status;
    }

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

    public Instant getCreatedDate() {
        return createdDate;
    }

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

    public Instant getExpiredDate() {
        return expiredDate;
    }

    public void setExpiredDate(Instant expiredDate) {
        this.expiredDate = expiredDate;
    }

    public Instant getModifiedDate() {
        return modifiedDate;
    }

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

    public TBDetailUser getCreatedBy() {
        return createdBy;
    }

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

    public TBDetailUser getModifiedBy() {
        return modifiedBy;
    }

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

    public Set<TBCodeDetails> getTbCodeDetails() {
        return tbCodeDetails;
    }

    public void setTbCodeDetails(Set<TBCodeDetails> tbCodeDetails) {
        this.tbCodeDetails = tbCodeDetails;
    }

    public Instant getDeletedDate() {
        return deletedDate;
    }

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

    public TBDetailUser getDeletedBy() {
        return deletedBy;
    }

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

    public TBCrop getTbCrop() {
        return tbCrop;
    }

    public void setTbCrop(TBCrop tbCrop) {
        this.tbCrop = tbCrop;
    }
}
