package com.its.op.dto.its.oper;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.its.op.entity.its.oper.TbWwwMember;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

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

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

    @ApiModelProperty("이메일주소")  // N VARCHAR2(50)
    @JsonProperty("email")
    private String email;

    @ApiModelProperty("이름")  // Y VARCHAR2(15)
    @JsonProperty("name")
    private String name;

    @ApiModelProperty("비밀번호")  // Y VARCHAR2(100)
    @JsonProperty("pwd")
    private String pwd;

    @ApiModelProperty("연락처")  // Y VARCHAR2(30)
    @JsonProperty("contact_num")
    private String contactNum;

    @ApiModelProperty("권한등급")  // Y VARCHAR2(3)
    @JsonProperty("user_auth")
    private String userAuth;

    @ApiModelProperty("비밀번호힌트질문('HNT')")  // Y VARCHAR2(7)
    @JsonProperty("hint_ques")
    private String hintQues;

    @ApiModelProperty("비밀번호힌트질문답")  // Y VARCHAR2(100)
    @JsonProperty("hint_ans")
    private String hintAns;

    @ApiModelProperty("로그인 실패 횟수")  // Y NUMBER(2)
    @JsonProperty("login_fail_count")
    private Integer loginFailCount;

    @ApiModelProperty("계정잠금여부(Y:계정잠김)")  // Y CHAR(1)
    @JsonProperty("is_account_lock")
    private String isAccountLock;

    @ApiModelProperty("관리자계정접속가능아이피(*:모두가능)")  // Y VARCHAR2(200)
    @JsonProperty("ip_address")
    private String ipAddress;

    @ApiModelProperty("등록시각")  // Y VARCHAR2(14)
    @JsonProperty("reg_dt")
    private String regDt;

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

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

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

        @ApiModelProperty("이메일주소, Nullable = N, VARCHAR2(50)")  // N VARCHAR2(50)
        @JsonProperty("email")
        @Size(min=1, max=50)
        private String email;

        @ApiModelProperty("이름, Nullable = Y, VARCHAR2(15)")  // Y VARCHAR2(15)
        @JsonProperty("name")
        @Size(min=1, max=15)
        private String name;

        @ApiModelProperty("비밀번호, Nullable = Y, VARCHAR2(100)")  // Y VARCHAR2(100)
        @JsonProperty("pwd")
        @Size(min=1, max=100)
        private String pwd;

        @ApiModelProperty("연락처, Nullable = Y, VARCHAR2(30)")  // Y VARCHAR2(30)
        @JsonProperty("contact_num")
        @Size(min=1, max=30)
        private String contactNum;

        @ApiModelProperty("권한등급, Nullable = Y, VARCHAR2(3)")  // Y VARCHAR2(3)
        @JsonProperty("user_auth")
        @Size(max=3)
        private String userAuth;

        @ApiModelProperty("비밀번호힌트질문('HNT'), Nullable = Y, VARCHAR2(7)")  // Y VARCHAR2(7)
        @JsonProperty("hint_ques")
        @Size(max=7)
        private String hintQues;

        @ApiModelProperty("비밀번호힌트질문답, Nullable = Y, VARCHAR2(100)")  // Y VARCHAR2(100)
        @JsonProperty("hint_ans")
        @Size(max=100)
        private String hintAns;

        @ApiModelProperty("로그인 실패 횟수, Nullable = Y, NUMBER(2)")  // Y NUMBER(2)
        @JsonProperty("login_fail_count")
        @PositiveOrZero
        private Integer loginFailCount;

        @ApiModelProperty("계정잠금여부(Y:계정잠김), Nullable = Y, CHAR(1)")  // Y CHAR(1)
        @JsonProperty("is_account_lock")
        @Size(min=1, max=1)
        @Pattern(regexp = "[YN]")
        private String isAccountLock;

        @ApiModelProperty("관리자계정접속가능아이피(*:모두가능), Nullable = Y, VARCHAR2(200)")  // Y VARCHAR2(200)
        @JsonProperty("ip_address")
        @Size(max=200)
        private String ipAddress;

        @ApiModelProperty("등록시각, Nullable = Y, VARCHAR2(14)")  // Y VARCHAR2(14)
        @JsonProperty("reg_dt")
        @Size(max=14)
        private String regDt;

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

        @Builder
        public TbWwwMemberUpdReq(String email, String name, String pwd, String contact_num, String user_auth, String hint_ques, String hint_ans, Integer login_fail_count, String is_account_lock, String ip_address, String reg_dt, String del_yn) {
            this.email = email;
            this.name = name;
            this.pwd = pwd;
            this.contactNum = contact_num;
            this.userAuth = user_auth;
            this.hintQues = hint_ques;
            this.hintAns = hint_ans;
            this.loginFailCount = login_fail_count;
            this.isAccountLock = is_account_lock;
            this.ipAddress = ip_address;
            this.regDt = reg_dt;
            this.delYn = del_yn;
        }
        @ApiModel("TbWwwMemberLockFreeReq(홈페이지관리자정보 락 해제)")
        @Getter
        @Setter
        @ToString
        @NoArgsConstructor//(access = AccessLevel.PROTECTED)
        public static class TbWwwMemberLockFreeReq {

            @ApiModelProperty("아이디, Nullable = N, VARCHAR(50)")  // N VARCHAR(50)
            @JsonProperty("email")
            @Size(min = 1, max = 50)
            private String email;

            @Builder
            public TbWwwMemberLockFreeReq(String email) {
                this.email = email;
            }
        }

        public TbWwwMember toEntity() {
            return TbWwwMember.builder()
                    .email(this.email)
                    .name(this.name)
                    .pwd(this.pwd)
                    .contactNum(this.contactNum)
                    .userAuth(this.userAuth)
                    .hintQues(this.hintQues)
                    .hintAns(this.hintAns)
                    .loginFailCount(this.loginFailCount)
                    .isAccountLock(this.isAccountLock)
                    .ipAddress(this.ipAddress)
                    .regDt(this.regDt)
                    .delYn(this.delYn)
                    .build();
        }

    }

}
