package com.jasamedika.medifirst2000.entities;

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.jasamedika.medifirst2000.base.BaseMaster;
import com.jasamedika.medifirst2000.helper.Caption;

@SuppressWarnings("serial")
@Entity
@Table(name = "LoginUser_S")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class LoginUser extends BaseMaster {

	public LoginUser() {}

	public LoginUser(String kataSandi, KelompokUser kelompokUser, String namaUser, String namaLengkap,
			String namaPanggilan, String nikIntern, String nipPns, String noIdentitas, String npwp, Integer id,
			String email, Integer ruanganId, String namaRuangan, String kdDepartemen, String namaDepartemen,
			Integer departemenId) {
		super();
		this.kataSandi = kataSandi;
		this.kelompokUser = kelompokUser;
		this.namaUser = namaUser;
		this.pegawai = new Pegawai(namaLengkap, namaPanggilan, nikIntern, nipPns, noIdentitas, npwp, id, email,
				ruanganId, namaRuangan, kdDepartemen, namaDepartemen, departemenId);
	}

	public LoginUser(Integer idLoginUser, String kataSandi, KelompokUser kelompokUser, String namaUser,
			String namaLengkap, String namaPanggilan, String nikIntern, String nipPns, String noIdentitas, String npwp, 
			Integer id, String email, Integer ruanganId, 
			String namaRuangan, String kdDepartemen, String namaDepartemen,
			Integer departemenId) {
		super();
		this.id = idLoginUser;
		this.kataSandi = kataSandi;
		this.kelompokUser = kelompokUser;
		this.namaUser = namaUser;
		this.pegawai = new Pegawai(namaLengkap, namaPanggilan, nikIntern, nipPns, noIdentitas, npwp, id, email,
				ruanganId, namaRuangan, kdDepartemen, namaDepartemen, departemenId);
	}
	
//	public LoginUser(Integer idLoginUser, String kataSandi, KelompokUser kelompokUser, String namaUser,
//			String namaLengkap, String namaPanggilan, String nikIntern, String nipPns, String noIdentitas, String npwp, 
//			Integer unitKerjaId, String unitKerja,	Integer id, String email, Integer ruanganId, 
//			String namaRuangan, String kdDepartemen, String namaDepartemen,
//			Integer departemenId) {
//		super();
//		this.id = idLoginUser;
//		this.kataSandi = kataSandi;
//		this.kelompokUser = kelompokUser;
//		this.namaUser = namaUser;
//		this.pegawai = new Pegawai(namaLengkap, namaPanggilan, nikIntern, nipPns, noIdentitas, npwp,unitKerjaId,unitKerja, id, email,
//				ruanganId, namaRuangan, kdDepartemen, namaDepartemen, departemenId);
//	}

	public LoginUser(Integer idLoginUser, KelompokUser kelompokUser, String namaUser, String namaLengkap,
			String namaPanggilan, String nikIntern, String nipPns, String noIdentitas, String npwp, Integer id,
			String email, Integer ruanganId, String namaRuangan, String kdDepartemen, String namaDepartemen,
			Integer departemenId) {
		super();
		this.id = idLoginUser;
		this.kelompokUser = kelompokUser;
		this.namaUser = namaUser;
		this.pegawai = new Pegawai(namaLengkap, namaPanggilan, nikIntern, nipPns, noIdentitas, npwp, id, email,
				ruanganId, namaRuangan, kdDepartemen, namaDepartemen, departemenId);
	}
	public LoginUser(Integer idLoginUser,String namaUser){
		super();
		this.id=idLoginUser;
		this.namaUser= namaUser;
	}
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "public.LoginUser_S_id_seq")
	@javax.persistence.SequenceGenerator(name = "public.LoginUser_S_id_seq", sequenceName = "public.LoginUser_S_id_seq", allocationSize = 1)
	@Column(name = "id")
	protected Integer id;

	@NotNull(message = "Kata Sandi tidak boleh kosong")
	@Column(name = "KataSandi", nullable = false, length = 50)
	@Caption(value = "Kata Sandi")
	private String kataSandi;

	@ManyToOne
	@JoinColumn(name = "ObjectKelompokUserFk")
	@NotNull(message = "Kd Kelompok User tidak boleh kosong")
	@Caption(value = "Object Kelompok User")
	private KelompokUser kelompokUser;

	@Column(name = "ObjectKelompokUserFk", insertable = false, updatable = false)
	private Integer kelompokUserId;

	@ManyToOne
	@JoinColumn(name = "ObjectPegawaiFk")
	@NotNull(message = "Kd Pegawai tidak boleh kosong")
	@Caption(value = "Object Pegawai")
	private Pegawai pegawai;

	@Column(name = "ObjectPegawaiFk", insertable = false, updatable = false, nullable = false)
	private Integer pegawaiId;

	@NotNull(message = "Nama User tidak boleh kosong")
	@Column(name = "NamaUser", nullable = false, length = 40, unique = true)
	@Caption(value = "Nama User")
	private String namaUser;

	@NotNull(message = "Status Login tidak boleh kosong")
	@Column(name = "StatusLogin", nullable = false)
	@Caption(value = "Status Login")
	private Byte statusLogin;
	
	@JsonBackReference
	@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.LAZY, mappedBy = "loginUser")
	private Set<MapLoginUserToRuangan> mapLoginUserToRuanganSet = new HashSet<>();
	
	public Integer getId() {
		return id;
	}

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

	public String getKataSandi() {
		return kataSandi;
	}

	public void setKataSandi(String kataSandi) {
		this.kataSandi = kataSandi;
	}

	public KelompokUser getKelompokUser() {
		return kelompokUser;
	}

	public void setKelompokUser(KelompokUser kelompokUser) {
		this.kelompokUser = kelompokUser;
	}

	public Integer getKelompokUserId() {
		return kelompokUserId;
	}

	public void setKelompokUserId(Integer kelompokUserId) {
		this.kelompokUserId = kelompokUserId;
	}

	public Pegawai getPegawai() {
		return pegawai;
	}

	public void setPegawai(Pegawai pegawai) {
		this.pegawai = pegawai;
	}

	public Integer getPegawaiId() {
		return pegawaiId;
	}

	public void setPegawaiId(Integer pegawaiId) {
		this.pegawaiId = pegawaiId;
	}

	public String getNamaUser() {
		return namaUser;
	}

	public void setNamaUser(String namaUser) {
		this.namaUser = namaUser;
	}

	public Byte getStatusLogin() {
		return statusLogin;
	}

	public void setStatusLogin(Byte statusLogin) {
		this.statusLogin = statusLogin;
	}

	public Set<MapLoginUserToRuangan> getMapLoginUserToRuanganSet() {
		return mapLoginUserToRuanganSet;
	}

	public void setMapLoginUserToRuanganSet(Set<MapLoginUserToRuangan> mapLoginUserToRuanganSet) {
		this.mapLoginUserToRuanganSet = mapLoginUserToRuanganSet;
	}

}
