<?php

declare(strict_types=1);

namespace Drupal\ffmpeg_media\Enum;

/**
 * Output type identifiers for the ffmpeg_media_outputs table.
 *
 * Each case represents a distinct output type stored in the `output_type`
 * column. Container formats (Mp4, WebM, etc.) come from profile output
 * configurations; processor outputs (Thumbnail, Transcript, etc.) are
 * created by the processor pipeline.
 */
enum OutputType: string {

  // Container/video formats.
  case Mp4 = 'mp4';
  case WebM = 'webm';
  case Mkv = 'mkv';
  case Flv = 'flv';
  case Mov = 'mov';
  case Ogg = 'ogg';
  case Jxl = 'jxl';

  // Adaptive streaming.
  case Hls = 'hls';
  case Dash = 'dash';

  // Processor pipeline outputs.
  case Thumbnail = 'thumbnail';
  case Gif = 'gif';
  case SegmentThumbnails = 'segment_thumbnails';
  case SegmentGifs = 'segment_gifs';
  case Transcript = 'transcript';
  case SubtitleTracks = 'subtitle_tracks';
  case Metadata = 'metadata';
  case Manifest = 'manifest';
  case MultiAudio = 'multi_audio';
  case AudioNormalized = 'audio_normalized';
  case Watermarked = 'watermarked';
  case Normalized = 'normalized';
  case Subtitled = 'subtitled';
  case HdrOutput = 'hdr_output';
  case SdrOutput = 'sdr_output';

  /**
   * Checks if this output type supports multiple files per media entity.
   *
   * Multi-value types allow multiple rows in the outputs table for the
   * same (media_id, field_name, output_type) combination.
   *
   * @return bool
   *   TRUE if multiple files are allowed.
   */
  #[\NoDiscard]
  public function isMultiValue(): bool {
    return match ($this) {
      self::SubtitleTracks,
      self::SegmentThumbnails,
      self::SegmentGifs => TRUE,
      default => FALSE,
    };
  }

  /**
   * Checks if this output type is an adaptive streaming format.
   *
   * @return bool
   *   TRUE for HLS and DASH.
   */
  #[\NoDiscard]
  public function isAdaptiveStreaming(): bool {
    return $this === self::Hls || $this === self::Dash;
  }

}
