<?php

declare(strict_types=1);


namespace Database\Seeders;

use App\Models\Setting;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Models\Role;

class DatabaseSeeder extends Seeder
{
    public function run(): void
    {
        foreach (['admin', 'editor', 'member'] as $role) {
            Role::findOrCreate($role);
        }

        $admin = User::query()->firstOrCreate(
            ['email' => 'admin@laralog.test'],
            [
                'name' => '管理员',
                'password' => Hash::make('password'),
            ]
        );
        $admin->assignRole('admin');

        Setting::seedDefaults([
            'site_name' => config('blog.name'),
            'site_description' => config('blog.description'),
            'site_icp' => config('blog.icp'),
            'active_theme' => 'sablog',
            'comment_audit' => '0',
            'comment_min_len' => (string) config('blog.comment_min_len'),
            'comment_max_len' => (string) config('blog.comment_max_len'),
            'comment_post_space' => (string) config('blog.comment_post_space'),
            'comment_order' => '1',
            'rss_num' => (string) config('blog.rss_num'),
            'seo_default_keywords' => '',
            'seo_default_description' => '',
            'site_closed' => '0',
            'site_closed_note' => '系统升级中...',
        ]);
    }
}
