"""
TextIQ Airflow Plugins Package.

This package contains custom Airflow operators, hooks, and models
for the TextIQ document extraction pipeline.
"""

import logging

log = logging.getLogger(__name__)

try:
    from airflow.plugins_manager import AirflowPlugin

    try:
        from api.upload import upload_app
        from api.tags import tags_app
        from api.domain_terms import domain_terms_app
        from api.metrics import register_metrics_route
    except ImportError:
        from airflow.plugins.api.upload import upload_app
        from airflow.plugins.api.tags import tags_app
        from airflow.plugins.api.domain_terms import domain_terms_app
        from airflow.plugins.api.metrics import register_metrics_route

    register_metrics_route(upload_app)
    register_metrics_route(tags_app)
    register_metrics_route(domain_terms_app)

    class TextIQPlugin(AirflowPlugin):
        """TextIQ custom Airflow plugin."""

        name = "textiq"
        fastapi_apps = [
            {
                "name": "upload",
                "app": upload_app,
                "url_prefix": "/api/v1/documents",
            },
            {
                "name": "tags",
                "app": tags_app,
                "url_prefix": "/api/v1/blocks",
            },
            {
                "name": "domain_terms",
                "app": domain_terms_app,
                "url_prefix": "/api/v1/domain-terms",
            },
        ]

    log.info("TextIQ plugin loaded successfully")

except ImportError:
    log.warning("TextIQ plugin not loaded - Airflow not installed")
