import { CirclesSdk } from "@ingocollatz/sdk";
import { PUBLIC_KEY_1, RPC_URL, SAFE_ADDRESS_USER } from "../config";
import Web3 from "web3";
import Safe, { Web3Adapter } from "@safe-global/protocol-kit";
import { Web3AbiEncoder } from "@ingocollatz/sdk-web3-adapter";
import { EthersAbiEncoder } from "@ingocollatz/sdk-ethers-adapter";
import { ethers } from "ethers";
import { EthersAdapter } from "@safe-global/protocol-kit";
import type { TxHistory, TxHistoryTypes } from "@ingocollatz/sdk-interfaces";


(async (): Promise<void> => {
  // Ethers
  const provider = new ethers.providers.JsonRpcProvider(RPC_URL);

  const safe = await Safe.create({
    ethAdapter: new EthersAdapter({
      ethers,
      signerOrProvider: provider,
    }),
    safeAddress: SAFE_ADDRESS_USER,
  });

  const abiEncoder = new EthersAbiEncoder();

  const circlesSdk = new CirclesSdk(safe, abiEncoder);

  const history = await circlesSdk.getTrustEvents({
    // limit: 10,
    // sortOrder: "Ascending",
  });


  console.log(`Existing trust events for ${SAFE_ADDRESS_USER}: `, history);


  // Web3
  // const web3 = new Web3(new Web3.providers.HttpProvider(RPC_URL));

  // const safe = await Safe.create({
  //   ethAdapter: new Web3Adapter({
  //     web3: new Web3(new Web3.providers.HttpProvider(RPC_URL)),
  //     signerAddress: PUBLIC_KEY_1,
  //   }),
  //   safeAddress: SAFE_ADDRESS_USER,
  // });

  // const safeAddress = await safe.getAddress();

  // const abiEncoder = new Web3AbiEncoder(web3);

  // const circlesSdk = new CirclesSdk(safe, abiEncoder);

  // const history = await circlesSdk.fetchTransactionHistory({
  //   limit: 10,
  //   offset: 0,
  //   type: "TRUST",
  //   trustConnections: true,
  // });

  // console.log(`Existing trust connections for ${SAFE_ADDRESS_USER}: `, history.trust);
})();

