package com.style24.batch.biz.job.display;

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

import com.style24.batch.biz.job.TsbAbstractJob;
import com.style24.batch.biz.service.TsbDisplayService;

import lombok.extern.slf4j.Slf4j;

/**
 * 카테고리 검색필터(브랜드, 사이즈, 가격, 연령대, 시즌, 색상, 혜택) 생성
 * 		상품혜택 생성 배치(TsbGoodsBenefitJob)가 선 실행되어야 한다.
 *
 * @author gagamel
 * @since 2021. 4. 8
 */
@Component
@Slf4j
public class TsbCategoryFilterJob extends TsbAbstractJob<String, String, String> {

	@Autowired
	private TsbDisplayService displayService;

	@Override
	public String read() throws Exception {
		return "OK";
	}

	@Override
	public String process(String result) throws Exception {
		int cnt = displayService.createTemporaryCategoryFilter();
		log.info("1.임시 카테고리별 검색필터 생성: 총 {}건", cnt);

		if (cnt > 0) {
			cnt = displayService.createCategoryFilter();
			log.info("2.카테고리별 검색필터 생성: {}건", cnt);
		}

		return result;
	}

	@Override
	public String write(String result) throws Exception {
		return result;
	}

	@Override
	public void notify(String result) throws Exception {
		// Do nothing
	}

}