<?php

namespace Database\Factories;

use App\Models\Feed;
use App\Models\Language;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<Feed>
 */
class FeedFactory extends Factory
{
    protected $model = Feed::class;

    public function definition(): array
    {
        return [
            'name' => $this->faker->words(3, true),
            'url' => $this->faker->unique()->url(),
            'type' => $this->faker->randomElement(['website', 'rss']),
            'provider' => $this->faker->randomElement(['vrt', 'belga']),
            'language_id' => null,
            'description' => $this->faker->optional()->sentence(),
            'settings' => [],
            'is_active' => true,
            'last_fetched_at' => null,
        ];
    }

    public function inactive(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_active' => false,
        ]);
    }

    public function website(): static
    {
        return $this->state(fn (array $attributes) => [
            'type' => 'website',
        ]);
    }

    public function rss(): static
    {
        return $this->state(fn (array $attributes) => [
            'type' => 'rss',
        ]);
    }

    public function recentlyFetched(): static
    {
        return $this->state(fn (array $attributes) => [
            'last_fetched_at' => now()->subHour(),
        ]);
    }

    public function language(Language $language): static
    {
        return $this->state(fn (array $attributes) => [
            'language_id' => $language->id,
        ]);
    }

    public function vrt(): static
    {
        return $this->state(fn (array $attributes) => [
            'provider' => 'vrt',
            'url' => 'https://www.vrt.be/vrtnws/en/',
        ]);
    }

    public function belga(): static
    {
        return $this->state(fn (array $attributes) => [
            'provider' => 'belga',
            'url' => 'https://www.belganewsagency.eu/feed',
            'type' => 'rss',
        ]);
    }
}
