package com.njcn.msgpush.module.push.client.sender;

import com.njcn.msgpush.module.push.service.channel.ChannelProviderConfigService;
import com.njcn.msgpush.module.push.service.channel.ProviderErrorCodeMappingService;
import com.njcn.msgpush.module.push.service.retry.MessageRetryQueueService;
import com.njcn.msgpush.module.push.util.RestTemplateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author caozehui
 * @data 2026-03-02
 */
@Component
public class Sender {

    @Autowired
    public ChannelProviderConfigService channelProviderConfigService;
    @Autowired
    public MessageRetryQueueService messageRetryQueueService;
    @Autowired
    public ProviderErrorCodeMappingService providerErrorCodeMappingService;
    @Autowired
    public RestTemplateUtil restTemplateUtil;

    public final ThreadPoolExecutor MSG_PUSH_THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(
            5,
            5,
            1000,
            TimeUnit.MILLISECONDS,
            new java.util.concurrent.ArrayBlockingQueue<>(1000),
            r -> {
                Thread thread = new Thread(r);
                thread.setName("msgPushThreadPool-" + thread.getId());
                thread.setDaemon(false);
                return thread;
            },
            new ThreadPoolExecutor.CallerRunsPolicy()
    );

}
