riglr-web-tools 0.3.0

Web-based data tools for riglr agents - Twitter, DexScreener, web search, and more
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
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
//! LunarCrush social analytics integration for cryptocurrency sentiment analysis
//!
//! This module provides advanced social analytics capabilities by integrating with LunarCrush,
//! enabling AI agents to access comprehensive social sentiment data, influencer tracking,
//! and trending cryptocurrency analysis.

use crate::{client::WebClient, error::WebToolError};
use chrono::{DateTime, Utc};
use riglr_core::provider::ApplicationContext;
use riglr_macros::tool;
use schemars::JsonSchema;

const LUNARCRUSH_API_KEY: &str = "LUNARCRUSH_API_KEY";
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tracing::{debug, info};

/// LunarCrush API configuration
#[derive(Debug, Clone)]
pub struct LunarCrushConfig {
    /// LunarCrush API key
    pub api_key: String,
    /// API base URL (default: https://api.lunarcrush.com/v2)
    pub base_url: String,
    /// Rate limit per minute (default: 60)
    pub rate_limit_per_minute: u32,
}

impl Default for LunarCrushConfig {
    fn default() -> Self {
        Self {
            api_key: std::env::var(LUNARCRUSH_API_KEY).unwrap_or_default(),
            base_url: "https://api.lunarcrush.com/v2".to_string(),
            rate_limit_per_minute: 60,
        }
    }
}

/// Social sentiment data for a cryptocurrency
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct SentimentData {
    /// Cryptocurrency symbol (e.g., "BTC", "ETH")
    pub symbol: String,
    /// Overall social score (0-100)
    pub social_score: f64,
    /// Sentiment score (-1 to 1, where 1 is very positive)
    pub sentiment_score: f64,
    /// Social volume (number of mentions)
    pub social_volume: u64,
    /// Total mentions across all platforms
    pub mentions: u64,
    /// Number of posts from influencers
    pub influencer_posts: u64,
    /// Average social volume over the timeframe
    pub avg_social_volume: f64,
    /// Social volume change percentage
    pub social_volume_change: f64,
    /// Sentiment breakdown by platform
    pub platform_sentiment: HashMap<String, f64>,
    /// Trending keywords associated with the token
    pub trending_keywords: Vec<String>,
    /// Data timestamp
    pub timestamp: DateTime<Utc>,
}

/// Trending cryptocurrency with social metrics
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct TrendingCrypto {
    /// Cryptocurrency symbol
    pub symbol: String,
    /// Full name of the cryptocurrency
    pub name: String,
    /// Current market rank
    pub market_rank: u32,
    /// Galaxy score (LunarCrush proprietary metric)
    pub galaxy_score: f64,
    /// AltRank (alternative ranking metric)
    pub alt_rank: u32,
    /// Social score
    pub social_score: f64,
    /// Price in USD
    pub price_usd: f64,
    /// 24h price change percentage
    pub price_change_24h: f64,
    /// Social volume
    pub social_volume: u64,
    /// Social volume change percentage
    pub social_volume_change: f64,
    /// Market cap in USD
    pub market_cap: u64,
    /// 24h trading volume
    pub volume_24h: u64,
}

/// Influencer mention data
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct InfluencerMention {
    /// Unique mention ID
    pub id: String,
    /// Influencer username
    pub influencer_username: String,
    /// Influencer display name
    pub influencer_name: String,
    /// Number of followers
    pub followers: u64,
    /// Post content/text
    pub text: String,
    /// Post timestamp
    pub timestamp: DateTime<Utc>,
    /// Platform (Twitter, Reddit, etc.)
    pub platform: String,
    /// Engagement metrics
    pub likes: u64,
    /// Number of shares/retweets
    pub shares: u64,
    /// Number of comments
    pub comments: u64,
    /// Post URL
    pub url: Option<String>,
    /// Sentiment score for this specific mention
    pub sentiment: f64,
}

/// Result containing multiple influencer mentions
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct InfluencerMentionsResult {
    /// Token symbol that was searched
    pub symbol: String,
    /// List of influencer mentions
    pub mentions: Vec<InfluencerMention>,
    /// Total number of mentions found
    pub total_mentions: u64,
    /// Timeframe of the search
    pub timeframe: String,
    /// Average sentiment across all mentions
    pub avg_sentiment: f64,
}

/// Helper function to get LunarCrush API key from ApplicationContext
fn get_api_key_from_context(context: &ApplicationContext) -> Result<String, WebToolError> {
    context
        .config
        .providers
        .lunarcrush_api_key
        .clone()
        .ok_or_else(|| {
            WebToolError::Config(
                "LunarCrush API key not configured. Set LUNARCRUSH_API_KEY in your environment."
                    .to_string(),
            )
        })
}

/// Creates a LunarCrush API client with context
async fn create_lunarcrush_client_with_context(
    context: &ApplicationContext,
) -> Result<WebClient, WebToolError> {
    let api_key = get_api_key_from_context(context)?;
    let client = WebClient::default().with_api_key("lunarcrush", api_key);
    Ok(client)
}

/// Creates a LunarCrush API client
#[allow(dead_code)]
async fn create_lunarcrush_client() -> Result<WebClient, WebToolError> {
    let config = LunarCrushConfig::default();

    if config.api_key.is_empty() {
        return Err(WebToolError::Config(
            "LUNARCRUSH_API_KEY environment variable not set".to_string(),
        ));
    }

    let client = WebClient::default().with_api_key("lunarcrush", config.api_key);

    Ok(client)
}

