import { appSchema, tableSchema } from '@nozbe/watermelondb';

export const schema = appSchema({
  version: 20,
  tables: [
    tableSchema({
      name: 'categories',
      columns: [
        { name: 'name', type: 'string' },
        { name: 'color', type: 'string' },
        { name: 'order', type: 'number' },
        { name: 'created_at', type: 'number' },
        { name: 'updated_at', type: 'number', isIndexed: true },
      ],
    }),
    tableSchema({
      name: 'tasks',
      columns: [
        { name: 'title', type: 'string' },
        { name: 'description', type: 'string' },
        { name: 'category_id', type: 'string', isIndexed: true },
        { name: 'tags', type: 'string', isOptional: true },
        { name: 'priority', type: 'string' },
        { name: 'completed', type: 'boolean', isIndexed: true },
        { name: 'completed_at', type: 'number', isOptional: true },
        { name: 'due_date', type: 'number', isIndexed: true },
        { name: 'due_time', type: 'string' },
        { name: 'end_time', type: 'string' },
        { name: 'all_day', type: 'boolean' },
        { name: 'repeat', type: 'string' },
        { name: 'repeat_interval', type: 'number' },
        { name: 'repeat_days', type: 'string' },
        { name: 'color', type: 'string' },
        { name: 'series_id', type: 'string', isIndexed: true },
        { name: 'order', type: 'number', isOptional: true },
        { name: 'reminder', type: 'string' },
        { name: 'reminders', type: 'string' },
        { name: 'assignee_id', type: 'string', isOptional: true },
        { name: 'created_at', type: 'number', isIndexed: true },
        { name: 'updated_at', type: 'number', isIndexed: true },
      ],
    }),
    tableSchema({
      name: 'subtasks',
      columns: [
        { name: 'task_id', type: 'string', isIndexed: true },
        { name: 'parent_subtask_id', type: 'string', isIndexed: true, isOptional: true },
        { name: 'category_id', type: 'string', isOptional: true },
        { name: 'tags', type: 'string', isOptional: true },
        { name: 'category_id', type: 'string', isIndexed: true, isOptional: true },
        { name: 'title', type: 'string' },
        { name: 'description', type: 'string', isOptional: true },
        { name: 'priority', type: 'string', isOptional: true },
        { name: 'completed', type: 'boolean' },
        { name: 'due_date', type: 'number', isOptional: true },
        { name: 'due_time', type: 'string', isOptional: true },
        { name: 'end_time', type: 'string', isOptional: true },
        { name: 'all_day', type: 'boolean' },
        { name: 'repeat', type: 'string' },
        { name: 'repeat_interval', type: 'number' },
        { name: 'repeat_days', type: 'string' },
        { name: 'series_id', type: 'string' },
        { name: 'reminder', type: 'string', isOptional: true },
        { name: 'reminders', type: 'string', isOptional: true },
        { name: 'assignee_id', type: 'string', isOptional: true },
        { name: 'order', type: 'number' },
        { name: 'created_at', type: 'number', isIndexed: true },
        { name: 'updated_at', type: 'number', isIndexed: true },
      ],
    }),
    tableSchema({
      name: 'repeat_profiles',
      columns: [
        { name: 'name', type: 'string' },
        { name: 'repeat', type: 'string' },
        { name: 'repeat_interval', type: 'number' },
        { name: 'repeat_days', type: 'string' },
        { name: 'created_at', type: 'number' },
        { name: 'updated_at', type: 'number', isIndexed: true },
      ],
    }),
    tableSchema({
      name: 'friendships',
      columns: [
        { name: 'user_id', type: 'string', isIndexed: true },
        { name: 'friend_id', type: 'string', isIndexed: true },
        { name: 'status', type: 'string' },
        { name: 'created_at', type: 'number' },
        { name: 'updated_at', type: 'number', isIndexed: true },
      ],
    }),
    tableSchema({
      name: 'tombstones',
      columns: [
        { name: 'entity', type: 'string' },
        { name: 'entity_id', type: 'string', isIndexed: true },
        { name: 'deleted_at', type: 'number', isIndexed: true },
      ],
    }),
  ],
});