/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014-2018, Regents of the University of California.
 *
 * This file is part of NDN repo-ng (Next generation of NDN repository).
 * See AUTHORS.md for complete list of repo-ng authors and contributors.
 *
 * repo-ng is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef REPO_REPO_COMMAND_HPP
#define REPO_REPO_COMMAND_HPP

#include "common.hpp"
#include "repo-command-parameter.hpp"

#include <stdexcept>

namespace repo {

class RepoCommand : boost::noncopyable
{
public:
  /** \brief represents an error in RepoCommandParameters
   */
  class ArgumentError : public std::invalid_argument
  {
  public:
    explicit
    ArgumentError(const std::string& what)
      : std::invalid_argument(what)
    {
    }
  };

  virtual
  ~RepoCommand() = default;

  class FieldValidator
  {
  public:
    FieldValidator();

    /** \brief declare a required field
     */
    FieldValidator&
    required(RepoParameterField field)
    {
      m_required[field] = true;
      return *this;
    }

    /** \brief declare an optional field
     */
    FieldValidator&
    optional(RepoParameterField field)
    {
      m_optional[field] = true;
      return *this;
    }

    /** \brief verify that all required fields are present,
     *         and all present fields are either required or optional
     *  \throw ArgumentError
     */
    void
    validate(const RepoCommandParameter& parameters) const;

  private:
    std::vector<bool> m_required;
    std::vector<bool> m_optional;
  };

  void
  validateRequest(const RepoCommandParameter& parameters);

private:
  virtual void
  check(const RepoCommandParameter& parameters) const
  {
  }

public:
  FieldValidator m_requestValidator;
};

class InsertCommand : public RepoCommand
{
public:
  InsertCommand();

private:
  void
  check(const RepoCommandParameter& parameters) const override;
};

class InsertCheckCommand : public RepoCommand
{
public:
  InsertCheckCommand();
};

class WatchStartCommand : public RepoCommand
{
public:
  WatchStartCommand();
};

class WatchCheckCommand : public RepoCommand
{
public:
  WatchCheckCommand();
};

class WatchStopCommand : public RepoCommand
{
public:
  WatchStopCommand();
};

class DeleteCommand : public RepoCommand
{
public:
  DeleteCommand();

private:
  void
  check(const RepoCommandParameter& parameters) const override;
};

} // namespace repo

#endif // REPO_REPO_COMMAND_HPP