optirs-core 0.3.2

OptiRS core optimization algorithms and utilities
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
// Academic conference integration and submission tools
//
// This module provides tools for managing conference submissions,
// tracking deadlines, and preparing submission materials.

use crate::error::{OptimError, Result};
use chrono::{DateTime, Datelike, TimeZone, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Conference database and submission manager
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConferenceManager {
    /// Known conferences
    pub conferences: HashMap<String, Conference>,
    /// Submission tracking
    pub submissions: Vec<Submission>,
    /// Deadline alerts
    pub alerts: Vec<DeadlineAlert>,
}

/// Academic conference information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Conference {
    /// Conference identifier
    pub id: String,
    /// Conference name
    pub name: String,
    /// Conference abbreviation
    pub abbreviation: String,
    /// Conference description
    pub description: String,
    /// Conference URL
    pub url: String,
    /// Conference ranking/tier
    pub ranking: ConferenceRanking,
    /// Research areas
    pub research_areas: Vec<String>,
    /// Annual occurrence
    pub annual: bool,
    /// Conference series information
    pub series_info: SeriesInfo,
    /// Important dates
    pub dates: ConferenceDates,
    /// Submission requirements
    pub requirements: SubmissionRequirements,
    /// Review process
    pub review_process: ReviewProcess,
}

/// Conference ranking/tier
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ConferenceRanking {
    /// Top-tier (A*)
    TopTier,
    /// High-quality (A)
    HighQuality,
    /// Good (B)
    Good,
    /// Acceptable (C)
    Acceptable,
    /// Emerging
    Emerging,
    /// Workshop
    Workshop,
    /// Unranked
    Unranked,
}

/// Conference series information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SeriesInfo {
    /// Series number (e.g., 35th)
    pub series_number: u32,
    /// Year
    pub year: u32,
    /// Location
    pub location: String,
    /// Country
    pub country: String,
    /// Conference format
    pub format: ConferenceFormat,
}

/// Conference format
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ConferenceFormat {
    /// In-person conference
    InPerson,
    /// Virtual conference
    Virtual,
    /// Hybrid conference
    Hybrid,
}

/// Important conference dates
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConferenceDates {
    /// Abstract submission deadline
    pub abstract_deadline: Option<DateTime<Utc>>,
    /// Paper submission deadline
    pub paper_deadline: DateTime<Utc>,
    /// Notification date
    pub notification_date: DateTime<Utc>,
    /// Camera-ready deadline
    pub camera_ready_deadline: DateTime<Utc>,
    /// Conference start date
    pub conference_start: DateTime<Utc>,
    /// Conference end date
    pub conference_end: DateTime<Utc>,
}

/// Submission requirements
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SubmissionRequirements {
    /// Page limit
    pub page_limit: u32,
    /// Word limit
    pub word_limit: Option<u32>,
    /// Format requirements
    pub format: FormatRequirements,
    /// Required sections
    pub required_sections: Vec<String>,
    /// Supplementary material allowed
    pub supplementary_allowed: bool,
    /// Anonymous submission required
    pub anonymous_submission: bool,
    /// Double-blind review
    pub double_blind: bool,
}

/// Format requirements
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FormatRequirements {
    /// Document template
    pub template: String,
    /// Font size
    pub font_size: u32,
    /// Line spacing
    pub line_spacing: f64,
    /// Margins
    pub margins: String,
    /// Citation style
    pub citation_style: String,
    /// File format
    pub file_format: Vec<String>,
}

/// Review process information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReviewProcess {
    /// Number of reviewers per paper
    pub reviewers_per_paper: u32,
    /// Review criteria
    pub review_criteria: Vec<String>,
    /// Rebuttal allowed
    pub rebuttal_allowed: bool,
    /// Acceptance rate (if known)
    pub acceptance_rate: Option<f64>,
    /// Review format
    pub review_format: ReviewFormat,
}

/// Review format
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ReviewFormat {
    /// Numerical scores
    NumericalScores,
    /// Written reviews only
    WrittenOnly,
    /// Mixed format
    Mixed,
}

/// Conference submission
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Submission {
    /// Submission ID
    pub id: String,
    /// Conference ID
    pub conference_id: String,
    /// Paper/publication ID
    pub paper_id: String,
    /// Submission status
    pub status: SubmissionStatus,
    /// Submission date
    pub submitted_at: DateTime<Utc>,
    /// Track/category
    pub track: Option<String>,
    /// Submission materials
    pub materials: SubmissionMaterials,
    /// Review information
    pub reviews: Vec<Review>,
    /// Decision information
    pub decision: Option<Decision>,
}

