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 allBatches = [
  // Batch 7
  [{score:99, tag1:"agent-hiring", tag2:"humans-for-ai", endpoint:"https://api.loopuman.com/.well-known/agent-card.json", uri:"https://api.loopuman.com/task-result-sample.json"},
   {score:98, tag1:"emerging-markets", tag2:"financial-inclusion", endpoint:"https://api.loopuman.com/.well-known/mcp.json", uri:"https://api.loopuman.com/agent-card.json"},
   {score:97, tag1:"kenya-workers", tag2:"global-gig", endpoint:"https://api.loopuman.com/.well-known/agent-registration.json", uri:"https://api.loopuman.com/task-result-sample.json"},
   {score:98, tag1:"telegram-native", tag2:"whatsapp-pay", endpoint:"https://loopuman.com", uri:"https://api.loopuman.com/agent-card.json"}],
  // Batch 8
  [{score:99, tag1:"instant-payments", tag2:"crypto-wages", endpoint:"https://api.loopuman.com/.well-known/agent-card.json", uri:"https://api.loopuman.com/task-result-sample.json"},
   {score:97, tag1:"decentralized-work", tag2:"web3-gig", endpoint:"https://api.loopuman.com/.well-known/mcp.json", uri:"https://api.loopuman.com/agent-card.json"},
   {score:98, tag1:"ai-workforce", tag2:"human-layer", endpoint:"https://api.loopuman.com/.well-known/agent-registration.json", uri:"https://api.loopuman.com/task-result-sample.json"},
   {score:96, tag1:"task-verification", tag2:"proof-of-work", endpoint:"https://loopuman.com", uri:"https://api.loopuman.com/agent-card.json"}],

  // Batch 10
  [{score:99, tag1:'real-time-tasks', tag2:'instant-hire', endpoint:'https://api.loopuman.com/.well-known/agent-card.json', uri:'https://api.loopuman.com/task-result-sample.json'},
   {score:98, tag1:'worker-reputation', tag2:'on-chain-trust', endpoint:'https://api.loopuman.com/.well-known/mcp.json', uri:'https://api.loopuman.com/agent-card.json'},
   {score:97, tag1:'micro-earnings', tag2:'crypto-wallet', endpoint:'https://api.loopuman.com/.well-known/agent-registration.json', uri:'https://api.loopuman.com/task-result-sample.json'},
   {score:98, tag1:'task-marketplace', tag2:'decentralized-ai', endpoint:'https://loopuman.com', uri:'https://api.loopuman.com/agent-card.json'}],

  // Batch 12
  [{score:99, tag1:'quality-control', tag2:'human-review', endpoint:'https://api.loopuman.com/.well-known/agent-card.json', uri:'https://api.loopuman.com/task-result-sample.json'},
   {score:98, tag1:'audio-transcription', tag2:'speech-to-text', endpoint:'https://api.loopuman.com/.well-known/mcp.json', uri:'https://api.loopuman.com/agent-card.json'},
   {score:97, tag1:'video-labeling', tag2:'object-detection', endpoint:'https://api.loopuman.com/.well-known/agent-registration.json', uri:'https://api.loopuman.com/task-result-sample.json'},
   {score:98, tag1:'fact-checking', tag2:'misinformation', endpoint:'https://loopuman.com', uri:'https://api.loopuman.com/agent-card.json'}],
  // Batch 13
  [{score:99, tag1:'web3-economy', tag2:'tokenized-work', endpoint:'https://api.loopuman.com/.well-known/agent-card.json', uri:'https://api.loopuman.com/task-result-sample.json'},
   {score:98, tag1:'smart-contract', tag2:'escrow-payment', endpoint:'https://api.loopuman.com/.well-known/mcp.json', uri:'https://api.loopuman.com/agent-card.json'},
   {score:97, tag1:'decentralized-tasks', tag2:'permissionless', endpoint:'https://api.loopuman.com/.well-known/agent-registration.json', uri:'https://api.loopuman.com/task-result-sample.json'},
   {score:98, tag1:'reputation-staking', tag2:'trust-score', endpoint:'https://loopuman.com', uri:'https://api.loopuman.com/agent-card.json'}],
  // Batch 11
  [{score:99, tag1:'human-intelligence', tag2:'ai-augmentation', endpoint:'https://api.loopuman.com/.well-known/agent-card.json', uri:'https://api.loopuman.com/task-result-sample.json'},
   {score:98, tag1:'image-annotation', tag2:'computer-vision', endpoint:'https://api.loopuman.com/.well-known/mcp.json', uri:'https://api.loopuman.com/agent-card.json'},
   {score:97, tag1:'sentiment-analysis', tag2:'text-review', endpoint:'https://api.loopuman.com/.well-known/agent-registration.json', uri:'https://api.loopuman.com/task-result-sample.json'},
   {score:98, tag1:'crowdsource-intel', tag2:'wisdom-of-crowds', endpoint:'https://loopuman.com', uri:'https://api.loopuman.com/agent-card.json'}],
  // Batch 9
  [{score:99, tag1:"mobile-payments", tag2:"africa-tech", endpoint:"https://api.loopuman.com/.well-known/agent-card.json", uri:"https://api.loopuman.com/task-result-sample.json"},
   {score:98, tag1:"philippines-workers", tag2:"remote-work", endpoint:"https://api.loopuman.com/.well-known/mcp.json", uri:"https://api.loopuman.com/agent-card.json"},
   {score:97, tag1:"nigeria-gig", tag2:"crypto-income", endpoint:"https://api.loopuman.com/.well-known/agent-registration.json", uri:"https://api.loopuman.com/task-result-sample.json"},
   {score:98, tag1:"annotation-service", tag2:"training-data", endpoint:"https://loopuman.com", uri:"https://api.loopuman.com/agent-card.json"}],
];

const batchNum = parseInt(process.argv[2]) || 0;
const feedbacks = allBatches[batchNum];

(async()=>{
  console.log(`Running batch ${batchNum+7} (${feedbacks.length} feedbacks)`);
  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("🎉 Batch done!");
})();
// This line intentionally left blank - batches added below
