<?php

namespace Database\Factories;

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

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Post>
 */
class PostFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $titles = [
            '周末的咖啡时光，享受慢生活的美好',
            '探索城市隐藏的宝藏小店',
            '今日穿搭分享｜简约不简单',
            '一个人的旅行，遇见不一样的风景',
            '家居改造计划｜打造温馨小窝',
            '读完这本书，我的思考',
            '春日踏青，感受大自然的馈赠',
            '美食日记｜自制下午茶',
            '工作之余的小确幸',
            '艺术展观后感｜美的感悟',
            '健身打卡第30天｜变化看得见',
            '治愈系好物分享',
            '摄影技巧｜如何拍出氛围感',
            '极简生活｜断舍离的心得',
            '复古风穿搭灵感',
            '居家办公的一天',
            '周末brunch推荐',
            '秋日漫步｜落叶缤纷',
            '手账分享｜记录生活的美好',
            '护肤心得｜找到适合自己的',
        ];

        $title = fake()->randomElement($titles) . ' ' . fake()->emoji();

        $content = '<p>' . fake()->paragraphs(3, true) . '</p>';
        $content .= '<h2>关于这次体验</h2>';
        $content .= '<p>' . fake()->paragraphs(2, true) . '</p>';
        $content .= '<blockquote><p>' . fake()->sentence(15) . '</p></blockquote>';
        $content .= '<p>' . fake()->paragraphs(2, true) . '</p>';
        $content .= '<h3>一些小建议</h3>';
        $content .= '<ul><li>' . fake()->sentence() . '</li>';
        $content .= '<li>' . fake()->sentence() . '</li>';
        $content .= '<li>' . fake()->sentence() . '</li></ul>';
        $content .= '<p>' . fake()->paragraphs(2, true) . '</p>';

        return [
            'user_id' => User::factory(),
            'category_id' => Category::factory(),
            'title' => $title,
            'slug' => Str::slug($title) . '-' . fake()->unique()->randomNumber(5),
            'excerpt' => fake()->sentence(20),
            'content' => $content,
            'cover_image' => null,
            'gallery' => null,
            'status' => fake()->randomElement(['draft', 'published', 'published', 'published']),
            'published_at' => fake()->dateTimeBetween('-6 months', 'now'),
            'is_featured' => fake()->boolean(20),
            'views_count' => fake()->numberBetween(0, 5000),
            'likes_count' => fake()->numberBetween(0, 500),
        ];
    }

    /**
     * Indicate that the post is published.
     */
    public function published(): static
    {
        return $this->state(fn (array $attributes) => [
            'status' => 'published',
            'published_at' => fake()->dateTimeBetween('-6 months', 'now'),
        ]);
    }

    /**
     * Indicate that the post is featured.
     */
    public function featured(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_featured' => true,
        ]);
    }
}

