import { Observable } from 'rxjs';
import { IMetadataProvider } from '@memberjunction/core';
import * as i0 from "@angular/core";
export interface TestingDashboardKPIs {
    totalTestsActive: number;
    passRateThisMonth: number;
    totalCostThisMonth: number;
    averageDuration: number;
    testsPendingReview: number;
    totalTestRuns: number;
    failedTests: number;
    skippedTests: number;
    passRateTrend: number;
}
export interface TestRunSummary {
    id: string;
    testId: string;
    testName: string;
    suiteName: string;
    testType: string;
    status: 'Passed' | 'Failed' | 'Skipped' | 'Error' | 'Running' | 'Timeout';
    score: number;
    duration: number;
    cost: number;
    runDateTime: Date;
    targetType: string;
    targetLogID: string;
}
export interface SuiteHierarchyNode {
    id: string;
    name: string;
    parentID: string | null;
    level: number;
    children: SuiteHierarchyNode[];
    testCount: number;
    passRate: number;
    totalCost: number;
    averageScore: number;
    expanded?: boolean;
}
export interface VersionMetrics {
    version: string;
    gitCommit: string;
    agentVersion: string;
    runDate: Date;
    totalTests: number;
    passRate: number;
    averageScore: number;
    totalCost: number;
    averageDuration: number;
    newFailures: number;
    newPasses: number;
}
export interface TestTrendData {
    timestamp: Date;
    totalRuns: number;
    passed: number;
    failed: number;
    skipped: number;
    errors: number;
    averageScore: number;
    totalCost: number;
    averageDuration: number;
}
export interface FeedbackPending {
    testRunID: string;
    testName: string;
    automatedScore: number;
    automatedStatus: string;
    runDateTime: Date;
    reason: 'no-feedback' | 'high-score-failed' | 'low-score-passed';
}
export interface TestAnalytics {
    topFailingTests: Array<{
        testName: string;
        failureCount: number;
        failureRate: number;
    }>;
    mostExpensiveTests: Array<{
        testName: string;
        totalCost: number;
        avgCost: number;
    }>;
    slowestTests: Array<{
        testName: string;
        avgDuration: number;
        maxDuration: number;
    }>;
    costByType: Array<{
        testType: string;
        totalCost: number;
        testCount: number;
    }>;
    costBySuite: Array<{
        suiteName: string;
        totalCost: number;
        testCount: number;
    }>;
    passingRateByType: Array<{
        testType: string;
        passRate: number;
        totalTests: number;
    }>;
}
export interface FeedbackStats {
    totalFeedback: number;
    reviewedCount: number;
    avgRating: number;
    agreementRate: number;
    disagreementRate: number;
    accuracyRate: number;
}
/**
 * Extended test run summary with human feedback data included
 */
export interface TestRunWithFeedbackSummary extends TestRunSummary {
    humanRating: number | null;
    humanIsCorrect: boolean | null;
    humanComments: string | null;
    hasHumanFeedback: boolean;
    feedbackId: string | null;
    passedChecks: number | null;
    failedChecks: number | null;
    totalChecks: number | null;
}
/**
 * Aggregated evaluation metrics
 */
export interface EvaluationSummaryMetrics {
    totalRuns: number;
    execCompletedCount: number;
    execErrorCount: number;
    execSuccessRate: number;
    humanReviewedCount: number;
    humanPendingCount: number;
    humanAvgRating: number;
    humanCorrectRate: number;
    autoEvaluatedCount: number;
    autoAvgScore: number;
    autoPassRate: number;
    agreementRate: number;
}
/**
 * A filter intent published by the AI agent (via the Testing dashboard's client
 * tools) for the Runs surface to apply. Both fields are optional — only the
 * provided ones are applied. This decouples the agent-actionable Runs filters
 * from any specific component instance: the agent sets an intent on this shared
 * root service, and the (possibly not-yet-mounted) Runs component consumes it.
 */
export interface RunsFilterIntent {
    status?: 'all' | 'running' | 'passed' | 'failed' | 'error';
    searchText?: string;
}
/**
 * A run-selection intent published by the AI agent (via the Testing dashboard's
 * `SelectTestRun` client tool) for the Runs surface to act on. The Runs component
 * owns the actual `SelectedRun` UI state (per the data-down/events-up Angular
 * convention), so the agent publishes the target run ID here and the (possibly
 * not-yet-mounted) Runs component consumes it when it mounts / when it changes.
 *
 * `open` distinguishes "open the detail panel for this run" (select) from
 * "open the run's record in the entity workspace" — both are read-only,
 * navigational affordances (no test execution side effects).
 */
