| 1 | from __future__ import annotations |
| 2 | |
| 3 | from typing import Dict, Optional, Type |
| 4 | |
| 5 | from core.user_modes import ( |
| 6 | BaseUserModeStrategy, |
| 7 | CollectMixUserModeStrategy, |
| 8 | CollectUserModeStrategy, |
| 9 | LikeUserModeStrategy, |
| 10 | MixUserModeStrategy, |
| 11 | MusicUserModeStrategy, |
| 12 | PostUserModeStrategy, |
| 13 | ) |
| 14 | |
| 15 | |
| 16 | class UserModeRegistry: |
| 17 | def __init__(self): |
| 18 | self._registry: Dict[str, Type[BaseUserModeStrategy]] = { |
| 19 | "post": PostUserModeStrategy, |
| 20 | "like": LikeUserModeStrategy, |
| 21 | "mix": MixUserModeStrategy, |
| 22 | "music": MusicUserModeStrategy, |
| 23 | "collect": CollectUserModeStrategy, |
| 24 | "collectmix": CollectMixUserModeStrategy, |
| 25 | } |
| 26 | |
| 27 | def get(self, mode: str) -> Optional[Type[BaseUserModeStrategy]]: |
| 28 | return self._registry.get((mode or "").strip()) |
| 29 | |
| 30 | def register(self, mode: str, strategy_cls: Type[BaseUserModeStrategy]) -> None: |
| 31 | self._registry[(mode or "").strip()] = strategy_cls |
| 32 | |
| 33 | def all_modes(self): |
| 34 | return sorted(self._registry.keys()) |
| 35 |