package com.jasamedika.medifirst2000.entities;

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 javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

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

@Getter
@Setter
@Entity
@Table(name = "KartuPengendali_T")
public class KartuPengendali extends BaseTransaction {

	@Column(name = "NoUsulan", nullable = false)
	@Caption(value = "No Usulan")
	private String noUsulan;

	@NotNull(message = "tanggal")
	@Column(name = "Tanggal", nullable = false)
	@Caption(value = "Tanggal")
	private Date tanggal;

	@Column(name = "TanggalDibutuhkan")
	@Caption(value = "TanggalDibtuhkan")
	private Date tanggalDibutuhkan;

	@JsonManagedReference
	@OneToMany(cascade = ALL, fetch = LAZY, mappedBy = "kartuPengendali")
	private List<KartuPengendaliDetail> kartuPengendaliDetail = new ArrayList<>();

	@Column(name = "Jumlah")
	@Caption(value = "Jumlah")
	private Double jumlah;

	@Column(name = "Ppn")
	@Caption(value = "Ppn")
	private Double ppn;

	@Column(name = "Total")
	@Caption(value = "Total")
	private Double total;

	@Column(name = "Pembulatan")
	@Caption(value = "Pembulatan")
	private Double pembulatan;

	@Column(name = "Terbilang")
	@Caption(value = "Terbilang")
	private String terbilang;

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

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

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

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

	@ManyToOne
	@JoinColumn(name = "ObjectMataAnggaranFk")
	@Caption(value = "Object Mata Anggaran")
	private MataAnggaran mataAnggaran;

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

}