#[tool]
/// Get social sentiment data for a cryptocurrency from LunarCrush
///
/// This tool provides comprehensive social analytics for any cryptocurrency,
/// including sentiment scores, social volume, and platform-specific data.
///
/// # Arguments
/// * `symbol` - Cryptocurrency symbol (e.g., "BTC", "ETH", "SOL")
/// * `timeframe` - Optional timeframe for analysis ("1h", "24h", "7d", "30d"). Defaults to "24h"
///
/// # Returns
/// Detailed sentiment analysis including scores, volume metrics, and trending keywords
pub async fn get_social_sentiment(
    context: &ApplicationContext,
    symbol: String,
    timeframe: Option<String>,
) -> Result<SentimentData, WebToolError> {
    info!(
        "Fetching social sentiment for {} (timeframe: {})",
        symbol,
        timeframe.as_deref().unwrap_or("24h")
    );

    let client = create_lunarcrush_client_with_context(context).await?;
    let timeframe = timeframe.unwrap_or_else(|| "24h".to_string());

    // Validate timeframe
    if !["1h", "24h", "7d", "30d"].contains(&timeframe.as_str()) {
        return Err(WebToolError::Config(
            "Invalid timeframe. Must be one of: 1h, 24h, 7d, 30d".to_string(),
        ));
    }

    let mut params = HashMap::new();
    params.insert("symbol".to_string(), symbol.to_uppercase());
    params.insert("data_points".to_string(), "1".to_string());
    params.insert("interval".to_string(), timeframe.clone());

    let config = LunarCrushConfig::default();
    let url = format!("{}/assets", config.base_url);

    let response_text = client.get_with_params(&url, &params).await?;

    let response_data: serde_json::Value = serde_json::from_str(&response_text)
        .map_err(|e| WebToolError::Parsing(format!("Invalid JSON response: {}", e)))?;

    // Extract asset data from the response
    let data = response_data
        .get("data")
        .ok_or_else(|| WebToolError::Parsing("Missing 'data' field".to_string()))?;

    let assets = data
        .as_array()
        .ok_or_else(|| WebToolError::Parsing("'data' is not an array".to_string()))?;

    let asset = assets
        .first()
        .ok_or_else(|| WebToolError::Parsing(format!("No data found for symbol {}", symbol)))?;

    // Parse the asset data
    let social_score = asset
        .get("galaxy_score")
        .and_then(|v| v.as_f64())
        .unwrap_or(0.0);
    let sentiment_score = asset
        .get("sentiment")
        .and_then(|v| v.as_f64())
        .unwrap_or(0.0);
    let social_volume = asset
        .get("social_volume")
        .and_then(|v| v.as_u64())
        .unwrap_or(0);
    let mentions = asset
        .get("total_mentions")
        .and_then(|v| v.as_u64())
        .unwrap_or(0);
    let influencer_posts = asset
        .get("influencer_posts")
        .and_then(|v| v.as_u64())
        .unwrap_or(0);
    let avg_social_volume = asset
        .get("avg_social_volume")
        .and_then(|v| v.as_f64())
        .unwrap_or(0.0);
    let social_volume_change = asset
        .get("social_volume_change_24h")
        .and_then(|v| v.as_f64())
        .unwrap_or(0.0);

    // Extract platform sentiment breakdown
    let mut platform_sentiment = HashMap::new();
    if let Some(platforms) = asset.get("platform_sentiment") {
        if let Some(twitter_sentiment) = platforms.get("twitter").and_then(|v| v.as_f64()) {
            platform_sentiment.insert("twitter".to_string(), twitter_sentiment);
        }
        if let Some(reddit_sentiment) = platforms.get("reddit").and_then(|v| v.as_f64()) {
            platform_sentiment.insert("reddit".to_string(), reddit_sentiment);
        }
    }

    // Extract trending keywords
    let trending_keywords = asset
        .get("keywords")
        .and_then(|v| v.as_array())
        .map(|arr| {
            arr.iter()
                .filter_map(|kw| kw.as_str().map(|s| s.to_string()))
                .collect()
        })
        .unwrap_or_default();

    debug!(
        "Successfully fetched sentiment data for {} with {} mentions",
        symbol, mentions
    );

    Ok(SentimentData {
        symbol: symbol.to_uppercase(),
        social_score,
        sentiment_score,
        social_volume,
        mentions,
        influencer_posts,
        avg_social_volume,
        social_volume_change,
        platform_sentiment,
        trending_keywords,
        timestamp: Utc::now(),
    })
}

