<?php

declare(strict_types=1);

namespace Drupal\Tests\flowdrop_trigger\Unit;

use Drupal\Tests\UnitTestCase;
use Drupal\flowdrop_trigger\Service\TriggerManagerInterface;
use Drupal\flowdrop_trigger\FlowDropEventTypeInterface;
use Drupal\Tests\flowdrop\Unit\Traits\InterfaceContractTestTrait;

/**
 * Tests trigger interface contracts are stable.
 *
 * @group flowdrop_trigger
 */
class InterfaceContractTest extends UnitTestCase {

  use InterfaceContractTestTrait;

  /**
   * Tests TriggerManagerInterface method signatures.
   *
   * @covers \Drupal\flowdrop_trigger\Service\TriggerManagerInterface
   */
  public function testTriggerManagerInterface(): void {
    $this->assertInterfaceHasMethod(
      TriggerManagerInterface::class,
      'processEvent',
      ['eventType', 'entity', 'context']
    );
    $this->assertInterfaceHasMethod(
      TriggerManagerInterface::class,
      'processFormEvent',
      ['eventType', 'formId', 'context']
    );
    $this->assertInterfaceHasMethod(
      TriggerManagerInterface::class,
      'processCronEvent',
      ['eventType', 'context']
    );
    $this->assertInterfaceHasMethod(
      TriggerManagerInterface::class,
      'getAllActiveTriggers'
    );
    $this->assertInterfaceHasMethod(
      TriggerManagerInterface::class,
      'getTriggersForWorkflow',
      ['workflowId']
    );
    $this->assertInterfaceMethodCount(TriggerManagerInterface::class, 5);
  }

  /**
   * Tests FlowDropEventTypeInterface method signatures.
   *
   * @covers \Drupal\flowdrop_trigger\FlowDropEventTypeInterface
   */
  public function testFlowDropEventTypeInterface(): void {
    $this->assertInterfaceHasMethod(FlowDropEventTypeInterface::class, 'getEventId');
    $this->assertInterfaceHasMethod(FlowDropEventTypeInterface::class, 'getLabel');
    $this->assertInterfaceHasMethod(FlowDropEventTypeInterface::class, 'getDescription');
    $this->assertInterfaceHasMethod(FlowDropEventTypeInterface::class, 'getCategory');
    $this->assertInterfaceHasMethod(FlowDropEventTypeInterface::class, 'getDefaultOrchestrator');
    $this->assertInterfaceHasMethod(FlowDropEventTypeInterface::class, 'getDefaultExecutionMode');
    $this->assertInterfaceHasMethod(FlowDropEventTypeInterface::class, 'getSupportedEntityTypes');
    $this->assertInterfaceHasMethod(FlowDropEventTypeInterface::class, 'supportsEntityType', ['entityType']);
    $this->assertInterfaceHasMethod(
      FlowDropEventTypeInterface::class,
      'extractTriggerData',
      ['entity', 'originalEntity', 'context']
    );
    $this->assertInterfaceHasMethod(FlowDropEventTypeInterface::class, 'getParameterSchema');
  }

}
