from __future__ import annotations

import enum
from abc import abstractmethod


class DiffError(ValueError):
    """
    Any problem detected while parsing or applying a patch.
    """


class DiffMethod(enum.Enum):
    NO_DIFF = "no_diff"
    V4A = "v4a"
    SEARCH_AND_REPLACE = "search_and_replace"


class Diff:
    """
    Base class for diff application strategies.
    """

    def __init__(
        self,
        content: str,
        source_code: dict[str, str],
        *,
        match_files_when_having_single_patch: bool = True,
    ) -> None:
        self.content = content
        self.source_code = source_code
        self.extracted_diff: dict[str, str] | None = None
        self.match_files_when_having_single_patch = (
            match_files_when_having_single_patch
        )

    @abstractmethod
    def run(self) -> dict[str, str]:
        """
        Apply the diff to the source code and return modified files.
        """
