# -*- coding: utf-8 -*-
"""ابزارهای کمکی: تبدیل اعداد فارسی، فرمت قیمت، تبدیل تتر."""
import config

_EN_TO_FA = str.maketrans("0123456789", "۰۱۲۳۴۵۶۷۸۹")
_FA_TO_EN = str.maketrans("۰۱۲۳۴۵۶۷۸۹", "0123456789")


def fa_num(s) -> str:
    """اعداد انگلیسی → فارسی."""
    return str(s).translate(_EN_TO_FA)


def en_num(s) -> str:
    """اعداد فارسی → انگلیسی (برای پردازش ورودی کاربر)."""
    return str(s).translate(_FA_TO_EN)


def format_toman(amount: int) -> str:
    """۵000000 → «۵,۰۰۰,۰۰۰ تومان»"""
    return f"{fa_num(f'{amount:,}')} تومان"


def toman_to_usdt(amount_toman: int) -> float:
    """تبدیل تومان به تتر بر اساس نرخ پیکربندی‌شده."""
    return round(amount_toman / config.TOMAN_PER_USDT, 2)


def short(text: str, n: int = 24) -> str:
    return text if len(text) <= n else text[: n - 1] + "…"
