import { test } from '@japa/runner'
import {
  createCalculatedSemantic,
  isCalculatedSemantic,
  type CalculatedConfig,
} from '../../../../src/modeling/definitions/Calculated.js'
import { SemanticType, type AppliedDataSemantic } from '../../../../src/modeling/Semantics.js'

test.group('Calculated Semantic Configuration', () => {
  test('should create semantic with custom config', ({ assert }) => {
    const config: CalculatedConfig = {
      formula: 'price * quantity',
      dependencies: ['price', 'quantity'],
      recalculateOnUpdate: true,
      allowManualOverride: true,
    }
    const semantic = createCalculatedSemantic(config)
    assert.equal(semantic.id, SemanticType.Calculated)
    assert.deepEqual(semantic.config, config)
  })

  test('should identify calculated semantic', ({ assert }) => {
    const config: CalculatedConfig = { formula: 'price * quantity' }
    const semantic = createCalculatedSemantic(config)
    assert.isTrue(isCalculatedSemantic(semantic))
  })

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