import 'package:flutter/foundation.dart'; import 'package:worldhopper/models/server.dart'; import 'package:worldhopper/services/server_software/kavita_server_software.dart'; import 'package:worldhopper/services/server_software/opds_server_software.dart'; import 'package:worldhopper/services/server_software/server_software.dart'; import 'package:worldhopper/services/server_software/server_software_type.dart'; /// Registry / dispatcher for server-software-specific operations. class ServerSoftwareService { final OPDSServerSoftware _opds = OPDSServerSoftware(); final KavitaServerSoftware _kavita = KavitaServerSoftware(); /// Detect the server software type from the server URL. /// Note: Kavita detection returns false (base URLs are not distinguishable). /// Users should select Kavita from the dropdown. ServerSoftwareType detect(Server server) { if (_kavita.detectFromUrl(server)) return ServerSoftwareType.kavita; return ServerSoftwareType.generic; } /// Get the [ServerSoftware] implementation for a given server. ServerSoftware getImplementation(Server server) { final type = server.softwareType ?? ServerSoftwareType.generic; debugPrint('ServerSoftwareService: dispatching to $type for ${server.id}'); return switch (type) { ServerSoftwareType.kavita => _kavita, ServerSoftwareType.generic => _opds, }; } /// Clear any cached tokens/state for the given server. void clearCachedState(String serverId) { _kavita.clearCachedState(serverId); _opds.clearCachedState(serverId); } }