| | | 1 | | namespace RoleRadar.Domain.Tracking; |
| | | 2 | | |
| | | 3 | | public sealed record PostingDifference( |
| | | 4 | | string Field, |
| | | 5 | | object? StoredValue, |
| | | 6 | | object? SuppliedValue); |
| | | 7 | | |
| | | 8 | | public sealed record PostingCandidate( |
| | | 9 | | Guid Id, |
| | | 10 | | string Title, |
| | | 11 | | PostingDisposition Disposition, |
| | | 12 | | string? Reason); |
| | | 13 | | |
| | | 14 | | |
| | | 15 | | public sealed class Posting |
| | | 16 | | { |
| | | 17 | | public const int MaxTitleLength = 200; |
| | | 18 | | public const int MaxUrlLength = 1000; |
| | | 19 | | public const int MaxAtsTenantLength = 100; |
| | | 20 | | public const int MaxRequisitionIdLength = 100; |
| | | 21 | | public const int MaxLocationLength = 150; |
| | | 22 | | public const int MaxCompensationTextLength = 300; |
| | | 23 | | public const int MaxCultureSummaryLength = 500; |
| | | 24 | | public const int MaxDispositionReasonLength = 500; |
| | | 25 | | |
| | 59690 | 26 | | public Guid Id { get; init; } |
| | 35562 | 27 | | public string OwnerId { get; init; } = string.Empty; |
| | 31174 | 28 | | public Guid CompanyId { get; private set; } |
| | 38358 | 29 | | public string Title { get; private set; } = string.Empty; |
| | 40204 | 30 | | public string NormalizedTitle { get; private set; } = string.Empty; |
| | 15144 | 31 | | public string? OriginalUrl { get; private set; } |
| | 14652 | 32 | | public string? NormalizedUrl { get; private set; } |
| | 13970 | 33 | | public SourceKind SourceKind { get; private set; } = SourceKind.Ats; |
| | 14248 | 34 | | public string? AtsTenant { get; private set; } |
| | 14970 | 35 | | public string? RequisitionId { get; private set; } |
| | 17398 | 36 | | public string? DedupKeyA { get; private set; } |
| | 17660 | 37 | | public string? DedupKeyB { get; private set; } |
| | 16934 | 38 | | public string? DedupKeyC { get; private set; } |
| | 24720 | 39 | | public string? Location { get; private set; } |
| | 35426 | 40 | | public RemoteType RemoteType { get; private set; } = RemoteType.Unknown; |
| | 33618 | 41 | | public Compensation Compensation { get; private set; } = new(); |
| | 24148 | 42 | | public bool? CompHighPriority { get; private set; } |
| | 13990 | 43 | | public string? PostedDate { get; private set; } |
| | 18654 | 44 | | public DateTimeOffset FirstSeenAt { get; init; } |
| | 30796 | 45 | | public DateTimeOffset LastVerifiedAt { get; private set; } |
| | 13980 | 46 | | public string? ClosedDate { get; private set; } |
| | 28582 | 47 | | public decimal? Score { get; private set; } |
| | 30670 | 48 | | public CultureLevel CultureLevel { get; private set; } = CultureLevel.Unknown; |
| | 14012 | 49 | | public string? CultureSummary { get; private set; } |
| | 34258 | 50 | | public PostingDisposition Disposition { get; private set; } = PostingDisposition.Lead; |
| | 14530 | 51 | | public string? DispositionReason { get; private set; } |
| | 14208 | 52 | | public Guid? DispositionCriterionId { get; private set; } |
| | 24618 | 53 | | public ResurfacePolicy ResurfacePolicy { get; private set; } = ResurfacePolicy.Never; |
| | 15078 | 54 | | public DateTimeOffset? DecidedAt { get; private set; } |
| | 14002 | 55 | | public Guid? DuplicateOfId { get; private set; } |
| | 14060 | 56 | | public Guid? ScreeningNoteId { get; private set; } |
| | 28296 | 57 | | public Guid VersionToken { get; private set; } |
| | 14020 | 58 | | public DateTimeOffset CreatedAt { get; init; } |
| | 14402 | 59 | | public DateTimeOffset UpdatedAt { get; private set; } |
| | | 60 | | |
| | | 61 | | public static Posting Create( |
| | | 62 | | string ownerId, |
| | | 63 | | Guid companyId, |
| | | 64 | | string title, |
| | | 65 | | SourceKind sourceKind = SourceKind.Ats, |
| | | 66 | | string? originalUrl = null, |
| | | 67 | | string? atsTenant = null, |
| | | 68 | | string? requisitionId = null, |
| | | 69 | | string? location = null, |
| | | 70 | | RemoteType remoteType = RemoteType.Unknown, |
| | | 71 | | Compensation? compensation = null, |
| | | 72 | | string? postedDate = null, |
| | | 73 | | decimal? score = null, |
| | | 74 | | CultureLevel cultureLevel = CultureLevel.Unknown, |
| | | 75 | | string? cultureSummary = null, |
| | | 76 | | PostingDisposition disposition = PostingDisposition.Lead, |
| | | 77 | | string? dispositionReason = null, |
| | | 78 | | Guid? dispositionCriterionId = null, |
| | | 79 | | ResurfacePolicy resurfacePolicy = ResurfacePolicy.Never, |
| | | 80 | | DateTimeOffset? decidedAt = null, |
| | | 81 | | Guid? duplicateOfId = null, |
| | | 82 | | Guid? screeningNoteId = null, |
| | | 83 | | Guid? id = null, |
| | | 84 | | DateTimeOffset? now = null, |
| | | 85 | | bool? compHighPriority = null, |
| | | 86 | | string? closedDate = null) |
| | | 87 | | { |
| | 5900 | 88 | | ArgumentException.ThrowIfNullOrWhiteSpace(ownerId); |
| | 5900 | 89 | | ArgumentException.ThrowIfNullOrWhiteSpace(title); |
| | | 90 | | |
| | 5896 | 91 | | var trimmedTitle = title.Trim(); |
| | 5896 | 92 | | if (trimmedTitle.Length > MaxTitleLength) |
| | | 93 | | { |
| | 4 | 94 | | throw new ArgumentException($"Posting title cannot exceed {MaxTitleLength} characters.", nameof(title)); |
| | | 95 | | } |
| | | 96 | | |
| | 5892 | 97 | | if (originalUrl is not null && originalUrl.Length > MaxUrlLength) |
| | | 98 | | { |
| | 4 | 99 | | throw new ArgumentException($"Original URL cannot exceed {MaxUrlLength} characters.", nameof(originalUrl)); |
| | | 100 | | } |
| | | 101 | | |
| | 5888 | 102 | | if (atsTenant is not null && atsTenant.Length > MaxAtsTenantLength) |
| | | 103 | | { |
| | 4 | 104 | | throw new ArgumentException($"ATS tenant cannot exceed {MaxAtsTenantLength} characters.", nameof(atsTenant)) |
| | | 105 | | } |
| | | 106 | | |
| | 5884 | 107 | | if (requisitionId is not null && requisitionId.Length > MaxRequisitionIdLength) |
| | | 108 | | { |
| | 4 | 109 | | throw new ArgumentException($"Requisition ID cannot exceed {MaxRequisitionIdLength} characters.", nameof(req |
| | | 110 | | } |
| | | 111 | | |
| | 5880 | 112 | | if (location is not null && location.Length > MaxLocationLength) |
| | | 113 | | { |
| | 4 | 114 | | throw new ArgumentException($"Location cannot exceed {MaxLocationLength} characters.", nameof(location)); |
| | | 115 | | } |
| | | 116 | | |
| | 5876 | 117 | | if (compensation?.Text is not null && compensation.Text.Length > MaxCompensationTextLength) |
| | | 118 | | { |
| | 4 | 119 | | throw new ArgumentException($"Compensation text cannot exceed {MaxCompensationTextLength} characters.", name |
| | | 120 | | } |
| | | 121 | | |
| | 5872 | 122 | | if (cultureSummary is not null && cultureSummary.Length > MaxCultureSummaryLength) |
| | | 123 | | { |
| | 4 | 124 | | throw new ArgumentException($"Culture summary cannot exceed {MaxCultureSummaryLength} characters.", nameof(c |
| | | 125 | | } |
| | | 126 | | |
| | 5868 | 127 | | if (dispositionReason is not null && dispositionReason.Length > MaxDispositionReasonLength) |
| | | 128 | | { |
| | 4 | 129 | | throw new ArgumentException($"Disposition reason cannot exceed {MaxDispositionReasonLength} characters.", na |
| | | 130 | | } |
| | | 131 | | |
| | 5864 | 132 | | if (score.HasValue && (score.Value < 0.0m || score.Value > 10.0m)) |
| | | 133 | | { |
| | 8 | 134 | | throw new ArgumentException("Score must be between 0.0 and 10.0.", nameof(score)); |
| | | 135 | | } |
| | | 136 | | |
| | 5856 | 137 | | var actualId = id ?? Guid.CreateVersion7(); |
| | 5856 | 138 | | if (duplicateOfId.HasValue && duplicateOfId.Value == actualId) |
| | | 139 | | { |
| | 4 | 140 | | throw new ArgumentException("A posting cannot be a duplicate of itself.", nameof(duplicateOfId)); |
| | | 141 | | } |
| | | 142 | | |
| | 5852 | 143 | | var timestamp = now ?? DateTimeOffset.UtcNow; |
| | 5852 | 144 | | var normalizedTitle = TitleNormalizer.Normalize(trimmedTitle); |
| | 5852 | 145 | | var normalizedUrl = UrlNormalizer.Normalize(originalUrl); |
| | | 146 | | |
| | 5852 | 147 | | var trimmedAtsTenant = string.IsNullOrWhiteSpace(atsTenant) ? null : atsTenant.Trim(); |
| | 5852 | 148 | | var trimmedReqId = string.IsNullOrWhiteSpace(requisitionId) ? null : requisitionId.Trim(); |
| | | 149 | | |
| | 5852 | 150 | | string? dedupKeyA = null; |
| | 5852 | 151 | | if (!string.IsNullOrWhiteSpace(trimmedAtsTenant) && !string.IsNullOrWhiteSpace(trimmedReqId)) |
| | | 152 | | { |
| | 1332 | 153 | | dedupKeyA = $"{trimmedAtsTenant}|{trimmedReqId}"; |
| | | 154 | | } |
| | | 155 | | |
| | 5852 | 156 | | string? dedupKeyB = normalizedUrl; |
| | | 157 | | |
| | 5852 | 158 | | string? dedupKeyC = null; |
| | 5852 | 159 | | if (string.IsNullOrWhiteSpace(trimmedAtsTenant) && !string.IsNullOrWhiteSpace(trimmedReqId)) |
| | | 160 | | { |
| | 1108 | 161 | | dedupKeyC = $"{companyId:D}|{trimmedReqId}"; |
| | | 162 | | } |
| | | 163 | | |
| | 5852 | 164 | | DateTimeOffset? initialDecidedAt = decidedAt; |
| | 5852 | 165 | | if (initialDecidedAt is null && (disposition == PostingDisposition.ScreenedOut || disposition == PostingDisposit |
| | | 166 | | { |
| | 744 | 167 | | initialDecidedAt = timestamp; |
| | | 168 | | } |
| | | 169 | | |
| | 5852 | 170 | | return new Posting |
| | 5852 | 171 | | { |
| | 5852 | 172 | | Id = actualId, |
| | 5852 | 173 | | OwnerId = ownerId, |
| | 5852 | 174 | | CompanyId = companyId, |
| | 5852 | 175 | | Title = trimmedTitle, |
| | 5852 | 176 | | NormalizedTitle = normalizedTitle, |
| | 5852 | 177 | | OriginalUrl = originalUrl, |
| | 5852 | 178 | | NormalizedUrl = normalizedUrl, |
| | 5852 | 179 | | SourceKind = sourceKind, |
| | 5852 | 180 | | AtsTenant = trimmedAtsTenant, |
| | 5852 | 181 | | RequisitionId = trimmedReqId, |
| | 5852 | 182 | | DedupKeyA = dedupKeyA, |
| | 5852 | 183 | | DedupKeyB = dedupKeyB, |
| | 5852 | 184 | | DedupKeyC = dedupKeyC, |
| | 5852 | 185 | | Location = location?.Trim(), |
| | 5852 | 186 | | RemoteType = remoteType, |
| | 5852 | 187 | | Compensation = compensation ?? new(), |
| | 5852 | 188 | | CompHighPriority = compHighPriority, |
| | 5852 | 189 | | PostedDate = postedDate, |
| | 5852 | 190 | | ClosedDate = closedDate, |
| | 5852 | 191 | | FirstSeenAt = timestamp, |
| | 5852 | 192 | | LastVerifiedAt = timestamp, |
| | 5852 | 193 | | Score = score, |
| | 5852 | 194 | | CultureLevel = cultureLevel, |
| | 5852 | 195 | | CultureSummary = cultureSummary?.Trim(), |
| | 5852 | 196 | | Disposition = disposition, |
| | 5852 | 197 | | DispositionReason = dispositionReason?.Trim(), |
| | 5852 | 198 | | DispositionCriterionId = dispositionCriterionId, |
| | 5852 | 199 | | ResurfacePolicy = resurfacePolicy, |
| | 5852 | 200 | | DecidedAt = initialDecidedAt, |
| | 5852 | 201 | | DuplicateOfId = duplicateOfId, |
| | 5852 | 202 | | ScreeningNoteId = screeningNoteId, |
| | 5852 | 203 | | VersionToken = Guid.CreateVersion7(), |
| | 5852 | 204 | | CreatedAt = timestamp, |
| | 5852 | 205 | | UpdatedAt = timestamp |
| | 5852 | 206 | | }; |
| | | 207 | | } |
| | | 208 | | |
| | | 209 | | public static Posting Rehydrate( |
| | | 210 | | Guid id, |
| | | 211 | | string ownerId, |
| | | 212 | | Guid companyId, |
| | | 213 | | string title, |
| | | 214 | | string normalizedTitle, |
| | | 215 | | string? originalUrl, |
| | | 216 | | string? normalizedUrl, |
| | | 217 | | SourceKind sourceKind, |
| | | 218 | | string? atsTenant, |
| | | 219 | | string? requisitionId, |
| | | 220 | | string? dedupKeyA, |
| | | 221 | | string? dedupKeyB, |
| | | 222 | | string? dedupKeyC, |
| | | 223 | | string? location, |
| | | 224 | | RemoteType remoteType, |
| | | 225 | | Compensation compensation, |
| | | 226 | | string? postedDate, |
| | | 227 | | DateTimeOffset firstSeenAt, |
| | | 228 | | DateTimeOffset lastVerifiedAt, |
| | | 229 | | string? closedDate, |
| | | 230 | | decimal? score, |
| | | 231 | | CultureLevel cultureLevel, |
| | | 232 | | string? cultureSummary, |
| | | 233 | | PostingDisposition disposition, |
| | | 234 | | string? dispositionReason, |
| | | 235 | | Guid? dispositionCriterionId, |
| | | 236 | | ResurfacePolicy resurfacePolicy, |
| | | 237 | | DateTimeOffset? decidedAt, |
| | | 238 | | Guid? duplicateOfId, |
| | | 239 | | Guid? screeningNoteId, |
| | | 240 | | Guid versionToken, |
| | | 241 | | DateTimeOffset createdAt, |
| | | 242 | | DateTimeOffset updatedAt, |
| | | 243 | | bool? compHighPriority = null) |
| | | 244 | | { |
| | 5530 | 245 | | return new Posting |
| | 5530 | 246 | | { |
| | 5530 | 247 | | Id = id, |
| | 5530 | 248 | | OwnerId = ownerId, |
| | 5530 | 249 | | CompanyId = companyId, |
| | 5530 | 250 | | Title = title, |
| | 5530 | 251 | | NormalizedTitle = normalizedTitle, |
| | 5530 | 252 | | OriginalUrl = originalUrl, |
| | 5530 | 253 | | NormalizedUrl = normalizedUrl, |
| | 5530 | 254 | | SourceKind = sourceKind, |
| | 5530 | 255 | | AtsTenant = atsTenant, |
| | 5530 | 256 | | RequisitionId = requisitionId, |
| | 5530 | 257 | | DedupKeyA = dedupKeyA, |
| | 5530 | 258 | | DedupKeyB = dedupKeyB, |
| | 5530 | 259 | | DedupKeyC = dedupKeyC, |
| | 5530 | 260 | | Location = location, |
| | 5530 | 261 | | RemoteType = remoteType, |
| | 5530 | 262 | | Compensation = compensation, |
| | 5530 | 263 | | CompHighPriority = compHighPriority, |
| | 5530 | 264 | | PostedDate = postedDate, |
| | 5530 | 265 | | FirstSeenAt = firstSeenAt, |
| | 5530 | 266 | | LastVerifiedAt = lastVerifiedAt, |
| | 5530 | 267 | | ClosedDate = closedDate, |
| | 5530 | 268 | | Score = score, |
| | 5530 | 269 | | CultureLevel = cultureLevel, |
| | 5530 | 270 | | CultureSummary = cultureSummary, |
| | 5530 | 271 | | Disposition = disposition, |
| | 5530 | 272 | | DispositionReason = dispositionReason, |
| | 5530 | 273 | | DispositionCriterionId = dispositionCriterionId, |
| | 5530 | 274 | | ResurfacePolicy = resurfacePolicy, |
| | 5530 | 275 | | DecidedAt = decidedAt, |
| | 5530 | 276 | | DuplicateOfId = duplicateOfId, |
| | 5530 | 277 | | ScreeningNoteId = screeningNoteId, |
| | 5530 | 278 | | VersionToken = versionToken, |
| | 5530 | 279 | | CreatedAt = createdAt, |
| | 5530 | 280 | | UpdatedAt = updatedAt |
| | 5530 | 281 | | }; |
| | | 282 | | } |
| | | 283 | | |
| | | 284 | | public void UpdateLastVerified(DateTimeOffset timestamp) |
| | | 285 | | { |
| | 14 | 286 | | LastVerifiedAt = timestamp; |
| | 14 | 287 | | UpdatedAt = timestamp; |
| | 14 | 288 | | VersionToken = Guid.CreateVersion7(); |
| | 14 | 289 | | } |
| | | 290 | | |
| | | 291 | | public void UpgradeIdentifiers(string? atsTenant, string? requisitionId, DateTimeOffset timestamp) |
| | | 292 | | { |
| | 8 | 293 | | var trimmedAtsTenant = string.IsNullOrWhiteSpace(atsTenant) ? AtsTenant : atsTenant.Trim(); |
| | 8 | 294 | | var trimmedReqId = string.IsNullOrWhiteSpace(requisitionId) ? RequisitionId : requisitionId.Trim(); |
| | | 295 | | |
| | 8 | 296 | | AtsTenant = trimmedAtsTenant; |
| | 8 | 297 | | RequisitionId = trimmedReqId; |
| | | 298 | | |
| | 8 | 299 | | if (!string.IsNullOrWhiteSpace(trimmedAtsTenant) && !string.IsNullOrWhiteSpace(trimmedReqId)) |
| | | 300 | | { |
| | 4 | 301 | | DedupKeyA = $"{trimmedAtsTenant}|{trimmedReqId}"; |
| | 4 | 302 | | DedupKeyC = null; |
| | | 303 | | } |
| | 4 | 304 | | else if (string.IsNullOrWhiteSpace(trimmedAtsTenant) && !string.IsNullOrWhiteSpace(trimmedReqId)) |
| | | 305 | | { |
| | 4 | 306 | | DedupKeyA = null; |
| | 4 | 307 | | DedupKeyC = $"{CompanyId:D}|{trimmedReqId}"; |
| | | 308 | | } |
| | | 309 | | |
| | 8 | 310 | | UpdatedAt = timestamp; |
| | 8 | 311 | | VersionToken = Guid.CreateVersion7(); |
| | 8 | 312 | | } |
| | | 313 | | |
| | | 314 | | public void Transition( |
| | | 315 | | PostingDisposition targetDisposition, |
| | | 316 | | string? reason, |
| | | 317 | | Guid? criterionId, |
| | | 318 | | ResurfacePolicy resurfacePolicy, |
| | | 319 | | DateTimeOffset timestamp, |
| | | 320 | | string? closedDate = null) |
| | | 321 | | { |
| | 110 | 322 | | Disposition = targetDisposition; |
| | 110 | 323 | | DispositionReason = reason?.Trim(); |
| | 110 | 324 | | DispositionCriterionId = criterionId; |
| | 110 | 325 | | ResurfacePolicy = resurfacePolicy; |
| | 110 | 326 | | if (closedDate is not null) |
| | | 327 | | { |
| | 0 | 328 | | ClosedDate = closedDate; |
| | | 329 | | } |
| | | 330 | | |
| | 110 | 331 | | if (targetDisposition == PostingDisposition.ScreenedOut || |
| | 110 | 332 | | targetDisposition == PostingDisposition.Closed || |
| | 110 | 333 | | targetDisposition == PostingDisposition.Rejected) |
| | | 334 | | { |
| | 88 | 335 | | DecidedAt = timestamp; |
| | | 336 | | } |
| | 22 | 337 | | else if (targetDisposition == PostingDisposition.Lead) |
| | | 338 | | { |
| | 16 | 339 | | DecidedAt = null; |
| | | 340 | | } |
| | | 341 | | |
| | 110 | 342 | | UpdatedAt = timestamp; |
| | 110 | 343 | | VersionToken = Guid.CreateVersion7(); |
| | 110 | 344 | | } |
| | | 345 | | |
| | | 346 | | public void TransitionToApplied(DateTimeOffset timestamp) |
| | | 347 | | { |
| | 114 | 348 | | Disposition = PostingDisposition.Applied; |
| | 114 | 349 | | DecidedAt = null; |
| | 114 | 350 | | UpdatedAt = timestamp; |
| | 114 | 351 | | VersionToken = Guid.CreateVersion7(); |
| | 114 | 352 | | } |
| | | 353 | | |
| | | 354 | | public void SynchronizeFromApplicationEvent( |
| | | 355 | | PostingDisposition terminalDisposition, |
| | | 356 | | string? reason, |
| | | 357 | | DateTimeOffset timestamp) |
| | | 358 | | { |
| | 22 | 359 | | Disposition = terminalDisposition; |
| | 22 | 360 | | if (!string.IsNullOrWhiteSpace(reason)) |
| | | 361 | | { |
| | 22 | 362 | | var trimmed = reason.Trim(); |
| | 22 | 363 | | DispositionReason = trimmed.Length > MaxDispositionReasonLength |
| | 22 | 364 | | ? trimmed[..MaxDispositionReasonLength] |
| | 22 | 365 | | : trimmed; |
| | | 366 | | } |
| | | 367 | | |
| | 22 | 368 | | DecidedAt = timestamp; |
| | 22 | 369 | | UpdatedAt = timestamp; |
| | 22 | 370 | | VersionToken = Guid.CreateVersion7(); |
| | 22 | 371 | | } |
| | | 372 | | |
| | | 373 | | public List<string> ApplyExplicitUpdate( |
| | | 374 | | Guid? companyId, |
| | | 375 | | string? title, |
| | | 376 | | string? originalUrl, |
| | | 377 | | SourceKind? sourceKind, |
| | | 378 | | string? atsTenant, |
| | | 379 | | string? requisitionId, |
| | | 380 | | string? location, |
| | | 381 | | RemoteType? remoteType, |
| | | 382 | | Compensation? compensation, |
| | | 383 | | string? postedDate, |
| | | 384 | | decimal? score, |
| | | 385 | | CultureLevel? cultureLevel, |
| | | 386 | | string? cultureSummary, |
| | | 387 | | Guid? duplicateOfId, |
| | | 388 | | Guid? screeningNoteId, |
| | | 389 | | DateTimeOffset timestamp, |
| | | 390 | | bool? compHighPriority = null) |
| | | 391 | | { |
| | 20 | 392 | | var changedFields = new List<string>(); |
| | | 393 | | |
| | 20 | 394 | | if (companyId.HasValue && companyId.Value != CompanyId) |
| | | 395 | | { |
| | 2 | 396 | | CompanyId = companyId.Value; |
| | 2 | 397 | | changedFields.Add("company_id"); |
| | | 398 | | } |
| | | 399 | | |
| | 20 | 400 | | if (!string.IsNullOrWhiteSpace(title) && title.Trim() != Title) |
| | | 401 | | { |
| | 8 | 402 | | Title = title.Trim(); |
| | 8 | 403 | | NormalizedTitle = TitleNormalizer.Normalize(Title); |
| | 8 | 404 | | changedFields.Add("title"); |
| | | 405 | | } |
| | | 406 | | |
| | 20 | 407 | | if (originalUrl is not null && originalUrl != OriginalUrl) |
| | | 408 | | { |
| | 2 | 409 | | OriginalUrl = originalUrl; |
| | 2 | 410 | | NormalizedUrl = UrlNormalizer.Normalize(originalUrl); |
| | 2 | 411 | | DedupKeyB = NormalizedUrl; |
| | 2 | 412 | | changedFields.Add("url"); |
| | | 413 | | } |
| | | 414 | | |
| | 20 | 415 | | if (sourceKind.HasValue && sourceKind.Value != SourceKind) |
| | | 416 | | { |
| | 2 | 417 | | SourceKind = sourceKind.Value; |
| | 2 | 418 | | changedFields.Add("source_kind"); |
| | | 419 | | } |
| | | 420 | | |
| | 20 | 421 | | if (atsTenant is not null && atsTenant != AtsTenant) |
| | | 422 | | { |
| | 4 | 423 | | AtsTenant = atsTenant.Trim(); |
| | 4 | 424 | | changedFields.Add("ats_tenant"); |
| | | 425 | | } |
| | | 426 | | |
| | 20 | 427 | | if (requisitionId is not null && requisitionId != RequisitionId) |
| | | 428 | | { |
| | 2 | 429 | | RequisitionId = requisitionId.Trim(); |
| | 2 | 430 | | changedFields.Add("requisition_id"); |
| | | 431 | | } |
| | | 432 | | |
| | | 433 | | // Recompute dedup keys if tenant or req id changed |
| | 20 | 434 | | if (changedFields.Contains("ats_tenant") || changedFields.Contains("requisition_id") || changedFields.Contains(" |
| | | 435 | | { |
| | 4 | 436 | | if (!string.IsNullOrWhiteSpace(AtsTenant) && !string.IsNullOrWhiteSpace(RequisitionId)) |
| | | 437 | | { |
| | 2 | 438 | | DedupKeyA = $"{AtsTenant}|{RequisitionId}"; |
| | 2 | 439 | | DedupKeyC = null; |
| | | 440 | | } |
| | 2 | 441 | | else if (string.IsNullOrWhiteSpace(AtsTenant) && !string.IsNullOrWhiteSpace(RequisitionId)) |
| | | 442 | | { |
| | 2 | 443 | | DedupKeyA = null; |
| | 2 | 444 | | DedupKeyC = $"{CompanyId:D}|{RequisitionId}"; |
| | | 445 | | } |
| | | 446 | | else |
| | | 447 | | { |
| | 0 | 448 | | DedupKeyA = null; |
| | 0 | 449 | | DedupKeyC = null; |
| | | 450 | | } |
| | | 451 | | } |
| | | 452 | | |
| | 20 | 453 | | if (location is not null && location != Location) |
| | | 454 | | { |
| | 6 | 455 | | Location = location.Trim(); |
| | 6 | 456 | | changedFields.Add("location"); |
| | | 457 | | } |
| | | 458 | | |
| | 20 | 459 | | if (remoteType.HasValue && remoteType.Value != RemoteType) |
| | | 460 | | { |
| | 4 | 461 | | RemoteType = remoteType.Value; |
| | 4 | 462 | | changedFields.Add("remote_type"); |
| | | 463 | | } |
| | | 464 | | |
| | 20 | 465 | | if (compensation is not null && compensation != Compensation) |
| | | 466 | | { |
| | 2 | 467 | | Compensation = compensation; |
| | 2 | 468 | | changedFields.Add("compensation"); |
| | | 469 | | } |
| | | 470 | | |
| | 20 | 471 | | if (postedDate is not null && postedDate != PostedDate) |
| | | 472 | | { |
| | 2 | 473 | | PostedDate = postedDate; |
| | 2 | 474 | | changedFields.Add("posted_date"); |
| | | 475 | | } |
| | | 476 | | |
| | 20 | 477 | | if (score.HasValue && score.Value != Score) |
| | | 478 | | { |
| | 8 | 479 | | if (score.Value < 0.0m || score.Value > 10.0m) |
| | | 480 | | { |
| | 2 | 481 | | throw new ArgumentException("Score must be between 0.0 and 10.0.", nameof(score)); |
| | | 482 | | } |
| | 6 | 483 | | Score = score.Value; |
| | 6 | 484 | | changedFields.Add("score"); |
| | | 485 | | } |
| | | 486 | | |
| | 18 | 487 | | if (cultureLevel.HasValue && cultureLevel.Value != CultureLevel) |
| | | 488 | | { |
| | 2 | 489 | | CultureLevel = cultureLevel.Value; |
| | 2 | 490 | | changedFields.Add("culture_level"); |
| | | 491 | | } |
| | | 492 | | |
| | 18 | 493 | | if (cultureSummary is not null && cultureSummary != CultureSummary) |
| | | 494 | | { |
| | 2 | 495 | | CultureSummary = cultureSummary.Trim(); |
| | 2 | 496 | | changedFields.Add("culture_summary"); |
| | | 497 | | } |
| | | 498 | | |
| | 18 | 499 | | if (duplicateOfId.HasValue && duplicateOfId.Value != DuplicateOfId) |
| | | 500 | | { |
| | 4 | 501 | | if (duplicateOfId.Value == Id) |
| | | 502 | | { |
| | 2 | 503 | | throw new ArgumentException("A posting cannot be a duplicate of itself.", nameof(duplicateOfId)); |
| | | 504 | | } |
| | 2 | 505 | | DuplicateOfId = duplicateOfId.Value; |
| | 2 | 506 | | changedFields.Add("duplicate_of_id"); |
| | | 507 | | } |
| | | 508 | | |
| | 16 | 509 | | if (screeningNoteId.HasValue && screeningNoteId.Value != ScreeningNoteId) |
| | | 510 | | { |
| | 2 | 511 | | ScreeningNoteId = screeningNoteId.Value; |
| | 2 | 512 | | changedFields.Add("screening_note_id"); |
| | | 513 | | } |
| | | 514 | | |
| | 16 | 515 | | if (compHighPriority.HasValue && compHighPriority.Value != CompHighPriority) |
| | | 516 | | { |
| | 2 | 517 | | CompHighPriority = compHighPriority.Value; |
| | 2 | 518 | | changedFields.Add("comp_high_priority"); |
| | | 519 | | } |
| | | 520 | | |
| | 16 | 521 | | if (changedFields.Count > 0) |
| | | 522 | | { |
| | 16 | 523 | | UpdatedAt = timestamp; |
| | 16 | 524 | | VersionToken = Guid.CreateVersion7(); |
| | | 525 | | } |
| | | 526 | | |
| | 16 | 527 | | return changedFields; |
| | | 528 | | } |
| | | 529 | | } |