'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    // Add drawing_number field
    await queryInterface.addColumn('material', 'drawing_number', {
      type: Sequelize.STRING(100),
      allowNull: true,
      comment: 'Drawing number for the material (used as filename for drawing file)'
    });

    // Add revision_number field
    await queryInterface.addColumn('material', 'revision_number', {
      type: Sequelize.STRING(20),
      allowNull: true,
      comment: 'Revision number for the drawing'
    });

    // Add drawing_file_path field
    await queryInterface.addColumn('material', 'drawing_file_path', {
      type: Sequelize.STRING(500),
      allowNull: true,
      comment: 'Path to the uploaded drawing file (PDF or Image)'
    });

    // Add drawing_file_name field (original filename)
    await queryInterface.addColumn('material', 'drawing_file_name', {
      type: Sequelize.STRING(255),
      allowNull: true,
      comment: 'Original filename of the uploaded drawing'
    });

    // Add drawing_file_size field
    await queryInterface.addColumn('material', 'drawing_file_size', {
      type: Sequelize.INTEGER,
      allowNull: true,
      comment: 'Size of the drawing file in bytes'
    });

    // Add drawing_file_type field (MIME type)
    await queryInterface.addColumn('material', 'drawing_file_type', {
      type: Sequelize.STRING(50),
      allowNull: true,
      comment: 'MIME type of the drawing file (e.g., application/pdf, image/png)'
    });

    // Add indexes for better query performance
    await queryInterface.addIndex('material', ['drawing_number'], {
      name: 'material_drawing_number_idx'
    });
  },

  async down(queryInterface, Sequelize) {
    // Remove indexes
    await queryInterface.removeIndex('material', 'material_drawing_number_idx');

    // Remove columns
    await queryInterface.removeColumn('material', 'drawing_file_type');
    await queryInterface.removeColumn('material', 'drawing_file_size');
    await queryInterface.removeColumn('material', 'drawing_file_name');
    await queryInterface.removeColumn('material', 'drawing_file_path');
    await queryInterface.removeColumn('material', 'revision_number');
    await queryInterface.removeColumn('material', 'drawing_number');
  }
};

