<?php

namespace Database\Seeders;

use App\Models\Group;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class AdminUserSeeder extends Seeder
{
    /**
     * Seed akun admin & member demo beserta keanggotaan grupnya.
     */
    public function run(): void
    {
        $admin = User::firstOrCreate(
            ['email' => 'admin@okeweb.id'],
            [
                'name' => 'Administrator',
                'first_name' => 'Administrator',
                'last_name' => 'OKEWEB',
                'username' => 'administrator',
                'password' => Hash::make('password'),
                'credit' => 0,
                'status' => 'active',
                'email_verified_at' => now(),
            ]
        );
        $admin->groups()->syncWithoutDetaching([Group::where('name', Group::ADMIN)->value('id')]);

        $member = User::firstOrCreate(
            ['email' => 'member@okeweb.id'],
            [
                'name' => 'Member Demo',
                'first_name' => 'Member',
                'last_name' => 'Demo',
                'company' => 'Toko Demo',
                'phone' => '081234567890',
                'username' => 'member',
                'password' => Hash::make('password'),
                'credit' => 0,
                'status' => 'active',
                'email_verified_at' => now(),
            ]
        );
        $member->groups()->syncWithoutDetaching([Group::where('name', Group::MEMBERS)->value('id')]);
    }
}
