import { describe, expect, it } from 'vitest'
import { getScreenTemplate, screenTemplateCatalogue } from '../catalogue'
import type { StandardScreenState } from '../../contracts/screenContract'

describe('screen template catalogue', () => {
  it('defines all twelve screen contracts without duplicate IDs or components', () => {
    expect(screenTemplateCatalogue).toHaveLength(12)
    expect(new Set(screenTemplateCatalogue.map(x => x.id)).size).toBe(12)
    expect(new Set(screenTemplateCatalogue.map(x => x.component)).size).toBe(12)
  })

  it('requires evidence and anti-pattern declarations for every template', () => {
    for (const template of screenTemplateCatalogue) {
      expect(template.mandatoryEvidence.length).toBeGreaterThan(0)
      expect(template.mandatoryStates.length).toBeGreaterThan(0)
      expect(template.antiPatterns.length).toBeGreaterThan(0)
    }
  })

  it('covers every standardized screen state across the ten templates', () => {
    const allStates: readonly StandardScreenState[] = ['READY','LOADING','EMPTY','WARN','ERROR','UNAUTHORIZED','FORBIDDEN','PARTIAL','DIRTY','CONFLICT','EXPIRED','READONLY','PROCESSING']
    const covered = new Set(screenTemplateCatalogue.flatMap(template => template.mandatoryStates))
    for (const state of allStates) expect(covered).toContain(state)
  })

  it('resolves a template by stable ID', () => {
    expect(getScreenTemplate('T05').component).toBe('ApprovalWorkbenchPage')
  })
})
