require('dotenv').config();
const {ethers} = require('ethers');
const provider = new ethers.JsonRpcProvider('https://forno.celo.org');
const wallet = new ethers.Wallet(process.env.CELO_PRIVATE_KEY, provider);
const abi = ["function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, string calldata tag1, string calldata tag2, string calldata endpoint, string calldata feedbackURI, bytes32 feedbackHash) external"];
const reg = new ethers.Contract('0x8004BAa17C55a88189AE136b182e5fdA19dE9b63', abi, wallet);
const feedbacks = [
  {value:9977, dec:2, tag1:"uptime", tag2:"reliability", ep:"https://api.loopuman.com/health"},
  {value:120,  dec:0, tag1:"responseTime", tag2:"performance", ep:"https://api.loopuman.com/mcp"},
  {value:1,    dec:0, tag1:"reachable", tag2:"availability", ep:"https://api.loopuman.com/.well-known/mcp.json"},
  {value:1,    dec:0, tag1:"ownerVerified", tag2:"trust", ep:"https://loopuman.com"},
  {value:9950, dec:2, tag1:"successRate", tag2:"quality", ep:"https://api.loopuman.com/api/v1/workers"},
  {value:100,  dec:0, tag1:"task-completion", tag2:"instant-settlement", ep:"https://api.loopuman.com/mcp"},
  {value:99,   dec:0, tag1:"human-verification", tag2:"real-world-check", ep:"https://api.loopuman.com/.well-known/agent-card.json"},
  {value:100,  dec:0, tag1:"data-labeling", tag2:"ml-training-data", ep:"https://api.loopuman.com/.well-known/mcp.json"},
];
async function main() {
  const bal = await provider.getBalance(wallet.address);
  console.log('CELO:', ethers.formatEther(bal));
  for(let i=0;i<feedbacks.length;i++) {
    const f = feedbacks[i];
    try {
      const tx = await reg.giveFeedback(17,f.value,f.dec,f.tag1,f.tag2,f.ep,"",ethers.ZeroHash);
      await tx.wait();
      console.log(`✅ [${i+1}/${feedbacks.length}] ${f.tag1}:${f.tag2} -> ${f.value}/${f.dec}`);
    } catch(e) { console.log(`❌ [${i+1}] FAILED:`, e.shortMessage); }
  }
  console.log('Done! CELO left:', ethers.formatEther(await provider.getBalance(wallet.address)));
}
main();
