package com.jasamedika.medifirst2000.entities;

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

import javax.persistence.*;
import javax.validation.constraints.NotNull;
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 = "DetailAnggaran_T")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class DetailAnggaran extends BaseTransaction {

	@ManyToOne
	@JoinColumn(name = "ObjectKegiatanAnggaranFk")
	@Caption(value = "Kegiatan Anggaran")
	@NotNull(message = "Kegiatan Anggaran Harus Diisi")
	private KegiatanAnggaran kegiatanAnggaran;

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

	@Column(name = "TanggalPengajuan")
	@Caption(value = "Tanggal Pengajuan")
	private Date tanggalPengajuan;

	@ManyToOne
	@JoinColumn(name = "ObjectMataAnggaranFk")
	@Caption(value = "Object Akun")
	private MataAnggaran akun;

	@Column(name = "ObjectMataAnggaranFk", insertable = false, updatable = false)
	private Integer akunId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectAsalProdukFk")
	@Caption(value = "Object Asal Produk")
	private AsalProduk asalProduk;

	@Column(name = "ObjectAsalProdukFk", insertable = false, updatable = false)
	private Integer asalProdukId;

	@ManyToOne
	@JoinColumn(name = "ObjectKomponenFk")
	@Caption(value = "Object Komponen")
	private Komponen komponen;

	@Column(name = "ObjectKomponenFk", insertable = false, updatable = false)
	private Integer komponenId;

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

}
