<?php

namespace Database\Factories;

use App\Models\BlogPost;
use App\Models\BlogPostReview;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<BlogPostReview>
 */
class BlogPostReviewFactory extends Factory
{
    protected $model = BlogPostReview::class;

    /**
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'blog_post_id' => BlogPost::factory(),
            'user_id' => User::factory(),
            'guest_name' => null,
            'guest_email' => null,
            'rating' => fake()->numberBetween(3, 5),
            'body' => fake()->optional(0.7)->paragraph(),
            'is_approved' => true,
        ];
    }

    /**
     * Guest review (no user account).
     *
     * @return $this
     */
    public function asGuest(): static
    {
        return $this->state(fn (array $attributes) => [
            'user_id' => null,
            'guest_name' => fake()->name(),
            'guest_email' => fake()->optional(0.5)->safeEmail(),
        ]);
    }

    /**
     * @return $this
     */
    public function pending(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_approved' => false,
        ]);
    }
}
