package com.its.op.entity.its.oper;

import com.its.op.dto.its.oper.TbUserInfrDto;
import com.its.op.security.UserInfrVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * 사용자정보 Entity Class
 */
@Getter
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@Builder
@AllArgsConstructor
@ApiModel("사용자정보")
@Entity
@Table(name = "TB_USER_INFR")
public class TbUserInfr implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("사용자ID(사원번호)")  // N VARCHAR2(20)
    @Id
    @Column(name = "USER_ID", nullable = false, length = 20)
    private String userId;

    @ApiModelProperty("비밀번호")  // Y VARCHAR2(64)
    @Column(name = "PWD", length = 64)
    private String pwd;

    @ApiModelProperty("이름")  // Y VARCHAR2(30)
    @Column(name = "NAME", length = 30)
    private String name;

    @ApiModelProperty("주민번호")  // Y VARCHAR2(14)
    @Column(name = "RESD_NMBR", length = 14)
    private String resdNmbr;

    @ApiModelProperty("회사명")  // Y VARCHAR2(100)
    @Column(name = "COMP", length = 100)
    private String comp;

    @ApiModelProperty("부서명")  // Y VARCHAR2(30)
    @Column(name = "DEPT_NAME", length = 30)
    private String deptName;

    @ApiModelProperty("직위(직급)명")  // Y VARCHAR2(30)
    @Column(name = "POS_NAME", length = 30)
    private String posName;

    @ApiModelProperty("이메일주소")  // Y VARCHAR2(128)
    @Column(name = "EMAIL", length = 128)
    private String email;

    @ApiModelProperty("전화번호")  // Y VARCHAR2(30)
    @Column(name = "TEL", length = 30)
    private String tel;

    @ApiModelProperty("이동전화번호")  // Y VARCHAR2(30)
    @Column(name = "MOBILE", length = 30)
    private String mobile;

    @ApiModelProperty("입사일자")  // Y VARCHAR2(8)
    @Column(name = "ENT_DT", length = 8)
    private String entDt;

    @ApiModelProperty("기타")  // Y VARCHAR2(512)
    @Column(name = "EMP_ETC", length = 512)
    private String empEtc;

    @ApiModelProperty("운영시스템ID")  // Y VARCHAR2(7)
    @Column(name = "OPER_SYST_ID", length = 7)
    private String operSystId;

    @ApiModelProperty("시스템권한 그룹ID")  // Y VARCHAR2(7)
    @Column(name = "GROP_ID", length = 7)
    private String gropId;

    @ApiModelProperty("비밀번호힌트질문('HNT')")  // Y VARCHAR2(7)
    @Column(name = "HINT_QUES", length = 7)
    private String hintQues;

    @ApiModelProperty("비밀번호힌트질문답")  // Y VARCHAR2(100)
    @Column(name = "HINT_ANS", length = 100)
    private String hintAns;

    @ApiModelProperty("삭제 여부")  // Y CHAR(1)
    @Column(name = "DEL_YN", columnDefinition = "CHAR", length = 1)
    private String delYn;

    public TbUserInfrDto toDto() {
        return TbUserInfrDto.builder()
                .userId(this.userId)
                .pwd(this.pwd)
                .name(this.name)
                .resdNmbr(this.resdNmbr)
                .comp(this.comp)
                .deptName(this.deptName)
                .posName(this.posName)
                .email(this.email)
                .tel(this.tel)
                .mobile(this.mobile)
                .entDt(this.entDt)
                .empEtc(this.empEtc)
                .operSystId(this.operSystId)
                .gropId(this.gropId)
                .hintQues(this.hintQues)
                .hintAns(this.hintAns)
                .delYn(this.delYn)
                .build();
    }

    public UserInfrVo toVo() {
        return UserInfrVo.builder()
                .userId(this.userId)
                .pwd(this.pwd)
                .name(this.name)
                .comp(this.comp)
                .tel(this.tel)
                .mobile(this.mobile)
                .email(this.email)
                .delYn(this.delYn)
                .hintQues(this.hintQues)
                .hintAns(this.hintAns)
                .gropId(this.gropId)
                .operSystId(this.operSystId)
                .build();
    }

    public TbUserInfr(String userId) {
        this.userId = userId;
    }

    public void updateInfo(TbUserInfrDto.TbUserInfrUpdReq req) {
        this.pwd = req.getPwd();
        this.name = req.getName();
        this.resdNmbr = req.getResdNmbr();
        this.comp = req.getComp();
        this.deptName = req.getDeptName();
        this.posName = req.getPosName();
        this.email = req.getEmail();
        this.tel = req.getTel();
        this.mobile = req.getMobile();
        this.entDt = req.getEntDt();
        this.empEtc = req.getEmpEtc();
        this.operSystId = req.getOperSystId();
        this.gropId = req.getGropId();
        this.hintQues = req.getHintQues();
        this.hintAns = req.getHintAns();
        this.delYn = req.getDelYn();
    }

    public void setDelete() {
        this.delYn = "Y";
    }

    public void updatePswd(TbUserInfrDto.TbUserPswdUpdReq req) {
        this.pwd = req.getPwd();
    }

}
