package com.foxx.androidcast;

/*********************************************************************
 * CastConfig.java
 * Created at: Fri 15 May 2026 16:49:02 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class CastConfig
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (11 commits, 80 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	46ab864bc4474c49c7e832578a1559f20f1fbb8365b87f77425bc8d53129729c
**********************************************************************/
/** Shared constants for the LAN cast POC. */
public final class CastConfig {
    public static final int DISCOVERY_PORT = 41234;
    /** One UDP browse pass duration (sender shows countdown on Refresh). */
    public static final long DISCOVERY_SCAN_PASS_MS = 30_000;
    /** Fast scan when user taps Refresh (UDP burst + NSD). */
    public static final long DISCOVERY_BURST_MS = 5_000;
    /** Idle gap between automatic browse passes. */
    public static final long DISCOVERY_PAUSE_MS = 30_000;
    /** How often the sender broadcasts a discover probe during a scan pass. */
    public static final long DISCOVERY_PROBE_INTERVAL_MS = 1_000;
    /** Probe interval during burst scan. */
    public static final long DISCOVERY_BURST_PROBE_MS = 250;
    /** NSD service type for LAN discovery (in addition to UDP). */
    public static final String NSD_SERVICE_TYPE = "_androidcast._udp.";
    public static final int CAST_PORT = 41235;
    public static final String DISCOVERY_MAGIC = "ACAST1";

    /**
     * Alpha / feature-freeze gate: limits transports in settings and disables 1:N cast until post-alpha soak.
     * Set to {@code false} on a release branch when re-enabling QUIC and multi-receiver experiments.
     */
    public static final boolean ALPHA_FEATURE_FREEZE = true;

    /** When true, sender list allows selecting multiple receivers (1:N cast). */
    public static final boolean MULTI_RECEIVER_ENABLED = !ALPHA_FEATURE_FREEZE;

    /** Transports exposed in cast settings while {@link #ALPHA_FEATURE_FREEZE} is on. */
    public static boolean isReleaseTransport(String transport) {
        return TRANSPORT_UDP.equals(transport) || TRANSPORT_TCP.equals(transport);
    }

    public static final int MAX_RECEIVERS = 5;
    public static final String DEFAULT_PIN = "1234";

    public static final String TRANSPORT_TCP = "tcp";
    public static final String TRANSPORT_UDP = "udp";
    public static final String TRANSPORT_QUIC = "quic";
    public static final String TRANSPORT_WEBRTC = "webrtc";
    /** USB tether / ADB reverse — stub until roadmap E is implemented. */
    public static final String TRANSPORT_USB_TETHER = "usb_tether";
    /** Default cast transport (UDP); TCP/QUIC remain selectable in settings. */
    public static final String DEFAULT_TRANSPORT = TRANSPORT_UDP;
    /** Dedicated port for experimental QUIC transport (UDP/TCP framed). */
    public static final int QUIC_PORT = 41236;

    public static int portForTransport(String transport) {
        if (TRANSPORT_QUIC.equals(transport)) {
            return QUIC_PORT;
        }
        return CAST_PORT;
    }

    /** Seconds between IDR frames (1 = faster recovery, slightly more bandwidth). */
    public static final int VIDEO_I_FRAME_INTERVAL = 1;

    /** Request sync frames on this interval when the screen is static (Mediatek stall workaround). */
    public static final long KEYFRAME_KEEPALIVE_MS = 2_000;

    /** P-frames smaller than this are treated as empty and not sent (unless keepalive IDR). */
    public static final int MIN_SIGNIFICANT_FRAME_BYTES = 400;

    public static final int AUDIO_SAMPLE_RATE = 44100;
    public static final int AUDIO_CHANNEL_COUNT = 2;
    public static final int AUDIO_BITRATE = 96_000;

    /**
     * Optional cap on calibration chart long edge (0 = use asset size as-is).
     * Keeps encoder load bounded if the reference PNG is replaced with a larger image.
     */
    public static final int CALIBRATION_MAX_LONG_EDGE = 0;

    /** Max UDP payload chunk (fits typical Wi‑Fi MTU with header). */
    public static final int UDP_CHUNK_SIZE = 1200;

    /** Max retained session stat JSON files (room for one new file on next session). */
    public static final int SESSION_STATS_MAX_FILES = 20;

    /** No video packets for this long → treat stream as stopped (robot overlay). */
    /** No inbound video this long → robot overlay (keep above ~2× slowest expected frame interval). */
    public static final long STREAM_IDLE_TIMEOUT_MS = 8_000;

    private CastConfig() {}
}
