import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/dist/src/signer-with-address";
import { ethers } from "hardhat";

import type { Greeter } from "../../src/types/Greeter";
import type { Greeter__factory } from "../../src/types/factories/Greeter__factory";

export async function deployGreeterFixture(): Promise<{ greeter: Greeter }> {
  const signers: SignerWithAddress[] = await ethers.getSigners();
  const admin: SignerWithAddress = signers[0];

  const greeting: string = "Hello, world!";
  const greeterFactory: Greeter__factory = <Greeter__factory>await ethers.getContractFactory("Greeter");
  const greeter: Greeter = <Greeter>await greeterFactory.connect(admin).deploy(greeting);
  await greeter.deployed();

  return { greeter };
}
