/**
 * platform_master 字典 / 参考数据 seed
 *
 * PR1 范围：L1b 字典（Currency / Country / GeoRegion / UnitOfMeasure / Dictionary）
 * 详见 docs/modules/robot-manager/business-analysis/重构方案.md §3.4
 */

import { PrismaClient } from '@prisma/client';

export async function seedPlatformMaster(prisma: PrismaClient) {
  const now = new Date();

  // Currencies — 项目当前主要结算币种
  await prisma.currency.createMany({
    data: [
      { code: 'USD', name: 'US Dollar', symbol: '$', decimals: 2, updatedAt: now },
      { code: 'CNY', name: '人民币', symbol: '¥', decimals: 2, updatedAt: now },
      { code: 'EUR', name: 'Euro', symbol: '€', decimals: 2, updatedAt: now },
      { code: 'AED', name: 'UAE Dirham', symbol: 'د.إ', decimals: 2, updatedAt: now },
    ],
    skipDuplicates: true,
  });

  // Countries — 项目当前覆盖国家
  await prisma.country.createMany({
    data: [
      { code: 'CN', iso3: 'CHN', name: 'China',                  region: 'APAC', updatedAt: now },
      { code: 'US', iso3: 'USA', name: 'United States',          region: 'NA',   updatedAt: now },
      { code: 'AE', iso3: 'ARE', name: 'United Arab Emirates',   region: 'MEA',  updatedAt: now },
      { code: 'DE', iso3: 'DEU', name: 'Germany',                region: 'EU',   updatedAt: now },
      { code: 'GB', iso3: 'GBR', name: 'United Kingdom',         region: 'EU',   updatedAt: now },
    ],
    skipDuplicates: true,
  });

  // GeoRegions
  await prisma.geoRegion.createMany({
    data: [
      { code: 'APAC', name: 'Asia-Pacific',  countries: ['CN'],       updatedAt: now },
      { code: 'NA',   name: 'North America', countries: ['US'],       updatedAt: now },
      { code: 'MEA',  name: 'Middle East & Africa', countries: ['AE'], updatedAt: now },
      { code: 'EU',   name: 'Europe',        countries: ['DE', 'GB'], updatedAt: now },
    ],
    skipDuplicates: true,
  });

  // UnitOfMeasure
  await prisma.unitOfMeasure.createMany({
    data: [
      { code: 'PCS', name: 'Piece',     category: 'count',  updatedAt: now },
      { code: 'KG',  name: 'Kilogram',  category: 'weight', updatedAt: now },
      { code: 'L',   name: 'Liter',     category: 'volume', updatedAt: now },
      { code: 'M',   name: 'Meter',     category: 'length', updatedAt: now },
    ],
    skipDuplicates: true,
  });

  // Dictionaries — 多个 category 的统一字典
  await prisma.dictionary.createMany({
    data: [
      // label_type — 7 个质量标签类型（v5 #63-#69）
      { category: 'label_type', code: 'BODY_FCC',         labelEn: 'Body FCC Label',      labelZh: '机身 FCC 标',  sortOrder: 1, updatedAt: now },
      { category: 'label_type', code: 'BODY_MADE_IN_CN',  labelEn: 'Body Made in CN',     labelZh: '机身 Made in CN 标', sortOrder: 2, updatedAt: now },
      { category: 'label_type', code: 'BODY_SN',          labelEn: 'Body SN Label',       labelZh: '机身 SN 标',   sortOrder: 3, updatedAt: now },
      { category: 'label_type', code: 'REMOTE_SN',        labelEn: 'Remote SN Label',     labelZh: '遥控器 SN 标', sortOrder: 4, updatedAt: now },
      { category: 'label_type', code: 'BATTERY_SN',       labelEn: 'Battery SN Label',    labelZh: '电池 SN 标',   sortOrder: 5, updatedAt: now },
      { category: 'label_type', code: 'INSPECTION_SHEET', labelEn: 'Inspection Sheet',    labelZh: '检验单标',     sortOrder: 6, updatedAt: now },
      { category: 'label_type', code: 'SHIPPING_BOX',     labelEn: 'Shipping Box Label',  labelZh: '出货箱标',     sortOrder: 7, updatedAt: now },

      // tariff_type
      { category: 'tariff_type', code: 'GENERAL',  labelEn: 'General Tariff',  labelZh: '一般关税', sortOrder: 1, updatedAt: now },
      { category: 'tariff_type', code: 'BONDED',   labelEn: 'Bonded',           labelZh: '保税',     sortOrder: 2, updatedAt: now },
      { category: 'tariff_type', code: 'FTA',      labelEn: 'FTA Preferential', labelZh: '自贸协定', sortOrder: 3, updatedAt: now },

      // declaration_type
      { category: 'declaration_type', code: 'NORMAL_IMPORT',  labelEn: 'Normal Import',  labelZh: '一般进口', sortOrder: 1, updatedAt: now },
      { category: 'declaration_type', code: 'BONDED_IMPORT',  labelEn: 'Bonded Import',  labelZh: '保税进口', sortOrder: 2, updatedAt: now },
      { category: 'declaration_type', code: 'TEMP_IMPORT',    labelEn: 'Temporary Import', labelZh: '暂时进口', sortOrder: 3, updatedAt: now },

      // service_issue_type — 来自 v5 实际 issue tag 取值
      { category: 'service_issue_type', code: 'WATER_DAMAGE',  labelEn: 'Water Damage',   labelZh: '进水',     sortOrder: 1, updatedAt: now },
      { category: 'service_issue_type', code: 'FRONT_DAMAGE',  labelEn: 'Front Damage',   labelZh: '前部损伤', sortOrder: 2, updatedAt: now },
      { category: 'service_issue_type', code: 'DISSEMBLED',    labelEn: 'Dissembled',     labelZh: '已拆解',   sortOrder: 3, updatedAt: now },
      { category: 'service_issue_type', code: 'BATTERY_ISSUE', labelEn: 'Battery Issue',  labelZh: '电池故障', sortOrder: 4, updatedAt: now },
      { category: 'service_issue_type', code: 'OTHER',         labelEn: 'Other',          labelZh: '其他',     sortOrder: 99, updatedAt: now },

      // industry — 客户行业（可选）
      { category: 'industry', code: 'ROBOTICS',    labelEn: 'Robotics',         labelZh: '机器人',   sortOrder: 1, updatedAt: now },
      { category: 'industry', code: 'AUTOMOTIVE',  labelEn: 'Automotive',       labelZh: '汽车',     sortOrder: 2, updatedAt: now },
      { category: 'industry', code: 'EDUCATION',   labelEn: 'Education',        labelZh: '教育',     sortOrder: 3, updatedAt: now },
      { category: 'industry', code: 'REAL_ESTATE', labelEn: 'Real Estate',      labelZh: '房地产',   sortOrder: 4, updatedAt: now },
      { category: 'industry', code: 'OTHER',       labelEn: 'Other',            labelZh: '其他',     sortOrder: 99, updatedAt: now },
    ],
    skipDuplicates: true,
  });

  console.log('  ✓ platform_master seed: currencies(4), countries(5), geo_regions(4), units_of_measure(4), dictionaries(22)');
}
