<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    use WithoutModelEvents;

    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        // Buat admin
        User::factory()->create([
            'name' => 'Admin Utama',
            'email' => 'admin@hiperdiet.com',
            'role' => 'admin',
        ]);

        // Buat beberapa pasien
        $patients = [
            ['name' => 'Ahmad Rahman', 'email' => 'ahmad@example.com'],
            ['name' => 'Siti Aminah', 'email' => 'siti@example.com'],
            ['name' => 'Budi Santoso', 'email' => 'budi@example.com'],
            ['name' => 'Dewi Lestari', 'email' => 'dewi@example.com'],
            ['name' => 'Eko Prasetyo', 'email' => 'eko@example.com'],
        ];

        foreach ($patients as $patient) {
            $user = User::factory()->create([
                'name' => $patient['name'],
                'email' => $patient['email'],
                'role' => 'user',
            ]);

            // Buat beberapa quiz results untuk setiap pasien
            $statuses = ['Sangat Baik', 'Cukup Baik', 'Perlu Perbaikan'];
            for ($i = 0; $i < rand(1, 3); $i++) {
                \App\Models\QuizResult::create([
                    'user_id' => $user->id,
                    'score' => rand(60, 100),
                    'status' => $statuses[array_rand($statuses)],
                    'answers' => [
                        ['question' => 'Apakah Anda mengonsumsi garam berlebih?', 'score' => rand(10, 20)],
                        ['question' => 'Apakah Anda rutin berolahraga?', 'score' => rand(10, 20)],
                        ['question' => 'Apakah Anda minum cukup air?', 'score' => rand(10, 20)],
                    ],
                    'created_at' => now()->subDays(rand(0, 30)),
                ]);
            }
        }
    }
}
