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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
//! Article resource implementation.
//!
//! This module provides the Article resource, which represents a blog article
//! in a Shopify store. Articles are nested under blogs and follow the same
//! nested path pattern as Variants under Products.
//!
//! # Nested Path Pattern
//!
//! Articles are always accessed under a blog:
//! - List: `/blogs/{blog_id}/articles`
//! - Find: `/blogs/{blog_id}/articles/{id}`
//! - Create: `/blogs/{blog_id}/articles`
//! - Update: `/blogs/{blog_id}/articles/{id}`
//! - Delete: `/blogs/{blog_id}/articles/{id}`
//! - Count: `/blogs/{blog_id}/articles/count`
//!
//! Use `Article::all_with_parent()` to list articles under a specific blog.
//!
//! # Example
//!
//! ```rust,ignore
//! use shopify_sdk::rest::{RestResource, ResourceResponse};
//! use shopify_sdk::rest::resources::v2025_10::{Article, ArticleListParams};
//!
//! // List articles under a specific blog
//! let articles = Article::all_with_parent(&client, "blog_id", 123, None).await?;
//! for article in articles.iter() {
//!     println!("Article: {}", article.title.as_deref().unwrap_or(""));
//! }
//!
//! // Create a new article under a blog
//! let mut article = Article {
//!     blog_id: Some(123),
//!     title: Some("New Post".to_string()),
//!     body_html: Some("<p>Article content</p>".to_string()),
//!     author: Some("Admin".to_string()),
//!     ..Default::default()
//! };
//! let saved = article.save(&client).await?;
//!
//! // Count articles in a blog
//! let count = Article::count_with_parent(&client, "blog_id", 123, None).await?;
//! println!("Total articles: {}", count);
//! ```

use std::collections::HashMap;

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

use crate::clients::RestClient;
use crate::rest::{
    build_path, get_path, ResourceError, ResourceOperation, ResourcePath, RestResource,
};
use crate::HttpMethod;

/// An image associated with an article.
///
/// Similar to `CollectionImage`, this represents the featured image
/// for a blog article.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct ArticleImage {
    /// The source URL of the article image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub src: Option<String>,

    /// Alternative text for the image (for accessibility).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alt: Option<String>,

    /// The width of the image in pixels.
    #[serde(skip_serializing)]
    pub width: Option<i64>,

    /// The height of the image in pixels.
    #[serde(skip_serializing)]
    pub height: Option<i64>,

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

