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:95, tag1:"human-layer", tag2:"enterprise-grade", endpoint:"https://api.loopuman.com/.well-known/agent-card.json", uri:"https://api.loopuman.com/task-result-sample.json"},
  {score:94, tag1:"ai-agents", tag2:"celo-native", endpoint:"https://api.loopuman.com/.well-known/mcp.json", uri:"https://api.loopuman.com/agent-card.json"},
  {score:96, tag1:"instant-payments", tag2:"real-workers", endpoint:"https://api.loopuman.com/.well-known/agent-registration.json", uri:"https://api.loopuman.com/task-result-sample.json"},
  {score:93, tag1:"production-ready", tag2:"human-in-loop", endpoint:"https://loopuman.com", uri:"https://api.loopuman.com/agent-card.json"},
];

(async()=>{
  for(let i=0;i<feedbacks.length;i++){
    const fb=feedbacks[i];
    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)+"/4] "+fb.tag1+":"+fb.tag2+" -> score:"+fb.score);
  }
  console.log("🎉 Done! 4 new feedback submitted");
})();
