import { ethers } from "hardhat";
async function main() {
  const sla = await ethers.getContractAt("AgentSLAEnforcer", "0xc0b7cFF13C7C7f4DAF36A7c67da47B2Cb311335D");
  const [deployer] = await ethers.getSigners();
  
  console.log("Deployer:", deployer.address);
  console.log("SLA owner:", await sla.owner());
  
  // Read current state
  const before = await sla.monitors(deployer.address);
  console.log("monitors[deployer] before:", before);
  
  // Set monitor with explicit gas
  console.log("Sending setMonitor tx...");
  const tx = await sla.setMonitor(deployer.address, true, { gasLimit: 100000 });
  console.log("TX hash:", tx.hash);
  const receipt = await tx.wait();
  console.log("TX status:", receipt?.status);
  console.log("Gas used:", receipt?.gasUsed?.toString());
  console.log("Events:", receipt?.logs?.length);
  
  // Wait a moment then read again
  await new Promise(r => setTimeout(r, 3000));
  
  const after = await sla.monitors(deployer.address);
  console.log("monitors[deployer] after:", after);
  
  // Also try reading the owner function and stats to make sure contract is responsive
  const stats = await sla.getSLAStats();
  console.log("SLA stats:", stats[0].toString(), stats[1].toString(), stats[2].toString());
}
main().catch(console.error);
