import { test } from '@japa/runner'
import { AllowPublicAccessRule } from '../../../../src/modeling/rules/AllowPublic.js'

test.group('AllowPublicAccessRule', () => {
  test('initializes with correct type', ({ assert }) => {
    const rule = new AllowPublicAccessRule()
    assert.equal(rule.type, 'allowPublic')
  }).tags(['@modeling', '@rule', '@allow-public'])

  test('toJSON returns valid schema', ({ assert }) => {
    const rule = new AllowPublicAccessRule()
    const json = rule.toJSON()

    assert.equal(json.type, 'allowPublic')
  }).tags(['@modeling', '@rule', '@allow-public', '@serialization'])

  test('notifies change', async ({ assert }) => {
    const rule = new AllowPublicAccessRule()
    let notified = false
    rule.addEventListener('change', () => {
      notified = true
    })

    rule.notifyChange()
    await Promise.resolve()
    assert.isTrue(notified)
  }).tags(['@modeling', '@rule', '@allow-public', '@observed'])
})
