package com.style24.scm.biz.web;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.style24.persistence.domain.AflinkFee;
import com.style24.persistence.domain.CommonCode;
import com.style24.scm.biz.service.TssRendererService;
import com.style24.scm.biz.service.TssSettleService;
import com.style24.scm.support.controller.TssBaseController;
import com.style24.scm.support.security.session.TssSession;

import lombok.extern.slf4j.Slf4j;

/**
 * 정산 Controller
 *
 * @author jaewonHo
 * @since 2021. 1. 20
 */
@Controller
@RequestMapping("/settle")
@Slf4j
public class TssSettleController extends TssBaseController {

	@Autowired
	private TssSettleService settleService;

	@Autowired
	private TssRendererService rendererService;

	/**
	 * 제휴채널정산 화면
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 20
	 */
	@GetMapping("/aflink/fee/form")
	public ModelAndView afLinkFeeForm() {
		ModelAndView mav = new ModelAndView("settle/AfLinkSettleForm");

		// 상위제휴채널 목록
		CommonCode commoncode = new CommonCode();
		commoncode.setCdGb("G053");
		commoncode.setCd(TssSession.getInfo().getAfChannel());
		mav.addObject("afChannelList", rendererService.getCommonCodeList(commoncode));

		// 제휴채널 목록
		mav.addObject("afLinkList", rendererService.getAflinkList(TssSession.getInfo().getAfChannel(), TssSession.getInfo().getAfLinkCd()));

		return mav;
	}

	/**
	 * 제휴채널정산 목록
	 * @param aflinkFee - 제휴채널수수료 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 20
	 */
	@PostMapping("/aflink/fee/list")
	@ResponseBody
	public Collection<AflinkFee> getAfLinkFeeList(@RequestBody AflinkFee aflinkFee) {
		// 파라미터로 다른 값을 입력해 조회할 수 있으므로 세션값으로 다시 설정
		aflinkFee.setAfChannel(TssSession.getInfo().getAfChannel());

		return settleService.getAfLinkFeeList(aflinkFee);
	}

}
