<?php

namespace Database\Seeders;

use App\Models\Game;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Log;

class GameBetterSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $agents = User::agents()->get();
        $games = Game::get();
        $games->each(function ($game) use ($agents) {

            $agents->each(function ($agent) use ($game) {
                $betting = $agent->bettings()->create([
                    'name' => 'BLAH BLAH',
                    'game_id' => $game->id,
                ]);
                $amount = rand(70, 900);
                $betting->details()->create([
                    'amount' => $amount,
                    'bet_number' => rand(0, 9),
                    'created_at' => now()->addSecond(5)
                ]);
                $agent->transactions()->create([
                    'type' => 'withdraw',
                    'amount' => $amount,
                    'purpose' => 'game_betting',
                ]);
                $agent->balance = $agent->balance - $amount;
                $agent->save();
            });
        });
    }
}
