/ src / buff_market / models.rs
models.rs
  1  use serde::{Deserialize, Serialize};
  2  
  3  #[derive(Debug, Serialize, Deserialize)]
  4  pub struct GoodsBuyOrderResponse {
  5      pub code: String,
  6      pub data: Option<GoodsBuyOrderData>,
  7      pub msg: Option<String>,
  8      // pub request_id: String, // This seems to be missing in some responses
  9  }
 10  
 11  #[derive(Debug, Serialize, Deserialize)]
 12  pub struct GoodsBuyOrderData {
 13      pub items: Vec<Item>,
 14      pub page_num: i32,
 15      pub page_size: i32,
 16      pub total_count: i32,
 17      pub total_page: i32,
 18      // pub user_infos: serde_json::Value, // Assuming this can be dynamic or we might need specific structs later
 19  }
 20  
 21  #[derive(Debug, Serialize, Deserialize)]
 22  pub struct Item {
 23      pub app_id: i32,
 24      pub asset_info: Option<AssetInfo>,
 25      pub bookmarked: bool,
 26      pub buy_max_price: Option<String>,
 27      pub buy_num: i32,
 28      pub can_bargain: bool,
 29      pub can_search_intent: bool,
 30      pub created_at: i64,
 31      pub goods_id: i64,
 32      pub id: String,
 33      pub updated_at: i64,
 34      pub user_id: i64,
 35      pub price: String, // This was 'url' in your python example, but 'price' seems more standard from API responses
 36      pub state: i32,    // 0: pending, 1: active etc. (need to confirm exact states)
 37      pub supported_pay_method: i32,
 38      pub trade_max_price: Option<String>,
 39  }
 40  
 41  #[derive(Debug, Serialize, Deserialize)]
 42  pub struct AssetInfo {
 43      pub appid: i32,
 44      pub assetid: String,
 45      pub classid: String,
 46      pub goods_id: i64, 
 47      pub instanceid: String,
 48      pub market_hash_name: String,
 49      // pub paintwear: Option<String>, // exterior wear, e.g. "0.06..."
 50      // pub inspect_details: Option<InspectDetails>, // More detailed info, if needed
 51      // pub sticker_info: Option<Vec<Sticker>> // Sticker details
 52  }
 53  
 54  // Structs for https://api.buff.market/api/market/goods endpoint
 55  
 56  #[derive(Debug, Serialize, Deserialize)]
 57  pub struct MarketGoodsResponse {
 58      pub code: String,
 59      pub data: Option<MarketGoodsData>,
 60      pub msg: Option<String>,
 61  }
 62  
 63  #[derive(Debug, Serialize, Deserialize)]
 64  pub struct MarketGoodsData {
 65      pub items: Vec<MarketGoodsItem>,
 66      pub page_num: i32,
 67      pub page_size: i32,
 68      pub total_count: i32,
 69      pub total_page: i32,
 70  }
 71  
 72  #[derive(Debug, Serialize, Deserialize)]
 73  pub struct MarketGoodsItem {
 74      pub appid: i32,
 75      #[serde(rename = "id")] // Assuming 'id' is the goods_id for the item itself in this context
 76      pub goods_internal_id: i64, // Renamed to avoid conflict if used alongside other IDs. The example shows "id": 1092
 77      pub name: String,
 78      pub market_hash_name: String,
 79      pub sell_min_price: String, // Price in a string format, e.g., "605"
 80      pub steam_price: Option<String>,
 81      pub steam_price_cny: Option<String>,
 82      pub icon_url: String,
 83      pub original_icon_url: Option<String>,
 84      pub goods_info: Option<GoodsInfo>, // Detailed info, might need further refinement
 85      pub info: Option<ItemInfoContainer>, // Contains tags
 86      pub bookmarked: Option<bool>,
 87      pub buy_max_price: Option<String>,
 88      pub buy_num: Option<i32>,
 89      pub can_bargain: Option<bool>,
 90      pub sell_num: Option<i32>,
 91      pub steam_market_url: Option<String>,
 92      pub transacted_num: Option<i32>, // Or i64 if it can be large
 93      pub short_name: Option<String>,
 94      pub has_buff_price_history: Option<bool>,
 95      // Add other fields from the JSON as needed, marking them optional if they might be missing
 96      // e.g., auction_num, can_search_by_tournament, description, game, item_id, market_min_price etc.
 97  }
 98  
 99  #[derive(Debug, Serialize, Deserialize)]
100  pub struct GoodsInfo {
101      // Based on user example: goods_info: {,…}
102      // This suggests it might be a complex object. For now, let's assume it might contain various details.
103      // If its structure is consistent, define specific fields. Otherwise, serde_json::Value might be an option.
104      // Example fields that *might* be here based on typical market data:
105      pub icon_url: Option<String>,
106      pub original_icon_url: Option<String>,
107      pub steam_price: Option<String>,
108      pub steam_price_cny: Option<String>,
109      // Add other relevant fields if known
110  }
111  
112  #[derive(Debug, Serialize, Deserialize)]
113  pub struct ItemInfoContainer {
114      pub tags: Option<ItemTags>,
115  }
116  
117  #[derive(Debug, Serialize, Deserialize)]
118  pub struct ItemTags {
119      pub category: Option<TagDetails>,
120      pub exterior: Option<TagDetails>,
121      pub quality: Option<TagDetails>,
122      pub rarity: Option<TagDetails>,
123      #[serde(rename = "type")]
124      pub type_tag: Option<TagDetails>, // Renamed 'type' to 'type_tag' to avoid Rust keyword conflict
125  }
126  
127  #[derive(Debug, Serialize, Deserialize)]
128  pub struct TagDetails {
129      pub category: String,
130      pub id: i64, // Or String if it can be non-numeric
131      pub internal_name: String,
132      pub localized_name: String,
133  }