"""Data models for function tracing."""

from __future__ import annotations

from pathlib import Path
from typing import Any

import attrs


@attrs.frozen
class TracedFunction:
    """A function discovered during tracing."""

    function_name: str
    file_name: Path = attrs.field(converter=Path)
    module_name: str
    class_name: str | None = None
    line_no: int | None = None
    method_type: str | None = None
    is_top_level: bool = True


class FakeCode:
    """Lightweight stand-in for a code object used by the profiler."""

    def __init__(self, filename: str, line: int, name: str) -> None:
        """Initialize with filename, line number, and function name."""
        self.co_filename = filename
        self.co_line = line
        self.co_name = name
        self.co_firstlineno = 0

    def __repr__(self) -> str:
        """Return a tuple-like representation of the fake code object."""
        return repr((self.co_filename, self.co_line, self.co_name, None))


class FakeFrame:
    """Lightweight stand-in for a frame object used by the profiler."""

    def __init__(self, code: FakeCode, prior: FakeFrame | None) -> None:
        """Initialize with a FakeCode and optional prior frame."""
        self.f_code = code
        self.f_back = prior
        self.f_locals: dict[str, Any] = {}
