import chalk from "chalk";
import { runMigration } from "../../integrations/linear/migration.js";
function getEnv(key, defaultValue) {
  const value = process.env[key];
  if (value === void 0) {
    if (defaultValue !== void 0) return defaultValue;
    throw new Error(`Environment variable ${key} is required`);
  }
  return value;
}
function getOptionalEnv(key) {
  return process.env[key];
}
function registerLinearMigrateCommand(parent) {
  parent.command("linear:migrate").description("Migrate STA- tasks from LiftCL to new Linear workspace").option("--source-key <key>", "Source workspace Linear API key").option("--target-key <key>", "Target workspace Linear API key").option("--dry-run", "Preview migration without making changes").option(
    "--delete-source",
    "Delete tasks from source after successful migration"
  ).option("--batch-size <n>", "Number of tasks per batch", "3").option("--delay <ms>", "Delay between batches in milliseconds", "3000").action(async (options) => {
    try {
      const sourceKey = options.sourceKey || process.env["LINEAR_API_KEY"];
      const targetKey = options.targetKey;
      if (!sourceKey) {
        console.error(
          chalk.red(
            "\u274C Source API key required. Use --source-key or set LINEAR_API_KEY"
          )
        );
        return;
      }
      if (!targetKey) {
        console.error(
          chalk.red("\u274C Target API key required. Use --target-key")
        );
        return;
      }
      console.log(chalk.blue("\u{1F680} Starting Linear Migration"));
      console.log(chalk.gray("   This will migrate all STA- prefixed tasks"));
      if (options.deleteSource) {
        console.log(
          chalk.yellow(
            "   \u26A0\uFE0F  Tasks will be DELETED from source after migration"
          )
        );
      }
      console.log();
      await runMigration({
        sourceApiKey: sourceKey,
        targetApiKey: targetKey,
        taskPrefix: "STA-",
        deleteFromSource: options.deleteSource,
        dryRun: options.dryRun,
        batchSize: parseInt(options.batchSize),
        delayMs: parseInt(options.delay)
      });
    } catch (error) {
      console.error(chalk.red("Migration failed:"), error.message);
      process.exit(1);
    }
  });
}
export {
  registerLinearMigrateCommand
};
//# sourceMappingURL=linear-migrate.js.map
