import { ethers } from 'hardhat'

async function main() {
  console.log('Deploying Sankofa Phoenix smart contracts...')

  // Get deployer account
  const [deployer] = await ethers.getSigners()
  console.log('Deploying contracts with account:', deployer.address)
  console.log('Account balance:', (await ethers.provider.getBalance(deployer.address)).toString())

  // Deploy ResourceProvisioning
  const ResourceProvisioningFactory = await ethers.getContractFactory('ResourceProvisioning')
  const resourceProvisioning = await ResourceProvisioningFactory.deploy()
  await resourceProvisioning.waitForDeployment()
  console.log('ResourceProvisioning deployed to:', await resourceProvisioning.getAddress())

  // Deploy IdentityManagement
  const IdentityManagementFactory = await ethers.getContractFactory('IdentityManagement')
  const identityManagement = await IdentityManagementFactory.deploy()
  await identityManagement.waitForDeployment()
  console.log('IdentityManagement deployed to:', await identityManagement.getAddress())

  // Deploy Billing
  const BillingFactory = await ethers.getContractFactory('Billing')
  const billing = await BillingFactory.deploy()
  await billing.waitForDeployment()
  console.log('Billing deployed to:', await billing.getAddress())

  // Deploy Compliance
  const ComplianceFactory = await ethers.getContractFactory('Compliance')
  const compliance = await ComplianceFactory.deploy()
  await compliance.waitForDeployment()
  console.log('Compliance deployed to:', await compliance.getAddress())

  console.log('\n✅ All contracts deployed successfully!')
  console.log('\nContract Addresses:')
  console.log('  ResourceProvisioning:', await resourceProvisioning.getAddress())
  console.log('  IdentityManagement:', await identityManagement.getAddress())
  console.log('  Billing:', await billing.getAddress())
  console.log('  Compliance:', await compliance.getAddress())
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error)
    process.exit(1)
  })

