<?php

namespace Database\Seeders;

use App\Models\CbtClass;
use App\Models\Question;
use App\Models\QuestionSet;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        // Seed Super Admin
        User::create([
            'name' => 'Super Admin',
            'email' => 'admin@school.com',
            'password' => Hash::make('password'),
            'role' => 'super_admin',
            'parent_name' => 'System',
            'parent_email' => 'system@school.com',
        ]);

        // Seed Sample Student
        User::create([
            'name' => 'Student One',
            'email' => 'student@example.com',
            'password' => Hash::make('password'),
            'role' => 'user',
            'parent_name' => 'Parent One',
            'parent_email' => 'parent@example.com',
        ]);

        // Seed Sample Class
        $class = CbtClass::create([
            'name' => 'Mathematics 101',
            'description' => 'Introductory mathematics course covering basic algebra and geometry.',
        ]);

        // Seed Question Set
        $questionSet = QuestionSet::create([
            'cbt_class_id' => $class->id,
            'title' => 'Mid-term Quiz',
            'description' => 'A quiz covering the first 5 chapters of the course.',
        ]);

        // Seed Questions
        Question::create([
            'question_set_id' => $questionSet->id,
            'question_text' => 'What is 2 + 2?',
            'option_a' => '3',
            'option_b' => '4',
            'option_c' => '5',
            'option_d' => '6',
            'correct_answer' => 'B',
        ]);

        Question::create([
            'question_set_id' => $questionSet->id,
            'question_text' => 'Solve for x: 2x = 10',
            'option_a' => '2',
            'option_b' => '5',
            'option_c' => '10',
            'option_d' => '20',
            'correct_answer' => 'B',
        ]);

        Question::create([
            'question_set_id' => $questionSet->id,
            'question_text' => 'Which shape has 3 sides?',
            'option_a' => 'Square',
            'option_b' => 'Circle',
            'option_c' => 'Triangle',
            'option_d' => 'Rectangle',
            'correct_answer' => 'C',
        ]);

        Question::create([
            'question_set_id' => $questionSet->id,
            'question_text' => 'What is the square root of 81?',
            'option_a' => '7',
            'option_b' => '8',
            'option_c' => '9',
            'option_d' => '10',
            'correct_answer' => 'C',
        ]);

        Question::create([
            'question_set_id' => $questionSet->id,
            'question_text' => 'What is 15 x 3?',
            'option_a' => '30',
            'option_b' => '40',
            'option_c' => '45',
            'option_d' => '50',
            'correct_answer' => 'C',
        ]);

        // Seed Plans
        \App\Models\Plan::create([
            'name' => 'monthly',
            'display_name' => 'Monthly Plan',
            'price' => 3.00,
            'duration_months' => 1,
            'credits' => 30,
        ]);

        \App\Models\Plan::create([
            'name' => '6_months',
            'display_name' => '6 Months Plan',
            'price' => 10.00,
            'duration_months' => 6,
            'credits' => 200,
        ]);

        \App\Models\Plan::create([
            'name' => 'yearly',
            'display_name' => 'Yearly Plan',
            'price' => 20.00,
            'duration_months' => 12,
            'credits' => 500,
        ]);
    }
}
