'use strict';

/**
 * Remove all PURCHASE.* permissions from Store roles (STORE_KEEPER, STORE_ASSISTANT).
 * Store users should only see Purchase Requisition under Stores (STORES.PURCHASE_REQUISITION.*),
 * not the Purchase menu (PURCHASE.*).
 */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.sequelize.query(`
      DELETE rp FROM role_permission rp
      INNER JOIN role r ON r.id = rp.role_id
      INNER JOIN permission p ON p.id = rp.permission_id
      WHERE r.role_code IN ('STORE_KEEPER', 'STORE_ASSISTANT')
      AND p.permission_code LIKE 'PURCHASE.%'
    `);
  },

  async down(queryInterface, Sequelize) {
    // Re-add would require re-running role-permission seed; down intentionally no-op
  }
};
