shopify-sdk 1.0.0

A Rust SDK for the Shopify API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
//! Variant resource implementation.
//!
//! This module provides the Variant resource, which represents a variant of a product
//! in a Shopify store. Variants are different versions of a product (e.g., size, color).
//!
//! # Dual Path Support
//!
//! The Variant resource supports both nested and standalone paths:
//! - Nested: `/products/{product_id}/variants/{id}` - when `product_id` is available
//! - Standalone: `/variants/{id}` - fallback when only variant id is available
//!
//! The path selection automatically chooses the most specific path based on available IDs.
//!
//! # Example
//!
//! ```rust,ignore
//! use shopify_sdk::rest::{RestResource, ResourceResponse};
//! use shopify_sdk::rest::resources::v2025_10::{Variant, VariantListParams, WeightUnit};
//!
//! // Find a variant by ID (standalone path)
//! let variant = Variant::find(&client, 123, None).await?;
//! println!("Variant: {}", variant.title.as_deref().unwrap_or(""));
//!
//! // List variants under a product (nested path)
//! let variants = Variant::all_with_parent(&client, "product_id", 456, None).await?;
//!
//! // Create a new variant under a product
//! let mut variant = Variant {
//!     product_id: Some(456),
//!     title: Some("Large / Blue".to_string()),
//!     price: Some("29.99".to_string()),
//!     sku: Some("PROD-LG-BL".to_string()),
//!     weight: Some(1.5),
//!     weight_unit: Some(WeightUnit::Kg),
//!     ..Default::default()
//! };
//! let saved = variant.save(&client).await?;
//! ```

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

use crate::rest::{ResourceOperation, ResourcePath, RestResource};
use crate::HttpMethod;

/// The unit of measurement for variant weight.
///
/// Used to specify whether the weight is in kilograms, grams, pounds, or ounces.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum WeightUnit {
    /// Kilograms
    #[default]
    Kg,
    /// Grams
    G,
    /// Pounds
    Lb,
    /// Ounces
    Oz,
}

