import { integer, pgTable, timestamp, uuid } from "drizzle-orm/pg-core";

/**
 * Safety canary: hourly deterministic checks written by a worker job and
 * read by the ops endpoint. The endpoint never runs heavy computations.
 */
export const opsSafetyCanary = pgTable("ops_safety_canary", {
  id: uuid("id").primaryKey().defaultRandom(),
  occurredAt: timestamp("occurred_at", { withTimezone: true }).notNull().defaultNow(),
  /** Recipes where stored allergens differ from freshly derived allergens. */
  allergenInvariantBrott: integer("allergen_invariant_brott").notNull().default(0),
  /** Publicly visible recipes that are not verificationStatus=verified. */
  overifieradeVisade: integer("overifierade_visade").notNull().default(0),
  /** Recipes rejected by the food-safety lint in the last 7 days. */
  foodSafetyLintAvvisade7d: integer("food_safety_lint_avvisade_7d"),
  computedAt: timestamp("computed_at", { withTimezone: true }).notNull().defaultNow(),
});
