"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.userSettings = exports.repeatProfiles = exports.subtasks = exports.tombstones = exports.tasks = exports.categories = exports.friendships = exports.users = exports.ENTITIES = void 0;
const pg_core_1 = require("drizzle-orm/pg-core");
const drizzle_orm_1 = require("drizzle-orm");
exports.ENTITIES = ['categories', 'tasks', 'subtasks', 'repeatProfiles', 'friendships'];
exports.users = (0, pg_core_1.pgTable)('users', {
    id: (0, pg_core_1.text)('id').primaryKey(),
    username: (0, pg_core_1.text)('username').notNull().unique(),
    passwordHash: (0, pg_core_1.text)('password_hash').notNull(),
    resetToken: (0, pg_core_1.text)('reset_token'),
    resetTokenExpiry: (0, pg_core_1.bigint)('reset_token_expiry', { mode: 'number' }),
    createdAt: (0, pg_core_1.bigint)('created_at', { mode: 'number' }).notNull().default((0, drizzle_orm_1.sql) `EXTRACT(EPOCH FROM NOW()) * 1000`),
});
exports.friendships = (0, pg_core_1.pgTable)('friendships', {
    id: (0, pg_core_1.text)('id').primaryKey(),
    userId: (0, pg_core_1.text)('user_id').notNull().references(() => exports.users.id, { onDelete: 'cascade' }),
    friendId: (0, pg_core_1.text)('friend_id').notNull().references(() => exports.users.id, { onDelete: 'cascade' }),
    status: (0, pg_core_1.text)('status', { enum: ['pending', 'accepted'] }).notNull().default('pending'),
    createdAt: (0, pg_core_1.bigint)('created_at', { mode: 'number' }).notNull().default((0, drizzle_orm_1.sql) `EXTRACT(EPOCH FROM NOW()) * 1000`),
    updatedAt: (0, pg_core_1.bigint)('updated_at', { mode: 'number' }).notNull().default((0, drizzle_orm_1.sql) `EXTRACT(EPOCH FROM NOW()) * 1000`),
}, (t) => ({
    pairUnique: (0, pg_core_1.unique)('friendships_pair').on(t.userId, t.friendId),
    userIdx: (0, pg_core_1.index)('friendships_user_idx').on(t.userId),
    friendIdx: (0, pg_core_1.index)('friendships_friend_idx').on(t.friendId),
}));
exports.categories = (0, pg_core_1.pgTable)('categories', {
    id: (0, pg_core_1.text)('id').primaryKey(),
    userId: (0, pg_core_1.text)('user_id').notNull().references(() => exports.users.id, { onDelete: 'cascade' }),
    name: (0, pg_core_1.text)('name').notNull(),
    color: (0, pg_core_1.text)('color').notNull(),
    order: (0, pg_core_1.integer)('order').notNull().default(0),
    createdAt: (0, pg_core_1.bigint)('created_at', { mode: 'number' }).notNull().default((0, drizzle_orm_1.sql) `EXTRACT(EPOCH FROM NOW()) * 1000`),
    updatedAt: (0, pg_core_1.bigint)('updated_at', { mode: 'number' }).notNull().default((0, drizzle_orm_1.sql) `EXTRACT(EPOCH FROM NOW()) * 1000`),
});
exports.tasks = (0, pg_core_1.pgTable)('tasks', {
    id: (0, pg_core_1.text)('id').primaryKey(),
    userId: (0, pg_core_1.text)('user_id').notNull().references(() => exports.users.id, { onDelete: 'cascade' }),
    categoryId: (0, pg_core_1.text)('category_id').references(() => exports.categories.id, { onDelete: 'cascade' }),
    title: (0, pg_core_1.text)('title').notNull(),
    description: (0, pg_core_1.text)('description').notNull().default(''),
    priority: (0, pg_core_1.text)('priority', { enum: ['none', 'low', 'medium', 'high', 'critical'] }).notNull().default('none'),
    completed: (0, pg_core_1.boolean)('completed').notNull().default(false),
    dueDate: (0, pg_core_1.bigint)('due_date', { mode: 'number' }).notNull().default(0),
    dueTime: (0, pg_core_1.text)('due_time').notNull().default(''),
    endTime: (0, pg_core_1.text)('end_time').notNull().default(''),
    allDay: (0, pg_core_1.boolean)('all_day').notNull().default(false),
    repeat: (0, pg_core_1.text)('repeat', { enum: ['none', 'daily', 'weekly', 'monthly', 'custom'] }).notNull().default('none'),
    repeatInterval: (0, pg_core_1.integer)('repeat_interval').notNull().default(1),
    repeatDays: (0, pg_core_1.text)('repeat_days').notNull().default(''),
    seriesId: (0, pg_core_1.text)('series_id').notNull().default(''),
    assigneeId: (0, pg_core_1.text)('assignee_id').references(() => exports.users.id, { onDelete: 'set null' }),
    reminder: (0, pg_core_1.text)('reminder', { enum: ['none', 'at_time', '15', '30', '60', '120', '1440'] }).notNull().default('none'),
    reminders: (0, pg_core_1.text)('reminders').notNull().default(''),
    completedAt: (0, pg_core_1.bigint)('completed_at', { mode: 'number' }),
    createdAt: (0, pg_core_1.bigint)('created_at', { mode: 'number' }).notNull().default((0, drizzle_orm_1.sql) `EXTRACT(EPOCH FROM NOW()) * 1000`),
    updatedAt: (0, pg_core_1.bigint)('updated_at', { mode: 'number' }).notNull().default((0, drizzle_orm_1.sql) `EXTRACT(EPOCH FROM NOW()) * 1000`),
});
exports.tombstones = (0, pg_core_1.pgTable)('tombstones', {
    entity: (0, pg_core_1.text)('entity', { enum: exports.ENTITIES }).notNull(),
    entityId: (0, pg_core_1.text)('entity_id').notNull(),
    userId: (0, pg_core_1.text)('user_id').notNull().references(() => exports.users.id, { onDelete: 'cascade' }),
    updatedAt: (0, pg_core_1.bigint)('updated_at', { mode: 'number' }).notNull(),
}, (t) => ({
    pk: (0, pg_core_1.primaryKey)({ columns: [t.entity, t.entityId] }),
    userIdx: (0, pg_core_1.index)('tombstones_user_updated_idx').on(t.userId, t.updatedAt),
}));
// Define subtasks with explicit type to avoid circular reference
exports.subtasks = (0, pg_core_1.pgTable)('subtasks', {
    id: (0, pg_core_1.text)('id').primaryKey(),
    userId: (0, pg_core_1.text)('user_id').notNull().references(() => exports.users.id, { onDelete: 'cascade' }),
    taskId: (0, pg_core_1.text)('task_id').notNull().references(() => exports.tasks.id, { onDelete: 'cascade' }),
    parentSubtaskId: (0, pg_core_1.text)('parent_subtask_id').references(() => exports.subtasks.id, { onDelete: 'cascade' }),
    title: (0, pg_core_1.text)('title').notNull(),
    description: (0, pg_core_1.text)('description').notNull().default(''),
    priority: (0, pg_core_1.text)('priority', { enum: ['none', 'low', 'medium', 'high', 'critical'] }).notNull().default('none'),
    completed: (0, pg_core_1.boolean)('completed').notNull().default(false),
    dueDate: (0, pg_core_1.bigint)('due_date', { mode: 'number' }).notNull().default(0),
    dueTime: (0, pg_core_1.text)('due_time').notNull().default(''),
    endTime: (0, pg_core_1.text)('end_time').notNull().default(''),
    allDay: (0, pg_core_1.boolean)('all_day').notNull().default(false),
    repeat: (0, pg_core_1.text)('repeat', { enum: ['none', 'daily', 'weekly', 'monthly', 'custom'] }).notNull().default('none'),
    repeatInterval: (0, pg_core_1.integer)('repeat_interval').notNull().default(1),
    repeatDays: (0, pg_core_1.text)('repeat_days').notNull().default(''),
    seriesId: (0, pg_core_1.text)('series_id').notNull().default(''),
    reminder: (0, pg_core_1.text)('reminder', { enum: ['none', 'at_time', '15', '30', '60', '120', '1440'] }).notNull().default('none'),
    reminders: (0, pg_core_1.text)('reminders').notNull().default(''),
    assigneeId: (0, pg_core_1.text)('assignee_id').references(() => exports.users.id, { onDelete: 'set null' }),
    order: (0, pg_core_1.integer)('order').notNull().default(0),
    createdAt: (0, pg_core_1.bigint)('created_at', { mode: 'number' }).notNull().default((0, drizzle_orm_1.sql) `EXTRACT(EPOCH FROM NOW()) * 1000`),
    updatedAt: (0, pg_core_1.bigint)('updated_at', { mode: 'number' }).notNull().default((0, drizzle_orm_1.sql) `EXTRACT(EPOCH FROM NOW()) * 1000`),
}, (t) => ({
    parentIdx: (0, pg_core_1.index)('subtasks_parent_idx').on(t.parentSubtaskId),
    taskIdx: (0, pg_core_1.index)('subtasks_task_idx').on(t.taskId),
    userIdx: (0, pg_core_1.index)('subtasks_user_idx').on(t.userId),
}));
exports.repeatProfiles = (0, pg_core_1.pgTable)('repeat_profiles', {
    id: (0, pg_core_1.text)('id').primaryKey(),
    userId: (0, pg_core_1.text)('user_id').notNull().references(() => exports.users.id, { onDelete: 'cascade' }),
    name: (0, pg_core_1.text)('name').notNull(),
    repeat: (0, pg_core_1.text)('repeat', { enum: ['none', 'daily', 'weekly', 'monthly', 'custom'] }).notNull().default('none'),
    repeatInterval: (0, pg_core_1.integer)('repeat_interval').notNull().default(1),
    repeatDays: (0, pg_core_1.text)('repeat_days').notNull().default(''),
    createdAt: (0, pg_core_1.bigint)('created_at', { mode: 'number' }).notNull().default((0, drizzle_orm_1.sql) `EXTRACT(EPOCH FROM NOW()) * 1000`),
    updatedAt: (0, pg_core_1.bigint)('updated_at', { mode: 'number' }).notNull().default((0, drizzle_orm_1.sql) `EXTRACT(EPOCH FROM NOW()) * 1000`),
});
exports.userSettings = (0, pg_core_1.pgTable)('user_settings', {
    userId: (0, pg_core_1.text)('user_id').primaryKey().references(() => exports.users.id, { onDelete: 'cascade' }),
    darkMode: (0, pg_core_1.boolean)('dark_mode').notNull().default(false),
    notifications: (0, pg_core_1.boolean)('notifications').notNull().default(true),
    reminderTime: (0, pg_core_1.text)('reminder_time').notNull().default('09:00'),
    defaultCategory: (0, pg_core_1.text)('default_category'),
    sortBy: (0, pg_core_1.text)('sort_by', { enum: ['dueDate', 'priority', 'title', 'createdAt'] }).notNull().default('dueDate'),
    sortOrder: (0, pg_core_1.text)('sort_order', { enum: ['asc', 'desc'] }).notNull().default('asc'),
    updatedAt: (0, pg_core_1.bigint)('updated_at', { mode: 'number' }).notNull().default((0, drizzle_orm_1.sql) `EXTRACT(EPOCH FROM NOW()) * 1000`),
});
//# sourceMappingURL=schema.js.map