class VideoAnalysis
  mattr_accessor :use_overlay_video, default: true

  def initialize(video, reanalysis)
    @video = video
    @reanalysis = reanalysis
  end

  # Use the custom hash to generate JSON format
  def as_json(*)
    to_hash
  end

  def to_hash
    {
      bucket_name: aws_bucket_name,
      collection_id: video.project.headshot_collection_uid,
      video_object_name: video.file.key,
      reanalysis: reanalysis,
    }
  end

  def overlay_video_url
    return if !use_overlay_video
    return if response.overlay_video_url == "None"

    response.overlay_video_url
  end

  def first_appearances
    response.first_appearances
  end

  private

  attr_reader :video, :reanalysis

  def aws_bucket_name
    ENV["AWS_BUCKET"]
  end

  def response
    @response ||= BrayniacAI::FacialRecognition.find(video.analysis_uid)
  end
end
