/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_quota_persistencetype_h_
#define mozilla_dom_quota_persistencetype_h_

#include <array>
#include <cstdint>

#include "mozilla/Maybe.h"
#include "mozilla/fallible.h"
#include "nsStringFwd.h"

class nsIFile;

namespace mozilla::dom::quota {

enum PersistenceType {
  PERSISTENCE_TYPE_PERSISTENT = 0,
  PERSISTENCE_TYPE_TEMPORARY,
  PERSISTENCE_TYPE_DEFAULT,
  PERSISTENCE_TYPE_PRIVATE,

  // Only needed for IPC serialization helper, should never be used in code.
  PERSISTENCE_TYPE_INVALID
};

static const PersistenceType kAllPersistenceTypes[] = {
    PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY,
    PERSISTENCE_TYPE_DEFAULT, PERSISTENCE_TYPE_PRIVATE};

static const PersistenceType kAllPersistenceTypesButPrivate[] = {
    PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY,
    PERSISTENCE_TYPE_DEFAULT};

static const PersistenceType kBestEffortPersistenceTypes[] = {
    PERSISTENCE_TYPE_TEMPORARY, PERSISTENCE_TYPE_DEFAULT,
    PERSISTENCE_TYPE_PRIVATE};

static const PersistenceType kInitializableBestEffortPersistenceTypes[] = {
    PERSISTENCE_TYPE_TEMPORARY, PERSISTENCE_TYPE_DEFAULT};

static const PersistenceType kTemporaryPersistenceTypes[] = {
    PERSISTENCE_TYPE_TEMPORARY, PERSISTENCE_TYPE_DEFAULT,
    PERSISTENCE_TYPE_PRIVATE};

bool IsTemporaryPersistenceType(const PersistenceType aPersistenceType);

bool IsValidPersistenceType(PersistenceType aPersistenceType);

bool IsBestEffortPersistenceType(const PersistenceType aPersistenceType);

nsLiteralCString PersistenceTypeToString(PersistenceType aPersistenceType);

Maybe<PersistenceType> PersistenceTypeFromString(const nsACString& aString,
                                                 const fallible_t&);

PersistenceType PersistenceTypeFromString(const nsACString& aString);

Maybe<PersistenceType> PersistenceTypeFromInt32(int32_t aInt32,
                                                const fallible_t&);

// aFile is expected to be a repository directory (not some file or directory
// within that).
Maybe<PersistenceType> PersistenceTypeFromFile(nsIFile& aFile,
                                               const fallible_t&);

std::array<PersistenceType, 2> ComplementaryPersistenceTypes(
    const PersistenceType aPersistenceType);

}  // namespace mozilla::dom::quota

#endif  // mozilla_dom_quota_persistencetype_h_
