# -*- coding: utf-8 -*-
import json, urllib.request, urllib.error

TOKEN = "CGHABG0SKVLELHZXPXYFYXIGURNQGGSQGXFXDXWGWMHZLLVPMLDZWHORXEUIBVUO"
BASE = "https://botapi.rubika.ir/v3/" + TOKEN

def post(url, data=None):
    if data is None: data = {}
    try:
        body = json.dumps(data).encode('utf-8')
        req = urllib.request.Request(url, data=body, method='POST')
        req.add_header('Content-Type', 'application/json')
        with urllib.request.urlopen(req, timeout=20) as r:
            return r.read().decode('utf-8')
    except urllib.error.HTTPError as e:
        return "HTTP " + str(e.code) + ": " + e.read().decode('utf-8', errors='ignore')[:500]
    except Exception as e:
        return "ERR: " + str(e)

print("=" * 60)
print("TEST 1: getUpdates بدون پارامتر")
print("=" * 60)
print(post(BASE + "/getUpdates", {}))
print()

print("=" * 60)
print("TEST 2: getUpdates با start_id=0")
print("=" * 60)
print(post(BASE + "/getUpdates", {"start_id": "0"}))
print()

print("=" * 60)
print("TEST 3: getUpdates با start_id خالی")
print("=" * 60)
print(post(BASE + "/getUpdates", {"start_id": ""}))
print()

print("=" * 60)
print("TEST 4: getUpdates با start_id عدد صحیح 0")
print("=" * 60)
print(post(BASE + "/getUpdates", {"start_id": 0}))
print()

print("=" * 60)
print("TEST 5: getUpdates با limit")
print("=" * 60)
print(post(BASE + "/getUpdates", {"start_id": "0", "limit": 10}))
print()

print("=" * 60)
print("TEST 6: getChats (لیست چت‌ها)")
print("=" * 60)
print(post(BASE + "/getChats", {}))
print()

print("=" * 60)
print("TEST 7: getChats با start_id")
print("=" * 60)
print(post(BASE + "/getChats", {"start_id": "0"}))
print()