from typing import Self

from htmlnode import HtmlNode


class ParentNode(HtmlNode):
    def __init__(
        self: Self,
        tag: str,
        children: list[HtmlNode],
        value: str | None = None,
        props: dict | None = None,
    ) -> None:
        super().__init__(tag, value, children, props)

    def to_html(self: Self) -> str:
        if self.tag is None:
            raise ValueError

        if self.children is None or len(self.children) == 0:
            raise ValueError
        
        html = []
        html.append(f"<{self.tag}{self.props_to_html()}>")

        for child in self.children:
            html.append(child.to_html())

        html.append(f"</{self.tag}>")

        return "".join(html)
