import { Arbiter } from '../../src/core/Arbiter.js';
import { describe, it, beforeEach } from 'node:test';
import assert from 'node:assert/strict';

describe('Simple Defeasible Logic Debug', () => {
  let arbiter;

  beforeEach(() => {
    arbiter = new Arbiter({ embeddingDimensions: 256 });
    
    // Set up basic entities
    arbiter.addNode('user:alice', 'user');
    arbiter.addNode('doc:test', 'document');
    
    // Set up basic relations
    arbiter.setRelationConfig('can_access', { type: 'direct' });
    arbiter.setRelationConfig('is_blocked', { type: 'direct' });
  });

  it('tests basic union logic', () => {
    // Set up user access
    arbiter.addRelation('user:alice', 'can_access', 'doc:test', { 
      value: 1.0, 
      possibility: 1.0,
      changed_last_at: Date.now()
    });
    
    // Test simple union
    arbiter.setRelationConfig('simple_union', {
      union: [
        { type: 'direct', relation: 'can_access' }
      ]
    });
    
    const result = arbiter.authChecker.check('user:alice', 'simple_union', 'doc:test');
    
    if (process.env.TEST_DEBUG === '1') console.log('Simple union result:', result);
    assert.ok(result.possibility > 0, `Expected some possibility, got ${result.possibility}`);
  });

  it('tests basic intersection logic', () => {
    // Set up user access
    arbiter.addRelation('user:alice', 'can_access', 'doc:test', { 
      value: 1.0, 
      possibility: 1.0,
      changed_last_at: Date.now()
    });
    
    // Test simple intersection
    arbiter.setRelationConfig('simple_intersection', {
      intersection: [
        { type: 'direct', relation: 'can_access' }
      ]
    });
    
    const result = arbiter.authChecker.check('user:alice', 'simple_intersection', 'doc:test');
    
    if (process.env.TEST_DEBUG === '1') console.log('Simple intersection result:', result);
    assert.ok(result.possibility > 0, `Expected some possibility, got ${result.possibility}`);
  });

});
