package com.gic.haoban.manage.service.service.out.impl.common;

import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.service.common.RouterApiService;
import com.gic.haoban.manage.service.service.contact.ContactLogService;
import com.gic.member.api.dto.event.clerk.ClerkAddEventParam;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service("routerApiService")
public class RouterApiServiceImpl implements RouterApiService {

    private static final Logger logger = LogManager.getLogger(RouterApiService.class);


    @Autowired
    private ContactLogService contactLogService;

    @Override
    public ServiceResponse<Void> memberClerkEvent(String params) {
        if (StringUtils.isBlank(params)) {
            return ServiceResponse.success();
        }
        ClerkAddEventParam clerkAddEventParam = JSONObject.parseObject(params, ClerkAddEventParam.class);
        String memberId = clerkAddEventParam.getMemberId();
        Integer changeType = clerkAddEventParam.getChangeType();
        if (Objects.equals(changeType, 1)) {
            // 换绑主导购清除建联状态
            contactLogService.clearContactLog(memberId, 2);
        }
        return ServiceResponse.success();
    }
}
