import { IRunViewProvider } from '@memberjunction/core';
import { MJCompanyIntegrationEntityMapEntity, MJCompanyIntegrationFieldMapEntity, MJCompanyIntegrationEntity, MJIntegrationEntity, MJIntegrationSourceTypeEntity, MJCompanyIntegrationSyncWatermarkEntity } from '@memberjunction/core-entities';
import { DiscoveredObjectResult, DiscoveredFieldResult, DiscoveryResult, ConnectionTestGraphQLResult, SchemaPreviewObjectInput, SchemaPreviewResult, DefaultConfigResult, ApplyAllResult } from '@memberjunction/graphql-dataprovider';
import * as i0 from "@angular/core";
/**
 * Simple row types for read-only data loaded via ResultType: 'simple'
 */
export interface IntegrationRow {
    ID: string;
    Name: string;
    IsActive: boolean | null;
    LastRunID: string | null;
    LastRunStartedAt: string | null;
    LastRunEndedAt: string | null;
    Company: string;
    Integration: string;
    DriverClassName: string | null;
}
export interface IntegrationRunRow {
    ID: string;
    CompanyIntegrationID: string;
    StartedAt: string | null;
    EndedAt: string | null;
    TotalRecords: number;
    Status: 'Failed' | 'In Progress' | 'Pending' | 'Success';
    ErrorLog: string | null;
    Integration: string;
    Company: string;
    RunByUser: string;
}
export interface SourceTypeRow {
    ID: string;
    Name: string;
    Description: string | null;
    DriverClass: string;
    IconClass: string | null;
    Status: 'Active' | 'Inactive';
}
export interface EntityMapRow {
    ID: string;
    CompanyIntegrationID: string;
    ExternalObjectName: string;
    ExternalObjectLabel: string | null;
    EntityID: string;
    SyncDirection: 'Bidirectional' | 'Pull' | 'Push';
    SyncEnabled: boolean;
    MatchStrategy: string | null;
    ConflictResolution: 'DestWins' | 'Manual' | 'MostRecent' | 'SourceWins';
    Priority: number;
    DeleteBehavior: 'DoNothing' | 'HardDelete' | 'SoftDelete';
    Status: 'Active' | 'Inactive';
    Entity: string;
}
export interface FieldMapRow {
    ID: string;
    EntityMapID: string;
    SourceFieldName: string;
    SourceFieldLabel: string | null;
    DestinationFieldName: string;
    DestinationFieldLabel: string | null;
    Direction: 'Both' | 'DestToSource' | 'SourceToDest';
    TransformPipeline: string | null;
    IsKeyField: boolean;
    IsRequired: boolean;
    DefaultValue: string | null;
    Priority: number;
    Status: 'Active' | 'Inactive';
}
/** Aggregated per-entity stats for a run (computed client-side from raw detail records) */
export interface RunDetailRow {
    EntityID: string;
    Entity: string;
    RecordsProcessed: number;
    RecordsCreated: number;
    RecordsUpdated: number;
    RecordsDeleted: number;
    RecordsErrored: number;
    RecordsSkipped: number;
}
/** Master integration definition (e.g., "HubSpot", "Salesforce") */
export interface IntegrationDefinitionRow {
    ID: string;
    Name: string;
    Description: string | null;
    ClassName: string | null;
    ImportPath: string | null;
    NavigationBaseURL: string | null;
    BatchMaxRequestCount: number;
    BatchRequestWaitTime: number;
    CredentialTypeID: string | null;
    SourceTypeID: string | null;
}
/** Aggregated summary for a single integration, used by the Control Tower UI */
export interface IntegrationSummary {
    Integration: MJCompanyIntegrationEntity;
    SourceType: MJIntegrationSourceTypeEntity | null;
    /** Icon from the Integration entity — FA class, URL, or base64 */
    Icon: string | null;
    LatestRun: IntegrationRunRow | null;
    RecentRuns: IntegrationRunRow[];
    StatusColor: 'green' | 'amber' | 'red' | 'gray';
    RelativeTime: string;
    TotalRecordsSyncedToday: number;
    TotalErrors: number;
    DurationMs: number | null;
}
/** KPI data for the Control Tower top strip */
export interface IntegrationKPIs {
    TotalIntegrations: number;
    ActiveSyncs: number;
    RecordsSyncedToday: number;
    ErrorRate: number;
    AverageSyncDurationMs: number | null;
}
/** Activity feed item for the Control Tower bottom section */
export interface ActivityFeedItem {
    RunID: string;
    IntegrationName: string;
    Status: 'Failed' | 'In Progress' | 'Pending' | 'Success';
    StatusColor: 'amber' | 'green' | 'red';
    StartedAt: string | null;
    RelativeTime: string;
    TotalRecords: number;
    RunByUser: string;
}
/** Daily record count for the bar chart */
export interface DailyRecordCount {
    Date: string;
    Label: string;
    Records: number;
}
/** Schedule row for the Schedules component (includes new scheduling fields) */
export interface ScheduleRow {
    ID: string;
    Name: string;
    Integration: string;
    Company: string;
    IsActive: boolean | null;
    ScheduleEnabled: boolean;
    ScheduleType: 'Manual' | 'Interval' | 'Cron';
    ScheduleIntervalMinutes: number | null;
    CronExpression: string | null;
    NextScheduledRunAt: string | null;
    LastScheduledRunAt: string | null;
    IsLocked: boolean;
    LockedAt: string | null;
}
/** Watermark row for the Activity detail panel */
export interface WatermarkRow {
    ID: string;
    EntityMapID: string;
    WatermarkType: string;
    WatermarkValue: string | null;
    Direction: 'Pull' | 'Push';
    EntityMap: string;
}
/**
 * Resolve an integration icon. Checks the entity's Icon field first (supports
 * Font Awesome classes, URLs, and base64), then falls back to pattern-based
 * name matching, then to a generic plug icon.
 */
