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 java.util.Date;
import java.util.HashSet;
import java.util.Set;

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

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

	@OneToOne(fetch = LAZY)
	@Caption(value = "Ipsrs Perbaikan")
	@JoinColumn(name = "ObjectIpsrsPerbaikanFk")
	private IpsrsPerbaikan ipsrsPerbaikan;

	@Column(name = "ObjectIpsrsPerbaikanFk", columnDefinition = "CHAR(32)", nullable = false, insertable = false, updatable = false)
	private String ipsrsPerbaikanId;

	@Temporal(TIMESTAMP)
	@Caption(value = "Tgl Mulai Periksa")
	@Column(name = "TglMulaiPeriksa")
	private Date tglMulaiPeriksa;

	@Caption(value = "Analisa Teknisi")
	@Column(name = "AnalisaTeknisi")
	private String analisaTeknisi;

	@Caption(value = "Analisa Kerusakan")
	@Column(name = "AnalisaKerusakan")
	private String analisaKerusakan;

	@JsonBackReference
	@OneToMany(cascade = ALL, fetch = LAZY, mappedBy = "ipsrsPelaksanaanPerbaikan")
	private Set<IpsrsPelaksanaanPerbaikanSukuCadang> ipsrsPelaksanaanPerbaikanSukuCadang = new HashSet<>();

	@JsonBackReference
	@OneToMany(cascade = ALL, fetch = LAZY, mappedBy = "ipsrsPelaksanaanPerbaikan")
	private Set<IpsrsPelaksanaanPerbaikanListTeknisi> ipsrsPelaksanaanPerbaikanListTeknisi = new HashSet<>();

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "ObjectUserFk")
	@Caption(value = "User")
	private Pegawai user;

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

}
