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

import com.its.api.its.model.dto.oper.TbUserInfrDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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 VARCHAR(20)
    @Id
    @Column(name = "USER_ID", nullable = false, length = 20)
    private String userId;

    @ApiModelProperty("암호")  // Y VARCHAR(64)
    @Column(name = "PWD", length = 64)
    private String pwd;

    @ApiModelProperty("성명")  // Y VARCHAR(30)
    @Column(name = "NAME", length = 30)
    private String name;

    @ApiModelProperty("회사")  // Y VARCHAR(50)
    @Column(name = "COMP", length = 50)
    private String comp;

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

    @ApiModelProperty("주소")  // Y VARCHAR(200)
    @Column(name = "ADDR", length = 200)
    private String addr;

    @ApiModelProperty("이동전화")  // Y VARCHAR(128)
    @Column(name = "MOBILE", length = 128)
    private String mobile;

    @ApiModelProperty("이메일")  // Y VARCHAR(128)
    @Column(name = "EMAL", length = 128)
    private String emal;

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

    @ApiModelProperty("등록일자")  // Y VARCHAR(14)
    @Column(name = "RGSTYMD", length = 14)
    private String rgstymd;

    @ApiModelProperty("수정일자")  // Y VARCHAR(14)
    @Column(name = "CRCTYMD", length = 14)
    private String crctymd;

    @ApiModelProperty("힌트질문")  // Y VARCHAR(7)
    @Column(name = "HINT_QUES", length = 7)
    private String hintQues;

    @ApiModelProperty("힌트질문답")  // Y VARCHAR(100)
    @Column(name = "HINT_ANS", length = 100)
    private String hintAns;

    @ApiModelProperty("그룹ID")  // Y VARCHAR(30)
    @Column(name = "GROP_ID", length = 30)
    private String gropId;

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

    public TbUserInfrDto toDto() {
        return TbUserInfrDto.builder()
                .userId(this.userId)
                .pwd(this.pwd)
                .name(this.name)
                .comp(this.comp)
                .tel(this.tel)
                .addr(this.addr)
                .mobile(this.mobile)
                .emal(this.emal)
                .delYn(this.delYn)
                .rgstymd(this.rgstymd)
                .crctymd(this.crctymd)
                .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.comp = req.getComp();
        this.tel = req.getTel();
        this.addr = req.getAddr();
        this.mobile = req.getMobile();
        this.emal = req.getEmal();
        this.delYn = req.getDelYn();
        this.rgstymd = req.getRgstymd();
        this.crctymd = req.getCrctymd();
        this.hintQues = req.getHintQues();
        this.hintAns = req.getHintAns();
        this.gropId = req.getGropId();
        this.operSystId = req.getOperSystId();
    }

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