export declare function ResolveIntegrationIcon(name: string, entityIcon?: string | null): string;
/**
 * Check if the Icon field contains an image URL or base64 data URI
 * (as opposed to a Font Awesome class). Used by templates to decide
 * whether to render an <i> or an <img>.
 */
export declare function IsImageIcon(icon: string | null | undefined): boolean;
export declare class IntegrationDataService {
    LoadIntegrationSummaries(provider?: IRunViewProvider | null): Promise<IntegrationSummary[]>;
    LoadEntityMaps(companyIntegrationID: string, _provider?: IRunViewProvider | null): Promise<MJCompanyIntegrationEntityMapEntity[]>;
    LoadFieldMaps(entityMapID: string, _provider?: IRunViewProvider | null): Promise<MJCompanyIntegrationFieldMapEntity[]>;
    LoadRunHistory(companyIntegrationID: string, limit?: number, provider?: IRunViewProvider | null): Promise<IntegrationRunRow[]>;
    LoadRunDetails(runID: string, provider?: IRunViewProvider | null): Promise<RunDetailRow[]>;
    /** Aggregate raw per-record detail rows into per-entity summary rows */
    private aggregateRunDetails;
    LoadIntegrationDefinitions(_provider?: IRunViewProvider | null): Promise<MJIntegrationEntity[]>;
    LoadSourceTypes(_provider?: IRunViewProvider | null): Promise<MJIntegrationSourceTypeEntity[]>;
    LoadRecentRuns(limit?: number, provider?: IRunViewProvider | null): Promise<ActivityFeedItem[]>;
    LoadDailyRecordCounts(days?: number, provider?: IRunViewProvider | null): Promise<DailyRecordCount[]>;
    ComputeKPIs(summaries: IntegrationSummary[]): IntegrationKPIs;
    FormatDuration(ms: number | null): string;
    ComputeRelativeTime(dateStr: string | null): string;
    CreateEntityMap(params: {
        CompanyIntegrationID: string;
        ExternalObjectName: string;
        ExternalObjectLabel?: string;
        EntityID: string;
        SyncDirection?: 'Pull' | 'Push' | 'Bidirectional';
        ConflictResolution?: 'SourceWins' | 'DestWins' | 'MostRecent' | 'Manual';
        Priority?: number;
        DeleteBehavior?: 'SoftDelete' | 'DoNothing' | 'HardDelete';
    }): Promise<MJCompanyIntegrationEntityMapEntity | null>;
    DeleteEntityMap(entityMapID: string): Promise<boolean>;
    ToggleEntityMapEnabled(entityMapID: string, enabled: boolean): Promise<boolean>;
    CreateFieldMap(params: {
        EntityMapID: string;
        SourceFieldName: string;
        SourceFieldLabel?: string;
        DestinationFieldName: string;
        DestinationFieldLabel?: string;
        IsKeyField?: boolean;
        IsRequired?: boolean;
        Direction?: 'SourceToDest' | 'DestToSource' | 'Both';
        TransformPipeline?: string | null;
        Priority?: number;
    }): Promise<MJCompanyIntegrationFieldMapEntity | null>;
    DeleteFieldMap(fieldMapID: string): Promise<boolean>;
    UpdateFieldMap(fieldMapID: string, updates: {
        SourceFieldName?: string;
        DestinationFieldName?: string;
        IsKeyField?: boolean;
        IsRequired?: boolean;
        Direction?: 'SourceToDest' | 'DestToSource' | 'Both';
        Status?: 'Active' | 'Inactive';
        TransformPipeline?: string | null;
    }): Promise<boolean>;
    /** Load available MJ entities for mapping target selection */
    LoadMJEntities(_provider?: IRunViewProvider | null): Promise<Array<{
        ID: string;
        Name: string;
    }>>;
    /** Load entity fields for a given entity (for field mapping destination picker) */
    LoadEntityFields(entityID: string, _provider?: IRunViewProvider | null): Promise<Array<{
        ID: string;
        Name: string;
        Type: string;
        IsRequired: boolean;
    }>>;
    /** Discover external objects available for a company integration */
    DiscoverObjects(companyIntegrationID: string): Promise<DiscoveryResult<DiscoveredObjectResult[]>>;
    /** Discover fields on a specific external object */
    DiscoverFields(companyIntegrationID: string, objectName: string): Promise<DiscoveryResult<DiscoveredFieldResult[]>>;
    /** Generate DDL preview for creating tables from discovered objects */
    SchemaPreview(companyIntegrationID: string, objects: SchemaPreviewObjectInput[], platform?: string): Promise<SchemaPreviewResult>;
    /** Execute the full RSU pipeline for an integration entity map */
    RunSchemaPipeline(companyIntegrationID: string, entityMap: EntityMapRow): Promise<{
        Success: boolean;
        Message?: string;
    }>;
    /** Execute the RSU pipeline for new entity maps — introspects, generates DDL, runs full pipeline */
    ApplySchemaForNewMaps(companyIntegrationID: string, objects: SchemaPreviewObjectInput[]): Promise<{
        Success: boolean;
        Message: string;
    }>;
    /** Batch apply schema for multiple connectors — one RSU pipeline run */
    ApplySchemaBatch(items: Array<{
        CompanyIntegrationID: string;
        Objects: SchemaPreviewObjectInput[];
    }>): Promise<{
        Success: boolean;
        Message: string;
        Items?: Array<{
            CompanyIntegrationID: string;
            Success: boolean;
            Message: string;
            Warnings?: string[];
        }>;
        Steps?: Array<{
            Name: string;
            Status: string;
            DurationMs: number;
            Message: string;
        }>;
        GitCommitSuccess?: boolean;
        APIRestarted?: boolean;
    }>;
    /** Full automatic "Apply All" flow: pipeline + entity maps + field maps + sync */
    ApplyAll(companyIntegrationID: string, sourceObjectNames: string[]): Promise<ApplyAllResult>;
    /** Start a sync for a company integration */
    StartSync(companyIntegrationID: string): Promise<{
        Success: boolean;
        Message: string;
        RunID?: string;
    }>;
    /** Get the connector's default configuration for quick setup */
    GetDefaultConfig(companyIntegrationID: string): Promise<DefaultConfigResult>;
    /** Test connection to the external system */
    TestConnection(companyIntegrationID: string): Promise<ConnectionTestGraphQLResult>;
    /** Preview source data from the external system via connector's FetchChanges */
    PreviewSourceData(companyIntegrationID: string, objectName: string, limit?: number): Promise<Array<Record<string, string | number | boolean | null>>>;
    /** Preview destination data by loading a few records from the target entity */
    PreviewDestinationData(entityID: string, limit?: number, provider?: IRunViewProvider | null): Promise<Array<Record<string, string | number | boolean | null>>>;
    /** Get a count of records in the destination MJ entity */
    GetDestinationRecordCount(entityID: string, provider?: IRunViewProvider | null): Promise<number>;
    /** Get the most recent run that touched a given entity */
    GetLastSyncForEntity(companyIntegrationID: string, entityID: string, provider?: IRunViewProvider | null): Promise<{
        StartedAt: string | null;
        EndedAt: string | null;
        Status: string;
        TotalRecords: number;
    } | null>;
    /** Run an integration sync via the "Run Integration Sync" action */
    RunSync(companyIntegrationID: string): Promise<{
        Success: boolean;
        Message: string;
    }>;
    /** Load schedule data for all company integrations (includes new scheduling fields) */
    LoadSchedules(_provider?: IRunViewProvider | null): Promise<MJCompanyIntegrationEntity[]>;
    /** Load sync watermarks for a specific company integration's entity maps */
    LoadWatermarks(companyIntegrationID: string, _provider?: IRunViewProvider | null): Promise<MJCompanyIntegrationSyncWatermarkEntity[]>;
    /**
     * Auto-map all entities in a given schema to a company integration.
     * For each entity in the schema that doesn't already have an entity map,
     * creates an entity map (ExternalObjectName = BaseTable) and 1:1 field maps
     * for every non-system column. Returns the count of maps created.
     */
    AutoMapSchema(companyIntegrationID: string, schemaName: string, direction?: 'Pull' | 'Push' | 'Bidirectional'): Promise<{
        EntityMapsCreated: number;
        FieldMapsCreated: number;
        Errors: string[];
    }>;
    /** Load available schemas (for auto-map schema picker) */
    LoadSchemas(): string[];
    /** Load entity map count per company integration (used by Overview cards) */
    LoadEntityMapCounts(_provider?: IRunViewProvider | null): Promise<Map<string, number>>;
    private lookupActionID;
    private getIntegrationClient;
    private createRunView;
    private buildSummary;
    private resolveSourceType;
    private buildActivityFeedItem;
    private runStatusColor;
    private computeRecordsSyncedToday;
    private computeDuration;
    private aggregateDailyCounts;
    private computeStatusColor;
    private isStale;
    private computeRelativeTime;
    static ɵfac: i0.ɵɵFactoryDeclaration<IntegrationDataService, never>;
    static ɵprov: i0.ɵɵInjectableDeclaration<IntegrationDataService>;
}
//# sourceMappingURL=integration-data.service.d.ts.map