import { describe, it, expect } from "vitest";
import { RecordingProcessingRestriction } from "./recording-processing-restriction";

describe("RecordingProcessingRestriction", () => {
  it("records setRestriction calls", async () => {
    const restriction = new RecordingProcessingRestriction();
    await restriction.setRestriction("alice", true);

    expect(restriction.sets).toHaveLength(1);
    expect(restriction.sets[0]).toEqual({ subjectId: "alice", granted: true });
  });

  it("isRestricted returns true after setRestriction(true)", async () => {
    const restriction = new RecordingProcessingRestriction();
    await restriction.setRestriction("alice", true);

    expect(await restriction.isRestricted("alice")).toBe(true);
  });

  it("isRestricted returns false after setRestriction(false)", async () => {
    const restriction = new RecordingProcessingRestriction();
    await restriction.setRestriction("alice", true);
    await restriction.setRestriction("alice", false);

    expect(await restriction.isRestricted("alice")).toBe(false);
  });

  it("isRestricted returns false for unknown subjects", async () => {
    const restriction = new RecordingProcessingRestriction();

    expect(await restriction.isRestricted("ghost")).toBe(false);
  });

  it("tracks restriction per subject independently", async () => {
    const restriction = new RecordingProcessingRestriction();
    await restriction.setRestriction("alice", true);
    await restriction.setRestriction("bob", false);

    expect(await restriction.isRestricted("alice")).toBe(true);
    expect(await restriction.isRestricted("bob")).toBe(false);
  });

  it("reset() clears sets and state", async () => {
    const restriction = new RecordingProcessingRestriction();
    await restriction.setRestriction("alice", true);
    restriction.reset();

    expect(restriction.sets).toHaveLength(0);
    expect(await restriction.isRestricted("alice")).toBe(false);
  });
});
