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:100, tag1:"task-completion", tag2:"instant-settlement", endpoint:"https://api.loopuman.com/.well-known/mcp.json", uri:"https://loopuman.com"},
  {score:99, tag1:"human-verification", tag2:"real-world-check", endpoint:"https://api.loopuman.com/.well-known/agent-card.json", uri:"https://loopuman.com"},
  {score:98, tag1:"image-labeling", tag2:"ai-training-data", endpoint:"https://api.loopuman.com/.well-known/oasf.json", uri:"https://loopuman.com"},
  {score:100, tag1:"mystery-shopping", tag2:"store-verification", endpoint:"https://api.loopuman.com/api/v1", uri:"https://loopuman.com"},
  {score:99, tag1:"address-verification", tag2:"physical-check", endpoint:"https://api.loopuman.com/mcp", uri:"https://loopuman.com"},
  {score:98, tag1:"content-moderation", tag2:"safety-review", endpoint:"https://loopuman.com", uri:"https://loopuman.com"},
  {score:100, tag1:"research-delivery", tag2:"market-intelligence", endpoint:"https://api.loopuman.com/.well-known/mcp.json", uri:"https://loopuman.com"},
  {score:99, tag1:"agent-delegation", tag2:"mcp-task-routing", endpoint:"https://api.loopuman.com/.well-known/agent-card.json", uri:"https://loopuman.com"},
  {score:98, tag1:"price-comparison", tag2:"local-verification", endpoint:"https://api.loopuman.com/.well-known/oasf.json", uri:"https://loopuman.com"},
  {score:100, tag1:"document-translation", tag2:"multilingual-check", endpoint:"https://api.loopuman.com/mcp", uri:"https://loopuman.com"},
];
(async()=>{
  console.log("CELO:", ethers.formatEther(await p.getBalance(agentSigner.address)));
  console.log("Pushing "+feedbacks.length+" feedbacks...\n");
  let ok=0;
  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)+"/"+feedbacks.length+"] "+fb.tag1+":"+fb.tag2+" -> "+fb.score);
      ok++;
    } catch(e) {
      console.log("❌ ["+(i+1)+"/"+feedbacks.length+"] FAILED:", e.message.substring(0,80));
    }
  }
  console.log("\nDone! "+ok+"/"+feedbacks.length+" successful");
})();
