'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    // Add supplier registration fields for Job Worker vendors
    await queryInterface.addColumn('business_partner', 'year_of_establishment', {
      type: Sequelize.INTEGER,
      allowNull: true,
      comment: 'Year of establishment'
    });

    await queryInterface.addColumn('business_partner', 'total_area_sqft', {
      type: Sequelize.DECIMAL(15, 2),
      allowNull: true,
      comment: 'Total area in square feet'
    });

    await queryInterface.addColumn('business_partner', 'built_up_area_sqft', {
      type: Sequelize.DECIMAL(15, 2),
      allowNull: true,
      comment: 'Built-up area in square feet'
    });

    await queryInterface.addColumn('business_partner', 'building_type', {
      type: Sequelize.ENUM('OWN', 'RENTED'),
      allowNull: true,
      comment: 'Own Building or Rented Building'
    });

    await queryInterface.addColumn('business_partner', 'nature_of_business', {
      type: Sequelize.ENUM('MANUFACTURER', 'DEALER', 'AGENCY', 'JOB_ORDER'),
      allowNull: true,
      comment: 'Nature of Business: Manufacturer / Dealer / Agency / Job-Order'
    });

    await queryInterface.addColumn('business_partner', 'nature_of_manufacturing_service', {
      type: Sequelize.STRING(500),
      allowNull: true,
      comment: 'Nature of Manufacturing / Service'
    });

    await queryInterface.addColumn('business_partner', 'company_type', {
      type: Sequelize.ENUM('PUBLIC', 'PRIVATE_LTD', 'PARTNERSHIP', 'PROPRIETORY'),
      allowNull: true,
      comment: 'Type of Company: Public / Private Ltd / Partnership / Proprietory'
    });

    await queryInterface.addColumn('business_partner', 'phone_numbers', {
      type: Sequelize.STRING(200),
      allowNull: true,
      comment: 'Phone Number(s)'
    });

    await queryInterface.addColumn('business_partner', 'fax_number', {
      type: Sequelize.STRING(50),
      allowNull: true,
      comment: 'Fax number'
    });

    await queryInterface.addColumn('business_partner', 'md_partner_proprietor_name', {
      type: Sequelize.STRING(200),
      allowNull: true,
      comment: 'MD / Partner / Proprietor Name(s)'
    });

    await queryInterface.addColumn('business_partner', 'experience_in_field', {
      type: Sequelize.STRING(200),
      allowNull: true,
      comment: 'Experience in the field'
    });

    await queryInterface.addColumn('business_partner', 'handling_facilities', {
      type: Sequelize.TEXT,
      allowNull: true,
      comment: 'Available handling facilities (Transport etc.)'
    });

    await queryInterface.addColumn('business_partner', 'capacity_plant', {
      type: Sequelize.DECIMAL(15, 2),
      allowNull: true,
      comment: 'Capacity - Plant'
    });

    await queryInterface.addColumn('business_partner', 'capacity_installed', {
      type: Sequelize.DECIMAL(15, 2),
      allowNull: true,
      comment: 'Capacity - Installed'
    });

    await queryInterface.addColumn('business_partner', 'capacity_spare', {
      type: Sequelize.DECIMAL(15, 2),
      allowNull: true,
      comment: 'Capacity - Spare'
    });

    await queryInterface.addColumn('business_partner', 'generator_available', {
      type: Sequelize.BOOLEAN,
      allowNull: true,
      comment: 'Is Generator available?'
    });

    await queryInterface.addColumn('business_partner', 'generator_capacity', {
      type: Sequelize.STRING(100),
      allowNull: true,
      comment: 'Generator Capacity if available'
    });

    await queryInterface.addColumn('business_partner', 'machinery_details', {
      type: Sequelize.TEXT,
      allowNull: true,
      comment: 'Details of Machinery'
    });

    await queryInterface.addColumn('business_partner', 'measuring_equipments_details', {
      type: Sequelize.TEXT,
      allowNull: true,
      comment: 'Details of Measuring Equipments'
    });

    await queryInterface.addColumn('business_partner', 'employees_technical_staff', {
      type: Sequelize.INTEGER,
      allowNull: true,
      comment: 'Number of Technical Staff'
    });

    await queryInterface.addColumn('business_partner', 'employees_skilled_workers', {
      type: Sequelize.INTEGER,
      allowNull: true,
      comment: 'Number of Skilled Workers'
    });

    await queryInterface.addColumn('business_partner', 'employees_non_technical_staff', {
      type: Sequelize.INTEGER,
      allowNull: true,
      comment: 'Number of Non-Technical Staff'
    });

    await queryInterface.addColumn('business_partner', 'employees_unskilled_workers', {
      type: Sequelize.INTEGER,
      allowNull: true,
      comment: 'Number of Unskilled Workers'
    });

    await queryInterface.addColumn('business_partner', 'working_hours', {
      type: Sequelize.STRING(50),
      allowNull: true,
      comment: 'Working hours'
    });

    await queryInterface.addColumn('business_partner', 'number_of_shifts', {
      type: Sequelize.INTEGER,
      allowNull: true,
      comment: 'Number of Shifts'
    });

    await queryInterface.addColumn('business_partner', 'shift_timings', {
      type: Sequelize.STRING(200),
      allowNull: true,
      comment: 'Shift timings'
    });

    await queryInterface.addColumn('business_partner', 'iso_9001_certified', {
      type: Sequelize.BOOLEAN,
      allowNull: true,
      comment: 'Is the Company Certified for ISO 9001?'
    });

    await queryInterface.addColumn('business_partner', 'iso_9001_certification_planned', {
      type: Sequelize.BOOLEAN,
      allowNull: true,
      comment: 'If No, Is there any plan to get Certification?'
    });

    await queryInterface.addColumn('business_partner', 'iso_9001_certification_target', {
      type: Sequelize.DATEONLY,
      allowNull: true,
      comment: 'If Yes, Target date for ISO 9001 certification'
    });

    await queryInterface.addColumn('business_partner', 'major_customer', {
      type: Sequelize.STRING(500),
      allowNull: true,
      comment: 'Major Customer'
    });
  },

  async down(queryInterface, Sequelize) {
    // Remove all added columns
    await queryInterface.removeColumn('business_partner', 'year_of_establishment');
    await queryInterface.removeColumn('business_partner', 'total_area_sqft');
    await queryInterface.removeColumn('business_partner', 'built_up_area_sqft');
    await queryInterface.removeColumn('business_partner', 'building_type');
    await queryInterface.removeColumn('business_partner', 'nature_of_business');
    await queryInterface.removeColumn('business_partner', 'nature_of_manufacturing_service');
    await queryInterface.removeColumn('business_partner', 'company_type');
    await queryInterface.removeColumn('business_partner', 'phone_numbers');
    await queryInterface.removeColumn('business_partner', 'fax_number');
    await queryInterface.removeColumn('business_partner', 'md_partner_proprietor_name');
    await queryInterface.removeColumn('business_partner', 'experience_in_field');
    await queryInterface.removeColumn('business_partner', 'handling_facilities');
    await queryInterface.removeColumn('business_partner', 'capacity_plant');
    await queryInterface.removeColumn('business_partner', 'capacity_installed');
    await queryInterface.removeColumn('business_partner', 'capacity_spare');
    await queryInterface.removeColumn('business_partner', 'generator_available');
    await queryInterface.removeColumn('business_partner', 'generator_capacity');
    await queryInterface.removeColumn('business_partner', 'machinery_details');
    await queryInterface.removeColumn('business_partner', 'measuring_equipments_details');
    await queryInterface.removeColumn('business_partner', 'employees_technical_staff');
    await queryInterface.removeColumn('business_partner', 'employees_skilled_workers');
    await queryInterface.removeColumn('business_partner', 'employees_non_technical_staff');
    await queryInterface.removeColumn('business_partner', 'employees_unskilled_workers');
    await queryInterface.removeColumn('business_partner', 'working_hours');
    await queryInterface.removeColumn('business_partner', 'number_of_shifts');
    await queryInterface.removeColumn('business_partner', 'shift_timings');
    await queryInterface.removeColumn('business_partner', 'iso_9001_certified');
    await queryInterface.removeColumn('business_partner', 'iso_9001_certification_planned');
    await queryInterface.removeColumn('business_partner', 'iso_9001_certification_target');
    await queryInterface.removeColumn('business_partner', 'major_customer');
  }
};
