import {index, int, sqliteTable, text} from 'drizzle-orm/sqlite-core'

export const tasksTable = sqliteTable('Task', {
  id: int().primaryKey({autoIncrement: true}),
  name: text().notNull(),
  completed: int({mode: 'boolean'}).notNull().default(false),
})

export const labelsTable = sqliteTable('Label', {
  id: int().primaryKey({autoIncrement: true}),
  name: text().notNull(),
  color: text().notNull(),
})

export const taskLabelTable = sqliteTable(
  'TaskLabel',
  {
    taskId: int()
      .notNull()
      .references(() => tasksTable.id, {onDelete: 'cascade'}),
    labelId: int()
      .notNull()
      .references(() => labelsTable.id, {onDelete: 'cascade'}),
  },
  t => [index('custom_name').on(t.taskId, t.labelId)],
)
