import { ethers } from "hardhat";
async function main() {
  const [deployer] = await ethers.getSigners();
  console.log("Deployer:", deployer.address);
  console.log("Balance:", ethers.formatEther(await ethers.provider.getBalance(deployer.address)), "POL");

  // 1. AgentSafetyManager - setSafetyOperator
  console.log("\n--- AgentSafetyManager.setSafetyOperator ---");
  const safety = await ethers.getContractAt("AgentSafetyManager", "0xCA5380aF3dd6a29C217cE0c0c9f45999B47cbdF3");
  const isOpBefore = await safety.safetyOperators(deployer.address);
  console.log("Before:", isOpBefore);
  if (!isOpBefore) {
    const tx = await safety.setSafetyOperator(deployer.address, true, { gasLimit: 150000 });
    console.log("TX:", tx.hash);
    await tx.wait();
    const after = await safety.safetyOperators(deployer.address);
    console.log("After:", after, after ? "✓" : "✗");
  } else {
    console.log("Already set ✓");
  }

  // 2. ComplianceRegistry - authorizeAuditor
  console.log("\n--- ComplianceRegistry.authorizeAuditor ---");
  const compliance = await ethers.getContractAt("ComplianceRegistry", "0x2DF3182EcD93AA33Deba464B5E6Bd616432DA42e");
  const audInfo = await compliance.auditors(deployer.address);
  console.log("Before:", audInfo[0]);
  if (!audInfo[0]) {
    const tx = await compliance.authorizeAuditor(deployer.address, "https://vaultfire.io/auditor", { gasLimit: 200000 });
    console.log("TX:", tx.hash);
    await tx.wait();
    const after = await compliance.auditors(deployer.address);
    console.log("After:", after[0], after[0] ? "✓" : "✗");
  } else {
    console.log("Already set ✓");
  }

  // 3. AgentSLAEnforcer - setMonitor
  console.log("\n--- AgentSLAEnforcer.setMonitor ---");
  const sla = await ethers.getContractAt("AgentSLAEnforcer", "0x3f385774dba7d067cda7E5190a659029BF8219dB");
  const isMonBefore = await sla.monitors(deployer.address);
  console.log("Before:", isMonBefore);
  if (!isMonBefore) {
    const tx = await sla.setMonitor(deployer.address, true, { gasLimit: 150000 });
    console.log("TX:", tx.hash);
    await tx.wait();
    const after = await sla.monitors(deployer.address);
    console.log("After:", after, after ? "✓" : "✗");
  } else {
    console.log("Already set ✓");
  }

  console.log("\nDone ✓");
}
main().catch(console.error);
