<?php

namespace Database\Factories;

use App\Models\Operator;
use App\Models\VpnPeer;
use App\Services\Wireguard\Keypair;
use Illuminate\Database\Eloquent\Factories\Factory;

class VpnPeerFactory extends Factory
{
    public function definition(): array
    {
        static $octet = 20;

        return [
            'name' => $this->faker->userName(),
            'kind' => VpnPeer::KIND_STAFF,
            'user_id' => Operator::factory()->role('Admin'),
            'public_key' => Keypair::generate()->publicKey,
            'allowed_ip' => '10.66.0.'.($octet++),
            'enabled' => true,
            'present' => true,
        ];
    }

    /** A peer registered by the host pipeline: no human owner. */
    public function forHost(): static
    {
        return $this->state(['kind' => VpnPeer::KIND_HOST, 'user_id' => null]);
    }

    public function ownedBy(Operator $operator): static
    {
        return $this->state(['kind' => VpnPeer::KIND_STAFF, 'user_id' => $operator->id]);
    }

    public function blocked(): static
    {
        return $this->state(['enabled' => false, 'present' => false]);
    }
}
