<?php

declare(strict_types=1);

namespace Drupal\Tests\flowdrop_workflow_executor\Unit\Enum;

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

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

  use EnumContractTestTrait;

  /**
   * @covers \Drupal\flowdrop_workflow_executor\Enum\WorkflowExecutionMode
   */
  public function testCasesAndValues(): void {
    $this->assertBackedEnumValues(WorkflowExecutionMode::class, [
      'Job' => 'job',
      'JobAsync' => 'job_async',
      'JobFireForget' => 'job_fire_forget',
    ]);
  }

  /**
   * @covers ::label
   */
  public function testLabels(): void {
    $this->assertEquals('Job (wait for completion)', WorkflowExecutionMode::Job->label());
    $this->assertEquals('Async (return session ID)', WorkflowExecutionMode::JobAsync->label());
    $this->assertEquals('Fire & Forget', WorkflowExecutionMode::JobFireForget->label());
  }

  /**
   * Tests from string construction.
   */
  public function testFromString(): void {
    $this->assertSame(WorkflowExecutionMode::Job, WorkflowExecutionMode::from('job'));
    $this->assertSame(WorkflowExecutionMode::JobAsync, WorkflowExecutionMode::from('job_async'));
    $this->assertSame(WorkflowExecutionMode::JobFireForget, WorkflowExecutionMode::from('job_fire_forget'));
  }

}
