<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Models\Bidders;
use App\Models\Items;
use App\Models\WinningBids;

class MyWinningsTest extends TestCase
{
    use DatabaseTransactions;

    public function test_mywinnings_form_is_accessible()
    {
        $response = $this->get('/mywinnings');
        $response->assertStatus(200);
        $response->assertSee('Check My Winnings');
    }

    public function test_mywinnings_results_show_correct_data()
    {
        // Create a bidder
        $bidder = Bidders::create([
            'bidder_assigned_number' => '999',
            'bidder_fname' => 'Test',
            'bidder_lname' => 'User',
        ]);

        // Create an item
        $item = Items::create([
            'item_assigned_num' => '777',
            'item_desc' => 'Test Item',
            'item_min_bid' => 10,
            'item_est_value' => 20,
        ]);

        // Create a winning bid
        WinningBids::create([
            'winning_bidder_num' => $bidder->idbidders,
            'winning_item_num' => $item->iditems,
            'winning_cost' => 15,
        ]);

        $response = $this->post('/mywinnings', [
            'bidder_number' => '999'
        ]);

        $response->assertStatus(200);
        $response->assertSee('Winnings for Bidder #999');
        $response->assertSee('Test Item');
        $response->assertSee('$15.00');
    }

    public function test_mywinnings_invalid_bidder_shows_error()
    {
        $response = $this->post('/mywinnings', [
            'bidder_number' => 'NONEXISTENT'
        ]);

        $response->assertStatus(200);
        $response->assertSee('Bidder number not found.');
    }
}
