package com.jasamedika.medifirst2000.entities;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.jasamedika.medifirst2000.base.BaseMaster;
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.GenerationType.SEQUENCE;

@Getter
@Setter
@Entity
@Table(name = "KajianEvaluasi_M")
public class KajianEvaluasi extends BaseMaster {

	@ManyToOne
	@JoinColumn(name = "ObjectUserFk")
	@NotNull(message = "User tidak boleh kosong")
	@Caption(value = "Kajian Evaluasi")
	private Pegawai user;

	@Column(name = "ObjectUserFk", insertable = false, updatable = false, nullable = false)
	private Integer userId;

	@Column(name = "noUsulan")
	@Caption(value = "Nomor Usulan")
	private String noUsulan;

	@Column(name = "tglUsulan")
	@Caption(value = "Tanggal Usulan")
	private Date tglUsulan;

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

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

	@JsonManagedReference
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "kajianId")
	@Caption(value = "detailKajianSet")
	private Set<DetailKajianEvaluasi> detailKajianSet = new HashSet<>();

	@Id
	@GeneratedValue(strategy = SEQUENCE, generator = "public.kajianevaluasi_m_id_seq")
	@SequenceGenerator(name = "public.kajianevaluasi_m_id_seq", sequenceName = "public.kajianevaluasi_m_id_seq", allocationSize = 1)
	@Column(name = "id")
	protected Integer id;

}