# retoor <retoor@molodetz.nl>
from __future__ import annotations

from dataclasses import dataclass, field
from typing import Callable

from devplacepy.services.jobs.isslop.analysis.signals import Signal


@dataclass
class DomPageContext:
    url: str
    dom: dict = field(default_factory=dict)
    console_warnings: list[str] = field(default_factory=list)
    console_errors: list[str] = field(default_factory=list)
    response_headers: dict[str, str] = field(default_factory=dict)
    resource_hosts: list[str] = field(default_factory=list)
    screenshot_bytes: bytes | None = None


@dataclass
class DomSiteContext:
    pages: list[DomPageContext] = field(default_factory=list)
    root_host: str = ""


DomPageDetector = Callable[[DomPageContext], list[Signal]]
DomSiteDetector = Callable[[DomSiteContext], list[Signal]]

DOM_CHECKS: list[DomPageDetector] = []
DOM_SITE_CHECKS: list[DomSiteDetector] = []


def dom_check(func: DomPageDetector) -> DomPageDetector:
    DOM_CHECKS.append(func)
    return func


def dom_site_check(func: DomSiteDetector) -> DomSiteDetector:
    DOM_SITE_CHECKS.append(func)
    return func
