package com.foxx.androidcast.network.transport;

/*********************************************************************
 * CombinedProtectionEngine.java
 * Created at: Sun 17 May 2026 22:49:49 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class CombinedProtectionEngine
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (3 commits, 53 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	8d2e19bd4e7b93efa54061257dd4a0c09d3ec026e67d46344cd5267ac8d34217
**********************************************************************/
/** FEC 3/4 (default) plus NACK retransmission. */
public final class CombinedProtectionEngine implements StreamProtectionEngine {
    private final FecProtectionEngine fec;
    private final NackProtectionEngine nack;

    public CombinedProtectionEngine(FecProtectionEngine fec, NackProtectionEngine nack) {
        this.fec = fec;
        this.nack = nack;
    }

    public NackProtectionEngine nack() {
        return nack;
    }

    public FecProtectionEngine fec() {
        return fec;
    }

    @Override
    public StreamProtectionMode mode() {
        return fec.mode() == StreamProtectionMode.FEC_REED_SOLOMON
                ? StreamProtectionMode.FEC_REED_SOLOMON
                : StreamProtectionMode.FEC_3_4;
    }

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

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

    @Override
    public void onNack(int messageId) {
        nack.onNack(messageId);
    }

    public NackProtectionEngine getNack() {
        return nack;
    }
}
