import { describe, expect, it } from 'vitest'
import * as helpdesk from './index.js'
import { appendTransition, listTransitions } from './transitions.js'
import { createTestDb } from './test-fixture.js'

describe('appendTransition / listTransitions', () => {
  it('is append-only — no update or delete exports exist', () => {
    expect(helpdesk).not.toHaveProperty('updateTransition')
    expect(helpdesk).not.toHaveProperty('deleteTransition')
    expect(typeof helpdesk.appendTransition).toBe('function')
  })

  it('scopes transition reads to (parentType, parentId)', async () => {
    const db = await createTestDb()

    await appendTransition(db, { parentType: 'ticket', parentId: '7' }, {
      fromStatus: 'open',
      toStatus: 'pending',
      actorId: 'agent-1',
    })
    await appendTransition(db, { parentType: 'case', parentId: '7' }, {
      fromStatus: 'new',
      toStatus: 'review',
      actorId: 'agent-2',
    })

    const ticketRows = await listTransitions(db, { parentType: 'ticket', parentId: '7' })
    expect(ticketRows).toHaveLength(1)
    expect(ticketRows[0]?.toStatus).toBe('pending')
  })
})
