import { describe, expect, it } from 'vitest'
import { ContentDefinitionError } from './registry.js'
import { defineContentStatus, normalizeContentStatusDefinition } from './status.js'

describe('content status registry normalization', () => {
  it('supports native review workflow states without conflating visibility', () => {
    const pending = defineContentStatus({
      key: 'pending', label: 'Pending review', published: false, internal: false, excludeFromSearch: true,
      publiclyQueryable: false, showInAdminAll: true, showInAdminStatusFilter: true,
      dateLabel: 'lastModified', transitionInput: 'none', position: 20,
    })
    expect(pending.origin).toBe('code')
    expect(pending.key).toBe('pending')
    expect(pending.published).toBe(false)
    expect(Object.isFrozen(pending)).toBe(true)
  })

  it('rejects contradictory scheduling and publication metadata', () => {
    expect(() => normalizeContentStatusDefinition({
      key: 'review', label: 'Review', published: false, internal: false, excludeFromSearch: true,
      publiclyQueryable: false, showInAdminAll: true, showInAdminStatusFilter: true,
      dateLabel: 'scheduled', transitionInput: 'none',
    })).toThrowError(expect.objectContaining<Partial<ContentDefinitionError>>({ code: 'invalid-definition', field: 'dateLabel' }))

    expect(() => normalizeContentStatusDefinition({
      key: 'review', label: 'Review', published: false, internal: false, excludeFromSearch: true,
      publiclyQueryable: false, showInAdminAll: true, showInAdminStatusFilter: true,
      dateLabel: 'lastModified', transitionInput: 'publishedAt',
    })).toThrowError(expect.objectContaining<Partial<ContentDefinitionError>>({ code: 'invalid-definition', field: 'transitionInput' }))
  })
})
