/**
 * Migration: Update categories to 6 types
 * travel(出行), accommodation(住宿), guide(导游), translation(翻译), consulting(咨询), other(其他)
 */

const { v4: uuidv4 } = require('uuid');

module.exports = {
  up: async (queryInterface, Sequelize) => {
    const now = new Date();
    
    // 先删除 service 表中的数据（因为有外键约束）
    await queryInterface.bulkDelete('service', null, {});
    console.log('✓ Deleted services');
    
    // 删除旧分类
    await queryInterface.bulkDelete('category', null, {});
    console.log('✓ Deleted old categories');
    
    // 插入新的6个分类
    const categories = [
      {
        id: uuidv4(),
        key: 'travel',
        name_zh: '出行',
        name_en: 'Travel',
        name_pt: 'Viagem',
        icon: '/icons/travel.png',
        sort_order: 1,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        key: 'accommodation',
        name_zh: '住宿',
        name_en: 'Accommodation',
        name_pt: 'Hospedagem',
        icon: '/icons/accommodation.png',
        sort_order: 2,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        key: 'guide',
        name_zh: '导游',
        name_en: 'Guide',
        name_pt: 'Guia',
        icon: '/icons/guide.png',
        sort_order: 3,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        key: 'translation',
        name_zh: '翻译',
        name_en: 'Translation',
        name_pt: 'Tradução',
        icon: '/icons/translation.png',
        sort_order: 4,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        key: 'consulting',
        name_zh: '咨询',
        name_en: 'Consulting',
        name_pt: 'Consultoria',
        icon: '/icons/consulting.png',
        sort_order: 5,
        created_at: now,
        updated_at: now,
      },
      {
        id: uuidv4(),
        key: 'other',
        name_zh: '其他',
        name_en: 'Other',
        name_pt: 'Outro',
        icon: '/icons/other.png',
        sort_order: 6,
        created_at: now,
        updated_at: now,
      },
    ];

    await queryInterface.bulkInsert('category', categories);
    console.log('✓ Inserted 6 new categories');
  },

  down: async (queryInterface, Sequelize) => {
    // 回滚时不做任何操作
    console.log('⊘ Rollback not supported for this migration');
  }
};
