package com.foxx.androidcast.network.transport;

/*********************************************************************
 * ProtectionNegotiationPrompts.java
 * Created at: Tue 19 May 2026 12:23:39 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class ProtectionNegotiationPrompts
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (2 commits, 63 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	26526ff9e1f666fd34f2592b5d7379e1e731ce89b10b587b3c2fc362248ef211
**********************************************************************/
import android.content.Context;

import com.foxx.androidcast.CastSettings;
import com.foxx.androidcast.R;

/** Formats {@link StreamProtectionNegotiation.Prompt} for logs and on-screen status. */
public final class ProtectionNegotiationPrompts {
    private ProtectionNegotiationPrompts() {}

    public static String format(Context context, StreamProtectionNegotiation.Prompt prompt,
            boolean localIsReceiver) {
        if (context == null || prompt == null) {
            return "";
        }
        String local = label(context, prompt.localPreference);
        String remote = label(context, prompt.remotePreference);
        String role = context.getString(prompt.target == StreamProtectionNegotiation.Prompt.Target.SENDER
                ? R.string.protection_negotiation_role_sender
                : R.string.protection_negotiation_role_receiver);
        return context.getString(prompt.messageResId, local, remote, role);
    }

    public static String summarize(Context context, StreamProtectionNegotiation negotiation) {
        if (context == null || negotiation == null) {
            return "";
        }
        String mode = label(context, negotiation.agreed);
        String nack = negotiation.nackEnabled
                ? context.getString(R.string.protection_negotiation_nack_on)
                : context.getString(R.string.protection_negotiation_nack_off);
        return context.getString(R.string.protection_negotiation_agreed, mode, nack);
    }

    public static String label(Context context, CastSettings.StreamProtection mode) {
        if (context == null || mode == null) {
            return "?";
        }
        switch (mode) {
            case FEC_3_4:
                return context.getString(R.string.protection_fec_34);
            case FEC_REED_SOLOMON:
                return context.getString(R.string.protection_fec_rs);
            case NACK:
                return context.getString(R.string.protection_nack);
            case FEC_NACK:
                return context.getString(R.string.protection_fec_nack);
            case AUTO:
                return context.getString(R.string.option_auto);
            case NONE:
            default:
                return context.getString(R.string.protection_none);
        }
    }
}
