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

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.api.its.model.entity.oper.TbUserInfr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;

/**
 * 사용자정보 DTO Class
 */
@Data
@Builder
@ApiModel("TbUserInfrDto(사용자정보)")
public class TbUserInfrDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("사용자ID")  // N VARCHAR(20)
    @JsonProperty("user_id")
    private String userId;

    @ApiModelProperty("암호")  // Y VARCHAR(64)
    @JsonProperty("pwd")
    private String pwd;

    @ApiModelProperty("성명")  // Y VARCHAR(30)
    @JsonProperty("name")
    private String name;

    @ApiModelProperty("회사")  // Y VARCHAR(50)
    @JsonProperty("comp")
    private String comp;

    @ApiModelProperty("전화번호")  // Y VARCHAR(128)
    @JsonProperty("tel")
    private String tel;

    @ApiModelProperty("주소")  // Y VARCHAR(200)
    @JsonProperty("addr")
    private String addr;

    @ApiModelProperty("이동전화")  // Y VARCHAR(128)
    @JsonProperty("mobile")
    private String mobile;

    @ApiModelProperty("이메일")  // Y VARCHAR(128)
    @JsonProperty("emal")
    private String emal;

    @ApiModelProperty("삭제 여부")  // Y CHAR(1)
    @JsonProperty("del_yn")
    private String delYn;

    @ApiModelProperty("등록일자")  // Y VARCHAR(14)
    @JsonProperty("rgstymd")
    private String rgstymd;

    @ApiModelProperty("수정일자")  // Y VARCHAR(14)
    @JsonProperty("crctymd")
    private String crctymd;

    @ApiModelProperty("힌트질문")  // Y VARCHAR(7)
    @JsonProperty("hint_ques")
    private String hintQues;

    @ApiModelProperty("힌트질문답")  // Y VARCHAR(100)
    @JsonProperty("hint_ans")
    private String hintAns;

    @ApiModelProperty("그룹ID")  // Y VARCHAR(30)
    @JsonProperty("grop_id")
    private String gropId;

    @ApiModelProperty("운영시스템ID")  // Y VARCHAR(30)
    @JsonProperty("oper_syst_id")
    private String operSystId;

    // Code Description Field
    @ApiModelProperty("삭제 여부 설명")
    @JsonProperty("del_desc")    // DEL_YN
    private String delDesc;

    @ApiModel("TbUserInfrUpdReq(사용자정보 정보변경)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbUserInfrUpdReq {

        @ApiModelProperty("사용자ID, Nullable = N, VARCHAR(20)")  // N VARCHAR(20)
        @JsonProperty("user_id")
        @Size(min=1, max=20)
        private String userId;

        @ApiModelProperty("암호, Nullable = Y, VARCHAR(64)")  // Y VARCHAR(64)
        @JsonProperty("pwd")
        @Size(min=1, max=64)
        private String pwd;

        @ApiModelProperty("성명, Nullable = Y, VARCHAR(30)")  // Y VARCHAR(30)
        @JsonProperty("name")
        @Size(min=1, max=30)
        private String name;

        @ApiModelProperty("회사, Nullable = Y, VARCHAR(50)")  // Y VARCHAR(50)
        @JsonProperty("comp")
        @Size(min=1, max=50)
        private String comp;

        @ApiModelProperty("전화번호, Nullable = Y, VARCHAR(128)")  // Y VARCHAR(128)
        @JsonProperty("tel")
        @Size(min=1, max=128)
        private String tel;

        @ApiModelProperty("주소, Nullable = Y, VARCHAR(200)")  // Y VARCHAR(200)
        @JsonProperty("addr")
        @Size(min=1, max=200)
        private String addr;

        @ApiModelProperty("이동전화, Nullable = Y, VARCHAR(128)")  // Y VARCHAR(128)
        @JsonProperty("mobile")
        @Size(min=1, max=128)
        private String mobile;

        @ApiModelProperty("이메일, Nullable = Y, VARCHAR(128)")  // Y VARCHAR(128)
        @JsonProperty("emal")
        @Size(min=1, max=128)
        private String emal;

        @ApiModelProperty("삭제 여부, Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("del_yn")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String delYn;

        @ApiModelProperty("등록일자, Nullable = Y, VARCHAR(14)")  // Y VARCHAR(14)
        @JsonProperty("rgstymd")
        @Size(min=1, max=14)
        private String rgstymd;

        @ApiModelProperty("수정일자, Nullable = Y, VARCHAR(14)")  // Y VARCHAR(14)
        @JsonProperty("crctymd")
        @Size(min=1, max=14)
        private String crctymd;

        @ApiModelProperty("힌트질문, Nullable = Y, VARCHAR(7)")  // Y VARCHAR(7)
        @JsonProperty("hint_ques")
        @Size(min=1, max=7)
        private String hintQues;

        @ApiModelProperty("힌트질문답, Nullable = Y, VARCHAR(100)")  // Y VARCHAR(100)
        @JsonProperty("hint_ans")
        @Size(min=1, max=100)
        private String hintAns;

        @ApiModelProperty("그룹ID, Nullable = Y, VARCHAR(30)")  // Y VARCHAR(30)
        @JsonProperty("grop_id")
        @Size(min=1, max=30)
        private String gropId;

        @ApiModelProperty("운영시스템ID, Nullable = Y, VARCHAR(30)")  // Y VARCHAR(30)
        @JsonProperty("oper_syst_id")
        @Size(min=1, max=30)
        private String operSystId;

        @Builder
        public TbUserInfrUpdReq(String user_id, String pwd, String name, String comp, String tel, String addr, String mobile, String emal, String del_yn, String rgstymd, String crctymd, String hint_ques, String hint_ans, String grop_id, String oper_syst_id) {
            this.userId = user_id;
            this.pwd = pwd;
            this.name = name;
            this.comp = comp;
            this.tel = tel;
            this.addr = addr;
            this.mobile = mobile;
            this.emal = emal;
            this.delYn = del_yn;
            this.rgstymd = rgstymd;
            this.crctymd = crctymd;
            this.hintQues = hint_ques;
            this.hintAns = hint_ans;
            this.gropId = grop_id;
            this.operSystId = oper_syst_id;
        }

        public TbUserInfr toEntity() {
            return TbUserInfr.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();
        }

    }

    @Getter
    @Setter
    @ToString
    @NoArgsConstructor(access = AccessLevel.PROTECTED)
    public static class TbUserPswdUpdReq {

        @NotEmpty
        @Size(min=1, max=64)
        @JsonProperty("old_pwd")
        private String oldPwd;

        @NotEmpty
        @Size(min=1, max=64)
        @JsonProperty("pwd")
        private String pwd;

        @Builder
        public TbUserPswdUpdReq(String oldPwd, String pwd) {
            this.oldPwd = oldPwd;
            this.pwd = pwd;
        }
    }
}
