"""SQL query strings used by the OpenCode session adapter.

OpenCode stores sessions in a SQLite database with three tables:

- ``session``: id (TEXT PK), title (TEXT), directory (TEXT),
  time_created (TEXT), time_updated (TEXT)
- ``message``: id (TEXT PK), session_id (TEXT FK), data (TEXT JSON blob),
  time (TEXT)
- ``part``: id (TEXT PK), data (TEXT JSON blob), time (TEXT)
"""

LIST_SESSIONS = (
    "SELECT id, title, directory, time_updated, time_created "
    "FROM session ORDER BY time_updated DESC LIMIT ?"
)

COUNT_MESSAGES = "SELECT COUNT(*) FROM message WHERE session_id = ?"

GET_SESSION = (
    "SELECT id, title, directory, time_updated, time_created, "
    "model, slug, cost, tokens_input, tokens_output, tokens_reasoning, metadata "
    "FROM session WHERE id = ?"
)

GET_MESSAGES = "SELECT id, data, time FROM message WHERE session_id = ? ORDER BY time ASC"

GET_PARTS = "SELECT id, data FROM part WHERE id IN ({placeholders})"

DETECT_BY_CWD = "SELECT id FROM session WHERE directory = ? ORDER BY time_updated DESC LIMIT 1"

DETECT_MOST_RECENT = "SELECT id FROM session ORDER BY time_updated DESC LIMIT 1"
