use serde::{Deserialize, Serialize};
use crate::{Currency, endpoint};
pub const URL: &str = "https://economy.roblox.com/v1";
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct PurchaseResponse {
pub purchased: bool,
}
#[derive(Clone, Debug, Deserialize)]
struct CurrencyResponse {
robux: u64,
}
#[derive(Serialize)]
struct PurchaseRequest {
#[serde(rename = "expectedCurrency")]
currency: u8,
#[serde(rename = "expectedPrice")]
price: u64,
#[serde(rename = "expectedSellerId")]
seller_user_id: Option<u64>,
}
endpoint! {
purchase(product_id: u64, price: u64, currency: Currency, seller_user_id: Option<u64>) -> PurchaseResponse {
POST "{URL}/purchases/products/{product_id}";
body_serialize { PurchaseRequest {
currency: currency as u8,
price,
seller_user_id,
}}
}
currency() -> u64 {
GET "{URL}/user/currency";
map |r: CurrencyResponse| r.robux
}
currency_from_user_id(id: u64) -> u64 {
GET "{URL}/users/{id}/currency";
map |r: CurrencyResponse| r.robux
}
currency_from_group_id(id: u64) -> u64 {
GET "{URL}/groups/{id}/currency";
map |r: CurrencyResponse| r.robux
}
}