export interface RunSelectionIntent {
    /** Target test-run ID to select (and optionally open). */
    runId: string;
    /** When true, also open the run's record in the entity workspace. */
    open?: boolean;
    /** Monotonic nonce so re-selecting the SAME run id still replays the intent. */
    nonce: number;
}
export declare class TestingInstrumentationService {
    private readonly _dateRange$;
    /**
     * Agent-driven filter intents for the Runs surface. Published by the Testing
     * dashboard's client tools; consumed by the Runs component. Starts as null
     * (no pending intent).
     */
    private readonly _runsFilterIntent$;
    /** Observable of agent-driven Runs filter intents. */
    readonly runsFilterIntent$: Observable<RunsFilterIntent | null>;
    /** Publish an agent-driven filter intent for the Runs surface to apply. */
    setRunsFilterIntent(intent: RunsFilterIntent): void;
    /**
     * Agent-driven run-SELECTION intents for the Runs surface. Published by the
     * Testing dashboard's `SelectTestRun` / open-run client tools; consumed by the
     * Runs component (which owns the actual {@link TestRunWithFeedbackSummary}
     * `SelectedRun` UI state). Starts as null (no pending intent). A monotonic
     * nonce on each intent lets the Runs component replay the SAME run id again
     * (re-select / re-open) even though the BehaviorSubject would otherwise
     * de-duplicate identical references.
     */
    private readonly _runSelectionIntent$;
    /** Observable of agent-driven run-selection intents. */
    readonly runSelectionIntent$: Observable<RunSelectionIntent | null>;
    /** Monotonic source for {@link RunSelectionIntent.nonce}. */
    private _runSelectionNonce;
    /**
     * Publish an agent-driven run-selection intent for the Runs surface to act on.
     * Assigns the next monotonic nonce so re-selecting the same run id still
     * replays. Returns the published intent (with its assigned nonce).
     */
    setRunSelectionIntent(runId: string, open?: boolean): RunSelectionIntent;
    private readonly _suiteFilter$;
    private readonly _testTypeFilter$;
    private readonly _refreshTrigger$;
    private readonly _isLoading$;
    private _provider;
    /** Set the metadata provider this service should use. Components should call this after injection. */
    set Provider(value: IMetadataProvider | null);
    get Provider(): IMetadataProvider;
    private get metadata();
    readonly isLoading$: Observable<boolean>;
    readonly dateRange$: Observable<{
        start: Date;
        end: Date;
    }>;
    constructor();
    readonly kpis$: Observable<TestingDashboardKPIs>;
    readonly testRuns$: Observable<TestRunSummary[]>;
    readonly suiteHierarchy$: Observable<SuiteHierarchyNode[]>;
    readonly trends$: Observable<TestTrendData[]>;
    readonly analytics$: Observable<TestAnalytics>;
    readonly pendingFeedback$: Observable<FeedbackPending[]>;
    readonly feedbackStats$: Observable<FeedbackStats>;
    /**
     * Test runs with feedback data joined - for evaluation display
     */
    readonly testRunsWithFeedback$: Observable<TestRunWithFeedbackSummary[]>;
    /**
     * Aggregated evaluation metrics from test runs with feedback
     */
    readonly evaluationMetrics$: Observable<EvaluationSummaryMetrics>;
    private checkLoadingComplete;
    setDateRange(start: Date, end: Date): void;
    /**
     * Set the active date range from a named time range. Centralizes the
     * range-to-dates computation so both the Runs surface UI and the agent's
     * `FilterTestsByTimeRange` tool resolve identical windows.
     */
    setDateRangeByName(range: 'today' | 'week' | 'month' | '90days'): void;
    setSuiteFilter(suiteId: string | null): void;
    setTestTypeFilter(typeId: string | null): void;
    refresh(): void;
    private loadKPIs;
    private countTestsPendingReview;
    private loadTestRuns;
    private loadSuiteHierarchy;
    private loadTrends;
    private loadAnalytics;
    private loadPendingFeedback;
    private loadFeedbackStats;
    submitFeedback(testRunID: string, rating: number, isCorrect: boolean, comments: string): Promise<boolean>;
    getVersionMetrics(): Promise<VersionMetrics[]>;
    private createTimeBuckets;
    private getBucketSize;
    /**
     * Load test runs with feedback data joined for evaluation display
     */
    private loadTestRunsWithFeedback;
    /**
     * Calculate aggregated evaluation metrics from test runs with feedback
     */
    private calculateEvaluationMetrics;
    static ɵfac: i0.ɵɵFactoryDeclaration<TestingInstrumentationService, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<TestingInstrumentationService>;
}
//# sourceMappingURL=testing-instrumentation.service.d.ts.map