'use strict';

/** Total line weight in KG (denormalized at save time) for purchase → inward → GRN chain */

module.exports = {
  async up(queryInterface, Sequelize) {
    const col = {
      type: Sequelize.DECIMAL(18, 3),
      allowNull: true,
      comment: 'Total line weight in KG at transaction time',
    };

    await queryInterface.addColumn('purchase_requisition_item', 'line_weight_kg', col);
    await queryInterface.addColumn('purchase_order_item', 'line_weight_kg', col);
    await queryInterface.addColumn('gate_entry_item', 'line_weight_kg', col);
    await queryInterface.addColumn('goods_receipt_note_item', 'line_weight_kg', col);
  },

  async down(queryInterface) {
    await queryInterface.removeColumn('goods_receipt_note_item', 'line_weight_kg');
    await queryInterface.removeColumn('gate_entry_item', 'line_weight_kg');
    await queryInterface.removeColumn('purchase_order_item', 'line_weight_kg');
    await queryInterface.removeColumn('purchase_requisition_item', 'line_weight_kg');
  },
};
