// Seed a completed chat_sessions row for TEST_PHONE so the bestie history
// list isn't empty when the Stage 8 flow opens it. Pairs the customer with
// the most-recently-online mitra in the dev DB.
//
// Hits the dev-only /internal/_test/seed-history-session endpoint.
const phone = TEST_PHONE
const url = BACKEND_INTERNAL_URL || 'http://localhost:3001'
const resp = http.post(`${url}/internal/_test/seed-history-session`, {
  body: JSON.stringify({ phone }),
  headers: { 'Content-Type': 'application/json' },
})
if (resp.status !== 200) {
  throw new Error(`seed-history-session failed (${resp.status}): ${resp.body}`)
}
const data = json(resp.body)
output.SESSION_ID = data.session_id
output.MITRA_ID = data.mitra_id
output.MITRA_NAME = data.mitra_name
// Regex-escaped variant for Maestro `text:` selectors (which do FULL-string
// regex match). Display names can contain `+` (phone-as-name), `.`, etc.
// which break selectors otherwise.
output.MITRA_NAME_RE = data.mitra_name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
