legend-saga 0.0.47

A Rust library for working with RabbitMQ and asynchronous operations
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
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use strum_macros::{AsRefStr, EnumIter, EnumString};

/// Represents the available events in the system.
#[derive(Debug, Clone, Copy, AsRefStr, EnumString, PartialEq, EnumIter, Hash, Eq)]
#[strum(serialize_all = "snake_case")]
pub enum MicroserviceEvent {
    #[strum(serialize = "test.image")]
    TestImage,
    #[strum(serialize = "test.mint")]
    TestMint,
    /// Emitted when an event is received by a microservice before processing starts (audit tracking)
    #[strum(serialize = "audit.received")]
    AuditReceived,
    /// Emitted when an event is successfully processed by a microservice for audit tracking
    #[strum(serialize = "audit.processed")]
    AuditProcessed,
    /// Emitted when a message is rejected/nacked and sent to dead letter queue
    #[strum(serialize = "audit.dead_letter")]
    AuditDeadLetter,
    /// Emitted when an event is published by a microservice (audit tracking)
    #[strum(serialize = "audit.published")]
    AuditPublished,
    #[strum(serialize = "auth.deleted_user")]
    AuthDeletedUser,
    #[strum(serialize = "auth.logout_user")]
    AuthLogoutUser,
    #[strum(serialize = "auth.new_user")]
    AuthNewUser,
    #[strum(serialize = "auth.blocked_user")]
    AuthBlockedUser,
    #[strum(serialize = "coins.notify_client")]
    CoinsNotifyClient,
    #[strum(serialize = "coins.send_email")]
    CoinsSendEmail,
    #[strum(serialize = "coins.update_subscription")]
    CoinsUpdateSubscription,
    #[strum(serialize = "legend_missions.completed_mission_reward")]
    LegendMissionsCompletedMissionReward,
    #[strum(serialize = "legend_missions.new_mission_created")]
    LegendMissionsNewMissionCreated,
    #[strum(serialize = "legend_missions.ongoing_mission")]
    LegendMissionsOngoingMission,
    #[strum(serialize = "legend_missions.mission_finished")]
    LegendMissionsMissionFinished,
    #[strum(serialize = "legend_missions.send_email_crypto_mission_completed")]
    LegendMissionsSendEmailCryptoMissionCompleted,
    #[strum(serialize = "legend_missions.send_email_code_exchange_mission_completed")]
    LegendMissionsSendEmailCodeExchangeMissionCompleted,
    #[strum(serialize = "legend_missions.send_email_nft_mission_completed")]
    LegendMissionsSendEmailNftMissionCompleted,
    #[strum(serialize = "legend_rankings.rankings_finished")]
    LegendRankingsRankingsFinished,
    #[strum(serialize = "legend_showcase.product_virtual_deleted")]
    LegendShowcaseProductVirtualDeleted,
    #[strum(serialize = "legend_showcase.update_allowed_mission_subscription_ids")]
    LegendShowcaseUpdateAllowedMissionSubscriptionIds,
    #[strum(serialize = "legend_showcase.update_allowed_ranking_subscription_ids")]
    LegendShowcaseUpdateAllowedRankingSubscriptionIds,
    #[strum(serialize = "room_creator.created_room")]
    RoomCreatorCreatedRoom,
    #[strum(serialize = "room_creator.updated_room")]
    RoomCreatorUpdatedRoom,
    #[strum(serialize = "room_inventory.update_vp_building_image")]
    RoomInventoryUpdateVpBuildingImage,
    #[strum(serialize = "room_snapshot.building_change_in_island")]
    RoomSnapshotBuildingChangeInIsland,
    #[strum(serialize = "room_snapshot.first_snapshot")]
    RoomSnapshotFirstSnapshot,
    #[strum(serialize = "social.block_chat")]
    SocialBlockChat,
    #[strum(serialize = "social.new_user")]
    SocialNewUser,
    #[strum(serialize = "social.unblock_chat")]
    SocialUnblockChat,
    #[strum(serialize = "social.updated_user")]
    SocialUpdatedUser,
    #[strum(serialize = "social_media_rooms.delete_in_batch")]
    SocialMediaRoomsDeleteInBatch,
    #[strum(serialize = "legend_rankings.new_ranking_created")]
    LegendRankingsNewRankingCreated,
    #[strum(serialize = "legend_rankings.intermediate_reward")]
    LegendRankingsIntermediateReward,
    #[strum(serialize = "legend_rankings.participation_reward")]
    LegendRankingsParticipationReward,
}

