import {SSHHost} from './SSHHost'
import * as ssh2 from 'ssh2'
import {shellCommand, ShellCommand} from './types'
import {ExecutionResult} from './ExecutionResult'
import {ErrorWithContext, Filesystem} from '@extollo/lib'

export class PCTHost extends SSHHost {
    constructor(
        config: ssh2.ConnectConfig,
        protected readonly vmid: number,
    ) {
        super(config)
    }

    async execute(command: ShellCommand): Promise<ExecutionResult> {
        return super.execute(shellCommand('pct exec', `${this.vmid}`, '--', command))
    }

    getFilesystem(): Promise<Filesystem>{
        throw new ErrorWithContext('Accessing Filesystem of PCTHost is not supported.', {
            vmid: this.vmid,
        })
    }
}
