// src/server/features/tasks/db/tasks.table.ts
// Tasks table schema for task management

import { mysqlTable, varchar, text, boolean, timestamp, int, index } from 'drizzle-orm/mysql-core';
import { randomUUID } from 'node:crypto';

export const tasks = mysqlTable('tasks', {
  id: varchar('id', { length: 36 }).primaryKey().$defaultFn(() => randomUUID()),
  userId: varchar('user_id', { length: 36 }).notNull(), // ID владельца задачи
  text: text('text').notNull(), // Текст задачи
  isCompleted: boolean('is_completed').notNull().default(false), // Статус выполнения
  parentId: varchar('parent_id', { length: 36 }), // ID родительской задачи для вложенности
  position: text('position'), // JSON: {x, y, w, h} для корневых задач
  order: int('order'), // Порядок сортировки подпунктов
  createdAt: timestamp('created_at').notNull().defaultNow(),
  updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(),
  archivedAt: timestamp('archived_at'), // Дата архивации (soft delete)
}, (table) => ({
  userIdIdx: index('idx_tasks_user_id').on(table.userId),
}));
