<?php

use App\Enums\PotentialClientType;
use App\Models\PotentialClient;

test('type is cast to PotentialClientType enum', function () {
    $client = PotentialClient::factory()->create([
        'type' => PotentialClientType::Individual,
    ]);

    expect($client->type)->toBeInstanceOf(PotentialClientType::class)
        ->and($client->type)->toBe(PotentialClientType::Individual);
});

test('all fields are fillable', function () {
    $data = [
        'type' => PotentialClientType::Company,
        'name' => 'Test Company',
        'phone' => '+1234567890',
        'email' => 'test@example.com',
        'address' => '123 Test Street',
        'social_media' => 'https://twitter.com/test',
        'website' => 'https://example.com',
        'notes' => 'Some notes here',
    ];

    $client = PotentialClient::create($data);

    expect($client->type)->toBe(PotentialClientType::Company)
        ->and($client->name)->toBe('Test Company')
        ->and($client->phone)->toBe('+1234567890')
        ->and($client->email)->toBe('test@example.com')
        ->and($client->address)->toBe('123 Test Street')
        ->and($client->social_media)->toBe('https://twitter.com/test')
        ->and($client->website)->toBe('https://example.com')
        ->and($client->notes)->toBe('Some notes here');
});

test('nullable fields can be null', function () {
    $client = PotentialClient::factory()->create([
        'type' => PotentialClientType::Individual,
        'name' => null,
        'phone' => null,
        'email' => null,
        'address' => null,
        'social_media' => null,
        'website' => null,
        'notes' => null,
    ]);

    expect($client->name)->toBeNull()
        ->and($client->phone)->toBeNull()
        ->and($client->email)->toBeNull()
        ->and($client->address)->toBeNull()
        ->and($client->social_media)->toBeNull()
        ->and($client->website)->toBeNull()
        ->and($client->notes)->toBeNull();
});

test('factory individual state creates individual type', function () {
    $client = PotentialClient::factory()->individual()->create();

    expect($client->type)->toBe(PotentialClientType::Individual);
});

test('factory company state creates company type', function () {
    $client = PotentialClient::factory()->company()->create();

    expect($client->type)->toBe(PotentialClientType::Company);
});

test('factory agency state creates agency type', function () {
    $client = PotentialClient::factory()->agency()->create();

    expect($client->type)->toBe(PotentialClientType::Agency);
});

test('factory generates valid data', function () {
    $client = PotentialClient::factory()->create();

    expect($client->type)->toBeInstanceOf(PotentialClientType::class)
        ->and($client->id)->toBeInt();
});

test('type enum returns english labels', function () {
    app()->setLocale('en');

    expect(PotentialClientType::Individual->label())->toBe('Individual')
        ->and(PotentialClientType::Company->label())->toBe('Company')
        ->and(PotentialClientType::Agency->label())->toBe('Agency');
});

test('type enum returns arabic labels', function () {
    app()->setLocale('ar');

    expect(PotentialClientType::Individual->label())->toBe('فرد')
        ->and(PotentialClientType::Company->label())->toBe('شركة')
        ->and(PotentialClientType::Agency->label())->toBe('وكالة');
});
