'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    const dialect = queryInterface.sequelize.getDialect ? queryInterface.sequelize.getDialect() : 'mysql';
    const countries = [
      { country_code: 'IND', country_code_iso2: 'IN', country_name: 'India', phone_code: '+91', currency_code: 'INR', is_active: 1 },
      { country_code: 'USA', country_code_iso2: 'US', country_name: 'United States', phone_code: '+1', currency_code: 'USD', is_active: 1 },
      { country_code: 'GBR', country_code_iso2: 'GB', country_name: 'United Kingdom', phone_code: '+44', currency_code: 'GBP', is_active: 1 }
    ];
    if (dialect === 'mysql' || dialect === 'mariadb') {
      for (const row of countries) {
        await queryInterface.sequelize.query(
          `INSERT IGNORE INTO country (country_code, country_code_iso2, country_name, phone_code, currency_code, is_active, created_at, updated_at)
           VALUES (:country_code, :country_code_iso2, :country_name, :phone_code, :currency_code, :is_active, NOW(), NOW())`,
          { replacements: { ...row } }
        );
      }
    } else {
      await queryInterface.bulkInsert('country', countries.map((row) => ({
        ...row,
        is_active: row.is_active === 1,
        created_at: new Date(),
        updated_at: new Date()
      })), { ignoreDuplicates: true });
    }
  },

  async down(queryInterface, Sequelize) {
    await queryInterface.bulkDelete('country', null, {});
  }
};

