package com.style24.front.support.startup;

import java.util.ArrayList;
import java.util.Collection;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.style24.core.biz.service.TscEnvsetService;
import com.style24.core.support.env.TscConstants;
import com.style24.front.biz.service.TsfDisplayService;
import com.style24.front.support.env.TsfConstants;
import com.style24.persistence.domain.Cate1;
import com.style24.persistence.domain.Meta;

import lombok.extern.slf4j.Slf4j;

/**
 * 각종 환경설정 정보 조회. 초기 로딩 시 가져옴
 * 		1. 메타정보
 * 		2. 카테고리정보
 * @author gagamel
 * @since 2021. 3. 19
 */
@Component
@Slf4j
public class TsfEnvsetInfo {

	private static Meta meta = new Meta();
	private static Collection<Cate1> allCateList = new ArrayList<>();

	@Autowired
	private TscEnvsetService envsetService;

	@Autowired
	private TsfDisplayService displayService;

	@PostConstruct
	public void init() {
		meta = envsetService.getMetaInfo(TscConstants.Site.STYLE24.value());
		log.info("\n\n---- Meta Info. ------------------------------------------");
		log.info("meta: [{}]", meta);
		log.info("\n------------------------------------------------------------\n");

		allCateList = displayService.getAllCategoryList(TsfConstants.CateGb.BYITEM.value());
		log.info("\n\n---- All Category List -----------------------------------");
		log.info("allCateList: [{}]", allCateList);
		log.info("\n------------------------------------------------------------\n");
	}

	/**
	 * 쇼핑몰 메타정보
	 * @return
	 */
	public Meta getMetaInfo() {
		if (meta == null) {
			meta = envsetService.getMetaInfo(TscConstants.Site.STYLE24.value());
		}

		return meta;
	}

	/**
	 * 전체 카테고리 목록
	 * @return
	 */
	public Collection<Cate1> getAllCateList() {
//		if (allCateList == null) {
//		allCateList = displayService.getAllCategoryList(TsfConstants.CateGb.BYITEM.value());
//		}
//
//		return allCateList;
		return displayService.getAllCategoryList(TsfConstants.CateGb.BYITEM.value());
	}

}