pub trait PayloadEvent {
    fn event_type(&self) -> MicroserviceEvent;
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TestImagePayload {
    pub image: String,
}

impl PayloadEvent for TestImagePayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::TestImage
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TestMintPayload {
    pub mint: String,
}

impl PayloadEvent for TestMintPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::TestMint
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AuthDeletedUserPayload {
    pub user_id: String,
}

impl PayloadEvent for AuthDeletedUserPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::AuthDeletedUser
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AuthLogoutUserPayload {
    pub user_id: String,
}

impl PayloadEvent for AuthLogoutUserPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::AuthLogoutUser
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AuthNewUserPayload {
    pub id: String,
    pub email: String,
    pub username: String,
    pub userlastname: String,
}

impl PayloadEvent for AuthNewUserPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::AuthNewUser
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AuthBlockedUserPayload {
    pub user_id: String,
    pub block_type: String,
    pub block_reason: Option<String>,
    pub block_expiration_hours: Option<i32>,
}

impl PayloadEvent for AuthBlockedUserPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::AuthBlockedUser
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CoinsUpdateSubscriptionPayload {
    pub user_id: String,
    pub paid_price_id: String,
}

impl PayloadEvent for CoinsUpdateSubscriptionPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::CoinsUpdateSubscription
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CoinsNotifyClientPayload {
    pub room: String,
    pub message: HashMap<String, serde_json::Value>,
}

impl PayloadEvent for CoinsNotifyClientPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::CoinsNotifyClient
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CoinsSendEmailPayload {
    pub user_id: String,
    pub email_type: String,
    pub email: String,
    pub coins: i32,
}

impl PayloadEvent for CoinsSendEmailPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::CoinsSendEmail
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendMissionsCompletedMissionRewardEventPayload {
    pub user_id: String,
    pub coins: i32,
}

impl PayloadEvent for LegendMissionsCompletedMissionRewardEventPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendMissionsCompletedMissionReward
    }
}

/// Represents the fields that will be sent by email when a mission is created.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendMissionsNewMissionCreatedEventPayload {
    pub title: String,
    pub author: String,
    pub author_email: String,
    pub reward: i32,
    pub start_date: String,
    pub end_date: String,
    pub max_players_claiming_reward: i32,
    pub time_to_reward: i32,
    pub notification_config: Option<NotificationConfig>,
}

impl PayloadEvent for LegendMissionsNewMissionCreatedEventPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendMissionsNewMissionCreated
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendMissionsOngoingMissionEventPayload {
    pub redis_key: String,
}

