from nonebot import require, get_driver
from nonebot.plugin import PluginMetadata

from .config import Config

require("danding_bot.plugins.danding_points")

__plugin_meta__ = PluginMetadata(
    name="Group Horse Racing",
    description="Group horse racing plugin with betting and points integration",
    usage="Use /赛马 commands for horse racing gameplay",
    type="application",
    config=Config,
    extra={
        "required_plugins": ["danding_bot.plugins.danding_points"],
    },
)

# 从 NoneBot driver config 中提取本插件配置（去掉 GROUP_HORSE_RACING_ 前缀）
_nb_config = get_driver().config
_raw = _nb_config.model_dump() if hasattr(_nb_config, "model_dump") else _nb_config.dict()
_prefix = "group_horse_racing_"

plugin_config = Config(**{
    k[len(_prefix):].upper(): v
    for k, v in _raw.items()
    if k.startswith(_prefix)
})

print("[group_horse_racing] Config loaded from NoneBot driver:")
print(f"  TEST_MODE = {plugin_config.TEST_MODE}")
print(f"  TESTERS = {plugin_config.TESTERS}")
print(f"  TEST_GROUPS = {plugin_config.TEST_GROUPS}")
print(f"  ALLOWED_GROUPS = {plugin_config.ALLOWED_GROUPS}")
print(f"  PARTICIPANT_REWARD = {plugin_config.PARTICIPANT_REWARD}")
print(f"  CHAMPION_REWARD = {plugin_config.CHAMPION_REWARD}")
print(f"  MIN_BET = {plugin_config.MIN_BET}")
print(f"  MIN_ODDS = {plugin_config.MIN_ODDS}")
print(f"  RACE_DISTANCE = {plugin_config.RACE_DISTANCE}")
print(f"  RACE_TICK_INTERVAL = {plugin_config.RACE_TICK_INTERVAL}")
print(f"  RACE_DB_FILE = {plugin_config.RACE_DB_FILE}")

from . import commands, test_commands  # noqa: F401, E402
