from ..profile import TracingAttribute

# Common context attributes that can be reused across nodes
common_execution_context_attributes: list[TracingAttribute] = [
    TracingAttribute(
        name="hierarchy_path",
        category="primary",
        data_type="string",
        display_name="Hierarchy Path",
        description="Hierarchy path of the context",
        group_name="execution_context",
        source_path="hierarchy_path",
    ),
    TracingAttribute(
        name="start_hierarchy_path",
        category="primary",
        data_type="string",
        display_name="Start Hierarchy Path",
        description="Start hierarchy path from the run context",
        group_name="execution_context",
        source_path="start_hierarchy_path",
    ),
    TracingAttribute(
        name="execution_status",
        category="primary",
        data_type="string",
        display_name="Execution Status",
        description="Status of the execution (pending, complete, failed)",
        group_name="execution_context",
        source_path="execution_status",
    ),
    TracingAttribute(
        name="created_at",
        category="secondary",
        data_type="string",
        display_name="Created At",
        description="When this execution started",
        group_name="execution_context",
        source_path="created_at",
        transform=lambda x: x.isoformat() if x else None,
        format_hint="datetime",
    ),
    TracingAttribute(
        name="completed_at",
        category="secondary",
        data_type="string",
        display_name="Completed At",
        description="When this execution completed",
        group_name="execution_context",
        source_path="completed_at",
        transform=lambda x: x.isoformat() if x else None,
        format_hint="datetime",
    ),
    TracingAttribute(
        name="execution_type",
        category="secondary",
        data_type="string",
        display_name="Execution Type",
        description="Type of execution (flow, node, agent)",
        group_name="execution_context",
        source_path="executable_type",
    ),
    TracingAttribute(
        name="error_message",
        category="tertiary",
        data_type="string",
        display_name="Error Message",
        description="Error message if execution failed",
        group_name="execution_context",
        source_path="execution_failed_message",
    ),
    TracingAttribute(
        name="parent_context",
        category="tertiary",
        data_type="string",
        display_name="Parent Context",
        description="Parent execution context ID, if any",
        group_name="execution_context",
        source_path="parent.component_id",
        transform=lambda x: x.component_id if x else "No-parent",
    ),
    TracingAttribute(
        name="metadata",
        category="tertiary",
        data_type="string",
        display_name="Metadata",
        description="Additional execution metadata",
        group_name="execution_context",
        source_path="metadata",
        transform=lambda x: {k: v for k, v in x.items() if isinstance(v, (str, int, float, bool))} if x else {},
        max_length=500,
        collapsible=True,
    ),
]
