"""Filter Template meta-filter — references another postprocessing template.

This filter exists in the registry for UI discovery only.  It is never
instantiated at runtime: ``LiveStreamManager`` expands it into the
referenced template's filters when building the processing pipeline.
"""

from typing import List, Optional

import numpy as np

from wled_controller.core.filters.base import FilterOptionDef, PostprocessingFilter
from wled_controller.core.filters.image_pool import ImagePool
from wled_controller.core.filters.registry import FilterRegistry


@FilterRegistry.register
class FilterTemplateFilter(PostprocessingFilter):
    """Include another filter template's chain at this position."""

    filter_id = "filter_template"
    filter_name = "Filter Template"
    supports_strip = False

    @classmethod
    def get_options_schema(cls) -> List[FilterOptionDef]:
        return [
            FilterOptionDef(
                key="template_id",
                label="Template",
                option_type="select",
                default="",
                min_value=None,
                max_value=None,
                step=None,
                choices=[],  # populated dynamically by GET /api/v1/filters
            ),
        ]

    def process_image(self, image: np.ndarray, image_pool: ImagePool) -> Optional[np.ndarray]:
        # Never called — expanded at pipeline build time by LiveStreamManager.
        return None
