import { schemaMigrations, addColumns, createTable } from '@nozbe/watermelondb/Schema/migrations';

export const migrations = schemaMigrations({
  migrations: [
    {
      toVersion: 2,
      steps: [
        addColumns({
          table: 'tasks',
          columns: [{ name: 'repeat', type: 'string' }],
        }),
      ],
    },
    {
      toVersion: 3,
      steps: [
        addColumns({
          table: 'tasks',
          columns: [
            { name: 'repeat_interval', type: 'number', isOptional: true },
            { name: 'repeat_days', type: 'string', isOptional: true },
            { name: 'color', type: 'string', isOptional: true },
            { name: 'series_id', type: 'string', isOptional: true },
          ],
        }),
      ],
    },
    {
      toVersion: 4,
      steps: [
        addColumns({
          table: 'tasks',
          columns: [{ name: 'reminder', type: 'string', isOptional: true }],
        }),
      ],
    },
    {
      toVersion: 5,
      steps: [
        addColumns({
          table: 'tasks',
          columns: [{ name: 'end_time', type: 'string', isOptional: true }],
        }),
      ],
    },
    {
      toVersion: 6,
      steps: [
        createTable({
          name: 'repeat_profiles',
          columns: [
            { name: 'name', type: 'string', isOptional: true },
            { name: 'repeat', type: 'string', isOptional: true },
            { name: 'repeat_interval', type: 'number', isOptional: true },
            { name: 'repeat_days', type: 'string', isOptional: true },
            { name: 'created_at', type: 'number' },
            { name: 'updated_at', type: 'number' },
          ],
        }),
      ],
    },
    {
      toVersion: 7,
      steps: [
        addColumns({
          table: 'tasks',
          columns: [{ name: 'assignee_id', type: 'string', isOptional: true }],
        }),
      ],
    },
    {
      toVersion: 8,
      steps: [
        addColumns({
          table: 'tasks',
          columns: [{ name: 'all_day', type: 'boolean', isOptional: true }],
        }),
      ],
    },
    {
      toVersion: 9,
      steps: [
        addColumns({
          table: 'subtasks',
          columns: [
            { name: 'description', type: 'string', isOptional: true },
            { name: 'priority', type: 'string', isOptional: true },
            { name: 'due_date', type: 'number', isOptional: true },
            { name: 'due_time', type: 'string', isOptional: true },
            { name: 'end_time', type: 'string', isOptional: true },
            { name: 'reminder', type: 'string', isOptional: true },
            { name: 'assignee_id', type: 'string', isOptional: true },
          ],
        }),
      ],
    },
    {
      toVersion: 10,
      steps: [
        addColumns({
          table: 'subtasks',
          columns: [
            { name: 'all_day', type: 'boolean', isOptional: true },
            { name: 'repeat', type: 'string', isOptional: true },
            { name: 'repeat_interval', type: 'number', isOptional: true },
            { name: 'repeat_days', type: 'string', isOptional: true },
            { name: 'series_id', type: 'string', isOptional: true },
          ],
        }),
      ],
    },
    {
      toVersion: 11,
      steps: [
        addColumns({
          table: 'tasks',
          columns: [{ name: 'reminders', type: 'string', isOptional: true }],
        }),
        addColumns({
          table: 'subtasks',
          columns: [{ name: 'reminders', type: 'string', isOptional: true }],
        }),
      ],
    },
    {
      toVersion: 12,
      steps: [
        createTable({
          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' },
          ],
        }),
      ],
    },
  ],
});
