class VideoAnalysesController < ApplicationController
  before_action :set_video, only: [:create, :show]

  def create
    AnalyzeVideoJob.perform_later(@video, reanalysis: true)
    AnalyzeAudioJob.perform_later(@video)

    redirect_to [@video, :video_analyses], notice: t(".notice")
  end

  def show
    @video_release_confirmations = @video.video_release_confirmations.order_by_ranked_release_type
    @talent_releases = @video.project.talent_releases
    @appearance_releases = @video.project.appearance_releases
    @location_releases = @video.project.location_releases
    @acquired_media_releases = @video.project.acquired_media_releases
    @music_releases = @video.project.music_releases
    @material_releases = @video.project.material_releases
    @bookmarks = @video.bookmarks

    video_analysis = authorize(VideoAnalysis.new(@video, false))
    audio_analysis = AudioAnalysis.new(@video)
    @video_analysis_presenter = VideoAnalysisService.new.presenter(
      @video,
      video_analysis,
      audio_analysis,
    )
    @graphics_elements_data = GraphicsElements::GraphicsElementsPresenter.new.present(@video.graphics_elements)
    @unreleased_appearances_data = UnreleasedAppearancesPresenter.new.present(@video.unreleased_appearances)
    @audio_confirmations = @video.audio_confirmations
  end

  private

  def set_video
    @video = authorize Video.find(params[:video_id]), policy_class: VideoAnalysisPolicy
  end
end