/// A product variant in a Shopify store.
///
/// Variants represent different versions of a product, typically distinguished by
/// attributes like size, color, or material. Each variant can have its own price,
/// SKU, inventory, and weight settings.
///
/// # Dual Path Access
///
/// Variants can be accessed through two path patterns:
/// - Nested under a product: `/products/{product_id}/variants/{id}`
/// - Standalone: `/variants/{id}`
///
/// The nested path is preferred when `product_id` is available.
///
/// # Fields
///
/// ## Writable Fields
/// - `product_id` - The ID of the product this variant belongs to
/// - `title` - The title of the variant
/// - `price` - The price of the variant
/// - `compare_at_price` - The original price for comparison (sale pricing)
/// - `sku` - Stock keeping unit identifier
/// - `barcode` - The barcode, UPC, or ISBN number
/// - `position` - The position in the variant list
/// - `grams` - The weight in grams (deprecated, use `weight`/`weight_unit`)
/// - `weight` - The weight value
/// - `weight_unit` - The unit of measurement for weight
/// - `inventory_management` - The fulfillment service tracking inventory
/// - `inventory_policy` - Whether to allow purchases when out of stock
/// - `fulfillment_service` - The fulfillment service for this variant
/// - `option1`, `option2`, `option3` - Option values
/// - `image_id` - The ID of the associated image
/// - `taxable` - Whether the variant is taxable
/// - `tax_code` - The tax code for the variant
/// - `requires_shipping` - Whether the variant requires shipping
///
/// ## Read-Only Fields
/// - `id` - The unique identifier
/// - `inventory_item_id` - The ID of the associated inventory item
/// - `inventory_quantity` - The available quantity
/// - `created_at` - When the variant was created
/// - `updated_at` - When the variant was last updated
/// - `admin_graphql_api_id` - The GraphQL API ID
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct Variant {
    /// The unique identifier of the variant.
    /// Read-only field.
    #[serde(skip_serializing)]
    pub id: Option<u64>,

    /// The ID of the product this variant belongs to.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub product_id: Option<u64>,

    /// The title of the variant.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,

    /// The price of the variant.
    /// Stored as a string to preserve decimal precision.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub price: Option<String>,

    /// The original price of the variant for comparison.
    /// Used to show sale pricing.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub compare_at_price: Option<String>,

    /// The stock keeping unit (SKU) of the variant.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sku: Option<String>,

    /// The barcode, UPC, or ISBN number of the variant.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub barcode: Option<String>,

    /// The position of the variant in the product's variant list.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub position: Option<i64>,

    /// The weight of the variant in grams.
    /// Deprecated: Use `weight` and `weight_unit` instead.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub grams: Option<i64>,

    /// The weight of the variant.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub weight: Option<f64>,

    /// The unit of measurement for the variant's weight.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub weight_unit: Option<WeightUnit>,

    /// The ID of the inventory item associated with this variant.
    /// Read-only field.
    #[serde(skip_serializing)]
    pub inventory_item_id: Option<u64>,

    /// The available quantity of the variant.
    /// Read-only field - use Inventory API to modify.
    #[serde(skip_serializing)]
    pub inventory_quantity: Option<i64>,

    /// The fulfillment service that tracks inventory for this variant.
    /// Valid values: "shopify" or the handle of a fulfillment service.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inventory_management: Option<String>,

    /// Whether customers can purchase the variant when it's out of stock.
    /// Valid values: "deny" or "continue".
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inventory_policy: Option<String>,

    /// The fulfillment service for this variant.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub fulfillment_service: Option<String>,

    /// The value of the first option.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub option1: Option<String>,

    /// The value of the second option.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub option2: Option<String>,

    /// The value of the third option.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub option3: Option<String>,

    /// The ID of the image associated with this variant.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub image_id: Option<u64>,

    /// Whether the variant is taxable.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub taxable: Option<bool>,

    /// The tax code for the variant (Shopify Plus feature).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tax_code: Option<String>,

    /// Whether the variant requires shipping.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub requires_shipping: Option<bool>,

    /// When the variant was created.
    /// Read-only field.
    #[serde(skip_serializing)]
    pub created_at: Option<DateTime<Utc>>,

    /// When the variant was last updated.
    /// Read-only field.
    #[serde(skip_serializing)]
    pub updated_at: Option<DateTime<Utc>>,

    /// The admin GraphQL API ID for this variant.
    /// Read-only field.
    #[serde(skip_serializing)]
    pub admin_graphql_api_id: Option<String>,
}

impl RestResource for Variant {
    type Id = u64;
    type FindParams = VariantFindParams;
    type AllParams = VariantListParams;
    type CountParams = VariantCountParams;

    const NAME: &'static str = "Variant";
    const PLURAL: &'static str = "variants";

    /// Paths for the Variant resource.
    ///
    /// The Variant resource supports DUAL PATHS:
    /// 1. Nested paths under products (more specific, preferred when `product_id` available)
    /// 2. Standalone paths (fallback when only variant id available)
    ///
    /// Path selection chooses the most specific path based on available IDs.
    const PATHS: &'static [ResourcePath] = &[
        // Nested paths (more specific - preferred when product_id is available)
        ResourcePath::new(
            HttpMethod::Get,
            ResourceOperation::Find,
            &["product_id", "id"],
            "products/{product_id}/variants/{id}",
        ),
        ResourcePath::new(
            HttpMethod::Get,
            ResourceOperation::All,
            &["product_id"],
            "products/{product_id}/variants",
        ),
        ResourcePath::new(
            HttpMethod::Get,
            ResourceOperation::Count,
            &["product_id"],
            "products/{product_id}/variants/count",
        ),
        ResourcePath::new(
            HttpMethod::Post,
            ResourceOperation::Create,
            &["product_id"],
            "products/{product_id}/variants",
        ),
        ResourcePath::new(
            HttpMethod::Put,
            ResourceOperation::Update,
            &["product_id", "id"],
            "products/{product_id}/variants/{id}",
        ),
        ResourcePath::new(
            HttpMethod::Delete,
            ResourceOperation::Delete,
            &["product_id", "id"],
            "products/{product_id}/variants/{id}",
        ),
        // Standalone paths (fallback - used when only variant id is available)
        ResourcePath::new(
            HttpMethod::Get,
            ResourceOperation::Find,
            &["id"],
            "variants/{id}",
        ),
        ResourcePath::new(
            HttpMethod::Put,
            ResourceOperation::Update,
            &["id"],
            "variants/{id}",
        ),
    ];

    fn get_id(&self) -> Option<Self::Id> {
        self.id
    }
}

