import { describe, it, expect } from 'vitest';
import {
  IIOS_EVENTS,
  PolicyDeniedError,
  ACTOR_KINDS,
  type ScopeVector,
  type IiosPlatformPorts,
} from './index';

describe('iios-contracts public entrypoint', () => {
  it('exports the event catalog', () => {
    expect(IIOS_EVENTS.interactionNormalized).toBe('com.insignia.iios.interaction.normalized.v1');
  });

  it('PolicyDeniedError carries the stable POLICY_DENIED code', () => {
    const err = new PolicyDeniedError('opa denied');
    expect(err.code).toBe('POLICY_DENIED');
    expect(err).toBeInstanceOf(Error);
  });

  it('actor kinds include the four real principals + UNKNOWN', () => {
    expect(ACTOR_KINDS).toContain('HUMAN');
    expect(ACTOR_KINDS).toContain('AI');
    expect(ACTOR_KINDS).toContain('SERVICE');
  });

  it('types are usable (compile-time check)', () => {
    const scope: ScopeVector = { orgId: 'org_1', appId: 'portal-demo' };
    const ports: Pick<IiosPlatformPorts, 'opa'> = {
      opa: { decide: async () => ({ decisionRef: 'd', allow: true, obligations: [], ttlSeconds: 60 }) },
    };
    expect(scope.appId).toBe('portal-demo');
    expect(typeof ports.opa.decide).toBe('function');
  });
});
