package com.lingniu.ingest.api.consumer;

/**
 * Non-throwing result for Kafka envelope consumers. It lets production
 * listeners isolate bad records without blocking the partition.
 */
public record EnvelopeIngestResult(Status status, String eventId, String vin, String message) {

    public enum Status {
        STORED,
        PROCESSED,
        SKIPPED,
        INVALID_ENVELOPE,
        FAILED
    }

    public EnvelopeIngestResult {
        if (status == null) {
            throw new IllegalArgumentException("status must not be null");
        }
        eventId = eventId == null ? "" : eventId;
        vin = vin == null ? "" : vin;
        message = message == null ? "" : message;
    }

    public static EnvelopeIngestResult stored(String eventId, String vin) {
        return new EnvelopeIngestResult(Status.STORED, eventId, vin, "");
    }

    public static EnvelopeIngestResult processed(String eventId, String vin) {
        return new EnvelopeIngestResult(Status.PROCESSED, eventId, vin, "");
    }

    public static EnvelopeIngestResult skipped(String eventId, String vin, String message) {
        return new EnvelopeIngestResult(Status.SKIPPED, eventId, vin, message);
    }

    public static EnvelopeIngestResult invalid(String message) {
        return new EnvelopeIngestResult(Status.INVALID_ENVELOPE, "", "", message);
    }

    public static EnvelopeIngestResult failed(String eventId, String vin, String message) {
        return new EnvelopeIngestResult(Status.FAILED, eventId, vin, message);
    }
}