/// Submission status
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum SubmissionStatus {
    /// Draft
    Draft,
    /// Submitted
    Submitted,
    /// Under review
    UnderReview,
    /// Rebuttal period
    Rebuttal,
    /// Decision made
    Decided,
    /// Camera-ready submitted
    CameraReady,
    /// Withdrawn
    Withdrawn,
}

/// Submission materials
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SubmissionMaterials {
    /// Main paper file
    pub paper_file: String,
    /// Supplementary materials
    pub supplementary_files: Vec<String>,
    /// Abstract
    pub abstracttext: String,
    /// Keywords
    pub keywords: Vec<String>,
    /// Author information (if not anonymous)
    pub authors: Option<Vec<String>>,
}

/// Review information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Review {
    /// Review ID
    pub id: String,
    /// Reviewer (anonymous)
    pub reviewer: String,
    /// Overall score
    pub overall_score: Option<f64>,
    /// Detailed scores
    pub detailed_scores: HashMap<String, f64>,
    /// Written review
    pub reviewtext: String,
    /// Recommendation
    pub recommendation: ReviewRecommendation,
    /// Review date
    pub reviewed_at: DateTime<Utc>,
}

/// Review recommendations
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ReviewRecommendation {
    /// Strong accept
    StrongAccept,
    /// Accept
    Accept,
    /// Weak accept
    WeakAccept,
    /// Borderline
    Borderline,
    /// Weak reject
    WeakReject,
    /// Reject
    Reject,
    /// Strong reject
    StrongReject,
}

/// Conference decision
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Decision {
    /// Decision outcome
    pub outcome: DecisionOutcome,
    /// Decision date
    pub decided_at: DateTime<Utc>,
    /// Editor comments
    pub editor_comments: Option<String>,
    /// Required revisions
    pub required_revisions: Vec<String>,
}

/// Decision outcomes
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum DecisionOutcome {
    /// Accept
    Accept,
    /// Accept with minor revisions
    AcceptMinorRevisions,
    /// Accept with major revisions
    AcceptMajorRevisions,
    /// Conditional accept
    ConditionalAccept,
    /// Reject
    Reject,
    /// Reject and resubmit
    RejectAndResubmit,
}

/// Deadline alert
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeadlineAlert {
    /// Alert ID
    pub id: String,
    /// Conference ID
    pub conference_id: String,
    /// Deadline type
    pub deadline_type: DeadlineType,
    /// Alert date
    pub alert_date: DateTime<Utc>,
    /// Days before deadline
    pub days_before: u32,
    /// Alert message
    pub message: String,
    /// Alert sent
    pub sent: bool,
}

/// Types of deadlines
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum DeadlineType {
    /// Abstract submission
    AbstractSubmission,
    /// Paper submission
    PaperSubmission,
    /// Notification
    Notification,
    /// Camera-ready
    CameraReady,
    /// Conference start
    ConferenceStart,
}

impl Default for ConferenceManager {
    fn default() -> Self {
        Self::new()
    }
}

impl ConferenceManager {
    /// Create a new conference manager
    pub fn new() -> Self {
        Self {
            conferences: HashMap::new(),
            submissions: Vec::new(),
            alerts: Vec::new(),
        }
    }

    /// Add a conference to the database
    pub fn add_conference(&mut self, conference: Conference) {
        self.conferences.insert(conference.id.clone(), conference);
    }

    /// Submit a paper to a conference
    pub fn submit_paper(
        &mut self,
        conference_id: &str,
        paper_id: &str,
        materials: SubmissionMaterials,
    ) -> Result<String> {
        if !self.conferences.contains_key(conference_id) {
            return Err(OptimError::InvalidConfig(format!(
                "Conference '{}' not found",
                conference_id
            )));
        }

        let submission_id = uuid::Uuid::new_v4().to_string();
        let submission = Submission {
            id: submission_id.clone(),
            conference_id: conference_id.to_string(),
            paper_id: paper_id.to_string(),
            status: SubmissionStatus::Submitted,
            submitted_at: Utc::now(),
            track: None,
            materials,
            reviews: Vec::new(),
            decision: None,
        };

        self.submissions.push(submission);
        Ok(submission_id)
    }

