headless_lms_credit_registration/registry/
answers.rs1use std::collections::HashMap;
4use std::time::Duration;
5
6use chrono::{DateTime, Utc};
7use headless_lms_models::credit_registrations::{
8 CreditRegistrationErrorCode, CreditRegistrationState,
9};
10use headless_lms_models::library::credit_registration::config_validation::CourseCodeVerdict;
11use headless_lms_models::library::credit_registration::study_registry::{
12 RegistryAttainment, RegistryEnrolment, RosterPerson,
13};
14use secrecy::SecretString;
15
16use super::ids::{CourseCode, SubmittedAttainmentRef};
17
18pub(crate) struct FoundPerson {
20 pub person_id: SecretString,
21 pub first_names: Option<SecretString>,
22 pub last_name: Option<SecretString>,
23}
24
25pub(crate) struct PersonAnswer {
28 pub reading: PersonReading,
29 pub error_message: Option<String>,
31}
32
33pub(crate) enum PersonReading {
34 Found(FoundPerson),
35 Refused {
37 code: CreditRegistrationErrorCode,
38 },
39}
40
41pub struct RegistryPerson {
43 pub sisu_person_id: SecretString,
44 pub first_names: Option<SecretString>,
45 pub last_name: Option<SecretString>,
46 pub code: String,
48}
49
50#[derive(Debug, Clone, PartialEq, Eq)]
53pub enum PersonLookupError {
54 StudyRegistryUnavailable,
56 ItemMissingFromResponse,
58 UnexpectedAnswer { code: String },
61}
62
63pub(crate) struct EnrolmentAnswer {
66 pub reading: EnrolmentReading,
67 pub enrolments: Vec<RegistryEnrolment>,
68 pub existing_attainments: Vec<RegistryAttainment>,
69}
70
71pub(crate) enum EnrolmentReading {
72 Listed,
73 Refused {
74 code: CreditRegistrationErrorCode,
75 error_message: Option<String>,
76 },
77}
78
79pub(crate) enum ImportAnswer {
80 Submitted {
83 submission: Option<SubmittedAttainmentRef>,
84 is_repeat_in_batch: bool,
85 },
86 Settled {
88 held: HeldCredit,
89 attainment: Option<RegistryAttainment>,
90 },
91 Refused {
94 code: CreditRegistrationErrorCode,
95 submission: Option<SubmittedAttainmentRef>,
96 error_message: Option<String>,
97 },
98 UnknownSuccessCode,
100}
101
102#[derive(Debug, Clone, Copy, PartialEq, Eq)]
104pub(crate) enum HeldCredit {
105 Duplicate,
106 NotImproved,
107}
108
109impl HeldCredit {
110 pub(crate) fn state(self) -> CreditRegistrationState {
111 match self {
112 Self::Duplicate => CreditRegistrationState::Duplicate,
113 Self::NotImproved => CreditRegistrationState::NotImproved,
114 }
115 }
116}
117
118pub(crate) struct VerificationAnswer {
120 pub reading: VerificationReading,
121 pub error_message: Option<String>,
123}
124
125pub(crate) enum VerificationReading {
126 Registered {
128 attainment: RegistryAttainment,
129 },
130 PartiallyRegistered,
132 Pending {
134 resubmit_not_before: Option<DateTime<Utc>>,
135 },
136 NotRegistered,
138 Failed {
139 code: CreditRegistrationErrorCode,
140 },
141 Inconclusive,
143}
144
145pub(crate) struct RosterListing {
147 pub duration: Duration,
148 pub rosters: Vec<Result<Vec<RosterPerson>, CreditRegistrationErrorCode>>,
150}
151
152pub(crate) struct RosterSearch {
154 pub person: Option<RosterPerson>,
156 pub has_unanswered_code: bool,
158}
159
160pub(crate) type CourseCodeVerdicts = HashMap<CourseCode, CourseCodeVerdict>;