package com.iformall.service.msg.impl;

import com.iformall.common.ErrorCode;
import com.iformall.domain.po.*;
import com.iformall.domain.po.msg.BaseMsg;
import com.iformall.domain.po.msg.FmInsideCLoginMsg;
import com.iformall.domain.po.msg.FmInsideCouponVerifyMsg;
import com.iformall.enums.EnumAssignTagsTrigger;
import com.iformall.enums.EnumScoreType;
import com.iformall.exception.MallinkException;
import com.iformall.service.WxCUserService;
import com.iformall.service.WxCouponOrderService;
import com.iformall.service.WxMerchantBUserService;
import com.iformall.service.WxScoreRulesService;
import com.iformall.service.msg.MsgSendService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 *
 * @author Stormeye Wu
 * @date 2019/5/10
 */
@Service
public class FmInsideCLoginMsgServiceImpl implements MsgSendService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxCUserService userService;

    @Override
    public void send(BaseMsg baseMsg) throws Exception {
        FmInsideCLoginMsg msg = (FmInsideCLoginMsg)baseMsg;
        WxCUser user = userService.getById(msg.getCUserId());
        if(user == null) {
            logger.error("用户ID未找到: " + msg.getCUserId());
            throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "用户ID未找到" + msg.getCUserId());
        }

        userService.actionAfterLogin(user, msg.getFindByUnionId());
    }
}
