use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
use crate::errors;
#[derive(Serialize, Deserialize, Debug)]
pub struct PostEntryResponse {
#[serde(rename = "PostHashHex")]
pub post_hash_hex: String, #[serde(rename = "PosterPublicKeyBase58Check")]
pub poster_public_key: String,
#[serde(rename = "Body")]
pub body: String,
#[serde(rename = "ImageURLs")]
pub image_urls: Option<Vec<String>>,
#[serde(rename = "HasUnlockable")]
pub has_unlockable: bool,
#[serde(rename = "PostExtraData")]
pub extra_data: HashMap<String, String>,
#[serde(rename = "NumNFTCopies")]
#[serde(default)]
pub copies_minted: u64,
#[serde(rename = "TimestampNanos")]
pub timestamp: u128,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct SinglePostResponse {
#[serde(rename = "PostFound")]
pub post: PostEntryResponse,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct SubmittedTransaction {
#[serde(rename = "PostEntryResponse")]
pub post_entry_response: PostEntryResponse,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct SubmitPostData {
#[serde(rename = "UpdaterPublicKeyBase58Check")]
pub public_key: String,
#[serde(rename = "ParentStakeID")]
pub parent_post_hash_hex: Option<String>,
#[serde(rename = "BodyObj")]
pub body_obj: SubmitPostBodyObject,
#[serde(rename = "MinFeeRateNanosPerKB")]
pub fee_rate: u64,
#[serde(rename = "IsHidden")]
pub is_hidden: bool,
#[serde(rename = "PostExtraData")]
pub extra_data: Option<HashMap<String, String>>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct SubmitPostDataBuilder {
pub public_key: Option<String>,
pub parent_post_hash_hex: Option<String>,
pub body: Option<String>,
pub image_urls: Option<Vec<String>>,
pub video_urls: Option<Vec<String>>,
pub fee_rate: Option<u64>,
pub is_hidden: Option<bool>,
pub extra_data: Option<HashMap<String, String>>,
}
#[allow(dead_code)]
impl SubmitPostDataBuilder {
pub fn new() -> Self {
SubmitPostDataBuilder {
public_key: None,
parent_post_hash_hex: None,
body: None,
image_urls: None,
video_urls: None,
fee_rate: Some(1250),
is_hidden: Some(false),
extra_data: None,
}
}
pub fn public_key(mut self, public_key: String) -> Self {
self.public_key = Some(public_key);
self
}
pub fn parent_post_hash_hex(mut self, post_hash_hex: String) -> Self {
self.parent_post_hash_hex = Some(post_hash_hex);
self
}
pub fn body(mut self, body: String) -> Self {
self.body = Some(body);
self
}
pub fn image_urls(mut self, image_urls: Vec<String>) -> Self {
self.image_urls = Some(image_urls);
self
}
pub fn video_urls(mut self, video_urls: Vec<String>) -> Self {
self.video_urls = Some(video_urls);
self
}
pub fn fee_rate(mut self, fee_rate: u64) -> Self {
self.fee_rate = Some(fee_rate);
self
}
pub fn is_hidden(mut self, is_hidden: bool) -> Self {
self.is_hidden = Some(is_hidden);
self
}
pub fn extra_data(mut self, extra_data: HashMap<String, String>) -> Self {
self.extra_data = Some(extra_data);
self
}
pub fn build(self) -> Result<SubmitPostData, errors::DesoError> {
if self.body.is_none() {
return Err(errors::DesoError::SubmitPostDataBuilderError(String::from(
"Body",
)));
}
if self.public_key.is_none() {
return Err(errors::DesoError::SubmitPostDataBuilderError(String::from(
"Poster Public Key",
)));
}
let body_object = SubmitPostBodyObject {
body: self.body.unwrap(),
image_urls: self.image_urls,
video_urls: self.video_urls,
};
Ok(SubmitPostData {
public_key: self.public_key.unwrap(),
parent_post_hash_hex: self.parent_post_hash_hex,
body_obj: body_object,
fee_rate: self.fee_rate.unwrap(),
is_hidden: self.is_hidden.unwrap(),
extra_data: self.extra_data,
})
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct GetSinglePost {
#[serde(rename = "PostHashHex")]
pub post_hash_hex: String,
#[serde(rename = "CommentLimit")]
pub comment_limit: u32,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct SubmitPostBodyObject {
#[serde(rename = "Body")]
pub body: String,
#[serde(rename = "ImageURLs")]
pub image_urls: Option<Vec<String>>,
#[serde(rename = "VideoURLs")]
pub video_urls: Option<Vec<String>>,
}