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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
import streamlit as st
import pandas as pd

from schemas.custom_app_form import CustomAppFormUpload
from utils.prep_validators_payload import process_extracted_data


upload_docs_tab, demo_validations_considered_tab, upload_docs_validation_results_tab = st.tabs(
    ["Upload Documents", "Demo Validations", "Validation Results"]
)

with upload_docs_tab:
    st.header("Upload Documents")
    # st.markdown("## Upload Custom Application Form")
    uploaded_custom_application_form_file = st.file_uploader(
        label="Upload Custom Application Form",
        accept_multiple_files=False,
        type=["csv"],
    )

    uploaded_files = st.file_uploader(
        label="Upload files to be validated",
        accept_multiple_files=True,
        type=["png", "jpg", "jpeg", "pdf", "zip"]
    )

    if uploaded_custom_application_form_file:
        uploaded_custom_form_df = pd.read_csv(
            uploaded_custom_application_form_file, header=None)
        uploaded_custom_form_dict = dict(
            zip(uploaded_custom_form_df[0], uploaded_custom_form_df[1]))
        st.write("Raw Dictionary:")
        st.json(uploaded_custom_form_dict)
        custom_app_form = CustomAppFormUpload.model_validate(
            uploaded_custom_form_dict).model_dump()
        st.write("Parsed Dictionary:")
        st.json(custom_app_form)
        # print(custom_app_form)
        if isinstance(custom_app_form, dict) and not custom_app_form.get("is_incomplete"):
            st.session_state["custom_app_form"] = custom_app_form
            st.write("Session State:")
            st.write(st.session_state)


