package ai.decompile.job.messaging;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
  private final String exchange;
  private final String queue;
  private final String routingKey;

  public RabbitMQConfig(
      @Value("${app.rabbitmq.exchange}") String exchange,
      @Value("${app.rabbitmq.queue}") String queue,
      @Value("${app.rabbitmq.routing-key}") String routingKey) {
    this.exchange = exchange;
    this.queue = queue;
    this.routingKey = routingKey;
  }

  @Bean
  public TopicExchange jobExchange() {
    return new TopicExchange(exchange);
  }

  @Bean
  public Queue jobQueue() {
    return new Queue(queue, true);
  }

  @Bean
  public Binding jobBinding(TopicExchange jobExchange, Queue jobQueue) {
    return BindingBuilder.bind(jobQueue).to(jobExchange).with(routingKey);
  }
}
