// Script de déploiement du contrat Voting
const hre = require("hardhat");

async function main() {
  console.log("Déploiement du contrat Voting...");

  try {
    // Récupération du compte de déploiement
    const [deployer] = await hre.ethers.getSigners();
    console.log("Déploiement avec le compte:", deployer.address);

    // Compilation du contrat
    const Voting = await hre.ethers.getContractFactory("Voting");
    // Déploiement du contrat
    const voting = await Voting.deploy();
    
    // Attente de la confirmation du déploiement
    await voting.deployed();

    console.log("Contrat Voting déployé à l'adresse:", voting.address);
  } catch (error) {
    console.error("Erreur détaillée:", error);
    throw error;
  }
}

// Exécution du script de déploiement avec gestion des erreurs
main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error("Erreur lors du déploiement:", error);
    process.exit(1);
  });