# Job to manage bulk deserialization.
class DeserializeJob < TrackableJob
  def do_job(data, preview)
    user = @net_id ? User.find_by(net_id: @net_id) : nil
    input = JSON.parse(data)
    tracker.log("Validating input and access for #{user.net_id}.")
    Deserializer.validate(input, user)
    if preview
      tracker.log('Generating preview.')
      tracker.preview(Deserializer.preview(input))
    else
      tracker.log('Starting deserialization.')
      Deserializer.bulk(input, user.net_id)
    end
  end

  def self.display_name
    'Bulk Deserialize'
  end

  def self.display_category
    'Export / Import'
  end

  def self.file_type; :json; end

  def self.requires_data?; true; end

  def self.previewable?; true; end
end
