| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- # plugin.py
- from typing import Callable, List, Dict
- from abc import ABC, abstractmethod
- from core_types import PluginConfig, AppointmentType, QueryResult, BookResult, PluginStatus
- # ================== Interface Class ==================
- class IPlugin(ABC):
- """
- @brief Plugin API interface class
- Defines core operations for visa automation plugins, including configuration, session management,
- querying, booking, health checks, and resource cleanup. All concrete plugin implementations must inherit from this interface.
- """
- name: str = ""
- version: str = "1.0.0"
- description: str = ""
- booking_supported: bool = True
- @classmethod
- def get_plugin_info(cls) -> Dict[str, str]:
- """
- @brief Gets plugin static metadata information.
- """
- return {
- "name": cls.name or cls.__name__,
- "version": cls.version,
- "description": cls.description,
- }
-
- @abstractmethod
- def set_config(self, config: PluginConfig):
- """
- @brief Sets API configuration.
- @param config PluginConfig configuration object
- """
- pass
-
- @abstractmethod
- def set_log(self, logger: Callable[[str], None]) -> None:
- """
- @brief Sets logging function. Must not raise exceptions.
- """
- pass
- @abstractmethod
- def create_session(self) -> None:
- """
- @brief Creates a new session. Raises exception on failure.
- """
- pass
- @abstractmethod
- def query(self, apt_type: AppointmentType) -> QueryResult:
- """
- @brief Queries available appointment slots. Raises exception on failure.
- @return QueryResult object containing query results
- """
- pass
- @abstractmethod
- def book(self, slot_info: QueryResult, user_inputs) -> BookResult:
- """
- @brief Executes booking attempt. Raises exception on failure.
- @param slot_info QueryResult slot information
- @param user_inputs User inputs for the booking
- @return BookResult object representing booking result
- """
- pass
-
- @abstractmethod
- def keep_alive(self):
- """
- @brief Keeps session alive. Must not raise exceptions.
- """
- pass
- @abstractmethod
- def health_check(self) -> bool:
- """
- @brief Performs health check to test API service status. Must not raise exceptions.
- @return True if healthy, False if issues exist
- """
- pass
-
- @abstractmethod
- def cleanup(self) -> None:
- """
- @brief Cleans up resources held by the plugin instance.
- """
- pass
- def get_plugin_status(self) -> PluginStatus:
- """
- @brief Gets snapshot of plugin instance runtime status.
- @return PluginStatus
- """
- return PluginStatus()
|