
module.exports = {
  async up(queryInterface, Sequelize) {
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.createTable('claim_requests', {
        id: {
          type: Sequelize.DataTypes.UUID,
          defaultValue: Sequelize.DataTypes.UUIDV4,
          primaryKey: true,
        },
        businessId: {
          type: Sequelize.DataTypes.UUID,
          references: {
            key: 'id',
            model: 'businesses',
          },
          allowNull: false,
        },
        userId: {
          type: Sequelize.DataTypes.UUID,
          references: {
            key: 'id',
            model: 'users',
          },
          allowNull: false,
        },
        status: {
          type: Sequelize.DataTypes.ENUM('PENDING', 'APPROVED', 'REJECTED'),
          defaultValue: 'PENDING',
          allowNull: false,
        },
        rejectionReason: {
          type: Sequelize.DataTypes.TEXT,
          allowNull: true,
        },
        createdById: {
          type: Sequelize.DataTypes.UUID,
          references: {
            key: 'id',
            model: 'users',
          },
        },
        updatedById: {
          type: Sequelize.DataTypes.UUID,
          references: {
            key: 'id',
            model: 'users',
          },
        },
        createdAt: { type: Sequelize.DataTypes.DATE },
        updatedAt: { type: Sequelize.DataTypes.DATE },
        deletedAt: { type: Sequelize.DataTypes.DATE },
      }, { transaction });

      await transaction.commit();
    } catch (error) {
      await transaction.rollback();
      throw error;
    }
  },
  async down(queryInterface, Sequelize) {
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.dropTable('claim_requests', { transaction });
      await transaction.commit();
    } catch (error) {
      await transaction.rollback();
      throw error;
    }
  },
};