#[tool]
/// Get trending cryptocurrencies by social metrics from LunarCrush
///
/// This tool identifies the most trending cryptocurrencies based on social media activity,
/// sentiment, and LunarCrush's proprietary Galaxy Score.
///
/// # Arguments
/// * `limit` - Maximum number of trending cryptocurrencies to return (1-50). Defaults to 10
/// * `sort_by` - Sort metric: "galaxy_score", "social_volume", "alt_rank". Defaults to "galaxy_score"
///
/// # Returns
/// List of trending cryptocurrencies with social and market metrics
pub async fn get_trending_cryptos(
    context: &ApplicationContext,
    limit: Option<u32>,
    sort_by: Option<String>,
) -> Result<Vec<TrendingCrypto>, WebToolError> {
    let limit = limit.unwrap_or(10).clamp(1, 50);
    let sort_by = sort_by.unwrap_or_else(|| "galaxy_score".to_string());

    info!(
        "Fetching top {} trending cryptos sorted by {}",
        limit, sort_by
    );

    // Validate sort_by parameter
    if !["galaxy_score", "social_volume", "alt_rank"].contains(&sort_by.as_str()) {
        return Err(WebToolError::Config(
            "Invalid sort_by parameter. Must be one of: galaxy_score, social_volume, alt_rank"
                .to_string(),
        ));
    }

    let client = create_lunarcrush_client_with_context(context).await?;

    let mut params = HashMap::new();
    params.insert("limit".to_string(), limit.to_string());
    params.insert("sort".to_string(), sort_by);

    let config = LunarCrushConfig::default();
    let url = format!("{}/market", config.base_url);

    let response_text = client.get_with_params(&url, &params).await?;

    let response_data: serde_json::Value = serde_json::from_str(&response_text)
        .map_err(|e| WebToolError::Parsing(format!("Invalid JSON response: {}", e)))?;

    let data = response_data
        .get("data")
        .ok_or_else(|| WebToolError::Parsing("Missing 'data' field".to_string()))?;

    let assets = data
        .as_array()
        .ok_or_else(|| WebToolError::Parsing("'data' is not an array".to_string()))?;

    let mut trending_cryptos = Vec::new();

    for asset in assets.iter().take(limit as usize) {
        let symbol = asset
            .get("symbol")
            .and_then(|v| v.as_str())
            .unwrap_or("UNKNOWN")
            .to_string();

        let name = asset
            .get("name")
            .and_then(|v| v.as_str())
            .unwrap_or("Unknown")
            .to_string();

        let market_rank = asset
            .get("market_cap_rank")
            .and_then(|v| v.as_u64())
            .unwrap_or(0) as u32;
        let galaxy_score = asset
            .get("galaxy_score")
            .and_then(|v| v.as_f64())
            .unwrap_or(0.0);
        let alt_rank = asset.get("alt_rank").and_then(|v| v.as_u64()).unwrap_or(0) as u32;
        let social_score = asset
            .get("social_score")
            .and_then(|v| v.as_f64())
            .unwrap_or(0.0);
        let price_usd = asset.get("price").and_then(|v| v.as_f64()).unwrap_or(0.0);
        let price_change_24h = asset
            .get("percent_change_24h")
            .and_then(|v| v.as_f64())
            .unwrap_or(0.0);
        let social_volume = asset
            .get("social_volume")
            .and_then(|v| v.as_u64())
            .unwrap_or(0);
        let social_volume_change = asset
            .get("social_volume_change_24h")
            .and_then(|v| v.as_f64())
            .unwrap_or(0.0);
        let market_cap = asset
            .get("market_cap")
            .and_then(|v| v.as_u64())
            .unwrap_or(0);
        let volume_24h = asset
            .get("volume_24h")
            .and_then(|v| v.as_u64())
            .unwrap_or(0);

        trending_cryptos.push(TrendingCrypto {
            symbol,
            name,
            market_rank,
            galaxy_score,
            alt_rank,
            social_score,
            price_usd,
            price_change_24h,
            social_volume,
            social_volume_change,
            market_cap,
            volume_24h,
        });
    }

    debug!(
        "Successfully fetched {} trending cryptocurrencies",
        trending_cryptos.len()
    );

    Ok(trending_cryptos)
}

