<?php

namespace Database\Seeders;

use App\Models\IftaQuestion;
use App\Models\SitePage;
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
    {
        $admin = User::updateOrCreate(
            ['email' => 'admin@jrk.local'],
            [
                'name' => 'JRK Admin',
                'password' => 'password',
                'role' => 'admin',
                'is_active' => true,
            ]
        );

        $user = User::updateOrCreate(
            ['email' => 'user@jrk.local'],
            [
                'name' => 'Website User',
                'password' => 'password',
                'role' => 'user',
                'is_active' => true,
            ]
        );

        SitePage::updateOrCreate(
            ['slug' => 'about', 'locale' => 'en'],
            [
                'title' => 'A free center for Islamic and modern education',
                'intro' => 'Editable content from the admin panel.',
                'body' => 'Administrators can manage this website content in four languages from the backend panel.',
                'updated_by' => $admin->id,
            ]
        );

        $question = IftaQuestion::updateOrCreate(
            ['title' => 'How should a student ask for leave?', 'locale' => 'en'],
            [
                'user_id' => $user->id,
                'category' => 'Education',
                'body' => 'What is the correct way for a student or guardian to request leave from the madrasa?',
                'status' => 'answered',
                'is_approved' => true,
                'answered_at' => now(),
                'approved_at' => now(),
                'approved_by' => $admin->id,
            ]
        );

        $question->replies()->updateOrCreate(
            ['user_id' => $admin->id, 'body' => 'The guardian should contact the administration directly and provide the reason for leave.'],
            [
                'is_official' => true,
                'is_approved' => true,
                'approved_at' => now(),
                'approved_by' => $admin->id,
            ]
        );
    }
}
