import { QueryInterface, DataTypes } from 'sequelize';

module.exports = {
  up: async (queryInterface: QueryInterface) => {
    await queryInterface.createTable('work_notes', {
      note_id: { type: DataTypes.UUID, primaryKey: true, defaultValue: DataTypes.UUIDV4, allowNull: false },
      request_id: { type: DataTypes.UUID, allowNull: false },
      user_id: { type: DataTypes.UUID, allowNull: false },
      user_name: { type: DataTypes.STRING(255), allowNull: true },
      user_role: { type: DataTypes.STRING(50), allowNull: true },
      message: { type: DataTypes.TEXT, allowNull: false },
      message_type: { type: DataTypes.STRING(50), allowNull: true },
      is_priority: { type: DataTypes.BOOLEAN, allowNull: true },
      has_attachment: { type: DataTypes.BOOLEAN, allowNull: true },
      parent_note_id: { type: DataTypes.UUID, allowNull: true },
      mentioned_users: { type: DataTypes.ARRAY(DataTypes.UUID), allowNull: true },
      reactions: { type: DataTypes.JSONB, allowNull: true },
      is_edited: { type: DataTypes.BOOLEAN, allowNull: true },
      is_deleted: { type: DataTypes.BOOLEAN, allowNull: true },
      created_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
      updated_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW }
    });
    await queryInterface.sequelize.query('CREATE INDEX IF NOT EXISTS "work_notes_request_id" ON "work_notes" ("request_id");');
    await queryInterface.sequelize.query('CREATE INDEX IF NOT EXISTS "work_notes_user_id" ON "work_notes" ("user_id");');
    await queryInterface.sequelize.query('CREATE INDEX IF NOT EXISTS "work_notes_created_at" ON "work_notes" ("created_at");');
  },
  down: async (queryInterface: QueryInterface) => {
    await queryInterface.dropTable('work_notes');
  }
};


