<?php

namespace Tests\Unit\SystemCore\Enums;

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

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

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

        $this->assertCount(5, $cases);
        $this->assertContains(CustomerStatus::Active, $cases);
        $this->assertContains(CustomerStatus::Inactive, $cases);
        $this->assertContains(CustomerStatus::Blocked, $cases);
        $this->assertContains(CustomerStatus::Pending, $cases);
        $this->assertContains(CustomerStatus::Suspended, $cases);
    }

    public function test_case_values_are_correct(): void
    {
        $this->assertEquals('active', CustomerStatus::Active->value);
        $this->assertEquals('inactive', CustomerStatus::Inactive->value);
        $this->assertEquals('blocked', CustomerStatus::Blocked->value);
        $this->assertEquals('pending', CustomerStatus::Pending->value);
        $this->assertEquals('suspended', CustomerStatus::Suspended->value);
    }

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

    public function test_label_returns_correct_string_for_active(): void
    {
        $this->assertEquals('Active', CustomerStatus::Active->label());
    }

    public function test_label_returns_correct_string_for_inactive(): void
    {
        $this->assertEquals('Inactive', CustomerStatus::Inactive->label());
    }

    public function test_label_returns_correct_string_for_blocked(): void
    {
        $this->assertEquals('Blocked', CustomerStatus::Blocked->label());
    }

    public function test_label_returns_correct_string_for_pending(): void
    {
        $this->assertEquals('Pending', CustomerStatus::Pending->label());
    }

    public function test_label_returns_correct_string_for_suspended(): void
    {
        $this->assertEquals('Suspended', CustomerStatus::Suspended->label());
    }

    // ==========================================
    // Color Tests
    // ==========================================

    public function test_color_returns_valid_bootstrap_class(): void
    {
        $validColors = ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'];

        foreach (CustomerStatus::cases() as $case) {
            $this->assertContains($case->color(), $validColors, "Invalid color for {$case->name}");
        }
    }

    public function test_color_returns_success_for_active(): void
    {
        $this->assertEquals('success', CustomerStatus::Active->color());
    }

    public function test_color_returns_danger_for_blocked(): void
    {
        $this->assertEquals('danger', CustomerStatus::Blocked->color());
    }

    public function test_color_returns_warning_for_pending(): void
    {
        $this->assertEquals('warning', CustomerStatus::Pending->color());
    }

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

    public function test_try_from_returns_enum_for_valid_value(): void
    {
        $status = CustomerStatus::tryFrom('active');

        $this->assertInstanceOf(CustomerStatus::class, $status);
        $this->assertEquals(CustomerStatus::Active, $status);
    }

    public function test_try_from_returns_null_for_invalid_value(): void
    {
        $status = CustomerStatus::tryFrom('invalid');

        $this->assertNull($status);
    }

    public function test_from_throws_for_invalid_value(): void
    {
        $this->expectException(\ValueError::class);
        CustomerStatus::from('invalid');
    }
}
