<?php

use App\Enums\UserStatus;
use App\Enums\UserType;
use App\Models\User;

test('user has correct user type cast', function () {
    $user = User::factory()->create(['user_type' => 'admin']);

    expect($user->user_type)->toBeInstanceOf(UserType::class)
        ->and($user->user_type)->toBe(UserType::Admin);
});

test('user has correct status cast', function () {
    $user = User::factory()->create(['status' => 'active']);

    expect($user->status)->toBeInstanceOf(UserStatus::class)
        ->and($user->status)->toBe(UserStatus::Active);
});

test('user is admin returns true for admin users', function () {
    $user = User::factory()->admin()->create();

    expect($user->isAdmin())->toBeTrue()
        ->and($user->isClient())->toBeFalse();
});

test('user is individual returns true for individual users', function () {
    $user = User::factory()->individual()->create();

    expect($user->isIndividual())->toBeTrue()
        ->and($user->isClient())->toBeTrue();
});

test('user is company returns true for company users', function () {
    $user = User::factory()->company()->create();

    expect($user->isCompany())->toBeTrue()
        ->and($user->isClient())->toBeTrue();
});

test('user initials are generated correctly', function () {
    $user = User::factory()->create(['full_name' => 'John Doe']);

    expect($user->initials())->toBe('JD');
});

test('user admins scope returns only admin users', function () {
    User::factory()->admin()->count(2)->create();
    User::factory()->individual()->count(3)->create();

    expect(User::admins()->count())->toBe(2);
});

test('user clients scope returns only client users', function () {
    User::factory()->admin()->count(2)->create();
    User::factory()->individual()->count(2)->create();
    User::factory()->company()->count(1)->create();

    expect(User::clients()->count())->toBe(3);
});

test('user active scope returns only active users', function () {
    User::factory()->count(2)->create();
    User::factory()->deactivated()->count(1)->create();

    expect(User::active()->count())->toBe(2);
});

test('user isActive returns true for active user', function () {
    $user = User::factory()->create();

    expect($user->isActive())->toBeTrue();
});

test('user isActive returns false for deactivated user', function () {
    $user = User::factory()->deactivated()->create();

    expect($user->isActive())->toBeFalse();
});
