package com.dbs.mplus.service.mobile.user.repository.dao;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.dbs.mplus.framework.util.ConvertUtil;
import com.dbs.mplus.framework.util.DateDeserializer;
import com.dbs.mplus.framework.util.DateSerializer;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
 * 사용자 
 * @author hyeeun 
 *
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class MPlusUser {
	// 시퀀스 
	private Long userSeq; 
	// 사용자번호 
	private String userId; 
	// 사용자 이름
	private String userName;
	// 부서 코드 (진료과 코드)
	private String deptCode;
	// 부서명 (진료과 이름)
	private String deptName;
	
	// 로컬 암호화 키 
	private String localCipherKeyValue; 
	// 로그인 실패 횟수 
	private Integer loginFailCnt; 
	// 암호 업뎃 날짜 
	private Date passWordUpdateDt; 
	// 로그인 암호 
	private String passWordValue; 
	// 사용 등록일 
	@JsonSerialize(using = DateSerializer.class)
	@JsonDeserialize(using = DateDeserializer.class)		
	private Date registerDt; 
	// 동의서 목록 
	private List<MPlusUserAgreement> agreementList;
	// 사용자가 다음에 이동할 페이지 
	// DB에 저장되는 값은 아니고, 로그인 처리용임 
	private String nextPage; 
	// 사용자가 선택한 속성
	private Long useAttrOrder;
	// 사용자가 선택한 진입화면
	private String indexPage;
	// 사용자의 Job 종류 코드
	private String jobKindCd;
	
	// 생성자
	public MPlusUser() {}
	
	public MPlusUser(String userId, String userName, String deptCode, String deptName, String jobKindCd, String indexPage) {
		this.userId = userId;
		this.userName = userName;
		this.deptCode = deptCode;
		this.deptName = deptName;
		this.jobKindCd = jobKindCd;
		this.indexPage = indexPage;
	}
	
	public String getIndexPage() {
		return indexPage;
	}

	public void setIndexPage(String indexPage) {
		this.indexPage = indexPage;
	}

	public String getJobKindCd() {
		return jobKindCd;
	}

	public void setJobKindCd(String jobKindCd) {
		this.jobKindCd = jobKindCd;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getDeptCode() {
		return deptCode;
	}

	public void setDeptCode(String deptCode) {
		this.deptCode = deptCode;
	}

	public String getDeptName() {
		return deptName;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}

	public Long getUserSeq() {
		return this.userSeq;
	}

	public void setUserSeq(Long userSeq) {
		this.userSeq = userSeq;
	}

	public String getUserId() {
		return this.userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}


	public String getLocalCipherKeyValue() {
		return this.localCipherKeyValue;
	}

	public void setLocalCipherKeyValue(String localCipherKeyValue) {
		this.localCipherKeyValue = localCipherKeyValue;
	}

	public Integer getLoginFailCnt() {
		return this.loginFailCnt;
	}

	public void setLoginFailCnt(Integer loginFailCnt) {
		this.loginFailCnt = loginFailCnt;
	}

	public Date getPassWordUpdateDt() {
		return this.passWordUpdateDt;
	}

	public void setPassWordUpdateDt(Date passWordUpdateDt) {
		this.passWordUpdateDt = passWordUpdateDt;
	}

	public String getPassWordValue() {
		return this.passWordValue;
	}

	public void setPassWordValue(String passWordValue) {
		this.passWordValue = passWordValue;
	}

	public Date getRegisterDt() {
		return this.registerDt;
	}

	public void setRegisterDt(Date registerDt) {
		this.registerDt = registerDt;
	}

	public List<MPlusUserAgreement> getAgreementList() {
		return this.agreementList;
	}

	public void setAgreementList(List<MPlusUserAgreement> agreementList) {
		this.agreementList = agreementList;
	}

	public String getNextPage() {
		return this.nextPage;
	}

	public void setNextPage(String nextPage) {
		this.nextPage = nextPage;
	}

	public Long getUseAttrOrder() {
		return useAttrOrder;
	}

	public void setUseAttrOrder(Long useAttrOrder) {
		this.useAttrOrder = useAttrOrder;
	}

	/**
	 * 변환 
	 * @param map
	 * @return
	 */
	public static MPlusUser convert(Map<String, Object> userMap) { 
		final MPlusUser user = new MPlusUser(); 
		final BigDecimal b = (BigDecimal) userMap.get("loginFailCnt"); 
		final BigDecimal attrOrder = (BigDecimal) userMap.get("useAttrOrder"); 
		
		user.setUserId((String) userMap.get("userId"));
//		user.setpName((String) userMap.get("pName"));
		user.setLoginFailCnt(ConvertUtil.convertInteger(b));
		user.setPassWordValue((String) userMap.get("passwordValue"));
		user.setPassWordUpdateDt((Date) userMap.get("passwordUpdateDt"));
		user.setLocalCipherKeyValue((String) userMap.get("localCipherKeyValue"));
		user.setUseAttrOrder(ConvertUtil.convertLong(attrOrder));
		return user; 
	}
	
	@Override
	public String toString() {
		return "MPUser [userSeq=" + this.userSeq + ", userId=" + this.userId 
				+ ", localCipherKeyValue=" + this.localCipherKeyValue + ", loginFailCnt=" + this.loginFailCnt
				+ ", passWordUpdateDt=" + this.passWordUpdateDt + ", passWordValue=" + this.passWordValue + ", registerDt="
				+ this.registerDt + ", agreementList=" + this.agreementList + ", nextPage=" + this.nextPage + "]";
	}
}
