import requests
import json

class SanjakBot:
    def __init__(self, token):
        self.token = token
        self.api_url = f"https://api.telegram.org/bot{token}/"

    def _post(self, method, data):
        """دالة داخلية عشان منكررش كود الاتصال كل شوية"""
        url = self.api_url + method
        try:
            return requests.post(url, data=data).json()
        except Exception as e:
            return {"ok": False, "error": str(e)}

    # --- أدوات أساسية ---
    
    def get_updates(self, offset=None):
        url = self.api_url + "getUpdates"
        params = {'timeout': 30, 'offset': offset}
        return requests.get(url, params=params).json()

    def send_message(self, chat_id, text):
        return self._post("sendMessage", {"chat_id": chat_id, "text": text})

    # --- أدوات مفيدة (إضافات عمر سنجق) ---

    def send_photo(self, chat_id, photo_url, caption=""):
        """
        ميزة مفيدة 1: إرسال صورة برابط مباشر
        بدل ما المستخدم يكتب كود طويل، يستخدم الدالة دي
        """
        data = {
            "chat_id": chat_id,
            "photo": photo_url,
            "caption": caption
        }
        return self._post("sendPhoto", data)

    def send_buttons(self, chat_id, text, buttons):
        """
        ميزة مفيدة 2: إرسال أزرار بسهولة
        المستخدم هيديك قائمة بأسماء الأزرار، وأنت هتحولها للشكل المعقد بتاع تلجرام
        buttons example: [["Google", "https://google.com"], ["Help", "callback_help"]]
        """
        # هنا السحر: بنحول القائمة البسيطة لـ JSON معقد
        keyboard = []
        for btn in buttons:
            text_label, action = btn[0], btn[1]
            if "http" in action:
                # زرار رابط
                keyboard.append([{"text": text_label, "url": action}])
            else:
                # زرار عادي (Callback)
                keyboard.append([{"text": text_label, "callback_data": action}])
        
        reply_markup = json.dumps({"inline_keyboard": keyboard})
        
        data = {
            "chat_id": chat_id,
            "text": text,
            "reply_markup": reply_markup
        }
        return self._post("sendMessage", data)


