package com.jasamedika.medifirst2000.entities;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
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.Date;

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

@Getter
@Setter
@Entity
@Table(name = "ItPerbaikan_T")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class ItPerbaikan extends BaseTransaction {

	@Caption(value = "No Order")
	@Column(name = "NoOrder")
	private String noOrder;

	@Temporal(TIMESTAMP)
	@Caption(value = "Tanggal Pesan")
	@NotNull(message = "Tanggal Pesan tidak boleh kosong")
	@Column(name = "TanggalPesan", nullable = false)
	private Date tglPesan;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectRegistrasiAsetFk")
	@Caption(value = "Registrasi Aset")
	private RegistrasiAset registrasiAset;

	@Column(name = "ObjectRegistrasiAsetFk", columnDefinition = "CHAR(32)", insertable = false, updatable = false)
	private String registrasiAsetId;

	@Caption(value = "Keluhan")
	@NotNull(message = "Keluhan tidak boleh kosong")
	@Column(name = "Keluhan", nullable = false)
	private String keluhan;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectPelaporFk")
	@Caption(value = "Pelapor")
	private Pegawai pelapor;

	@Column(name = "ObjectPelaporFk", nullable = false, insertable = false, updatable = false)
	private Integer pelaporId;

	@JsonBackReference
	@OneToOne(cascade = ALL, fetch = LAZY, mappedBy = "itPerbaikan")
	private ItStatusPerbaikan itStatusPerbaikan;

	@JsonBackReference
	@OneToOne(cascade = ALL, fetch = LAZY, mappedBy = "itPerbaikan")
	private ItPelaksanaanPerbaikan itPelaksanaanPerbaikan;

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectStrukOrderFk")
	private StrukOrder strukOrder;

	@Column(name = "ObjectStrukOrderFk", insertable = false, updatable = false, nullable = false)
	private String strukOrderId;

}
