from prowler.lib.check.models import Check, CheckReportLinode
from prowler.providers.linode.services.networking.networking_client import (
    networking_client,
)


class networking_firewall_default_inbound_policy_drop(Check):
    """Check if Linode Cloud Firewall default inbound policy is DROP."""

    def execute(self) -> list[CheckReportLinode]:
        """Execute the networking_firewall_default_inbound_policy_drop check.

        Iterates over all Cloud Firewalls and checks whether the default
        inbound policy is DROP.

        Returns:
            list[CheckReportLinode]: A list of findings for each firewall.
        """
        findings = []

        for fw in networking_client.firewalls:
            report = CheckReportLinode(
                metadata=self.metadata(),
                resource=fw,
                resource_name=fw.label,
                resource_id=str(fw.id),
                region="global",
            )
            report.resource_tags = fw.tags

            if fw.inbound_policy == "DROP":
                report.status = "PASS"
                report.status_extended = (
                    f"Firewall '{fw.label}' has default inbound policy set to DROP."
                )
            else:
                report.status = "FAIL"
                report.status_extended = f"Firewall '{fw.label}' has default inbound policy set to {fw.inbound_policy}."

            findings.append(report)

        return findings
