import { HardhatRuntimeEnvironment } from "hardhat/types"
import { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
  const { deployments, getNamedAccounts } = hre
  const { deploy, get, execute } = deployments
  const { deployer } = await getNamedAccounts()

  const result = await deploy("BNPL", {
    from: deployer,
    log: true,
    skipIfAlreadyDeployed: true,
    args: [
      (await get("ConduitController")).address,
      (await get("ERC4907")).address
    ]
  })

  if (result.newlyDeployed) {
    await execute(
      "ERC4907",
      { from: deployer, log: true },
      "transferOwnership",
      (await get("BNPL")).address
    )
  }
}

export default func
func.tags = ["BNPL"]
func.dependencies = ["ConduitController","ERC4907"]