package com.jasamedika.medifirst2000.entities;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.jasamedika.medifirst2000.base.BaseTransaction;
import com.jasamedika.medifirst2000.helper.Caption;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import static javax.persistence.CascadeType.ALL;
import static javax.persistence.FetchType.LAZY;

@Getter
@Setter
@Entity
@Table(name = "DetailSpekAnggaran_T")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class DetailSpekAnggaran extends BaseTransaction {

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectDetailAnggaranFk")
	@Caption(value = "detail Anggaran")
	private DetailAnggaran detailAnggaran;

	@Column(name = "ObjectDetailAnggaranFk", columnDefinition = "CHAR(32)", insertable = false, updatable = false, nullable = false)
	private String detailAnggaranId;

	@ManyToOne
	@JoinColumn(name = "ObjectProdukFk")
	@Caption(value = "Produk")
	private Produk produk;

	@Column(name = "ObjectProdukFk", insertable = false, updatable = false)
	private Integer produkId;

	@Column(name = "VolumeBarang")
	@Caption(value = "Volume Barang")
	private float volumeBarang;

	@Caption(value = "Harga Satuan Barang")
	@Column(name = "HargaSatuanBarang")
	private Double hargaSatuanBarang;

	@Caption(value = "Total Harga Barang")
	@Column(name = "TotalHargaBarang")
	private Double totalHargaBarang;

	@Column(name = "StatusCode")
	@Caption(value = "Status Code")
	private Integer statusCode;

	@Column(name = "isVerifikasi")
	public String isVerifikasi;

	@Column(name = "isActive")
	public Boolean isActive;

	@ManyToOne
	@JoinColumn(name = "ObjectRuanganFk")
	@Caption(value = "Ruangan")
	private Ruangan ruangan;

	@Column(name = "ObjectRuanganFk", insertable = false, updatable = false)
	private Integer ruanganId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectJenisBelanjaFk")
	@Caption(value = "Jenis Belanja")
	private JenisBelanja jenisBelanja;

	@Column(name = "ObjectJenisBelanjaFk", insertable = false, updatable = false)
	private Integer jenisBelanjaId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectJenisPengadaanFk")
	@Caption(value = "Jenis Pengadaan")
	private JenisPengadaan jenisPengadaan;

	@Column(name = "ObjectJenisBelanjaFk", insertable = false, updatable = false)
	private Integer jenisPengadaanId;

	@Column(name = "PeriodeAwal")
	@Caption(value = "Periode Awal")
	private Date periodeAwal;

	@Column(name = "PeriodeAhir")
	@Caption(value = "Periode Ahir")
	private Date periodeAhir;

	@Column(name = "keterangan")
	@Caption(value = "Keterangan")
	private String keterangan;

	@ManyToOne
	@JoinColumn(name = "ObjectPengendaliFk")
	@Caption(value = "Object Pengendali")
	private Pengendali pengendali;

	@Column(name = "ObjectPengendaliFk", insertable = false, updatable = false)
	private Integer pengendaliId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectDetailSpekAnggaranFk")
	@Caption(value = "Detail Spek ANggaran")
	@JsonBackReference
	private DetailSpekAnggaran detailSpekAnggaran;

	@Column(name = "ObjectDetailSpekAnggaranFk", columnDefinition = "CHAR(32)", insertable = false, updatable = false)
	private String detailSpekAnggaranId;

	@Column(name = "Spesifikasi")
	@Caption(value = "Spesifikasi")
	private String spesifikasi;

	@Column(name = "Tipe")
	@Caption(value = "Tipe")
	private String tipe;

	@JsonManagedReference
	@OneToMany(cascade = ALL, fetch = LAZY, mappedBy = "detailSpekAnggaran")
	private Set<DetailSpekAnggaran> detailSpekAnggaranSet = new HashSet<>();

	@Transient
	private Date pelaksanaanPemilihanAwal;

	@Transient
	private Date pelaksanaanPemilihanAhir;

	@Transient
	private Date pelaksanaanPekerjaanAwal;

	@Transient
	private Date pelaksanaanPekerjaanAhir;

	@Transient
	private String keteranganRup;

}
