1use crate::controllers::{
2 products::{ProductModify, ProductModifyBuilder},
3 Entity,
4};
5
6use super::MetaData;
7use chrono::NaiveDateTime;
8use serde::{Deserialize, Serialize};
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct Product {
11 pub id: i32,
13 pub name: String,
15 pub slug: String,
17 pub permalink: String,
19 pub date_created: NaiveDateTime,
21 pub date_created_gmt: NaiveDateTime,
23 pub date_modified: NaiveDateTime,
25 pub date_modified_gmt: NaiveDateTime,
27 #[serde(rename = "type")]
29 pub product_type: ProductType,
30 pub status: ProductStatus,
32 pub featured: bool,
34 pub catalog_visibility: CatalogVisibility,
36 pub description: String,
38 pub short_description: String,
40 pub sku: String,
42 pub price: String,
44 pub regular_price: String,
46 pub sale_price: String,
48 pub date_on_sale_from: Option<NaiveDateTime>,
50 pub date_on_sale_from_gmt: Option<NaiveDateTime>,
52 pub date_on_sale_to: Option<NaiveDateTime>,
54 pub date_on_sale_to_gmt: Option<NaiveDateTime>,
56 pub price_html: String,
58 pub on_sale: bool,
60 pub purchasable: bool,
62 pub total_sales: i32,
64 #[serde(rename = "virtual")]
66 pub is_virtual: bool,
67 pub downloadable: bool,
69 pub downloads: Vec<Download>,
71 pub download_limit: i32,
73 pub download_expiry: i32,
75 pub external_url: String,
77 pub button_text: String,
79 pub tax_status: TaxStatus,
81 pub tax_class: String,
83 pub manage_stock: bool,
85 pub stock_quantity: Option<i32>,
87 pub stock_status: StockStatus,
89 pub backorders: BackordersStatus,
91 pub backorders_allowed: bool,
93 pub backordered: bool,
95 pub sold_individually: bool,
97 pub weight: String,
99 pub dimensions: Dimensions,
101 pub shipping_required: bool,
103 pub shipping_taxable: bool,
105 pub shipping_class: String,
107 pub shipping_class_id: i32,
109 pub reviews_allowed: bool,
111 pub average_rating: String,
113 pub rating_count: i32,
115 pub related_ids: Vec<i32>,
117 pub upsell_ids: Vec<i32>,
119 pub cross_sell_ids: Vec<i32>,
121 pub parent_id: i32,
123 pub purchase_note: String,
125 pub categories: Vec<ProductCategory>,
127 pub tags: Vec<ProductTag>,
129 pub images: Vec<ProductImage>,
131 pub attributes: Vec<ProductAttribute>,
133 pub default_attributes: Vec<ProductDefaultAttribute>,
135 pub variations: Vec<i32>,
137 pub grouped_products: Vec<i32>,
139 pub menu_order: i32,
141 pub meta_data: Vec<MetaData>,
143}
144impl Entity for Product {
145 fn endpoint() -> String {
146 String::from("products/")
147 }
148 fn child_endpoint(parent_id: i32) -> String {
149 let _ = parent_id;
150 String::new()
151 }
152}
153impl Product {
154 pub fn builder() -> ProductModifyBuilder {
155 ProductModify::builder()
156 }
157}
158#[derive(Debug, Clone, Serialize, Deserialize, Default)]
159#[serde(rename_all = "lowercase")]
160pub enum ProductType {
161 #[default]
162 Simple,
163 Grouped,
164 External,
165 Variable,
166}
167#[derive(Debug, Clone, Serialize, Deserialize, Default)]
168#[serde(rename_all = "lowercase")]
169pub enum ProductStatus {
170 Draft,
171 Pending,
172 Private,
173 #[default]
174 Publish,
175}
176#[derive(Debug, Clone, Serialize, Deserialize, Default)]
177#[serde(rename_all = "lowercase")]
178pub enum CatalogVisibility {
179 #[default]
180 Visible,
181 Catalog,
182 Search,
183 Hidden,
184}
185#[derive(Debug, Clone, Serialize, Deserialize, Default)]
186#[serde(rename_all = "lowercase")]
187pub enum TaxStatus {
188 #[default]
189 Taxable,
190 Shipping,
191 None,
192}
193#[derive(Debug, Clone, Serialize, Deserialize, Default)]
194#[serde(rename_all = "lowercase")]
195pub enum StockStatus {
196 #[default]
197 Instock,
198 Outofstock,
199 Onbackorder,
200}
201#[derive(Debug, Clone, Serialize, Deserialize, Default)]
202#[serde(rename_all = "lowercase")]
203pub enum BackordersStatus {
204 #[default]
205 No,
206 Notify,
207 Yes,
208}
209#[derive(Debug, Clone, Serialize, Deserialize)]
210pub struct Download {
211 pub id: String,
213 pub name: String,
215 pub file: String,
217}
218#[derive(Debug, Clone, Serialize, Deserialize)]
219pub struct Dimensions {
220 pub length: String,
222 pub width: String,
224 pub height: String,
226}
227#[derive(Debug, Clone, Serialize, Deserialize)]
228pub struct ProductCategory {
229 pub id: i32,
231 pub name: String,
233 pub slug: String,
235}
236#[derive(Debug, Clone, Serialize, Deserialize)]
237pub struct ProductTag {
238 pub id: i32,
240 pub name: String,
242 pub slug: String,
244}
245#[derive(Debug, Clone, Serialize, Deserialize)]
246pub struct ProductImage {
247 pub id: i32,
249 pub date_created: NaiveDateTime,
251 pub date_created_gmt: NaiveDateTime,
253 pub date_modified: NaiveDateTime,
255 pub date_modified_gmt: NaiveDateTime,
257 pub src: String,
259 pub name: String,
261 pub alt: String,
263}
264#[derive(Debug, Clone, Serialize, Deserialize)]
265pub struct ProductAttribute {
266 pub id: i32,
268 pub name: String,
270 pub position: i32,
272 pub visible: bool,
274 pub variation: bool,
276 pub options: Vec<String>,
278}
279#[derive(Debug, Clone, Serialize, Deserialize)]
280pub struct ProductDefaultAttribute {
281 pub id: i32,
283 pub name: String,
285 pub option: String,
287}