import asyncio
import json
import sys

import httpx

from app.core.settings import get_settings

if sys.stdout and hasattr(sys.stdout, "reconfigure"):
    sys.stdout.reconfigure(encoding="utf-8")


async def check_stealth():
    settings = get_settings()
    api_key = settings.openrouter_api_key
    headers = {
        "Authorization": f"Bearer {api_key}",
        "HTTP-Referer": "https://github.com/dscons",
        "X-Title": "DSCons Operations",
    }
    payload = {
        "model": "stealth/ox-alpha",
        "messages": [
            {
                "role": "system",
                "content": "You are QS Engineer Quỳnh. Output JSON only.",
            },
            {
                "role": "user",
                "content": "Bóc tách khối lượng bản vẽ Nhà Văn Hóa Đại Thắng (NVH - DAI THANG). Xuất JSON với items, drawing_code, drawing_title.",
            },
        ],
        "max_tokens": 1000,
    }
    async with httpx.AsyncClient(timeout=30) as client:
        res = await client.post(
            "https://openrouter.ai/api/v1/chat/completions",
            json=payload,
            headers=headers,
        )
        print("Status:", res.status_code)
        data = res.json()
        print("Response JSON:", json.dumps(data, indent=2, ensure_ascii=False))


if __name__ == "__main__":
    asyncio.run(check_stealth())
