import sys
sys.path.insert(0, '.')
from src.app_controller import AppController
from src.result_types import OK, Result, ErrorInfo, ErrorKind
import inspect

ctrl = AppController()
print('Has _handle_generate_send:', hasattr(ctrl, '_handle_generate_send'))

src = inspect.getsource(ctrl._handle_generate_send)
print('Has Result[None] annotation:', 'Result[None]' in src)
print('Has return OK:', 'return OK' in src)
print('Has event_queue.put:', 'event_queue.put' in src)
print('Has ai_status sending:', "ai_status = \"sending...\"" in src)
print('Has submit_io:', 'submit_io(worker)' in src)

# Check _run_event_loop
src_loop = inspect.getsource(ctrl._run_event_loop)
print('_run_event_loop has _process_event_queue:', '_process_event_queue()' in src_loop)
print('_run_event_loop position of _process_event_queue:')
for i, line in enumerate(src_loop.split('\n')):
    if '_process_event_queue' in line:
        print(f'  Line {i}: {line!r}')