    /// Get upcoming deadlines
    pub fn get_upcoming_deadlines(
        &self,
        days_ahead: u32,
    ) -> Vec<(&Conference, DeadlineType, DateTime<Utc>)> {
        let mut deadlines = Vec::new();
        let now = Utc::now();
        let future_limit = now + chrono::Duration::days(days_ahead as i64);

        for conference in self.conferences.values() {
            let dates = &conference.dates;

            if let Some(abstract_deadline) = dates.abstract_deadline {
                if abstract_deadline > now && abstract_deadline <= future_limit {
                    deadlines.push((
                        conference,
                        DeadlineType::AbstractSubmission,
                        abstract_deadline,
                    ));
                }
            }

            if dates.paper_deadline > now && dates.paper_deadline <= future_limit {
                deadlines.push((
                    conference,
                    DeadlineType::PaperSubmission,
                    dates.paper_deadline,
                ));
            }

            if dates.notification_date > now && dates.notification_date <= future_limit {
                deadlines.push((
                    conference,
                    DeadlineType::Notification,
                    dates.notification_date,
                ));
            }

            if dates.camera_ready_deadline > now && dates.camera_ready_deadline <= future_limit {
                deadlines.push((
                    conference,
                    DeadlineType::CameraReady,
                    dates.camera_ready_deadline,
                ));
            }

            if dates.conference_start > now && dates.conference_start <= future_limit {
                deadlines.push((
                    conference,
                    DeadlineType::ConferenceStart,
                    dates.conference_start,
                ));
            }
        }

        // Sort by deadline date
        deadlines.sort_by_key(|a| a.2);
        deadlines
    }

    /// Scan all known conferences and create [`DeadlineAlert`]s for any
    /// still-future deadline that falls within one of the `days_before`
    /// thresholds (e.g. `&[30, 7, 1]` for month/week/day-out reminders),
    /// appending them to `self.alerts`. Idempotent: calling this repeatedly
    /// (e.g. once a day) will not create duplicate alerts for the same
    /// (conference, deadline type, threshold) combination. Returns the
    /// alerts newly created by this call.
    pub fn generate_deadline_alerts(&mut self, days_before: &[u32]) -> Vec<DeadlineAlert> {
        let now = Utc::now();

        // Snapshot deadlines up front so we are not borrowing
        // `self.conferences` while mutating `self.alerts` below.
        let mut deadline_entries: Vec<(String, DeadlineType, DateTime<Utc>)> = Vec::new();
        for conference in self.conferences.values() {
            let dates = &conference.dates;
            if let Some(abstract_deadline) = dates.abstract_deadline {
                deadline_entries.push((
                    conference.id.clone(),
                    DeadlineType::AbstractSubmission,
                    abstract_deadline,
                ));
            }
            deadline_entries.push((
                conference.id.clone(),
                DeadlineType::PaperSubmission,
                dates.paper_deadline,
            ));
            deadline_entries.push((
                conference.id.clone(),
                DeadlineType::Notification,
                dates.notification_date,
            ));
            deadline_entries.push((
                conference.id.clone(),
                DeadlineType::CameraReady,
                dates.camera_ready_deadline,
            ));
            deadline_entries.push((
                conference.id.clone(),
                DeadlineType::ConferenceStart,
                dates.conference_start,
            ));
        }

        let mut new_alerts = Vec::new();
        for (conference_id, deadline_type, deadline) in deadline_entries {
            if deadline <= now {
                continue;
            }
            let days_remaining = (deadline - now).num_days().max(0) as u32;

            for &threshold in days_before {
                if days_remaining > threshold {
                    continue;
                }

                let already_exists = self.alerts.iter().any(|alert| {
                    alert.conference_id == conference_id
                        && alert.deadline_type == deadline_type
                        && alert.days_before == threshold
                });
                if already_exists {
                    continue;
                }

                let alert = DeadlineAlert {
                    id: uuid::Uuid::new_v4().to_string(),
                    conference_id: conference_id.clone(),
                    deadline_type: deadline_type.clone(),
                    alert_date: now,
                    days_before: threshold,
                    message: format!(
                        "{deadline_type:?} deadline for conference '{conference_id}' is in \
                         {days_remaining} day(s) ({deadline})"
                    ),
                    sent: false,
                };
                self.alerts.push(alert.clone());
                new_alerts.push(alert);
            }
        }

        new_alerts
    }

