package com.jasamedika.medifirst2000.entities;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.jasamedika.medifirst2000.base.BaseMaster;
import com.jasamedika.medifirst2000.helper.Caption;
import com.jasamedika.medifirst2000.listener.MyEventListener;
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.FetchType.LAZY;
import static javax.persistence.GenerationType.SEQUENCE;

@Getter
@Setter
@Entity
@Table(name = "Pasien_M")
@EntityListeners(value = { MyEventListener.class })
public class Pasien extends BaseMaster {
	@Id
	@GeneratedValue(strategy = SEQUENCE, generator = "public.pasien_m_id_seq")
	@SequenceGenerator(name = "public.pasien_m_id_seq", sequenceName = "public.pasien_m_id_seq", allocationSize = 1)
	@Column(name = "id")
	protected Integer id;

	@Transient
	private String umur;

	@Column(name = "TglMeninggal")
	@Caption(value = "Tanggal Meninggal")
	private Date tanggalMeninggal;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "DokumenRekamMedis")
	@Caption(value = "DokumenRekamMedis")
	private Dokumen dokumenRekamMedis;

	@Column(name = "DokumenRekamMedis", insertable = false, updatable = false)
	private Integer dokumenRekamMedisId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectAgamaFk")
	@Caption(value = "Object Agama")
	private Agama agama;

	@Column(name = "ObjectAgamaFk", insertable = false, updatable = false)
	private Integer agamaId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectGolonganDarahFk")
	@Caption(value = "Object Golongan Darah")
	private GolonganDarah golonganDarah;

	@Column(name = "ObjectGolonganDarahFk", insertable = false, updatable = false)
	private Integer golonganDarahId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectJenisKelaminFk")
	@Caption(value = "Object Jenis Kelamin")
	private JenisKelamin jenisKelamin;

	@Column(name = "ObjectJenisKelaminFk", insertable = false, updatable = false)
	private Integer jenisKelaminId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectPekerjaanFk")
	@Caption(value = "Object Pekerjaan")
	private Pekerjaan pekerjaan;

	@Column(name = "ObjectPekerjaanFk", insertable = false, updatable = false)
	private Integer pekerjaanId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectNegaraFk")
	@Caption(value = "Object Negara")
	private Negara negara;

	@Column(name = "ObjectNegaraFk", insertable = false, updatable = false)
	private Integer negaraId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectKebangsaanFk")
	@Caption(value = "Object kebangsaan")
	private Kebangsaan kebangsaan;

	@Column(name = "ObjectKebangsaanFk", insertable = false, updatable = false)
	private Integer kebangsaanId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectPendidikanFk")
	@Caption(value = "Object Pendidikan")
	private Pendidikan pendidikan;

	@Column(name = "ObjectPendidikanFk", insertable = false, updatable = false, nullable = false)
	private Integer pendidikanId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectStatusPerkawinanFk")
	@Caption(value = "Object Status Perkawinan")
	private StatusPerkawinan statusPerkawinan;

	@Column(name = "ObjectStatusPerkawinanFk", insertable = false, updatable = false, nullable = false)
	private Integer statusPerkawinanId;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectTitleFk")
	@Caption(value = "Object Title")
	private TitlePasien titlePasien;

	@Column(name = "ObjectTitleFk", insertable = false, updatable = false)
	private Integer titlePasienId;

	@NotNull(message = "Nama Pasien tidak boleh kosong")
	@Column(name = "NamaPasien", nullable = false, length = 40)
	@Caption(value = "Nama Pasien")
	private String namaPasien;

	@Column(name = "NamaIbu", length = 40)
	@Caption(value = "Nama Ibu")
	private String namaIbu;

	@Column(name = "NamaAyah", length = 40)
	@Caption(value = "Nama Ayah")
	private String namaAyah;

	@Column(name = "namaKeluarga", length = 40)
	@Caption(value = "namaKeluarga")
	private String namaKeluarga;

	@Column(name = "NamaSuamiIstri", length = 40)
	@Caption(value = "Nama Suami/Istri")
	private String namaSuamiIstri;

	@Column(name = "NoTelepon", length = 40)
	@Caption(value = "No Telepon")
	private String noTelepon;

	@Column(name = "noCm")
	@Caption(value = "No C M")
	private String noCm;

	@Column(name = "QPasien")
	@Caption(value = "QPasien")
	private Integer qPasien;

	@NotNull(message = "Tgl Daftar tidak boleh kosong")
	@Column(name = "TglDaftar", nullable = false)
	@Caption(value = "Tanggal Daftar")
	private Date tglDaftar;

	@Column(name = "TglLahir")
	@Caption(value = "Tanggal Lahir")
	private Date tglLahir;

	@OneToMany(fetch = LAZY, mappedBy = "pasien")
	private Set<Alamat> alamats = new HashSet<>();

	@JsonBackReference
	@OneToMany(fetch = LAZY, mappedBy = "pasien")
	private Set<CatatanPasien> catatanPasien = new HashSet<>();

	@JsonBackReference
	@OneToMany(fetch = LAZY, mappedBy = "pasien")
	private Set<AntrianPasienRegistrasi> antrianPasienRegistrasis = new HashSet<>();

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

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

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

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

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

	@Column(name = "TempatLahir")
	@Caption(value = "Tempat Lahir")
	private String tempatLahir;

	@Column(name = "NoBpjs")
	@Caption(value = "No Bpjs")
	private String noBpjs;

	@Column(name = "NoAsuransiLain")
	@Caption(value = "No AsuransiLain")
	private String noAsuransiLain;

	@Column(name = "NoHp")
	@Caption(value = "No Hp")
	private String noHp;

	@Column(name = "JamLahir")
	@Caption(value = "JamLahir")
	private Date jamLahir;

	@Column(name = "email")
	@Caption(value = "Email")
	private String email;
}
