import { Client, type ConnectConfig } from "ssh2";

type Param = {
    config: ConnectConfig;
};

export default async function connectSSH({
    config,
}: Param): Promise<Client | undefined> {
    return new Promise((resolve) => {
        const ssh = new Client();

        ssh.on("ready", () => {
            resolve(ssh);
        }).connect(config);

        ssh.on("error", (err) => {
            console.log(`SHH connect ERROR: ${err.message}`);
            resolve(undefined);
        });
    });
}
