package com.style24.admin.support.security.session;

import java.util.Collection;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import com.style24.admin.support.security.TsaLoginDetails;
import com.style24.core.support.session.TscSession;
import com.style24.persistence.domain.Menu;
import com.style24.persistence.domain.Pos;
import com.style24.persistence.domain.User;

import lombok.extern.slf4j.Slf4j;

/**
 * Session
 * 
 * @author gagamel
 * @since 2020. 10. 5
 */
@Slf4j
public class TsaSession extends TscSession {

	/**
	 * Get Session Info.
	 * @return 세션 정보
	 */
	public static User getInfo() {
		TsaLoginDetails loginDetails = (TsaLoginDetails)RequestContextHolder.currentRequestAttributes().getAttribute("session", RequestAttributes.SCOPE_SESSION);

		if (loginDetails == null)
			return null;

		return loginDetails.getLoginInfo();
	}

	/**
	 * 로그인 여부
	 * @return true/false
	 */
	public static boolean isLogin() {
		TsaLoginDetails loginDetails = (TsaLoginDetails)RequestContextHolder.currentRequestAttributes().getAttribute("session", RequestAttributes.SCOPE_SESSION);

		if (loginDetails == null)
			return false;

		return loginDetails.isLogin();
	}

	/**
	 * Get the login menu list.
	 * @return 로그인 메뉴 목록
	 */
	public static Collection<Menu> getLoginMenuList() {
		TsaLoginDetails loginDetails = (TsaLoginDetails)RequestContextHolder.currentRequestAttributes().getAttribute("session", RequestAttributes.SCOPE_SESSION);

		if (loginDetails == null)
			return null;

		return loginDetails.getLoginMenuList();
	}

	/**
	 * 매장 세션 정보
	 * @return 매장 세션 정보
	 */
	public static Pos getPosInfo() {
		return (Pos)RequestContextHolder.currentRequestAttributes().getAttribute("sessionPosInfo", RequestAttributes.SCOPE_SESSION);
	}

	/**
	 * 매장로그인 여부
	 * @return true/false
	 */
	public static boolean isStoreLogin() {
		Pos posInfo = (Pos)RequestContextHolder.currentRequestAttributes().getAttribute("sessionPosInfo", RequestAttributes.SCOPE_SESSION);

		if (posInfo == null)
			return false;

		return true;
	}

}