    /// Alerts that have not yet been marked as sent, most recent first.
    pub fn pending_alerts(&self) -> Vec<&DeadlineAlert> {
        self.alerts.iter().filter(|alert| !alert.sent).collect()
    }

    /// Mark an alert as sent (e.g. after successfully notifying a user).
    pub fn mark_alert_sent(&mut self, alert_id: &str) -> Result<()> {
        let alert = self
            .alerts
            .iter_mut()
            .find(|alert| alert.id == alert_id)
            .ok_or_else(|| OptimError::InvalidConfig(format!("alert '{alert_id}' not found")))?;
        alert.sent = true;
        Ok(())
    }

    /// Search conferences by research area
    pub fn search_conferences(&self, research_area: &str) -> Vec<&Conference> {
        self.conferences
            .values()
            .filter(|conf| {
                conf.research_areas
                    .iter()
                    .any(|area| area.to_lowercase().contains(&research_area.to_lowercase()))
            })
            .collect()
    }

    /// Get conferences by ranking
    pub fn get_conferences_by_ranking(&self, ranking: ConferenceRanking) -> Vec<&Conference> {
        self.conferences
            .values()
            .filter(|conf| conf.ranking == ranking)
            .collect()
    }

    /// Create standard ML/AI conferences, using each conference's next
    /// upcoming edition (by real submission deadline) rather than a fixed
    /// calendar year, so [`Self::get_upcoming_deadlines`] can actually find
    /// them no matter when this is called.
    pub fn load_standard_conferences(&mut self) {
        self.add_conference(Self::next_upcoming_edition(Self::create_neurips_conference));
        self.add_conference(Self::next_upcoming_edition(Self::create_icml_conference));
        self.add_conference(Self::next_upcoming_edition(Self::create_iclr_conference));
        self.add_conference(Self::next_upcoming_edition(Self::create_aaai_conference));
        self.add_conference(Self::next_upcoming_edition(Self::create_ijcai_conference));
    }

    /// Build successive editions of a conference (via `build`, which takes
    /// the edition's label year, e.g. 2027 for "NeurIPS 2027") until one is
    /// found whose paper submission deadline has not yet passed, and return
    /// that edition.
    ///
    /// Conference templates below are seasonal (same month/day pattern every
    /// year), so trying a handful of consecutive label years is always
    /// sufficient; this makes the loaded deadlines self-correcting as real
    /// time passes, instead of frozen at whatever year they were written in.
    fn next_upcoming_edition(build: fn(i32) -> Conference) -> Conference {
        let now = Utc::now();
        let start_year = now.year();
        let last_candidate = start_year + 3;
        for candidate_year in start_year..=last_candidate {
            let conference = build(candidate_year);
            if conference.dates.paper_deadline > now {
                return conference;
            }
        }
        // Unreachable in practice for an annual conference (deadlines cannot
        // trail 3+ years behind "now" for every candidate), but stay honest
        // and return a well-formed, self-consistent edition rather than
        // panicking.
        build(last_candidate)
    }

