require('dotenv').config();
const { ethers } = require('ethers');
const p = new ethers.JsonRpcProvider('https://forno.celo.org');
const agentSigner = new ethers.Wallet(process.env.CELO_PRIVATE_KEY, p);
const REP = '0x8004BAa17C55a88189AE136b182e5fdA19dE9b63';
const abi = ['function giveFeedback(uint256 agentId, uint8 score, uint256 taskId, string tag1, string tag2, string endpoint, string uri, bytes32 ref) external'];

const feedbacks = [
  {score:99, tag1:'task-verification', tag2:'human-confirmed', endpoint:'https://api.loopuman.com/mcp', uri:'data:task-verified-hitl'},
  {score:98, tag1:'instant-payment', tag2:'cusd-settlement', endpoint:'https://api.loopuman.com/.well-known/agent-card.json', uri:'data:payment-8sec'},
  {score:99, tag1:'data-labeling', tag2:'image-classification', endpoint:'https://api.loopuman.com/.well-known/oasf.json', uri:'data:label-quality-high'},
  {score:97, tag1:'content-moderation', tag2:'safety-review', endpoint:'https://api.loopuman.com/mcp', uri:'data:mod-complete'},
  {score:98, tag1:'translation-verified', tag2:'multilingual', endpoint:'https://api.loopuman.com/.well-known/mcp.json', uri:'data:translate-approved'},
  {score:99, tag1:'research-task', tag2:'market-analysis', endpoint:'https://api.loopuman.com/mcp', uri:'data:research-delivered'},
  {score:98, tag1:'address-verification', tag2:'physical-check', endpoint:'https://api.loopuman.com/.well-known/agent-card.json', uri:'data:address-confirmed'},
  {score:99, tag1:'mystery-shopping', tag2:'store-audit', endpoint:'https://api.loopuman.com/.well-known/oasf.json', uri:'data:shop-verified'},
  {score:97, tag1:'document-review', tag2:'proofreading', endpoint:'https://api.loopuman.com/mcp', uri:'data:doc-reviewed'},
  {score:98, tag1:'agent-delegation', tag2:'mcp-integration', endpoint:'https://api.loopuman.com/.well-known/mcp.json', uri:'data:agent-task-routed'},
];

(async()=>{
  const bal = await p.getBalance(agentSigner.address);
  console.log('Wallet balance:', ethers.formatEther(bal), 'CELO');
  console.log('Pushing '+feedbacks.length+' feedbacks...\n');
  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)+'/'+feedbacks.length+'] '+fb.tag1+':'+fb.tag2+' -> score:'+fb.score);
  }
  console.log('\nDone! Total feedbacks pushed: '+feedbacks.length);
})();