impl PayloadEvent for LegendMissionsOngoingMissionEventPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendMissionsOngoingMission
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct MissionFinishedParticipant {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub email: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub position: Option<i32>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendMissionsMissionFinishedEventPayload {
    pub mission_title: String,
    pub participants: Vec<MissionFinishedParticipant>,
}

impl PayloadEvent for LegendMissionsMissionFinishedEventPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendMissionsMissionFinished
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RankingWinners {
    pub user_id: String,
    pub reward: i32,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CompletedRanking {
    pub title: String,
    pub description: String,
    pub author_email: String,
    pub ends_at: String,
    pub reward: String,
    pub reward_type: String,
    pub winners: Vec<RankingWinners>,
    // Present only if reward_type is "Nft"
    pub nft_blockchain_network: Option<String>,
    pub nft_contract_address: Option<String>,
    // Present only if reward_type is "Crypto"
    pub wallet_crypto_asset: Option<String>,
    /// Optional notification config (JSON) to enrich email templates
    pub notification_config: Option<serde_json::Value>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendMissionsSendEmailCryptoMissionCompletedPayload {
    pub user_id: String,
    pub mission_title: String,
    pub reward: String,
    pub blockchain_network: String,
    pub crypto_asset: String,
}

impl PayloadEvent for LegendMissionsSendEmailCryptoMissionCompletedPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendMissionsSendEmailCryptoMissionCompleted
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendMissionsSendEmailCodeExchangeMissionCompletedPayload {
    pub user_id: String,
    pub mission_title: String,
    pub code_value: String,
    pub code_description: String,
}

impl PayloadEvent for LegendMissionsSendEmailCodeExchangeMissionCompletedPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendMissionsSendEmailCodeExchangeMissionCompleted
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendMissionsSendEmailNftMissionCompletedPayload {
    pub user_id: String,
    pub mission_title: String,
    pub nft_contract_address: String,
    pub nft_token_id: String,
}

impl PayloadEvent for LegendMissionsSendEmailNftMissionCompletedPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendMissionsSendEmailNftMissionCompleted
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendRankingsRankingsFinishedEventPayload {
    pub completed_rankings: Vec<CompletedRanking>,
}

impl PayloadEvent for LegendRankingsRankingsFinishedEventPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendRankingsRankingsFinished
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendShowcaseProductVirtualDeletedEventPayload {
    /// Unique identifier of the deleted virtual product
    pub product_virtual_id: String,
    /// Slug of the deleted virtual product
    pub product_virtual_slug: String,
}

impl PayloadEvent for LegendShowcaseProductVirtualDeletedEventPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendShowcaseProductVirtualDeleted
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendShowcaseUpdateAllowedMissionSubscriptionIdsEventPayload {
    pub product_virtual_slug: String,
    pub allowed_subscription_ids: Vec<String>,
}

impl PayloadEvent for LegendShowcaseUpdateAllowedMissionSubscriptionIdsEventPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendShowcaseUpdateAllowedMissionSubscriptionIds
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendShowcaseUpdateAllowedRankingSubscriptionIdsEventPayload {
    pub product_virtual_id: String,
    pub allowed_subscription_ids: Vec<String>,
}

impl PayloadEvent for LegendShowcaseUpdateAllowedRankingSubscriptionIdsEventPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendShowcaseUpdateAllowedRankingSubscriptionIds
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Room {
    #[serde(rename = "Id")]
    pub id: String,
    #[serde(rename = "CreateAt")]
    pub create_at: String,
    #[serde(rename = "UpdateAt")]
    pub update_at: String,
    #[serde(rename = "type")]
    pub room_type: String,
    pub name: String,
    pub owner_id: String,
    pub owner_email: String,
    pub max_players: i32,
    pub max_layers: i32,
    pub template_id: String,
    pub have_editor: bool,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct RoomCreatorCreatedRoomPayload {
    #[serde(rename = "room")]
    pub room: Room,
}

impl PayloadEvent for RoomCreatorCreatedRoomPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::RoomCreatorCreatedRoom
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct RoomCreatorUpdatedRoomPayload {
    #[serde(rename = "room")]
    pub room: Room,
}

impl PayloadEvent for RoomCreatorUpdatedRoomPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::RoomCreatorUpdatedRoom
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RoomInventoryUpdateVpBuildingImagePayload {
    pub images: Vec<String>,
    pub room_type: String,
    pub user_id: String,
}

impl PayloadEvent for RoomInventoryUpdateVpBuildingImagePayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::RoomInventoryUpdateVpBuildingImage
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RoomSnapshotBuildingChangeInIslandPayload {
    pub building: String,
    pub user_id: String,
}

impl PayloadEvent for RoomSnapshotBuildingChangeInIslandPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::RoomSnapshotBuildingChangeInIsland
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RoomSnapshotFirstSnapshotPayload {
    pub slug: String,
}

impl PayloadEvent for RoomSnapshotFirstSnapshotPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::RoomSnapshotFirstSnapshot
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SocialBlockChatPayload {
    pub user_id: String,
    pub user_to_block_id: String,
}

impl PayloadEvent for SocialBlockChatPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::SocialBlockChat
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SocialMediaRoomsDeleteInBatchPayload {
    pub bucket_name: String,
    pub file_paths: Vec<String>,
}

impl PayloadEvent for SocialMediaRoomsDeleteInBatchPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::SocialMediaRoomsDeleteInBatch
    }
}

/// Gender represents the possible genders a social user can have.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "UPPERCASE")]
pub enum Gender {
    Male,
    Female,
    Undefined,
}

/// Represents the geographical location of a user
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct UserLocation {
    pub continent: String,
    pub country: String,
    pub region: String,
    pub city: String,
}

/// SocialUser represents the social user model.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SocialUser {
    #[serde(rename = "_id")]
    pub id: String,
    pub username: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub first_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_name: Option<String>,
    pub gender: Gender,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_public_profile: Option<bool>,
    pub followers: Vec<String>,
    pub following: Vec<String>,
    pub email: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub birthday: Option<DateTime<Utc>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub location: Option<UserLocation>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar_screenshot: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_image: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub glb_url: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub social_media: Option<HashMap<String, String>>,
    pub preferences: Vec<String>,
    pub blocked_users: Vec<String>,
    #[serde(rename = "RPMAvatarId", skip_serializing_if = "Option::is_none")]
    pub rpm_avatar_id: Option<String>,
    #[serde(rename = "RPMUserId", skip_serializing_if = "Option::is_none")]
    pub rpm_user_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub paid_price_id: Option<String>,
    pub created_at: DateTime<Utc>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SocialNewUserPayload {
    pub social_user: SocialUser,
}

impl PayloadEvent for SocialNewUserPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::SocialNewUser
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SocialUpdatedUserPayload {
    pub social_user: SocialUser,
}

impl PayloadEvent for SocialUpdatedUserPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::SocialUpdatedUser
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SocialUnblockChatPayload {
    pub user_id: String,
    pub user_to_unblock_id: String,
}

impl PayloadEvent for SocialUnblockChatPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::SocialUnblockChat
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct NotificationConfig {
    pub custom_emails: Option<Vec<String>>,
    pub template_name: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendRankingsNewRankingCreatedEventPayload {
    pub title: String,
    pub description: String,
    pub author_email: String,
    pub reward_type: String,
    pub ends_at: String,
    pub nft_blockchain_network: Option<String>,
    pub nft_contract_address: Option<String>,
    pub wallet_crypto_asset: Option<String>,
    pub notification_config: Option<NotificationConfig>,
}

impl PayloadEvent for LegendRankingsNewRankingCreatedEventPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendRankingsNewRankingCreated
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendRankingsIntermediateRewardEventPayload {
    pub user_id: String,
    pub ranking_id: i32,
    pub intermediate_reward_type: String,
    pub reward_config: serde_json::Value,
    pub template_name: String,
    pub template_data: serde_json::Value,
}

impl PayloadEvent for LegendRankingsIntermediateRewardEventPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendRankingsIntermediateReward
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LegendRankingsParticipationRewardEventPayload {
    pub user_id: String,
    pub ranking_id: i32,
    pub participation_reward_type: String,
    pub reward_config: serde_json::Value,
    pub template_name: String,
    pub template_data: serde_json::Value,
}

impl PayloadEvent for LegendRankingsParticipationRewardEventPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::LegendRankingsParticipationReward
    }
}

// ********** AUDIT ************** //
/// Payload for audit.received event - tracks when event is received before processing
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AuditReceivedPayload {
    /// The microservice that published the original event
    pub publisher_microservice: String,
    /// The microservice that received the event
    pub receiver_microservice: String,
    /// The event that was received
    pub received_event: String,
    /// Timestamp when the event was received (UNIX timestamp in milliseconds)
    pub received_at: u64,
    /// The queue name from which the event was consumed
    pub queue_name: String,
    /// Event identifier for cross-event correlation (UUID v7)
    pub event_id: String,
}

impl PayloadEvent for AuditReceivedPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::AuditReceived
    }
}

