import { QueryInterface, DataTypes } from 'sequelize';

module.exports = {
  up: async (queryInterface: QueryInterface) => {
    await queryInterface.createTable('activities', {
      activity_id: { type: DataTypes.UUID, primaryKey: true, defaultValue: DataTypes.UUIDV4, allowNull: false },
      request_id: { type: DataTypes.UUID, allowNull: false },
      user_id: { type: DataTypes.UUID, allowNull: true },
      user_name: { type: DataTypes.STRING(255), allowNull: true },
      activity_type: { type: DataTypes.STRING(100), allowNull: false },
      activity_description: { type: DataTypes.TEXT, allowNull: false },
      activity_category: { type: DataTypes.STRING(100), allowNull: true },
      severity: { type: DataTypes.STRING(50), allowNull: true },
      metadata: { type: DataTypes.JSONB, allowNull: true },
      is_system_event: { type: DataTypes.BOOLEAN, allowNull: true },
      ip_address: { type: DataTypes.STRING(100), allowNull: true },
      user_agent: { type: DataTypes.TEXT, allowNull: true },
      created_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW }
    });
    await queryInterface.sequelize.query('CREATE INDEX IF NOT EXISTS "activities_request_id" ON "activities" ("request_id");');
    await queryInterface.sequelize.query('CREATE INDEX IF NOT EXISTS "activities_created_at" ON "activities" ("created_at");');
    await queryInterface.sequelize.query('CREATE INDEX IF NOT EXISTS "activities_activity_type" ON "activities" ("activity_type");');
  },
  down: async (queryInterface: QueryInterface) => {
    await queryInterface.dropTable('activities');
  }
};


