'use strict';

/**
 * Remove ALL Material-related permissions from Production Manager role.
 * Run this if Material menu still shows after previous migration.
 */
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 = 'PROD_MGR' 
      AND (
        p.permission_code = 'DASHBOARD.VIEW'
        OR p.permission_code LIKE 'MASTER.MATERIAL.%'
        OR p.permission_code LIKE 'MASTER.MATERIAL_TYPE.%'
        OR p.permission_code LIKE 'MASTER.MATERIAL_GROUP.%'
        OR p.permission_code LIKE 'MASTER.MATERIAL_THICKNESS.%'
        OR p.permission_code LIKE 'MASTER.MATERIAL_GRADE.%'
        OR p.permission_code LIKE 'MASTER.MATERIAL_SHEET_TYPE.%'
        OR p.permission_code LIKE 'MASTER.MATERIAL_SUBSTITUTION.%'
      )
    `);
  },

  async down(queryInterface, Sequelize) {
    // No-op
  }
};