with demo_validations_considered_tab:
    st.header("Demo Validations")
    # demo_validations = [
    #     # {
    #     #     "Document Type": "Passport",
    #     #     "Validation": "Full name must be present",
    #     #     "Raises Red Flag": True,
    #     #     # "Error Message": "Applicant's full name not present",
    #     # },
    #     # {
    #     #     "Document Type": "Passport",
    #     #     "Validation": "Full name must have length between 2 & 61",
    #     #     "Raises Red Flag": True,
    #     #     # "Error Message": "Full name must have a length of at least 2 & at most 61",
    #     # },
    #     # {
    #     #     "Document Type": "Passport",
    #     #     "Validation": "Full name must have at least two words",
    #     #     "Raises Red Flag": True,
    #     #     # "Error Message": "Full name must consist of at least 2 words (first name + last name)",
    #     # },
    #     {
    #         "Document Type": "Passport",
    #         "Validation": (
    #             "Full name must be present. "
    #             "Full name must have length between 2 & 61. "
    #             "Full name must have at least two words."
    #         ),
    #         "Raises Red Flag": True,
    #         # "Error Message": "Applicant's full name not present",
    #     },
    #     {
    #         "Document Type": "Passport",
    #         "Validation": "Expiry date must be present & after a year from current date",
    #         "Raises Red Flag": True,
    #         # "Error Message": "Provided passport expires within 1 year",
    #     },
    #     {
    #         "Document Type": "Payslip",
    #         "Validation": (
    #             "Full name must be present. "
    #             "Full name must have length between 2 & 61. "
    #             "Full name must have at least two words."
    #         ),
    #         "Raises Red Flag": True,
    #         # "Error Message": "Applicant's full name not present",
    #     },
    #     {
    #         "Document Type": "Payslip",
    #         "Validation": "Employer name must be present",
    #         "Raises Red Flag": True,
    #         # "Error Message": "Employer name not present",
    #     },
    #     {
    #         "Document Type": "Payslip",
    #         "Validation": "Employer name must have at least alphabet",
    #         "Raises Red Flag": True,
    #         # "Error Message": "Employer name must contain at least one letter",
    #     },
    #     {
    #         "Document Type": "Payslip",
    #         "Validation": "Employer name cannot be only whitespace",
    #         "Raises Red Flag": True,
    #         # "Error Message": "Employer name cannot be only whitespace",
    #     },
    #     {
    #         "Document Type": "Payslip",
    #         "Validation": "Employer name must match the provided value",
    #         "Raises Red Flag": True,
    #         # "Error Message": "Employer name mismatch with provided value",
    #     },
    #     {
    #         "Document Type": "Payslip",
    #         "Validation": (
    #             "Pay period start & dates must be present.\n"
    #             "Pay period start date cannot be on or after the end date.\n"
    #             "Pay period's end date must be within the last 35 days & not in the future.\n"
    #             "Pay period's date(s) must not be older than those of the last calendar month.\n"
    #             "Pay period's start date & end date must have a gap of at least 28 days."
    #         ),
    #         "Raises Red Flag": True,
    #         # "Error Message": "Employer name mismatch with provided value",
    #     },
    #     {
    #         "Document Type": "Payslip",
    #         "Validation": (
    #             "Basic salary, Net Salary and/or other requisite salary components must be present. "
    #             "Tax Deduction line item must be present. "
    #             "NI/National Insurance line item must be present."
    #         ),
    #         "Raises Red Flag": True,
    #     },
    #     {
    #         "Document Type": "Payslip",
    #         "Validation": (
    #             "Applicant's address must be present. "
    #             "Applicant's complete address must have a length of at least 10 & at most 300. "
    #             "Complete address must match with provided value. "
    #         ),
    #         "Raises Red Flag": True,
    #     },
    #     {
    #         "Document Type": "Payslip",
    #         "Validation": "Employee number must be greater than 25",
    #         "Raises Red Flag": True,
    #     },
    #     {
    #         "Document Type": "Digital Bank Account Statement",
    #         "Validation": (
    #             "Full name must be present. "
    #             "Full name must have length between 2 & 61. "
    #             "Full name must have at least two words."
    #         ),
    #         "Raises Red Flag": True,
    #         # "Error Message": "Applicant's full name not present",
    #     },
    #     {
    #         "Document Type": "Digital Bank Account Statement",
    #         "Validation": (
    #             "Bank name must be present. "
    #             "Bank name must have length between 4 & 50. "
    #             "Bank Name must match provided value."
    #         ),
    #         "Raises Red Flag": True,
    #         # "Error Message": "Applicant's full name not present",
    #     },
    #     {
    #         "Document Type": "Digital Bank Account Statement",
    #         "Validation": (
    #             "Bank account number must be present. "
    #             "Bank account number must be of 8 digits only. "
    #         ),
    #         "Raises Red Flag": True,
    #         # "Error Message": "Applicant's full name not present",
    #     },
    #     {
    #         "Document Type": "Digital Bank Account Statement",
    #         "Validation": (
    #             "Sort number must be present. "
    #             "It must be of the format xx-xx-xx wherein x are digits. "
    #         ),
    #         "Raises Red Flag": True,
    #         # "Error Message": "Applicant's full name not present",
    #     },
    #     {
    #         "Document Type": "Digital Bank Account Statement",
    #         "Validation": (
    #             "Both statement start date & statement end date must be present. "
    #             "Account statement period's start date & end date must have a gap of at least 28 days. "
    #             "At least one salary credit must be present. "
    #             "Statement period's end date must be after the start date. "
    #         ),
    #         "Raises Red Flag": True,
    #         # "Error Message": "Applicant's full name not present",
    #     },
    # ]
    demo_validations = [
        # {
        #     "Topic / Document Type": "General Guidance",
        #     "Policy / Rule / Condition": "Income/Employment Docs Risk",
        #     "Action / Guidance / Requirement": "Be aware of higher risk of manipulation (Payslips, bank statements, Customer name).",
        #     "Red Flag / Caution": "Higher risk category.",
        #     "Notes / Details": "",
        # },
        {
            "Topic / Document Type": "General Guidance",
            "Policy / Rule / Condition": "Document Consistency",
            # "Action / Guidance / Requirement": "Compare information across all documents (e.g., payslips vs bank statements) to ensure consistency.",
            "Action / Guidance / Requirement": "Compare applicant's full name across all documents to ensure consistency.",
            # "Red Flag / Caution": "Inconsistencies require investigation.",
            # "Notes / Details": "",
        },
        # {
        #     "Topic / Document Type": "General Guidance",
        #     "Policy / Rule / Condition": "Payslip YTD Check",
        #     "Action / Guidance / Requirement": "Do Year-to-Date figures (gross income, tax) make sense?",
        #     "Red Flag / Caution": "If figures don’t make sense, investigate.",
        #     "Notes / Details": "",
        # },
        # {
        #     "Topic / Document Type": "General Guidance",
        #     "Policy / Rule / Condition": "Payslip Details Check",
        #     "Action / Guidance / Requirement": "Check for low employee numbers, rounded figures, differences in payment methods (e.g., payslip says BACS, statement shows Faster Payment).",
        #     "Red Flag / Caution": "These can be red flags requiring investigation.",
        #     "Notes / Details": "",
        # },
        {
            "Topic / Document Type": "General Guidance",
            "Policy / Rule / Condition": "Overall Validation",
            "Action / Guidance / Requirement": "Ensure document is genuine, not fraudulent, belongs to the customer, and is from the expected source.",
            # "Red Flag / Caution": "Any doubt may indicate fraud.",
            # "Notes / Details": "Applies to all documents.",
        },
        {
            "Topic / Document Type": "Passport",
            "Policy / Rule / Condition": "Full Name",
            "Action / Guidance / Requirement": (
                "Full name must be present. "
                "Full name must have length between 2 & 61. "
                "Full name must have at least two words."
            ),
            # "Raises Red Flag": True,
            # "Error Message": "Applicant's full name not present",
        },
        {
            "Topic / Document Type": "Passport",
            "Policy / Rule / Condition": "Expiry Date",
            "Action / Guidance / Requirement": "Expiry date must be present & after a year from current date",
            # "Raises Red Flag": True,
            # "Error Message": "Provided passport expires within 1 year",
        },
        {
            "Topic / Document Type": "Payslips",
            "Policy / Rule / Condition": "Employer & Customer Names",
            "Action / Guidance / Requirement": "Must include correct Employer’s and Customer’s names.",
            # "Red Flag / Caution": "Missing or incorrect names.",
            # "Notes / Details": "Cross-reference with BMM/HOME.",
        },
        {
            "Topic / Document Type": "Payslips",
            "Policy / Rule / Condition": "Submission Requirement (Monthly Pay)",
            "Action / Guidance / Requirement": "Minimum one month's most recent payslip required.",
            # "Red Flag / Caution": "",
            # "Notes / Details": "",
        },
        {
            "Topic / Document Type": "Payslips",
            "Policy / Rule / Condition": "Pay Date Requirement",
            # "Action / Guidance / Requirement": "Pay date must be within 35 days of FCD (Final Completion Date).",
            "Action / Guidance / Requirement": "Pay date must be within 35 days of document upload date.",
            # "Red Flag / Caution": "Pay date older than 35 days from FCD.",
            # "Notes / Details": "",
        },
        {
            "Topic / Document Type": "Payslips",
            "Policy / Rule / Condition": "Pay Period End Date (DD/MM/YYYY, if no pay date)",
            "Action / Guidance / Requirement": "Period end date must be within 35 days of FCD.",
            # "Red Flag / Caution": "Period end date older than 35 days from FCD.",
            # "Notes / Details": "",
        },
        {
            "Topic / Document Type": "Payslips",
            # "Policy / Rule / Condition": "Pay Period Month (MM/YYYY, if no pay date)",
            "Policy / Rule / Condition": "Pay Period Month (MM/YYYY, if no pay date) basis pay period duration",
            "Action / Guidance / Requirement": "Payslips dated in the current or previous calendar month are acceptable (must be the most recent).",
            # "Red Flag / Caution": "Older than previous calendar month.",
            # "Notes / Details": "",
        },
        {
            "Topic / Document Type": "Payslips",
            "Policy / Rule / Condition": "Undated Payslips",
            "Action / Guidance / Requirement": "Unacceptable.",
            # "Red Flag / Caution": "Undated payslip received.",
            # "Notes / Details": "Request a dated version.",
        },
        {
            "Topic / Document Type": "Payslips",
            "Policy / Rule / Condition": "Tax & NI Contributions",
            "Action / Guidance / Requirement": "Must be visible. Perform a sense check.",
            # "Red Flag / Caution": "Missing or nonsensical Tax/NI figures.",
            # "Notes / Details": "",
        },
        # custom
        {
            "Topic / Document Type": "Payslips",
            "Policy / Rule / Condition": "Applicant Address",
            "Action / Guidance / Requirement": (
                "Applicant's address must be present. "
                "Applicant's complete address must have a length of at least 10 & at most 300. "
                "Complete address must match with provided value. "
            ),
            # "Red Flag / Caution": "Missing or nonsensical Tax/NI figures.",
            # "Notes / Details": "",
        },
        # {
        #     "Topic / Document Type": "Payslips",
        #     "Policy / Rule / Condition": "YTD Figures Match",
        #     "Action / Guidance / Requirement": "Verify YTD figures match declared income.",
        #     "Red Flag / Caution": "YTD figures do not match declared income.",
        #     "Notes / Details": "Add to YMI/FDM memo if they do not match.",
        # },
        # {
        #     "Topic / Document Type": "Payslips",
        #     "Policy / Rule / Condition": "Pension Income (on Payslip)",
        #     "Action / Guidance / Requirement": "Must show within the last 35 days / be the most recent.",
        #     "Red Flag / Caution": "Pension income shown is dated >35 days ago.",
        #     "Notes / Details": "Alternatively use pension annual statement/latest P60. Cross-reference with bank statement if possible.",
        # },
        # {
        #     "Topic / Document Type": "Payslips",
        #     "Policy / Rule / Condition": "Joint Applicants",
        #     "Action / Guidance / Requirement": "Required if applicable.",
        #     "Red Flag / Caution": "Missing payslip for a joint applicant.",
        #     "Notes / Details": "",
        # },
        # {
        #     "Topic / Document Type": "Payslips",
        #     "Policy / Rule / Condition": "Payslip Red Flags",
        #     "Action / Guidance / Requirement": "",
        #     "Red Flag / Caution": "Rounded figures. Low employee/payroll number. Presence of these flags.",
        #     "Notes / Details": "Investigate further.",
        # },
        # {
        #     "Topic / Document Type": "Payslips",
        #     "Policy / Rule / Condition": "Payslip Verification (HOME)",
        #     "Action / Guidance / Requirement": "Check information in HOME against payslip details (employer name, customer name, etc.).",
        #     "Red Flag / Caution": "Mismatches found (e.g., misspellings, missing words).",
        #     "Notes / Details": "Correct HOME after consulting customer. If correction not possible (e.g., space), add YMI/FDM memo explaining.",
        # },
        # {
        #     "Topic / Document Type": "Payslips",
        #     "Policy / Rule / Condition": "Payslip Near 35-Day Limit",
        #     "Action / Guidance / Requirement": "If payslip is close to the 35-day limit and no decision is obtained.",
        #     "Red Flag / Caution": "Decision pending, payslip nearing expiry.",
        #     "Notes / Details": "Another, more recent payslip may be required.",
        # },
        # {
        #     "Topic / Document Type": "Digital Bank Stmts",
        #     "Policy / Rule / Condition": "Purpose",
        #     "Action / Guidance / Requirement": "Used to confirm income/expenditure.",
        #     "Red Flag / Caution": "",
        #     "Notes / Details": "Cannot be used for ID & VA confirmation.",
        # },
        {
            "Topic / Document Type": "Digital Bank Stmts",
            "Policy / Rule / Condition": "Coverage",
            # "Action / Guidance / Requirement": "Must cover a full calendar month (vs 28 days for original).",
            "Action / Guidance / Requirement": "Account statement period's start date & end date must have a gap of at least 28 days.",
            # "Red Flag / Caution": "",
            # "Notes / Details": "",
        },
        {
            "Topic / Document Type": "Digital Bank Stmts",
            "Policy / Rule / Condition": "Data Match",
            "Action / Guidance / Requirement": "Customer data on statement must match profile.",
            # "Red Flag / Caution": "Data mismatch.",
            # "Notes / Details": "",
        },
        # {
        #     "Topic / Document Type": "Digital Bank Stmts",
        #     "Policy / Rule / Condition": "Pay Info Match",
        #     "Action / Guidance / Requirement": "Verify pay information matches the payslip.",
        #     "Red Flag / Caution": "Pay info mismatch vs payslip.",
        #     "Notes / Details": "",
        # },
        {
            "Topic / Document Type": "Digital Bank Stmts",
            "Policy / Rule / Condition": "Authenticity Doubt",
            "Action / Guidance / Requirement": "If any doubt regarding authenticity.",
            # "Red Flag / Caution": "Suspected non-genuine digital statement.",
            # "Notes / Details": "Cases may be referred to Fraud.",
        },
        {
            "Topic / Document Type": "Digital Bank Stmts",
            "Policy / Rule / Condition": "Bank name",
            "Action / Guidance / Requirement": (
                "Bank name must be present. "
                "Bank name must have length between 4 & 50. "
                "Bank Name must match provided value."
            ),
        },
        {
            "Topic / Document Type": "Digital Bank Stmts",
            "Policy / Rule / Condition": "Bank account number",
            "Action / Guidance / Requirement": (
                "Bank account number must be present. "
                "Bank account number must be of 8 digits only. "
            ),
        },
        {
            "Topic / Document Type": "Digital Bank Stmts",
            "Policy / Rule / Condition": "Sort code",
            "Action / Guidance / Requirement": (
                "Sort number must be present. "
                "It must be of the format xx-xx-xx wherein x are digits. "
            ),
        },
        {
            "Topic / Document Type": "Digital Bank Stmts",
            "Policy / Rule / Condition": "Date checks",
            "Action / Guidance / Requirement": (
                "Both statement start date & statement end date must be present. "
                "At least one salary credit must be present. "
                "Statement period's end date must be after the start date. "
            ),
        },
    ]

    demo_validations_df = pd.DataFrame(demo_validations)
    st.table(demo_validations_df)


with upload_docs_validation_results_tab:
    st.header("Validation Results")
    if st.session_state:
        st.session_state