import { test } from '@japa/runner'
import {
  createPublicUniqueNameSemantic,
  isPublicUniqueNameSemantic,
  DEFAULT_PUBLIC_UNIQUE_NAME_CONFIG,
  type PublicUniqueNameConfig,
} from '../../../../src/modeling/definitions/PublicUniqueName.js'
import { SemanticType, type AppliedDataSemantic } from '../../../../src/modeling/Semantics.js'

test.group('PublicUniqueName Semantic Configuration', () => {
  test('should create semantic with default config', ({ assert }) => {
    const semantic = createPublicUniqueNameSemantic()
    assert.equal(semantic.id, SemanticType.PublicUniqueName)
    assert.deepEqual(semantic.config, DEFAULT_PUBLIC_UNIQUE_NAME_CONFIG)
  })

  test('should create semantic with custom config', ({ assert }) => {
    const config: PublicUniqueNameConfig = {
      sourceField: 'title',
      separator: '-',
      maxLength: 50,
    }
    const semantic = createPublicUniqueNameSemantic(config)
    assert.equal(semantic.id, SemanticType.PublicUniqueName)
    assert.deepEqual(semantic.config, { ...DEFAULT_PUBLIC_UNIQUE_NAME_CONFIG, ...config })
  })

  test('should identify public unique name semantic', ({ assert }) => {
    const semantic = createPublicUniqueNameSemantic()
    assert.isTrue(isPublicUniqueNameSemantic(semantic))
  })

  test('should not identify non-public-unique-name semantic', ({ assert }) => {
    // Simulate a different semantic
    const fakeSemantic: AppliedDataSemantic = { id: SemanticType.Email, config: {} }
    assert.isFalse(isPublicUniqueNameSemantic(fakeSemantic))
  })
})
