<?php

namespace App\Provisioning\Steps\Host;

use App\Models\ProvisioningRun;
use App\Provisioning\StepResult;

class ValidateHostInput extends HostStep
{
    public function key(): string
    {
        return 'validate_host_input';
    }

    public function maxDuration(): int
    {
        return 60;
    }

    public function execute(ProvisioningRun $run): StepResult
    {
        $host = $this->host($run);

        if (blank($host->public_ip) || blank($host->datacenter)) {
            return StepResult::fail('Host is missing public_ip or datacenter.');
        }

        if (blank($run->context('root_password'))) {
            return StepResult::fail('Missing root password in run context.');
        }

        $host->update(['status' => 'onboarding']);

        return StepResult::advance();
    }
}
