package com.izouma.nineth.listener;

import com.izouma.nineth.service.CollectionService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@AllArgsConstructor
@RocketMQMessageListener(
        consumerGroup = "${general.update-quota-group}",
        topic = "${general.update-quota-topic}",
        consumeMode = ConsumeMode.ORDERLY)
@ConditionalOnProperty(value = "general.notify-server", havingValue = "false", matchIfMissing = true)
public class UpdateQuotaListener implements RocketMQListener<Long> {

    private CollectionService collectionService;

    @Override
    public void onMessage(Long id) {
        collectionService.syncQuota(id);
    }
}
