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

/**
 * Seed Categories
 * Creates initial service categories (6 types)
 * travel(出行), accommodation(住宿), guide(导游), translation(翻译), consulting(咨询), other(其他)
 */
module.exports = {
  up: async (queryInterface) => {
    // 检查是否已有分类数据
    const [results] = await queryInterface.sequelize.query('SELECT COUNT(*) as count FROM category');
    if (results[0].count > 0) {
      console.log('✓ Categories already exist, skipping seed');
      return;
    }

    const now = new Date();
    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('✓ Seeded 6 categories');
  },

  down: async (queryInterface) => {
    await queryInterface.bulkDelete('category', null, {});
  },
};
