'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    const rows = [
      { currency_code: 'INR', currency_name: 'Indian Rupee', currency_symbol: '₹', decimal_places: 2, is_base_currency: 1, status: 'ACTIVE' },
      { currency_code: 'USD', currency_name: 'US Dollar', currency_symbol: '$', decimal_places: 2, is_base_currency: 0, status: 'ACTIVE' },
      { currency_code: 'EUR', currency_name: 'Euro', currency_symbol: '€', decimal_places: 2, is_base_currency: 0, status: 'ACTIVE' },
      { currency_code: 'GBP', currency_name: 'British Pound', currency_symbol: '£', decimal_places: 2, is_base_currency: 0, status: 'ACTIVE' }
    ];
    const dialect = queryInterface.sequelize.getDialect ? queryInterface.sequelize.getDialect() : 'mysql';
    if (dialect === 'mysql' || dialect === 'mariadb') {
      for (const r of rows) {
        await queryInterface.sequelize.query(
          `INSERT IGNORE INTO currency (currency_code, currency_name, currency_symbol, decimal_places, is_base_currency, status, created_at, updated_at)
           VALUES (:currency_code, :currency_name, :currency_symbol, :decimal_places, :is_base_currency, :status, NOW(), NOW())`,
          { replacements: r }
        );
      }
    } else {
      await queryInterface.bulkInsert('currency', rows.map((r) => ({
        ...r,
        is_base_currency: !!r.is_base_currency,
        created_at: new Date(),
        updated_at: new Date()
      })), { ignoreDuplicates: true });
    }
  },

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

