| | | 1 | | namespace RoleRadar.Domain.Tracking; |
| | | 2 | | |
| | | 3 | | public sealed class CareerSource |
| | | 4 | | { |
| | | 5 | | public const int MaxTenantLength = 100; |
| | | 6 | | public const int MaxSlugLength = 150; |
| | | 7 | | public const int MaxNotesLength = 500; |
| | | 8 | | |
| | 266 | 9 | | public Guid Id { get; init; } |
| | 388 | 10 | | public string OwnerId { get; init; } = string.Empty; |
| | 214 | 11 | | public Guid CompanyId { get; init; } |
| | 390 | 12 | | public string AtsType { get; private set; } = string.Empty; |
| | 264 | 13 | | public string? Tenant { get; private set; } |
| | 258 | 14 | | public string? Slug { get; private set; } |
| | 226 | 15 | | public FetchMethod FetchMethod { get; private set; } = FetchMethod.Api; |
| | 220 | 16 | | public string? Notes { get; private set; } |
| | 408 | 17 | | public bool IsActive { get; private set; } = true; |
| | 244 | 18 | | public Guid VersionToken { get; private set; } |
| | 194 | 19 | | public DateTimeOffset CreatedAt { get; init; } |
| | 212 | 20 | | public DateTimeOffset UpdatedAt { get; private set; } |
| | | 21 | | |
| | | 22 | | public static CareerSource Create( |
| | | 23 | | string ownerId, |
| | | 24 | | Guid companyId, |
| | | 25 | | string atsType, |
| | | 26 | | string? tenant = null, |
| | | 27 | | string? slug = null, |
| | | 28 | | FetchMethod fetchMethod = FetchMethod.Api, |
| | | 29 | | string? notes = null, |
| | | 30 | | bool isActive = true, |
| | | 31 | | Guid? id = null, |
| | | 32 | | DateTimeOffset? now = null) |
| | | 33 | | { |
| | 68 | 34 | | ArgumentException.ThrowIfNullOrWhiteSpace(ownerId); |
| | 68 | 35 | | ArgumentException.ThrowIfNullOrWhiteSpace(atsType); |
| | | 36 | | |
| | 66 | 37 | | if (companyId == Guid.Empty) |
| | | 38 | | { |
| | 4 | 39 | | throw new ArgumentException("Company ID cannot be empty.", nameof(companyId)); |
| | | 40 | | } |
| | | 41 | | |
| | 62 | 42 | | if (tenant is not null && tenant.Length > MaxTenantLength) |
| | | 43 | | { |
| | 4 | 44 | | throw new ArgumentException($"Tenant cannot exceed {MaxTenantLength} characters.", nameof(tenant)); |
| | | 45 | | } |
| | | 46 | | |
| | 58 | 47 | | if (slug is not null && slug.Length > MaxSlugLength) |
| | | 48 | | { |
| | 4 | 49 | | throw new ArgumentException($"Slug cannot exceed {MaxSlugLength} characters.", nameof(slug)); |
| | | 50 | | } |
| | | 51 | | |
| | 54 | 52 | | if (notes is not null && notes.Length > MaxNotesLength) |
| | | 53 | | { |
| | 4 | 54 | | throw new ArgumentException($"Notes cannot exceed {MaxNotesLength} characters.", nameof(notes)); |
| | | 55 | | } |
| | | 56 | | |
| | 50 | 57 | | var timestamp = now ?? DateTimeOffset.UtcNow; |
| | | 58 | | |
| | 50 | 59 | | return new CareerSource |
| | 50 | 60 | | { |
| | 50 | 61 | | Id = id ?? Guid.CreateVersion7(), |
| | 50 | 62 | | OwnerId = ownerId.Trim(), |
| | 50 | 63 | | CompanyId = companyId, |
| | 50 | 64 | | AtsType = atsType.Trim(), |
| | 50 | 65 | | Tenant = tenant?.Trim(), |
| | 50 | 66 | | Slug = slug?.Trim(), |
| | 50 | 67 | | FetchMethod = fetchMethod, |
| | 50 | 68 | | Notes = notes, |
| | 50 | 69 | | IsActive = isActive, |
| | 50 | 70 | | VersionToken = Guid.CreateVersion7(), |
| | 50 | 71 | | CreatedAt = timestamp, |
| | 50 | 72 | | UpdatedAt = timestamp |
| | 50 | 73 | | }; |
| | | 74 | | } |
| | | 75 | | |
| | | 76 | | public static CareerSource Rehydrate( |
| | | 77 | | Guid id, |
| | | 78 | | string ownerId, |
| | | 79 | | Guid companyId, |
| | | 80 | | string atsType, |
| | | 81 | | string? tenant, |
| | | 82 | | string? slug, |
| | | 83 | | FetchMethod fetchMethod, |
| | | 84 | | string? notes, |
| | | 85 | | bool isActive, |
| | | 86 | | Guid versionToken, |
| | | 87 | | DateTimeOffset createdAt, |
| | | 88 | | DateTimeOffset updatedAt) |
| | | 89 | | { |
| | 98 | 90 | | return new CareerSource |
| | 98 | 91 | | { |
| | 98 | 92 | | Id = id, |
| | 98 | 93 | | OwnerId = ownerId, |
| | 98 | 94 | | CompanyId = companyId, |
| | 98 | 95 | | AtsType = atsType, |
| | 98 | 96 | | Tenant = tenant, |
| | 98 | 97 | | Slug = slug, |
| | 98 | 98 | | FetchMethod = fetchMethod, |
| | 98 | 99 | | Notes = notes, |
| | 98 | 100 | | IsActive = isActive, |
| | 98 | 101 | | VersionToken = versionToken, |
| | 98 | 102 | | CreatedAt = createdAt, |
| | 98 | 103 | | UpdatedAt = updatedAt |
| | 98 | 104 | | }; |
| | | 105 | | } |
| | | 106 | | |
| | | 107 | | public void Retire(DateTimeOffset? now = null) |
| | | 108 | | { |
| | 6 | 109 | | IsActive = false; |
| | 6 | 110 | | VersionToken = Guid.CreateVersion7(); |
| | 6 | 111 | | UpdatedAt = now ?? DateTimeOffset.UtcNow; |
| | 6 | 112 | | } |
| | | 113 | | |
| | | 114 | | public void Reactivate(DateTimeOffset? now = null) |
| | | 115 | | { |
| | 6 | 116 | | IsActive = true; |
| | 6 | 117 | | VersionToken = Guid.CreateVersion7(); |
| | 6 | 118 | | UpdatedAt = now ?? DateTimeOffset.UtcNow; |
| | 6 | 119 | | } |
| | | 120 | | |
| | | 121 | | public void Update( |
| | | 122 | | string? atsType = null, |
| | | 123 | | string? tenant = null, |
| | | 124 | | string? slug = null, |
| | | 125 | | FetchMethod? fetchMethod = null, |
| | | 126 | | string? notes = null, |
| | | 127 | | bool? isActive = null, |
| | | 128 | | DateTimeOffset? now = null) |
| | | 129 | | { |
| | 12 | 130 | | if (!string.IsNullOrWhiteSpace(atsType)) |
| | | 131 | | { |
| | 6 | 132 | | AtsType = atsType.Trim(); |
| | | 133 | | } |
| | | 134 | | |
| | 12 | 135 | | if (tenant is not null) |
| | | 136 | | { |
| | 8 | 137 | | if (tenant.Length > MaxTenantLength) |
| | | 138 | | { |
| | 2 | 139 | | throw new ArgumentException($"Tenant cannot exceed {MaxTenantLength} characters.", nameof(tenant)); |
| | | 140 | | } |
| | 6 | 141 | | Tenant = tenant.Trim(); |
| | | 142 | | } |
| | | 143 | | |
| | 10 | 144 | | if (slug is not null) |
| | | 145 | | { |
| | 8 | 146 | | if (slug.Length > MaxSlugLength) |
| | | 147 | | { |
| | 2 | 148 | | throw new ArgumentException($"Slug cannot exceed {MaxSlugLength} characters.", nameof(slug)); |
| | | 149 | | } |
| | 6 | 150 | | Slug = slug.Trim(); |
| | | 151 | | } |
| | | 152 | | |
| | 8 | 153 | | if (fetchMethod.HasValue) |
| | | 154 | | { |
| | 6 | 155 | | FetchMethod = fetchMethod.Value; |
| | | 156 | | } |
| | | 157 | | |
| | 8 | 158 | | if (notes is not null) |
| | | 159 | | { |
| | 4 | 160 | | if (notes.Length > MaxNotesLength) |
| | | 161 | | { |
| | 2 | 162 | | throw new ArgumentException($"Notes cannot exceed {MaxNotesLength} characters.", nameof(notes)); |
| | | 163 | | } |
| | 2 | 164 | | Notes = notes; |
| | | 165 | | } |
| | | 166 | | |
| | 6 | 167 | | if (isActive.HasValue) |
| | | 168 | | { |
| | 6 | 169 | | IsActive = isActive.Value; |
| | | 170 | | } |
| | | 171 | | |
| | 6 | 172 | | VersionToken = Guid.CreateVersion7(); |
| | 6 | 173 | | UpdatedAt = now ?? DateTimeOffset.UtcNow; |
| | 6 | 174 | | } |
| | | 175 | | } |