package com.eactive.eai.rms.data.entity.onl.code;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;

import com.eactive.eai.data.converter.LocalDateTimeToStringConverter14;
import com.eactive.eai.data.entity.AbstractEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)

@Entity
@Table(name = "tseaicm20")
@org.hibernate.annotations.Table(appliesTo = "tseaicm20", comment = "코드 정보")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Code extends AbstractEntity<CodeId> implements Serializable {
	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private CodeId id;

	@Column(length = 200)
	@Comment("코드 한글명")
	private String codename;

	@Column(name = "codename_en", length = 200)
	@Comment("코드 영문명")
	private String codenameEn;

	@Column(length = 8)
	@Comment("생성자")
	@CreatedBy
	private String createby;

	@Column(length = 14)
	@Comment("생성 일시")
	@CreatedDate
	@Convert(converter = LocalDateTimeToStringConverter14.class)
	private LocalDateTime createon;

	@Column(length = 50)
	@Comment("extra 1")
	private String ext1;

	@Column(length = 50)
	@Comment("extra 2")
	private String ext2;

	@Column(length = 50)
	@Comment("extra 3")
	private String ext3;

	@Column(length = 50)
	@Comment("extra 4")
	private String ext4;

	@Column(length = 50)
	@Comment("extra 5")
	private String ext5;

	@Column(length = 50)
	@Comment("상위 코드")
	private String parentcode;

	@Column(length = 50)
	@Comment("상위 코드 그룹")
	private String parentcodegroup;

	@Column(precision = 10)
	@Comment("정렬순서")
	private BigDecimal seq;

	@Column(length = 8)
	@Comment("수정자")
	@LastModifiedBy
	private String updateby;

	@Column(length = 14)
	@Comment("수정 일시")
	@Convert(converter = LocalDateTimeToStringConverter14.class)
	@LastModifiedDate
	private LocalDateTime updateon;

	@Column(length = 1)
	@Comment("사용여부")
	private String useyn;

	public String getCodeName(String language) {
		if (StringUtils.equalsIgnoreCase(language, "EN")) {
			return this.getCodenameEn();
		} else {
			return this.getCodename();
		}
	}

	@ManyToOne
	@JoinColumn(name = "codegroup", insertable = false, updatable = false)
	@ToString.Exclude
	private CodeGroup codegroups;

}