| | | 1 | | using RoleRadar.Application.Abstractions; |
| | | 2 | | using RoleRadar.Domain.Common; |
| | | 3 | | |
| | | 4 | | namespace RoleRadar.Application.Tracking.Import.Pipeline; |
| | | 5 | | |
| | | 6 | | public static class CsvHeaderValidator |
| | | 7 | | { |
| | 8 | 8 | | public static readonly IReadOnlyList<string> AppendixHeaders = new[] |
| | 8 | 9 | | { |
| | 8 | 10 | | "source", "proposed_disposition", "company", "title", "req", "comp_detected", |
| | 8 | 11 | | "comp_is_estimate", "remote_mentioned", "details_raw", "added_md", "reason_primary", |
| | 8 | 12 | | "reason_all", "proposed_resurface", "company_also_in_db", "review_flags", "reason_text", |
| | 8 | 13 | | "decision", "corrected_notes" |
| | 8 | 14 | | }; |
| | | 15 | | |
| | 8 | 16 | | public static readonly IReadOnlyList<string> ApplicationsHeaders = new[] |
| | 8 | 17 | | { |
| | 8 | 18 | | "kind", "company", "title", "req", "applied_on", "rejected", "rejected_date_md", |
| | 8 | 19 | | "desired_salary", "referral", "fit", "resume_variant", "people_detected", |
| | 8 | 20 | | "review_flags", "raw", "decision", "corrected_notes" |
| | 8 | 21 | | }; |
| | | 22 | | |
| | 8 | 23 | | public static readonly IReadOnlyList<string> WatchlistHeaders = new[] |
| | 8 | 24 | | { |
| | 8 | 25 | | "company", "proposed_status", "text", "decision", "corrected_notes" |
| | 8 | 26 | | }; |
| | | 27 | | |
| | 8 | 28 | | public static readonly IReadOnlyList<string> CompanyAliasesHeaders = new[] |
| | 8 | 29 | | { |
| | 8 | 30 | | "alias", "canonical" |
| | 8 | 31 | | }; |
| | | 32 | | |
| | | 33 | | public static Result<bool> Validate(string fileName, IReadOnlyList<string> actualHeaders, IReadOnlyList<string> expe |
| | | 34 | | { |
| | 204 | 35 | | if (actualHeaders == null || actualHeaders.Count == 0) |
| | | 36 | | { |
| | 0 | 37 | | return Result<bool>.Failure(ErrorCode.ValidationError, $"Missing header row in {fileName}."); |
| | | 38 | | } |
| | | 39 | | |
| | 204 | 40 | | var missing = expectedHeaders |
| | 21480 | 41 | | .Where(exp => !actualHeaders.Any(act => string.Equals(act.Trim(), exp, StringComparison.OrdinalIgnoreCase))) |
| | 204 | 42 | | .ToList(); |
| | | 43 | | |
| | 204 | 44 | | if (missing.Count > 0) |
| | | 45 | | { |
| | 4 | 46 | | return Result<bool>.Failure(ErrorCode.ValidationError, $"Missing or misspelled column '{missing[0]}' in {fil |
| | | 47 | | } |
| | | 48 | | |
| | 200 | 49 | | var unknown = actualHeaders |
| | 20784 | 50 | | .Where(act => !string.IsNullOrWhiteSpace(act) && !expectedHeaders.Any(exp => string.Equals(exp, act.Trim(), |
| | 200 | 51 | | .ToList(); |
| | | 52 | | |
| | 200 | 53 | | if (unknown.Count > 0) |
| | | 54 | | { |
| | 0 | 55 | | return Result<bool>.Failure(ErrorCode.ValidationError, $"Unrecognized column '{unknown[0].Trim()}' in {fileN |
| | | 56 | | } |
| | | 57 | | |
| | 200 | 58 | | return Result<bool>.Success(true); |
| | | 59 | | } |
| | | 60 | | } |