import { describe, expect, it } from 'vitest'
import type { KbxLookupProvider } from '@kbx/contracts'

const provider: KbxLookupProvider<string> = {
  async search(request) {
    return { items: [{ id: '1', code: '10001', displayName: '대한상사' }], totalCount: 1 }
  },
  async resolveById(id) {
    return id === '1' ? { id: '1', code: '10001', displayName: '대한상사' } : null
  },
  async resolveByCode(code) {
    return code === '10001' ? { id: '1', code: '10001', displayName: '대한상사' } : null
  },
}

describe('KbxLookup provider contract', () => {
  it('never invents an entity: unknown code resolves null', async () => {
    expect(await provider.resolveByCode('UNKNOWN')).toBeNull()
  })

  it('search returns stable domain id + code + displayName', async () => {
    const result = await provider.search({ query: '대한', page: 1, pageSize: 30 })
    expect(result.items[0]).toEqual(expect.objectContaining({ id: '1', code: '10001', displayName: '대한상사' }))
  })
})
