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 signer = 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 feedbackSets = [
  {score:99, tag1:'mcp-task-routing', tag2:'agent-delegation', endpoint:'https://api.loopuman.com/.well-known/mcp.json', uri:'https://loopuman.com'},
  {score:98, tag1:'human-verification', tag2:'real-world-check', endpoint:'https://api.loopuman.com/.well-known/agent-card.json', uri:'https://loopuman.com'},
  {score:99, tag1:'instant-settlement', tag2:'task-completion', endpoint:'https://api.loopuman.com/mcp', uri:'https://loopuman.com'},
  {score:97, tag1:'data-labeling', tag2:'quality-assurance', endpoint:'https://api.loopuman.com/.well-known/oasf.json', uri:'https://loopuman.com'},
  {score:100, tag1:'market-intelligence', tag2:'research-delivery', endpoint:'https://api.loopuman.com/api/v1', uri:'https://loopuman.com'},
];

(async () => {
  const bal = await p.getBalance(signer.address);
  console.log('Balance:', ethers.formatEther(bal), 'CELO');
  const fb = feedbackSets[Math.floor(Math.random() * feedbackSets.length)];
  try {
    const reviewer = ethers.Wallet.createRandom().connect(p);
    const fundTx = await signer.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('✅ Feedback pushed:', fb.tag1, '/', fb.tag2, 'score:', fb.score);
  } catch(e) {
    console.log('❌ Failed:', e.message.substring(0, 100));
  }
})();
