import { pgTable, varchar, text, timestamp } from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { roleNameEnum } from "./enums";

export const protectedRoutes = pgTable("protected_routes", {
  path: varchar("path", { length: 255 }).primaryKey(), // /auth/register-user
  methods: varchar("methods", { length: 50 }).array().notNull().default([]), // Массив: ["GET", "POST", "PUT", "DELETE", "PATCH"]
  roles: roleNameEnum("roles").array().notNull().default([]), // Массив: ["admin", "director", "manager"]
  description: text("description"), // Описание маршрута
  createdAt: timestamp("created_at", { withTimezone: true })
    .defaultNow()
    .notNull(),
  updatedAt: timestamp("updated_at", { withTimezone: true })
    .defaultNow()
    .notNull(),
});

// Zod schemas for validation
export const insertProtectedRouteSchema = createInsertSchema(protectedRoutes);
export const selectProtectedRouteSchema = createSelectSchema(protectedRoutes);

// Type exports
export type ProtectedRoute = typeof protectedRoutes.$inferSelect;
export type NewProtectedRoute = typeof protectedRoutes.$inferInsert;
