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

export default appSchema({
  version: 3,
  tables: [
    tableSchema({
      name: 'chats',
      columns: [
        { name: 'chat_key', type: 'string', isOptional: true },
        { name: 'chat_uid', type: 'number', isOptional: true, isIndexed: true },
        { name: 'group_chat_token', type: 'string', isOptional: true, isIndexed: true },

        { name: 'name', type: 'string' },
        { name: 'avatar', type: 'string', isOptional: true },
        { name: 'avatar_local', type: 'string', isOptional: true },
        { name: 'avatar_etag', type: 'string', isOptional: true },
        { name: 'avatar_checked_at', type: 'number', isOptional: true },
        { name: 'short', type: 'string' },
        { name: 'sent_by', type: 'number' },
        { name: 'updated', type: 'number', isIndexed: true },
        { name: 'status', type: 'number' },
        { name: 'unread_count', type: 'number' },
        { name: 'last_message_id', type: 'number' },
        { name: 'pin', type: 'number' },
        { name: 'pin_order', type: 'number' },
        { name: 'archive', type: 'number' },
        { name: 'archive_order', type: 'number' },
        { name: 'attachement_name', type: 'string' },
        { name: 'encrypted', type: 'number' },
        { name: 'muted', type: 'number' },
        { name: 'user_type', type: 'string', isOptional: true },

        { name: 'group_avatar', type: 'string', isOptional: true },
        { name: 'can_send_messages', type: 'number', isOptional: true },
        { name: 'is_admin', type: 'number', isOptional: true },
        { name: 'announcement', type: 'number', isOptional: true },

        { name: 'is_dirty', type: 'boolean', isOptional: true },
        { name: 'dirty_actions', type: 'string', isOptional: true },
        { name: 'removed', type: 'boolean', isOptional: true }
      ]
    }),
    tableSchema({
      name: 'messages',
      columns: [
        { name: 'chat_key', type: 'string', isOptional: true },
        { name: 'is_group', type: 'boolean' },
        { name: 'reply_to_id', type: 'number', isOptional: true },
        { name: 'is_sending', type: 'boolean', isOptional: true },
        { name: 'composite_id', type: 'string', isIndexed: true },
        { name: 'message_id', type: 'number', isOptional: true },

        { name: 'sender_id', type: 'number' },
        { name: 'recipient_id', type: 'number' },
        { name: 'text', type: 'string', isOptional: true },

        { name: 'sent_at', type: 'string' },
        { name: 'received_at', type: 'number', isOptional: true },
        { name: 'read_at', type: 'number', isOptional: true },
        { name: 'status', type: 'number' },

        { name: 'reactions', type: 'string', isOptional: true },
        { name: 'edits', type: 'string', isOptional: true },
        { name: 'attachment', type: 'string', isOptional: true },
        { name: 'reply_to', type: 'string', isOptional: true },
        { name: 'encrypted', type: 'number', isOptional: true },

        { name: 'sender_name', type: 'string', isOptional: true },
        { name: 'sender_avatar', type: 'string', isOptional: true },
        { name: 'is_dirty', type: 'boolean', isOptional: true },
        { name: 'dirty_actions', type: 'string', isOptional: true }
      ]
    }),
    tableSchema({
      name: 'blocked_users',
      columns: [
        { name: 'user_id', type: 'number', isIndexed: true },
        { name: 'first_name', type: 'string' },
        { name: 'last_name', type: 'string' },
        { name: 'avatar', type: 'string', isOptional: true },
        { name: 'removed', type: 'boolean', isOptional: true },
        { name: 'is_dirty', type: 'boolean', isOptional: true },
        { name: 'dirty_actions', type: 'string', isOptional: true }
      ]
    })
  ]
});
