package com.foxx.androidcast;

/*********************************************************************
 * IntentExtras.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 IntentExtras
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (3 commits, 51 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	19f9b1ab3e5b3ce7eb7623e31f52e5a116a4cde8c0a58da6e3c320e807bb6b8a
**********************************************************************/
import android.content.Intent;
import android.os.Build;

import com.foxx.androidcast.sender.CastReceiverTarget;

import java.util.ArrayList;

/** API 33+ safe extras helpers. */
public final class IntentExtras {
    private IntentExtras() {}

    public static Intent getParcelableIntent(Intent intent, String key) {
        if (intent == null) {
            return null;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            return intent.getParcelableExtra(key, Intent.class);
        }
        return intent.getParcelableExtra(key);
    }

    public static CastSettings getCastSettings(Intent intent) {
        if (intent == null) {
            return null;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            return intent.getSerializableExtra(CastSettings.EXTRA, CastSettings.class);
        }
        return (CastSettings) intent.getSerializableExtra(CastSettings.EXTRA);
    }

    @SuppressWarnings("unchecked")
    public static ArrayList<CastReceiverTarget> getReceiverTargets(Intent intent, String key) {
        if (intent == null) {
            return null;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            return intent.getSerializableExtra(key, ArrayList.class);
        }
        return (ArrayList<CastReceiverTarget>) intent.getSerializableExtra(key);
    }
}
