export type Sub =
  | { kind: "channel"; channel: string; accountId?: string }
  | { kind: "agent"; agentId: string }
  | { kind: "channel-catchall" };

export function matchesChannelSub(
  subs: Sub[],
  event: { channel: string; accountId: string },
): boolean {
  return subs.some((s) => {
    if (s.kind === "channel-catchall") return true;
    if (s.kind !== "channel") return false;
    if (s.channel !== event.channel) return false;
    if (s.accountId !== undefined && s.accountId !== event.accountId) return false;
    return true;
  });
}

export function matchesAgentSub(subs: Sub[], agentId: string | undefined): boolean {
  if (!agentId) return false;
  return subs.some((s) => s.kind === "agent" && s.agentId === agentId);
}
