package com.style24.admin.support.security;

import java.util.Collection;

import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.style24.persistence.domain.Menu;
import com.style24.persistence.domain.User;

/**
 * 로그인 상세 정보
 * 
 * @author gagamel
 * @since 2020. 10. 5
 */
@SuppressWarnings("serial")
@JsonSerialize
@JsonIgnoreProperties(ignoreUnknown = true)
public class TsaLoginDetails implements UserDetails {

	private User loginInfo = null;

	private Collection<SimpleGrantedAuthority> authorities = null;

	// 메뉴 목록 (로그인 시 설정)
	private Collection<Menu> menuList;

	public TsaLoginDetails() {

	}

	public TsaLoginDetails(User loginInfo, Collection<SimpleGrantedAuthority> authorities) {
		this.loginInfo = loginInfo;
		this.authorities = authorities;

//		if (authorities != null && !authorities.isEmpty()) {
//			isLogin = true;
//		}
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}

	@Override
	public String getPassword() {
		return loginInfo.getPasswd();
	}

	@Override
	public String getUsername() {
		return loginInfo.getUserId();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	public boolean isLogin() {
		return (StringUtils.isNotBlank(loginInfo.getUserId())) ? true : false;
	}

	public User getLoginInfo() {
		return loginInfo;
	}

	public void setLoginMenuList(Collection<Menu> menuList) {
		this.menuList = menuList;
	}

	public Collection<Menu> getLoginMenuList() {
		return menuList;
	}

}
