"use client";

import { Capacitor, registerPlugin } from "@capacitor/core";

// The app's own plugin: android/.../RangookAppPlugin.java. Not on iOS yet (callers fall back).

export interface NativeBuildInfo {
    /** Product flavor: bazaar | myket | direct. */
    channel: string;
    applicationId: string;
    versionName: string;
    versionCode: number;
    buildType: string;
    debug: boolean;
}

export interface RangookAppPlugin {
    getBuildInfo(): Promise<NativeBuildInfo>;
    /** Open outside the WebView. Resolves opened:false when nothing handles the URL. */
    openExternal(options: { url: string; package?: string }): Promise<{ opened: boolean }>;
    openAppSettings(): Promise<{ opened: boolean }>;
}

export const RangookApp = registerPlugin<RangookAppPlugin>("RangookApp");

export function isRangookAppAvailable(): boolean {
    return Capacitor.isPluginAvailable("RangookApp");
}
