import { index, pgEnum, pgTable, text, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
import { createdAt } from "./_shared.js";
import { users } from "./users.js";

export const feedbackTypeEnum = pgEnum("feedback_type", ["bug", "onskemal"]);
export const feedbackStatusEnum = pgEnum("feedback_status", ["oppen", "pagar", "stangd"]);

/** Användarfeedback: buggrapporter och önskemål (doc §2). */
export const feedback = pgTable(
  "feedback",
  {
    id: uuid("id").primaryKey().defaultRandom(),
    userId: uuid("user_id").references(() => users.id, { onDelete: "set null" }),
    typ: feedbackTypeEnum("typ").notNull(),
    rubrik: varchar("rubrik", { length: 200 }).notNull(),
    /** Full text – visas aldrig i ops-sammanfattningen. */
    text: text("text").notNull(),
    status: feedbackStatusEnum("status").notNull().default("oppen"),
    plattform: varchar("plattform", { length: 16 }),
    appVersion: varchar("app_version", { length: 32 }),
    createdAt: createdAt(),
  },
  (t) => [
    index("feedback_status_created_idx").on(t.status, t.createdAt),
    index("feedback_user_idx").on(t.userId, t.createdAt),
  ],
);
