import { HardhatRuntimeEnvironment } from 'hardhat/types';
const { ethers, upgrades } = require("hardhat");
import { DeployFunction } from 'hardhat-deploy/types';

import { getSetupAddresses } from '../src/addresses/setup';

const deployFn: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {

    const { deployments, ethers, getChainId, getNamedAccounts, network } = hre;

    const { deployer } = await getNamedAccounts();
	const chainId = await getChainId();

	const _addresses = await getSetupAddresses(chainId, network, deployments);

	if ((!_addresses.DAO || _addresses.DAO === ethers.constants.AddressZero) && network.name !== 'hardhat') {
		console.log('You need to set DAO address to transfer ownership of summoner', _addresses.DAO);
		return;
	}

	console.log('\n\nDeploying BaalSummoner factory on network:', network.name);
	console.log('Deployer address:', `${chainId}:${deployer}`);
	console.log(
		'Deployer balance:',
		ethers.utils.formatEther(await ethers.provider.getBalance(deployer)),
	);

    const { deploy } = deployments;

    const summonerDeeployed = await deploy('BaalSummoner', {
		contract: 'BaalSummoner',
		from: deployer,
		args: [],
		log: true,
	});
	console.log('BaalSummoner deployment Tx ->', summonerDeeployed.transactionHash);

    
};

export default deployFn;
deployFn.tags = ['UpgradeBaalSummoner'];
