package com.jasamedika.medifirst2000.entities;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.gson.annotations.Expose;
import com.jasamedika.medifirst2000.base.BaseMaster;
import com.jasamedika.medifirst2000.helper.Caption;

@Entity
@Table(name = "Ruangan_M")
@JsonSerialize
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class Ruangan extends BaseMaster {

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

	@Column(name = "KdInternal", nullable = true, length = 5)
	@Caption(value = "KodeInternal")
	private String kdInternal;

	@Column(name = "AlamatEmail", nullable = true, length = 50)
	@Caption(value = "Alamat Email")
	private String alamatEmail;

	@Column(name = "Faksimile", nullable = true, length = 30)
	@Caption(value = "Faksimile")
	private String faksimile;

	@Column(name = "FixedPhone", nullable = true, length = 30)
	@Caption(value = "Fixed Phone")
	private String fixedPhone;

	@Column(name = "JamBuka", nullable = true, length = 5)
	@Caption(value = "Jam Buka")
	private String jamBuka;

	@Column(name = "JamTutup", nullable = true, length = 5)
	@Caption(value = "Jam Tutup")
	private String jamTutup;

	@ManyToOne
	@JoinColumn(name = "ObjectUnitKerjaFk")
	@Caption(value = "Object Unit Kerja")
	private UnitKerjaPegawai unitKerja;

	@Column(name = "ObjectUnitKerjaFk", insertable = false, updatable = false)
	private Integer unitKerjaId;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ObjectDepartemenFk")
	@Expose(serialize = false)
	@Caption(value = "Object Departemen")
	private Departemen departemen;

	@Column(name = "ObjectDepartemenFk", insertable = false, updatable = false)
	private Integer departemenId;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ObjectKelasHeadFk")
	@Caption(value = "Object Kelas Head")
	private Kelas kelasHead;

	@Column(name = "ObjectKelasHeadFk", insertable = false, updatable = false, nullable = false)
	private Integer kelasHeadId;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ObjectModulAplikasiFk")
	@Caption(value = "Object Modul Aplikasi")
	private ModulAplikasi modulAplikasi;

	@Column(name = "ObjectModulAplikasiFk", insertable = false, updatable = false)
	private Integer modulAplikasiId;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ObjectPegawaiKepalaFk")
	@Caption(value = "Object Pegawai Kepala")
	private Pegawai pegawaiKepala;

	@Column(name = "ObjectPegawaiKepalaFk", insertable = false, updatable = false)
	private Integer pegawaiKepalaId;

	@NotNull(message = "Kd Ruangan tidak boleh kosong")
	@Column(name = "KdRuangan", nullable = false, length = 3)
	@Caption(value = "Kode Ruangan")
	private String kdRuangan;

	@Column(name = "LokasiRuangan", nullable = true, length = 50)
	@Caption(value = "Lokasi Ruangan")
	private String lokasiRuangan;

	@Column(name = "MobilePhone", nullable = true, length = 30)
	@Caption(value = "Mobile Phone")
	private String mobilePhone;

	@NotNull(message = "Nama Ruangan tidak boleh kosong")
	@Column(name = "NamaRuangan", nullable = false, length = 50)
	@Caption(value = "Nama Ruangan")
	private String namaRuangan;

	@Column(name = "NoCounter", nullable = true)
	@Caption(value = "No Counter")
	private Integer noCounter;

	@Column(name = "NoRuangan", nullable = true, length = 4)
	@Caption(value = "No Ruangan")
	private String noRuangan;

	@Column(name = "PrefixNoAntrian", nullable = true, length = 4)
	@Caption(value = "Prefix No Antrian")
	private String prefixNoAntrian;

	@NotNull(message = "QRuangan tidak boleh kosong")
	@Column(name = "QRuangan", nullable = false)
	@Caption(value = "QRuangan")
	private short qRuangan;

	@Column(name = "StatusViewData", nullable = true)
	@Caption(value = "Status View Data")
	private Boolean statusViewData;

	@Column(name = "Website", nullable = true, length = 80)
	@Caption(value = "Website")
	private String website;

	@Column(name = "tanggal", nullable = true)
	@Caption(value = "tanggal")
	private Date tanggal;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ObjectRuanganFk")
	@Caption(value = "Object Ruangan")
	private Ruangan headRuangan;

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

	@JsonBackReference
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "ruangan")
	Set<Kamar> kamarSet = new HashSet<>();

	public Ruangan(String jamBuka, String jamTutup, String kdRuangan, String namaRuangan, String noRuangan,
			Boolean statusViewData, Integer id, Integer departemenId, Ruangan head) {
		super();

		this.departemenId = departemenId;
		this.jamBuka = jamBuka;
		this.jamTutup = jamTutup;
		this.departemenId = departemenId;
		this.kdRuangan = kdRuangan;
		this.namaRuangan = namaRuangan;
		this.noRuangan = noRuangan;
		this.statusViewData = statusViewData;
		this.headRuangan = head;
		this.id = id;
	}

	public Ruangan(String jamBuka, String jamTutup, String kdRuangan, String namaRuangan, String noRuangan,
			Boolean statusViewData, Integer id, Integer departemenId) {
		super();

		this.departemenId = departemenId;
		this.jamBuka = jamBuka;
		this.jamTutup = jamTutup;
		this.departemenId = departemenId;
		this.kdRuangan = kdRuangan;
		this.namaRuangan = namaRuangan;
		this.noRuangan = noRuangan;
		this.statusViewData = statusViewData;
		this.id = id;
	}

	public Ruangan(String kdRuangan, String namaRuangan, Integer id) {
		super();
		this.kdRuangan = kdRuangan;
		this.namaRuangan = namaRuangan;
		this.id = id;
	}

	public Ruangan(String namaRuangan, Integer id, String kdDepartemen, String namaDepartemen, Integer departementId) {
		super();
		this.namaRuangan = namaRuangan;
		this.id = id;
		this.departemen = new Departemen(kdDepartemen, namaDepartemen, departementId);
	}

	public Ruangan() {

	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getKdInternal() {
		return kdInternal;
	}

	public void setKdInternal(String kdInternal) {
		this.kdInternal = kdInternal;
	}

	public String getAlamatEmail() {
		return alamatEmail;
	}

	public void setAlamatEmail(String alamatEmail) {
		this.alamatEmail = alamatEmail;
	}

	public String getFaksimile() {
		return faksimile;
	}

	public void setFaksimile(String faksimile) {
		this.faksimile = faksimile;
	}

	public String getFixedPhone() {
		return fixedPhone;
	}

	public void setFixedPhone(String fixedPhone) {
		this.fixedPhone = fixedPhone;
	}

	public String getJamBuka() {
		return jamBuka;
	}

	public void setJamBuka(String jamBuka) {
		this.jamBuka = jamBuka;
	}

	public String getJamTutup() {
		return jamTutup;
	}

	public void setJamTutup(String jamTutup) {
		this.jamTutup = jamTutup;
	}

	public Departemen getDepartemen() {
		return departemen;
	}

	public void setDepartemen(Departemen departemen) {
		this.departemen = departemen;
	}

	public Integer getDepartemenId() {
		return departemenId;
	}

	public void setDepartemenId(Integer departemenId) {
		this.departemenId = departemenId;
	}

	public Kelas getKelasHead() {
		return kelasHead;
	}

	public void setKelasHead(Kelas kelasHead) {
		this.kelasHead = kelasHead;
	}

	public Integer getKelasHeadId() {
		return kelasHeadId;
	}

	public void setKelasHeadId(Integer kelasHeadId) {
		this.kelasHeadId = kelasHeadId;
	}

	public ModulAplikasi getModulAplikasi() {
		return modulAplikasi;
	}

	public void setModulAplikasi(ModulAplikasi modulAplikasi) {
		this.modulAplikasi = modulAplikasi;
	}

	public Integer getModulAplikasiId() {
		return modulAplikasiId;
	}

	public void setModulAplikasiId(Integer modulAplikasiId) {
		this.modulAplikasiId = modulAplikasiId;
	}

	public Pegawai getPegawaiKepala() {
		return pegawaiKepala;
	}

	public void setPegawaiKepala(Pegawai pegawaiKepala) {
		this.pegawaiKepala = pegawaiKepala;
	}

	public Integer getPegawaiKepalaId() {
		return pegawaiKepalaId;
	}

	public void setPegawaiKepalaId(Integer pegawaiKepalaId) {
		this.pegawaiKepalaId = pegawaiKepalaId;
	}

	public String getKdRuangan() {
		return kdRuangan;
	}

	public void setKdRuangan(String kdRuangan) {
		this.kdRuangan = kdRuangan;
	}

	public String getLokasiRuangan() {
		return lokasiRuangan;
	}

	public void setLokasiRuangan(String lokasiRuangan) {
		this.lokasiRuangan = lokasiRuangan;
	}

	public String getMobilePhone() {
		return mobilePhone;
	}

	public void setMobilePhone(String mobilePhone) {
		this.mobilePhone = mobilePhone;
	}

	public String getNamaRuangan() {
		return namaRuangan;
	}

	public void setNamaRuangan(String namaRuangan) {
		this.namaRuangan = namaRuangan;
	}

	public Integer getNoCounter() {
		return noCounter;
	}

	public void setNoCounter(Integer noCounter) {
		this.noCounter = noCounter;
	}

	public String getNoRuangan() {
		return noRuangan;
	}

	public void setNoRuangan(String noRuangan) {
		this.noRuangan = noRuangan;
	}

	public String getPrefixNoAntrian() {
		return prefixNoAntrian;
	}

	public void setPrefixNoAntrian(String prefixNoAntrian) {
		this.prefixNoAntrian = prefixNoAntrian;
	}

	public short getqRuangan() {
		return qRuangan;
	}

	public void setqRuangan(short qRuangan) {
		this.qRuangan = qRuangan;
	}

	public Boolean getStatusViewData() {
		return statusViewData;
	}

	public void setStatusViewData(Boolean statusViewData) {
		this.statusViewData = statusViewData;
	}

	public String getWebsite() {
		return website;
	}

	public void setWebsite(String website) {
		this.website = website;
	}

	public Date getTanggal() {
		return tanggal;
	}

	public void setTanggal(Date tanggal) {
		this.tanggal = tanggal;
	}

	public Ruangan getHeadRuangan() {
		return headRuangan;
	}

	public void setHeadRuangan(Ruangan headRuangan) {
		this.headRuangan = headRuangan;
	}

	public Integer getHeadRuanganId() {
		return headRuanganId;
	}

	public void setHeadRuanganId(Integer headRuanganId) {
		this.headRuanganId = headRuanganId;
	}

	public Set<Kamar> getKamarSet() {
		return kamarSet;
	}

	public void setKamarSet(Set<Kamar> kamarSet) {
		this.kamarSet = kamarSet;
	}

	public UnitKerjaPegawai getUnitKerja() {
		return unitKerja;
	}

	public void setUnitKerja(UnitKerjaPegawai unitKerja) {
		this.unitKerja = unitKerja;
	}

	public Integer getUnitKerjaId() {
		return unitKerjaId;
	}

	public void setUnitKerjaId(Integer unitKerjaId) {
		this.unitKerjaId = unitKerjaId;
	}
	
	@Override
	public String toString() {
		return "Ruangan [id=" + id + ", namaRuangan=" + namaRuangan + ", statusEnabled=" + statusEnabled + "]";
	}

}
