"""JavaScript/TypeScript language handler implementation.

Thin delegation layer that routes requests to the actual module implementations.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

from core.languages.js_ts.optimizer import optimize_javascript
from core.languages.js_ts.testgen import testgen_javascript

if TYPE_CHECKING:
    from authapp.auth import AuthenticatedRequest
    from core.shared.optimizer_schemas import OptimizeErrorResponseSchema, OptimizeResponseSchema
    from core.shared.optimizer_models import OptimizeSchema
    from core.shared.testgen_models import TestGenErrorResponseSchema, TestGenResponseSchema, TestGenSchema


class JSTypeScriptHandler:
    """JavaScript/TypeScript language handler."""

    language = "js_ts"

    supports_testgen = True
    supports_optimizer = True
    supports_code_repair = False
    supports_jit_rewrite = False
    supports_optimization_review = False
    supports_explanations = False

    async def testgen_generate(
        self, request: AuthenticatedRequest, data: TestGenSchema
    ) -> tuple[int, TestGenResponseSchema | TestGenErrorResponseSchema]:
        """Generate tests for JavaScript/TypeScript code."""
        return await testgen_javascript(request, data)

    async def optimizer_optimize(
        self, request: AuthenticatedRequest, data: OptimizeSchema
    ) -> tuple[int, OptimizeResponseSchema | OptimizeErrorResponseSchema]:
        """Optimize JavaScript/TypeScript code for performance."""
        return await optimize_javascript(request, data)
