"""Data types for test discovery and filtering."""

from __future__ import annotations

import enum
from pathlib import Path

import attrs


class TestType(enum.IntEnum):
    """Type of test discovered."""

    __test__ = False

    EXISTING_UNIT_TEST = 1
    INSPIRED_REGRESSION = 2
    GENERATED_REGRESSION = 3
    REPLAY_TEST = 4
    CONCOLIC_COVERAGE_TEST = 5
    INIT_STATE_TEST = 6

    def to_name(self) -> str:
        """Human-readable display name for PR comments."""
        return _TEST_TYPE_NAME_MAP.get(self, "")


_TEST_TYPE_NAME_MAP: dict[TestType, str] = {
    TestType.EXISTING_UNIT_TEST: "Existing Unit Tests",
    TestType.INSPIRED_REGRESSION: "Inspired Regression Tests",
    TestType.GENERATED_REGRESSION: "Generated Regression Tests",
    TestType.REPLAY_TEST: "Replay Tests",
    TestType.CONCOLIC_COVERAGE_TEST: "Concolic Coverage Tests",
}


@attrs.frozen
class CodePosition:
    """Line and column position in source code."""

    line_no: int
    col_no: int


@attrs.frozen
class TestsInFile:
    """A test function found in a test file."""

    __test__ = False

    test_file: Path = attrs.field(converter=Path)
    test_class: str | None
    test_function: str
    test_type: TestType


@attrs.frozen
class FunctionCalledInTest:
    """A target function called from within a test."""

    tests_in_file: TestsInFile
    position: CodePosition


@attrs.frozen
class ReplayTestMetadata:
    """Metadata parsed from a tracer-generated replay test file."""

    trace_file_path: Path
    function_names: tuple[str, ...]
