"""SMS 验证码服务（dev 模式仅打日志，生产接阿里云/腾讯云）"""

import logging

from app.config import settings

logger = logging.getLogger(__name__)

SMS_PROVIDER = settings.SMS_PROVIDER or ""


def is_dev_mode() -> bool:
    return not SMS_PROVIDER or SMS_PROVIDER == "mock"


async def send_sms(phone: str, code: str) -> bool:
    """发送短信验证码

    生产环境调用 SMS 供应商 API；开发模式将验证码打印到日志。
    """
    if is_dev_mode():
        logger.info("[DEV SMS] To %s: Your verification code is %s", phone, code)
        return True

    # TODO: 对接实际 SMS 供应商
    # if SMS_PROVIDER == "aliyun":
    #     from aliyunsdkcore.client import AcsClient
    #     ...
    # elif SMS_PROVIDER == "tencent":
    #     from tencentcloud.sms.v20210111 import sms_client
    #     ...
    logger.warning("SMS provider %s not yet implemented, falling back to log", SMS_PROVIDER)
    logger.info("[FALLBACK SMS] To %s: Your verification code is %s", phone, code)
    return True
