#pragma once
// Spec: shell.md section 6 (DevPlaceApi protocol). Abstract callback API the UI codes against; implemented by
// ProdDevPlaceApi (network) and MockDevPlaceApi (fixtures, --mock). Every method returns a CancelPtr; a cancelled
// call never calls back. Callbacks run on the UI thread. Calls without a token fail with DevPlaceError::notLoggedIn()
// (delivered asynchronously). Result<Unit> is the "Void" result.
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "api/ApiTypes.hpp"
#include "api/MessagesSocket.hpp"
#include "model/BirthDate.hpp"
#include "model/Feed.hpp"
#include "model/MessagesInbox.hpp"
#include "model/NotificationCounts.hpp"
#include "model/NotificationOpen.hpp"
#include "model/Notifications.hpp"
#include "model/PostDetail.hpp"
#include "model/PostTopic.hpp"
#include "model/Profile.hpp"
#include "model/ReportReason.hpp"
#include "model/TargetType.hpp"
#include "model/UploadResponse.hpp"
#include "model/UserSearch.hpp"
#include "model/Vote.hpp"
namespace dp {
class DevPlaceApi {
public:
using Str = std::optional<std::string>;
virtual ~DevPlaceApi() = default;
virtual CancelPtr logIn(const std::string& email, const std::string& password, Done<Unit> done) = 0;
virtual CancelPtr signUp(const std::string& username, const std::string& email, const std::string& password,
const std::string& confirmPassword, const BirthDate& birthDate, bool acceptTerms,
Done<Unit> done) = 0;
virtual CancelPtr deleteAccount(const std::string& password, Done<Unit> done) = 0;
virtual CancelPtr feed(const std::optional<Date>& before, Done<Feed> done) = 0;
virtual CancelPtr postDetail(const std::string& slug, Done<PostDetail> done) = 0;
virtual CancelPtr createPost(const Str& title, const std::optional<PostTopic>& topic, const std::string& content,
const std::vector<UploadResponse>& attachments, const Str& pollQuestion,
const std::vector<std::string>& pollOptions, const Str& projectLink, Done<Unit> done) = 0;
virtual CancelPtr editPost(const std::string& slug, const std::string& title, PostTopic topic, const std::string& content,
const std::string& projectLink, Done<Unit> done) = 0;
virtual CancelPtr deletePost(const std::string& slug, Done<Unit> done) = 0;
virtual CancelPtr deleteComment(const std::string& uid, Done<Unit> done) = 0;
virtual CancelPtr editComment(const std::string& uid, const std::string& content, Done<Unit> done) = 0;
virtual CancelPtr createComment(TargetType targetType, const std::string& targetId, const std::string& content,
const Str& parentId, const std::vector<UploadResponse>& attachments, Done<Unit> done) = 0;
virtual CancelPtr profile(const Str& username, Done<Profile> done) = 0;
virtual CancelPtr followUser(const std::string& username, Done<Unit> done) = 0;
virtual CancelPtr unfollowUser(const std::string& username, Done<Unit> done) = 0;
virtual CancelPtr blockUser(const std::string& username, Done<Unit> done) = 0;
virtual CancelPtr unblockUser(const std::string& username, Done<Unit> done) = 0;
virtual CancelPtr muteUser(const std::string& username, Done<Unit> done) = 0;
virtual CancelPtr unmuteUser(const std::string& username, Done<Unit> done) = 0;
virtual CancelPtr messages(const Str& withUid, Done<MessagesInbox> done) = 0;
virtual CancelPtr sendMessage(const std::string& receiverId, const std::string& content,
const std::vector<UploadResponse>& attachments, Done<Unit> done) = 0;
virtual std::unique_ptr<MessagesSocket> makeMessagesSocket(const std::string& otherUserId) = 0;
virtual CancelPtr usersForMentioning(const std::string& query, Done<UserSearch> done) = 0;
virtual CancelPtr notifications(const std::optional<Date>& before, Done<Notifications> done) = 0;
virtual CancelPtr openNotification(const std::string& uid, Done<NotificationOpen> done) = 0;
virtual CancelPtr notificationCounts(Done<NotificationCounts> done) = 0;
virtual CancelPtr markNotificationRead(const std::string& uid, Done<Unit> done) = 0;
virtual CancelPtr markAllNotificationsRead(Done<Unit> done) = 0;
virtual CancelPtr registerPushDevice(const std::string& deviceToken, Done<Unit> done) = 0;
virtual CancelPtr unregisterPushDevice(const std::string& deviceToken, Done<Unit> done) = 0;
// The backend toggles: always send Vote::Up to add or remove an upvote (see AppState::performVoteToggle).
virtual CancelPtr vote(TargetType targetType, const std::string& targetId, Vote vote, Done<Unit> done) = 0;
virtual CancelPtr submitPollChoice(const std::string& pollId, const std::string& optionId, Done<Unit> done) = 0;
virtual CancelPtr react(TargetType targetType, const std::string& targetId, const std::string& emoji, Done<Unit> done) = 0;
virtual CancelPtr reportReasons(Done<std::vector<ReportReason>> done) = 0;
virtual CancelPtr report(TargetType targetType, const std::string& targetId, const std::string& reason, const Str& detail,
Done<Unit> done) = 0;
virtual CancelPtr uploadFile(const std::string& data, const std::string& filename, const std::string& mimeType,
Done<UploadResponse> done) = 0;
virtual CancelPtr uploadFromUrl(const std::string& url, const Str& filename, Done<UploadResponse> done) = 0;
virtual CancelPtr deleteAttachment(const std::string& uid, Done<Unit> done) = 0;
// Convenience overloads (Swift protocol extension). Derived classes must `using DevPlaceApi::feed;` etc.
CancelPtr feed(Done<Feed> done) { return feed(std::nullopt, std::move(done)); }
CancelPtr notifications(Done<Notifications> done) { return notifications(std::nullopt, std::move(done)); }
CancelPtr messages(Done<MessagesInbox> done) { return messages(std::nullopt, std::move(done)); }
// Swift extension: when AppState has a token that willExpireSoon, log in again with the stored session
// credentials (silently succeeds without them), then call `done`. A login failure is reported to `done`.
CancelPtr refreshTokenIfNeeded(Done<Unit> done);
};
} // namespace dp