<?php

namespace App\Domains\Domain\Actions;

use App\Domains\Domain\Models\Domain;
use App\Domains\Workspace\Models\Workspace;
use Illuminate\Support\Str;

class CreateDomain
{
    public function handle(Workspace $workspace, string $hostname): Domain
    {
        return Domain::create([
            'workspace_id' => $workspace->id,
            'hostname' => strtolower(trim($hostname)),
            'verification_token' => Str::random(32),
            'ssl_status' => 'pending',
            'is_default' => false,
        ]);
    }
}
