#include "model/Attachment.hpp"
#include "core/JsonDecode.hpp"
namespace dp {
Attachment Attachment::fromJson(const Json& j) {
using D = JsonDecode;
Attachment a;
a.id = D::req<std::string>(j, "uid");
a.filename = D::opt<std::string>(j, "filename");
a.url = D::req<std::string>(j, "url");
a.size = D::opt<std::int64_t>(j, "size");
a.isImage = D::req<bool>(j, "is_image");
a.isVideo = D::req<bool>(j, "is_video");
a.mimeType = D::req<std::string>(j, "mime_type");
a.createdAt = D::reqDate(j, "created_at");
a.canModify = D::req<bool>(j, "can_modify");
return a;
}
Attachment Attachment::fromChatFrame(const Json& j) {
using D = JsonDecode;
Attachment a;
a.id = D::req<std::string>(j, "uid");
a.filename = D::opt<std::string>(j, "filename");
a.url = D::req<std::string>(j, "url");
a.size = D::opt<std::int64_t>(j, "size");
a.isImage = D::orDefault<bool>(j, "is_image", false);
a.isVideo = D::orDefault<bool>(j, "is_video", false);
a.mimeType = D::orDefault<std::string>(j, "mime_type", "");
a.createdAt = D::optDate(j, "created_at").value_or(DateCodec::now());
a.canModify = D::orDefault<bool>(j, "can_modify", false);
return a;
}
} // namespace dp