import { default as default_2 } from 'react';
import { NiceBaseProps } from '@nice2dev/ui-core';

declare type BranchStatus = 'active' | 'stale' | 'merged' | 'deleted' | 'syncing' | 'conflict';

/** Diff change types */
declare type ChangeType = 'added' | 'modified' | 'deleted' | 'renamed' | 'unchanged';

export declare interface ConflictResolution {
    conflictId: string;
    strategy: MergeStrategy;
    fieldResolutions: FieldResolutionMap;
}

declare interface ConflictResolutionChoice {
    conflictId: string;
    strategy: MergeStrategy;
    customValue?: unknown;
}

declare type ConflictType = 'concurrent-update' | 'delete-update' | 'update-delete' | 'constraint-violation' | 'unique-key-conflict' | 'foreign-key-missing' | 'type-mismatch' | 'schema-change';

declare interface CreateSnapshotConfig {
    name: string;
    description?: string;
    tables?: string[];
    tags?: string[];
}

declare interface DataBranch extends VersioningBranch {
    type: 'data';
    environment: DataEnvironment;
    tenant: string;
    sourceSnapshot?: string;
    syncSchedule?: SyncSchedule;
    tables?: string[];
    size?: {
        records: number;
        bytes: number;
    };
}

declare interface DataBranchCommit {
    id: string;
    shortId: string;
    message: string;
    description?: string;
    branch: string;
    environment: DataEnvironment;
    author: {
        id: string;
        name: string;
    };
    timestamp: Date;
    parents: string[];
    isMerge: boolean;
    isSnapshot: boolean;
    stats: {
        tables: number;
        recordsAdded: number;
        recordsModified: number;
        recordsDeleted: number;
    };
    tags?: string[];
}

export declare interface DataConflict {
    id: string;
    table: string;
    tableName: string;
    recordId: string;
    recordLabel?: string;
    type: ConflictType;
    severity: 'low' | 'medium' | 'high' | 'critical';
    fields: FieldConflict[];
    metadata?: {
        sourceModifiedAt?: Date;
        sourceModifiedBy?: string;
        targetModifiedAt?: Date;
        targetModifiedBy?: string;
    };
    suggestion?: MergeStrategy;
    suggestionReason?: string;
}

declare type DataEnvironment = 'development' | 'testing' | 'uat' | 'staging' | 'production';

declare interface DataFieldDiff {
    field: string;
    fieldType: string;
    oldValue: unknown;
    newValue: unknown;
    changeType: ChangeType;
}

declare type ExportFormat = 'sql' | 'json' | 'csv' | 'parquet';

declare interface FieldConflict {
    field: string;
    fieldLabel: string;
    dataType: string;
    sourceValue: unknown;
    targetValue: unknown;
    baseValue?: unknown;
    resolution?: 'source' | 'target' | 'custom' | 'skip';
    customValue?: unknown;
}

declare type FieldResolutionMap = Record<string, {
    resolution: 'source' | 'target' | 'custom';
    value: unknown;
}>;

export declare interface MergeConfig {
    sourceId: string;
    targetId: string;
    strategy: MergeStrategy;
    tables?: string[];
    createBackup: boolean;
    dryRun: boolean;
    scheduledAt?: Date;
    conflictResolutions?: Record<string, ConflictResolutionChoice>;
}

/** Merge strategies */
declare type MergeStrategy = 'keep-source' | 'keep-target' | 'keep-both' | 'keep-base' | 'manual' | 'auto';

export declare const NiceDataBranchGraph: default_2.FC<NiceDataBranchGraphProps>;

export declare interface NiceDataBranchGraphProps extends NiceBaseProps {
    /** Branches to display */
    branches?: DataBranch[];
    /** Commits/snapshots */
    commits?: DataBranchCommit[];
    /** Selected commit ID */
    selectedCommitId?: string;
    /** View mode */
    viewMode?: 'timeline' | 'graph' | 'list';
    /** Show environment lanes */
    showLanes?: boolean;
    onSelectCommit?: (commitId: string) => void;
    onSelectBranch?: (branchId: string) => void;
    onCompare?: (sourceId: string, targetId: string) => void;
    onRestore?: (commitId: string) => void;
}

export declare const NiceDataBranchManager: default_2.FC<NiceDataBranchManagerProps>;

export declare interface NiceDataBranchManagerProps extends NiceBaseProps {
    /** Current tenant ID */
    tenant: string;
    /** Available environments/branches */
    branches?: DataBranch[];
    /** Current user */
    currentUser?: VersioningAuthor;
    /** Available tables for partial clone */
    availableTables?: TableInfo[];
    /** Read-only mode */
    readOnly?: boolean;
    onCreateBranch?: (branch: DataBranch) => void;
    onDeleteBranch?: (branchId: string) => void;
    onSwitchBranch?: (branchId: string) => void;
    onCloneBranch?: (sourceId: string, targetEnv: DataEnvironment, tables?: string[]) => void;
    onSyncBranch?: (branchId: string, direction: 'push' | 'pull') => void;
    onProtectBranch?: (branchId: string, rules: ProtectionConfig) => void;
    onScheduleSync?: (branchId: string, schedule: SyncSchedule) => void;
}

export declare const NiceDataConflictResolver: default_2.FC<NiceDataConflictResolverProps>;