/// A blog article in a Shopify store.
///
/// Articles are blog posts that belong to a specific blog. They are
/// nested resources that require a `blog_id` for all operations.
///
/// # Nested Resource
///
/// Articles follow the same nested path pattern as Variants:
/// - All operations require `blog_id` context
/// - Use `all_with_parent()` to list articles under a blog
/// - The `blog_id` field is required for creating new articles
///
/// # Fields
///
/// ## Read-Only Fields
/// - `id` - The unique identifier of the article
/// - `blog_id` - The ID of the blog this article belongs to (also required for creation)
/// - `user_id` - The ID of the user who authored the article
/// - `created_at` - When the article was created
/// - `updated_at` - When the article was last updated
/// - `admin_graphql_api_id` - The GraphQL API ID
///
/// ## Writable Fields
/// - `title` - The title of the article
/// - `handle` - The URL-friendly handle (auto-generated from title if not set)
/// - `body_html` - The HTML content of the article
/// - `author` - The author name displayed on the article
/// - `summary_html` - The summary/excerpt of the article
/// - `template_suffix` - The suffix of the Liquid template used for the article
/// - `tags` - Comma-separated tags for the article
/// - `image` - The featured image for the article
/// - `published_at` - When the article was published (can be set to future for scheduling)
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct Article {
    /// The unique identifier of the article.
    /// Read-only field.
    #[serde(skip_serializing)]
    pub id: Option<u64>,

    /// The ID of the blog this article belongs to.
    /// Required for creating new articles.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub blog_id: Option<u64>,

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

    /// The URL-friendly handle of the article.
    /// Auto-generated from the title if not specified.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub handle: Option<String>,

    /// The HTML content of the article.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub body_html: Option<String>,

    /// The author name displayed on the article.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub author: Option<String>,

    /// The summary/excerpt of the article in HTML.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub summary_html: Option<String>,

    /// The suffix of the Liquid template used for the article.
    /// For example, if the value is "custom", the article uses the
    /// `article.custom.liquid` template.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub template_suffix: Option<String>,

    /// Comma-separated tags for the article.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<String>,

    /// The featured image for the article.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub image: Option<ArticleImage>,

    /// When the article was or will be published.
    /// Set to a future date to schedule publication.
    /// Set to `null` to unpublish.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub published_at: Option<DateTime<Utc>>,

    /// The ID of the user who authored the article.
    /// Read-only field.
    #[serde(skip_serializing)]
    pub user_id: Option<u64>,

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

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

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

impl Article {
    /// Counts articles under a specific blog.
    ///
    /// # Arguments
    ///
    /// * `client` - The REST client to use for the request
    /// * `parent_id_name` - The name of the parent ID parameter (should be `blog_id`)
    /// * `parent_id` - The blog ID
    /// * `params` - Optional parameters for filtering
    ///
    /// # Returns
    ///
    /// The count of matching articles as a `u64`.
    ///
    /// # Errors
    ///
    /// Returns [`ResourceError::PathResolutionFailed`] if no count path exists.
    ///
    /// # Example
    ///
    /// ```rust,ignore
    /// let count = Article::count_with_parent(&client, "blog_id", 123, None).await?;
    /// println!("Articles in blog: {}", count);
    /// ```
    pub async fn count_with_parent<ParentId: std::fmt::Display + Send>(
        client: &RestClient,
        parent_id_name: &str,
        parent_id: ParentId,
        params: Option<ArticleCountParams>,
    ) -> Result<u64, ResourceError> {
        let mut ids: HashMap<&str, String> = HashMap::new();
        ids.insert(parent_id_name, parent_id.to_string());

        let available_ids: Vec<&str> = ids.keys().copied().collect();
        let path = get_path(Self::PATHS, ResourceOperation::Count, &available_ids).ok_or(
            ResourceError::PathResolutionFailed {
                resource: Self::NAME,
                operation: "count",
            },
        )?;

        let url = build_path(path.template, &ids);

        // Build query params
        let query = params
            .map(|p| {
                let value = serde_json::to_value(&p).map_err(|e| {
                    ResourceError::Http(crate::clients::HttpError::Response(
                        crate::clients::HttpResponseError {
                            code: 400,
                            message: format!("Failed to serialize params: {e}"),
                            error_reference: None,
                        },
                    ))
                })?;

                let mut query = HashMap::new();
                if let serde_json::Value::Object(map) = value {
                    for (key, val) in map {
                        match val {
                            serde_json::Value::String(s) => {
                                query.insert(key, s);
                            }
                            serde_json::Value::Number(n) => {
                                query.insert(key, n.to_string());
                            }
                            serde_json::Value::Bool(b) => {
                                query.insert(key, b.to_string());
                            }
                            // Skip null, arrays, and objects
                            _ => {}
                        }
                    }
                }
                Ok::<_, ResourceError>(query)
            })
            .transpose()?
            .filter(|q| !q.is_empty());

        let response = client.get(&url, query).await?;

        if !response.is_ok() {
            return Err(ResourceError::from_http_response(
                response.code,
                &response.body,
                Self::NAME,
                None,
                response.request_id(),
            ));
        }

        // Extract count from response
        let count = response
            .body
            .get("count")
            .and_then(serde_json::Value::as_u64)
            .ok_or_else(|| {
                ResourceError::Http(crate::clients::HttpError::Response(
                    crate::clients::HttpResponseError {
                        code: response.code,
                        message: "Missing 'count' in response".to_string(),
                        error_reference: response.request_id().map(ToString::to_string),
                    },
                ))
            })?;

        Ok(count)
    }
}

impl RestResource for Article {
    type Id = u64;
    type FindParams = ArticleFindParams;
    type AllParams = ArticleListParams;
    type CountParams = ArticleCountParams;

    const NAME: &'static str = "Article";
    const PLURAL: &'static str = "articles";

    /// Paths for the Article resource.
    ///
    /// Articles are NESTED under blogs. All operations require `blog_id`.
    /// This follows the same pattern as Variants nested under Products.
    const PATHS: &'static [ResourcePath] = &[
        // All paths require blog_id
        ResourcePath::new(
            HttpMethod::Get,
            ResourceOperation::Find,
            &["blog_id", "id"],
            "blogs/{blog_id}/articles/{id}",
        ),
        ResourcePath::new(
            HttpMethod::Get,
            ResourceOperation::All,
            &["blog_id"],
            "blogs/{blog_id}/articles",
        ),
        ResourcePath::new(
            HttpMethod::Get,
            ResourceOperation::Count,
            &["blog_id"],
            "blogs/{blog_id}/articles/count",
        ),
        ResourcePath::new(
            HttpMethod::Post,
            ResourceOperation::Create,
            &["blog_id"],
            "blogs/{blog_id}/articles",
        ),
        ResourcePath::new(
            HttpMethod::Put,
            ResourceOperation::Update,
            &["blog_id", "id"],
            "blogs/{blog_id}/articles/{id}",
        ),
        ResourcePath::new(
            HttpMethod::Delete,
            ResourceOperation::Delete,
            &["blog_id", "id"],
            "blogs/{blog_id}/articles/{id}",
        ),
    ];

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

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

/// Parameters for listing articles.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct ArticleListParams {
    /// Filter by article author.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub author: Option<String>,

    /// Filter by article handle.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub handle: Option<String>,

    /// Filter by tag.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,

    /// Filter by published status.
    /// Valid values: `published`, `unpublished`, `any`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub published_status: Option<String>,

    /// Show articles created after this date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at_min: Option<DateTime<Utc>>,

    /// Show articles created before this date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at_max: Option<DateTime<Utc>>,

    /// Show articles updated after this date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at_min: Option<DateTime<Utc>>,

    /// Show articles updated before this date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at_max: Option<DateTime<Utc>>,

    /// Show articles published after this date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub published_at_min: Option<DateTime<Utc>>,

    /// Show articles published before this date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub published_at_max: Option<DateTime<Utc>>,

    /// Maximum number of results to return (default: 50, max: 250).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,

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

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

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

/// Parameters for counting articles.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct ArticleCountParams {
    /// Filter by article author.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub author: Option<String>,

    /// Filter by tag.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<String>,

    /// Filter by published status.
    /// Valid values: `published`, `unpublished`, `any`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub published_status: Option<String>,

    /// Show articles created after this date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at_min: Option<DateTime<Utc>>,

    /// Show articles created before this date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at_max: Option<DateTime<Utc>>,

    /// Show articles updated after this date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at_min: Option<DateTime<Utc>>,

    /// Show articles updated before this date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at_max: Option<DateTime<Utc>>,

    /// Show articles published after this date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub published_at_min: Option<DateTime<Utc>>,

    /// Show articles published before this date.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub published_at_max: Option<DateTime<Utc>>,
}

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

    #[test]
    fn test_article_struct_serialization() {
        let article = Article {
            id: Some(12345),
            blog_id: Some(67890),
            title: Some("New Blog Post".to_string()),
            handle: Some("new-blog-post".to_string()),
            body_html: Some("<p>This is the article content.</p>".to_string()),
            author: Some("Jane Doe".to_string()),
            summary_html: Some("<p>Article summary.</p>".to_string()),
            template_suffix: Some("custom".to_string()),
            tags: Some("tech, rust, web".to_string()),
            image: Some(ArticleImage {
                src: Some("https://cdn.shopify.com/article.jpg".to_string()),
                alt: Some("Article image".to_string()),
                width: Some(1200),
                height: Some(800),
                created_at: None,
            }),
            published_at: Some(
                DateTime::parse_from_rfc3339("2024-01-15T10:30:00Z")
                    .unwrap()
                    .with_timezone(&Utc),
            ),
            user_id: Some(111222),
            created_at: Some(
                DateTime::parse_from_rfc3339("2024-01-10T08:00:00Z")
                    .unwrap()
                    .with_timezone(&Utc),
            ),
            updated_at: Some(
                DateTime::parse_from_rfc3339("2024-06-20T15:45:00Z")
                    .unwrap()
                    .with_timezone(&Utc),
            ),
            admin_graphql_api_id: Some("gid://shopify/OnlineStoreArticle/12345".to_string()),
        };

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

        // Writable fields should be present
        assert_eq!(parsed["blog_id"], 67890);
        assert_eq!(parsed["title"], "New Blog Post");
        assert_eq!(parsed["handle"], "new-blog-post");
        assert_eq!(parsed["body_html"], "<p>This is the article content.</p>");
        assert_eq!(parsed["author"], "Jane Doe");
        assert_eq!(parsed["summary_html"], "<p>Article summary.</p>");
        assert_eq!(parsed["template_suffix"], "custom");
        assert_eq!(parsed["tags"], "tech, rust, web");
        assert!(parsed["published_at"].as_str().is_some());
        assert_eq!(
            parsed["image"]["src"],
            "https://cdn.shopify.com/article.jpg"
        );
        assert_eq!(parsed["image"]["alt"], "Article image");

        // Read-only fields should be omitted
        assert!(parsed.get("id").is_none());
        assert!(parsed.get("user_id").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());

        // Image read-only fields should be omitted
        assert!(parsed["image"].get("width").is_none());
        assert!(parsed["image"].get("height").is_none());
    }

    #[test]
    fn test_article_deserialization_from_api_response() {
        let json = r#"{
            "id": 134645308,
            "blog_id": 241253187,
            "title": "My new blog post",
            "handle": "my-new-blog-post",
            "body_html": "<p>This is the content of the article.</p>",
            "author": "John Smith",
            "summary_html": "<p>Summary here.</p>",
            "template_suffix": null,
            "tags": "tech, news",
            "image": {
                "src": "https://cdn.shopify.com/s/files/1/article.jpg",
                "alt": "Blog image",
                "width": 1200,
                "height": 800,
                "created_at": "2024-01-15T10:30:00Z"
            },
            "published_at": "2024-01-15T10:30:00Z",
            "user_id": 799407056,
            "created_at": "2024-01-10T08:00:00Z",
            "updated_at": "2024-06-20T15:45:00Z",
            "admin_graphql_api_id": "gid://shopify/OnlineStoreArticle/134645308"
        }"#;

        let article: Article = serde_json::from_str(json).unwrap();

        assert_eq!(article.id, Some(134645308));
        assert_eq!(article.blog_id, Some(241253187));
        assert_eq!(article.title, Some("My new blog post".to_string()));
        assert_eq!(article.handle, Some("my-new-blog-post".to_string()));
        assert_eq!(
            article.body_html,
            Some("<p>This is the content of the article.</p>".to_string())
        );
        assert_eq!(article.author, Some("John Smith".to_string()));
        assert_eq!(
            article.summary_html,
            Some("<p>Summary here.</p>".to_string())
        );
        assert!(article.template_suffix.is_none());
        assert_eq!(article.tags, Some("tech, news".to_string()));
        assert!(article.image.is_some());
        let image = article.image.unwrap();
        assert_eq!(
            image.src,
            Some("https://cdn.shopify.com/s/files/1/article.jpg".to_string())
        );
        assert_eq!(image.alt, Some("Blog image".to_string()));
        assert_eq!(image.width, Some(1200));
        assert_eq!(image.height, Some(800));
        assert!(image.created_at.is_some());
        assert!(article.published_at.is_some());
        assert_eq!(article.user_id, Some(799407056));
        assert!(article.created_at.is_some());
        assert!(article.updated_at.is_some());
        assert_eq!(
            article.admin_graphql_api_id,
            Some("gid://shopify/OnlineStoreArticle/134645308".to_string())
        );
    }

    #[test]
    fn test_article_nested_paths_require_blog_id() {
        // All paths should require blog_id (nested under blogs)

        // Find requires both blog_id and id
        let find_path = get_path(Article::PATHS, ResourceOperation::Find, &["blog_id", "id"]);
        assert!(find_path.is_some());
        assert_eq!(find_path.unwrap().template, "blogs/{blog_id}/articles/{id}");

        // Find with only id should fail (no standalone path)
        let find_without_blog = get_path(Article::PATHS, ResourceOperation::Find, &["id"]);
        assert!(find_without_blog.is_none());

        // All requires blog_id
        let all_path = get_path(Article::PATHS, ResourceOperation::All, &["blog_id"]);
        assert!(all_path.is_some());
        assert_eq!(all_path.unwrap().template, "blogs/{blog_id}/articles");

        // All without blog_id should fail
        let all_without_blog = get_path(Article::PATHS, ResourceOperation::All, &[]);
        assert!(all_without_blog.is_none());

        // Count requires blog_id
        let count_path = get_path(Article::PATHS, ResourceOperation::Count, &["blog_id"]);
        assert!(count_path.is_some());
        assert_eq!(
            count_path.unwrap().template,
            "blogs/{blog_id}/articles/count"
        );

        // Create requires blog_id
        let create_path = get_path(Article::PATHS, ResourceOperation::Create, &["blog_id"]);
        assert!(create_path.is_some());
        assert_eq!(create_path.unwrap().template, "blogs/{blog_id}/articles");

        // Update requires both blog_id and id
        let update_path = get_path(
            Article::PATHS,
            ResourceOperation::Update,
            &["blog_id", "id"],
        );
        assert!(update_path.is_some());
        assert_eq!(
            update_path.unwrap().template,
            "blogs/{blog_id}/articles/{id}"
        );

        // Delete requires both blog_id and id
        let delete_path = get_path(
            Article::PATHS,
            ResourceOperation::Delete,
            &["blog_id", "id"],
        );
        assert!(delete_path.is_some());
        assert_eq!(
            delete_path.unwrap().template,
            "blogs/{blog_id}/articles/{id}"
        );
    }

    #[test]
    fn test_article_list_params_serialization() {
        let params = ArticleListParams {
            author: Some("Jane Doe".to_string()),
            handle: Some("my-post".to_string()),
            tag: Some("tech".to_string()),
            published_status: Some("published".to_string()),
            limit: Some(50),
            since_id: Some(100),
            ..Default::default()
        };

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

        assert_eq!(json["author"], "Jane Doe");
        assert_eq!(json["handle"], "my-post");
        assert_eq!(json["tag"], "tech");
        assert_eq!(json["published_status"], "published");
        assert_eq!(json["limit"], 50);
        assert_eq!(json["since_id"], 100);

        // Fields not set should be omitted
        assert!(json.get("created_at_min").is_none());
        assert!(json.get("page_info").is_none());
    }

    #[test]
    fn test_article_count_params_serialization() {
        let params = ArticleCountParams {
            author: Some("Jane Doe".to_string()),
            tag: Some("tech".to_string()),
            published_status: Some("any".to_string()),
            ..Default::default()
        };

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

        assert_eq!(json["author"], "Jane Doe");
        assert_eq!(json["tag"], "tech");
        assert_eq!(json["published_status"], "any");

        // Test empty params
        let empty_params = ArticleCountParams::default();
        let empty_json = serde_json::to_value(&empty_params).unwrap();
        assert_eq!(empty_json, serde_json::json!({}));
    }

    #[test]
    fn test_article_tags_field_handling() {
        // Tags as comma-separated string
        let article = Article {
            title: Some("Tech Article".to_string()),
            tags: Some("rust, programming, web, api".to_string()),
            ..Default::default()
        };

        let json = serde_json::to_value(&article).unwrap();
        assert_eq!(json["tags"], "rust, programming, web, api");

        // Deserialize tags back
        let deserialized: Article = serde_json::from_value(json).unwrap();
        assert_eq!(
            deserialized.tags,
            Some("rust, programming, web, api".to_string())
        );
    }

    #[test]
    fn test_article_get_id_returns_correct_value() {
        // Article with ID
        let article_with_id = Article {
            id: Some(123456789),
            blog_id: Some(987654321),
            title: Some("Test Article".to_string()),
            ..Default::default()
        };
        assert_eq!(article_with_id.get_id(), Some(123456789));

        // Article without ID (new article)
        let article_without_id = Article {
            id: None,
            blog_id: Some(987654321),
            title: Some("New Article".to_string()),
            ..Default::default()
        };
        assert_eq!(article_without_id.get_id(), None);
    }

    #[test]
    fn test_article_image_struct() {
        let image = ArticleImage {
            src: Some("https://cdn.shopify.com/article-img.jpg".to_string()),
            alt: Some("Featured image".to_string()),
            width: Some(1920),
            height: Some(1080),
            created_at: Some(
                DateTime::parse_from_rfc3339("2024-01-15T10:30:00Z")
                    .unwrap()
                    .with_timezone(&Utc),
            ),
        };

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

        // Writable fields should be present
        assert_eq!(json["src"], "https://cdn.shopify.com/article-img.jpg");
        assert_eq!(json["alt"], "Featured image");

        // Read-only fields should be omitted
        assert!(json.get("width").is_none());
        assert!(json.get("height").is_none());
        assert!(json.get("created_at").is_none());
    }

    #[test]
    fn test_article_constants() {
        assert_eq!(Article::NAME, "Article");
        assert_eq!(Article::PLURAL, "articles");
    }
}