class VideoAnalyses::EdlEventsController < ApplicationController
  before_action :set_video

  def create
    @timecode = timecode
    @edl_events = edl_event_gateway.edl_events
    @info_message = t(".info_message", count: @edl_events.size)
  end

  private

  def videos
    policy_scope(Video)
  end

  def set_video
    @video = authorize videos.find(params[:video_id])
  end

  def edl_event_gateway
    @edl_event_gateway ||= EdlEventGateway.new(FilesForRequest.new(@video), timecode, timecode)
  end

  def edl_event_params
    params.require(:edl_event).permit(:time_elapsed)
  end

  def timecode
    time_elapsed = edl_event_params.fetch(:time_elapsed)
    Timecode.from_seconds(time_elapsed.to_f).to_s
  end
end
