from .collector import Collector
from .config import Config
from .sender import Sender


class Tracker:
    def __init__(self):
        self.config = Config()
        self.collector = Collector(self.config)
        self.sender = Sender(self.config)

    def track(self):
        try:
            if self.config.is_verbose():
                print("[package-tracker] Configuration:", self.config.get_config())

            if not self.config.is_tracking_enabled():
                if self.config.is_verbose():
                    print("[package-tracker] Tracking is disabled")
                return {"success": False, "reason": "disabled"}

            data = self.collector.collect()
            if self.config.is_verbose():
                print("[package-tracker] Collected data:", data)

            result = self.sender.send(data)
            if self.config.is_verbose():
                print("[package-tracker] Send result:", result)

            return result
        except Exception as error:
            if self.config.is_verbose():
                print(f"[package-tracker] Error: {error}")
            return {"success": False, "error": str(error)}
