#!/usr/bin/env python3
"""Send a test message through jb_ai_assistant (requires API key)."""
import odoo
from odoo import api, SUPERUSER_ID

odoo.tools.config.parse_config(['-d', 'odoo', '--no-http'])
registry = odoo.registry('odoo')
with registry.cursor() as cr:
    env = api.Environment(cr, SUPERUSER_ID, {})
    boot = env['jb.ai.conversation'].get_bootstrap()
    assert boot['api_configured'], 'API key not configured'
    conv = env['jb.ai.conversation'].create_conversation()
    result = env['jb.ai.conversation'].send_message(conv['id'], 'Say hello in one short sentence.')
    reply = result['assistant_message']['body']
    print('USER:', result['user_message']['body'])
    print('ASSISTANT:', reply[:200])
    assert reply.strip(), 'Empty assistant reply'
    cr.rollback()
    print('CHAT_TEST_PASSED')
