#pragma once // Spec: INV-posts 11 (ReportButton+ViewModel). Reasons loading, selection, detail text and submission. #include #include #include #include #include #include "core/Result.hpp" #include "model/ReportReason.hpp" #include "model/TargetType.hpp" namespace dp { class ReportViewModel { public: ReportViewModel(TargetType type, std::string targetId); // Cached per target so the loaded reasons survive between presentations. static std::shared_ptr shared(TargetType type, const std::string& targetId); static void clearCache(); TargetType targetType() const { return type_; } const std::string& targetId() const { return targetId_; } // "comment" for comments, "post" otherwise. std::string targetNoun() const; std::string sheetTitle() const; std::size_t detailLimit() const; const std::vector& reasons() const { return reasons_; } bool didFailToLoadReasons() const { return failed_; } bool isSubmitting() const { return submitting_; } const std::optional& selectedReasonKey() const { return selected_; } void selectReason(const std::string& key) { selected_ = key; } std::string detail; bool isDetailWithinLimit() const; bool canSubmit() const; void prepareForPresentation(); // Only when reasons are empty and no load is running (RBVM.swift:55-66). void loadReasons(); // Trims the detail (whitespace and newlines), nullopt when empty. `done(true)` on success. void submit(std::function done); static std::optional trimmedDetail(const std::string& detail); private: TargetType type_; std::string targetId_; std::vector reasons_; bool loading_ = false; bool failed_ = false; bool submitting_ = false; std::optional selected_; std::weak_ptr self_; }; } // namespace dp