#[tool]
/// Get influencer mentions for a specific token from LunarCrush
///
/// This tool tracks mentions from cryptocurrency influencers and high-follower accounts,
/// providing insights into what key opinion leaders are saying about specific tokens.
///
/// # Arguments
/// * `token_symbol` - Cryptocurrency symbol to search for (e.g., "BTC", "ETH", "SOL")
/// * `limit` - Maximum number of mentions to return (1-50). Defaults to 20
/// * `timeframe` - Time period to search: "24h", "7d", "30d". Defaults to "24h"
///
/// # Returns
/// Collection of influencer mentions with engagement metrics and sentiment analysis
pub async fn get_influencer_mentions(
    context: &ApplicationContext,
    token_symbol: String,
    limit: Option<u32>,
    timeframe: Option<String>,
) -> Result<InfluencerMentionsResult, WebToolError> {
    let limit = limit.unwrap_or(20).clamp(1, 50);
    let timeframe = timeframe.unwrap_or_else(|| "24h".to_string());

    info!(
        "Fetching influencer mentions for {} (limit: {}, timeframe: {})",
        token_symbol, limit, timeframe
    );

    // Validate timeframe
    if !["24h", "7d", "30d"].contains(&timeframe.as_str()) {
        return Err(WebToolError::Config(
            "Invalid timeframe. Must be one of: 24h, 7d, 30d".to_string(),
        ));
    }

    let client = create_lunarcrush_client_with_context(context).await?;

    let mut params = HashMap::new();
    params.insert("symbol".to_string(), token_symbol.to_uppercase());
    params.insert("limit".to_string(), limit.to_string());
    params.insert("interval".to_string(), timeframe.clone());
    params.insert("sources".to_string(), "influencers".to_string());

    let config = LunarCrushConfig::default();
    let url = format!("{}/feeds", config.base_url);

    let response_text = client.get_with_params(&url, &params).await?;

    let response_data: serde_json::Value = serde_json::from_str(&response_text)
        .map_err(|e| WebToolError::Parsing(format!("Invalid JSON response: {}", e)))?;

    let data = response_data
        .get("data")
        .ok_or_else(|| WebToolError::Parsing("Missing 'data' field".to_string()))?;

    let posts = data
        .as_array()
        .ok_or_else(|| WebToolError::Parsing("'data' is not an array".to_string()))?;

    let mut mentions = Vec::new();
    let mut total_sentiment = 0.0;

    for post in posts.iter().take(limit as usize) {
        let id = post
            .get("id")
            .and_then(|v| v.as_str())
            .unwrap_or("unknown")
            .to_string();

        let influencer_username = post
            .get("user_name")
            .and_then(|v| v.as_str())
            .unwrap_or("unknown")
            .to_string();

        let influencer_name = post
            .get("user_display_name")
            .and_then(|v| v.as_str())
            .unwrap_or(&influencer_username)
            .to_string();

        let followers = post
            .get("user_followers")
            .and_then(|v| v.as_u64())
            .unwrap_or(0);

        let text = post
            .get("content")
            .and_then(|v| v.as_str())
            .unwrap_or("")
            .to_string();

        let timestamp_str = post
            .get("created_time")
            .and_then(|v| v.as_str())
            .unwrap_or("1970-01-01T00:00:00Z");

        let timestamp = DateTime::parse_from_rfc3339(timestamp_str)
            .unwrap_or_else(|_| {
                DateTime::from_timestamp(0, 0)
                    .map(|dt| dt.into())
                    .unwrap_or_else(|| Utc::now().into())
            })
            .with_timezone(&Utc);

        let platform = post
            .get("type")
            .and_then(|v| v.as_str())
            .unwrap_or("twitter")
            .to_string();

        let likes = post
            .get("interactions")
            .and_then(|i| i.get("likes"))
            .and_then(|v| v.as_u64())
            .unwrap_or(0);
        let shares = post
            .get("interactions")
            .and_then(|i| i.get("retweets"))
            .and_then(|v| v.as_u64())
            .unwrap_or(0);
        let comments = post
            .get("interactions")
            .and_then(|i| i.get("replies"))
            .and_then(|v| v.as_u64())
            .unwrap_or(0);

        let url = post
            .get("url")
            .and_then(|v| v.as_str())
            .map(|s| s.to_string());

        let sentiment = post
            .get("sentiment")
            .and_then(|v| v.as_f64())
            .unwrap_or(0.0);
        total_sentiment += sentiment;

        mentions.push(InfluencerMention {
            id,
            influencer_username,
            influencer_name,
            followers,
            text,
            timestamp,
            platform,
            likes,
            shares,
            comments,
            url,
            sentiment,
        });
    }

    let avg_sentiment = if mentions.is_empty() {
        0.0
    } else {
        total_sentiment / mentions.len() as f64
    };

    debug!(
        "Successfully fetched {} influencer mentions for {} with avg sentiment {:.2}",
        mentions.len(),
        token_symbol,
        avg_sentiment
    );

    let total_mentions = mentions.len() as u64;

    Ok(InfluencerMentionsResult {
        symbol: token_symbol.to_uppercase(),
        mentions,
        total_mentions,
        timeframe,
        avg_sentiment,
    })
}

#[cfg(test)]
mod tests {
    use super::*;
    use chrono::{TimeZone, Utc};
    use std::env;

    // Tests for LunarCrushConfig
    #[test]
    fn test_lunarcrush_config_default_without_env_var() {
        // Remove the env var if it exists
        env::remove_var(LUNARCRUSH_API_KEY);

        let config = LunarCrushConfig::default();
        assert_eq!(config.api_key, "");
        assert_eq!(config.base_url, "https://api.lunarcrush.com/v2");
        assert_eq!(config.rate_limit_per_minute, 60);
    }

    #[test]
    fn test_lunarcrush_config_default_with_env_var() {
        env::set_var(LUNARCRUSH_API_KEY, "test_api_key");

        let config = LunarCrushConfig::default();
        assert_eq!(config.api_key, "test_api_key");
        assert_eq!(config.base_url, "https://api.lunarcrush.com/v2");
        assert_eq!(config.rate_limit_per_minute, 60);

        env::remove_var(LUNARCRUSH_API_KEY);
    }

    #[test]
    fn test_lunarcrush_config_debug_trait() {
        let config = LunarCrushConfig {
            api_key: "test_key".to_string(),
            base_url: "https://test.com".to_string(),
            rate_limit_per_minute: 30,
        };

        let debug_str = format!("{:?}", config);
        assert!(debug_str.contains("test_key"));
        assert!(debug_str.contains("https://test.com"));
        assert!(debug_str.contains("30"));
    }

    #[test]
    fn test_lunarcrush_config_clone() {
        let config = LunarCrushConfig {
            api_key: "test_key".to_string(),
            base_url: "https://test.com".to_string(),
            rate_limit_per_minute: 30,
        };

        let cloned = config.clone();
        assert_eq!(config.api_key, cloned.api_key);
        assert_eq!(config.base_url, cloned.base_url);
        assert_eq!(config.rate_limit_per_minute, cloned.rate_limit_per_minute);
    }

