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.frog.event.inner.EventType;
import com.sonic.frog.event.inner.payload.SubtractHeartbeatValPayload;
import com.sonic.frog.service.AiUserHeartbeatRelationService;
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 SubtractHeartbeatValHandler implements EventHandler, InitializingBean {

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

    @Override
    public void onEvent(Event event) {
        SubtractHeartbeatValPayload payload = event.normalizedData(SubtractHeartbeatValPayload.class);
        log.info("SubtractHeartbeatValHandler payload:{}", payload);
        if (payload.getUserId() == null) {
            return;
        }
//        aiUserHeartbeatRelationService.subtractHeartbeatVal(payload.getUserId());
    }

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