import { BaseEngine, IMetadataProvider, UserInfo } from '@memberjunction/core';
import { MJRecordProcessEntity, MJProcessRunEntity } from '@memberjunction/core-entities';
import type { Observable } from 'rxjs';
/**
 * Name of the seeded `MJ: Record Process Categories` row that marks a Record
 * Process as a Feature Pipeline. Authored in
 * `metadata/record-process-categories/.record-process-categories.json` and pushed
 * with `mj sync`. Mirrors `FEATURE_PIPELINE_CATEGORY_NAME` in the server-side
 * `@memberjunction/predictive-studio` engine — kept in sync by value (the two
 * packages don't share a dependency, so the constant is intentionally duplicated
 * rather than re-exported across the package boundary).
 */
export declare const FEATURE_PIPELINE_CATEGORY_NAME = "Feature Pipeline";
/** Normalized last-run status for a Feature Pipeline, derived from the most recent Process Run. */
export type FeaturePipelineRunStatus = 'Never' | 'Running' | 'Completed' | 'Failed' | 'Cancelled';
/**
 * UI-facing summary of one Feature Pipeline: what it is, the entity it writes to,
 * the attribute it produces, and last-run / freshness. Built purely from the
 * cached Record Process + Process Run entities by {@link FeaturePipelineEngine.GetSummaries}.
 */
export interface FeaturePipelineSummary {
    /** The underlying `MJ: Record Processes` id (also the `RunFeaturePipeline` `featurePipelineID`). */
    ID: string;
    /** Display name (the Record Process name). */
    Name: string;
    /** Optional description. */
    Description: string | null;
    /** Record Process lifecycle status. */
    Status: 'Active' | 'Disabled' | 'Draft';
    /**
     * The per-record work the pipeline performs. Derived from the entity's `WorkType` so it tracks
     * the CodeGen-generated union (sourced from the `CK_RecordProcess_WorkType` CHECK constraint) and
     * never drifts as work types are added (e.g. `'ML Model'`).
     */
    WorkType: MJRecordProcessEntity['WorkType'];
    /** Id of the target entity whose records the pipeline derives features for. */
    TargetEntityID: string;
    /** Display name of the target entity. */
    TargetEntity: string;
    /** Best-effort attribute written back, parsed from the Record Process `OutputMapping`. */
    OutputAttribute: string | null;
    /** Whether the pipeline can be run on demand (the Run button is enabled). */
    OnDemandEnabled: boolean;
    /** Whether the pipeline runs on a cron schedule. */
    ScheduleEnabled: boolean;
    /** Timestamp of the most recent run (start time, falling back to end time), or null. */
    LastRunAt: Date | null;
    /** Normalized status of the most recent run. */
    LastRunStatus: FeaturePipelineRunStatus;
    /** Id of the most recent `MJ: Process Runs` row, or null. */
    LastRunProcessRunID: string | null;
    /** Records processed in the most recent run, or null. */
    LastRunProcessed: number | null;
    /** Records whose features were written in the most recent run, or null. */
    LastRunSuccess: number | null;
    /** Records that errored in the most recent run, or null. */
    LastRunErrors: number | null;
}
/**
 * **FeaturePipelineEngine** (Knowledge Hub, Angular) — the discovery + monitoring
 * cache for Feature Pipelines (Predictive Studio SP6).
 *
 * A Feature Pipeline has no dedicated entity: it IS an `MJ: Record Processes` row
 * categorized into the seeded {@link FEATURE_PIPELINE_CATEGORY_NAME} category. This
 * engine caches those rows (plus the recent `MJ: Process Runs` headers) so the KH
 * UI can list "what feature pipelines exist, what entity each writes to, and when
 * each last ran" — reactively, via the canonical MJ BaseEngine pattern (`Config()`
 * declaring `BaseEnginePropertyConfig[]`, lazy-loaded, `ObserveProperty`
 * reactivity for free).
 *
 * The freshness/projection logic is a pure static function ({@link BuildSummaries})
 * so it can be exercised without a provider, and it intentionally mirrors the
 * server-side `@memberjunction/predictive-studio` engine of the same name (the two
 * don't share a dependency).
 */
export declare class FeaturePipelineEngine extends BaseEngine<FeaturePipelineEngine> {
    /** Singleton accessor for the default provider — never `new` this directly. */
    static get Instance(): FeaturePipelineEngine;
    private _RecordProcesses;
    private _ProcessRuns;
    /**
     * Lazy-load the Record Process + recent Process Run caches. Safe to call from
     * every entry point — a no-op when already loaded (unless `forceRefresh`).
     * Process Runs are ordered newest-first so the most recent run per pipeline is
     * the first match.
     */
    Config(forceRefresh?: boolean, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<void>;
    /** Every cached Record Process categorized as a Feature Pipeline. */
    get Pipelines(): MJRecordProcessEntity[];
    /** All cached Process Run headers (newest first; all entities — callers filter). */
    get Runs(): MJProcessRunEntity[];
    /** Reactive stream of the raw Record Processes — re-emits on any save/delete/remote-invalidate. */
    get Pipelines$(): Observable<MJRecordProcessEntity[]>;
    /** Reactive stream of the Process Run headers. */
    get Runs$(): Observable<MJProcessRunEntity[]>;
    /** Build the UI summaries for every feature pipeline from the loaded caches. */
    GetSummaries(): FeaturePipelineSummary[];
    /**
     * Pure, side-effect-free summary builder — used by {@link GetSummaries} and by
     * unit tests (which pass in-memory arrays, no provider).
     */
    static BuildSummaries(pipelines: ReadonlyArray<MJRecordProcessEntity>, runs: ReadonlyArray<MJProcessRunEntity>): FeaturePipelineSummary[];
    /** Whether a Record Process belongs to the seeded Feature Pipeline category. */
    private static isFeaturePipeline;
    /** Project one pipeline + the run set into a {@link FeaturePipelineSummary}. */
    private static buildSummary;
    /** Newest run for a pipeline id, scanning by StartTime/EndTime/createdAt regardless of input order. */
    private static newestRun;
    /** Normalize a Process Run status into the small union the UI renders. `undefined` → `'Never'`. */
    private static mapRunStatus;
    /**
     * Best-effort attribute the pipeline writes, parsed from the Record Process
     * `OutputMapping` JSON. Probes the common shapes (`field` / `targetField` /
     * `attribute`, or a `fields` array / object) and returns null otherwise. Never
     * throws on malformed JSON.
     */
    private static deriveOutputAttribute;
    /** Collect field names from either an object map or an array of names. */
    private static fieldNamesFrom;
}
//# sourceMappingURL=feature-pipeline.engine.d.ts.map