import db from "../src/models/index.js";
import TransactionController from "../src/controllers/transactionController.js";

/**
 * DRY RUN VERIFICATION SCRIPT
 * This script mocks a 9PSB webhook and checks if the extraction logic works.
 * It does NOT send real webhooks.
 */

async function verifyWebhookLogic() {
  console.log("🏁 Starting Dry Run Verification...");

  const mockPayload = {
    "transaction": {
      "sessionid": "TEST_SESSION_12345",
      "date": "2026-04-02T17:09:05"
    },
    "customer": {
      "account": {
        "number": "6400001348",
        "sendername": "DANIEL OSAGIE ABIEVBODE",
        "senderaccountnumber": "8032184432",
        "senderbankname": "Palmpay",
        "senderbankcode": "100033"
      }
    },
    "order": {
      "amount": "200",
      "currency": "NGN"
    },
    "code": "00"
  };

  const req = { body: mockPayload };
  const res = {
    status: (code) => ({
      json: (data) => console.log(`📡 Response [${code}]:`, data)
    })
  };

  try {
    // 1. Manually testing the extraction logic (mimicking handleWebhook)
    const { transaction, customer: pCustomer, order } = mockPayload;
    const amount = parseFloat(order?.amount);
    
    console.log("-----------------------------------------");
    console.log("🔍 Extraction Test:");
    console.log(`✅ Sender Name: ${pCustomer?.account?.sendername}`);
    console.log(`✅ Date: ${transaction?.date}`);
    console.log(`✅ Amount: ${amount}`);
    console.log("-----------------------------------------");

    if (pCustomer?.account?.sendername === "DANIEL OSAGIE ABIEVBODE" && transaction?.date === "2026-04-02T17:09:05") {
      console.log("🏆 Logic Verified: Webhook data is extracted correctly!");
    } else {
      throw new Error("Logic Mismatch!");
    }

  } catch (error) {
    console.error("❌ Verification Failed:", error.message);
  } finally {
    process.exit();
  }
}

verifyWebhookLogic();
