<?php

declare(strict_types=1);

namespace Drupal\Tests\flowdrop_orchestration\Unit\DTO;

use Drupal\Tests\UnitTestCase;
use Drupal\flowdrop_orchestration\DTO\Orchestrator\OrchestrationResponse;

/**
 * Tests the OrchestrationResponse DTO.
 *
 * @coversDefaultClass \Drupal\flowdrop_orchestration\DTO\Orchestrator\OrchestrationResponse
 * @group flowdrop_orchestration
 */
class OrchestrationResponseTest extends UnitTestCase {

  /**
   * @covers ::__construct
   * @covers ::getExecutionId
   * @covers ::getStatus
   * @covers ::getResults
   * @covers ::getExecutionTime
   * @covers ::getMetadata
   */
  public function testConstructorAndGetters(): void {
    $response = new OrchestrationResponse(
      executionId: "exec_1",
      status: "completed",
      results: ["output" => "data"],
      executionTime: 1.5,
      metadata: ["nodes_executed" => 3],
    );

    $this->assertEquals("exec_1", $response->getExecutionId());
    $this->assertEquals("completed", $response->getStatus());
    $this->assertEquals(["output" => "data"], $response->getResults());
    $this->assertEquals(1.5, $response->getExecutionTime());
    $this->assertEquals(["nodes_executed" => 3], $response->getMetadata());
  }

  /**
   * @covers ::toArray
   */
  public function testToArray(): void {
    $response = new OrchestrationResponse(
      executionId: "exec_2",
      status: "failed",
      results: [],
      executionTime: 0.5,
      metadata: ["error" => "timeout"],
    );

    $array = $response->toArray();
    $this->assertEquals("exec_2", $array["execution_id"]);
    $this->assertEquals("failed", $array["status"]);
    $this->assertEquals([], $array["results"]);
    $this->assertEquals(0.5, $array["execution_time"]);
    $this->assertEquals(["error" => "timeout"], $array["metadata"]);
  }

}
