pilots.h 11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
#ifndef AIRMAP_PILOTS_H_
#define AIRMAP_PILOTS_H_

#include <airmap/aircraft.h>
#include <airmap/do_not_copy_or_move.h>
#include <airmap/error.h>
#include <airmap/optional.h>
#include <airmap/outcome.h>
#include <airmap/pilot.h>

#include <functional>
#include <iosfwd>
#include <string>
#include <vector>

namespace airmap {

/// Pilots provides functionality to manage (the authorized) pilot.
class Pilots : DoNotCopyOrMove {
 public:
  /// Exclude enumerates fields that can be excluded when querying pilot and aircraft properties.
  enum class Exclude {
    aircraft        = 1 << 0,  ///< Exclude aircraft data from results.
    user_metadata   = 1 << 1,  ///< Exclude user-specific metadata from results.
    app_metadata    = 1 << 2,  ///< Exclude app-specific metadata from results.
    authorized_apps = 1 << 3   ///< Exclude list of authorized apps from results.
  };

  /// Authenticated bundles up types to ease interaction
  /// with Pilots::authenticated.
  struct Authenticated {
    /// Parameters bundles up input parameters.
    struct Parameters {
      std::string authorization;        ///< Authorization token obtained by logging in to the AirMap services.
      Optional<Exclude> exclude{};      ///< Exclude these fields from results.
      bool retrieve_statistics{false};  ///< If true, statistics about flights and aircrafts are requested.
    };

    /// Result models the outcome of calling Pilots::authenticated.
    using Result = Outcome<Pilot, Error>;
    /// Callback describes the function signature of the callback that is
    /// invoked when a call to Pilots::authenticated finishes.
    using Callback = std::function<void(const Result&)>;
  };

  /// ForId bundles up types to ease interaction
  /// with Pilots::for_id.
  struct ForId {
    /// Parameters bundles up input parameters.
    struct Parameters {
      std::string authorization;        ///< Authorization token obtained by logging in to the AirMap services.
      std::string id;                   ///< Searches for the specific pilot with this id.
      Optional<Exclude> exclude{};      ///< Exclude these fields from results.
      bool retrieve_statistics{false};  ///< If true, statistics about flights and aircrafts are requested.
    };

    /// Result models the outcome of calling Pilots::for_id.
    using Result = Outcome<Pilot, Error>;
    /// Callback describes the function signature of the callback that is
    /// invoked when a call to Pilots::for_id finishes.
    using Callback = std::function<void(const Result&)>;
  };

  /// UpdateForId bundles up types to ease interaction
  /// with Pilots::update_for_id.
  struct UpdateForId {
    /// Parameters bundles up input parameters.
    struct Parameters {
      std::string authorization;  ///< Authorization token obtained by logging in to the AirMap services.
      std::string id;             ///< Updates the specific pilot with this id.
      std::string first_name;     ///< The first name of the pilot.
      std::string last_name;      ///< The last name of the pilot.
      std::string user_name;      ///< The AirMap username of this pilot.
      std::string phone;          ///< The phone number of the pilot.
      std::map<std::string, std::string> app_metadata;   ///< App-specific metadata associated to the pilot.
      std::map<std::string, std::string> user_metadata;  ///< User-specific metadata associated to the pilot.
    };

    /// Result models the outcome of calling Pilots::update_for_id.
    using Result = Outcome<Pilot, Error>;
    /// Callback describes the function signature of the callback that is
    /// invoked when a call to Pilots::update_for_id finishes.
    using Callback = std::function<void(const Result&)>;
  };

  /// StartVerifyPilotPhoneForId bundles up types to ease interaction
  /// with Pilots::start_verify_pilot_phone_for_id.
  struct StartVerifyPilotPhoneForId {
    /// Parameters bundles up input parameters.
    struct Parameters {
      std::string authorization;  ///< Authorization token obtained by logging in to the AirMap services.
      std::string id;             ///< Verifies the phone number for the pilot with this id.
    };

    struct Empty {};

    /// Result models the outcome of calling Pilots::start_verify_pilot_phone_for_id.
    using Result = Outcome<Empty, Error>;
    /// Callback describes the function signature of the callback that is
    /// invoked when a call to Pilots::start_verify_pilot_phone_for_id finishes.
    using Callback = std::function<void(const Result&)>;
  };

  /// FinishVerifyPilotPhoneForId bundles up types to ease interaction
  /// with Pilots::finish_verify_pilot_phone_for_id.
  struct FinishVerifyPilotPhoneForId {
    /// Parameters bundles up input parameters.
    struct Parameters {
      std::string authorization;  ///< Authorization token obtained by logging in to the AirMap services.
      std::string id;             ///< Verifies the phone number for the pilot with this id.
      std::uint32_t token;        ///< The token that was received on the pilot's phone.
    };

    struct Empty {};

    /// Result models the outcome of calling Pilots::finish_verify_pilot_phone_for_id.
    using Result = Outcome<Empty, Error>;
    /// Callback describes the function signature of the callback that is
    /// invoked when a call to Pilots::finish_verify_pilot_phone_for_id finishes.
    using Callback = std::function<void(const Result&)>;
  };

  /// Aircrafts bundles up types to ease interaction
  /// with Pilots::aircrafts.
  struct Aircrafts {
    /// Parameters bundles up input parameters.
    struct Parameters {
      std::string authorization;  ///< Authorization token obtained by logging in to the AirMap services.
      std::string id;             ///< Lists all aircrafts owned by the pilot with this id.
    };

