package com.sonic.frog.event.inner.handler;

import com.sonic.common.event.Event;
import com.sonic.common.event.EventConsumer;
import com.sonic.common.event.EventHandler;
import com.sonic.common.utils.RedisLock;
import com.sonic.frog.event.inner.EventType;
import com.sonic.frog.event.inner.payload.AiUserStatPayload;
import com.sonic.frog.event.inner.payload.CalcHeartbeatLevelPayload;
import com.sonic.frog.service.AiUserHeartbeatRelationService;
import com.sonic.frog.service.AiUserStatService;
import com.sonic.frog.utils.RedisKeyUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * AI用户数据比诸
 *
 * @author mzc
 */
@Slf4j
@Component
public class AiUserStatHandler implements EventHandler, InitializingBean {

    @Autowired
    private EventConsumer eventConsumer;
    @Autowired
    private AiUserStatService aiUserStatService;

    @Override
    public void onEvent(Event event) {
        AiUserStatPayload payload = event.normalizedData(AiUserStatPayload.class);
        log.info("AiUserStatHandler payload:{}", payload);
        aiUserStatService.aiUserStat(payload);
    }

    @Override
    public void afterPropertiesSet() {
        eventConsumer.registerHandler(EventType.AI_USER_STAT.getEventCode(), this);
    }
}
