from pathlib import Path

from pbreflect.pbgen.utils.format import format_file


class PbReflectPatcher:
    """Patcher for formatting files generated by pbreflect plugin.

    This class applies code formatting using ruff to files generated
    by the pbreflect plugin (with _pbreflect.py suffix). It performs
    both code formatting and automatic style error fixing with the linter.

    Implements the CodePatcher protocol.
    """

    def __init__(self, output_dir: str) -> None:
        """Initialize the formatting patcher.

        Args:
            output_dir: Directory containing generated files
        """
        self.output_dir = str(Path(output_dir))

    def patch(self) -> None:
        """Apply formatting to generated files with _pbreflect.py suffix."""
        format_file(self.output_dir, "_pbreflect.py")