    /// Result models the outcome of calling Pilots::aircrafts.
    using Result = Outcome<std::vector<Pilot::Aircraft>, Error>;
    /// Callback describes the function signature of the callback that is
    /// invoked when a call to Pilots::aircrafts finishes.
    using Callback = std::function<void(const Result&)>;
  };

  /// AddAircraft bundles up types to ease interaction
  /// with Pilots::add_aircraft.
  struct AddAircraft {
    /// Parameters bundles up input parameters.
    struct Parameters {
      std::string authorization;  ///< Authorization token obtained by logging in to the AirMap services.
      std::string id;             ///< Adds an aircraft for the pilot with this id.
      std::string model_id;       ///< The id of the model of the aircraft.
      std::string nick_name;      ///< The nickname of the aircraft.
    };

    /// Result models the outcome of calling Pilots::add_aircraft.
    using Result = Outcome<Pilot::Aircraft, Error>;
    /// Callback describes the function signature of the callback that is
    /// invoked when a call to Pilots::add_aircraft finishes.
    using Callback = std::function<void(const Result&)>;
  };

  /// DeleteAircraft bundles up types to ease interaction
  /// with Pilots::delete_aircraft.
  struct DeleteAircraft {
    /// Parameters bundles up input parameters.
    struct Parameters {
      std::string authorization;  ///< Authorization token obtained by logging in to the AirMap services.
      std::string id;             ///< Deletes an aircraft for the pilot with this id.
      std::string aircraft_id;    ///< Deletes the specific aircraft with this id.
    };

    struct Empty {};

    /// Result models the outcome of calling Pilots::delete_aircraft.
    using Result = Outcome<Empty, Error>;
    /// Callback describes the function signature of the callback that is
    /// invoked when a call to Pilots::delete_aircraft finishes.
    using Callback = std::function<void(const Result&)>;
  };

  /// UpdateAircraft bundles up types to ease interaction
  /// with Pilots::update_aircraft.
  struct UpdateAircraft {
    /// Parameters bundles up input parameters.
    struct Parameters {
      std::string authorization;  ///< Authorization token obtained by logging in to the AirMap services.
      std::string id;             ///< Updates an aircraft for the pilot with this id.
      std::string aircraft_id;    ///< Update the specific aircraft with this id.
      std::string nick_name;      ///< The new nick name for the aircraft.
    };

    struct Empty {};
    /// Result models the outcome of calling Pilots::update_aircraft.
    using Result = Outcome<Empty, Error>;
    /// Callback describes the function signature of the callback that is
    /// invoked when a call to Pilots::update_aircraft finishes.
    using Callback = std::function<void(const Result&)>;
  };

  /// current_user queries the AirMap services for the pilot profile
  /// connected to the authenticated user, reporting results to 'cb'.
  virtual void authenticated(const Authenticated::Parameters& parameters, const Authenticated::Callback& cb) = 0;

  /// for_id queries the AirMap services for the pilot profile
  /// with a given id, reporting results to 'cb'.
  virtual void for_id(const ForId::Parameters& parameters, const ForId::Callback& cb) = 0;

  /// update_for_id updates the pilot profile specified
  // by Parameters::id, reporting results to 'cb'.
  virtual void update_for_id(const UpdateForId::Parameters& parameters, const UpdateForId::Callback& cb) = 0;

  /// start_verify_pilot_phone_for_id sends a verification token to the phone
  /// number stored in the pilot profile, reporting results to 'cb'.
  virtual void start_verify_pilot_phone_for_id(const StartVerifyPilotPhoneForId::Parameters& parameters,
                                               const StartVerifyPilotPhoneForId::Callback& cb) = 0;

  /// finish_verify_pilot_phone_for_id responds to a verification request by
  /// sending back the token sent to the pilot's phone, reporting results to 'cb'.
  virtual void finish_verify_pilot_phone_for_id(const FinishVerifyPilotPhoneForId::Parameters& parameters,
                                                const FinishVerifyPilotPhoneForId::Callback& cb) = 0;

  /// aircrafts queries the list of aircrafts owned by a pilot, reporting results to 'cb'.
  virtual void aircrafts(const Aircrafts::Parameters& parameters, const Aircrafts::Callback& cb) = 0;

  /// add_aircraft associates a new aircraft with a pilot, reporting results to 'cb'.
  virtual void add_aircraft(const AddAircraft::Parameters& parameters, const AddAircraft::Callback& cb) = 0;

  /// delete_aircraft removes an aircraft from a pilot profile, reporting results to 'cb'.
  virtual void delete_aircraft(const DeleteAircraft::Parameters& parameters, const DeleteAircraft::Callback& cb) = 0;

  /// update_aircraft updates the properties of an aircraft associated with a pilot, reporting results to 'cb'.
  virtual void update_aircraft(const UpdateAircraft::Parameters& parameters, const UpdateAircraft::Callback& cb) = 0;

 protected:
  Pilots() = default;
};

/// @cond
Pilots::Exclude operator|(Pilots::Exclude, Pilots::Exclude);
Pilots::Exclude operator&(Pilots::Exclude, Pilots::Exclude);
std::ostream& operator<<(std::ostream& out, Pilots::Exclude exclude);
/// @endcond

}  // namespace airmap

#endif  // AIRMAP_PILOTS_H_