/**
 * Dev seed — 注册 PAC 一期接入的 hosts。
 *
 * 当前注册:
 *   - jvs-dw   瑞尔集团 DW 数仓(一期试点 host,数据通过 cold-import 摄入)
 *              单 host 多 tenant — manifest yaml 临时映射 brand → DW UUID
 *                瑞尔 → ba67e6cf30dc4f9c9c46adef188bbd04
 *                瑞泰 → 77057aed269f4a14957ae0ad0eff359a
 *              (DW 补全各表 tenant_id 字段后,改 tenant_field=tenant_id pass-through)
 *
 * After seeding:
 *   POST /pac/v1/auth/token  with appId=jvs-dw-app + appSecret=<plaintext> → JWT
 */
import { PrismaClient } from '@prisma/client';
import { hashSecret } from '@pac/utils';

const prisma = new PrismaClient();

async function main() {
  const jvsDwAppSecret = 'jvs-dw-secret-dev';
  const jvsDwPushSecret = 'jvs-dw-push-secret-dev';

  const jvsDw = await prisma.host.upsert({
    where: { appId: 'jvs-dw-app' },
    update: {},
    create: {
      name: 'jvs-dw',
      appId: 'jvs-dw-app',
      appSecretHash: hashSecret(jvsDwAppSecret),
      // 一期走 cold-import;pull 通道(ClickHouseSqlPullStrategy)留后续
      pullConfig: {
        endpoints: {},
        amountUnit: 'yuan',
        timezone: 'Asia/Shanghai',
        intervalMinutes: 5,
      },
      pushSecretHashes: [hashSecret(jvsDwPushSecret)],
      actionUrls: {},
      active: true,
    },
  });

  // eslint-disable-next-line no-console
  console.log(
    `Seeded host:\n` +
      `  id=${jvsDw.id}\n` +
      `  name=${jvsDw.name}\n` +
      `  appId=jvs-dw-app   appSecret=${jvsDwAppSecret}\n` +
      `  pushSecret=${jvsDwPushSecret}(数组 1 个 key)`,
  );
}

main()
  .catch((e) => {
    // eslint-disable-next-line no-console
    console.error(e);
    process.exit(1);
  })
  .finally(() => void prisma.$disconnect());
