"""DSS Export/Import System - Complete project archival and restoration

This module provides comprehensive export/import capabilities for DSS projects:

1. EXPORT: Create .dss archive files containing complete project state
   - manifest.json: Project metadata and archive structure
   - tokens.json: All design tokens with metadata and source attribution
   - components.json: All components with variants, props, and dependencies
   - themes.json: Theme definitions and token cascades
   - config.json: Project configuration

2. IMPORT: Restore projects from .dss archives with multiple strategies
   - REPLACE: Full project restoration (backup restore, cloning)
   - MERGE: Smart UUID-based reconciliation (collaboration, updates)
   - FORK: Create duplicates for conflicting items (safe conflicts)

3. VALIDATION: Pre-import checks prevent data corruption
   - Archive integrity validation
   - Schema version compatibility
   - Referential integrity checking
   - Conflict detection and resolution

4. MIGRATIONS: Handle schema evolution transparently
   - Automatic version migration
   - Forward compatibility
   - Rollback protection

Example Usage:

    from pathlib import Path
    from dss.models.project import Project
    from dss.export_import import DSSArchiveExporter, DSSArchiveImporter

    # EXPORT a project to .dss file
    project = Project(...)
    exporter = DSSArchiveExporter(project)
    archive_path = exporter.export_to_file(Path("my-project.dss"))

    # ANALYZE an archive before importing
    importer = DSSArchiveImporter(Path("my-project.dss"))
    analysis = importer.analyze()
    print(f"Valid: {analysis.is_valid}")
    print(f"Projects: {analysis.project_name}")
    print(f"Token count: {analysis.content_summary['tokens']['count']}")

    # IMPORT with REPLACE strategy (full restoration)
    imported_project = importer.import_replace()

    # IMPORT with MERGE strategy (smart update)
    from dss.export_import.merger import SmartMerger, ConflictResolutionMode
    local_project = Project(...)
    imported_project = importer.import_replace()
    merger = SmartMerger(local_project, imported_project)

    # Analyze merge
    analysis = merger.analyze_merge()
    print(f"New tokens: {len(analysis.new_items['tokens'])}")
    print(f"Conflicts: {len(analysis.conflicted_items)}")

    # Perform merge with conflict handling
    merged = merger.merge_with_strategy(
        ConflictResolutionMode.OVERWRITE
    )
"""

from .exporter import (
    DSSArchiveExporter,
    DSSArchiveManifest,
    ArchiveWriter,
)
from .importer import (
    DSSArchiveImporter,
    ArchiveValidator,
    ImportAnalysis,
    ImportValidationError,
)
from .merger import (
    SmartMerger,
    ConflictResolutionMode,
    ConflictItem,
    MergeAnalysis,
    UUIDHashMap,
)
from .migrations import (
    MigrationManager,
    SchemaMigration,
)
from .service import (
    DSSProjectService,
    ExportSummary,
    ImportSummary,
    MergeSummary,
)
from .security import (
    ZipSlipValidator,
    MemoryLimitManager,
    StreamingJsonLoader,
    TimestampConflictResolver,
    DatabaseLockingStrategy,
    ArchiveIntegrity,
)

__version__ = "1.0.1"
__all__ = [
    # Exporter
    "DSSArchiveExporter",
    "DSSArchiveManifest",
    "ArchiveWriter",
    # Importer
    "DSSArchiveImporter",
    "ArchiveValidator",
    "ImportAnalysis",
    "ImportValidationError",
    # Merger
    "SmartMerger",
    "ConflictResolutionMode",
    "ConflictItem",
    "MergeAnalysis",
    "UUIDHashMap",
    # Migrations
    "MigrationManager",
    "SchemaMigration",
    # Service Layer (Production-Ready)
    "DSSProjectService",
    "ExportSummary",
    "ImportSummary",
    "MergeSummary",
    # Security & Hardening
    "ZipSlipValidator",
    "MemoryLimitManager",
    "StreamingJsonLoader",
    "TimestampConflictResolver",
    "DatabaseLockingStrategy",
    "ArchiveIntegrity",
]
