import { describe, expect, it } from 'vitest'
import {
  ActionsDomainSchema,
  ActionInvocationSchema,
  DEFAULT_ORGANIZATION_MODEL_ACTIONS
} from '../../domains/actions'

describe('actions domain', () => {
  it('keeps the generic core default action catalog empty', () => {
    const domain = ActionsDomainSchema.parse(DEFAULT_ORGANIZATION_MODEL_ACTIONS)

    expect(domain).toEqual({})
  })

  it('accepts entity references in affects', () => {
    expect(() =>
      ActionsDomainSchema.parse({
        'crm.deal.update': {
          id: 'crm.deal.update',
          order: 10,
          label: 'Update deal',
          affects: ['crm.deal']
        }
      })
    ).not.toThrow()
  })

  it('accepts every invocation kind', () => {
    expect(() =>
      ActionInvocationSchema.parse({
        kind: 'slash-command',
        command: '/lead-gen source',
        toolFactory: 'lead-gen-source'
      })
    ).not.toThrow()
    expect(() => ActionInvocationSchema.parse({ kind: 'mcp-tool', server: 'lead-gen', name: 'source' })).not.toThrow()
    expect(() =>
      ActionInvocationSchema.parse({
        kind: 'api-endpoint',
        method: 'POST',
        path: '/api/prospecting/source',
        requestSchema: 'source-request',
        responseSchema: 'source-response'
      })
    ).not.toThrow()
    expect(() =>
      ActionInvocationSchema.parse({ kind: 'script-execution', resourceId: 'scripts.lead-gen-source' })
    ).not.toThrow()
  })

  it('rejects malformed slash commands', () => {
    expect(() => ActionInvocationSchema.parse({ kind: 'slash-command', command: 'lead-gen source' })).toThrow()
  })
})
