import { index, integer, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
import { agents } from "./agents.js";
import { goals } from "./goals.js";
import { heartbeatRuns } from "./heartbeat_runs.js";
import { issues } from "./issues.js";
import { organizations } from "./organizations.js";
import { projects } from "./projects.js";
export const costEvents = pgTable("cost_events", {
    id: uuid("id").primaryKey().defaultRandom(),
    orgId: uuid("org_id").notNull().references(() => organizations.id),
    agentId: uuid("agent_id").notNull().references(() => agents.id),
    issueId: uuid("issue_id").references(() => issues.id),
    projectId: uuid("project_id").references(() => projects.id),
    goalId: uuid("goal_id").references(() => goals.id),
    heartbeatRunId: uuid("heartbeat_run_id").references(() => heartbeatRuns.id),
    billingCode: text("billing_code"),
    provider: text("provider").notNull(),
    biller: text("biller").notNull().default("unknown"),
    billingType: text("billing_type").notNull().default("unknown"),
    model: text("model").notNull(),
    inputTokens: integer("input_tokens").notNull().default(0),
    cachedInputTokens: integer("cached_input_tokens").notNull().default(0),
    outputTokens: integer("output_tokens").notNull().default(0),
    costCents: integer("cost_cents").notNull(),
    occurredAt: timestamp("occurred_at", { withTimezone: true }).notNull(),
    createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
}, (table) => ({
    companyOccurredIdx: index("cost_events_company_occurred_idx").on(table.orgId, table.occurredAt),
    companyAgentOccurredIdx: index("cost_events_company_agent_occurred_idx").on(table.orgId, table.agentId, table.occurredAt),
    companyProviderOccurredIdx: index("cost_events_company_provider_occurred_idx").on(table.orgId, table.provider, table.occurredAt),
    companyBillerOccurredIdx: index("cost_events_company_biller_occurred_idx").on(table.orgId, table.biller, table.occurredAt),
    companyHeartbeatRunIdx: index("cost_events_company_heartbeat_run_idx").on(table.orgId, table.heartbeatRunId),
}));
//# sourceMappingURL=cost_events.js.map