package com.its.api.its.model.entity.link;

import com.its.api.its.model.dto.link.LinkParaClctSystDto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.domain.Persistable;

import javax.persistence.*;

@DynamicInsert
@DynamicUpdate
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "TB_LINK_PARA_CLCT_SYST")
@IdClass(TbLinkParaClctSystKey.class)
public class TbLinkParaClctSyst implements Persistable {

    @Id
    @Column(nullable = false, length = 7)
    private Long    LINK_ID;        //	N	NUMBER(10)	N			링크ID
    @Id
    @Column(nullable = false, length = 7)
    private String  CLCT_SYST_CD;   //	N	VARCHAR2(7)	N			수집 시스템 코드
    @Column(length = 2)
    private Integer FUSN_PRRT;      //	N	NUMBER(2)	Y	0		퓨전 우선순위
    @Column(columnDefinition = "NUMBER", length = 5, precision = 2)
    private Double  FUSN_WGHT;      //	N	NUMBER(5,2)	Y	0		퓨전 가중치

    @Transient
    private boolean isNew = true;

    @PrePersist
    @PostLoad
    public void markNew() {
        this.isNew = false;
    }

    @Override
    public Object getId() {
        return this.LINK_ID + "*" + this.CLCT_SYST_CD;
    }

    public TbLinkParaClctSyst(Long LINK_ID) {
        this.LINK_ID = LINK_ID;
    }

    public void updateInfo(LinkParaClctSystDto.LinkParaClctSystUpdateReq req) {
        this.CLCT_SYST_CD = req.getCLCT_SYST_CD();
        this.FUSN_PRRT = req.getFUSN_PRRT();
        this.FUSN_WGHT = req.getFUSN_WGHT();

    }

}
