package com.foxx.androidcast.network.transport;

/*********************************************************************
 * StreamProtectionEngine.java
 * Created at: Sat 16 May 2026 18:50:36 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * interface StreamProtectionEngine
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (3 commits, 46 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	e5fb2347ba725ee16f5078394e2cbed9ac6c73b7f3328a04306d82f1af496e14
**********************************************************************/
/**
 * FEC / NACK over UDP logical payloads (before ACUD fragmentation).
 */
public interface StreamProtectionEngine {
    StreamProtectionMode mode();

    /** Called before UDP payload is fragmented (outbound). */
    byte[] onOutboundPayload(byte type, byte[] payload);

    /**
     * Called when a reassembled UDP message is ready (inbound).
     * Return {@code null} to signal decode failure (may trigger NACK).
     */
    byte[] onInboundPayload(byte type, byte[] payload);

    /** Sender handles NACK for a lost {@code messageId}. */
    default void onNack(int messageId) {}

    static StreamProtectionEngine noop() {
        return new StreamProtectionEngine() {
            @Override
            public StreamProtectionMode mode() {
                return StreamProtectionMode.NONE;
            }

            @Override
            public byte[] onOutboundPayload(byte type, byte[] payload) {
                return payload;
            }

            @Override
            public byte[] onInboundPayload(byte type, byte[] payload) {
                return payload;
            }
        };
    }
}
