module Recordings
  class PlaybackUrl
    def initialize(recording)
      @recording = recording
    end

    def call
      raise ArgumentError, "Replay non pronto" unless @recording.ready?
      raise ArgumentError, "Storage key mancante" if @recording.storage_key.blank?

      "#{MatchLiveTv.app_public_url.chomp('/')}/replay/#{@recording.stream_session_id}/stream"
    end

    def local_path
      storage = Recordings::Storage.new
      path = storage.local_path_for_key(@recording.storage_key)
      path if path && File.exist?(path)
    end
  end
end
