<?php

declare(strict_types=1);

namespace Drupal\ffmpeg_media\Event;

use Drupal\Component\EventDispatcher\Event;
use Drupal\ffmpeg_media\ValueObject\ConversionResult;
use Drupal\media\MediaInterface;

/**
 * Event dispatched when a video conversion completes successfully.
 */
final class ConversionCompletedEvent extends Event {

  /**
   * Constructs a ConversionCompletedEvent.
   *
   * @param \Drupal\media\MediaInterface $media
   *   The media entity that was converted.
   * @param \Drupal\ffmpeg_media\ValueObject\ConversionResult $result
   *   The conversion result.
   */
  public function __construct(
    public readonly MediaInterface $media,
    public readonly ConversionResult $result,
  ) {}

  /**
   * Gets the media entity ID.
   *
   * @return int
   *   The media entity ID.
   */
  public function getMediaId(): int {
    return (int) $this->media->id();
  }

  /**
   * Gets the output file paths.
   *
   * @return array<string, string>
   *   Array of output paths keyed by format.
   */
  public function getOutputs(): array {
    return $this->result->outputs;
  }

  /**
   * Gets the conversion duration.
   *
   * @return float
   *   Duration in seconds.
   */
  public function getDuration(): float {
    return $this->result->duration;
  }

}
