<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use App\Models\User;
use App\Models\Group;
use App\Models\Company;
use App\Models\CompanyType;
use Illuminate\Support\Str;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {


     
        // DB::table('company_types')->insert([
        //     ['name' => 'Netbay Admin'],
        //     ['name' => 'Broker'],
        //     ['name' => 'Importer']
        // ]);


        // $this->call([
        //     PermissionSeeder::class,
        //     RoleSeeder::class,
        //     CompaniesSeeder::class,
        //     GroupSeeder::class,
        // ]);

        // \App\Models\User::factory()->create([
        //     'username' => 'Test User',
        //     'email' => 'test@example.com',
        //     'password' => bcrypt('password'),
        //     'uid' => Str::random(21)
        // ]);

        $users = [
            [
                'username' => 'Sarun',
                'email' => 'sarun@netbay.co.th',
                'password' => bcrypt('password'),
                'uid' => Str::random(21)
            ],
        ];

        foreach ($users as $userData) {
            $user = User::create($userData);

            // Assign groups to users
            $groups = Group::inRandomOrder()->take(2)->get(); // Assign 2 random groups to each user
            foreach ($groups as $group) {
                $user->groups()->attach($group);
            }
        }
    }
}
