"""Post-processor for injecting framework services into aware Pods.

This module provides ApplicationContextAwareProcessor which injects
container and application context into Pods implementing aware interfaces.
"""

from spakky.core.pod.interfaces.application_context import IApplicationContext
from spakky.core.pod.interfaces.aware.application_context_aware import (
    IApplicationContextAware,
)
from spakky.core.pod.interfaces.aware.container_aware import IContainerAware
from spakky.core.pod.interfaces.aware.tag_registry_aware import ITagRegistryAware
from spakky.core.pod.interfaces.post_processor import IPostProcessor


class ApplicationContextAwareProcessor(IPostProcessor):
    """Post-processor for injecting framework services into aware Pods.

    Checks if Pods implement aware interfaces and injects corresponding services:
    - IContainerAware: Injects IoC container
    - IApplicationContextAware: Injects application context
    """

    __application_context: IApplicationContext

    def __init__(self, application_context: IApplicationContext) -> None:
        """Initialize aware post-processor.

        Args:
            application_context: The application context to inject.
        """
        self.__application_context = application_context

    def post_process(self, pod: object) -> object:
        """Inject framework services into aware Pods.

        Args:
            pod: The Pod instance to process.

        Returns:
            The Pod instance with injected services.
        """
        if isinstance(pod, IContainerAware):
            pod.set_container(self.__application_context)
        if isinstance(pod, ITagRegistryAware):
            pod.set_tag_registry(self.__application_context)
        if isinstance(pod, IApplicationContextAware):
            pod.set_application_context(self.__application_context)
        return pod
