import {
  init_clock,
  nowMs
} from "./chunk-HFDLUBWN.js";
import {
  getDrizzle,
  init_drizzle
} from "./chunk-RII4M3J2.js";
import {
  schema_exports
} from "./chunk-DDJOPRB7.js";

// src/db/proxy.ts
init_drizzle();
init_clock();
import { eq } from "drizzle-orm";
function isProxied(id) {
  const db = getDrizzle();
  const row = db.select({ resource_id: schema_exports.proxyResources.resource_id }).from(schema_exports.proxyResources).where(eq(schema_exports.proxyResources.resource_id, id)).get();
  return !!row;
}
function getProxiedTenantId(id) {
  const db = getDrizzle();
  const row = db.select({ tenant_id: schema_exports.proxyResources.tenant_id }).from(schema_exports.proxyResources).where(eq(schema_exports.proxyResources.resource_id, id)).get();
  if (!row) return void 0;
  return row.tenant_id;
}
function markProxied(id, type, tenantId = null) {
  const db = getDrizzle();
  db.insert(schema_exports.proxyResources).values({ resource_id: id, resource_type: type, tenant_id: tenantId, created_at: nowMs() }).onConflictDoNothing().run();
}
function unmarkProxied(id) {
  const db = getDrizzle();
  db.delete(schema_exports.proxyResources).where(eq(schema_exports.proxyResources.resource_id, id)).run();
}

export {
  isProxied,
  getProxiedTenantId,
  markProxied,
  unmarkProxied
};
