<?php

namespace Tests\Unit\SystemCore\Enums;

use Modules\SystemCore\App\Enums\CustomerType;
use PHPUnit\Framework\TestCase;

class CustomerTypeTest extends TestCase
{
    // ==========================================
    // Cases Tests
    // ==========================================

    public function test_all_expected_cases_exist(): void
    {
        $cases = CustomerType::cases();

        $this->assertCount(7, $cases);
        $this->assertContains(CustomerType::B2B, $cases);
        $this->assertContains(CustomerType::B2C, $cases);
        $this->assertContains(CustomerType::Lead, $cases);
        $this->assertContains(CustomerType::Prospect, $cases);
        $this->assertContains(CustomerType::Distributor, $cases);
        $this->assertContains(CustomerType::Retailer, $cases);
        $this->assertContains(CustomerType::Wholesaler, $cases);
    }

    public function test_case_values_are_correct(): void
    {
        $this->assertEquals('b2b', CustomerType::B2B->value);
        $this->assertEquals('b2c', CustomerType::B2C->value);
        $this->assertEquals('lead', CustomerType::Lead->value);
        $this->assertEquals('prospect', CustomerType::Prospect->value);
        $this->assertEquals('distributor', CustomerType::Distributor->value);
        $this->assertEquals('retailer', CustomerType::Retailer->value);
        $this->assertEquals('wholesaler', CustomerType::Wholesaler->value);
    }

    // ==========================================
    // Label Tests
    // ==========================================

    public function test_label_returns_correct_string_for_b2b(): void
    {
        $this->assertEquals('Business to Business', CustomerType::B2B->label());
    }

    public function test_label_returns_correct_string_for_b2c(): void
    {
        $this->assertEquals('Business to Consumer', CustomerType::B2C->label());
    }

    public function test_label_returns_correct_string_for_lead(): void
    {
        $this->assertEquals('Lead', CustomerType::Lead->label());
    }

    public function test_label_returns_correct_string_for_prospect(): void
    {
        $this->assertEquals('Prospect', CustomerType::Prospect->label());
    }

    public function test_label_returns_correct_string_for_distributor(): void
    {
        $this->assertEquals('Distributor', CustomerType::Distributor->label());
    }

    public function test_label_returns_correct_string_for_retailer(): void
    {
        $this->assertEquals('Retailer', CustomerType::Retailer->label());
    }

    public function test_label_returns_correct_string_for_wholesaler(): void
    {
        $this->assertEquals('Wholesaler', CustomerType::Wholesaler->label());
    }

    // ==========================================
    // TryFrom Tests
    // ==========================================

    public function test_try_from_returns_enum_for_valid_value(): void
    {
        $type = CustomerType::tryFrom('b2b');

        $this->assertInstanceOf(CustomerType::class, $type);
        $this->assertEquals(CustomerType::B2B, $type);
    }

    public function test_try_from_returns_null_for_invalid_value(): void
    {
        $type = CustomerType::tryFrom('enterprise');

        $this->assertNull($type);
    }
}
