import { pgTable, text, uuid, uniqueIndex } from "drizzle-orm/pg-core";
import { user } from "./auth-schema.js";

export const userRoles = pgTable(
    "user_roles",
    {
        userRoleId: uuid("user_role_id").defaultRandom().primaryKey(),
        userId: text("user_id")
            .notNull()
            .references(() => user.id, { onDelete: "cascade" }),
        module: text("module").notNull(), // e.g. "siloAdjustments"
        role: text("role").notNull(), // e.g. "admin" | "manager" | "viewer"
    },
    (table) => [
        uniqueIndex("unique_user_module").on(table.userId, table.module),
    ]
);
export type UserRole = typeof userRoles.$inferSelect;
