#!/usr/bin/env node

import axios from 'axios';

const baseUrl = process.env.TOKEN_AGGREGATION_BASE_URL || 'http://localhost:3000';

const body = {
  partner: process.env.PARTNER || '0x',
  amount: process.env.AMOUNT || '1000000',
  fromChainId: process.env.FROM_CHAIN_ID ? Number(process.env.FROM_CHAIN_ID) : 138,
  toChainId: process.env.TO_CHAIN_ID ? Number(process.env.TO_CHAIN_ID) : 138,
  routeType: process.env.ROUTE_TYPE || 'swap',
  tokenIn: process.env.TOKEN_IN || '0x93E66202A11B1772E55407B32B44e5Cd8eda7f22',
  tokenOut: process.env.TOKEN_OUT || '0xf22258f57794CC8E06237084b353Ab30fFfa640b',
  takerAddress: process.env.TAKER_ADDRESS || '0x000000000000000000000000000000000000dEaD',
  recipient: process.env.RECIPIENT || '0x000000000000000000000000000000000000dEaD',
  includeUnsupported: String(process.env.INCLUDE_UNSUPPORTED || 'true').toLowerCase() === 'true',
};

async function main() {
  const response = await axios.post(
    `${baseUrl.replace(/\/+$/, '')}/api/v1/routes/partner-payloads/resolve`,
    body,
    {
      headers: {
        'Content-Type': 'application/json',
        Accept: 'application/json',
      },
      timeout: 15000,
    }
  );

  console.log(JSON.stringify(response.data, null, 2));
}

main().catch((error) => {
  const message = error?.response?.data || error?.message || error;
  console.error('Partner payload resolution failed:', message);
  process.exit(1);
});

