package cz.moneta.test.dsl.kafka;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.endpoints.kafka.KafkaEndpoint;
import cz.moneta.test.harness.support.messaging.kafka.KafkaRequest;

/**
 * Kafka DSL that provides fluent API for Kafka messaging.
 * <p>
 * Usage:
 * <pre>{@code
 * harness.withKafka()
 *     .toTopic("order-events")
 *     .withKey("order-123")
 *     .withPayload("{\"orderId\": \"123\"}")
 *     .send();
 * }</pre>
 */
public class Kafka {

    private final Harness harness;

    public Kafka(Harness harness) {
        this.harness = harness;
    }

    /**
     * Starts a Kafka send operation.
     */
    public KafkaRequest.KafkaPayloadPhase toTopic(String topic) {
        KafkaEndpoint endpoint = harness.getEndpoint(KafkaEndpoint.class);
        return KafkaRequest.builder(endpoint).toTopic(topic);
    }

    /**
     * Starts a Kafka receive operation.
     */
    public KafkaRequest.KafkaReceiveFilterPhase fromTopic(String topic) {
        KafkaEndpoint endpoint = harness.getEndpoint(KafkaEndpoint.class);
        return KafkaRequest.builder(endpoint).fromTopic(topic);
    }
}
