package com.style24.scm.biz.web;

import com.style24.scm.biz.service.TssDisplayService;
import com.style24.scm.biz.service.TssRendererService;
import com.style24.scm.support.controller.TssBaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.style24.persistence.domain.Category;

import java.util.Collection;


/**
 * 전시 Controller
 *
 * @author
 * @since 2021. 5. 21
 */
@Controller
@RequestMapping("/display")
@Slf4j
public class TssDisplayController extends TssBaseController {
	@Autowired
	private TssRendererService rendererService;

	@Autowired
	private TssDisplayService displayService;

	/**
	 * 카테고리 목록 화면(팝업)
	 * @param category
	 * @return
	 * @author xyzp1539
	 * @since 2021. 01. 11
	 */
	@GetMapping("/category/popup/form")
	public ModelAndView categorySearchForm(Category category) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("siteList", rendererService.getAvailCommonCodeList("G000"));
		mav.addObject("cateGbList", rendererService.getAvailCommonCodeList("G032"));
		mav.addObject("cateTypeList", rendererService.getAvailCommonCodeList("G031"));
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));
		mav.addObject("conentsLocList", rendererService.getAvailCommonCodeList("G028"));
		mav.addObject("params", category);

		mav.setViewName("display/CategorySearchForm");
		return mav;
	}

	/**
	 * 카테고리 목록
	 * @param category - 카테고리 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 4
	 */
	@PostMapping("/category/list")
	@ResponseBody
	public Collection<Category> getCategoryList(@RequestBody Category category) {
		return displayService.getCategoryList(category);
	}

}
