import { test } from '@japa/runner'
import {
  createDerivedSemantic,
  isDerivedSemantic,
  type DerivedConfig,
} from '../../../../src/modeling/definitions/Derived.js'
import { SemanticType, type AppliedDataSemantic } from '../../../../src/modeling/Semantics.js'

test.group('Derived Semantic Configuration', () => {
  test('should create semantic with custom config', ({ assert }) => {
    const config: DerivedConfig = {
      sourceFields: ['firstName', 'lastName'],
      transformation: 'concat',
      allowManualOverride: true,
      recalculateOnUpdate: false,
    }
    const semantic = createDerivedSemantic(config)
    assert.equal(semantic.id, SemanticType.Derived)
    assert.deepEqual(semantic.config, config)
  })

  test('should identify derived semantic', ({ assert }) => {
    const config: DerivedConfig = { sourceFields: ['firstName', 'lastName'] }
    const semantic = createDerivedSemantic(config)
    assert.isTrue(isDerivedSemantic(semantic))
  })

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