export declare interface NiceDataConflictResolverProps extends NiceBaseProps {
    /** Conflicts to resolve */
    conflicts?: DataConflict[];
    /** Source environment */
    sourceEnvironment?: DataEnvironment;
    /** Target environment */
    targetEnvironment?: DataEnvironment;
    /** Show auto-resolution suggestions */
    showSuggestions?: boolean;
    /** Allow custom value editing */
    allowCustomValues?: boolean;
    onResolve?: (resolutions: ConflictResolution[]) => void;
    onSkip?: (conflictId: string) => void;
    onCancel?: () => void;
}

export declare const NiceDataDiffViewer: default_2.FC<NiceDataDiffViewerProps>;

export declare interface NiceDataDiffViewerProps extends NiceBaseProps {
    /** Source environment */
    sourceBranch?: DataBranch;
    /** Target environment */
    targetBranch?: DataBranch;
    /** Available branches for selection */
    branches?: DataBranch[];
    /** Diff data */
    diffItems?: TableDiffSummary[];
    onCompare?: (sourceId: string, targetId: string) => void;
    onExport?: (format: 'json' | 'csv' | 'sql') => void;
    onSelectRecord?: (table: string, recordId: string) => void;
}

export declare const NiceDataMergeBuilder: default_2.FC<NiceDataMergeBuilderProps>;

export declare interface NiceDataMergeBuilderProps extends NiceBaseProps {
    /** Available branches */
    branches?: DataBranch[];
    /** Pre-selected source branch */
    sourceBranchId?: string;
    /** Pre-selected target branch */
    targetBranchId?: string;
    onPreview?: (sourceId: string, targetId: string) => void;
    onMerge?: (config: MergeConfig) => void;
    onCancel?: () => void;
}

export declare const NiceDataSnapshot: default_2.FC<NiceDataSnapshotProps>;

export declare interface NiceDataSnapshotProps extends NiceBaseProps {
    /** Current environment */
    environment?: DataEnvironment;
    /** Available snapshots */
    snapshots?: Snapshot[];
    /** Retention policy */
    retentionPolicy?: RetentionPolicy;
    /** Scheduled snapshots */
    schedules?: SnapshotSchedule[];
    onCreateSnapshot?: (config: CreateSnapshotConfig) => void;
    onRestoreSnapshot?: (snapshotId: string) => void;
    onDeleteSnapshot?: (snapshotId: string) => void;
    onCompareSnapshots?: (sourceId: string, targetId: string) => void;
    onExportSnapshot?: (snapshotId: string, format: ExportFormat) => void;
    onUpdateRetentionPolicy?: (policy: RetentionPolicy) => void;
    onUpdateSchedules?: (schedules: SnapshotSchedule[]) => void;
}

declare interface ProtectionConfig {
    requireApproval: boolean;
    approversCount: number;
    requireBackup: boolean;
    allowDirectChanges: boolean;
    restrictTables?: string[];
}

declare interface RecordDiff {
    id: string;
    changeType: ChangeType;
    primaryKey: Record<string, unknown>;
    fields: DataFieldDiff[];
    changedAt?: Date;
    changedBy?: string;
}

export declare interface RetentionPolicy {
    enabled: boolean;
    maxCount?: number;
    maxAgeDays?: number;
    keepTagged?: boolean;
    keepLocked?: boolean;
}

export declare interface Snapshot {
    id: string;
    name: string;
    description?: string;
    environment: DataEnvironment;
    createdAt: Date;
    createdBy: {
        id: string;
        name: string;
    };
    size: {
        records: number;
        bytes: number;
    };
    type: 'manual' | 'scheduled' | 'pre-merge' | 'pre-restore';
    status: 'creating' | 'ready' | 'failed' | 'expired' | 'locked';
    tables?: string[];
    tags?: string[];
    expiresAt?: Date;
}

export declare interface SnapshotSchedule {
    id: string;
    name: string;
    cron: string;
    enabled: boolean;
    nextRun?: Date;
    lastRun?: Date;
    retainCount?: number;
}

declare interface SyncSchedule {
    enabled: boolean;
    frequency: 'manual' | 'hourly' | 'daily' | 'weekly';
    lastSync?: VersioningTimestamp;
    nextSync?: VersioningTimestamp;
    direction: 'push' | 'pull' | 'bidirectional';
}

declare interface TableDiffSummary {
    table: string;
    displayName: string;
    module?: string;
    added: number;
    modified: number;
    deleted: number;
    records: RecordDiff[];
}

declare interface TableInfo {
    name: string;
    displayName: string;
    recordCount: number;
    sizeBytes: number;
    module?: string;
    hasForeignKeys?: boolean;
}

/** Author/User information */
declare interface VersioningAuthor {
    id: string;
    name: string;
    email?: string;
    avatar?: string;
}

/** Base branch representation */
declare interface VersioningBranch extends VersioningId {
    name: string;
    displayName?: string;
    description?: string;
    isDefault: boolean;
    isProtected: boolean;
    createdBy: VersioningAuthor;
    createdAt: VersioningTimestamp;
    lastActivity?: VersioningTimestamp;
    upstream?: string;
    status: BranchStatus;
    metadata?: Record<string, unknown>;
}

/**
 * NiceVersioningCore — Shared abstraction for Git and Data Branching
 * @nice2dev/ui - Versioning System
 *
 * Provides common types, hooks, and utilities for:
 * - Git version control (code)
 * - Data Branching (ERP data)
 */
/** Base versioning entity identifier */
declare interface VersioningId {
    id: string;
    shortId: string;
}

/** Timestamp with timezone */
declare interface VersioningTimestamp {
    date: Date;
    timezone?: string;
    relative?: string;
}

export { }