# ==========================
# قسم القرآن الكريم (Cloud)
# ==========================
class Quran:
    # قاعدة البيانات السحابية
    _data = {
    "yasser": {
        "1": "CQACAgQAAxkBAAIJD2l3jaby7FH95_peN71Gj7AaeXuFAAJ7IgACSRe5U60ukB_l6gLwOAQ",
        "2": "CQACAgQAAxkBAAIJFWl3kYMPRZgxmC2PkwILpQlbFAMjAAJ-IgACSRe5Uzu1oSc0p1g2OAQ",
        "3": "CQACAgQAAxkBAAIJL2l3m6vtnbrWGxZ8Op1Z34dpc2bTAAKOIgACSRe5UzDBQkcNIvfAOAQ",
        "4": "CQACAgQAAxkBAAIJPml3oyFpL35dIm7t8Gd7HGv_vIMkAAKrIgACSRe5U98r8nmBwW_jOAQ",
        "5": "CQACAgQAAxkBAAIJGml3lat98tjayqj8vUtyeJbXwojkAAKGIgACSRe5U07r_LcKvvl1OAQ",
        "6": "CQACAgQAAxkBAAIJH2l3lasLxW_TAeYT9R4OY3yjl_chAAKLIgACSRe5U4t7ppxwpfJJOAQ",
        "7": "CQACAgQAAxkBAAIJNWl3m6ujOacrdiuWa1U405ecsroZAAKVIgACSRe5UzHWhDweSsQlOAQ",
        "8": "CQACAgQAAxkBAAIJP2l3oyE-c9t0m0sUvlANURJyCjAhAAKsIgACSRe5U6tmFOPFWaBbOAQ",
        "9": "CQACAgQAAxkBAAIJN2l3m6vfFr8vZ0Zky5r9-t0JohJ5AAKXIgACSRe5U5e-Pv_iWUtTOAQ",
        "10": "CQACAgQAAxkBAAIJHWl3las_eOdI8QqfQIrnkBySad-zAAKJIgACSRe5UxjYcvLb_IT2OAQ",
        "11": "CQACAgQAAxkBAAIJMGl3m6ur_phfT9lkmx9dGYv9lUb1AAKPIgACSRe5UxU7hTvA3fqfOAQ",
        "12": "CQACAgQAAxkBAAIJO2l3oyEdeKNiI5tJDAs6jx75xxPSAAKeIgACSRe5U8RyJlvBlDN1OAQ",
        "13": "CQACAgQAAxkBAAIJOml3oyGMwisC7VgOudYd4G2srh2mAAKbIgACSRe5U3-C-spi4QrvOAQ",
        "14": "CQACAgQAAxkBAAIJGGl3lavyHwyTcXOgHFKwGvqpFEghAAKAIgACSRe5U0ZOQF4yqB9WOAQ",
        "15": "CQACAgQAAxkBAAIJHGl3lauv2q2VMI-G_F-mQGMav_qmAAKIIgACSRe5U97txXmiWQjvOAQ",
        "16": "CQACAgQAAxkBAAIJMWl3m6tjvkjluQi2R4ND1N-1GlUBAAKQIgACSRe5U2j-7WEev33XOAQ",
        "17": "CQACAgQAAxkBAAIJPGl3oyFBWB5i3HQPhrOBh2vXIe-uAAKnIgACSRe5U0sjstw01zCGOAQ",
        "18": "CQACAgQAAxkBAAIJG2l3lasq0smeMtzQsKX84H1We5UhAAKHIgACSRe5U3Rfa5nbPTn1OAQ",
        "19": "CQACAgQAAxkBAAIJLml3m6sG_m5RK-LQvFH43pD_6bf8AAKNIgACSRe5UzL2flZ-LoGyOAQ",
        "20": "CQACAgQAAxkBAAIJNml3m6sfNEOOXRIRfPBuwg8cilMeAAKWIgACSRe5Uz3t6u_beqRJOAQ",
        "21": "CQACAgQAAxkBAAIJOGl3oyFKdOZoXXGDF-vhRAN1OJrEAAKYIgACSRe5U9yy4EAOMjyGOAQ",
        "22": "CQACAgQAAxkBAAIJF2l3lau-upLzDDI5MVkHbeFl9fQiAAJ_IgACSRe5U0ncZkwlDVFBOAQ",
        "23": "CQACAgQAAxkBAAIJIGl3latzldZ_TV68Y3wLlT3jsnNUAAKMIgACSRe5UzjmkkF4ZHkYOAQ",
        "24": "CQACAgQAAxkBAAIJNGl3m6vtz-HXEXskDLC9kDm_HKbfAAKTIgACSRe5U6gl-eAdeHIcOAQ",
        "25": "CQACAgQAAxkBAAIJMml3m6s4bIfzIzi0EJ1YkmfvaLxeAAKRIgACSRe5U-hkXEg5Eb2UOAQ",
        "26": "CQACAgQAAxkBAAIJOWl3oyElDT9ApKQNAmp3a7cAAWfInAACmiIAAkkXuVNUzwnqeM2YeTgE",
        "27": "CQACAgQAAxkBAAIJGWl3lauxu6dssrpBd6PkvfjvNQkMAAKEIgACSRe5Ux7mUda_iV-GOAQ",
        "28": "CQACAgQAAxkBAAIJHml3lavgu8gZw264VY1gV96JP7_tAAKKIgACSRe5U1NI2fGgLwABUDgE",
        "29": "CQACAgQAAxkBAAIJM2l3m6sZ_exOU52wPfzru5eL-INZAAKSIgACSRe5U6CptxazD9dnOAQ",
        "30": "CQACAgQAAxkBAAIJPWl3oyFw7Sa_au-bZtgBGH1uhv7tAAKoIgACSRe5U7CpH4-5ivvsOAQ",
        "31": "CQACAgQAAxkBAAIJ5Wl3qhwEyVlNI5chanwVeTXfOmp5AALkGwACw6LAU2XT39PuirQeOAQ",
        "32": "CQACAgQAAxkBAAIJ52l3qiqkXfH76k-TOwUsG8cwr2ncAALxGwACw6LAU3yvRryC41h3OAQ",
        "33": "CQACAgQAAxkBAAIJ6Wl3qjBPMCBvsBuyTVx5yWK2uafPAALqGwACw6LAUysH19xQ4CdyOAQ",
        "34": "CQACAgQAAxkBAAIJ62l3qj3LGERsGxA2I4wl07Dh15_gAAL2GwACw6LAU3REWS_K6NV4OAQ",
        "35": "CQACAgQAAxkBAAIJ7Wl3qki2p7ysPk58jdJVtROeH5LQAALoGwACw6LAUxXax5g-aghhOAQ",
        "36": "CQACAgQAAxkBAAIJ72l3qlCe9qQrhOqdjLBL1ASEVAV4AALvGwACw6LAUxipzak3Cxq8OAQ",
        "37": "CQACAgQAAxkBAAIJ8Wl3qlemJtylCdtSjFvVHM1AeNcUAALmGwACw6LAUwPv2nEgMBUYOAQ",
        "38": "CQACAgQAAxkBAAIJ82l3qmVuR5noo61P1Ag_XalaP9WYAALgGwACw6LAU3DK0pl-UwkhOAQ",
        "39": "CQACAgQAAxkBAAIJ9Wl3qmxxGovtLxFJDHNqxCyApCpPAALtGwACw6LAU6Uyvvnm9ClAOAQ",
        "40": "CQACAgQAAxkBAAIJ92l3qnNmJlf9HvY3x2VEcFGn7jcEAALsGwACw6LAUxUKkK2aDTztOAQ",
        "41": "CQACAgQAAxkBAAIJ-Wl3qnogVAU1TkZcj-8838p0hG6jAALhGwACw6LAU_nO1P09RZQ9OAQ",
        "42": "CQACAgQAAxkBAAIJ-2l3qpI8TnEjd4gGcAOSPPM7NWbPAALlGwACw6LAU0oWxjnbmt5EOAQ",
        "43": "CQACAgQAAxkBAAIJ_Wl3qpnlCuxGFC9KaxVmVkYZsbvlAALwGwACw6LAU8qDreVkm-saOAQ",
        "44": "CQACAgQAAxkBAAIJ_2l3qp5EMiRhO5Y7FWdGgkvUqcriAALnGwACw6LAU05ImrQ_yyDNOAQ",
        "45": "CQACAgQAAxkBAAIKAWl3qqT3fheVaG0WkfprRDtRKWZZAALuGwACw6LAUyA0lo6uD1T6OAQ",
        "46": "CQACAgQAAxkBAAIKA2l3qrJ1CTB5g951v6Lsz9GwVxY4AALpGwACw6LAUyq9a9QRTtHGOAQ",
        "47": "CQACAgQAAxkBAAIKBWl3quHiOMtFdmZIrnPrz8D_IVwUAAL4GwACw6LAUyq526_jFrUgOAQ",
        "48": "CQACAgQAAxkBAAIKB2l3qwOqn7_a_vjIV6c3akdhHqxJAALjGwACw6LAUw4oaa2newABijgE",
        "49": "CQACAgQAAxkBAAIKCWl3qyTvXV7TsZ8JwNzcKAUa5bXwAALyGwACw6LAU67k6bb240WTOAQ",
        "50": "CQACAgQAAxkBAAIKC2l3qytQinxftC3qJVnwAAEofKxu-gAC4hsAAsOiwFMhEZwNwFPZ9jgE",
        "51": "CQACAgQAAxkBAAIKDWl3qzL7wU2mbJ7PwroRg7Kfm57sAAIXHAACw6LAU9k_mPByVBIfOAQ",
        "52": "CQACAgQAAxkBAAIKD2l3q0VmJYnEUunJ5Fu9aFkN7kbNAAIaHAACw6LAU2xTHaPHUg3AOAQ",
        "53": "CQACAgQAAxkBAAIKEWl3q02ryFIcv9zRBmvH3MdPN6wtAAIkHAACw6LAU8jIq8Moso-wOAQ",
        "54": "CQACAgQAAxkBAAIKE2l3q1MXjeiek923wXSzBm7Z8kIvAAIrHAACw6LAU3qrx0fJ7XzaOAQ",
        "55": "CQACAgQAAxkBAAIKFWl3q1qiV8S8FtuyPVyA15c16zALAAItHAACw6LAU5yMwpd66v0dOAQ",
        "56": "CQACAgQAAxkBAAIKF2l3q2cigt5qYw-luEV9SmadmBbKAAIxHAACw6LAUz6PfaOFIauZOAQ",
        "57": "CQACAgQAAxkBAAIKGWl3q3BMedgGpMjoWV4PF17PIr7JAAL6GwACw6LAU9JwAX4kiCBwOAQ",
        "58": "CQACAgQAAxkBAAIKG2l3q3qsSQEHhWHjvuCdZKcuXjeWAAMcAALDosBTyiuDrj1QFvg4BA",
        "59": "CQACAgQAAxkBAAIKHWl3q4HTE9p15PucS_6wKikR5Bl0AAIOHAACw6LAUzEQH96LlRMwOAQ",
        "60": "CQACAgQAAxkBAAIKH2l3q5FY1k_e5EU4KeLW-yd8RxZoAAI1HAACw6LAU76D2sSR1sbyOAQ",
        "61": "CQACAgQAAxkBAAIKIWl3q5jVdAABqQjIxspyg5EnOujpZAACHhwAAsOiwFPWSHkeGL4pQTgE",
        "62": "CQACAgQAAxkBAAIKI2l3q6vh3iSomzHL9D5oIRkh_9tkAAInHAACw6LAU6xFibwCUWquOAQ",
        "63": "CQACAgQAAxkBAAIKJWl3q7TSyKQPc-Vs9Yxlcyn7uakuAAIMHAACw6LAUw_rCw12qQlEOAQ",
        "64": "CQACAgQAAxkBAAIKJ2l3q87BhAb9B_frrySPNRG8dWjSAAISHAACw6LAU9JYeRLmp-65OAQ",
        "65": "CQACAgQAAxkBAAIKKWl3q9Zg3M4sjv4E9oQVIfFgiR48AAL8GwACw6LAU58QpYHkvYSDOAQ",
        "66": "CQACAgQAAxkBAAIKK2l3q-QJMKbIHFyUVu2rfyOCqPbOAAIDHAACw6LAU670GpdQIlO_OAQ",
        "67": "CQACAgQAAxkBAAIKLWl3q-5tt7M774g0J2u2n5SN6qQ-AAIEHAACw6LAUxaICQpqf5B2OAQ",
        "68": "CQACAgQAAxkBAAIKL2l3q_UKtn0hbTi8rW0-V2mHyndEAAIqHAACw6LAU-Vyg9Gl0mhiOAQ",
        "69": "CQACAgQAAxkBAAIKMWl3rAKhD3p3IXRj3dAEmNHfbTYmAAIwHAACw6LAU0Eb1XF9ME9BOAQ",
        "70": "CQACAgQAAxkBAAIKM2l3rCO5UMJ3Hw80LxP_ST-Bhg9RAAIjHAACw6LAU1e5kTA-jbG3OAQ",
        "71": "CQACAgQAAxkBAAIKNWl3rDJo8TioxNKrqJIQ8GwQZfvBAAIoHAACw6LAU7j0XLKHvk44OAQ",
        "72": "CQACAgQAAxkBAAIKN2l3rOgSNKI6J1HniwRSbnKr1M-FAAIvHAACw6LAU7PfnEYKR5keOAQ",
        "73": "CQACAgQAAxkBAAIKOWl3rPsjcL2M34FpnIQv_1h3uC3DAAI0HAACw6LAUzgBMNoBMW0rOAQ",
        "74": "CQACAgQAAxkBAAIKO2l3rQH8K8AXnTR_PPOoIv47SOKZAAL_GwACw6LAU5aZ6joIRy0XOAQ",
        "75": "CQACAgQAAxkBAAIKPWl3rQhZj9o7DyrNWh8a35zZiEXSAAIIHAACw6LAU1N-otFtvxLhOAQ",
        "76": "CQACAgQAAxkBAAIKP2l3rRQeFcseJYkgSI0J-rSM2oE4AAILHAACw6LAU7QJ5u1EYj8uOAQ",
        "77": "CQACAgQAAxkBAAIKQWl3rR4tiscE2lM3uZcEjTbaf-4WAAIUHAACw6LAUyelmd-P8ej9OAQ",
        "78": "CQACAgQAAxkBAAIKQ2l3rTClk-esjqII6vhg2XxWS3JmAAIfHAACw6LAUzajKswdKsH3OAQ",
        "79": "CQACAgQAAxkBAAIKRWl3rUlJeZQfqgI81WIAAW2CDD7RZQACJhwAAsOiwFMtXZPMvy9pwzgE",
        "80": "CQACAgQAAxkBAAIKR2l3rVCsa7VVhq69xM5RgkpVTohMAAIGHAACw6LAUy6cRwZmaJCXOAQ",
        "81": "CQACAgQAAxkBAAIKSWl3rVrDAAHSyo2L-FPF5cRAGryXsQACFRwAAsOiwFNs3KOs5yvw1DgE",
        "82": "CQACAgQAAxkBAAIKS2l3rWHjcM55SmdQoENsVg-86m_xAAL7GwACw6LAU2Q-OeHEEpsZOAQ",
        "83": "CQACAgQAAxkBAAIKTWl3rWwkscSS7h73tm92vj1kCyOXAAIBHAACw6LAU33j69qtOg8jOAQ",
        "84": "CQACAgQAAxkBAAIKT2l3rYNWzcC0w1844aLFOcYwCBJLAAIJHAACw6LAU0_dFG0CIapDOAQ",
        "85": "CQACAgQAAxkBAAIKUWl3rm-hiFF7JHpx1i7fZJTSn6DwAAIsHAACw6LAU55sH8b_uCMtOAQ",
        "86": "CQACAgQAAxkBAAIKU2l3rnfx2Q8fBfYfdFA7LJlXu1YSAAI4HAACw6LAU72wEbDolGMYOAQ",
        "87": "CQACAgQAAxkBAAIKVWl3roE3LYFL5nUwSvYHy2GQ9txyAAIhHAACw6LAU7SH7WkGb1xDOAQ",
        "88": "CQACAgQAAxkBAAIKV2l3rohe8pBSmEJ8RNDbHoWA_bGtAAIiHAACw6LAUyQMa9AY8dHBOAQ",
        "89": "CQACAgQAAxkBAAIKWWl3ro-ivY57m7SCCMJpb76e2A8nAAIPHAACw6LAUwVb_xxyIkaOOAQ",
        "90": "CQACAgQAAxkBAAIKW2l3rpk506xIGIav9NL0vo694_irAAL9GwACw6LAUzej59lrOR0qOAQ",
        "91": "CQACAgQAAxkBAAIKXWl3rqB5NbCsPAYlcWhOw9v0-lS2AAIzHAACw6LAUyERNML59mxvOAQ",
        "92": "CQACAgQAAxkBAAIKX2l3rqfCP24jTpYSofc9EtnaaKHzAAIFHAACw6LAU4Sed0fvYE03OAQ",
        "93": "CQACAgQAAxkBAAIKYWl3rq3jFyoUxz2fmoLL0nPwN2bJAAINHAACw6LAU4p9ScF-8Av_OAQ",
        "94": "CQACAgQAAxkBAAIKY2l3rvJda0uD8VTOyybAwgABnoBwsQACExwAAsOiwFNmhAQFiGpvoTgE",
        "95": "CQACAgQAAxkBAAIKZWl3rvoxS--C5RvC0Pg7sWoEIO33AAIbHAACw6LAU1KyEZ0Ipmt6OAQ",
        "96": "CQACAgQAAxkBAAIKZ2l3rwdU2Hm1KvVlhowsw4kc89ODAAIgHAACw6LAU7qdJmX1XchzOAQ",
        "97": "CQACAgQAAxkBAAIKaWl3rxBGynY_VyecgwhYee9AA3OtAAIlHAACw6LAUzIwS8rljouIOAQ",
        "98": "CQACAgQAAxkBAAIKa2l3ryvgFE99sj7FeeazG6926hR_AAIuHAACw6LAU790QtpWSPajOAQ",
        "99": "CQACAgQAAxkBAAIKbWl3rzIMc-7A0ZI2rcDSd8epKsglAAI2HAACw6LAU4uKi00JskaEOAQ",
        "100": "CQACAgQAAxkBAAIKb2l3rzxXkRzdRwABil8izPDpiX5sSAACEBwAAsOiwFNrf1waHWswkDgE",
        "101": "CQACAgQAAxkBAAIKjWl377R0hXTn1VzObWLL5Nty0811AAIZHAACw6LAU8TVi9R04veFOAQ",
        "102": "CQACAgQAAxkBAAIKc2l3r3AEc7Ejcr9w7u--WeNVTecIAAL-GwACw6LAUyhkEaLrmQAB_zgE",
        "103": "CQACAgQAAxkBAAIKdWl3r31Xd6FbVpwoZB8dJpPgzZbbAAIHHAACw6LAU6a-lLXY7fJ4OAQ",
        "104": "CQACAgQAAxkBAAIKd2l3r4UTjnMo4oDbokxWB1tctc4TAAICHAACw6LAU6TKAAEP3rhHQTgE",
        "105": "CQACAgQAAxkBAAIKeWl3r4uDIKCvJwlMZUv10Q498LtWAAIpHAACw6LAU8nvr7hPmo0GOAQ",
        "106": "CQACAgQAAxkBAAIKe2l3r7fdq0LuqIvTb-62dvB2tfyiAAIyHAACw6LAU3zIDA9AedWMOAQ",
        "107": "CQACAgQAAxkBAAIKfWl3sAZae-S3nYnwegfATChM2ghAAAIdHAACw6LAUyBVdYDFrm39OAQ",
        "108": "CQACAgQAAxkBAAIKf2l3sAz5dVpDvz2vMLY-roTzeUxsAAIcHAACw6LAU34iPVndMzFtOAQ",
        "109": "CQACAgQAAxkBAAIKgWl3sBPhCIRlFhdQdXllXcBhWQStAAIWHAACw6LAU8rcY6VrnVjrOAQ",
        "110": "CQACAgQAAxkBAAIKg2l3sBwBYrJPH1u_MKb-iwTlelPUAAI3HAACw6LAUzLSPChzCj3bOAQ",
        "111": "CQACAgQAAxkBAAIKcWl3r2RMgYLyNaGuRuJLfnxGS79rAAL5GwACw6LAU8vUIoS7J_7BOAQ",
        "112": "CQACAgQAAxkBAAIKh2l3sDgBQZcVyt5Kz4dQ3D3K728qAAIKHAACw6LAU5ceTrkEgsw2OAQ",
        "113": "CQACAgQAAxkBAAIKiWl3sE6yOKpKeyIlQyCB32NRaiNOAAIRHAACw6LAU8lX4qfaFru3OAQ",
        "114": "CQACAgQAAxkBAAIKi2l3tX_9d5w3bv5VgT8g0cZQE8f3AAIYHAACw6LAU8yNJlHhEzJROAQ"
    }
}

    @staticmethod
    def get_audio_id(reader_key, surah_number):
        '''
        جلب معرف الملف الصوتي
        :param reader_key: مفتاح القارئ (مثل 'yasser')
        :param surah_number: رقم السورة (1-114)
        '''
        reader_data = Quran._data.get(reader_key)
        if reader_data:
            return reader_data.get(str(surah_number))
        return None

    @staticmethod
    def get_available_readers():
        '''إرجاع قائمة القراء المتاحين'''
        return list(Quran._data.keys())
