<?php

namespace Database\Factories;

use App\Models\ReviewedWebsite;
use App\Models\ReviewedWebsiteReview;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<ReviewedWebsiteReview>
 */
class ReviewedWebsiteReviewFactory extends Factory
{
    protected $model = ReviewedWebsiteReview::class;

    /**
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'reviewed_website_id' => ReviewedWebsite::factory(),
            'user_id' => User::factory(),
            'guest_name' => null,
            'guest_email' => null,
            'rating' => fake()->numberBetween(2, 5),
            'user_verdict' => fake()->randomElement([
                ReviewedWebsiteReview::VERDICT_LEGIT,
                ReviewedWebsiteReview::VERDICT_SCAM,
                ReviewedWebsiteReview::VERDICT_UNSURE,
            ]),
            'body' => fake()->optional(0.8)->paragraph(),
            'status' => ReviewedWebsiteReview::STATUS_PENDING,
        ];
    }

    public function approved(): static
    {
        return $this->state(fn (array $attributes) => [
            'status' => ReviewedWebsiteReview::STATUS_APPROVED,
        ]);
    }

    public function asGuest(): static
    {
        return $this->state(fn (array $attributes) => [
            'user_id' => null,
            'guest_name' => fake()->name(),
            'guest_email' => fake()->optional()->safeEmail(),
        ]);
    }
}
