<?php

namespace Database\Factories;

use App\Models\NetworkStatus;
use Illuminate\Database\Eloquent\Factories\Factory;

class NetworkStatusFactory extends Factory
{
    protected $model = NetworkStatus::class;

    public function definition(): array
    {
        return [
            'title'       => $this->faker->sentence(4),
            'description' => $this->faker->paragraph(),
            'status'      => $this->faker->randomElement([
                NetworkStatus::STATUS_REPORTED,
                NetworkStatus::STATUS_INVESTIGATING,
                NetworkStatus::STATUS_IN_PROGRESS,
            ]),
            'type'   => $this->faker->randomElement([
                NetworkStatus::TYPE_INCIDENT,
                NetworkStatus::TYPE_MAINTENANCE,
                NetworkStatus::TYPE_DEGRADED_PERFORMANCE,
                NetworkStatus::TYPE_PARTIAL_OUTAGE,
                NetworkStatus::TYPE_MAJOR_OUTAGE,
            ]),
            'impact'            => $this->faker->randomElement([
                NetworkStatus::IMPACT_NONE,
                NetworkStatus::IMPACT_MINOR,
                NetworkStatus::IMPACT_MAJOR,
                NetworkStatus::IMPACT_CRITICAL,
            ]),
            'started_at'        => now(),
            'resolved_at'       => null,
            'scheduled_at'      => null,
            'scheduled_end_at'  => null,
            'affected_services' => [],
            'sort_order'        => $this->faker->numberBetween(0, 100),
        ];
    }

    public function resolved(): static
    {
        return $this->state(fn (array $attributes) => [
            'status'      => NetworkStatus::STATUS_RESOLVED,
            'resolved_at' => now(),
        ]);
    }

    public function investigating(): static
    {
        return $this->state(fn (array $attributes) => [
            'status'      => NetworkStatus::STATUS_INVESTIGATING,
            'resolved_at' => null,
        ]);
    }

    public function scheduled(): static
    {
        return $this->state(fn (array $attributes) => [
            'status'       => NetworkStatus::STATUS_SCHEDULED,
            'scheduled_at' => now()->addDay(),
        ]);
    }
}
