package com.madeu.controller.web.webmarketing;

import com.madeu.init.ManagerDraftAction;
import com.madeu.service.web.webloghistory.WebLogHistoryService;
import com.madeu.service.web.webmember.WebMemberService;
import com.madeu.util.HttpUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;


@Slf4j
@Controller
public class WebMarketingController extends ManagerDraftAction{

	@Autowired
	private WebMemberService webMemberService;
	
	@Autowired
	private WebLogHistoryService webLogHistoryService;

	/**
	 * 알림톡 화면으로 이동.
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webmarketing/selectListMarketingKakaoIntro.do")
	public String  selectListMarketingKakaoIntro(HttpSession session,HttpServletRequest request, HttpServletResponse response, Model model) {
		log.debug("WebMemberController  selectListMarketingKakaoIntro START");

		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		try{
			if(!webCheckLogin(session)){
				return "/web/login/logout";
			}
			else {
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webMemberService.selectListMemberIntro(paramMap);
				
				model.addAttribute("selectUseYn", map.get("selectUseYn"));
				model.addAttribute("insertUseYn", map.get("insertUseYn"));
				model.addAttribute("updateUseYn", map.get("updateUseYn"));
				model.addAttribute("deleteUseYn", map.get("deleteUseYn"));
				model.addAttribute("downloadUseYn", map.get("downloadUseYn"));
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return "/web/login/logout";
		}
		log.debug("WebMemberController  selectListMarketingKakaoIntro END");
		return "/web/marketing/marketingKakaoSelectList";
	}


	/**
	 * 알림톡 발송내역 리스트 화면으로 이동.
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/webmarketing/selectListMarketingKakaoHistIntro.do")
	public String  selectListMarketingKakaoHistIntro(HttpSession session,HttpServletRequest request, HttpServletResponse response, Model model) {
		log.debug("WebMemberController  selectListMarketingKakaoHistIntro START");

		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		try{
			if(!webCheckLogin(session)){
				return "/web/login/logout";
			}
			else {
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webMemberService.selectListMemberIntro(paramMap);

				model.addAttribute("selectUseYn", map.get("selectUseYn"));
				model.addAttribute("insertUseYn", map.get("insertUseYn"));
				model.addAttribute("updateUseYn", map.get("updateUseYn"));
				model.addAttribute("deleteUseYn", map.get("deleteUseYn"));
				model.addAttribute("downloadUseYn", map.get("downloadUseYn"));
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return "/web/login/logout";
		}
		log.debug("WebMemberController  selectListMarketingKakaoHistIntro END");
		return "/web/marketing/marketingKakaoHistSelectList";
	}

	/**
	 * SMS 리스트 화면으로 이동.
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/webmarketing/selectListMarketingSmsIntro.do")
	public String  selectListMarketingSmsIntro(HttpSession session,HttpServletRequest request, HttpServletResponse response, Model model) {
		log.debug("WebMemberController  selectListMarketingSmsIntro START");

		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		try{
			if(!webCheckLogin(session)){
				return "/web/login/logout";
			}
			else {
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webMemberService.selectListMemberIntro(paramMap);

				model.addAttribute("selectUseYn", map.get("selectUseYn"));
				model.addAttribute("insertUseYn", map.get("insertUseYn"));
				model.addAttribute("updateUseYn", map.get("updateUseYn"));
				model.addAttribute("deleteUseYn", map.get("deleteUseYn"));
				model.addAttribute("downloadUseYn", map.get("downloadUseYn"));
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return "/web/login/logout";
		}
		log.debug("WebMemberController  selectListMarketingSmsIntro END");
		return "/web/marketing/marketingSmsSelectList";
	}

	/**
	 * SMS 발송내역 리스트 화면으로 이동.
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/webmarketing/selectListMarketingSmsHistIntro.do")
	public String  selectListMarketingSmsHistIntro(HttpSession session,HttpServletRequest request, HttpServletResponse response, Model model) {
		log.debug("WebMemberController  selectListMarketingSmsHistIntro START");

		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		try{
			if(!webCheckLogin(session)){
				return "/web/login/logout";
			}
			else {
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webMemberService.selectListMemberIntro(paramMap);

				model.addAttribute("selectUseYn", map.get("selectUseYn"));
				model.addAttribute("insertUseYn", map.get("insertUseYn"));
				model.addAttribute("updateUseYn", map.get("updateUseYn"));
				model.addAttribute("deleteUseYn", map.get("deleteUseYn"));
				model.addAttribute("downloadUseYn", map.get("downloadUseYn"));
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return "/web/login/logout";
		}
		log.debug("WebMemberController  selectListMarketingSmsHistIntro END");
		return "/web/marketing/marketingSmsHistSelectList";
	}

	/**
	 * 푸시 화면으로 이동.
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/webmarketing/selectListMarketingPushIntro.do")
	public String  selectListMarketingPushIntro(HttpSession session,HttpServletRequest request, HttpServletResponse response, Model model) {
		log.debug("WebMemberController  selectListMarketingPushIntro START");

		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		try{
			if(!webCheckLogin(session)){
				return "/web/login/logout";
			}
			else {
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webMemberService.selectListMemberIntro(paramMap);

				model.addAttribute("selectUseYn", map.get("selectUseYn"));
				model.addAttribute("insertUseYn", map.get("insertUseYn"));
				model.addAttribute("updateUseYn", map.get("updateUseYn"));
				model.addAttribute("deleteUseYn", map.get("deleteUseYn"));
				model.addAttribute("downloadUseYn", map.get("downloadUseYn"));
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return "/web/login/logout";
		}
		log.debug("WebMemberController  selectListMarketingPushIntro END");
		return "/web/marketing/marketingPushSelectList";
	}


	/**
	 * 푸시 발송내역 리스트 화면으로 이동.
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/webmarketing/selectListMarketingPushHistIntro.do")
	public String  selectListMarketingPushHistIntro(HttpSession session,HttpServletRequest request, HttpServletResponse response, Model model) {
		log.debug("WebMemberController  selectListMarketingPushHistIntro START");

		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		try{
			if(!webCheckLogin(session)){
				return "/web/login/logout";
			}
			else {
				paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
				map = webMemberService.selectListMemberIntro(paramMap);

				model.addAttribute("selectUseYn", map.get("selectUseYn"));
				model.addAttribute("insertUseYn", map.get("insertUseYn"));
				model.addAttribute("updateUseYn", map.get("updateUseYn"));
				model.addAttribute("deleteUseYn", map.get("deleteUseYn"));
				model.addAttribute("downloadUseYn", map.get("downloadUseYn"));
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			return "/web/login/logout";
		}
		log.debug("WebMemberController  selectListMarketingPushHistIntro END");
		return "/web/marketing/marketingPushHistSelectList";
	}

}
