"""SQL query strings for the Devin CLI sessions and message_nodes tables."""

LIST_SESSIONS = (
    "SELECT id, title, working_directory, last_activity_at, created_at "
    "FROM sessions ORDER BY last_activity_at DESC LIMIT ?"
)

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

GET_SESSION = (
    "SELECT id, title, working_directory, last_activity_at, created_at, "
    "model, backend_type, agent_mode, metadata "
    "FROM sessions WHERE id = ?"
)

GET_MESSAGE_NODES = (
    "SELECT id, parent_id, chat_message, created_at "
    "FROM message_nodes WHERE session_id = ? ORDER BY created_at ASC"
)

DETECT_BY_CWD = (
    "SELECT id FROM sessions WHERE working_directory = ? ORDER BY last_activity_at DESC LIMIT 1"
)

DETECT_MOST_RECENT = "SELECT id FROM sessions ORDER BY last_activity_at DESC LIMIT 1"
