import type { IiosPlatformPorts, PlatformPrincipal } from '@insignia/iios-contracts';

type SessionPort = IiosPlatformPorts['session'];

/** Deterministic Session fake. Returns a fixed principal; can be set to reject. */
export class FakeSession implements SessionPort {
  private principal: PlatformPrincipal = {
    principalRef: 'fake-principal',
    orgId: 'org_demo',
    appId: 'portal-demo',
    assurance: 'authenticated',
  };
  private fail = false;

  setPrincipal(p: Partial<PlatformPrincipal>): this {
    this.principal = { ...this.principal, ...p };
    return this;
  }

  reject(): this {
    this.fail = true;
    return this;
  }

  async verify(_token: string): Promise<PlatformPrincipal> {
    if (this.fail) throw new Error('invalid token');
    return this.principal;
  }
}
