// db/schema/table-presets.ts import { pgTable, text, timestamp, boolean, integer, uuid } from "drizzle-orm/pg-core" import { json } from "drizzle-orm/pg-core" import { z } from "zod" // TableSettings 타입 정의 export interface TableSettings { // 페이지네이션 page: number perPage: number // 정렬 sort: Array<{ id: string desc: boolean }> // 필터 filters: Array<{ id: string value: any operator?: string type?: string }> joinOperator: "and" | "or" basicFilters: Array<{ id: string value: any operator?: string type?: string }> basicJoinOperator: "and" | "or" search: string // 날짜 범위 (선택적) from?: string to?: string // 테이블 상태 columnVisibility: Record columnOrder: string[] pinnedColumns: { left: string[] right: string[] } // 기타 확장 가능한 설정들 groupBy?: string[] expandedRows?: string[] } export const tablePresets = pgTable("table_presets", { id: uuid("id").primaryKey().defaultRandom(), userId: text("user_id").notNull(), tableId: text("table_id").notNull(), // 'rfq-list', 'purchase-orders' 등 name: text("name").notNull(), settings: json("settings").$type().notNull(), isDefault: boolean("is_default").default(false).notNull(), isActive: boolean("is_active").default(false).notNull(), isShared: boolean("is_shared").default(false).notNull(), createdBy: text("created_by"), createdAt: timestamp("created_at").defaultNow().notNull(), updatedAt: timestamp("updated_at").defaultNow().notNull(), }) // 공유 프리셋 테이블 export const presetShares = pgTable("preset_shares", { id: uuid("id").primaryKey().defaultRandom(), presetId: uuid("preset_id").references(() => tablePresets.id, { onDelete: "cascade" }).notNull(), sharedWithUserId: text("shared_with_user_id").notNull(), permission: text("permission").default("read").notNull(), // 'read', 'write' createdAt: timestamp("created_at").defaultNow().notNull(), }) // TypeScript 타입 추출 export type TablePreset = typeof tablePresets.$inferSelect export type NewTablePreset = typeof tablePresets.$inferInsert