package at.procon.eventhub.yellowfox.api;

import at.procon.eventhub.yellowfox.dto.YellowFoxD8BookingDto;
import java.util.List;
import java.util.Map;
import org.apache.camel.ProducerTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/eventhub/acquisition/yellowfox")
public class YellowFoxIngestionController {

    private final ProducerTemplate producerTemplate;

    public YellowFoxIngestionController(ProducerTemplate producerTemplate) {
        this.producerTemplate = producerTemplate;
    }

    @PostMapping("/d8-bookings")
    public ResponseEntity<Map<String, Object>> ingestYellowFoxD8Bookings(@RequestBody List<YellowFoxD8BookingDto> bookings) {
        producerTemplate.sendBody("direct:yellowfox-d8-booking-input", bookings);
        return ResponseEntity.accepted().body(Map.of(
                "accepted", bookings.size(),
                "route", "direct:yellowfox-d8-booking-input",
                "note", "Events are accepted into Camel acquisition routes, grouped by EventSource/package context, sorted in each batch, and then handed to the current ingestion adapter."
        ));
    }
}
