import "dotenv/config";
import "reflect-metadata";
import { AppDataSource } from "../database/data-source";
import { clearOldOrgRevisionData } from "../services/ClearOldOrgRevisionService";

// "clear:old-org-revision": "ts-node src/scripts/ClearOldOrgRevision.ts",

const defaultOrgRevisionId = "24dacf63-d289-496c-8102-8b25079dbaf2";

async function main(): Promise<void> {
  const orgRevisionId = process.argv[2] || defaultOrgRevisionId;

  try {
    await AppDataSource.initialize();
    const result = await clearOldOrgRevisionData(orgRevisionId);
    console.info(JSON.stringify(result, null, 2));
  } catch (error) {
    console.error("[ClearOldOrgRevision] Failed:", error);
    process.exitCode = 1;
  } finally {
    if (AppDataSource.isInitialized) {
      await AppDataSource.destroy();
    }
  }
}

void main();
