#!/usr/bin/env node

import { mkdirSync, writeFileSync } from "fs";
import path from "path";

const outputPath = process.argv[2];
if (!outputPath) {
  console.error("Usage: node scripts/write-default-db.mjs <output-path>");
  process.exit(1);
}

const now = new Date();
const expires = new Date(now.getTime() + 14 * 24 * 60 * 60 * 1000);
const db = {
  account: {
    id: "acct-local",
    accountName: "未连接 Pinterest",
    businessAccount: false,
    scopes: [],
    tokenStatus: "missing",
    updatedAt: now.toISOString()
  },
  oauth: {
    state: {
      scopes: []
    },
    token: {}
  },
  boards: [
    {
      id: "board-demo-1",
      name: "Product Ideas",
      description: "用于承接产品 Pin 和内容灵感的示例图板。",
      privacy: "PUBLIC",
      pinCount: 0,
      createdAt: now.toISOString(),
      updatedAt: now.toISOString()
    }
  ],
  pinDrafts: [
    {
      id: "pin-demo-1",
      boardId: "board-demo-1",
      title: "Seasonal product inspiration",
      description: "用趋势关键词和真实产品卖点生成的 Pin 草稿，等待人工确认。",
      link: "https://example.com/product",
      mediaType: "image",
      keywords: ["seasonal", "product", "inspiration"],
      status: "pending_review",
      createdAt: now.toISOString(),
      updatedAt: now.toISOString()
    }
  ],
  operatorPlans: [],
  trendResearch: [],
  leads: [],
  knowledgeDocuments: [],
  tasks: [],
  auditLogs: [],
  license: {
    licenseId: "trial-local",
    customerName: "试用客户",
    plan: "growth",
    status: "trial",
    purchaseType: "trial",
    issuedAt: now.toISOString(),
    expiresAt: expires.toISOString(),
    seats: 1,
    pinterestAccounts: 1,
    verificationStatus: "unverified",
    remoteServerUrl: "",
    remoteLicenseKey: "",
    heartbeatStatus: "not_configured",
    graceHours: 5
  },
  riskLimits: {
    dailyTrendResearches: 20,
    dailyPinPublishes: 20,
    dailyBoardCreates: 5,
    dailyApiWrites: 80,
    requireApprovalForPublish: true,
    requireApprovalForFollow: true,
    requireApprovalForComment: true,
    requireApprovalForMessage: true
  }
};

mkdirSync(path.dirname(outputPath), { recursive: true });
writeFileSync(outputPath, `${JSON.stringify(db, null, 2)}\n`);
