import { CloudReporterOptions, ReportMode, CloudConfig } from '@testrelic/core';

/**
 * @testrelic/appium-analytics — Type definitions
 *
 * Appium-specific types for configuration, log capture, command tracking,
 * and capability detection. Re-exports shared types from @testrelic/core.
 */

type AppTestMode = 'native' | 'hybrid' | 'mobile-web';
type Platform = 'android' | 'ios' | 'unknown';
interface DetectedCapabilities {
    readonly platform: Platform;
    readonly testMode: AppTestMode;
    readonly platformVersion: string | null;
    readonly deviceName: string | null;
    readonly automationName: string | null;
    readonly appPath: string | null;
    readonly browserName: string | null;
    readonly udid: string | null;
}
interface AppiumReporterConfig {
    readonly outputPath?: string;
    readonly htmlReportPath?: string;
    readonly openReport?: boolean;
    readonly includeDeviceLogs?: boolean;
    readonly includeNetworkLogs?: boolean;
    readonly includeConsoleLogs?: boolean;
    readonly includeScreenshots?: boolean;
    readonly screenshotOnEvery?: 'test' | 'failure' | 'never';
    readonly includeVideoRecording?: boolean;
    readonly includeCommands?: boolean;
    readonly includeAssertions?: boolean;
    readonly includeActionSteps?: boolean;
    readonly deviceLogPollInterval?: number;
    readonly maxDeviceLogs?: number;
    readonly preferBiDi?: boolean;
    readonly redactPatterns?: (string | RegExp)[];
    readonly testRunId?: string;
    readonly metadata?: Record<string, unknown>;
    readonly cloud?: CloudReporterOptions;
    readonly reportMode?: ReportMode;
    readonly streamingThreshold?: number;
    readonly quiet?: boolean;
}
interface ResolvedAppiumConfig {
    readonly outputPath: string;
    readonly htmlReportPath: string;
    readonly openReport: boolean;
    readonly includeDeviceLogs: boolean;
    readonly includeNetworkLogs: boolean;
    readonly includeConsoleLogs: boolean;
    readonly includeScreenshots: boolean;
    readonly screenshotOnEvery: 'test' | 'failure' | 'never';
    readonly includeVideoRecording: boolean;
    readonly includeCommands: boolean;
    readonly includeAssertions: boolean;
    readonly includeActionSteps: boolean;
    readonly deviceLogPollInterval: number;
    readonly maxDeviceLogs: number;
    readonly preferBiDi: boolean;
    readonly redactPatterns: (string | RegExp)[];
    readonly testRunId: string | null;
    readonly metadata: Record<string, unknown> | null;
    readonly cloud: CloudConfig | null;
    readonly reportMode: ReportMode;
    readonly streamingThreshold: number;
    readonly quiet: boolean;
}
type DeviceLogSource = 'logcat' | 'syslog' | 'crashlog' | 'browser' | 'safariConsole' | 'safariNetwork' | 'performance' | 'server' | 'bidi';
interface DeviceLogEntry {
    readonly timestamp: string;
    readonly level: 'verbose' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
    readonly message: string;
    readonly tag?: string;
    readonly source: DeviceLogSource;
    readonly pid?: number;
    readonly stackTrace?: string;
}
type CommandCategory = 'find' | 'interaction' | 'gesture' | 'navigation' | 'lifecycle' | 'context' | 'device' | 'keyboard' | 'alert' | 'screenshot' | 'other';
interface AppiumCommandStep {
    readonly type: 'command';
    readonly command: string;
    readonly category: CommandCategory;
    readonly args?: unknown[];
    readonly selector?: string;
    readonly timestamp: string;
    readonly duration: number;
    readonly result: 'success' | 'error';
    readonly error?: string;
    readonly endpoint?: string;
    readonly method?: string;
}
interface AppiumAssertionStep {
    readonly type: 'assertion';
    readonly matcherName: string;
    readonly expectedValue?: unknown;
    readonly passed: boolean;
    readonly message: string;
    readonly timestamp: string;
    readonly duration: number;
}
interface AppiumNetworkEntry {
    readonly url: string;
    readonly method: string;
    readonly status?: number;
    readonly requestHeaders?: Record<string, string>;
    readonly responseHeaders?: Record<string, string>;
    readonly requestBody?: string;
    readonly responseBody?: string;
    readonly duration?: number;
    readonly timestamp: string;
    readonly source: 'bidi' | 'performance' | 'safariNetwork';
    readonly mimeType?: string;
    readonly size?: number;
}
interface CollectedTestData {
    readonly commands: AppiumCommandStep[];
    readonly assertions: AppiumAssertionStep[];
    readonly deviceLogs: DeviceLogEntry[];
    readonly networkEntries: AppiumNetworkEntry[];
    readonly screenshotPaths: string[];
    readonly videoPath: string | null;
    readonly detectedCaps: DetectedCapabilities;
}

/**
 * Tracks WDIO v9 assertion results via beforeAssertion/afterAssertion hooks.
 */

interface AssertionHookParams {
    matcherName: string;
    expectedValue?: unknown;
    options: object;
}
interface AfterAssertionHookParams extends AssertionHookParams {
    result: {
        message: () => string;
        result: boolean;
    };
}

/**
 * WDIO Service: Runtime hooks for capturing device logs, commands,
 * assertions, screenshots, and network activity during test execution.
 */

type DriverLike = {
    getLogs(type: string): Promise<Array<{
        level: string;
        timestamp: number;
        message: string;
    }>>;
    getLogTypes(): Promise<string[]>;
    saveScreenshot(filepath: string): Promise<void>;
    execute(script: string, args?: unknown[]): Promise<unknown>;
    sessionSubscribe?(params: {
        events: string[];
    }): Promise<void>;
    on?(event: string, handler: (...args: unknown[]) => void): void;
    capabilities?: Record<string, unknown>;
    requestedCapabilities?: Record<string, unknown>;
};
declare class TestRelicService {
    private config;
    private detectedCaps;
    private driver;
    private deviceLogCollector;
    private consoleLogCollector;
    private networkInterceptor;
    private commandTracker;
    private assertionTracker;
    private screenshotCollector;
    /** Offsets into the collectors at the start of each test (for per-test slicing). */
    private testStartDeviceLogOffset;
    private testStartNetworkOffset;
    constructor(options?: Partial<AppiumReporterConfig>);
    before(capabilities: Record<string, unknown>, _specs: string[], browser: DriverLike): Promise<void>;
    after(): Promise<void>;
    beforeTest(): Promise<void>;
    afterTest(test: {
        title?: string;
        fullTitle?: string;
    } | unknown, _context: unknown, result: {
        passed: boolean;
    }): Promise<void>;
    beforeCommand(commandName: string, args: unknown[]): void;
    afterCommand(commandName: string, args: unknown[], result: unknown, error?: Error): void;
    beforeAssertion(params: AssertionHookParams): void;
    afterAssertion(params: AfterAssertionHookParams): void;
    getCollectedData(): CollectedTestData;
    dispose(): void;
}

export { type AppiumReporterConfig as A, type CollectedTestData as C, type DetectedCapabilities as D, type Platform as P, type ResolvedAppiumConfig as R, TestRelicService as T, type AppTestMode as a, type AppiumCommandStep as b, type AppiumAssertionStep as c, type DeviceLogEntry as d, type AppiumNetworkEntry as e, type CommandCategory as f, type DeviceLogSource as g };