/// Payload for audit.processed event - tracks successful event processing
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AuditProcessedPayload {
    /// The microservice that published the original event
    pub publisher_microservice: String,
    /// The microservice that processed the event
    pub processor_microservice: String,
    /// The original event that was processed
    pub processed_event: String,
    /// Timestamp when the event was processed (UNIX timestamp in milliseconds)
    pub processed_at: u64,
    /// The queue name where the event was consumed
    pub queue_name: String,
    /// Event identifier for cross-event correlation (UUID v7)
    pub event_id: String,
}

impl PayloadEvent for AuditProcessedPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::AuditProcessed
    }
}

/// Payload for audit.dead_letter event - tracks when message is rejected/nacked
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AuditDeadLetterPayload {
    /// The microservice that published the original event
    pub publisher_microservice: String,
    /// The microservice that rejected the event
    pub rejector_microservice: String,
    /// The original event that was rejected
    pub rejected_event: String,
    /// Timestamp when the event was rejected (UNIX timestamp in milliseconds)
    pub rejected_at: u64,
    /// The queue name where the event was rejected from
    pub queue_name: String,
    /// Reason for rejection (delay, fibonacci_strategy, etc.)
    pub rejection_reason: String,
    /// Optional retry count
    pub retry_count: Option<u32>,
    /// Event identifier for cross-event correlation (UUID v7)
    pub event_id: String,
}

impl PayloadEvent for AuditDeadLetterPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::AuditDeadLetter
    }
}

/// Payload for audit.published event - tracks when event is published at the source microservice
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AuditPublishedPayload {
    /// The microservice that published the event
    pub publisher_microservice: String,
    /// The event that was published
    pub published_event: String,
    /// Timestamp when the event was published (UNIX timestamp in milliseconds)
    pub published_at: u64,
    /// Event identifier for cross-event correlation (UUID v7)
    pub event_id: String,
}

