<?php

declare(strict_types=1);

namespace Drupal\Tests\flowdrop_workflow_executor\Unit\Enum;

use Drupal\Tests\UnitTestCase;
use Drupal\flowdrop_workflow_executor\Enum\WorkflowExecutionStatus;
use Drupal\Tests\flowdrop\Unit\Traits\EnumContractTestTrait;

/**
 * Tests the WorkflowExecutionStatus enum.
 *
 * @coversDefaultClass \Drupal\flowdrop_workflow_executor\Enum\WorkflowExecutionStatus
 * @group flowdrop_workflow_executor
 */
class WorkflowExecutionStatusTest extends UnitTestCase {

  use EnumContractTestTrait;

  /**
   * @covers \Drupal\flowdrop_workflow_executor\Enum\WorkflowExecutionStatus
   */
  public function testCasesAndValues(): void {
    $this->assertBackedEnumValues(WorkflowExecutionStatus::class, [
      'Completed' => 'completed',
      'Running' => 'running',
      'Pending' => 'pending',
      'Failed' => 'failed',
      'Timeout' => 'timeout',
    ]);
  }

  /**
   * @covers ::label
   */
  public function testLabels(): void {
    $this->assertEquals('Completed', WorkflowExecutionStatus::Completed->label());
    $this->assertEquals('Running', WorkflowExecutionStatus::Running->label());
    $this->assertEquals('Pending', WorkflowExecutionStatus::Pending->label());
    $this->assertEquals('Failed', WorkflowExecutionStatus::Failed->label());
    $this->assertEquals('Timed Out', WorkflowExecutionStatus::Timeout->label());
  }

  /**
   * @covers ::isTerminal
   */
  public function testIsTerminal(): void {
    $this->assertTrue(WorkflowExecutionStatus::Completed->isTerminal());
    $this->assertTrue(WorkflowExecutionStatus::Failed->isTerminal());
    $this->assertTrue(WorkflowExecutionStatus::Timeout->isTerminal());
    $this->assertFalse(WorkflowExecutionStatus::Running->isTerminal());
    $this->assertFalse(WorkflowExecutionStatus::Pending->isTerminal());
  }

  /**
   * @covers ::isSuccess
   */
  public function testIsSuccess(): void {
    $this->assertTrue(WorkflowExecutionStatus::Completed->isSuccess());
    $this->assertFalse(WorkflowExecutionStatus::Failed->isSuccess());
    $this->assertFalse(WorkflowExecutionStatus::Running->isSuccess());
    $this->assertFalse(WorkflowExecutionStatus::Pending->isSuccess());
    $this->assertFalse(WorkflowExecutionStatus::Timeout->isSuccess());
  }

  /**
   * Tests from string construction.
   */
  public function testFromString(): void {
    $this->assertSame(WorkflowExecutionStatus::Completed, WorkflowExecutionStatus::from('completed'));
    $this->assertSame(WorkflowExecutionStatus::Failed, WorkflowExecutionStatus::from('failed'));
  }

}