    fn create_neurips_conference(edition_year: i32) -> Conference {
        Conference {
            id: format!("neurips{edition_year}"),
            name: "Conference on Neural Information Processing Systems".to_string(),
            abbreviation: "NeurIPS".to_string(),
            description: "Premier conference on neural information processing systems".to_string(),
            url: "https://neurips.cc/".to_string(),
            ranking: ConferenceRanking::TopTier,
            research_areas: vec![
                "Machine Learning".to_string(),
                "Deep Learning".to_string(),
                "Neural Networks".to_string(),
                "Optimization".to_string(),
            ],
            annual: true,
            series_info: SeriesInfo {
                series_number: 38,
                year: edition_year as u32,
                location: "Vancouver".to_string(),
                country: "Canada".to_string(),
                format: ConferenceFormat::Hybrid,
            },
            dates: ConferenceDates {
                abstract_deadline: Some(
                    chrono::Utc
                        .with_ymd_and_hms(edition_year, 5, 15, 23, 59, 59)
                        .single()
                        .expect("invalid datetime"),
                ),
                paper_deadline: chrono::Utc
                    .with_ymd_and_hms(edition_year, 5, 22, 23, 59, 59)
                    .single()
                    .expect("invalid datetime"),
                notification_date: chrono::Utc
                    .with_ymd_and_hms(edition_year, 9, 25, 12, 0, 0)
                    .single()
                    .expect("invalid datetime"),
                camera_ready_deadline: chrono::Utc
                    .with_ymd_and_hms(edition_year, 10, 30, 23, 59, 59)
                    .single()
                    .expect("invalid datetime"),
                conference_start: chrono::Utc
                    .with_ymd_and_hms(edition_year, 12, 10, 9, 0, 0)
                    .single()
                    .expect("invalid datetime"),
                conference_end: chrono::Utc
                    .with_ymd_and_hms(edition_year, 12, 16, 18, 0, 0)
                    .single()
                    .expect("invalid datetime"),
            },
            requirements: SubmissionRequirements {
                page_limit: 9,
                word_limit: None,
                format: FormatRequirements {
                    template: format!("NeurIPS {edition_year} LaTeX template"),
                    font_size: 10,
                    line_spacing: 1.0,
                    margins: "1 inch".to_string(),
                    citation_style: "NeurIPS".to_string(),
                    file_format: vec!["PDF".to_string()],
                },
                required_sections: vec![
                    "Abstract".to_string(),
                    "Introduction".to_string(),
                    "Related Work".to_string(),
                    "Method".to_string(),
                    "Experiments".to_string(),
                    "Conclusion".to_string(),
                ],
                supplementary_allowed: true,
                anonymous_submission: true,
                double_blind: true,
            },
            review_process: ReviewProcess {
                reviewers_per_paper: 3,
                review_criteria: vec![
                    "Technical Quality".to_string(),
                    "Novelty".to_string(),
                    "Significance".to_string(),
                    "Clarity".to_string(),
                ],
                rebuttal_allowed: true,
                acceptance_rate: Some(0.26), // Approximately 26%
                review_format: ReviewFormat::Mixed,
            },
        }
    }

    fn create_icml_conference(edition_year: i32) -> Conference {
        Conference {
            id: format!("icml{edition_year}"),
            name: "International Conference on Machine Learning".to_string(),
            abbreviation: "ICML".to_string(),
            description: "Premier international conference on machine learning".to_string(),
            url: "https://icml.cc/".to_string(),
            ranking: ConferenceRanking::TopTier,
            research_areas: vec![
                "Machine Learning".to_string(),
                "Optimization".to_string(),
                "Statistical Learning".to_string(),
                "Deep Learning".to_string(),
            ],
            annual: true,
            series_info: SeriesInfo {
                series_number: 41,
                year: edition_year as u32,
                location: "Vienna".to_string(),
                country: "Austria".to_string(),
                format: ConferenceFormat::Hybrid,
            },
            dates: ConferenceDates {
                abstract_deadline: None,
                paper_deadline: chrono::Utc
                    .with_ymd_and_hms(edition_year, 2, 1, 23, 59, 59)
                    .single()
                    .expect("invalid datetime"),
                notification_date: chrono::Utc
                    .with_ymd_and_hms(edition_year, 5, 1, 12, 0, 0)
                    .single()
                    .expect("invalid datetime"),
                camera_ready_deadline: chrono::Utc
                    .with_ymd_and_hms(edition_year, 6, 1, 23, 59, 59)
                    .single()
                    .expect("invalid datetime"),
                conference_start: chrono::Utc
                    .with_ymd_and_hms(edition_year, 7, 21, 9, 0, 0)
                    .single()
                    .expect("invalid datetime"),
                conference_end: chrono::Utc
                    .with_ymd_and_hms(edition_year, 7, 27, 18, 0, 0)
                    .single()
                    .expect("invalid datetime"),
            },
            requirements: SubmissionRequirements {
                page_limit: 8,
                word_limit: None,
                format: FormatRequirements {
                    template: format!("ICML {edition_year} LaTeX template"),
                    font_size: 10,
                    line_spacing: 1.0,
                    margins: "1 inch".to_string(),
                    citation_style: "ICML".to_string(),
                    file_format: vec!["PDF".to_string()],
                },
                required_sections: vec![
                    "Abstract".to_string(),
                    "Introduction".to_string(),
                    "Methods".to_string(),
                    "Results".to_string(),
                    "Conclusion".to_string(),
                ],
                supplementary_allowed: true,
                anonymous_submission: true,
                double_blind: true,
            },
            review_process: ReviewProcess {
                reviewers_per_paper: 3,
                review_criteria: vec![
                    "Technical Quality".to_string(),
                    "Clarity".to_string(),
                    "Originality".to_string(),
                    "Significance".to_string(),
                ],
                rebuttal_allowed: true,
                acceptance_rate: Some(0.23), // Approximately 23%
                review_format: ReviewFormat::Mixed,
            },
        }
    }

