"""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.logoutSuccess": {
        "en": "Logged out successfully",
        "ar": "تم تسجيل الخروج بنجاح",
    },
    "msg.invalidToken": {
        "en": "Invalid or expired token",
        "ar": "الرمز غير صالح أو منتهي الصلاحية",
    },
    "msg.invalidFirebaseToken": {
        "en": "Invalid or expired Firebase token",
        "ar": "رمز Firebase غير صالح أو منتهي الصلاحية",
    },
    "msg.missingUid": {
        "en": "Firebase token missing UID",
        "ar": "رمز Firebase لا يحتوي على معرف المستخدم",
    },
    "msg.uaeOnly": {
        "en": "Only UAE phone numbers (+971) are allowed",
        "ar": "يُسمح فقط بأرقام الهواتف الإماراتية (+971)",
    },
    "msg.profileUpdated": {
        "en": "Profile updated successfully",
        "ar": "تم تحديث الملف الشخصي بنجاح",
    },
    "msg.accountDeleted": {
        "en": "Your account has been deleted",
        "ar": "تم حذف حسابك",
    },

    # Engagement
    "msg.favoriteAdded": {
        "en": "Added to favorites",
        "ar": "تمت الإضافة إلى المفضلة",
    },
    "msg.favoriteRemoved": {
        "en": "Removed from favorites",
        "ar": "تمت الإزالة من المفضلة",
    },
    "msg.notificationRead": {
        "en": "Notification marked as read",
        "ar": "تم تحديد الإشعار كمقروء",
    },

    # Referrals
    "msg.referralApplied": {
        "en": "Referral code applied successfully",
        "ar": "تم تطبيق رمز الإحالة بنجاح",
    },
    "msg.referralInvalid": {
        "en": "Invalid referral code",
        "ar": "رمز الإحالة غير صالح",
    },

    # Stores
    "msg.reviewAdded": {
        "en": "Review added successfully",
        "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))
