<?php

namespace Database\Seeders;

use App\Models\System\Roles\Role;
use App\Models\User;
use Illuminate\Database\Seeder;

class UsersTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $this->createRoles();
        $this->createAdmins();
    }

    public function createRoles(): void
    {
        if (Role::count() > 0) {
            return;
        }

        $roles = [
            'king',
            'superadmin',
            'admin',
            'operator',
            'user',
        ];

        foreach ($roles as $role) {
            Role::create(['name' => $role]);
        }
    }

    public function createAdmins(): void
    {
        $admins = [
            [
                'name' => 'Nurmuhammet Allanov',
                'email' => 'nurmuhammet@mail.com',
                'password' => '$2y$10$O7LFNdFIT3Rmfeo8tUfbqekB0x0incovkRP6eQuzvb7dVXysQyyBC',
            ], [
                'name' => 'Mahmyt Allaberdiyev',
                'email' => 'mahmyt1206@gmail.com',
                'password' => '$2y$10$O7LFNdFIT3Rmfeo8tUfbqekB0x0incovkRP6eQuzvb7dVXysQyyBC',
            ], [
                'name' => 'Döwran Myratlyýew',
                'email' => 'dovran.m@mail.ru',
                'password' => '$2y$10$EFQaBb.aM2KJRGGtuhjdM.3m4Mtm/vw68NjU2280d2RICDGI.o336',
            ],
        ];

        foreach ($admins as $admin) {
            $user = User::create($admin);
            $user->assignRole('superadmin');
        }
    }
}