impl PayloadEvent for AuditPublishedPayload {
    fn event_type(&self) -> MicroserviceEvent {
        MicroserviceEvent::AuditPublished
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::time::{SystemTime, UNIX_EPOCH};

    // Year 2020 in milliseconds (Jan 1, 2020 00:00:00 UTC)
    const YEAR_2020_MS: u64 = 1577836800000;
    // Year 2030 in milliseconds (Jan 1, 2030 00:00:00 UTC)
    const YEAR_2030_MS: u64 = 1893456000000;

    #[test]
    fn test_audit_published_payload_timestamp_precision() {
        let current_ms = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_millis() as u64;

        let payload = AuditPublishedPayload {
            publisher_microservice: "test-service".to_string(),
            published_event: "test.event".to_string(),
            published_at: current_ms,
            event_id: "test-uuid".to_string(),
        };

        // Verify timestamp is in reasonable range (year 2020-2030)
        assert!(
            payload.published_at > YEAR_2020_MS,
            "Timestamp {} should be after year 2020 ({})",
            payload.published_at,
            YEAR_2020_MS
        );
        assert!(
            payload.published_at < YEAR_2030_MS,
            "Timestamp {} should be before year 2030 ({})",
            payload.published_at,
            YEAR_2030_MS
        );

        // Verify millisecond precision (should have 3+ more digits than seconds)
        let as_seconds = payload.published_at / 1000;
        assert!(
            payload.published_at > as_seconds * 1000,
            "Timestamp should have millisecond precision, not just seconds"
        );
    }

    #[test]
    fn test_audit_received_payload_timestamp_precision() {
        let current_ms = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_millis() as u64;

        let payload = AuditReceivedPayload {
            publisher_microservice: "publisher-service".to_string(),
            receiver_microservice: "receiver-service".to_string(),
            received_event: "test.event".to_string(),
            received_at: current_ms,
            queue_name: "test_queue".to_string(),
            event_id: "test-uuid".to_string(),
        };

        // Verify timestamp is in reasonable range
        assert!(payload.received_at > YEAR_2020_MS);
        assert!(payload.received_at < YEAR_2030_MS);

        // Verify millisecond precision
        let as_seconds = payload.received_at / 1000;
        assert!(payload.received_at > as_seconds * 1000);
    }

    #[test]
    fn test_audit_processed_payload_timestamp_precision() {
        let current_ms = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_millis() as u64;

        let payload = AuditProcessedPayload {
            publisher_microservice: "publisher-service".to_string(),
            processor_microservice: "processor-service".to_string(),
            processed_event: "test.event".to_string(),
            processed_at: current_ms,
            queue_name: "test_queue".to_string(),
            event_id: "test-uuid".to_string(),
        };

        // Verify timestamp is in reasonable range
        assert!(payload.processed_at > YEAR_2020_MS);
        assert!(payload.processed_at < YEAR_2030_MS);

        // Verify millisecond precision
        let as_seconds = payload.processed_at / 1000;
        assert!(payload.processed_at > as_seconds * 1000);
    }

    #[test]
    fn test_audit_dead_letter_payload_timestamp_precision() {
        let current_ms = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_millis() as u64;

        let payload = AuditDeadLetterPayload {
            publisher_microservice: "publisher-service".to_string(),
            rejector_microservice: "rejector-service".to_string(),
            rejected_event: "test.event".to_string(),
            rejected_at: current_ms,
            queue_name: "test_queue".to_string(),
            rejection_reason: "test_reason".to_string(),
            retry_count: Some(3),
            event_id: "test-uuid".to_string(),
        };

        // Verify timestamp is in reasonable range
        assert!(payload.rejected_at > YEAR_2020_MS);
        assert!(payload.rejected_at < YEAR_2030_MS);

        // Verify millisecond precision
        let as_seconds = payload.rejected_at / 1000;
        assert!(payload.rejected_at > as_seconds * 1000);
    }

    #[test]
    fn test_millisecond_vs_second_timestamps() {
        // Generate timestamp in milliseconds
        let timestamp_ms = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_millis() as u64;

        // Generate timestamp in seconds (old way)
        let timestamp_s = SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_secs();

        // Milliseconds should be ~1000x larger than seconds
        assert!(
            timestamp_ms > timestamp_s * 100,
            "Millisecond timestamp {} should be much larger than second timestamp {}",
            timestamp_ms,
            timestamp_s
        );

        // If treated as milliseconds, seconds would show as 1970
        // (timestamp_s in milliseconds would be < year 2000)
        assert!(
            timestamp_s < YEAR_2020_MS,
            "Second timestamp {} would be before year 2000 if treated as milliseconds",
            timestamp_s
        );
    }
}