/**
 * date : 2022. 4. 25.
 * auth : ckr
 * desc : 채널관리
 */
package kr.co.uplus.ez.api.channelMgt;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import kr.co.uplus.ez.api.channelMgt.dto.TmpltListExcelReqDto;
import kr.co.uplus.ez.api.channelMgt.dto.TmpltListExcelResDto;
import kr.co.uplus.ez.api.channelMgt.dto.TmpltListReqDto;
import kr.co.uplus.ez.api.channelMgt.dto.TmpltListResDto;
import kr.co.uplus.ez.common.components.ValidComponents;
import kr.co.uplus.ez.common.data.ApiResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@RestController
@RequestMapping(value = "api/v1/bo/channelMgt")
public class ChannelMgtController {

	@Autowired
	ChannelMgtService channelService;

	@Autowired
	ValidComponents validComponents;

	/**
	 * date : 2022. 4. 25.
	 * auth : ckr
	 * desc : 알림톡 템플릿 목록 조회
	 * @param tmpltListReqDto
	 * @return
	 * @
	 */
	@ApiOperation(value = "tmpltList", notes = "알림톡 템플릿 목록 조회")
	@ApiResponses({ @ApiResponse(code = HttpServletResponse.SC_OK, message = "SUCESS") })
	@RequestMapping(value = "tmpltList", method = { RequestMethod.POST })
	@ResponseBody
	public TmpltListResDto tmpltList(@RequestBody @Valid TmpltListReqDto tmpltListReqDto, BindingResult bindingResult) {

		if (validComponents.validParameter(bindingResult)) {
			return new TmpltListResDto(ApiResponseCode.CM_PARAMETER_ERROR);
		}

		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
		String userId = auth.getName();

		return channelService.tmpltList(tmpltListReqDto, userId);
	}

	/**
	 * date : 2022. 4. 25.
	 * auth : ckr
	 * desc : 알림톡 템플릿 엑셀 다운로드 목록 조회
	 * @param tmpltListExcelReqDto
	 * @return
	 * @
	 */
	@ApiOperation(value = "tmpltListExcel", notes = "알림톡 템플릿 엑셀 다운로드 목록 조회")
	@ApiResponses({ @ApiResponse(code = HttpServletResponse.SC_OK, message = "SUCESS") })
	@RequestMapping(value = "tmpltListExcel", method = { RequestMethod.POST })
	@ResponseBody
	public TmpltListExcelResDto tmpltListExcel(@RequestBody @Valid TmpltListExcelReqDto tmpltListExcelReqDto, BindingResult bindingResult) {

		if (validComponents.validParameter(bindingResult)) {
			return new TmpltListExcelResDto(ApiResponseCode.CM_PARAMETER_ERROR);
		}

		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
		String userId = auth.getName();

		return channelService.tmpltListExcel(tmpltListExcelReqDto, userId);
	}
	
	/**
	 * date : 2022. 4. 25.
	 * auth : ckr
	 * desc : 알림톡 템플릿 목록 조회
	 * @param tmpltListReqDto
	 * @return
	 * @
	 */
	@ApiOperation(value = "tmpltRejectList", notes = "알림톡 템플릿 반려 목록 조회")
	@ApiResponses({ @ApiResponse(code = HttpServletResponse.SC_OK, message = "SUCESS") })
	@RequestMapping(value = "tmpltRejectList", method = { RequestMethod.POST })
	@ResponseBody
	public TmpltListResDto tmpltRejectList(@RequestBody @Valid TmpltListReqDto tmpltListReqDto, BindingResult bindingResult) {

		if (validComponents.validParameter(bindingResult)) {
			return new TmpltListResDto(ApiResponseCode.CM_PARAMETER_ERROR);
		}

		return channelService.tmpltRejectList(tmpltListReqDto);
	}
}