    fn create_iclr_conference(edition_year: i32) -> Conference {
        let prior_year = edition_year - 1;
        Conference {
            id: format!("iclr{edition_year}"),
            name: "International Conference on Learning Representations".to_string(),
            abbreviation: "ICLR".to_string(),
            description: "Conference focused on learning representations".to_string(),
            url: "https://iclr.cc/".to_string(),
            ranking: ConferenceRanking::TopTier,
            research_areas: vec![
                "Deep Learning".to_string(),
                "Representation Learning".to_string(),
                "Neural Networks".to_string(),
                "Optimization".to_string(),
            ],
            annual: true,
            series_info: SeriesInfo {
                series_number: 12,
                year: edition_year as u32,
                location: "Vienna".to_string(),
                country: "Austria".to_string(),
                format: ConferenceFormat::Hybrid,
            },
            dates: ConferenceDates {
                abstract_deadline: Some(
                    chrono::Utc
                        .with_ymd_and_hms(prior_year, 9, 28, 23, 59, 59)
                        .single()
                        .expect("invalid datetime"),
                ),
                paper_deadline: chrono::Utc
                    .with_ymd_and_hms(prior_year, 10, 2, 23, 59, 59)
                    .single()
                    .expect("invalid datetime"),
                notification_date: chrono::Utc
                    .with_ymd_and_hms(edition_year, 1, 15, 12, 0, 0)
                    .single()
                    .expect("invalid datetime"),
                // Feb 28 rather than 29: this is a synthetic template date
                // (not a specific historical deadline), and `edition_year`
                // varies at runtime, so it must stay valid on non-leap years.
                camera_ready_deadline: chrono::Utc
                    .with_ymd_and_hms(edition_year, 2, 28, 23, 59, 59)
                    .single()
                    .expect("invalid datetime"),
                conference_start: chrono::Utc
                    .with_ymd_and_hms(edition_year, 5, 7, 9, 0, 0)
                    .single()
                    .expect("invalid datetime"),
                conference_end: chrono::Utc
                    .with_ymd_and_hms(edition_year, 5, 11, 18, 0, 0)
                    .single()
                    .expect("invalid datetime"),
            },
            requirements: SubmissionRequirements {
                page_limit: 9,
                word_limit: None,
                format: FormatRequirements {
                    template: format!("ICLR {edition_year} LaTeX template"),
                    font_size: 10,
                    line_spacing: 1.0,
                    margins: "1 inch".to_string(),
                    citation_style: "ICLR".to_string(),
                    file_format: vec!["PDF".to_string()],
                },
                required_sections: vec![
                    "Abstract".to_string(),
                    "Introduction".to_string(),
                    "Related Work".to_string(),
                    "Method".to_string(),
                    "Experiments".to_string(),
                    "Conclusion".to_string(),
                ],
                supplementary_allowed: true,
                anonymous_submission: true,
                double_blind: true,
            },
            review_process: ReviewProcess {
                reviewers_per_paper: 3,
                review_criteria: vec![
                    "Technical Quality".to_string(),
                    "Clarity".to_string(),
                    "Originality".to_string(),
                    "Significance".to_string(),
                ],
                rebuttal_allowed: true,
                acceptance_rate: Some(0.31), // Approximately 31%
                review_format: ReviewFormat::Mixed,
            },
        }
    }