/// Parameters for finding a single variant.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct VariantFindParams {
    /// Comma-separated list of fields to include in the response.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub fields: Option<String>,
}

/// Parameters for listing variants.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct VariantListParams {
    /// Maximum number of results to return (default: 50, max: 250).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,

    /// Return variants after this ID.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub since_id: Option<u64>,

    /// Comma-separated list of fields to include in the response.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub fields: Option<String>,

    /// Cursor for pagination.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_info: Option<String>,
}

/// Parameters for counting variants.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct VariantCountParams {
    // No specific count params for variants beyond the product_id in the path
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::rest::{get_path, ResourceOperation};

    #[test]
    fn test_variant_struct_serialization() {
        let variant = Variant {
            id: Some(12345),         // Read-only, should be skipped
            product_id: Some(67890), // Writable
            title: Some("Large / Blue".to_string()),
            price: Some("29.99".to_string()),
            compare_at_price: Some("39.99".to_string()),
            sku: Some("PROD-LG-BL".to_string()),
            barcode: Some("1234567890123".to_string()),
            position: Some(2),
            grams: Some(500),
            weight: Some(0.5),
            weight_unit: Some(WeightUnit::Kg),
            inventory_item_id: Some(111222), // Read-only
            inventory_quantity: Some(100),   // Read-only
            inventory_management: Some("shopify".to_string()),
            inventory_policy: Some("deny".to_string()),
            fulfillment_service: Some("manual".to_string()),
            option1: Some("Large".to_string()),
            option2: Some("Blue".to_string()),
            option3: None,
            image_id: Some(999888),
            taxable: Some(true),
            tax_code: None,
            requires_shipping: Some(true),
            created_at: Some(
                DateTime::parse_from_rfc3339("2024-01-15T10:30:00Z")
                    .unwrap()
                    .with_timezone(&Utc),
            ), // Read-only
            updated_at: Some(
                DateTime::parse_from_rfc3339("2024-06-20T15:45:00Z")
                    .unwrap()
                    .with_timezone(&Utc),
            ), // Read-only
            admin_graphql_api_id: Some("gid://shopify/ProductVariant/12345".to_string()), // Read-only
        };

        let json = serde_json::to_string(&variant).unwrap();
        let parsed: serde_json::Value = serde_json::from_str(&json).unwrap();

        // Writable fields should be present
        assert_eq!(parsed["product_id"], 67890);
        assert_eq!(parsed["title"], "Large / Blue");
        assert_eq!(parsed["price"], "29.99");
        assert_eq!(parsed["compare_at_price"], "39.99");
        assert_eq!(parsed["sku"], "PROD-LG-BL");
        assert_eq!(parsed["barcode"], "1234567890123");
        assert_eq!(parsed["position"], 2);
        assert_eq!(parsed["grams"], 500);
        assert_eq!(parsed["weight"], 0.5);
        assert_eq!(parsed["weight_unit"], "kg");
        assert_eq!(parsed["inventory_management"], "shopify");
        assert_eq!(parsed["inventory_policy"], "deny");
        assert_eq!(parsed["fulfillment_service"], "manual");
        assert_eq!(parsed["option1"], "Large");
        assert_eq!(parsed["option2"], "Blue");
        assert_eq!(parsed["image_id"], 999888);
        assert_eq!(parsed["taxable"], true);
        assert_eq!(parsed["requires_shipping"], true);

        // Read-only fields should be omitted
        assert!(parsed.get("id").is_none());
        assert!(parsed.get("inventory_item_id").is_none());
        assert!(parsed.get("inventory_quantity").is_none());
        assert!(parsed.get("created_at").is_none());
        assert!(parsed.get("updated_at").is_none());
        assert!(parsed.get("admin_graphql_api_id").is_none());

        // Optional fields that are None should be omitted
        assert!(parsed.get("option3").is_none());
        assert!(parsed.get("tax_code").is_none());
    }

    #[test]
    fn test_variant_deserialization_from_api_response() {
        let json = r#"{
            "id": 39072856,
            "product_id": 788032119674292922,
            "title": "Large / Blue",
            "price": "29.99",
            "compare_at_price": "39.99",
            "sku": "PROD-LG-BL",
            "barcode": "1234567890123",
            "position": 2,
            "grams": 500,
            "weight": 0.5,
            "weight_unit": "kg",
            "inventory_item_id": 111222333,
            "inventory_quantity": 100,
            "inventory_management": "shopify",
            "inventory_policy": "deny",
            "fulfillment_service": "manual",
            "option1": "Large",
            "option2": "Blue",
            "option3": null,
            "image_id": 999888777,
            "taxable": true,
            "tax_code": null,
            "requires_shipping": true,
            "created_at": "2024-01-15T10:30:00Z",
            "updated_at": "2024-06-20T15:45:00Z",
            "admin_graphql_api_id": "gid://shopify/ProductVariant/39072856"
        }"#;

        let variant: Variant = serde_json::from_str(json).unwrap();

        // Verify all fields are deserialized correctly
        assert_eq!(variant.id, Some(39072856));
        assert_eq!(variant.product_id, Some(788032119674292922));
        assert_eq!(variant.title, Some("Large / Blue".to_string()));
        assert_eq!(variant.price, Some("29.99".to_string()));
        assert_eq!(variant.compare_at_price, Some("39.99".to_string()));
        assert_eq!(variant.sku, Some("PROD-LG-BL".to_string()));
        assert_eq!(variant.barcode, Some("1234567890123".to_string()));
        assert_eq!(variant.position, Some(2));
        assert_eq!(variant.grams, Some(500));
        assert_eq!(variant.weight, Some(0.5));
        assert_eq!(variant.weight_unit, Some(WeightUnit::Kg));
        assert_eq!(variant.inventory_item_id, Some(111222333));
        assert_eq!(variant.inventory_quantity, Some(100));
        assert_eq!(variant.inventory_management, Some("shopify".to_string()));
        assert_eq!(variant.inventory_policy, Some("deny".to_string()));
        assert_eq!(variant.fulfillment_service, Some("manual".to_string()));
        assert_eq!(variant.option1, Some("Large".to_string()));
        assert_eq!(variant.option2, Some("Blue".to_string()));
        assert_eq!(variant.option3, None);
        assert_eq!(variant.image_id, Some(999888777));
        assert_eq!(variant.taxable, Some(true));
        assert_eq!(variant.tax_code, None);
        assert_eq!(variant.requires_shipping, Some(true));
        assert!(variant.created_at.is_some());
        assert!(variant.updated_at.is_some());
        assert_eq!(
            variant.admin_graphql_api_id,
            Some("gid://shopify/ProductVariant/39072856".to_string())
        );
    }

    #[test]
    fn test_dual_path_patterns() {
        // Test nested path (with both product_id and id) - most specific for Find
        let nested_find_path = get_path(
            Variant::PATHS,
            ResourceOperation::Find,
            &["product_id", "id"],
        );
        assert!(nested_find_path.is_some());
        assert_eq!(
            nested_find_path.unwrap().template,
            "products/{product_id}/variants/{id}"
        );

        // Test standalone path (with only id) - fallback for Find
        let standalone_find_path = get_path(Variant::PATHS, ResourceOperation::Find, &["id"]);
        assert!(standalone_find_path.is_some());
        assert_eq!(standalone_find_path.unwrap().template, "variants/{id}");

        // Test nested All path (requires product_id)
        let nested_all_path = get_path(Variant::PATHS, ResourceOperation::All, &["product_id"]);
        assert!(nested_all_path.is_some());
        assert_eq!(
            nested_all_path.unwrap().template,
            "products/{product_id}/variants"
        );

        // Test that All without product_id fails (no standalone All path)
        let standalone_all_path = get_path(Variant::PATHS, ResourceOperation::All, &[]);
        assert!(standalone_all_path.is_none());

        // Test nested Update path (with both product_id and id)
        let nested_update_path = get_path(
            Variant::PATHS,
            ResourceOperation::Update,
            &["product_id", "id"],
        );
        assert!(nested_update_path.is_some());
        assert_eq!(
            nested_update_path.unwrap().template,
            "products/{product_id}/variants/{id}"
        );

        // Test standalone Update path (with only id)
        let standalone_update_path = get_path(Variant::PATHS, ResourceOperation::Update, &["id"]);
        assert!(standalone_update_path.is_some());
        assert_eq!(standalone_update_path.unwrap().template, "variants/{id}");

        // Test Create path (requires product_id)
        let create_path = get_path(Variant::PATHS, ResourceOperation::Create, &["product_id"]);
        assert!(create_path.is_some());
        assert_eq!(
            create_path.unwrap().template,
            "products/{product_id}/variants"
        );

        // Test Delete path (requires both product_id and id)
        let delete_path = get_path(
            Variant::PATHS,
            ResourceOperation::Delete,
            &["product_id", "id"],
        );
        assert!(delete_path.is_some());
        assert_eq!(
            delete_path.unwrap().template,
            "products/{product_id}/variants/{id}"
        );

        // Test Count path (requires product_id)
        let count_path = get_path(Variant::PATHS, ResourceOperation::Count, &["product_id"]);
        assert!(count_path.is_some());
        assert_eq!(
            count_path.unwrap().template,
            "products/{product_id}/variants/count"
        );

        // Verify constants
        assert_eq!(Variant::NAME, "Variant");
        assert_eq!(Variant::PLURAL, "variants");
    }

    #[test]
    fn test_weight_unit_enum_serialization() {
        // Test serialization to lowercase
        assert_eq!(serde_json::to_string(&WeightUnit::Kg).unwrap(), "\"kg\"");
        assert_eq!(serde_json::to_string(&WeightUnit::G).unwrap(), "\"g\"");
        assert_eq!(serde_json::to_string(&WeightUnit::Lb).unwrap(), "\"lb\"");
        assert_eq!(serde_json::to_string(&WeightUnit::Oz).unwrap(), "\"oz\"");

        // Test deserialization from lowercase
        let kg: WeightUnit = serde_json::from_str("\"kg\"").unwrap();
        let g: WeightUnit = serde_json::from_str("\"g\"").unwrap();
        let lb: WeightUnit = serde_json::from_str("\"lb\"").unwrap();
        let oz: WeightUnit = serde_json::from_str("\"oz\"").unwrap();

        assert_eq!(kg, WeightUnit::Kg);
        assert_eq!(g, WeightUnit::G);
        assert_eq!(lb, WeightUnit::Lb);
        assert_eq!(oz, WeightUnit::Oz);

        // Test default value
        assert_eq!(WeightUnit::default(), WeightUnit::Kg);
    }

    #[test]
    fn test_variant_list_params_serialization() {
        let params = VariantListParams {
            limit: Some(50),
            since_id: Some(12345),
            fields: Some("id,title,price,sku".to_string()),
            page_info: Some("eyJsYXN0X2lkIjoxMjM0NTY3ODkwfQ".to_string()),
        };

        let json = serde_json::to_value(&params).unwrap();

        assert_eq!(json["limit"], 50);
        assert_eq!(json["since_id"], 12345);
        assert_eq!(json["fields"], "id,title,price,sku");
        assert_eq!(json["page_info"], "eyJsYXN0X2lkIjoxMjM0NTY3ODkwfQ");

        // Test with minimal params (all None)
        let empty_params = VariantListParams::default();
        let empty_json = serde_json::to_value(&empty_params).unwrap();

        // Empty object when all fields are None
        assert_eq!(empty_json, serde_json::json!({}));
    }

    #[test]
    fn test_variant_get_id_returns_correct_value() {
        // Variant with ID
        let variant_with_id = Variant {
            id: Some(123456789),
            product_id: Some(987654321),
            title: Some("Test Variant".to_string()),
            ..Default::default()
        };
        assert_eq!(variant_with_id.get_id(), Some(123456789));

        // Variant without ID (new variant)
        let variant_without_id = Variant {
            id: None,
            product_id: Some(987654321),
            title: Some("New Variant".to_string()),
            ..Default::default()
        };
        assert_eq!(variant_without_id.get_id(), None);
    }
}