    // Tests for SentimentData
    #[test]
    fn test_sentiment_data_serialization_and_deserialization() {
        let mut platform_sentiment = HashMap::new();
        platform_sentiment.insert("twitter".to_string(), 0.8);
        platform_sentiment.insert("reddit".to_string(), 0.6);

        let sentiment = SentimentData {
            symbol: "BTC".to_string(),
            social_score: 85.5,
            sentiment_score: 0.7,
            social_volume: 10000,
            mentions: 15000,
            influencer_posts: 250,
            avg_social_volume: 9500.0,
            social_volume_change: 15.2,
            platform_sentiment,
            trending_keywords: vec!["bitcoin".to_string(), "crypto".to_string()],
            timestamp: Utc::now(),
        };

        let serialized = serde_json::to_string(&sentiment).unwrap();
        assert!(serialized.contains("BTC"));
        assert!(serialized.contains("85.5"));
        assert!(serialized.contains("twitter"));
        assert!(serialized.contains("bitcoin"));

        let deserialized: SentimentData = serde_json::from_str(&serialized).unwrap();
        assert_eq!(deserialized.symbol, "BTC");
        assert_eq!(deserialized.social_score, 85.5);
        assert_eq!(deserialized.platform_sentiment.len(), 2);
        assert_eq!(deserialized.trending_keywords.len(), 2);
    }

    #[test]
    fn test_sentiment_data_debug_trait() {
        let sentiment = SentimentData {
            symbol: "ETH".to_string(),
            social_score: 90.0,
            sentiment_score: 0.5,
            social_volume: 5000,
            mentions: 8000,
            influencer_posts: 100,
            avg_social_volume: 4800.0,
            social_volume_change: -5.2,
            platform_sentiment: HashMap::new(),
            trending_keywords: vec![],
            timestamp: Utc::now(),
        };

        let debug_str = format!("{:?}", sentiment);
        assert!(debug_str.contains("ETH"));
        assert!(debug_str.contains("90"));
    }

    #[test]
    fn test_sentiment_data_clone() {
        let sentiment = SentimentData {
            symbol: "SOL".to_string(),
            social_score: 75.0,
            sentiment_score: 0.3,
            social_volume: 3000,
            mentions: 4000,
            influencer_posts: 50,
            avg_social_volume: 2900.0,
            social_volume_change: 10.5,
            platform_sentiment: HashMap::new(),
            trending_keywords: vec!["solana".to_string()],
            timestamp: Utc::now(),
        };

        let cloned = sentiment.clone();
        assert_eq!(sentiment.symbol, cloned.symbol);
        assert_eq!(sentiment.social_score, cloned.social_score);
        assert_eq!(sentiment.trending_keywords, cloned.trending_keywords);
    }

    // Tests for TrendingCrypto
    #[test]
    fn test_trending_crypto_serialization_and_deserialization() {
        let trending = TrendingCrypto {
            symbol: "ETH".to_string(),
            name: "Ethereum".to_string(),
            market_rank: 2,
            galaxy_score: 90.0,
            alt_rank: 1,
            social_score: 88.0,
            price_usd: 2500.0,
            price_change_24h: 5.2,
            social_volume: 25000,
            social_volume_change: 12.5,
            market_cap: 300000000000,
            volume_24h: 15000000000,
        };

        let serialized = serde_json::to_string(&trending).unwrap();
        assert!(serialized.contains("ETH"));
        assert!(serialized.contains("Ethereum"));
        assert!(serialized.contains("90"));

        let deserialized: TrendingCrypto = serde_json::from_str(&serialized).unwrap();
        assert_eq!(deserialized.symbol, "ETH");
        assert_eq!(deserialized.name, "Ethereum");
        assert_eq!(deserialized.market_rank, 2);
    }

    #[test]
    fn test_trending_crypto_debug_trait() {
        let trending = TrendingCrypto {
            symbol: "BTC".to_string(),
            name: "Bitcoin".to_string(),
            market_rank: 1,
            galaxy_score: 95.0,
            alt_rank: 1,
            social_score: 92.0,
            price_usd: 50000.0,
            price_change_24h: -2.1,
            social_volume: 50000,
            social_volume_change: -8.3,
            market_cap: 1000000000000,
            volume_24h: 30000000000,
        };

        let debug_str = format!("{:?}", trending);
        assert!(debug_str.contains("BTC"));
        assert!(debug_str.contains("Bitcoin"));
        assert!(debug_str.contains("95"));
    }

    #[test]
    fn test_trending_crypto_clone() {
        let trending = TrendingCrypto {
            symbol: "ADA".to_string(),
            name: "Cardano".to_string(),
            market_rank: 5,
            galaxy_score: 70.0,
            alt_rank: 4,
            social_score: 68.0,
            price_usd: 1.5,
            price_change_24h: 3.4,
            social_volume: 8000,
            social_volume_change: 15.7,
            market_cap: 50000000000,
            volume_24h: 2000000000,
        };

        let cloned = trending.clone();
        assert_eq!(trending.symbol, cloned.symbol);
        assert_eq!(trending.name, cloned.name);
        assert_eq!(trending.market_rank, cloned.market_rank);
    }

    // Tests for InfluencerMention
    #[test]
    fn test_influencer_mention_serialization_and_deserialization() {
        let mention = InfluencerMention {
            id: "12345".to_string(),
            influencer_username: "crypto_guru".to_string(),
            influencer_name: "Crypto Guru".to_string(),
            followers: 100000,
            text: "Bitcoin is looking bullish!".to_string(),
            timestamp: Utc.with_ymd_and_hms(2023, 1, 1, 12, 0, 0).unwrap(),
            platform: "twitter".to_string(),
            likes: 500,
            shares: 100,
            comments: 50,
            url: Some("https://twitter.com/post/12345".to_string()),
            sentiment: 0.8,
        };

        let serialized = serde_json::to_string(&mention).unwrap();
        assert!(serialized.contains("12345"));
        assert!(serialized.contains("crypto_guru"));
        assert!(serialized.contains("Bitcoin is looking bullish"));

        let deserialized: InfluencerMention = serde_json::from_str(&serialized).unwrap();
        assert_eq!(deserialized.id, "12345");
        assert_eq!(deserialized.influencer_username, "crypto_guru");
        assert_eq!(deserialized.followers, 100000);
    }

