from pathlib import Path

from ai_archive.importers import import_chatgpt, import_claude


def test_import_chatgpt_pages(tmp_path: Path):
    raw = tmp_path / "raw"
    (raw / "Project").mkdir(parents=True)
    (raw / "Project" / "Note.md").write_text("# Note\n\nHello world", encoding="utf-8")
    conversations = import_chatgpt(raw)
    assert len(conversations) == 1
    assert conversations[0].title == "Note"
    assert conversations[0].messages[0].content.startswith("# Note")


def test_import_claude_conversations(tmp_path: Path):
    p = tmp_path / "conversations.json"
    p.write_text('[{"uuid":"1","name":"Example","created_at":"2024-01-01T00:00:00Z","updated_at":"2024-01-01T00:00:00Z","chat_messages":[{"uuid":"m1","sender":"human","content":[{"type":"text","text":"Hi"}],"created_at":"2024-01-01T00:00:00Z"},{"uuid":"m2","sender":"assistant","content":[{"type":"text","text":"Hello"}],"created_at":"2024-01-01T00:01:00Z"}]}]', encoding="utf-8")
    conversations = import_claude(p)
    assert len(conversations) == 1
    convo = conversations[0]
    assert convo.title == "Example"
    assert convo.messages[0].role == "user"
    assert convo.messages[1].role == "assistant"
