<?php

declare(strict_types=1);

namespace Drupal\Tests\flowdrop_interrupt\Unit\Enum;

use Drupal\Tests\UnitTestCase;
use Drupal\flowdrop_interrupt\Enum\InterruptType;
use Drupal\Tests\flowdrop\Unit\Traits\EnumContractTestTrait;

/**
 * Tests the InterruptType enum.
 *
 * @coversDefaultClass \Drupal\flowdrop_interrupt\Enum\InterruptType
 * @group flowdrop_interrupt
 */
class InterruptTypeTest extends UnitTestCase {

  use EnumContractTestTrait;

  /**
   * @covers \Drupal\flowdrop_interrupt\Enum\InterruptType
   */
  public function testCasesAndValues(): void {
    $this->assertBackedEnumValues(InterruptType::class, [
      'Confirmation' => 'confirmation',
      'Choice' => 'choice',
      'Text' => 'text',
      'Form' => 'form',
      'WorkflowExecution' => 'workflow_execution',
      'PipelineCompletion' => 'pipeline_completion',
      'SchemaForm' => 'schema_form',
      'Cancel' => 'cancel',
      'Pause' => 'pause',
      'Timer' => 'timer',
    ]);
  }

  /**
   * @covers ::label
   */
  public function testLabels(): void {
    $this->assertEquals('Confirmation', InterruptType::Confirmation->label());
    $this->assertEquals('Choice', InterruptType::Choice->label());
    $this->assertEquals('Text Input', InterruptType::Text->label());
    $this->assertEquals('Form', InterruptType::Form->label());
    $this->assertEquals('Sub-workflow execution', InterruptType::WorkflowExecution->label());
    $this->assertEquals('Pipeline completion sentinel', InterruptType::PipelineCompletion->label());
    $this->assertEquals('Schema-driven form', InterruptType::SchemaForm->label());
    $this->assertEquals('Cancel signal', InterruptType::Cancel->label());
    $this->assertEquals('Pause signal', InterruptType::Pause->label());
    $this->assertEquals('Timer', InterruptType::Timer->label());
  }

  /**
   * @covers ::description
   */
  public function testDescriptions(): void {
    $this->assertNotEmpty(InterruptType::Confirmation->description());
    $this->assertNotEmpty(InterruptType::Choice->description());
    $this->assertNotEmpty(InterruptType::Text->description());
    $this->assertNotEmpty(InterruptType::Form->description());
    $this->assertNotEmpty(InterruptType::WorkflowExecution->description());
    $this->assertNotEmpty(InterruptType::PipelineCompletion->description());
    $this->assertNotEmpty(InterruptType::SchemaForm->description());
    $this->assertNotEmpty(InterruptType::Cancel->description());
    $this->assertNotEmpty(InterruptType::Pause->description());
    $this->assertNotEmpty(InterruptType::Timer->description());
  }

  /**
   * Tests from string construction.
   */
  public function testFromString(): void {
    $this->assertSame(InterruptType::Confirmation, InterruptType::from('confirmation'));
    $this->assertSame(InterruptType::Form, InterruptType::from('form'));
  }

}
