<?php

namespace Tests\Unit\SystemCore\Enums;

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

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

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

        $this->assertCount(5, $cases);
        $this->assertContains(ProductStatus::Active, $cases);
        $this->assertContains(ProductStatus::Inactive, $cases);
        $this->assertContains(ProductStatus::Discontinued, $cases);
        $this->assertContains(ProductStatus::OutOfStock, $cases);
        $this->assertContains(ProductStatus::Draft, $cases);
    }

    public function test_case_values_are_correct(): void
    {
        $this->assertEquals('active', ProductStatus::Active->value);
        $this->assertEquals('inactive', ProductStatus::Inactive->value);
        $this->assertEquals('discontinued', ProductStatus::Discontinued->value);
        $this->assertEquals('out_of_stock', ProductStatus::OutOfStock->value);
        $this->assertEquals('draft', ProductStatus::Draft->value);
    }

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

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

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

    public function test_label_returns_correct_string_for_discontinued(): void
    {
        $this->assertEquals('Discontinued', ProductStatus::Discontinued->label());
    }

    public function test_label_returns_correct_string_for_out_of_stock(): void
    {
        $this->assertEquals('Out of Stock', ProductStatus::OutOfStock->label());
    }

    public function test_label_returns_correct_string_for_draft(): void
    {
        $this->assertEquals('Draft', ProductStatus::Draft->label());
    }

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

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

        foreach (ProductStatus::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', ProductStatus::Active->color());
    }

    public function test_color_returns_secondary_for_inactive(): void
    {
        $this->assertEquals('secondary', ProductStatus::Inactive->color());
    }

    public function test_color_returns_danger_for_discontinued(): void
    {
        $this->assertEquals('danger', ProductStatus::Discontinued->color());
    }

    public function test_color_returns_warning_for_out_of_stock(): void
    {
        $this->assertEquals('warning', ProductStatus::OutOfStock->color());
    }

    public function test_color_returns_info_for_draft(): void
    {
        $this->assertEquals('info', ProductStatus::Draft->color());
    }

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

    public function test_try_from_returns_enum_for_valid_value(): void
    {
        $status = ProductStatus::tryFrom('out_of_stock');

        $this->assertInstanceOf(ProductStatus::class, $status);
        $this->assertEquals(ProductStatus::OutOfStock, $status);
    }

    public function test_try_from_returns_null_for_invalid_value(): void
    {
        $status = ProductStatus::tryFrom('sold_out');

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