package com.style24.core.biz.service;

import com.gagaframework.web.parameter.GagaMap;
import com.style24.core.biz.thirdparty.FingerPushSender;
import com.style24.core.support.env.TscConstants;
import com.style24.persistence.domain.CustContactHst;
import com.style24.persistence.domain.Customer;
import com.style24.persistence.domain.FingerPush;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
public class TscFingerPushService {

	@Autowired
	private Environment env;

	@Autowired
	private FingerPushSender fingerPushSender;

	@Autowired
	private TscCustomerService coreCustomerService;


	@Transactional("shopTxnManager")
	public void send(Customer customer, int ansSq) {
		FingerPush fingerPush = new FingerPush();
		fingerPush.setIdentify(String.valueOf(customer.getCustNo()));		// 수신 고객 식별자(custNo)
		fingerPush.setPhone(customer.getCellPhnno());
		fingerPush.setFailedtype("LMS");

		GagaMap replaceInfo = new GagaMap();

		fingerPushSender.send(ansSq, fingerPush, replaceInfo);				// ansSq ex) FingerPushSender.FingerPushSq.WISHLIST_DISCOUNT.value()

		try {
			// 고객접촉이력 정보
			CustContactHst custContactHst = new CustContactHst();
			custContactHst.setContactMethod(TscConstants.ContactMethod.PUSH.value()); //푸시
			custContactHst.setContactType(customer.getContactType());
			custContactHst.setContactContents(customer.getContactContents());
			custContactHst.setReceiverNo(customer.getCustNo());
			custContactHst.setSenderNo(customer.getRegNo());
			custContactHst.setRegNo(customer.getRegNo());
			custContactHst.setUpdNo(customer.getUpdNo());
			coreCustomerService.createCustomerContactHistory(custContactHst);
		} catch (Exception e) {
			log.error("error", e);
			// Do nothing
		}
	}

}
