import { pgTable, integer, primaryKey } from "drizzle-orm/pg-core";
import { usersTable } from "./users";
import { appsTable } from "./apps";

export const userAppOrdersTable = pgTable(
  "user_app_orders",
  {
    userId: integer("user_id")
      .notNull()
      .references(() => usersTable.id, { onDelete: "cascade" }),
    appId: integer("app_id")
      .notNull()
      .references(() => appsTable.id, { onDelete: "cascade" }),
    sortOrder: integer("sort_order").notNull(),
  },
  (t) => [primaryKey({ columns: [t.userId, t.appId] })],
);

export type UserAppOrder = typeof userAppOrdersTable.$inferSelect;
