import { OnInit } from '@angular/core';
import { BaseResourceComponent } from '@memberjunction/ng-shared';
import { ResourceData, MJIntegrationObjectFieldEntity, MJCompanyIntegrationEntity } from '@memberjunction/core-entities';
import { IntegrationRunRow, EntityMapRow, FieldMapRow, RunDetailRow } from '../../services/integration-data.service';
import * as i0 from "@angular/core";
/** Source object from integration metadata */
interface DiscoveredObject {
    Name: string;
    Label: string;
    Category: string;
    Description: string;
    SupportsIncrementalSync: boolean;
    SupportsWrite: boolean;
}
/** Target MJ entity for the picker */
interface MJEntityOption {
    ID: string;
    Name: string;
}
/** MJ entity field for field mapping destination picker */
interface MJFieldOption {
    ID: string;
    Name: string;
    Type: string;
    IsRequired: boolean;
}
/** Transform type for the pipeline builder */
type TransformType = 'direct' | 'regex' | 'split' | 'combine' | 'lookup' | 'format' | 'coerce' | 'substring' | 'custom';
/** A single step in a transform pipeline */
interface TransformStepUI {
    Type: TransformType;
    Config: Record<string, unknown>;
    OnError: 'Skip' | 'Null' | 'Fail';
}
/** Editable field map row used in the center panel */
interface EditableFieldMap {
    ID: string | null;
    SourceFieldName: string;
    SourceFieldLabel: string;
    SourceFieldType: string;
    DestinationFieldName: string;
    DestinationFieldLabel: string;
    IsKeyField: boolean;
    IsRequired: boolean;
    Direction: 'Both' | 'DestToSource' | 'SourceToDest';
    Status: 'Active' | 'Inactive';
    IsNew: boolean;
    IsDirty: boolean;
    IsSourcePK: boolean;
    IsSourceRequired: boolean;
    IsSourceReadOnly: boolean;
    TransformPipeline: TransformStepUI[];
    ShowTransformEditor: boolean;
}
/** Pending entity map — entity hasn't been created yet */
interface PendingMapEntry {
    LocalID: string;
    SourceObjectName: string;
    SourceObjectLabel: string;
    SchemaName: string;
    TableName: string;
    EntityName: string;
    SyncDirection: 'Bidirectional' | 'Pull' | 'Push';
    SourceFields: MJIntegrationObjectFieldEntity[];
    DDLContent: string;
    CreatedAt: Date;
}
/** Combined list item for left panel — merges real and pending maps */
interface MapListItem {
    ID: string;
    SourceName: string;
    TargetName: string;
    SyncDirection: string;
    SyncEnabled: boolean;
    IsPending: boolean;
    RealMap: EntityMapRow | null;
    PendingMap: PendingMapEntry | null;
}
type TargetMode = 'existing' | 'new';
/** Data preview row — key/value record */
type PreviewRecord = Record<string, string | number | boolean | null>;
export declare class MappingWorkspaceComponent extends BaseResourceComponent implements OnInit {
    Integrations: MJCompanyIntegrationEntity[];
    EntityMaps: EntityMapRow[];
    FieldMaps: FieldMapRow[];
    RunEntityDetails: RunDetailRow[];
    LatestRun: IntegrationRunRow | null;
    SelectedIntegrationID: string;
    SelectedMapID: string | null;
    EntityMapSearchText: string;
    IsLoadingIntegrations: boolean;
    IsLoadingEntityMaps: boolean;
    IsLoadingFieldMaps: boolean;
    IsLoadingRunDetails: boolean;
    ShowAddPanel: boolean;
    TargetMode: TargetMode;
    DiscoveredObjects: DiscoveredObject[];
    IsDiscoveringObjects: boolean;
    DiscoverError: string;
    SelectedSourceObjectName: string;
    MJEntities: MJEntityOption[];
    IsLoadingEntities: boolean;
    SelectedEntityID: string | null;
    NewEntitySchemaName: string;
    NewEntityTableName: string;
    NewEntityName: string;
    DBSchemas: string[];
    AddSyncDirection: 'Bidirectional' | 'Pull' | 'Push';
    IsSavingEntityMap: boolean;
    PendingMaps: PendingMapEntry[];
    IsGeneratingDDL: boolean;
    DDLPreviewContent: string;
    DDLPreviewError: string;
    EditableFields: EditableFieldMap[];
    DestinationFields: MJFieldOption[];
    IsLoadingDestFields: boolean;
    IsSavingFields: boolean;
    AutoMapCount: number;
    ShowAutoMapBanner: boolean;
    SourceFields: MJIntegrationObjectFieldEntity[];
    IsLoadingSourceFields: boolean;
    SourcePreviewData: PreviewRecord[];
    DestPreviewData: PreviewRecord[];
    IsLoadingSourcePreview: boolean;
    IsLoadingDestPreview: boolean;
    ShowSourcePreview: boolean;
    ShowDestPreview: boolean;
    private dataService;
    private cdr;
    private discoverCache;
    private pendingCounter;
    ngOnInit(): Promise<void>;
    /** Merged list of real entity maps + pending maps, for the left panel */
    get AllMaps(): MapListItem[];
    get FilteredMaps(): MapListItem[];
    get SelectedMap(): MapListItem | null;
    get SelectedEntityMap(): EntityMapRow | null;
    get SelectedPendingMap(): PendingMapEntry | null;
    get HasDirtyFields(): boolean;
    get ActiveEditableFields(): EditableFieldMap[];
    get IsAddFormValid(): boolean;
    /** Auto-suggest table/entity names from selected source object */
    get SuggestedTableName(): string;
    get SuggestedEntityName(): string;
    LoadIntegrations(): Promise<void>;
    OnIntegrationChange(integrationID: string): Promise<void>;
    private LoadEntityMapsForIntegration;
    private LoadLatestRunForIntegration;
    /** Load source objects from IntegrationObject metadata via engine (cached per integration) */
    private DiscoverSourceObjects;
    OnMapSelect(item: MapListItem): Promise<void>;
    IsSelectedMap(id: string): boolean;
    OnToggleEntityMap(em: EntityMapRow): Promise<void>;
    OnDeleteMap(item: MapListItem, event: Event): Promise<void>;
    OpenAddPanel(): void;
    CloseAddPanel(): void;
    SetTargetMode(mode: TargetMode): void;
    OnSourceObjectChange(objectName: string): void;
    OnSchemaNameChange(): void;
    SaveAddMap(): Promise<void>;
    private SaveExistingEntityMap;
    private SaveNewEntityMap;
    private ResetAddForm;
    private EnsureEntitiesLoaded;
    private LoadDBSchemas;
    PreviewDDL(): Promise<void>;
    private ToEditableField;
    private ParseTransformPipeline;
    SerializeTransformPipeline(steps: TransformStepUI[]): string | null;
    private LoadDestinationFields;
    /** Auto-generate field mappings by matching source fields to destination by name */
    AutoGenerateFieldMappings(entityMap: EntityMapRow): Promise<void>;
    private MatchFieldsByName;
    /** Validation: count fields missing destination mapping */
    get UnmappedRequiredCount(): number;
    /** Validation: check if at least one key field is configured */
    get HasKeyField(): boolean;
    /** Validation: overall mapping readiness */
    get MappingValidation(): {
        IsValid: boolean;
        Warnings: string[];
    };
    /** Re-run auto-mapping for the currently selected entity map */
    RerunAutoMap(): Promise<void>;
    OnFieldChanged(field: EditableFieldMap): void;
    AddFieldMapping(): void;
    RemoveFieldMapping(index: number): void;
    SaveFieldMappings(): Promise<void>;
    DismissAutoMapBanner(): void;
    /** Available transform types with display metadata */
    readonly TransformTypes: Array<{
        Value: TransformType;
        Label: string;
        Icon: string;
        Description: string;
    }>;
    ToggleTransformEditor(field: EditableFieldMap): void;
    AddTransformStep(field: EditableFieldMap): void;
    RemoveTransformStep(field: EditableFieldMap, stepIndex: number): void;
    OnTransformTypeChange(field: EditableFieldMap, step: TransformStepUI, newType: TransformType): void;
    OnTransformConfigChange(field: EditableFieldMap): void;
    private GetDefaultConfigForType;
    GetTransformLabel(type: TransformType): string;
    GetTransformIcon(type: TransformType): string;
    /** For combine transforms: get available source field names */
    GetAvailableSourceFields(): string[];
    /**
     * Resolve source fields from IntegrationObjectField metadata via IntegrationEngineBase.
     * CompanyIntegrationID → Integration → IntegrationObject → IntegrationObjectFields.
     */
    private resolveSourceFieldsFromMetadata;
    /** For lookup transforms: add a new key-value pair */
    AddLookupEntry(config: Record<string, unknown>): void;
    GetLookupEntries(config: Record<string, unknown>): Array<{
        key: string;
        value: string;
    }>;
    UpdateLookupEntry(config: Record<string, unknown>, oldKey: string, newKey: string, newValue: string): void;
    RemoveLookupEntry(config: Record<string, unknown>, key: string): void;
    /** For combine transforms: toggle a source field */
    ToggleCombineField(config: Record<string, unknown>, fieldName: string): void;
    IsCombineFieldSelected(config: Record<string, unknown>, fieldName: string): boolean;
    LoadSourcePreview(): Promise<void>;
    LoadDestPreview(): Promise<void>;
    CloseSourcePreview(): void;
    CloseDestPreview(): void;
    private CloseAllPreviews;
    GetPreviewColumns(data: PreviewRecord[]): string[];
    FormatPreviewValue(value: string | number | boolean | null): string;
    CopyDDLToClipboard(ddl: string): void;
    GetPendingStepStatus(pendingMap: PendingMapEntry, step: number): 'current' | 'done' | 'future';
    get RunStatusColor(): string;
    FormatDate(dateStr: string | null): string;
    GetResourceDisplayName(_data: ResourceData): Promise<string>;
    GetResourceIconClass(_data: ResourceData): Promise<string>;
    static ɵfac: i0.ɵɵFactoryDeclaration<MappingWorkspaceComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<MappingWorkspaceComponent, "app-mapping-workspace", never, {}, {}, never, never, false, never>;
}
export declare function LoadMappingWorkspace(): void;
export {};
//# sourceMappingURL=mapping-workspace.component.d.ts.map