from neonize.client import NewClient
from neonize.events import MessageEv, ConnectedEv, event

from neonize.utils import build_jid
import logging
logging.basicConfig(level=logging.DEBUG)


# Initialize the client
client = NewClient("my_first_bot")

@client.event(ConnectedEv)
def on_connected(client: NewClient, event: ConnectedEv):
    print("✅ Bot connected successfully!")
    #print(f"📱 Logged in as: {event.device.User}")

@client.event(MessageEv)
def on_message(client: NewClient, event: MessageEv):
    # Get message text
    text = event.Message.conversation or event.Message.extendedTextMessage.text

    # Respond to specific messages
    if text == "ping":
        client.reply_message("pong! 🏓", event)
    elif text == "hello":
        client.reply_message("Hello! 👋 How can I help you?", event)

# Connect and start the bot
client.connect()
#event.wait()  # Keep the bot running


# Check connection status
if client.is_connected:
    print("Connected!")

# Check login status
if client.is_logged_in:
    print("Logged in!")

# Get your own JID
me = client.get_me()
print(f"My JID: {me.JID.User}")

# Get device information
print(f"Device: {me}")


# Build recipient JID
country_code = "521"
number = "2288472526"
recipient = build_jid(f"{country_code}{number}")

# Send message
#response = client.send_message(recipient, "Hello, World!")

# Enable link preview
response = client.send_message(
    recipient,
    "Check this out: https://hbues.net",
    link_preview=True
)

print(f"Message ID: {response.ID}")