    #[test]
    fn test_influencer_mention_without_url() {
        let mention = InfluencerMention {
            id: "67890".to_string(),
            influencer_username: "trader_joe".to_string(),
            influencer_name: "Trader Joe".to_string(),
            followers: 50000,
            text: "Market is volatile".to_string(),
            timestamp: Utc::now(),
            platform: "reddit".to_string(),
            likes: 200,
            shares: 25,
            comments: 75,
            url: None,
            sentiment: -0.2,
        };

        let serialized = serde_json::to_string(&mention).unwrap();
        let deserialized: InfluencerMention = serde_json::from_str(&serialized).unwrap();
        assert_eq!(deserialized.url, None);
        assert_eq!(deserialized.sentiment, -0.2);
    }

    #[test]
    fn test_influencer_mention_debug_trait() {
        let mention = InfluencerMention {
            id: "test_id".to_string(),
            influencer_username: "test_user".to_string(),
            influencer_name: "Test User".to_string(),
            followers: 1000,
            text: "Test content".to_string(),
            timestamp: Utc::now(),
            platform: "twitter".to_string(),
            likes: 10,
            shares: 5,
            comments: 2,
            url: None,
            sentiment: 0.0,
        };

        let debug_str = format!("{:?}", mention);
        assert!(debug_str.contains("test_id"));
        assert!(debug_str.contains("test_user"));
    }

    #[test]
    fn test_influencer_mention_clone() {
        let mention = InfluencerMention {
            id: "clone_test".to_string(),
            influencer_username: "clone_user".to_string(),
            influencer_name: "Clone User".to_string(),
            followers: 2000,
            text: "Clone test".to_string(),
            timestamp: Utc::now(),
            platform: "reddit".to_string(),
            likes: 20,
            shares: 10,
            comments: 5,
            url: Some("test_url".to_string()),
            sentiment: 0.5,
        };

        let cloned = mention.clone();
        assert_eq!(mention.id, cloned.id);
        assert_eq!(mention.influencer_username, cloned.influencer_username);
        assert_eq!(mention.url, cloned.url);
    }

    // Tests for InfluencerMentionsResult
    #[test]
    fn test_influencer_mentions_result_serialization_and_deserialization() {
        let mentions = vec![InfluencerMention {
            id: "1".to_string(),
            influencer_username: "user1".to_string(),
            influencer_name: "User One".to_string(),
            followers: 1000,
            text: "Content 1".to_string(),
            timestamp: Utc::now(),
            platform: "twitter".to_string(),
            likes: 10,
            shares: 5,
            comments: 2,
            url: None,
            sentiment: 0.5,
        }];

        let result = InfluencerMentionsResult {
            symbol: "BTC".to_string(),
            mentions,
            total_mentions: 1,
            timeframe: "24h".to_string(),
            avg_sentiment: 0.5,
        };

        let serialized = serde_json::to_string(&result).unwrap();
        assert!(serialized.contains("BTC"));
        assert!(serialized.contains("24h"));

        let deserialized: InfluencerMentionsResult = serde_json::from_str(&serialized).unwrap();
        assert_eq!(deserialized.symbol, "BTC");
        assert_eq!(deserialized.total_mentions, 1);
        assert_eq!(deserialized.timeframe, "24h");
    }

    #[test]
    fn test_influencer_mentions_result_empty_mentions() {
        let result = InfluencerMentionsResult {
            symbol: "ETH".to_string(),
            mentions: vec![],
            total_mentions: 0,
            timeframe: "7d".to_string(),
            avg_sentiment: 0.0,
        };

        assert_eq!(result.mentions.len(), 0);
        assert_eq!(result.total_mentions, 0);
        assert_eq!(result.avg_sentiment, 0.0);
    }

    #[test]
    fn test_influencer_mentions_result_debug_trait() {
        let result = InfluencerMentionsResult {
            symbol: "SOL".to_string(),
            mentions: vec![],
            total_mentions: 5,
            timeframe: "30d".to_string(),
            avg_sentiment: 0.3,
        };

        let debug_str = format!("{:?}", result);
        assert!(debug_str.contains("SOL"));
        assert!(debug_str.contains("30d"));
        assert!(debug_str.contains("0.3"));
    }

    #[test]
    fn test_influencer_mentions_result_clone() {
        let result = InfluencerMentionsResult {
            symbol: "DOGE".to_string(),
            mentions: vec![],
            total_mentions: 10,
            timeframe: "24h".to_string(),
            avg_sentiment: -0.1,
        };

        let cloned = result.clone();
        assert_eq!(result.symbol, cloned.symbol);
        assert_eq!(result.total_mentions, cloned.total_mentions);
        assert_eq!(result.timeframe, cloned.timeframe);
        assert_eq!(result.avg_sentiment, cloned.avg_sentiment);
    }

