"""DNS helper predicates used by vulnerability checks.

Offers simple string-based checks for qtypes and response types.
"""
from __future__ import annotations

from ptnetinspector.utils.dns_types import DNS_RECORD_NAMES, DNS_RECORD_NAMES_NO_PTR


def contains_dns_qtype(packet: str, qtypes: set[str] | None = None) -> bool:
    """Case-insensitive check for any DNS qtype marker inside a packet string."""
    target = qtypes or DNS_RECORD_NAMES
    packet_lower = packet.lower()
    return any(f"qtype = {qt.lower()}" in packet_lower for qt in target)


def contains_dns_type(packet: str, types_set: set[str] | None = None) -> bool:
    """Case-insensitive check for any DNS response type marker inside a packet string."""
    target = types_set or DNS_RECORD_NAMES
    packet_lower = packet.lower()
    return any(f"type = {tp.lower()}" in packet_lower for tp in target)


def dns_record_types_no_ptr() -> set[str]:
    return DNS_RECORD_NAMES_NO_PTR
