#!/usr/bin/env python3
"""
#exonware/xwnode/src/exonware/xwnode/queries/executors/data/merge_executor.py
MERGE Executor
Company: eXonware.com
Author: eXonware Backend Team
Email: connect@exonware.com
Version: 0.0.1.8
Generation Date: 09-Oct-2025
"""

from typing import Any
from ..base import AUniversalOperationExecutor
from ....contracts import QueryAction, ExecutionContext, ExecutionResult
from ....defs import OperationType


class MergeExecutor(AUniversalOperationExecutor):
    """
    MERGE operation executor.
    Merges/upserts data
    Capability: Universal
    Operation Type: DATA_OPS
    """
    OPERATION_NAME = "MERGE"
    OPERATION_TYPE = OperationType.DATA_OPS
    SUPPORTED_NODE_TYPES = []  # Universal

    def _do_execute(self, action: QueryAction, context: ExecutionContext) -> ExecutionResult:
        """Execute MERGE operation."""
        params = action.params
        node = context.node
        result_data = self._execute_merge(node, params, context)
        return ExecutionResult(
            success=True,
            data=result_data,
            action_type=self.OPERATION_NAME,
            metadata={'operation': self.OPERATION_NAME}
        )

    def _execute_merge(self, node: Any, params: dict, context: ExecutionContext) -> dict:
        """Execute MERGE - combine datasets."""
        source = params.get('source', params.get('with', []))
        strategy = params.get('strategy', 'append')  # append, upsert, deep_merge
        # FUTURE: Integrate with xwnode merge strategies
        return {'strategy': strategy, 'source_count': len(source) if isinstance(source, list) else 1,
                'status': 'basic_implementation', 
                'note': 'Will use xwnode merge strategies for advanced merging'}