    // Tests for create_lunarcrush_client function
    #[tokio::test]
    async fn test_create_lunarcrush_client_missing_api_key() {
        env::remove_var(LUNARCRUSH_API_KEY);

        let result = create_lunarcrush_client().await;
        assert!(result.is_err());

        if let Err(WebToolError::Config(msg)) = result {
            assert_eq!(msg, "LUNARCRUSH_API_KEY environment variable not set");
        } else {
            panic!("Expected Config error");
        }
    }

    #[tokio::test]
    async fn test_create_lunarcrush_client_with_empty_api_key() {
        env::set_var(LUNARCRUSH_API_KEY, "");

        let result = create_lunarcrush_client().await;
        assert!(result.is_err());

        env::remove_var(LUNARCRUSH_API_KEY);
    }

    // Test timeframe validation in various functions
    #[test]
    fn test_timeframe_validation_get_social_sentiment() {
        // This tests the validation logic that would be used in get_social_sentiment
        let valid_timeframes = ["1h", "24h", "7d", "30d"];
        let invalid_timeframes = ["2h", "1d", "1w", "1m", "invalid"];

        for tf in valid_timeframes {
            assert!(["1h", "24h", "7d", "30d"].contains(&tf));
        }

        for tf in invalid_timeframes {
            assert!(!["1h", "24h", "7d", "30d"].contains(&tf));
        }
    }

    #[test]
    fn test_timeframe_validation_get_influencer_mentions() {
        // This tests the validation logic that would be used in get_influencer_mentions
        let valid_timeframes = ["24h", "7d", "30d"];
        let invalid_timeframes = ["1h", "1d", "1w", "1m", "invalid"];

        for tf in valid_timeframes {
            assert!(["24h", "7d", "30d"].contains(&tf));
        }

        for tf in invalid_timeframes {
            assert!(!["24h", "7d", "30d"].contains(&tf));
        }
    }

    #[test]
    fn test_sort_by_validation_get_trending_cryptos() {
        // This tests the validation logic that would be used in get_trending_cryptos
        let valid_sort_options = ["galaxy_score", "social_volume", "alt_rank"];
        let invalid_sort_options = ["price", "market_cap", "invalid"];

        for sort_by in valid_sort_options {
            assert!(["galaxy_score", "social_volume", "alt_rank"].contains(&sort_by));
        }

        for sort_by in invalid_sort_options {
            assert!(!["galaxy_score", "social_volume", "alt_rank"].contains(&sort_by));
        }
    }

    #[test]
    fn test_limit_clamping() {
        // Test limit clamping logic used in get_trending_cryptos
        let test_cases = [
            (None, 10),      // Default case
            (Some(0), 1),    // Below minimum
            (Some(5), 5),    // Valid value
            (Some(25), 25),  // Valid value
            (Some(100), 50), // Above maximum
        ];

        for (input, expected) in test_cases {
            let result = input.unwrap_or(10).clamp(1, 50);
            assert_eq!(result, expected);
        }
    }

    #[test]
    fn test_limit_clamping_influencer_mentions() {
        // Test limit clamping logic used in get_influencer_mentions
        let test_cases = [
            (None, 20),      // Default case
            (Some(0), 1),    // Below minimum
            (Some(10), 10),  // Valid value
            (Some(30), 30),  // Valid value
            (Some(100), 50), // Above maximum
        ];

        for (input, expected) in test_cases {
            let result = input.unwrap_or(20).clamp(1, 50);
            assert_eq!(result, expected);
        }
    }

    #[test]
    fn test_string_case_conversion() {
        // Test the string case conversion logic used throughout the module
        let symbols = ["btc", "ETH", "SoL", "DOGE"];
        let expected = ["BTC", "ETH", "SOL", "DOGE"];

        for (input, expected_output) in symbols.iter().zip(expected.iter()) {
            assert_eq!(input.to_uppercase(), *expected_output);
        }
    }

    #[test]
    fn test_datetime_parsing_edge_cases() {
        use chrono::DateTime;

        // Test valid RFC3339 datetime
        let valid_datetime = "2023-01-01T12:00:00Z";
        let parsed = DateTime::parse_from_rfc3339(valid_datetime);
        assert!(parsed.is_ok());

        // Test invalid datetime format
        let invalid_datetime = "invalid-datetime";
        let parsed = DateTime::parse_from_rfc3339(invalid_datetime);
        assert!(parsed.is_err());

        // Test fallback behavior (mimics the code in get_influencer_mentions)
        let fallback_timestamp = DateTime::parse_from_rfc3339("invalid")
            .unwrap_or_else(|_| {
                DateTime::from_timestamp(0, 0)
                    .map(|dt| dt.into())
                    .unwrap_or_else(|| Utc::now().into())
            })
            .with_timezone(&Utc);

        // Should be either epoch time or current time, both valid
        assert!(fallback_timestamp.timestamp() >= 0);
    }

    #[test]
    fn test_average_sentiment_calculation() {
        // Test sentiment average calculation logic used in get_influencer_mentions

        // Empty case
        let sentiments: Vec<f64> = vec![];
        let avg = if sentiments.is_empty() {
            0.0
        } else {
            sentiments.iter().sum::<f64>() / sentiments.len() as f64
        };
        assert_eq!(avg, 0.0);

        // Single value
        let sentiments = vec![0.5];
        let avg = sentiments.iter().sum::<f64>() / sentiments.len() as f64;
        assert_eq!(avg, 0.5);

        // Multiple values
        let sentiments = vec![0.8, -0.2, 0.1, 0.3];
        let avg = sentiments.iter().sum::<f64>() / sentiments.len() as f64;
        assert_eq!(avg, 0.25);

        // All positive
        let sentiments = vec![0.9, 0.8, 0.7];
        let avg = sentiments.iter().sum::<f64>() / sentiments.len() as f64;
        assert!((avg - 0.8).abs() < f64::EPSILON);

        // All negative
        let sentiments = vec![-0.5, -0.3, -0.2];
        let avg = sentiments.iter().sum::<f64>() / sentiments.len() as f64;
        assert!((avg - (-1.0 / 3.0)).abs() < 0.01);
    }

