// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_
#define COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_

#include <stdint.h>
#include <vector>

#include "base/callback.h"
#include "components/offline_pages/background/request_queue.h"
#include "components/offline_pages/background/save_page_request.h"
#include "components/offline_pages/offline_store_types.h"

namespace offline_pages {

// Interface for classes storing save page requests.
class RequestQueueStore {
 public:
  enum class UpdateStatus {
    ADDED,    // Request was added successfully.
    UPDATED,  // Request was updated successfully.
    FAILED,   // Add or update attempt failed.
  };

  using UpdateCallback = RequestQueue::UpdateCallback;

  typedef base::Callback<void(
      bool /* success */,
      std::vector<std::unique_ptr<SavePageRequest>> /* requests */)>
      GetRequestsCallback;
  typedef base::Callback<void(ItemActionStatus)> AddCallback;
  typedef base::Callback<void(bool /* success */)> ResetCallback;

  virtual ~RequestQueueStore(){};

  // Gets all of the requests from the store.
  virtual void GetRequests(const GetRequestsCallback& callback) = 0;

  // Gets requests with specified IDs from the store. UpdateCallback is used
  // instead of GetRequestsCallback to indicate which requests where not found.
  virtual void GetRequestsByIds(const std::vector<int64_t>& request_ids,
                                const UpdateCallback& callback) = 0;

  // Asynchronously adds request in store. Fails if request with the same
  // offline ID already exists.
  virtual void AddRequest(const SavePageRequest& offline_page,
                          const AddCallback& callback) = 0;

  // Asynchronously updates requests in store.
  virtual void UpdateRequests(const std::vector<SavePageRequest>& requests,
                              const UpdateCallback& callback) = 0;

  // Asynchronously removes requests from the store using their IDs.
  // Result of the update, and a number of removed pages is passed in the
  // callback.
  // Result of remove should be false, when one of the provided items couldn't
  // be deleted, e.g. because it was missing.
  virtual void RemoveRequests(const std::vector<int64_t>& request_ids,
                              const UpdateCallback& callback) = 0;

  // Resets the store.
  virtual void Reset(const ResetCallback& callback) = 0;

  // Gets the store state.
  virtual StoreState state() const = 0;
};

}  // namespace offline_pages

#endif  // COMPONENTS_OFFLINE_PAGES_BACKGROUND_REQUEST_QUEUE_STORE_H_
