#!/usr/bin/env python3
"""
#exonware/xwquery/src/exonware/xwquery/executors/graph/degree_executor.py
DEGREE Operation Executor - Calculate node degree
Company: eXonware.com
Author: eXonware Backend Team
Email: connect@exonware.com
Version: 0.0.1.8
Generation Date: 28-Oct-2025
"""

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


class DegreeExecutor(AUniversalOperationExecutor):
    """
    DEGREE operation executor - Calculate node degree (in/out/total).
    Degree = number of edges connected to a node.
    - In-degree: number of incoming edges
    - Out-degree: number of outgoing edges
    - Total degree: in-degree + out-degree
    Reuses xwnode degree calculation.
    """
    OPERATION_NAME = "DEGREE"

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

    def _execute_degree(self, node: Any, params: dict, context: ExecutionContext) -> dict:
        """
        Execute DEGREE - Calculate node degree.
        FUTURE: Will use xwnode degree calculation.
        """
        degree_type = params.get('type', 'total')  # in, out, total
        edge_type = params.get('edge_type')
        in_degree = 0
        out_degree = 0
        total_degree = 0
        # FUTURE: Use xwnode's degree methods
        # if degree_type in ['in', 'total']:
        #     in_degree = node.in_degree(edge_type=edge_type)
        # if degree_type in ['out', 'total']:
        #     out_degree = node.out_degree(edge_type=edge_type)
        # total_degree = in_degree + out_degree
        return {
            'in_degree': in_degree,
            'out_degree': out_degree,
            'total_degree': total_degree,
            'degree_type': degree_type,
            'edge_type': edge_type,
            'status': 'basic_implementation',
            'note': 'Will use xwnode degree calculation for production'
        }
__all__ = ['DegreeExecutor']