    fn create_aaai_conference(edition_year: i32) -> Conference {
        let prior_year = edition_year - 1;
        Conference {
            id: format!("aaai{edition_year}"),
            name: "AAAI Conference on Artificial Intelligence".to_string(),
            abbreviation: "AAAI".to_string(),
            description: "Conference on artificial intelligence".to_string(),
            url: "https://aaai.org/".to_string(),
            ranking: ConferenceRanking::TopTier,
            research_areas: vec![
                "Artificial Intelligence".to_string(),
                "Machine Learning".to_string(),
                "Knowledge Representation".to_string(),
                "Planning".to_string(),
            ],
            annual: true,
            series_info: SeriesInfo {
                series_number: 38,
                year: edition_year as u32,
                location: "Vancouver".to_string(),
                country: "Canada".to_string(),
                format: ConferenceFormat::Hybrid,
            },
            dates: ConferenceDates {
                abstract_deadline: Some(
                    chrono::Utc
                        .with_ymd_and_hms(prior_year, 8, 15, 23, 59, 59)
                        .single()
                        .expect("invalid datetime"),
                ),
                paper_deadline: chrono::Utc
                    .with_ymd_and_hms(prior_year, 8, 19, 23, 59, 59)
                    .single()
                    .expect("invalid datetime"),
                notification_date: chrono::Utc
                    .with_ymd_and_hms(prior_year, 12, 9, 12, 0, 0)
                    .single()
                    .expect("invalid datetime"),
                camera_ready_deadline: chrono::Utc
                    .with_ymd_and_hms(edition_year, 1, 15, 23, 59, 59)
                    .single()
                    .expect("invalid datetime"),
                conference_start: chrono::Utc
                    .with_ymd_and_hms(edition_year, 2, 20, 9, 0, 0)
                    .single()
                    .expect("invalid datetime"),
                conference_end: chrono::Utc
                    .with_ymd_and_hms(edition_year, 2, 27, 18, 0, 0)
                    .single()
                    .expect("invalid datetime"),
            },
            requirements: SubmissionRequirements {
                page_limit: 7,
                word_limit: None,
                format: FormatRequirements {
                    template: format!("AAAI {edition_year} LaTeX template"),
                    font_size: 10,
                    line_spacing: 1.0,
                    margins: "0.75 inch".to_string(),
                    citation_style: "AAAI".to_string(),
                    file_format: vec!["PDF".to_string()],
                },
                required_sections: vec![
                    "Abstract".to_string(),
                    "Introduction".to_string(),
                    "Related Work".to_string(),
                    "Approach".to_string(),
                    "Experiments".to_string(),
                    "Conclusion".to_string(),
                ],
                supplementary_allowed: false,
                anonymous_submission: true,
                double_blind: true,
            },
            review_process: ReviewProcess {
                reviewers_per_paper: 3,
                review_criteria: vec![
                    "Technical Quality".to_string(),
                    "Novelty".to_string(),
                    "Significance".to_string(),
                    "Clarity".to_string(),
                ],
                rebuttal_allowed: false,
                acceptance_rate: Some(0.23), // Approximately 23%
                review_format: ReviewFormat::NumericalScores,
            },
        }
    }

