'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('coaching_audit_events', {
      id: { type: Sequelize.UUID, allowNull: false, primaryKey: true },
      event_type: { type: Sequelize.STRING(64), allowNull: false },
      actorId: { type: Sequelize.UUID, allowNull: true },
      target_type: { type: Sequelize.STRING(32), allowNull: false },
      target_id: { type: Sequelize.UUID, allowNull: true },
      metadata: { type: Sequelize.JSONB, allowNull: false, defaultValue: {} },
      createdAt: { type: Sequelize.DATE, allowNull: false },
      updatedAt: { type: Sequelize.DATE, allowNull: false },
    });
    await queryInterface.addIndex('coaching_audit_events', ['event_type', 'createdAt']);
    await queryInterface.addIndex('coaching_audit_events', ['target_type', 'target_id']);
  },

  async down(queryInterface) {
    await queryInterface.dropTable('coaching_audit_events');
  },
};
