<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Mail;
use Tests\TestCase;
use App\Models\User;

class CorporateRegistrationTest extends TestCase
{
    public function test_user_can_register_as_corporate_customer(): void
    {
        Mail::fake();

        // Generate unique names/emails to avoid database collision if running on existing database
        $uniqueId = uniqid();
        $name = 'Corporate User ' . $uniqueId;
        $email = 'corporate_' . $uniqueId . '@example.com';

        $response = $this->post(route('american.plastic.user.register'), [
            'name' => $name,
            'email' => $email,
            'password' => 'Password123',
            'is_corporate' => '1',
        ]);

        $response->assertRedirect(route('american.plastic.web'));
        $response->assertSessionHas('verify-email', true);

        // Assert database has user with is_corporate = 1
        $this->assertDatabaseHas('users', [
            'name' => $name,
            'email' => $email,
            'is_corporate' => 1,
        ]);
    }

    public function test_user_can_register_as_regular_customer(): void
    {
        Mail::fake();

        $uniqueId = uniqid();
        $name = 'Regular User ' . $uniqueId;
        $email = 'regular_' . $uniqueId . '@example.com';

        $response = $this->post(route('american.plastic.user.register'), [
            'name' => $name,
            'email' => $email,
            'password' => 'Password123',
        ]);

        $response->assertRedirect(route('american.plastic.web'));
        $response->assertSessionHas('verify-email', true);

        // Assert database has user with is_corporate = 0
        $this->assertDatabaseHas('users', [
            'name' => $name,
            'email' => $email,
            'is_corporate' => 0,
        ]);
    }
}
