<?php

use App\Enums\VerificationStatus;
use App\Models\Company;
use App\Models\User;
use App\Models\VerificationRequest;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

test('verification request has correct guarded properties', function () {
    $request = new VerificationRequest;
    expect($request->getGuarded())->toBe(['id']);
});

test('verification request has correct casts', function () {
    $request = new VerificationRequest;
    expect($request->getCasts())->toHaveKey('status', VerificationStatus::class);
});

test('verification request can be created using factory', function () {
    $request = VerificationRequest::factory()->create();

    expect($request->status)->toBe(VerificationStatus::PENDING);
    $this->assertDatabaseHas('verification_requests', ['id' => $request->id]);
});

test('verification request scopes filter correctly', function () {
    VerificationRequest::factory()->count(2)->approved()->create();
    VerificationRequest::factory()->count(3)->pending()->create();
    VerificationRequest::factory()->count(1)->rejected()->create();
    VerificationRequest::factory()->count(1)->needRevision()->create();

    expect(VerificationRequest::approved()->count())->toBe(2);
    expect(VerificationRequest::pending()->count())->toBe(3);
    expect(VerificationRequest::rejected()->count())->toBe(1);
    expect(VerificationRequest::needRevision()->count())->toBe(1);
});

test('verification request belongs to company and user', function () {
    $company = Company::factory()->create();
    $user = User::factory()->create();

    $request = VerificationRequest::factory()->create([
        'company_id' => $company->id,
        'submitted_by' => $user->id,
    ]);

    expect($request->company)->toBeInstanceOf(Company::class);
    expect($request->submittedBy)->toBeInstanceOf(User::class);
    expect($request->company->id)->toBe($company->id);
    expect($request->submittedBy->id)->toBe($user->id);
});
