<?php

namespace Database\Factories;

use App\Models\News;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\News>
 */
class NewsFactory extends Factory
{
    protected $model = News::class;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $title = $this->faker->sentence(6);

        return [
            'author_id' => User::factory(),
            'title' => $title,
            'slug' => Str::slug($title),
            'content' => $this->faker->paragraphs(3, true),
            'link' => $this->faker->optional(0.3)->url(),
            'view' => $this->faker->numberBetween(0, 10000),
        ];
    }

    /**
     * Indicate that the news has high views.
     */
    public function popular(): static
    {
        return $this->state(fn (array $attributes) => [
            'view' => $this->faker->numberBetween(5000, 50000),
        ]);
    }

    /**
     * Indicate that the news has external link.
     */
    public function withLink(): static
    {
        return $this->state(fn (array $attributes) => [
            'link' => $this->faker->url(),
        ]);
    }

    /**
     * Indicate that the news has no views.
     */
    public function unpublished(): static
    {
        return $this->state(fn (array $attributes) => [
            'view' => 0,
        ]);
    }
}
