from __future__ import annotations

import concurrent.futures
from dataclasses import dataclass

from .mypy import run_mypy
from .pyright import run_pyright
from .result import Result
from .ty import run_ty


@dataclass
class TypecheckResult:
    pyright: list[Result]
    mypy: list[Result]
    ty: list[Result]


def typecheck(
    code: str, strict: bool = True, mypy_plugins: list[str] | None = None
) -> TypecheckResult:
    with concurrent.futures.ThreadPoolExecutor() as executor:
        pyright_future = executor.submit(run_pyright, code, strict=strict)
        mypy_future = executor.submit(
            run_mypy, code, strict=strict, mypy_plugins=mypy_plugins
        )
        ty_future = executor.submit(run_ty, code, strict=strict)

        pyright_results = pyright_future.result()
        mypy_results = mypy_future.result()
        ty_results = ty_future.result()

    return TypecheckResult(pyright=pyright_results, mypy=mypy_results, ty=ty_results)
