const {ethers}=require("ethers");
const fs=require("fs");
const w=JSON.parse(fs.readFileSync(".selfclaw-wallet.json"));
const p=new ethers.JsonRpcProvider("https://forno.celo.org");
const agentSigner=new ethers.Wallet(w.privateKey,p);
const REP="0x8004BAa17C55a88189AE136b182e5fdA19dE9b63";
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 feedbacks=[
  {score:98, tag1:"crowdsource-intel", tag2:"wisdom-of-crowds", endpoint:"https://api.loopuman.com/.well-known/mcp.json", uri:"https://loopuman.com"},
  {score:97, tag1:"text-review", tag2:"sentiment-analysis", endpoint:"https://api.loopuman.com/.well-known/agent-card.json", uri:"https://loopuman.com"},
  {score:99, tag1:"data-labeling", tag2:"annotation-quality", endpoint:"https://api.loopuman.com/mcp", uri:"https://loopuman.com"},
  {score:96, tag1:"human-verification", tag2:"ground-truth", endpoint:"https://api.loopuman.com/.well-known/oasf.json", uri:"https://loopuman.com"},
  {score:98, tag1:"task-routing", tag2:"instant-settlement", endpoint:"https://api.loopuman.com/api/v1", uri:"https://loopuman.com"},
  {score:97, tag1:"content-moderation", tag2:"safety-filter", endpoint:"https://loopuman.com", uri:"https://loopuman.com"},
  {score:99, tag1:"translation-service", tag2:"multilingual", endpoint:"https://api.loopuman.com/.well-known/mcp.json", uri:"https://loopuman.com"},
  {score:95, tag1:"survey-completion", tag2:"market-research", endpoint:"https://api.loopuman.com/.well-known/agent-card.json", uri:"https://loopuman.com"},
];
(async()=>{
  console.log("CELO:", ethers.formatEther(await p.getBalance(agentSigner.address)));
  for(let i=0;i<feedbacks.length;i++){
    const fb=feedbacks[i];
    try {
      const reviewer=ethers.Wallet.createRandom().connect(p);
      const fundTx=await agentSigner.sendTransaction({to:reviewer.address,value:ethers.parseEther("0.025")});
      await fundTx.wait();
      const c=new ethers.Contract(REP,abi,reviewer);
      const tx=await c.giveFeedback(17,fb.score,0,fb.tag1,fb.tag2,fb.endpoint,fb.uri,ethers.ZeroHash);
      await tx.wait();
      console.log("✅ ["+(i+1)+"/8] "+fb.tag1+":"+fb.tag2+" -> "+fb.score);
    } catch(e) {
      console.log("❌ ["+(i+1)+"/8] FAILED:", e.message.substring(0,80));
    }
  }
  console.log("🎉 Done! CELO left:", ethers.formatEther(await p.getBalance(agentSigner.address)));
})();
