<?php

use Illuminate\Database\Seeder;
use App\Comment;
use App\Topic;
use App\CommentDetail;

class FakeComment extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker = Faker\Factory::create();
        $topics = Topic::select('id', 'code')->published()->where('id', '>', 24)->get();

        foreach ($topics as $topic) {
            for($i = 0; $i < 1200; $i++) {
                $content = $faker->text(150);
                $countLike = rand(1000, 10000);
                $countDislike = rand(500, 5000);
                $comment = Comment::create([
                    'topic_id'         => $topic->id,
                    /*'parent_id'        => 0,*/
                    'content'          => $content,
                    'author'           => "",
                    'like'             => $countLike,
                    'dislike'          => $countDislike,
                    'is_anonymous'     => 1,
                    'is_show_id'       => 0,
                    'is_allow_comment' => 1,
                    'is_activated'     => 1,
                    'is_deleted'       => 0,
                    'created_at'       => date('Y-m-d H:i:s'),
                    'updated_at'       => date('Y-m-d H:i:s'),
                ]);

                CommentDetail::create([
                    'comment_id'  => $comment->id,
                    'content'     => $content,
                    'current_img' => -1,
                    'is_url'      => 0,
                    'created_at'       => date('Y-m-d H:i:s'),
                    'updated_at'       => date('Y-m-d H:i:s'),
                ]);
            }
            print "Create fake comment for topic: " . $topic->code . "\r\n";
        }
    }
}
