package com.style24.admin.biz.service;

import com.gagaframework.web.parameter.GagaMap;
import com.style24.admin.support.security.session.TsaSession;
import com.style24.core.biz.service.TscCustomerService;
import com.style24.core.support.env.TscConstants;
import com.style24.persistence.domain.CustContactHst;
import com.style24.persistence.domain.Customer;
import com.style24.persistence.domain.SsgDirectMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.style24.core.biz.thirdparty.SsgKakaoSender;

import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;

/**
 * 카카오알림톡 Service. 모든 카카오알림톡 발송은 여기에서 처리한다.
 *
 * @author gagamel
 * @since 2020. 11. 9
 */
@Service
@Slf4j
public class TsaKakaoService {

	@Autowired
	private SsgKakaoSender kakaoSender;

	@Autowired
	private TscCustomerService coreCustomerService;

	public static final String siteNm = "STYLE24";


//
//	/**
//	 * 일대일문의 답변 알림톡 발송
//	 * @param counsel - 상담 정보
//	 * @author gagamel
//	 * @since 2020. 4. 6
//	 */
//	@Transactional("shopTxnManager")
//	public void sendOnetoOneAnswer(AdmCounsel counsel) {
//		SsgDirectMessage dm = new SsgDirectMessage();
//		dm.setFdestine(counsel.getCellPhnno());
//		dm.setFkkoresendtype("LMS");
//		dm.setButtonNm("마이페이지 > 1:1문의");
//		dm.setButtonUrl("/mypage/counsel/detail/form/" + counsel.getCounselSq());
//
//		GagaMap replaceInfo = new GagaMap();
//		replaceInfo.setString("siteNm", systemService.getSiteName(AdmConstants.SITE_CD));
//		replaceInfo.setString("custNm", counsel.getCustNm());
//
//		kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.OtoAnswer.value(), dm, replaceInfo);
//
//		try {
//			// 고객접촉이력 정보
//			AdmCustomer customer = new AdmCustomer();
//			customer.setContactType("204"); // 접촉유형:1:1문의답변(공통코드G054)
//			customer.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value()); // 접촉방법:알림톡+문자(공통코드G055)
//			customer.setContactContents("1:1 문의 답변 발송");
//			customer.setReceiverId(counsel.getCustNo());
//			customerService.createCustomerContactHistory(customer);
//		} catch (Exception e) {
//			log.error("error", e);
//			// Do nothing
//		}
//	}
//

//
//	/**
//	 * 품절에의한 주문취소 안내
//	 * @param delivery
//	 * @author yujung
//	 * @since 2020. 4. 23
//	 */
//	public void sendCancelBySoldout(String payMeans, AdmDelivery delivery) {
//		SsgDirectMessage dm = new SsgDirectMessage();
//		dm.setFdestine(delivery.getOrderPhnno());
//		dm.setFkkoresendtype("LMS");
//
//		GagaMap replaceInfo = new GagaMap();
//		replaceInfo.setString("siteNm", systemService.getSiteName(AdmConstants.SITE_CD));
//		replaceInfo.setString("custNm", delivery.getOrderNm());
//		replaceInfo.setString("goodsNm", delivery.getGoodsNm());
//		replaceInfo.setString("callcenterTelNo", TscConstants.CALLCENTER_TEL_NO);
//
//		Integer KakaoAnswerSq = null;
//		if (payMeans.equals(TscConstants.PayMeans.CREDIT_CARD.value())) { // 신용카드
//			KakaoAnswerSq = SsgKakaoSender.KakaoAnswerSq.CardCancelBySoldout.value();
//		} else if (payMeans.equals(TscConstants.PayMeans.ACCOUNT_TRANSFER.value())) { // 실시간계좌이체
//			KakaoAnswerSq = SsgKakaoSender.KakaoAnswerSq.AtCancelBySoldout.value();
//		} else if (payMeans.equals(TscConstants.PayMeans.BANK_DEPOSIT.value())) { // 무통장입금
//			KakaoAnswerSq = SsgKakaoSender.KakaoAnswerSq.VaCancelBySoldout.value();
//		}
//
//		kakaoSender.send(KakaoAnswerSq, dm, replaceInfo);
//
//		try {
//			// 고객접촉이력 정보
//			AdmCustomer customer = new AdmCustomer();
//			customer.setContactType("304"); // 접촉유형 : 주문-품절안내(공통코드G054)
//			customer.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value()); // 접촉방법 : 알림톡+문자(공통코드G055)
//			customer.setContactContents("품절에의한 주문취소 안내");
//			customer.setReceiverId(delivery.getCustNo());
//			customerService.createCustomerContactHistory(customer);
//		} catch (Exception e) {
//			log.error("error", e);
//			// Do nothing
//		}
//	}
//
//	/**
//	 * 주문취소안내 알림톡
//	 * @param customer - 고객 정보
//	 * @author gagamel
//	 * @since 2020. 11. 9
//	 */
//	@Transactional("shopTxnManager")
//	public void sendOrderCancel(AdmCustomer customer, AdmOrder order) {
//		SsgDirectMessage dm = new SsgDirectMessage();
//		dm.setFdestine(customer.getCellPhnno());
//		dm.setFkkoresendtype("LMS");
//
//		dm.setButtonNm("마이페이지 > 주문내역");
//		dm.setButtonUrl("/mypage/order/list/form");
//
//		GagaMap replaceInfo = new GagaMap();
//		replaceInfo.setString("siteNm", systemService.getSiteName(AdmConstants.SITE_CD));
//		replaceInfo.setString("custNm", customer.getCustNm());
//
//		if (order.getPayMeans().equals(TscConstants.PayMeans.CREDIT_CARD.value())) { // 신용카드
//			kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.CardCancelRefund.value(), dm, replaceInfo);
//		} else if (order.getPayMeans().equals(TscConstants.PayMeans.ACCOUNT_TRANSFER.value())) { // 실시간계좌이체
//			kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.AtCancelRefund.value(), dm, replaceInfo);
//		} else if (order.getPayMeans().equals(TscConstants.PayMeans.BANK_DEPOSIT.value())) { // 무통장입금
//			kakaoSender.send(SsgKakaoSender.KakaoAnswerSq.VaCancelRefund.value(), dm, replaceInfo);
//		}
//
//		try {
//			// 고객접촉이력 정보
//			customer.setContactType("305"); // 접촉유형:주문안내(공통코드G054)
//			customer.setContactMethod(TscConstants.ContactMethod.KAKAOTALK.value()); // 접촉방법:알림톡+문자(공통코드G055)
//			customer.setContactContents("주문-취소안내");
//			customer.setReceiverId(customer.getCustNo());
//			customerService.createCustomerContactHistory(customer);
//		} catch (Exception e) {
//			log.error("error", e);
//			// Do nothing
//		}
//	}
//


}