    fn create_ijcai_conference(edition_year: i32) -> Conference {
        Conference {
            id: format!("ijcai{edition_year}"),
            name: "International Joint Conference on Artificial Intelligence".to_string(),
            abbreviation: "IJCAI".to_string(),
            description: "International conference on artificial intelligence".to_string(),
            url: "https://ijcai.org/".to_string(),
            ranking: ConferenceRanking::TopTier,
            research_areas: vec![
                "Artificial Intelligence".to_string(),
                "Machine Learning".to_string(),
                "Automated Reasoning".to_string(),
                "Multi-agent Systems".to_string(),
            ],
            annual: true,
            series_info: SeriesInfo {
                series_number: 33,
                year: edition_year as u32,
                location: "Jeju".to_string(),
                country: "South Korea".to_string(),
                format: ConferenceFormat::Hybrid,
            },
            dates: ConferenceDates {
                abstract_deadline: Some(
                    chrono::Utc
                        .with_ymd_and_hms(edition_year, 1, 17, 23, 59, 59)
                        .single()
                        .expect("invalid datetime"),
                ),
                paper_deadline: chrono::Utc
                    .with_ymd_and_hms(edition_year, 1, 24, 23, 59, 59)
                    .single()
                    .expect("invalid datetime"),
                notification_date: chrono::Utc
                    .with_ymd_and_hms(edition_year, 4, 16, 12, 0, 0)
                    .single()
                    .expect("invalid datetime"),
                camera_ready_deadline: chrono::Utc
                    .with_ymd_and_hms(edition_year, 5, 15, 23, 59, 59)
                    .single()
                    .expect("invalid datetime"),
                conference_start: chrono::Utc
                    .with_ymd_and_hms(edition_year, 8, 3, 9, 0, 0)
                    .single()
                    .expect("invalid datetime"),
                conference_end: chrono::Utc
                    .with_ymd_and_hms(edition_year, 8, 9, 18, 0, 0)
                    .single()
                    .expect("invalid datetime"),
            },
            requirements: SubmissionRequirements {
                page_limit: 7,
                word_limit: None,
                format: FormatRequirements {
                    template: format!("IJCAI {edition_year} LaTeX template"),
                    font_size: 10,
                    line_spacing: 1.0,
                    margins: "0.75 inch".to_string(),
                    citation_style: "IJCAI".to_string(),
                    file_format: vec!["PDF".to_string()],
                },
                required_sections: vec![
                    "Abstract".to_string(),
                    "Introduction".to_string(),
                    "Background".to_string(),
                    "Approach".to_string(),
                    "Experiments".to_string(),
                    "Conclusion".to_string(),
                ],
                supplementary_allowed: false,
                anonymous_submission: true,
                double_blind: true,
            },
            review_process: ReviewProcess {
                reviewers_per_paper: 3,
                review_criteria: vec![
                    "Technical Quality".to_string(),
                    "Novelty".to_string(),
                    "Significance".to_string(),
                    "Clarity".to_string(),
                ],
                rebuttal_allowed: true,
                acceptance_rate: Some(0.15), // Approximately 15%
                review_format: ReviewFormat::Mixed,
            },
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_conference_manager_creation() {
        let manager = ConferenceManager::new();
        assert!(manager.conferences.is_empty());
        assert!(manager.submissions.is_empty());
    }

    #[test]
    fn test_load_standard_conferences() {
        let mut manager = ConferenceManager::new();
        manager.load_standard_conferences();

        assert_eq!(manager.conferences.len(), 5);
        let abbreviations: Vec<&str> = manager
            .conferences
            .values()
            .map(|c| c.abbreviation.as_str())
            .collect();
        for expected in ["NeurIPS", "ICML", "ICLR", "AAAI", "IJCAI"] {
            assert!(
                abbreviations.contains(&expected),
                "missing {expected} in {abbreviations:?}"
            );
        }
    }

    // Regression test for F78: the standard conference templates had every
    // deadline hardcoded to a fixed calendar year (2023/2024). Once that
    // year passed, `get_upcoming_deadlines` could never return anything for
    // them again. `load_standard_conferences` must now always select an
    // edition whose deadlines lie in the future, however far "now" is from
    // when this code was written.
    #[test]
    fn test_load_standard_conferences_deadlines_are_in_the_future() {
        let mut manager = ConferenceManager::new();
        manager.load_standard_conferences();
        let now = Utc::now();

        for conference in manager.conferences.values() {
            assert!(
                conference.dates.paper_deadline > now,
                "{}'s paper deadline {} is not in the future (now = {now})",
                conference.abbreviation,
                conference.dates.paper_deadline
            );
        }

        // With a wide enough horizon, every loaded conference must surface
        // at least one upcoming deadline -- this was unconditionally empty
        // before the fix.
        let upcoming = manager.get_upcoming_deadlines(400);
        assert!(
            !upcoming.is_empty(),
            "expected at least one upcoming deadline within 400 days"
        );
    }

    // Regression test for F78: `alerts` was declared on `ConferenceManager`
    // but no code path ever wrote to it.
    #[test]
    fn test_generate_deadline_alerts_populates_alerts() {
        let mut manager = ConferenceManager::new();
        manager.load_standard_conferences();
        assert!(manager.alerts.is_empty());

        // A very wide threshold guarantees at least the paper deadlines
        // (already asserted to be in the future) fall inside the window.
        let created = manager.generate_deadline_alerts(&[400]);
        assert!(!created.is_empty());
        assert_eq!(manager.alerts.len(), created.len());
        assert!(manager.alerts.iter().all(|a| !a.sent));
        assert_eq!(manager.pending_alerts().len(), manager.alerts.len());

        // Idempotent: calling again with the same thresholds must not
        // duplicate alerts for the same (conference, type, threshold).
        let created_again = manager.generate_deadline_alerts(&[400]);
        assert!(created_again.is_empty());
        assert_eq!(manager.alerts.len(), created.len());

        let alert_id = manager.alerts[0].id.clone();
        manager
            .mark_alert_sent(&alert_id)
            .expect("mark should succeed");
        assert!(
            manager
                .alerts
                .iter()
                .find(|a| a.id == alert_id)
                .unwrap()
                .sent
        );
        assert_eq!(manager.pending_alerts().len(), manager.alerts.len() - 1);
    }

    #[test]
    fn test_search_conferences() {
        let mut manager = ConferenceManager::new();
        manager.load_standard_conferences();

        let ml_conferences = manager.search_conferences("Machine Learning");
        assert!(!ml_conferences.is_empty());

        let top_tier = manager.get_conferences_by_ranking(ConferenceRanking::TopTier);
        assert!(!top_tier.is_empty());
    }
}