from pydantic import field_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
import os


class Config(BaseSettings):
    """Points system configuration."""

    model_config = SettingsConfigDict(
        extra="ignore",
    )

    # xapi /bot/points 运行时 API 配置
    POINTS_API_HOST: str = os.getenv("DANDING_POINTS_API_HOST", "https://api.danding.vip/bot/points")
    BOT_USER: str = os.getenv("DANDING_BOT_USER", "1424473282")
    BOT_TOKEN: str = os.getenv(
        "DANDING_BOT_TOKEN",
        os.getenv("DANDING_API_TOKEN", os.getenv("BOT_TOKEN", "")),
    )

    @field_validator("POINTS_API_HOST")
    @classmethod
    def validate_api_host(cls, value):
        if not value:
            raise ValueError("POINTS_API_HOST cannot be empty")
        return value.rstrip("/")

    @field_validator("BOT_USER")
    @classmethod
    def validate_bot_user(cls, value):
        if not value:
            raise ValueError("BOT_USER cannot be empty")
        return value
