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

import com.icomsys.main_vm.biz.common.login.res.UserVo;
import com.icomsys.main_vm.biz.common.system.vo.SystemCustSaveReq;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.time.LocalDateTime;

@Table(name = "TB_ICS_CUST_INFO")
@Entity
@Getter
@Setter
@NoArgsConstructor
@DynamicUpdate
public class TbIcsCustInfo {

    @Id
    @Column(name = "CUST_CODE", nullable = false, length = 20)
    private String custCode;
    @Column(name = "CUST_NAME", nullable = false, length = 50)
    private String custName;
    @Column(name = "CUST_TEL", nullable = true, length = 20)
    private String custTel;
    @Column(name = "CUST_SERVICE_MENT", nullable = true, length = 500)
    private String custServiceMent;
    @Column(name = "USE_YN", nullable = false, 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 TbIcsCustInfo(String custCode, String custName, String custTel, String custServiceMent, String useYn, String registId, LocalDateTime registDate, String updateId, LocalDateTime updateDate) {
        this.custCode = custCode;
        this.custName = custName;
        this.custTel = custTel;
        this.custServiceMent = custServiceMent;
        this.useYn = useYn;
        this.registId = registId;
        this.registDate = registDate;
        this.updateId = updateId;
        this.updateDate = updateDate;
    }

    public TbIcsCustInfo UpdateCust(SystemCustSaveReq dto, UserVo uv) {
        if (dto.getCustName() != null && !dto.getCustName().equals("") && dto.getCustName() != this.custName) {
            this.custName = dto.getCustName();
        }
        if (dto.getCustUseYn() != null && !dto.getCustUseYn().equals("") && dto.getCustUseYn() != this.useYn) {
            this.useYn = dto.getCustUseYn();
        }
//        this.custTel = custTel;
//        this.custServiceMent = custServiceMent;
        this.updateId = uv.getUserId();
        this.updateDate = LocalDateTime.now();
        return this;
    }

}
