package com.sonic.bear.service.impl;


import com.sonic.bear.event.outer.payload.UserCratedPayload;
import com.sonic.bear.service.CommonSendMqService;
import com.sonic.common.event.Event;
import com.sonic.common.event.EventProducer;
import com.sonic.common.event.RabbitmqEventProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import static com.sonic.bear.event.outer.EventType.USER_CREATED;

/**
 * 发送消息到im的mq
 */
@Service
@Slf4j
public class CommonSendMqServiceImpl implements CommonSendMqService {

    @Autowired
    private EventProducer eventProducer;

    @Autowired
    @Qualifier("userCreatedMeta")
    private RabbitmqEventProducer.RabbitmqMessageMeta userCreatedMeta;

    @Override
    public void userCreatedSendMq(Long userId) {
        UserCratedPayload payload = UserCratedPayload.builder()
                .userId(userId)
                .build();
        eventProducer.send(Event.builder()
                .eventScene(USER_CREATED.getEventCode().getScene())
                .eventModule(USER_CREATED.getEventCode().getModule())
                .eventName(USER_CREATED.getEventCode().getName())
                .data(payload).build(), userCreatedMeta);
    }
}
