// src/server/features/notes/db/note_layouts.table.ts
// Note layouts table schema for personal positioning of notes

import { mysqlTable, varchar, int, timestamp, uniqueIndex } from 'drizzle-orm/mysql-core';
import { sql } from 'drizzle-orm';
import { notes } from './notes.table';

export const noteLayouts = mysqlTable('note_layouts', {
  id: varchar('id', { length: 36 }).primaryKey(),
  noteId: varchar('note_id', { length: 36 }).notNull().references(() => notes.id, { onDelete: 'cascade' }),
  userId: varchar('user_id', { length: 36 }).notNull(),
  // Позиционирование на доске
  column: int('column').notNull().default(1), // Номер колонки (1-6)
  positionY: int('position_y').notNull().default(0), // Вертикальная позиция (кратна 5px)
  height: int('height').notNull().default(220), // Высота карточки в пикселях (мин. 65px)
  // Персональные настройки
  reminderAt: timestamp('reminder_at'), // Время персонального напоминания (nullable)
  lastViewedAt: timestamp('last_viewed_at'), // Время последнего просмотра заметки (комменты, приоритет, контент)
  // Системные поля
  createdAt: timestamp('created_at').notNull().defaultNow(),
  updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(),
}, (table) => ({
  // Уникальный индекс на пару (noteId, userId)
  uniqueNoteUser: uniqueIndex('unique_note_user_idx').on(table.noteId, table.userId),
}));
