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.CalcHeartbeatLevelPayload;
import com.sonic.frog.event.inner.payload.CalcHeartbeatScorePayload;
import com.sonic.frog.service.AiUserHeartbeatRelationService;
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;

/**
 * @author code
 */
@Slf4j
@Component
public class CalcHeartbeatScoreHandler implements EventHandler, InitializingBean {

    @Autowired
    private EventConsumer eventConsumer;
    @Autowired
    private AiUserHeartbeatRelationService aiUserHeartbeatRelationService;

    @Override
    public void onEvent(Event event) {
        CalcHeartbeatScorePayload payload = event.normalizedData(CalcHeartbeatScorePayload.class);
        log.info("CalcHeartbeatScoreHandler payload:{}", payload);
        aiUserHeartbeatRelationService.calcAiUserHeartbeatScore(payload.getUserId(),payload.getAiId());
    }

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