"""Bilingual API response messages (English / Arabic)."""

MESSAGES = {
    # General
    "success": {
        "en": "Success",
        "ar": "تم بنجاح",
    },
    "error": {
        "en": "An error occurred",
        "ar": "حدث خطأ",
    },
    "not_found": {
        "en": "Not found",
        "ar": "غير موجود",
    },
    "unauthorized": {
        "en": "Authentication required",
        "ar": "يجب تسجيل الدخول",
    },
    "forbidden": {
        "en": "You do not have permission",
        "ar": "ليس لديك صلاحية",
    },
    "validation_error": {
        "en": "Validation error",
        "ar": "خطأ في البيانات",
    },

    # Auth
    "msg.loginSuccess": {
        "en": "Login successful",
        "ar": "تم تسجيل الدخول بنجاح",
    },
    "msg.tokenRefreshed": {
        "en": "Token refreshed",
        "ar": "تم تحديث الرمز",
    },

    # Suppliers
    "msg.documentUploaded": {
        "en": "Document uploaded",
        "ar": "تم رفع المستند",
    },
    "msg.paymentLinkCreated": {
        "en": "Payment link created",
        "ar": "تم إنشاء رابط الدفع",
    },
    "msg.supplierLinked": {
        "en": "Supplier linked to user",
        "ar": "تم ربط المورّد بالمستخدم",
    },
    "msg.userNotFound": {
        "en": "User not found",
        "ar": "المستخدم غير موجود",
    },
    "msg.webhookReceived": {
        "en": "Webhook processed",
        "ar": "تم معالجة الإشعار",
    },
}


def get_message(key, lang="en"):
    """
    Get a translated message by key.
    Falls back to English, then returns the key itself if not found.
    """
    msg = MESSAGES.get(key)
    if msg is None:
        return key
    return msg.get(lang, msg.get("en", key))