    #[test]
    fn test_json_field_extraction_patterns() {
        use serde_json::json;

        // Test the pattern used for extracting values with defaults
        let test_json = json!({
            "galaxy_score": 85.5,
            "sentiment": null,
            "social_volume": "not_a_number",
            "missing_field": null
        });

        // Test f64 extraction with default
        let galaxy_score = test_json
            .get("galaxy_score")
            .and_then(|v| v.as_f64())
            .unwrap_or(0.0);
        assert_eq!(galaxy_score, 85.5);

        // Test f64 extraction with null value
        let sentiment = test_json
            .get("sentiment")
            .and_then(|v| v.as_f64())
            .unwrap_or(0.0);
        assert_eq!(sentiment, 0.0);

        // Test u64 extraction with invalid string
        let social_volume = test_json
            .get("social_volume")
            .and_then(|v| v.as_u64())
            .unwrap_or(0);
        assert_eq!(social_volume, 0);

        // Test missing field
        let missing = test_json
            .get("missing_field")
            .and_then(|v| v.as_f64())
            .unwrap_or(99.9);
        assert_eq!(missing, 99.9);
    }

    #[test]
    fn test_platform_sentiment_extraction() {
        use serde_json::json;

        let test_data = json!({
            "platform_sentiment": {
                "twitter": 0.8,
                "reddit": 0.6,
                "youtube": "invalid"
            }
        });

        let mut platform_sentiment = HashMap::new();
        if let Some(platforms) = test_data.get("platform_sentiment") {
            if let Some(twitter_sentiment) = platforms.get("twitter").and_then(|v| v.as_f64()) {
                platform_sentiment.insert("twitter".to_string(), twitter_sentiment);
            }
            if let Some(reddit_sentiment) = platforms.get("reddit").and_then(|v| v.as_f64()) {
                platform_sentiment.insert("reddit".to_string(), reddit_sentiment);
            }
            if let Some(youtube_sentiment) = platforms.get("youtube").and_then(|v| v.as_f64()) {
                platform_sentiment.insert("youtube".to_string(), youtube_sentiment);
            }
        }

        assert_eq!(platform_sentiment.len(), 2);
        assert_eq!(platform_sentiment.get("twitter"), Some(&0.8));
        assert_eq!(platform_sentiment.get("reddit"), Some(&0.6));
        assert_eq!(platform_sentiment.get("youtube"), None);
    }

    #[test]
    fn test_keywords_extraction() {
        use serde_json::json;

        // Test valid keywords array
        let test_data = json!({
            "keywords": ["bitcoin", "crypto", "blockchain"]
        });

        let trending_keywords: Vec<String> = test_data
            .get("keywords")
            .and_then(|v| v.as_array())
            .map(|arr| {
                arr.iter()
                    .filter_map(|kw| kw.as_str().map(|s| s.to_string()))
                    .collect()
            })
            .unwrap_or_default();

        assert_eq!(trending_keywords.len(), 3);
        assert!(trending_keywords.contains(&"bitcoin".to_string()));

        // Test missing keywords field
        let test_data_empty = json!({});
        let trending_keywords_empty: Vec<String> = test_data_empty
            .get("keywords")
            .and_then(|v| v.as_array())
            .map(|arr| {
                arr.iter()
                    .filter_map(|kw| kw.as_str().map(|s| s.to_string()))
                    .collect()
            })
            .unwrap_or_default();

        assert_eq!(trending_keywords_empty.len(), 0);

        // Test keywords with mixed types
        let test_data_mixed = json!({
            "keywords": ["bitcoin", 123, null, "ethereum"]
        });

        let trending_keywords_mixed: Vec<String> = test_data_mixed
            .get("keywords")
            .and_then(|v| v.as_array())
            .map(|arr| {
                arr.iter()
                    .filter_map(|kw| kw.as_str().map(|s| s.to_string()))
                    .collect()
            })
            .unwrap_or_default();

        assert_eq!(trending_keywords_mixed.len(), 2);
        assert!(trending_keywords_mixed.contains(&"bitcoin".to_string()));
        assert!(trending_keywords_mixed.contains(&"ethereum".to_string()));
    }

    #[test]
    fn test_take_limit_behavior() {
        // Test the behavior of iterating with take() as used in the API functions
        let test_vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

        // Take fewer items than available
        let result: Vec<_> = test_vec.iter().take(3).collect();
        assert_eq!(result.len(), 3);

        // Take more items than available
        let result: Vec<_> = test_vec.iter().take(20).collect();
        assert_eq!(result.len(), 10); // Should only get what's available

        // Take zero items
        let result: Vec<_> = test_vec.iter().take(0).collect();
        assert_eq!(result.len(), 0);
    }

    #[test]
    fn test_const_api_key_name() {
        // Test that the constant is correctly defined
        assert_eq!(LUNARCRUSH_API_KEY, "LUNARCRUSH_API_KEY");
    }
}