<?php

namespace Database\Factories;

use App\Models\IpAddress;
use App\Models\IpPool;
use Illuminate\Database\Eloquent\Factories\Factory;

class IpAddressFactory extends Factory
{
    protected $model = IpAddress::class;

    public function definition(): array
    {
        $address = $this->faker->ipv4();
        return [
            'pool_id' => IpPool::factory(),
            'address' => $address,
            'address_long' => ip2long($address),
            'status' => 'free',
        ];
    }

    public function free(): self
    {
        return $this->state(['status' => 'free']);
    }

    public function used(): self
    {
        return $this->state(['status' => 'used', 'assigned_at' => now()]);
    }

    public function quarantined(int $daysFromNow = 7): self
    {
        return $this->state([
            'status' => 'quarantined',
            'released_at' => now()->addDays($daysFromNow),
        ]);
    }
}
