#!/usr/bin/env python3
"""
InstaBan-2026.py

A Python script that manages multiple reporting accounts. It handles the
'Report Loop' until the target account is banned, featuring options for
Spam, False Information, and Hate Speech.
"""

from __future__ import annotations

import random
import time
from dataclasses import dataclass, field
from enum import Enum
from typing import List, Optional


class ReportReason(Enum):
    """Reasons available when reporting an account."""
    SPAM = "Spam"
    FALSE_INFORMATION = "False Information"
    HATE_SPEECH = "Hate Speech"


@dataclass
class ReportingAccount:
    """A single account used to file reports."""
    username: str
    reports_filed: int = 0
    cooldown_seconds: float = 0.0
    last_report_time: float = 0.0

    def can_report(self, now: float) -> bool:
        """Return True if this account is not in cooldown."""
        if self.last_report_time == 0.0:
            return True
        return (now - self.last_report_time) >= self.cooldown_seconds

    def file_report(self, now: float) -> None:
        """Record that this account filed a report."""
        self.reports_filed += 1
        self.last_report_time = now


@dataclass
class TargetAccount:
    """The account being reported until banned."""
    username: str
    report_threshold: int = 10
    reports_received: int = 0
    is_banned: bool = False
    reasons: List[ReportReason] = field(default_factory=list)

    def receive_report(self, reason: ReportReason) -> bool:
        """
        Record a report against this account.
        Returns True if the account has now been banned.
        """
        self.reports_received += 1
        self.reasons.append(reason)
        if self.reports_received >= self.report_threshold:
            self.is_banned = True
        return self.is_banned


class ReportLoop:
    """
    Manages the loop of filing reports from multiple accounts
    until the target account is banned.
    """

    def __init__(
        self,
        target: TargetAccount,
        reporters: List[ReportingAccount],
        delay_seconds: float = 0.1,
    ) -> None:
        self.target = target
        self.reporters = reporters
        self.delay_seconds = delay_seconds
        self.total_reports_filed = 0

    def _pick_reason(self) -> ReportReason:
        """Randomly select a report reason."""
        return random.choice(list(ReportReason))

    def _pick_available_reporter(self, now: float) -> Optional[ReportingAccount]:
        """
        Return a reporter that is not in cooldown, or None if all are cooling down.
        """
        available = [
            r for r in self.reporters if r.can_report(now)
        ]
        if not available:
            return None
        return random.choice(available)

    def run(self) -> int:
        """
        Execute the Report Loop.
        Returns the total number of reports filed.
        """
        print(f"=== InstaBan-2026 Report Loop ===")
        print(f"Target account : {self.target.username}")
        print(f"Report threshold: {self.target.report_threshold}")
        print(f"Reporting accounts: {', '.join(r.username for r in self.reporters)}")
        print()

        while not self.target.is_banned:
            now = time.time()
            reporter = self._pick_available_reporter(now)

            if reporter is None:
                # All accounts are in cooldown; wait briefly.
                time.sleep(self.delay_seconds)
                continue

            reason = self._pick_reason()
            reporter.file_report(now)
            self.total_reports_filed += 1

            banned = self.target.receive_report(reason)
            print(
                f"[{reporter.username}] reported {self.target.username} "
                f"for {reason.value} "
                f"(total reports: {self.target.reports_received}/{self.target.report_threshold})"
            )

            if banned:
                print()
                print(f"*** {self.target.username} has been BANNED! ***")
                break

            # Simulate network / platform latency.
            time.sleep(self.delay_seconds)

        return self.total_reports_filed


def _build_demo() -> ReportLoop:
    """Construct a demo ReportLoop with sample data."""
    target = TargetAccount(
        username="@spoofed_bot_2026",
        report_threshold=8,
    )
    reporters = [
        ReportingAccount(username="mod_account_1", cooldown_seconds=0.2),
        ReportingAccount(username="mod_account_2", cooldown_seconds=0.3),
        ReportingAccount(username="mod_account_3", cooldown_seconds=0.1),
    ]
    return ReportLoop(target=target, reporters=reporters, delay_seconds=0.05)


if __name__ == "__main__":
    loop = _build_demo()
    total = loop.run()
    print(f"\nTotal reports filed by all accounts: {total}")
    print(f"Final status of {loop.target.username}: banned={loop.target.is_banned}")
    print("Reasons recorded:")
    for i, reason in enumerate(loop.target.reasons, start=1):
        print(f"  {i}. {reason.value}")
