from mwedittypes.node_differ import get_html_diff_count, get_wikitext_diff_count
from mwedittypes.simple_differ import get_diff as get_simple_diff
from mwedittypes.tree_differ import get_diff as get_structured_diff


class StructuredEditTypes:
    def __init__(self, content_type, prev_content="", curr_content="", lang="en"):
        self.content_type = content_type
        self.prev_content = prev_content
        self.curr_content = curr_content
        self.lang = lang
        self.tree_diff = None
        self.actions = None

    def get_diff(self):
        self.tree_diff = get_structured_diff(
            content_type=self.content_type,
            prev_content=self.prev_content,
            curr_content=self.curr_content,
            lang=self.lang,
        )
        if self.content_type == "wikitext":
            self.actions = get_wikitext_diff_count(self.tree_diff, lang=self.lang)
        elif self.content_type == "html":
            self.actions = get_html_diff_count(self.tree_diff, lang=self.lang)
        else:
            self.actions = None
        return self.actions


class SimpleEditTypes:
    def __init__(self, content_type, prev_content="", curr_content="", lang="en"):
        self.content_type = content_type
        self.prev_content = prev_content
        self.curr_content = curr_content
        self.lang = lang
        self.actions = None

    def get_diff(self):
        self.actions = get_simple_diff(
            self.prev_content, self.curr_content, self.content_type, lang=self.lang
        )
        return self.actions
