package com.icomsys.main_vm.db.jpa.entity.conversation;

import com.icomsys.main_vm.db.mybatis.alias.LoginVO;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;

@Table(name = "TB_SYNONYM_MASTER")
@Entity
@Getter
@Setter
@NoArgsConstructor
public class TbSynonymMaster {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "SEQ", nullable = false, length = 20)
    private Long seq;
    @Column(name = "OPR_MNG_CODE", nullable = true, length = 50)
    private String oprMngCode;
    @Column(name = "IDIV_WORD", nullable = true, length = 50)
    private String idivWord;
    @Column(name = "REP_WORD", nullable = true, length = 20)
    private String repWord;
    @Column(name = "IF_MAPPING_ID", nullable = true, length = 20)
    private Long ifMappingId;
    @Column(name = "USE_YN", nullable = true, length = 1)
    private String useYn;
    @Column(name = "REGIST_ID", nullable = false, length = 20)
    private String registId;
    @Column(name = "REGIST_DATE", nullable = false)
    private LocalDateTime registDate;
    @Column(name = "UPDATE_ID", nullable = true, length = 20)
    private String updateId;
    @Column(name = "UPDATE_DATE", nullable = true)
    private LocalDateTime updateDate;

    @Builder
    public TbSynonymMaster(Long seq, String oprMngCode, String idivWord, String repWord, Long ifMappingId, String useYn, String registId, LocalDateTime registDate, String updateId, LocalDateTime updateDate) {
        this.seq = seq;
        this.oprMngCode = oprMngCode;
        this.idivWord = idivWord;
        this.repWord = repWord;
        this.ifMappingId = ifMappingId;
        this.useYn = useYn;
        this.registId = registId;
        this.registDate = registDate;
        this.updateId = updateId;
        this.updateDate = updateDate;
    }

    @OneToMany(cascade = CascadeType.ALL, targetEntity = TbSynonymWord.class, fetch = FetchType.EAGER)
    @JoinColumn(name = "MASTER_SEQ",referencedColumnName ="SEQ")
    private List<TbSynonymWord> tbSynonymWords;

    public TbSynonymMaster UpdateSynonymMaster(HashMap eMap) {
        this.idivWord = eMap.get("idivWord").toString();
        this.repWord = eMap.get("repWord").toString();
        this.useYn = "Y";
        this.updateId = eMap.get("userId").toString();
        this.updateDate = LocalDateTime.now();

        return this;
    };

}
