@jsb188/schedule 1.1.12 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +33 -14
  3. package/src/constants/schedule.ts +710 -306
  4. package/src/types/schedule.d.ts +1827 -456
  5. package/src/ui/ScheduleSettingsUI.tsx +21 -23
  6. package/src/utils/autofill.ts +469 -0
  7. package/src/utils/availability.ts +167 -0
  8. package/src/utils/candidates.ts +447 -0
  9. package/src/utils/coverage.helpers.ts +509 -554
  10. package/src/utils/coverage.ts +1121 -526
  11. package/src/utils/cpm.helpers.ts +27 -29
  12. package/src/utils/cpm.ts +53 -41
  13. package/src/utils/cpmLeveling.helpers.ts +89 -16
  14. package/src/utils/cpmLeveling.ts +28 -26
  15. package/src/utils/cycle.ts +325 -0
  16. package/src/utils/demand.ts +239 -0
  17. package/src/utils/eligibility.ts +553 -400
  18. package/src/utils/ids.ts +47 -0
  19. package/src/utils/laborRules.ts +740 -0
  20. package/src/utils/localTime.ts +312 -0
  21. package/src/utils/offer.ts +300 -0
  22. package/src/utils/planCsv.ts +73 -19
  23. package/src/utils/predicate.ts +111 -0
  24. package/src/utils/request.ts +212 -114
  25. package/src/utils/resource.ts +412 -112
  26. package/src/utils/rule.ts +697 -163
  27. package/src/utils/rulePresets.ts +116 -0
  28. package/src/utils/run.ts +0 -8
  29. package/src/utils/scheduleText.ts +4074 -0
  30. package/src/utils/shiftChange.ts +279 -0
  31. package/src/utils/standing.ts +730 -0
  32. package/src/utils/template.ts +619 -0
  33. package/src/utils/violation.ts +184 -0
  34. package/src/utils/workTime.ts +341 -120
  35. package/src/utils/defaults.ts +0 -8
  36. package/src/utils/recurrence.ts +0 -616
  37. package/src/utils/series.ts +0 -161
  38. package/src/utils/slot.ts +0 -208
  39. package/tests/coverage.fixtures.ts +0 -111
  40. package/tests/coverage.test.ts +0 -503
  41. package/tests/cpm.bench.test.ts +0 -154
  42. package/tests/cpm.test.ts +0 -354
  43. package/tests/cpmCorrectness.test.ts +0 -327
  44. package/tests/cpmLeveling.test.ts +0 -471
  45. package/tests/eligibility.test.ts +0 -320
  46. package/tests/gantt-geometry.test.ts +0 -367
  47. package/tests/gantt-histogram.test.ts +0 -78
  48. package/tests/gantt-keyboard.test.ts +0 -69
  49. package/tests/helpers/cpmFixtures.ts +0 -101
  50. package/tests/projectInputs.test.ts +0 -165
  51. package/tests/recurrence.test.ts +0 -68
  52. package/tests/request.test.ts +0 -99
  53. package/tests/resource.test.ts +0 -95
  54. package/tests/rule.test.ts +0 -98
  55. package/tests/series.test.ts +0 -120
  56. package/tests/workTime.test.ts +0 -1007
  57. package/tests/workTimeContracts.test.ts +0 -111
  58. package/tsconfig.json +0 -13
  59. package/vitest.config.ts +0 -8
@@ -1,63 +1,156 @@
1
1
  import type {
2
- SCHEDULE_ASSIGNMENT_VIA_ENUMS,
3
- SCHEDULE_ASSIGNMENT_RELEASE_REASON_ENUMS,
4
- SCHEDULE_REQUEST_KIND_ENUMS,
5
- SCHEDULE_REQUEST_STATUS_ENUMS,
6
- SCHEDULE_PROJECT_RUN_KIND_ENUMS,
7
- SCHEDULE_PROJECT_RUN_TRIGGER_ENUMS,
8
- SCHEDULE_NOTIFICATION_STATUS_ENUMS,
9
- SCHEDULE_NOTIFICATION_EVENT_KIND_ENUMS,
10
2
  SCHEDULE_ACTIVITY_STATUS_ENUMS,
11
3
  SCHEDULE_ACTIVITY_TYPE_ENUMS,
12
- SCHEDULE_ASSIGNMENT_STATUS_ENUMS,
4
+ SCHEDULE_ASK_ANSWER_ENUMS,
5
+ SCHEDULE_ASK_ANSWER_VIA_ENUMS,
6
+ SCHEDULE_ASK_CHANNEL_ENUMS,
7
+ SCHEDULE_ASK_KIND_ENUMS,
8
+ SCHEDULE_ASK_REASON_ENUMS,
9
+ SCHEDULE_ASK_STATUS_ENUMS,
10
+ SCHEDULE_AVAILABILITY_KIND_ENUMS,
13
11
  SCHEDULE_CONSTRAINT_TYPE_ENUMS,
14
- SCHEDULE_DEFAULT_VIEW_ENUMS,
12
+ SCHEDULE_COVERAGE_DIAGNOSTIC_CODE_ENUMS,
13
+ SCHEDULE_CRITICALITY_MODE_ENUMS,
15
14
  SCHEDULE_DIAGNOSTIC_CODE_ENUMS,
15
+ SCHEDULE_DIAGNOSTIC_SEVERITY_ENUMS,
16
+ SCHEDULE_EDIT_SCOPE_ENUMS,
17
+ SCHEDULE_ELIGIBILITY_REASON_ENUMS,
18
+ SCHEDULE_ELIGIBILITY_VIOLATION_CODE_ENUMS,
16
19
  SCHEDULE_LAG_CALENDAR_ENUMS,
17
- SCHEDULE_MODE_ENUMS,
18
- SCHEDULE_OCCURRENCE_KIND_ENUMS,
19
- SCHEDULE_OCCURRENCE_STATUS_ENUMS,
20
+ SCHEDULE_LEVELING_PRIORITY_RULE_ENUMS,
21
+ SCHEDULE_MAX_HOURS_PERIOD_ENUMS,
22
+ SCHEDULE_NOTICE_VIOLATION_CODE_ENUMS,
23
+ SCHEDULE_NOTIFICATION_DELIVERY_STATUS_ENUMS,
24
+ SCHEDULE_NOTIFICATION_EVENT_KIND_ENUMS,
25
+ SCHEDULE_NOTIFICATION_SKIP_REASON_ENUMS,
26
+ SCHEDULE_NOTIFICATION_STATUS_ENUMS,
27
+ SCHEDULE_NOTIFY_CHANNEL_ENUMS,
28
+ SCHEDULE_OFFER_CREATED_VIA_ENUMS,
29
+ SCHEDULE_OFFER_STATUS_ENUMS,
30
+ SCHEDULE_PREPARE_EDIT_KIND_ENUMS,
20
31
  SCHEDULE_PROGRESS_LOGIC_ENUMS,
32
+ SCHEDULE_PROJECT_CHECK_CADENCE_ENUMS,
33
+ SCHEDULE_PROJECT_RUN_KIND_ENUMS,
21
34
  SCHEDULE_PROJECT_RUN_STATUS_ENUMS,
35
+ SCHEDULE_PROJECT_RUN_TRIGGER_ENUMS,
22
36
  SCHEDULE_PROJECT_STATUS_ENUMS,
23
- SCHEDULE_RECURRENCE_FREQ_ENUMS,
37
+ SCHEDULE_RATIO_MODE_ENUMS,
38
+ SCHEDULE_RATIO_VIOLATION_CODE_ENUMS,
24
39
  SCHEDULE_RELATIONSHIP_TYPE_ENUMS,
40
+ SCHEDULE_REQUEST_KIND_ENUMS,
41
+ SCHEDULE_REQUEST_STATUS_ENUMS,
42
+ SCHEDULE_REQUEST_VIA_ENUMS,
25
43
  SCHEDULE_RESOURCE_KIND_ENUMS,
44
+ SCHEDULE_ROSTER_UNFILLED_REASON_ENUMS,
26
45
  SCHEDULE_RULE_KIND_ENUMS,
27
46
  SCHEDULE_RULE_SEVERITY_ENUMS,
47
+ SCHEDULE_SHIFT_CHANGE_KIND_ENUMS,
48
+ SCHEDULE_SHIFT_CHANGE_VIA_ENUMS,
49
+ SCHEDULE_SHIFT_CREATED_VIA_ENUMS,
50
+ SCHEDULE_SHIFT_EDIT_FIELDS,
51
+ SCHEDULE_SHIFT_RETIME_FIELDS,
52
+ SCHEDULE_SHIFT_STATUS_ENUMS,
53
+ SCHEDULE_SMS_CONSENT_ENUMS,
28
54
  SCHEDULE_SOURCE_KIND_ENUMS,
29
55
  SCHEDULE_SOURCE_REVIEW_STATUS_ENUMS,
30
- SCHEDULE_CRITICALITY_MODE_ENUMS,
31
- SCHEDULE_LEVELING_PRIORITY_RULE_ENUMS,
32
- SCHEDULE_DIAGNOSTIC_SEVERITY_ENUMS,
33
- SCHEDULE_ELIGIBILITY_REASON_ENUMS,
34
- SCHEDULE_COVERAGE_DIAGNOSTIC_CODE_ENUMS,
56
+ SCHEDULE_STAFF_VISIBILITY_ENUMS,
57
+ SCHEDULE_STANDING_FIELD_GROUP_ENUMS,
58
+ SCHEDULE_TASK_CREATED_VIA_ENUMS,
59
+ SCHEDULE_TASK_PRIORITY_ENUMS,
60
+ SCHEDULE_TASK_STATUS_ENUMS,
35
61
  SCHEDULE_TIME_OFF_STATUS_ENUMS,
36
- SCHEDULE_NOTIFY_CHANNEL_ENUMS,
37
- SCHEDULE_ELIGIBILITY_VIOLATION_CODE_ENUMS,
38
- SCHEDULE_ACTOR_WINDOW_VIOLATION_CODE_ENUMS,
39
62
  } from '../constants/schedule.ts';
40
63
 
41
64
  /**
42
- * Enums
65
+ * Enums: staff schedules
43
66
  */
44
67
 
45
- export type ScheduleModeEnum = (typeof SCHEDULE_MODE_ENUMS)[number];
46
- export type ScheduleDefaultViewEnum =
47
- (typeof SCHEDULE_DEFAULT_VIEW_ENUMS)[number];
48
68
  export type ScheduleResourceKindEnum =
49
69
  (typeof SCHEDULE_RESOURCE_KIND_ENUMS)[number];
50
- export type ScheduleOccurrenceKindEnum =
51
- (typeof SCHEDULE_OCCURRENCE_KIND_ENUMS)[number];
52
- export type ScheduleOccurrenceStatusEnum =
53
- (typeof SCHEDULE_OCCURRENCE_STATUS_ENUMS)[number];
54
- export type ScheduleAssignmentStatusEnum =
55
- (typeof SCHEDULE_ASSIGNMENT_STATUS_ENUMS)[number];
70
+ export type ScheduleShiftStatusEnum =
71
+ (typeof SCHEDULE_SHIFT_STATUS_ENUMS)[number];
72
+ export type ScheduleShiftCreatedViaEnum =
73
+ (typeof SCHEDULE_SHIFT_CREATED_VIA_ENUMS)[number];
74
+ export type ScheduleShiftChangeKindEnum =
75
+ (typeof SCHEDULE_SHIFT_CHANGE_KIND_ENUMS)[number];
76
+ export type ScheduleShiftChangeViaEnum =
77
+ (typeof SCHEDULE_SHIFT_CHANGE_VIA_ENUMS)[number];
78
+ export type ScheduleShiftJournalFieldEnum =
79
+ | (typeof SCHEDULE_SHIFT_RETIME_FIELDS)[number]
80
+ | (typeof SCHEDULE_SHIFT_EDIT_FIELDS)[number];
81
+ export type ScheduleAvailabilityKindEnum =
82
+ (typeof SCHEDULE_AVAILABILITY_KIND_ENUMS)[number];
56
83
  export type ScheduleRuleKindEnum = (typeof SCHEDULE_RULE_KIND_ENUMS)[number];
57
84
  export type ScheduleRuleSeverityEnum =
58
85
  (typeof SCHEDULE_RULE_SEVERITY_ENUMS)[number];
59
- export type ScheduleRecurrenceFreqEnum =
60
- (typeof SCHEDULE_RECURRENCE_FREQ_ENUMS)[number];
86
+ export type ScheduleMaxHoursPeriodEnum =
87
+ (typeof SCHEDULE_MAX_HOURS_PERIOD_ENUMS)[number];
88
+ export type ScheduleRatioModeEnum = (typeof SCHEDULE_RATIO_MODE_ENUMS)[number];
89
+ export type ScheduleEligibilityReasonEnum =
90
+ (typeof SCHEDULE_ELIGIBILITY_REASON_ENUMS)[number];
91
+ export type ScheduleEligibilityViolationCodeEnum =
92
+ (typeof SCHEDULE_ELIGIBILITY_VIOLATION_CODE_ENUMS)[number];
93
+ export type ScheduleCoverageDiagnosticCodeEnum =
94
+ (typeof SCHEDULE_COVERAGE_DIAGNOSTIC_CODE_ENUMS)[number];
95
+ export type ScheduleRequestKindEnum =
96
+ (typeof SCHEDULE_REQUEST_KIND_ENUMS)[number];
97
+ export type ScheduleRequestStatusEnum =
98
+ (typeof SCHEDULE_REQUEST_STATUS_ENUMS)[number];
99
+ export type ScheduleRequestViaEnum =
100
+ (typeof SCHEDULE_REQUEST_VIA_ENUMS)[number];
101
+ export type ScheduleTimeOffStatusEnum =
102
+ (typeof SCHEDULE_TIME_OFF_STATUS_ENUMS)[number];
103
+ export type ScheduleNotificationStatusEnum =
104
+ (typeof SCHEDULE_NOTIFICATION_STATUS_ENUMS)[number];
105
+ export type ScheduleNotificationEventKindEnum =
106
+ (typeof SCHEDULE_NOTIFICATION_EVENT_KIND_ENUMS)[number];
107
+ export type ScheduleNotifyChannelEnum =
108
+ (typeof SCHEDULE_NOTIFY_CHANNEL_ENUMS)[number];
109
+ export type ScheduleNotificationDeliveryStatusEnum =
110
+ (typeof SCHEDULE_NOTIFICATION_DELIVERY_STATUS_ENUMS)[number];
111
+ export type ScheduleNotificationSkipReasonEnum =
112
+ (typeof SCHEDULE_NOTIFICATION_SKIP_REASON_ENUMS)[number];
113
+ export type ScheduleStaffVisibilityEnum =
114
+ (typeof SCHEDULE_STAFF_VISIBILITY_ENUMS)[number];
115
+ export type ScheduleAskKindEnum = (typeof SCHEDULE_ASK_KIND_ENUMS)[number];
116
+ export type ScheduleAskStatusEnum = (typeof SCHEDULE_ASK_STATUS_ENUMS)[number];
117
+ export type ScheduleAskChannelEnum =
118
+ (typeof SCHEDULE_ASK_CHANNEL_ENUMS)[number];
119
+ export type ScheduleAskAnswerEnum = (typeof SCHEDULE_ASK_ANSWER_ENUMS)[number];
120
+ export type ScheduleAskAnswerViaEnum =
121
+ (typeof SCHEDULE_ASK_ANSWER_VIA_ENUMS)[number];
122
+ export type ScheduleAskReasonEnum = (typeof SCHEDULE_ASK_REASON_ENUMS)[number];
123
+ export type ScheduleOfferStatusEnum =
124
+ (typeof SCHEDULE_OFFER_STATUS_ENUMS)[number];
125
+ export type ScheduleOfferCreatedViaEnum =
126
+ (typeof SCHEDULE_OFFER_CREATED_VIA_ENUMS)[number];
127
+ export type ScheduleSmsConsentEnum =
128
+ (typeof SCHEDULE_SMS_CONSENT_ENUMS)[number];
129
+ export type ScheduleEditScopeEnum = (typeof SCHEDULE_EDIT_SCOPE_ENUMS)[number];
130
+ export type ScheduleStandingFieldGroupEnum =
131
+ (typeof SCHEDULE_STANDING_FIELD_GROUP_ENUMS)[number];
132
+ export type ScheduleRosterUnfilledReasonEnum =
133
+ (typeof SCHEDULE_ROSTER_UNFILLED_REASON_ENUMS)[number];
134
+ export type SchedulePrepareEditKindEnum =
135
+ (typeof SCHEDULE_PREPARE_EDIT_KIND_ENUMS)[number];
136
+ export type ScheduleTaskStatusEnum =
137
+ (typeof SCHEDULE_TASK_STATUS_ENUMS)[number];
138
+ export type ScheduleTaskCreatedViaEnum =
139
+ (typeof SCHEDULE_TASK_CREATED_VIA_ENUMS)[number];
140
+ export type ScheduleTaskPriorityEnum =
141
+ (typeof SCHEDULE_TASK_PRIORITY_ENUMS)[number];
142
+
143
+ // The code on a persisted finding: ELIGIBILITY, RATIO and NOTICE_PERIOD carry
144
+ // one; every other kind has code null
145
+ export type ScheduleCoverageViolationCode =
146
+ | ScheduleEligibilityViolationCodeEnum
147
+ | (typeof SCHEDULE_RATIO_VIOLATION_CODE_ENUMS)[number]
148
+ | (typeof SCHEDULE_NOTICE_VIOLATION_CODE_ENUMS)[number];
149
+
150
+ /**
151
+ * Enums: projects
152
+ */
153
+
61
154
  export type ScheduleProjectStatusEnum =
62
155
  (typeof SCHEDULE_PROJECT_STATUS_ENUMS)[number];
63
156
  export type ScheduleActivityTypeEnum =
@@ -82,6 +175,12 @@ export type ScheduleSourceKindEnum =
82
175
  (typeof SCHEDULE_SOURCE_KIND_ENUMS)[number];
83
176
  export type ScheduleSourceReviewStatusEnum =
84
177
  (typeof SCHEDULE_SOURCE_REVIEW_STATUS_ENUMS)[number];
178
+ export type ScheduleProjectRunKindEnum =
179
+ (typeof SCHEDULE_PROJECT_RUN_KIND_ENUMS)[number];
180
+ export type ScheduleProjectRunTriggerEnum =
181
+ (typeof SCHEDULE_PROJECT_RUN_TRIGGER_ENUMS)[number];
182
+ export type ScheduleProjectCheckCadenceEnum =
183
+ (typeof SCHEDULE_PROJECT_CHECK_CADENCE_ENUMS)[number];
85
184
 
86
185
  /**
87
186
  * Every *Data interface below models a database row, so ids are the shapes
@@ -90,31 +189,6 @@ export type ScheduleSourceReviewStatusEnum =
90
189
  */
91
190
  export type ScheduleId = number | bigint;
92
191
 
93
- export type ScheduleAssignmentViaEnum =
94
- (typeof SCHEDULE_ASSIGNMENT_VIA_ENUMS)[number];
95
- export type ScheduleAssignmentReleaseReasonEnum =
96
- (typeof SCHEDULE_ASSIGNMENT_RELEASE_REASON_ENUMS)[number];
97
- export type ScheduleRequestKindEnum =
98
- (typeof SCHEDULE_REQUEST_KIND_ENUMS)[number];
99
- export type ScheduleRequestStatusEnum =
100
- (typeof SCHEDULE_REQUEST_STATUS_ENUMS)[number];
101
- export type ScheduleProjectRunKindEnum =
102
- (typeof SCHEDULE_PROJECT_RUN_KIND_ENUMS)[number];
103
- export type ScheduleProjectRunTriggerEnum =
104
- (typeof SCHEDULE_PROJECT_RUN_TRIGGER_ENUMS)[number];
105
- export type ScheduleNotificationStatusEnum =
106
- (typeof SCHEDULE_NOTIFICATION_STATUS_ENUMS)[number];
107
- export type ScheduleNotificationEventKindEnum =
108
- (typeof SCHEDULE_NOTIFICATION_EVENT_KIND_ENUMS)[number];
109
-
110
- export interface ScheduleRequestPolicyObj {
111
- autoApproveClaims: boolean;
112
- autoApproveDrops: boolean;
113
- requireCounterpartyConsent: boolean;
114
- minNoticeHours: number;
115
- requestExpiryHours: number;
116
- }
117
-
118
192
  /**
119
193
  * Base access policy shared with Sheets and Notes; grants live in
120
194
  * access_grants rows
@@ -129,7 +203,9 @@ export interface ScheduleAccessObj {
129
203
  * Working-time calendars
130
204
  */
131
205
 
132
- // "HH:mm" local wall-clock bounds of one working interval, end exclusive
206
+ // "HH:mm" local wall-clock bounds of one working interval, end exclusive. An
207
+ // end at or before the start ends on the next day (a bar's 20:00-02:00); the
208
+ // spill belongs to the start's day.
133
209
  export type ScheduleWorkInterval = [string, string];
134
210
 
135
211
  // Working intervals per JavaScript weekday key ("0" = Sunday); a missing or
@@ -182,7 +258,7 @@ export interface ScheduleWorkCalendarExceptionData {
182
258
  }
183
259
 
184
260
  /**
185
- * Resources
261
+ * Resources, roles, capacity and availability
186
262
  */
187
263
 
188
264
  export interface ScheduleQualificationObj {
@@ -190,12 +266,19 @@ export interface ScheduleQualificationObj {
190
266
  expiresAt: string | null; // normalized ISO instant, or null = never expires
191
267
  }
192
268
 
269
+ export interface ScheduleNotifyPrefsObj {
270
+ channels: ScheduleNotifyChannelEnum[]; // deduped; [] = opted out. The validator is the only writer.
271
+ }
272
+
273
+ export interface ScheduleResourcePreferencesObj {
274
+ targetWeeklyMinutes: number | null; // worked minutes wanted per pay week (candidate ranking); null = no preference
275
+ }
276
+
193
277
  export interface ScheduleResourceConfigObj {
194
- qualifications: ScheduleQualificationObj[]; // LABOR only, else []
195
- roles: string[]; // LABOR only, sorted
278
+ qualifications: ScheduleQualificationObj[]; // PERSON only, else []; sorted by key
196
279
  tags: string[]; // any kind, sorted
197
- ageGroup: string | null; // SPACE only: UI default key for new demand rows; the engine never reads it
198
- notify: ScheduleNotifyPrefsObj | null; // LABOR only; read by schedule_notify, never by the engine
280
+ notify: ScheduleNotifyPrefsObj | null; // PERSON only; read by schedule notify, never by the engine
281
+ preferences: ScheduleResourcePreferencesObj | null; // PERSON only
199
282
  }
200
283
 
201
284
  export interface ScheduleResourceData {
@@ -204,24 +287,28 @@ export interface ScheduleResourceData {
204
287
  id: ScheduleId;
205
288
  organizationId: ScheduleId;
206
289
  siteId: ScheduleId | null;
207
- accountId: ScheduleId | null;
290
+ accountId: ScheduleId | null; // set exactly when kind = PERSON
208
291
  workCalendarId: ScheduleId | null;
209
292
  kind: ScheduleResourceKindEnum;
210
293
  key: string;
211
294
  name: string;
212
- // Largest units one day may hold for LABOR and EQUIPMENT (minutes)
295
+ // Largest units one day may hold for PERSON, LABOR and EQUIPMENT (minutes)
213
296
  maxUnitsPerDay: number | null;
214
- // Concurrent occupancy for SPACE; null means unbounded
297
+ // Concurrent occupancy for SPACE (licensed children); null means unbounded
215
298
  capacity: number | null;
216
299
  unitOfMeasure: string | null;
217
300
  config: ScheduleResourceConfigObj;
218
301
  ordinal: number;
219
302
  retiredAt: Date | string | null;
303
+ smsConsent: ScheduleSmsConsentEnum; // PERSON only; NONE for every other kind
304
+ smsConsentAskedAt: Date | string | null; // when the consent ask was sent
305
+ smsConsentAt: Date | string | null; // when the person opted in or out
220
306
  createdAt: Date | string;
221
307
  updatedAt: Date | string;
222
308
  }
223
309
 
224
- export interface ScheduleResourceAvailabilityData {
310
+ // schedule_resource_capacity: dated leveling capacity; never read by shifts
311
+ export interface ScheduleResourceCapacityData {
225
312
  id: ScheduleId;
226
313
  organizationId: ScheduleId;
227
314
  resourceId: ScheduleId;
@@ -233,183 +320,339 @@ export interface ScheduleResourceAvailabilityData {
233
320
  updatedAt: Date | string;
234
321
  }
235
322
 
236
- /**
237
- * Calendars, recurring series and coverage occurrences
238
- */
239
-
240
- export interface ScheduleCalendarData {
241
- revision: number | bigint;
242
- version: number | bigint;
323
+ // schedule_roles: the org's positions (BARTENDER, LEAD_TEACHER)
324
+ export interface ScheduleRoleData {
243
325
  id: ScheduleId;
244
326
  organizationId: ScheduleId;
327
+ key: string;
245
328
  name: string;
246
- description: string | null;
247
- timeZone: string;
248
- siteId: ScheduleId | null;
249
- workCalendarId: ScheduleId | null;
250
- access: ScheduleAccessObj | null;
251
329
  color: string | null;
252
- settings: Record<string, unknown>;
330
+ requiredQualifications: string[]; // qualification keys a holder needs, unexpired at seat start
253
331
  ordinal: number;
332
+ archivedAt: Date | string | null; // hidden from pickers; existing seats keep it
333
+ createdAt: Date | string;
334
+ updatedAt: Date | string;
335
+ }
336
+
337
+ // schedule_availability: a recurring weekly window a PERSON cannot work or
338
+ // prefers to work. No rows = available.
339
+ export interface ScheduleAvailabilityData {
340
+ id: ScheduleId;
341
+ organizationId: ScheduleId;
342
+ resourceId: ScheduleId;
343
+ kind: ScheduleAvailabilityKindEnum;
344
+ weekday: number; // 0 = Sunday ... 6 = Saturday
345
+ startTime: string; // TIME: 'HH:mm:ss' as read from Postgres
346
+ endTime: string; // <= startTime ends the next day; 00:00-00:00 = all day
347
+ timeZone: string; // the zone the local times were stated in
348
+ effectiveFrom: Date | string;
349
+ effectiveTo: Date | string | null; // inclusive; null = open-ended
350
+ note: string | null;
254
351
  createdByAccountId: ScheduleId | null;
255
- deletedAt: Date | string | null;
256
352
  createdAt: Date | string;
257
353
  updatedAt: Date | string;
258
354
  }
259
355
 
260
- /**
261
- * One recurrence rule, stored as schedule_series."recurrence" JSONB.
262
- *
263
- * - byWeekday uses the JavaScript convention (0 = Sunday ... 6 = Saturday)
264
- * and applies to WEEKLY rules
265
- * - byMonthDay applies to MONTHLY and YEARLY rules; -1 means the last day
266
- * - byMonth (1 = January ... 12 = December) applies to YEARLY rules
267
- * - count and until both bound the series; whichever is reached first wins
268
- */
269
- export interface ScheduleRecurrenceObj {
270
- freq: ScheduleRecurrenceFreqEnum;
271
- interval?: number | null;
272
- byWeekday?: number[] | null;
273
- byMonthDay?: number[] | null;
274
- byMonth?: number[] | null;
275
- count?: number | null;
276
- until?: string | null;
356
+ export interface ScheduleTimeOffData {
357
+ allDay: boolean;
358
+ timeZone: string;
359
+ id: ScheduleId;
360
+ organizationId: ScheduleId;
361
+ resourceId: ScheduleId;
362
+ requesterAccountId: ScheduleId | null;
363
+ startAt: Date | string;
364
+ endAt: Date | string;
365
+ status: ScheduleTimeOffStatusEnum;
366
+ reason: string | null;
367
+ decidedByAccountId: ScheduleId | null;
368
+ decidedAt: Date | string | null;
369
+ decisionNote: string | null;
370
+ version: number | bigint;
371
+ createdAt: Date | string;
372
+ updatedAt: Date | string;
277
373
  }
278
374
 
279
375
  /**
280
- * Who may fill a slot. Every listed requirement must hold; an empty predicate
281
- * means anyone.
376
+ * Settings (validated JSON, no DDL)
282
377
  */
283
- export interface ScheduleSlotPredicateObj {
284
- roles?: string[] | null;
285
- qualifications?: string[] | null;
286
- tags?: string[] | null;
378
+
379
+ // organizations.settings.schedule.ageGroups entry, ordered youngest first
380
+ export interface ScheduleAgeGroupObj {
381
+ key: string; // the demand key and RATIO ratio key
382
+ label: string;
383
+ }
384
+
385
+ // organizations.settings.schedule
386
+ export interface ScheduleOrganizationSettingsObj {
387
+ ageGroups: ScheduleAgeGroupObj[];
388
+ payWeekStart: number; // 0 = Sunday ... 6 = Saturday: every week, pay week and period starts here
389
+ }
390
+
391
+ // settings.cycle: how the next period is prepared (Phase 3)
392
+ export interface ScheduleCycleSettingsObj {
393
+ enabled: boolean;
394
+ weeks: 1 | 2; // how far ahead one period reaches; independent of rotationWeeks
395
+ prepareDaysBefore: number; // days before the period's first day
396
+ prepareAtHour: number; // 0..23, calendar-local
287
397
  }
288
398
 
289
- export interface ScheduleSlotTemplateObj {
399
+ // settings.instructions entry: a standing instruction for the preparation pass
400
+ export interface ScheduleInstructionObj {
290
401
  key: string;
291
- label: string | null;
292
- requiredCount: number;
293
- predicate: ScheduleSlotPredicateObj | null;
294
- ordinal: number;
402
+ text: string; // at most SCHEDULE_INSTRUCTION_MAX_LENGTH characters
295
403
  }
296
404
 
297
- export interface ScheduleSeriesData {
298
- finishedAt: Date | string | null;
405
+ // settings.requestPolicy
406
+ export interface ScheduleRequestPolicyObj {
407
+ autoApproveClaims: boolean;
408
+ autoApproveDrops: boolean;
409
+ autoApproveCallOuts: boolean;
410
+ autoApproveSwaps: boolean; // after the counterparty agrees
411
+ minNoticeHours: number; // 0..8760; never applies to CALL_OUT or CLAIM
412
+ requestExpiryHours: number; // 0..8760; 0 = expires only at the seat's start
413
+ }
414
+
415
+ // Calendar-local 'HH:mm' bounds; an end at or before the start ends next day
416
+ export interface ScheduleQuietHoursObj {
417
+ start: string;
418
+ end: string;
419
+ }
420
+
421
+ // settings.offerDefaults (Phase 2)
422
+ export interface ScheduleOfferDefaultsObj {
423
+ waveSize: number; // candidates asked per wave; 1 = one person at a time
424
+ responseWindowMinutes: number; // gap between waves
425
+ autoApprove: boolean; // a yes to an offer is approved on the spot
426
+ autoOfferOnOpen: boolean; // an approved DROP / CALL_OUT starts an offer
427
+ quietHours: ScheduleQuietHoursObj | null; // waves move out of it unless the seat starts within 12 hours
428
+ }
429
+
430
+ // settings.notify
431
+ export interface ScheduleCalendarNotifyObj {
432
+ defaultChannels: ScheduleNotifyChannelEnum[];
433
+ }
434
+
435
+ // schedule_calendars.settings, every key resolved (SCHEDULE_CALENDAR_DEFAULT_SETTINGS)
436
+ export interface ScheduleCalendarSettingsObj {
437
+ cycle: ScheduleCycleSettingsObj;
438
+ instructions: ScheduleInstructionObj[];
439
+ requestPolicy: ScheduleRequestPolicyObj;
440
+ offerDefaults: ScheduleOfferDefaultsObj;
441
+ decisionMakers: string[]; // decimal account ids asked to decide; [] = the calendar's managers
442
+ staffVisibility: ScheduleStaffVisibilityEnum;
443
+ notify: ScheduleCalendarNotifyObj;
444
+ }
445
+
446
+ /**
447
+ * Calendars (one location plus its access unit)
448
+ */
449
+
450
+ export interface ScheduleCalendarData {
451
+ revision: number | bigint;
299
452
  version: number | bigint;
300
453
  id: ScheduleId;
301
454
  organizationId: ScheduleId;
302
- calendarId: ScheduleId;
303
- resourceId: ScheduleId | null;
304
- kind: ScheduleOccurrenceKindEnum;
305
- title: string;
306
- note: string | null;
307
- location: string | null;
308
- recurrence: ScheduleRecurrenceObj;
455
+ name: string;
456
+ description: string | null;
309
457
  timeZone: string;
310
- startsAt: Date | string;
311
- endsAt: Date | string | null;
312
- durationMinutes: number;
313
- allDay: boolean;
314
- slotTemplate: ScheduleSlotTemplateObj[];
315
- active: boolean;
316
- materializedThrough: Date | string | null;
458
+ siteId: ScheduleId | null;
459
+ workCalendarId: ScheduleId | null;
460
+ access: ScheduleAccessObj | null;
461
+ color: string | null;
462
+ // As stored; readers resolve missing keys from SCHEDULE_CALENDAR_DEFAULT_SETTINGS
463
+ settings: Partial<ScheduleCalendarSettingsObj>;
464
+ preparedThrough: Date | string | null; // the last date the cycle drafted a period through
465
+ ordinal: number;
317
466
  createdByAccountId: ScheduleId | null;
318
467
  deletedAt: Date | string | null;
319
468
  createdAt: Date | string;
320
469
  updatedAt: Date | string;
321
470
  }
322
471
 
323
- export interface ScheduleOccurrenceData {
324
- source: ScheduleSourceObj | null;
472
+ /**
473
+ * Templates and the standing schedule
474
+ */
475
+
476
+ export interface ScheduleTemplateData {
325
477
  id: ScheduleId;
326
478
  organizationId: ScheduleId;
327
479
  calendarId: ScheduleId;
328
- seriesId: ScheduleId | null;
329
- recurrenceDate: Date | string | null;
330
- resourceId: ScheduleId | null;
331
- kind: ScheduleOccurrenceKindEnum;
332
- title: string;
333
- note: string | null;
334
- location: string | null;
335
- startAt: Date | string;
336
- endAt: Date | string;
337
- timeZone: string;
338
- allDay: boolean;
339
- status: ScheduleOccurrenceStatusEnum;
340
- detached: boolean;
480
+ name: string;
481
+ standing: boolean; // the calendar's standing schedule (at most one)
482
+ rotationWeeks: number; // 1..SCHEDULE_ROTATION_MAX_WEEKS
483
+ rotationAnchor: Date | string | null; // a date of rotation week 1 (week A), stored as its week's first day; the pay week containing it is week A even after payWeekStart changes; required when rotationWeeks > 1
341
484
  version: number | bigint;
342
485
  createdByAccountId: ScheduleId | null;
343
- publishedAt: Date | string | null;
344
- canceledAt: Date | string | null;
345
- deletedAt: Date | string | null;
346
486
  createdAt: Date | string;
347
487
  updatedAt: Date | string;
348
- // Attached by reads that load child rows
349
- slots?: ScheduleSlotData[];
350
- assignments?: ScheduleAssignmentData[];
351
488
  }
352
489
 
353
- export interface ScheduleSlotData {
490
+ // One row = one seat of one rotation week
491
+ export interface ScheduleTemplateItemData {
354
492
  id: ScheduleId;
355
493
  organizationId: ScheduleId;
356
- occurrenceId: ScheduleId;
357
- key: string;
494
+ templateId: ScheduleId;
495
+ week: number; // rotation week: 1 = week A ... (<= the template's rotationWeeks)
496
+ weekday: number; // 0 = Sunday ... 6 = Saturday: the local day the seat starts
497
+ startTime: string; // TIME: 'HH:mm:ss' as read from Postgres
498
+ endTime: string; // <= startTime ends the next day
499
+ roleId: ScheduleId | null;
500
+ locationResourceId: ScheduleId | null; // SPACE
501
+ assigneeResourceId: ScheduleId | null; // pre-assigned PERSON; null = an open seat
502
+ unpaidBreakMinutes: number;
358
503
  label: string | null;
359
- requiredCount: number;
360
- predicate: ScheduleSlotPredicateObj | null;
361
- ordinal: number;
504
+ createdAt: Date | string;
505
+ updatedAt: Date | string;
362
506
  }
363
507
 
364
- export interface ScheduleAssignmentData {
365
- releasedByAccountId: ScheduleId | null;
366
- releasedAt: Date | string | null;
367
- assignedVia: ScheduleAssignmentViaEnum;
368
- releaseReason: ScheduleAssignmentReleaseReasonEnum | null;
369
- requestId: ScheduleId | null;
508
+ /**
509
+ * Shifts (one row = one seat) and the post-publish journal
510
+ */
511
+
512
+ // Never select or write the generated "during" column
513
+ export interface ScheduleShiftData {
370
514
  id: ScheduleId;
371
515
  organizationId: ScheduleId;
372
- occurrenceId: ScheduleId;
373
- resourceId: ScheduleId;
374
- slotKey: string | null;
375
- status: ScheduleAssignmentStatusEnum;
516
+ calendarId: ScheduleId;
517
+ shiftDate: Date | string; // the business day: the calendar-local date of startAt
518
+ startAt: Date | string;
519
+ endAt: Date | string; // at most SCHEDULE_SHIFT_MAX_DURATION_MINUTES after startAt
520
+ roleId: ScheduleId | null; // null = any role
521
+ locationResourceId: ScheduleId | null; // SPACE; null = the calendar's location as a whole
522
+ assigneeResourceId: ScheduleId | null; // PERSON; null = open shift
523
+ unpaidBreakMinutes: number;
524
+ label: string | null;
376
525
  note: string | null;
377
- assignedByAccountId: ScheduleId | null;
526
+ status: ScheduleShiftStatusEnum;
527
+ createdVia: ScheduleShiftCreatedViaEnum;
528
+ templateItemId: ScheduleId | null;
529
+ copiedFromShiftId: ScheduleId | null;
530
+ version: number | bigint; // 1 = never edited
531
+ publishedAt: Date | string | null; // set exactly when status <> DRAFT
532
+ canceledAt: Date | string | null; // set exactly when status = CANCELED
533
+ createdByAccountId: ScheduleId | null;
378
534
  createdAt: Date | string;
379
535
  updatedAt: Date | string;
380
536
  }
381
537
 
382
- export interface ScheduleDemandData {
538
+ // A journal row's previousValues / nextValues: changed fields only. Instants
539
+ // are ISO strings, local dates 'YYYY-MM-DD', ids decimal strings.
540
+ export interface ScheduleShiftValuesObj {
541
+ startAt?: string;
542
+ endAt?: string;
543
+ shiftDate?: string;
544
+ roleId?: string | null;
545
+ locationResourceId?: string | null;
546
+ unpaidBreakMinutes?: number;
547
+ label?: string | null;
548
+ note?: string | null;
549
+ }
550
+
551
+ export interface ScheduleShiftChangeData {
383
552
  id: ScheduleId;
384
553
  organizationId: ScheduleId;
385
- calendarId: ScheduleId;
386
- resourceId: ScheduleId;
387
- key: string;
388
- quantity: number;
389
- startAt: Date | string;
390
- endAt: Date | string;
391
- note: string | null;
554
+ shiftId: ScheduleId;
555
+ kind: ScheduleShiftChangeKindEnum;
556
+ via: ScheduleShiftChangeViaEnum;
557
+ fromResourceId: ScheduleId | null; // assignee before (ASSIGNED, UNASSIGNED)
558
+ toResourceId: ScheduleId | null; // assignee after (ASSIGNED)
559
+ previousValues: ScheduleShiftValuesObj | null;
560
+ nextValues: ScheduleShiftValuesObj | null;
561
+ requestId: ScheduleId | null;
562
+ actorAccountId: ScheduleId | null;
392
563
  createdAt: Date | string;
393
- updatedAt: Date | string;
394
564
  }
395
565
 
396
566
  /**
397
- * Coverage rules and violations
567
+ * Rules (per-kind config) and violations
398
568
  */
399
569
 
570
+ // Who counts for a rule. Every listed requirement must hold; an empty or null
571
+ // predicate means anyone countable.
572
+ export interface SchedulePredicateObj {
573
+ roleIdsAny?: string[] | null; // holds at least one of these roles (schedule_resource_roles)
574
+ qualifications?: string[] | null; // holds every one of these qualification keys (expiry judged separately)
575
+ tags?: string[] | null; // has every one of these tags
576
+ }
577
+
578
+ // A calendar-local weekly window; an end at or before the start ends next day
579
+ export interface ScheduleWeeklyWindowObj {
580
+ weekday: number; // 0 = Sunday ... 6 = Saturday: the day the window starts
581
+ start: string; // 'HH:mm'
582
+ end: string; // 'HH:mm'
583
+ }
584
+
585
+ export interface ScheduleStaffingRequirementConfigObj {
586
+ roleIdsAny: string[]; // >= 1; a seat counts when its roleId is listed, or its roleId is null and its assignee holds a listed role
587
+ windows: ScheduleWeeklyWindowObj[]; // >= 1
588
+ minCount: number; // 1..SCHEDULE_RULE_MAX_MIN_COUNT
589
+ locationResourceId: string | null; // set = only seats in that SPACE count
590
+ }
591
+
592
+ export interface ScheduleRatioConfigObj {
593
+ ratios: Record<string, number>; // age-group key -> children per adult (integer 1..SCHEDULE_RULE_MAX_RATIO); >= 1 entry
594
+ mode: ScheduleRatioModeEnum;
595
+ maxGroupSize: Record<string, number> | null; // age-group key -> most children of that group in one room
596
+ predicate: SchedulePredicateObj | null; // who counts as an adult; null = any countable PERSON
597
+ }
598
+
599
+ export type ScheduleRoomCapacityConfigObj = Record<string, never>;
600
+
601
+ export interface ScheduleOperatingHoursConfigObj {
602
+ minAdults: number; // integer 1..SCHEDULE_RULE_MAX_MIN_ADULTS
603
+ predicate: SchedulePredicateObj | null; // roleIdsAny replaces the old config.roles
604
+ }
605
+
606
+ export interface ScheduleEligibilityConfigObj {
607
+ unavailable: ScheduleRuleSeverityEnum; // severity of an UNAVAILABLE overlap; default WARN. Hard checks are always BLOCK.
608
+ }
609
+
610
+ export interface ScheduleMaxHoursConfigObj {
611
+ period: ScheduleMaxHoursPeriodEnum;
612
+ days: number | null; // ROLLING_DAYS only: 1..SCHEDULE_RULE_MAX_DAYS; null otherwise
613
+ maxMinutes: number; // worked minutes (duration - unpaidBreakMinutes), 1..SCHEDULE_RULE_MAX_MINUTES
614
+ }
615
+
616
+ export interface ScheduleMinRestConfigObj {
617
+ minMinutes: number; // 1..SCHEDULE_RULE_MAX_REST_MINUTES between consecutive live seats
618
+ }
619
+
620
+ export interface ScheduleMaxConsecutiveDaysConfigObj {
621
+ days: number; // 1..SCHEDULE_RULE_MAX_DAYS consecutive shiftDates with any live seat (each seat's own calendar-local date)
622
+ }
623
+
624
+ export interface ScheduleShiftLengthConfigObj {
625
+ minMinutes: number | null; // at least one bound; minutes of duration (not worked minutes)
626
+ maxMinutes: number | null; // <= SCHEDULE_SHIFT_MAX_DURATION_MINUTES
627
+ }
628
+
629
+ export interface ScheduleNoticePeriodConfigObj {
630
+ days: number; // 1..SCHEDULE_RULE_MAX_DAYS
631
+ }
632
+
633
+ export interface ScheduleRuleConfigByKind {
634
+ STAFFING_REQUIREMENT: ScheduleStaffingRequirementConfigObj;
635
+ RATIO: ScheduleRatioConfigObj;
636
+ ROOM_CAPACITY: ScheduleRoomCapacityConfigObj;
637
+ OPERATING_HOURS: ScheduleOperatingHoursConfigObj;
638
+ ELIGIBILITY: ScheduleEligibilityConfigObj;
639
+ MAX_HOURS: ScheduleMaxHoursConfigObj;
640
+ MIN_REST: ScheduleMinRestConfigObj;
641
+ MAX_CONSECUTIVE_DAYS: ScheduleMaxConsecutiveDaysConfigObj;
642
+ SHIFT_LENGTH: ScheduleShiftLengthConfigObj;
643
+ NOTICE_PERIOD: ScheduleNoticePeriodConfigObj;
644
+ }
645
+
400
646
  export type ScheduleRuleConfigObj =
401
- | Record<string, never> // REQUIRED_COUNT, ROOM_CAPACITY, ELIGIBILITY: severity only
402
- | ScheduleDerivedCountConfigObj
403
- | ScheduleOperatingHoursConfigObj
404
- | ScheduleActorWindowConfigObj;
647
+ ScheduleRuleConfigByKind[ScheduleRuleKindEnum];
405
648
 
406
649
  export interface ScheduleRuleData {
407
650
  id: ScheduleId;
408
651
  organizationId: ScheduleId;
409
- calendarId: ScheduleId | null;
410
- resourceId: ScheduleId | null;
652
+ calendarId: ScheduleId | null; // null = organization scope
653
+ resourceId: ScheduleId | null; // a room (SPACE) or a person (PERSON)
411
654
  kind: ScheduleRuleKindEnum;
412
- key: string;
655
+ key: string; // one key per scope; a more specific rule with the same key replaces a less specific one
413
656
  label: string;
414
657
  config: ScheduleRuleConfigObj;
415
658
  severity: ScheduleRuleSeverityEnum;
@@ -423,16 +666,15 @@ export interface ScheduleViolationData {
423
666
  acknowledgedByAccountId: ScheduleId | null;
424
667
  acknowledgedAt: Date | string | null;
425
668
  createdAt: Date | string;
426
- violationKey: string;
427
- identityKey: string;
669
+ violationKey: string; // identityKey|ISO startAt
670
+ identityKey: string; // kind|ruleId|resourceId|shiftId|code
428
671
  code: ScheduleCoverageViolationCode | null;
429
- slotKey: string | null;
430
672
  degree: number;
431
673
  id: ScheduleId;
432
674
  organizationId: ScheduleId;
433
675
  calendarId: ScheduleId;
434
676
  ruleId: ScheduleId | null;
435
- occurrenceId: ScheduleId | null;
677
+ shiftId: ScheduleId | null;
436
678
  resourceId: ScheduleId | null;
437
679
  kind: ScheduleRuleKindEnum;
438
680
  severity: ScheduleRuleSeverityEnum;
@@ -444,32 +686,305 @@ export interface ScheduleViolationData {
444
686
  }
445
687
 
446
688
  /**
447
- * Projects (PROJECT mode)
689
+ * Demand: recurring enrollment per room x age group, plus dated overrides.
690
+ * Both are calendar-local; an override row for (room, key, date) replaces
691
+ * that date's pattern rows for that room and key entirely.
448
692
  */
449
693
 
450
- export interface ScheduleSchedulingOptionsObj {
451
- progressLogic?: ScheduleProgressLogicEnum | null; // default RETAINED
452
- lagCalendar?: ScheduleLagCalendarEnum | null; // default PREDECESSOR
453
- criticalFloatThresholdMinutes?: number | null; // default 0
454
- criticalityMode?: ScheduleCriticalityModeEnum | null; // default FLOAT
455
- autoSchedule?: boolean | null; // decision #1; read by the server, ignored by the engine
456
- leveling?: ScheduleLevelingOptionsObj | null;
694
+ export interface ScheduleDemandPatternData {
695
+ id: ScheduleId;
696
+ organizationId: ScheduleId;
697
+ calendarId: ScheduleId;
698
+ resourceId: ScheduleId; // SPACE: the room
699
+ key: string; // age group
700
+ weekday: number; // 0 = Sunday ... 6 = Saturday
701
+ startTime: string; // TIME: 'HH:mm:ss'
702
+ endTime: string; // <= startTime ends the next day
703
+ quantity: number;
704
+ effectiveFrom: Date | string;
705
+ effectiveTo: Date | string | null; // inclusive; null = open-ended
706
+ note: string | null;
707
+ createdAt: Date | string;
708
+ updatedAt: Date | string;
709
+ }
710
+
711
+ export interface ScheduleDemandData {
712
+ id: ScheduleId;
713
+ organizationId: ScheduleId;
714
+ calendarId: ScheduleId;
715
+ resourceId: ScheduleId; // SPACE: the room
716
+ key: string; // age group
717
+ date: Date | string; // the calendar-local date this override replaces
718
+ startTime: string; // TIME: 'HH:mm:ss'
719
+ endTime: string; // <= startTime ends the next day
720
+ quantity: number; // 0 = nobody that day
721
+ note: string | null;
722
+ createdAt: Date | string;
723
+ updatedAt: Date | string;
457
724
  }
458
725
 
459
726
  /**
460
- * Where a row came from. Written by imports and by the RFP extraction
461
- * pipeline, so a planner can see and review machine-proposed scope.
727
+ * Requests, notifications and publications
462
728
  */
463
- export interface ScheduleSourceObj {
464
- kind: ScheduleSourceKindEnum;
465
- documentId?: string | null;
466
- // Page or section reference and the quoted passage that produced the row
467
- reference?: string | null;
468
- quote?: string | null;
469
- confidence?: number | null;
470
- reviewStatus?: ScheduleSourceReviewStatusEnum | null;
729
+
730
+ export interface ScheduleRequestData {
731
+ autoApproved: boolean;
732
+ id: ScheduleId;
733
+ organizationId: ScheduleId;
734
+ calendarId: ScheduleId;
735
+ kind: ScheduleRequestKindEnum;
736
+ status: ScheduleRequestStatusEnum;
737
+ shiftId: ScheduleId; // CLAIM: the open seat; otherwise the requester's seat
738
+ targetShiftId: ScheduleId | null; // SWAP: the counterparty's seat
739
+ requesterResourceId: ScheduleId;
740
+ requesterAccountId: ScheduleId | null;
741
+ counterpartyResourceId: ScheduleId | null; // SWAP: holder of targetShiftId
742
+ counterpartyRespondedAt: Date | string | null;
743
+ proposedStartAt: Date | string | null; // RETIME only
744
+ proposedEndAt: Date | string | null; // RETIME only
745
+ subjectStartAt: Date | string;
746
+ eligibility: Record<string, unknown> | null;
747
+ via: ScheduleRequestViaEnum;
748
+ version: number | bigint;
749
+ reason: string | null;
750
+ decidedByAccountId: ScheduleId | null;
751
+ decidedAt: Date | string | null;
752
+ decisionNote: string | null;
753
+ expiresAt: Date | string; // never after subjectStartAt
754
+ closedAt: Date | string | null;
755
+ offerId: ScheduleId | null; // CLAIM only: the offer whose yes created it
756
+ createdAt: Date | string;
757
+ updatedAt: Date | string;
758
+ }
759
+
760
+ export interface ScheduleNotificationAudienceObj {
761
+ accountIds?: string[];
762
+ resourceIds?: string[];
763
+ calendarManagers?: { calendarId: string };
764
+ projectEditors?: { projectId: string };
765
+ assignedInWindow?: {
766
+ calendarId: string;
767
+ from: string;
768
+ to: string;
769
+ shiftIds?: string[];
770
+ };
771
+ requestParticipants?: { requestId: string; includeManagers: boolean };
772
+ timeOffParticipants?: { timeOffId: string; includeManagers: boolean };
773
+ publicationId?: string;
774
+ }
775
+
776
+ // subject/body are rendered at insert for ordinary notices; a coalesced
777
+ // SHIFTS_CHANGED row carries resourceId + shiftIds and is rendered at send
778
+ export interface ScheduleNotificationPayloadObj {
779
+ subject?: string;
780
+ body?: string;
781
+ excludeAccountId?: string | null;
782
+ resourceId?: string;
783
+ shiftIds?: string[];
784
+ toldByAsk?: boolean; // SHIFTS_CHANGED: every change came from the person's own yes to a question, whose reply told them (no SMS)
785
+ fromDate?: string; // VIOLATION_RAISED: the evaluated window, calendar-local
786
+ toDate?: string;
787
+ slip?: ScheduleProjectSlipPayloadObj; // MILESTONE_AT_RISK: what slipped (rendered at delivery, formatProjectSlip)
788
+ appOnly?: boolean; // MILESTONE_AT_RISK: the run reported no new status (a plan edit): the app only, never a text
789
+ digest?: ScheduleProjectDigestPayloadObj; // PROJECT_DIGEST: what it reports (rendered at delivery, formatProjectDigest)
790
+ assignedByAccountId?: string | null; // TASK_ASSIGNED: who assigned the to-do
791
+ }
792
+
793
+ export interface ScheduleNotificationData {
794
+ id: ScheduleId;
795
+ organizationId: ScheduleId;
796
+ eventKind: ScheduleNotificationEventKindEnum;
797
+ entityType: string;
798
+ entityId: ScheduleId;
799
+ calendarId: ScheduleId | null;
800
+ projectId: ScheduleId | null;
801
+ audience: ScheduleNotificationAudienceObj;
802
+ payload: ScheduleNotificationPayloadObj;
803
+ link: string | null;
804
+ idempotencyKey: string;
805
+ status: ScheduleNotificationStatusEnum;
806
+ attempts: number;
807
+ coalesceKey: string | null; // 'shifts:<calendarId>:<resourceId>' while the row still collects; PENDING only
808
+ availableAt: Date | string;
809
+ sentAt: Date | string | null;
810
+ lastError: string | null;
811
+ jobId: ScheduleId | null;
812
+ createdAt: Date | string;
813
+ updatedAt: Date | string;
814
+ }
815
+
816
+ // One row per notification x account x channel
817
+ export interface ScheduleNotificationDeliveryData {
818
+ id: ScheduleId;
819
+ organizationId: ScheduleId;
820
+ notificationId: ScheduleId;
821
+ accountId: ScheduleId;
822
+ channel: ScheduleNotifyChannelEnum;
823
+ status: ScheduleNotificationDeliveryStatusEnum;
824
+ skipReason: ScheduleNotificationSkipReasonEnum | null; // set exactly when SKIPPED
825
+ providerRef: ScheduleId | null; // sms_outbound / outbound email id
826
+ attempts: number;
827
+ lastError: string | null;
828
+ sentAt: Date | string | null;
829
+ createdAt: Date | string;
830
+ updatedAt: Date | string;
831
+ }
832
+
833
+ export interface SchedulePublicationData {
834
+ id: ScheduleId;
835
+ organizationId: ScheduleId;
836
+ calendarId: ScheduleId;
837
+ windowStart: Date | string;
838
+ windowEnd: Date | string;
839
+ shiftCount: number;
840
+ acknowledgedWarnings: CoverageViolationObj[];
841
+ acknowledgedWarningCount: number;
842
+ notificationId: ScheduleId | null;
843
+ publishedByAccountId: ScheduleId | null;
844
+ publishedAt: Date | string;
845
+ }
846
+
847
+ /**
848
+ * Asks and offers (Phase 2)
849
+ */
850
+
851
+ // What an ask showed and what its answer did; every key optional
852
+ export interface ScheduleAskPayloadObj {
853
+ text?: string; // the body sent (SMS or in-app), set when sent
854
+ line?: string; // one line for chat context and lists (formatAskLine), set when sent
855
+ subjectLabel?: string; // e.g. "Fri Dec 4, 8pm-2am at Main St" (closing notes), set when sent
856
+ periodRevision?: string; // PUBLISH_REVIEW: the period's seat revision (fetchSchedulePeriodRevision) read before the text was rendered
857
+ warningKeys?: string[]; // PUBLISH_REVIEW: identity keys of the unacknowledged warnings the text listed
858
+ nudgedAt?: string; // PUBLISH_REVIEW: ISO, the one reminder
859
+ shiftIds?: string[]; // SHIFTS_CONFIRM: the newly published seats of this person
860
+ claimRequestId?: string; // OFFER: the CLAIM a yes created
861
+ closedNote?: string; // OFFER: the "covered" text queued when the offer closed
862
+ closedNoteSentAt?: string;
863
+ closedCause?: 'FILLED' | 'CANCELED' | 'CHANGED' | 'STOPPED'; // OFFER: why the offer closed while this question was PENDING (a send in flight gets its note)
864
+ outcome?: string; // the answer outcome (ScheduleAskAnswerOutcome), stored for replays
865
+ reply?: string; // the reply text given, stored for replays
866
+ supersededByAskId?: string;
867
+ activityIds?: string[]; // PLAN_REVIEW: the reviewed set; PROGRESS_CHECK: item n = activityIds[n-1]
868
+ slotAt?: string; // PROGRESS_CHECK: ISO, the check-in slot
869
+ acceptedCount?: number; // PLAN_REVIEW YES: the activities it marked reviewed
870
+ }
871
+
872
+ export interface ScheduleAskData {
873
+ id: ScheduleId;
874
+ organizationId: ScheduleId;
875
+ calendarId: ScheduleId | null;
876
+ projectId: ScheduleId | null; // PLAN_REVIEW and PROGRESS_CHECK only
877
+ kind: ScheduleAskKindEnum;
878
+ recipientAccountId: ScheduleId;
879
+ recipientResourceId: ScheduleId | null; // the PERSON asked as a worker; null = asked as a manager
880
+ offerId: ScheduleId | null;
881
+ requestId: ScheduleId | null;
882
+ timeOffId: ScheduleId | null;
883
+ publicationId: ScheduleId | null;
884
+ periodStart: Date | string | null;
885
+ periodEnd: Date | string | null;
886
+ payload: ScheduleAskPayloadObj;
887
+ rank: number | null;
888
+ wave: number | null;
889
+ score: ScheduleCandidateScoreObj | null;
890
+ channel: ScheduleAskChannelEnum;
891
+ status: ScheduleAskStatusEnum;
892
+ answer: ScheduleAskAnswerEnum | null;
893
+ reason: ScheduleAskReasonEnum | null;
894
+ smsOutboundId: ScheduleId | null;
895
+ sendAt: Date | string;
896
+ sentAt: Date | string | null;
897
+ answeredAt: Date | string | null;
898
+ answeredVia: ScheduleAskAnswerViaEnum | null;
899
+ answeredByMessageKey: string | null;
900
+ replyText: string | null;
901
+ expiresAt: Date | string;
902
+ createdAt: Date | string;
903
+ updatedAt: Date | string;
904
+ }
905
+
906
+ export interface ScheduleOfferData {
907
+ id: ScheduleId;
908
+ organizationId: ScheduleId;
909
+ calendarId: ScheduleId;
910
+ shiftId: ScheduleId;
911
+ status: ScheduleOfferStatusEnum;
912
+ autoApprove: boolean;
913
+ waveSize: number;
914
+ responseWindowMinutes: number;
915
+ expiresAt: Date | string;
916
+ message: string | null;
917
+ createdVia: ScheduleOfferCreatedViaEnum;
918
+ requestId: ScheduleId | null;
919
+ filledByResourceId: ScheduleId | null;
920
+ filledAt: Date | string | null;
921
+ createdByAccountId: ScheduleId | null;
922
+ version: number | bigint;
923
+ closedAt: Date | string | null;
924
+ createdAt: Date | string;
925
+ updatedAt: Date | string;
926
+ }
927
+
928
+ /**
929
+ * To-dos (Phase 4)
930
+ */
931
+
932
+ // schedule_tasks: one to-do in exactly one calendar or one project
933
+ export interface ScheduleTaskData {
934
+ id: ScheduleId;
935
+ organizationId: ScheduleId;
936
+ calendarId: ScheduleId | null; // exactly one of calendarId / projectId
937
+ projectId: ScheduleId | null;
938
+ activityId: ScheduleId | null; // project to-dos only
939
+ shiftId: ScheduleId | null; // calendar to-dos only
940
+ title: string;
941
+ note: string | null;
942
+ assigneeResourceId: ScheduleId | null; // a PERSON; null = unassigned
943
+ dueAt: Date | string | null;
944
+ dueAllDay: boolean; // dueAt is the local midnight of the due date in timeZone
945
+ timeZone: string; // the scope's zone at creation (never changes)
946
+ status: ScheduleTaskStatusEnum;
947
+ priority: number; // the index in SCHEDULE_TASK_PRIORITY_ENUMS (0 NONE ... 3 HIGH)
948
+ completedAt: Date | string | null; // set exactly when DONE
949
+ completedByAccountId: ScheduleId | null;
950
+ createdVia: ScheduleTaskCreatedViaEnum;
951
+ ordinal: number;
952
+ version: number | bigint;
953
+ createdByAccountId: ScheduleId | null;
954
+ createdAt: Date | string;
955
+ updatedAt: Date | string;
956
+ }
957
+
958
+ /**
959
+ * Projects
960
+ */
961
+
962
+ export interface ScheduleSchedulingOptionsObj {
963
+ progressLogic?: ScheduleProgressLogicEnum | null; // default RETAINED
964
+ lagCalendar?: ScheduleLagCalendarEnum | null; // default PREDECESSOR
965
+ criticalFloatThresholdMinutes?: number | null; // default 0
966
+ criticalityMode?: ScheduleCriticalityModeEnum | null; // default FLOAT
967
+ autoSchedule?: boolean | null; // decision #1; read by the server, ignored by the engine
968
+ leveling?: ScheduleLevelingOptionsObj | null;
969
+ }
970
+
971
+ /**
972
+ * Where a row came from. Written by imports and by the RFP extraction
973
+ * pipeline, so a planner can see and review machine-proposed scope.
974
+ */
975
+ export interface ScheduleSourceObj {
976
+ kind: ScheduleSourceKindEnum;
977
+ documentId?: string | null;
978
+ // Page or section reference and the quoted passage that produced the row
979
+ reference?: string | null;
980
+ quote?: string | null;
981
+ confidence?: number | null;
982
+ reviewStatus?: ScheduleSourceReviewStatusEnum | null;
471
983
  reviewedByAccountId?: string | null;
472
984
  reviewedAt?: string | null;
985
+ // An UNREVIEWED row an import wrote over a live activity with the same code:
986
+ // rejecting the proposal deletes an activity that existed before it
987
+ replacedExisting?: boolean | null;
473
988
  }
474
989
 
475
990
  export interface ScheduleProjectData {
@@ -496,6 +1011,11 @@ export interface ScheduleProjectData {
496
1011
  lastScheduledAt: Date | string | null;
497
1012
  access: ScheduleAccessObj | null;
498
1013
  source: ScheduleSourceObj | null;
1014
+ // The stored chat settings JSON; read it through getScheduleProjectSettings
1015
+ // (ScheduleProjectSettingsObj, defaults applied)
1016
+ settings: Record<string, unknown>;
1017
+ progressCheckedAt: Date | string | null; // the last check-in slot handled
1018
+ digestSentAt: Date | string | null; // the last digest slot handled
499
1019
  version: number | bigint;
500
1020
  createdByAccountId: ScheduleId | null;
501
1021
  deletedAt: Date | string | null;
@@ -503,6 +1023,77 @@ export interface ScheduleProjectData {
503
1023
  updatedAt: Date | string;
504
1024
  }
505
1025
 
1026
+ // schedule_projects.settings.progressCheck, as read; absent = no check-ins
1027
+ export interface ScheduleProjectProgressCheckObj {
1028
+ cadence: ScheduleProjectCheckCadenceEnum;
1029
+ atHour: number; // 0-23, project-local
1030
+ weekday: number | null; // WEEKLY only, 0 = Sunday
1031
+ }
1032
+
1033
+ // schedule_projects.settings.digest, as read (absent keys are
1034
+ // SCHEDULE_PROJECT_DIGEST_DEFAULTS)
1035
+ export interface ScheduleProjectDigestSettingsObj {
1036
+ enabled: boolean;
1037
+ weekday: number; // 0 = Sunday
1038
+ atHour: number; // 0-23, project-local
1039
+ }
1040
+
1041
+ // schedule_projects.settings, as read (defaults applied)
1042
+ export interface ScheduleProjectSettingsObj {
1043
+ progressCheck: ScheduleProjectProgressCheckObj | null;
1044
+ digest: ScheduleProjectDigestSettingsObj;
1045
+ }
1046
+
1047
+ // MILESTONE_AT_RISK payload.slip: stored at insert, rendered at delivery
1048
+ // (formatProjectSlip). Instants are ISO strings.
1049
+ export interface ScheduleProjectSlipPayloadObj {
1050
+ previousFinishAt: string | null; // the project's scheduled finish before the run
1051
+ finishAt: string | null; // after the run
1052
+ mustFinishByAt: string | null;
1053
+ milestones: Array<{
1054
+ activityId: string;
1055
+ code: string;
1056
+ name: string;
1057
+ previousFinishAt: string | null;
1058
+ finishAt: string;
1059
+ totalFloatMinutes: number | null;
1060
+ atRisk: boolean; // its float went below zero in this run
1061
+ }>; // at most 10, biggest slip first
1062
+ milestoneCount: number; // every milestone that slipped or went negative
1063
+ }
1064
+
1065
+ // PROJECT_DIGEST payload.digest: stored at insert, rendered at delivery
1066
+ // (formatProjectDigest), so a retry renders the same words. Instants are ISO
1067
+ // strings.
1068
+ // What a plan text's critical path is: the critical activities, or, when none
1069
+ // is critical (a deadline gives every activity float), the longest path, the
1070
+ // chain of driving links that sets the finish
1071
+ export type ScheduleCriticalPathKindEnum = 'CRITICAL' | 'LONGEST';
1072
+
1073
+ export interface ScheduleProjectDigestPayloadObj {
1074
+ slotDate: string; // project-local date of the digest slot
1075
+ asOf: string; // ISO, when it was built
1076
+ calculated: boolean; // the latest complete run matches the network
1077
+ pending: boolean; // a run was queued or running when it was built
1078
+ criticalPathKind: ScheduleCriticalPathKindEnum; // what criticalActivityIds, newlyCritical and criticalHead hold
1079
+ finishAt: string | null;
1080
+ previousFinishAt: string | null; // the last digest's finishAt; null for the first digest
1081
+ baselineFinishAt: string | null;
1082
+ mustFinishByAt: string | null;
1083
+ criticalActivityIds: string[]; // every activity on the path now (at most 500), for the next digest
1084
+ newlyCritical: Array<{ code: string; name: string }>; // on the path since the previous digest; [] for the first digest
1085
+ newlyCriticalCount: number;
1086
+ criticalHead: Array<{ code: string; name: string }>; // the path's first 5 activities by start (shown when there is no previous digest)
1087
+ starting: Array<{
1088
+ code: string;
1089
+ name: string;
1090
+ startAt: string;
1091
+ responsibleNames: string[];
1092
+ }>; // NOT_STARTED, startAt within the lookahead, at most 10 by startAt
1093
+ startingCount: number;
1094
+ checkIns: { asked: number; answered: number } | null; // PROGRESS_CHECK asks of the last 7 days; null when check-ins are off
1095
+ }
1096
+
506
1097
  export interface ScheduleWbsNodeData {
507
1098
  id: ScheduleId;
508
1099
  organizationId: ScheduleId;
@@ -696,111 +1287,6 @@ export interface ScheduleRunProgressObj {
696
1287
  updatedAt?: string;
697
1288
  }
698
1289
 
699
- export interface ScheduleRequestData {
700
- autoApproved: boolean;
701
- id: ScheduleId;
702
- organizationId: ScheduleId;
703
- calendarId: ScheduleId;
704
- kind: ScheduleRequestKindEnum;
705
- status: ScheduleRequestStatusEnum;
706
- occurrenceId: ScheduleId;
707
- slotKey: string | null;
708
- sourceAssignmentId: ScheduleId | null;
709
- targetAssignmentId: ScheduleId | null;
710
- requesterResourceId: ScheduleId;
711
- requesterAccountId: ScheduleId | null;
712
- counterpartyResourceId: ScheduleId | null;
713
- counterpartyRespondedAt: Date | string | null;
714
- targetOccurrenceId: ScheduleId | null;
715
- subjectStartAt: Date | string;
716
- eligibility: Record<string, unknown>;
717
- version: number | bigint;
718
- reason: string | null;
719
- decidedByAccountId: ScheduleId | null;
720
- decidedAt: Date | string | null;
721
- decisionNote: string | null;
722
- expiresAt: Date | string;
723
- closedAt: Date | string | null;
724
- createdAt: Date | string;
725
- updatedAt: Date | string;
726
- }
727
-
728
- export interface ScheduleTimeOffData {
729
- allDay: boolean;
730
- timeZone: string;
731
- id: ScheduleId;
732
- organizationId: ScheduleId;
733
- resourceId: ScheduleId;
734
- requesterAccountId: ScheduleId | null;
735
- startAt: Date | string;
736
- endAt: Date | string;
737
- status: ScheduleTimeOffStatusEnum;
738
- reason: string | null;
739
- decidedByAccountId: ScheduleId | null;
740
- decidedAt: Date | string | null;
741
- decisionNote: string | null;
742
- version: number | bigint;
743
- createdAt: Date | string;
744
- updatedAt: Date | string;
745
- }
746
-
747
- export interface ScheduleNotificationAudienceObj {
748
- accountIds?: string[];
749
- resourceIds?: string[];
750
- calendarManagers?: { calendarId: string };
751
- projectEditors?: { projectId: string };
752
- assignedInWindow?: {
753
- calendarId: string;
754
- from: string;
755
- to: string;
756
- seriesId?: string;
757
- occurrenceIds?: string[];
758
- };
759
- requestParticipants?: { requestId: string; includeManagers: boolean };
760
- timeOffParticipants?: { timeOffId: string; includeManagers: boolean };
761
- publicationId?: string;
762
- }
763
-
764
- export interface ScheduleNotificationData {
765
- id: ScheduleId;
766
- organizationId: ScheduleId;
767
- eventKind: ScheduleNotificationEventKindEnum;
768
- entityType: string;
769
- entityId: ScheduleId;
770
- calendarId: ScheduleId | null;
771
- projectId: ScheduleId | null;
772
- audience: ScheduleNotificationAudienceObj;
773
- payload: { subject: string; body: string; excludeAccountId?: string | null };
774
- link: string | null;
775
- idempotencyKey: string;
776
- status: ScheduleNotificationStatusEnum;
777
- attempts: number;
778
- recipientCount: number;
779
- deliveredCount: number;
780
- failedCount: number;
781
- inAppSentAt: Date | string | null;
782
- availableAt: Date | string;
783
- sentAt: Date | string | null;
784
- lastError: string | null;
785
- jobId: ScheduleId | null;
786
- createdAt: Date | string;
787
- updatedAt: Date | string;
788
- }
789
-
790
- export interface SchedulePublicationData {
791
- id: ScheduleId;
792
- organizationId: ScheduleId;
793
- calendarId: ScheduleId;
794
- windowStart: Date | string;
795
- windowEnd: Date | string;
796
- occurrenceCount: number;
797
- acknowledgedWarnings: CoverageViolationObj[];
798
- acknowledgedWarningCount: number;
799
- notificationId: ScheduleId | null;
800
- publishedByAccountId: ScheduleId | null;
801
- publishedAt: Date | string;
802
- }
803
-
804
1290
  export interface ScheduleResourceUsageData {
805
1291
  id: ScheduleId;
806
1292
  organizationId: ScheduleId;
@@ -880,14 +1366,14 @@ export interface CpmActivityResult {
880
1366
  earlyStartAt: Date;
881
1367
  earlyFinishAt: Date;
882
1368
  lateStartAt: Date;
883
- lateFinishAt: Date; // analytics (decision #2)
1369
+ lateFinishAt: Date; // analytics (decision #2); never past the late-finish basis in working time unless a MANDATORY_* date pins it
884
1370
  startAt: Date;
885
1371
  finishAt: Date; // effective dates: early dates, or leveled dates when leveling ran
886
1372
  remainingDurationMinutes: number;
887
1373
  totalFloatMinutes: number | null; // CPM float (unleveled); null for COMPLETE
888
1374
  freeFloatMinutes: number | null;
889
1375
  isCritical: boolean; // by options.criticalityMode
890
- drivingPredecessorIds: string[]; // binding predecessors, in predecessor input order (§5.10); the persist step derives isDriving pairs from it
1376
+ drivingPredecessorIds: string[]; // binding predecessors, in predecessor input order; the persist step derives isDriving pairs from it
891
1377
  levelingDelayMinutes: number; // wm(activityCal, earlyStartAt, startAt); 0 when not leveled
892
1378
  levelingConstrainedByResourceId: string | null;
893
1379
  }
@@ -904,102 +1390,14 @@ export interface CpmScheduleResult {
904
1390
  stats: ScheduleProjectRunStatsObj;
905
1391
  }
906
1392
 
907
- /**
908
- * Recurrence expansion output
909
- */
1393
+ export type ScheduleCriticalityModeEnum =
1394
+ (typeof SCHEDULE_CRITICALITY_MODE_ENUMS)[number];
910
1395
 
911
- export interface ScheduleExpandedInstance {
912
- recurrenceDate: string;
913
- startAt: Date;
914
- endAt: Date;
915
- }
1396
+ export type ScheduleLevelingPriorityRuleEnum =
1397
+ (typeof SCHEDULE_LEVELING_PRIORITY_RULE_ENUMS)[number];
916
1398
 
917
- /**
918
- * Coverage evaluation contract (utils/coverage.ts)
919
- */
920
-
921
- export interface CoverageResourceInput {
922
- id: string;
923
- kind: ScheduleResourceKindEnum; // every kind accepted; NOT_LABOR is a real outcome, never an UNKNOWN_RESOURCE
924
- retiredAt: Date | string | null;
925
- capacity: number | null; // SPACE: licensed children; null = unbounded
926
- config: ScheduleResourceConfigObj;
927
- }
928
-
929
- export interface CoverageAssignmentInput {
930
- id: string | null; // null = simulated
931
- resourceId: string;
932
- slotKey: string | null; // null = unslotted
933
- }
934
-
935
- export interface CoverageOccurrenceInput {
936
- id: string;
937
- kind: ScheduleOccurrenceKindEnum; // SHIFT | EVENT | BLOCK
938
- resourceId: string | null; // SHIFT: the room (SPACE) or null = no room (a crew shift); BLOCK: the closed room, or null = the center is closed; EVENT: ignored
939
- startAt: Date | string;
940
- endAt: Date | string;
941
- slots: CoverageSlotInput[]; // SHIFT only
942
- assignments: CoverageAssignmentInput[]; // status ASSIGNED only
943
- }
944
-
945
- export interface CoverageDemandInput {
946
- id: string;
947
- resourceId: string; // the room — NOT NULL (decision #6)
948
- key: string; // age group / demand key, open string
949
- quantity: number; // ≥ 0, may be fractional (NUMERIC(12,2)); summed, then divided and ceil'd
950
- startAt: Date | string;
951
- endAt: Date | string;
952
- }
953
-
954
- export interface CoverageRuleInput {
955
- id: string;
956
- kind: ScheduleRuleKindEnum;
957
- calendarId: string | null; // scope ladder (§4)
958
- resourceId: string | null;
959
- config: ScheduleRuleConfigObj;
960
- severity: ScheduleRuleSeverityEnum;
961
- }
962
-
963
- export interface CoverageEvaluationInput {
964
- calendarId: string; // the evaluated calendar: every occurrence below belongs to it
965
- window: CoverageWindow;
966
- timeZone: string; // calendar zone; used only to build operating intervals
967
- operatingHours: ScheduleWorkCalendarDef | null; // schedule_calendars.workCalendarId resolved, or null
968
- occurrences: CoverageOccurrenceInput[]; // rows of calendarId overlapping the window (SHIFT/EVENT/BLOCK, not CANCELED, not deleted)
969
- external: CoverageExternalAssignmentInput[]; // other calendars / outside the window, for the window's people (§3.2)
970
- resources: CoverageResourceInput[];
971
- demand: CoverageDemandInput[];
972
- timeOff: CoverageTimeOffInput[];
973
- rules: CoverageRuleInput[]; // org + calendar + resource scoped, active only, unresolved
974
- options?: {
975
- anchorExternal?: boolean; // eligibility mode: ACTOR_WINDOW_AGGREGATE may flag external rows too (default false)
976
- };
977
- }
978
-
979
- export interface CoverageViolationObj {
980
- key: string; // identity + startAt (§7.1) — the persisted natural key
981
- identity: string; // identity WITHOUT startAt — merge/diff basis
982
- kind: ScheduleRuleKindEnum;
983
- code: ScheduleCoverageViolationCode | null; // ELIGIBILITY reason, HOURS|REST for ACTOR_WINDOW_AGGREGATE, else null
984
- ruleId: string | null;
985
- severity: ScheduleRuleSeverityEnum;
986
- resourceId: string | null; // the SUBJECT: room for ROOM kinds (null = center, or a room-less shift), person for PERSON kinds
987
- occurrenceId: string | null;
988
- slotKey: string | null;
989
- startAt: Date;
990
- endAt: Date; // clipped to the window
991
- degree: number; // how bad: shortfall, excess children, minutes over, minutes short, count
992
- detail: Record<string, unknown>; // kind-specific, JSON-stable (sorted keys), ids only — no names
993
- }
994
-
995
- export type ScheduleCriticalityModeEnum =
996
- (typeof SCHEDULE_CRITICALITY_MODE_ENUMS)[number];
997
-
998
- export type ScheduleLevelingPriorityRuleEnum =
999
- (typeof SCHEDULE_LEVELING_PRIORITY_RULE_ENUMS)[number];
1000
-
1001
- export type ScheduleDiagnosticSeverityEnum =
1002
- (typeof SCHEDULE_DIAGNOSTIC_SEVERITY_ENUMS)[number];
1399
+ export type ScheduleDiagnosticSeverityEnum =
1400
+ (typeof SCHEDULE_DIAGNOSTIC_SEVERITY_ENUMS)[number];
1003
1401
 
1004
1402
  export interface ScheduleLevelingOptionsObj {
1005
1403
  enabled?: boolean | null; // default false
@@ -1013,7 +1411,7 @@ export interface ScheduleLevelingOptionsObj {
1013
1411
  export interface CpmAssignmentInput {
1014
1412
  activityId: string;
1015
1413
  resourceId: string;
1016
- remainingUnits: number; // LABOR/EQUIPMENT: working minutes still to spend; 0 with unitsPerDay null ⇒ FULL TIME (§7.4)
1414
+ remainingUnits: number; // LABOR/EQUIPMENT: working minutes still to spend; 0 with unitsPerDay null ⇒ FULL TIME
1017
1415
  unitsPerDay?: number | null; // daily rate on the activity calendar; set ⇒ that rate on every activity working day
1018
1416
  }
1019
1417
 
@@ -1035,7 +1433,7 @@ export interface CpmExternalUsageInput {
1035
1433
  resourceId: string;
1036
1434
  startAt: Date | string; // the other project's startAt
1037
1435
  finishAt: Date | string; // the other project's finishAt
1038
- unitsPerDay: number; // server-computed daily rate (§8.3); spread over the resource calendar's working days inside [max(startAt, floor), finishAt)
1436
+ unitsPerDay: number; // server-computed daily rate; spread over the resource calendar's working days inside [max(startAt, floor), finishAt)
1039
1437
  }
1040
1438
 
1041
1439
  export interface CpmResourceUsageDay {
@@ -1061,62 +1459,86 @@ export interface CpmOverallocation {
1061
1459
  activityIds: string[];
1062
1460
  }
1063
1461
 
1064
- export type ScheduleEligibilityReasonEnum =
1065
- (typeof SCHEDULE_ELIGIBILITY_REASON_ENUMS)[number];
1066
-
1067
- export type ScheduleCoverageDiagnosticCodeEnum =
1068
- (typeof SCHEDULE_COVERAGE_DIAGNOSTIC_CODE_ENUMS)[number];
1069
-
1070
- export type ScheduleTimeOffStatusEnum =
1071
- (typeof SCHEDULE_TIME_OFF_STATUS_ENUMS)[number];
1072
-
1073
- export type ScheduleNotifyChannelEnum =
1074
- (typeof SCHEDULE_NOTIFY_CHANNEL_ENUMS)[number];
1075
-
1076
- export type ScheduleCoverageViolationCode =
1077
- | (typeof SCHEDULE_ELIGIBILITY_VIOLATION_CODE_ENUMS)[number]
1078
- | (typeof SCHEDULE_ACTOR_WINDOW_VIOLATION_CODE_ENUMS)[number];
1462
+ /**
1463
+ * Staff-schedule engine contracts (utils/coverage.ts, eligibility.ts,
1464
+ * laborRules.ts, rule.ts, template.ts, demand.ts, availability.ts,
1465
+ * shiftChange.ts, request.ts, scheduleText.ts). Ids are strings (decimal DB
1466
+ * ids on the server) so the same engine runs in a browser preview and on the
1467
+ * server. Local dates are 'YYYY-MM-DD'; local times are 'HH:mm' (or 'HH:mm:ss'
1468
+ * straight from a TIME column); a local interval whose end is at or before its
1469
+ * start ends on the next day. Instants are Date or ISO strings.
1470
+ */
1079
1471
 
1080
- export interface ScheduleNotifyPrefsObj {
1081
- channels: ScheduleNotifyChannelEnum[]; // deduped; [] = opted out. The notifications design may widen this object; the validator is the only writer.
1472
+ // Half-open [from, to)
1473
+ export interface CoverageWindow {
1474
+ from: Date | string;
1475
+ to: Date | string;
1082
1476
  }
1083
1477
 
1084
- export interface ScheduleDerivedCountConfigObj {
1085
- ratios: Record<string, number>; // demand key → children per adult (integer 1..50); ≥ 1 entry
1086
- predicate: ScheduleSlotPredicateObj | null; // who counts as an adult for this rule; null = any countable LABOR
1478
+ export interface CoverageResourceInput {
1479
+ id: string;
1480
+ kind: ScheduleResourceKindEnum; // every kind accepted; NOT_PERSON is a real outcome, never an UNKNOWN_RESOURCE
1481
+ retiredAt: Date | string | null;
1482
+ isMember: boolean; // PERSON: a current member of the organization; ignored for other kinds
1483
+ capacity: number | null; // SPACE: licensed children; null = unbounded
1484
+ roleIds: string[]; // PERSON: the roles it can work (schedule_resource_roles); [] otherwise
1485
+ config: ScheduleResourceConfigObj;
1087
1486
  }
1088
1487
 
1089
- export interface ScheduleOperatingHoursConfigObj {
1090
- minAdults: number; // integer 1..99
1091
- predicate: ScheduleSlotPredicateObj | null;
1488
+ // The role catalog, archived roles included (existing seats keep them)
1489
+ export interface CoverageRoleInput {
1490
+ id: string;
1491
+ key: string;
1492
+ requiredQualifications: string[];
1493
+ archivedAt: Date | string | null;
1092
1494
  }
1093
1495
 
1094
- export interface ScheduleActorWindowConfigObj {
1095
- windowDays: number | null; // 1..31, required together with maxMinutes
1096
- maxMinutes: number | null; // 1..44640
1097
- minRestMinutes: number | null; // 1..1440; at least one of the two groups present
1496
+ export interface CoverageShiftInput {
1497
+ id: string;
1498
+ calendarId: string;
1499
+ shiftDate: string; // the calendar-local date of startAt
1500
+ status: ScheduleShiftStatusEnum; // CANCELED seats are ignored
1501
+ publishedAt: Date | string | null;
1502
+ locationResourceId: string | null; // SPACE, or null = the calendar's location as a whole
1503
+ roleId: string | null;
1504
+ assigneeResourceId: string | null; // PERSON, or null = open
1505
+ startAt: Date | string;
1506
+ endAt: Date | string;
1507
+ unpaidBreakMinutes: number; // worked minutes = duration - break; presence is the whole seat
1098
1508
  }
1099
1509
 
1100
- export interface CoverageWindow {
1101
- from: Date | string;
1102
- to: Date | string;
1510
+ export interface CoverageAvailabilityInput {
1511
+ id: string;
1512
+ resourceId: string;
1513
+ kind: ScheduleAvailabilityKindEnum;
1514
+ weekday: number;
1515
+ startTime: string;
1516
+ endTime: string;
1517
+ timeZone: string; // the zone the window was stated in (not necessarily the calendar's)
1518
+ effectiveFrom: string;
1519
+ effectiveTo: string | null; // inclusive
1103
1520
  }
1104
1521
 
1105
- export interface CoverageSlotInput {
1106
- key: string;
1107
- label: string | null;
1108
- requiredCount: number;
1109
- predicate: ScheduleSlotPredicateObj | null;
1110
- ordinal: number;
1522
+ export interface CoverageDemandPatternInput {
1523
+ id: string;
1524
+ resourceId: string; // the room
1525
+ key: string; // age group
1526
+ weekday: number;
1527
+ startTime: string;
1528
+ endTime: string;
1529
+ quantity: number; // >= 0, up to two decimals
1530
+ effectiveFrom: string;
1531
+ effectiveTo: string | null; // inclusive
1111
1532
  }
1112
1533
 
1113
- export interface CoverageExternalAssignmentInput {
1114
- occurrenceId: string;
1115
- calendarId: string;
1116
- kind: 'SHIFT' | 'EVENT';
1117
- resourceId: string; // the person
1118
- startAt: Date | string;
1119
- endAt: Date | string;
1534
+ export interface CoverageDemandOverrideInput {
1535
+ id: string;
1536
+ resourceId: string; // the room
1537
+ key: string; // age group
1538
+ date: string; // replaces this date's pattern rows for (room, key)
1539
+ startTime: string;
1540
+ endTime: string;
1541
+ quantity: number; // 0 = nobody that day
1120
1542
  }
1121
1543
 
1122
1544
  export interface CoverageTimeOffInput {
@@ -1124,26 +1546,975 @@ export interface CoverageTimeOffInput {
1124
1546
  resourceId: string;
1125
1547
  startAt: Date | string;
1126
1548
  endAt: Date | string; // APPROVED rows only
1549
+ allDay?: boolean; // whole local days (startAt and endAt at local midnight): its reasons read as the day off
1550
+ }
1551
+
1552
+ // A journal row, for NOTICE_PERIOD LATE_CHANGE
1553
+ export interface CoverageShiftChangeInput {
1554
+ id: string;
1555
+ shiftId: string;
1556
+ kind: ScheduleShiftChangeKindEnum;
1557
+ fromResourceId: string | null;
1558
+ toResourceId: string | null;
1559
+ createdAt: Date | string;
1560
+ }
1561
+
1562
+ export interface CoverageRuleInput {
1563
+ id: string;
1564
+ kind: ScheduleRuleKindEnum;
1565
+ key: string;
1566
+ calendarId: string | null; // scope ladder: org (null) < calendar < resource
1567
+ resourceId: string | null;
1568
+ config: unknown; // as stored; revalidated by validateScheduleRuleConfig at evaluation time
1569
+ severity: ScheduleRuleSeverityEnum;
1570
+ }
1571
+
1572
+ export interface CoverageEvaluationInput {
1573
+ calendarId: string; // the evaluated calendar: every row of `shifts` belongs to it
1574
+ window: CoverageWindow; // at most SCHEDULE_COVERAGE_MAX_WINDOW_DAYS
1575
+ now: Date | string; // the evaluation instant (NOTICE_PERIOD LATE_PUBLISH); the engine never reads the clock
1576
+ timeZone: string; // calendar zone: demand dates, staffing windows, DAY / PAY_WEEK / consecutive days
1577
+ payWeekStart: number; // the org's organizations.settings.schedule.payWeekStart
1578
+ ageGroups: ScheduleAgeGroupObj[]; // the org's catalog, youngest first (RATIO YOUNGEST)
1579
+ operatingHours: ScheduleWorkCalendarDef | null; // schedule_calendars.workCalendarId resolved, or null
1580
+ shifts: CoverageShiftInput[]; // live (DRAFT + PUBLISHED) seats of calendarId overlapping the window
1581
+ external: CoverageShiftInput[]; // other assigned live seats of the people in `shifts`, any calendar (this one outside the window included), inside the widened person-rule window
1582
+ resources: CoverageResourceInput[]; // every resource referenced by shifts, external, demand, time off, availability and rules
1583
+ roles: CoverageRoleInput[];
1584
+ availability: CoverageAvailabilityInput[]; // windows of the people in shifts + external
1585
+ demandPatterns: CoverageDemandPatternInput[]; // rows of calendarId
1586
+ demandOverrides: CoverageDemandOverrideInput[]; // rows of calendarId whose date touches the window (one day either side)
1587
+ timeOff: CoverageTimeOffInput[]; // APPROVED rows of the people in shifts + external
1588
+ shiftChanges: CoverageShiftChangeInput[]; // journal rows of the PUBLISHED seats in `shifts`
1589
+ rules: CoverageRuleInput[]; // org + calendar + resource scoped, active only, unresolved
1590
+ options?: {
1591
+ anchorExternal?: boolean; // simulation mode: person rules may flag external seats too (default false)
1592
+ };
1593
+ }
1594
+
1595
+ export interface CoverageViolationObj {
1596
+ key: string; // identity + '|' + ISO startAt: the persisted natural key (unique per evaluation)
1597
+ identity: string; // kind|ruleId|resourceId|shiftId|code: merge, diff and acknowledgement basis
1598
+ kind: ScheduleRuleKindEnum;
1599
+ code: ScheduleCoverageViolationCode | null;
1600
+ ruleId: string | null; // null = an implicit rule
1601
+ severity: ScheduleRuleSeverityEnum;
1602
+ resourceId: string | null; // the SUBJECT: room for coverage kinds (null = the whole location), person for person kinds and NOTICE_PERIOD (null = an open seat)
1603
+ shiftId: string | null; // the seat: ELIGIBILITY, SHIFT_LENGTH, NOTICE_PERIOD, and the breaking (later) seat for MAX_HOURS / MIN_REST / MAX_CONSECUTIVE_DAYS; null for coverage kinds
1604
+ startAt: Date;
1605
+ endAt: Date; // clipped to the window
1606
+ degree: number; // how bad: shortfall, excess children, minutes over or short, days over, count
1607
+ detail: Record<string, unknown>; // kind-specific, JSON-stable (sorted keys), ids only, no names
1127
1608
  }
1128
1609
 
1129
1610
  export interface CoverageDiagnosticObj {
1130
1611
  code: ScheduleCoverageDiagnosticCodeEnum;
1131
1612
  ruleId: string | null;
1132
1613
  resourceId: string | null;
1133
- occurrenceId: string | null;
1134
- demandId: string | null;
1135
- detail: Record<string, unknown>; // e.g. { key } for QUALIFICATION_EXPIRY_INVALID / RATIO_NOT_CONFIGURED
1614
+ shiftId: string | null;
1615
+ detail: Record<string, unknown>; // e.g. { key } for RATIO_NOT_CONFIGURED, { roleId } for UNKNOWN_ROLE
1136
1616
  }
1137
1617
 
1138
1618
  export interface CoverageEvaluationResult {
1139
- violations: CoverageViolationObj[]; // merged, clipped, sorted
1140
- diagnostics: CoverageDiagnosticObj[];
1619
+ violations: CoverageViolationObj[]; // merged, clipped, sorted; keys unique
1620
+ diagnostics: CoverageDiagnosticObj[]; // deduped, sorted
1141
1621
  stats: {
1142
1622
  boundaryCount: number;
1143
1623
  segmentCount: number;
1144
- occurrenceCount: number;
1624
+ shiftCount: number;
1145
1625
  externalCount: number;
1146
1626
  operatingIntervalCount: number;
1627
+ demandIntervalCount: number;
1147
1628
  rawViolationCount: number;
1148
1629
  };
1149
1630
  }
1631
+
1632
+ // Before/after comparison (utils/violation.ts diffCoverageViolations): seat-bound
1633
+ // findings by identity (worsened = a higher maximum degree), coverage stretches
1634
+ // (shiftId null) per instant (introduced = an instant newly in violation,
1635
+ // worsened = a higher degree at some instant, resolved = an instant no longer)
1636
+ export interface CoverageViolationDiff {
1637
+ introduced: CoverageViolationObj[];
1638
+ worsened: CoverageViolationObj[];
1639
+ resolved: CoverageViolationObj[];
1640
+ }
1641
+
1642
+ // A hypothetical seat change, applied as retime, then unassign, then assign
1643
+ export interface ScheduleShiftSimulationObj {
1644
+ retime?: Array<{
1645
+ shiftId: string;
1646
+ startAt: Date | string;
1647
+ endAt: Date | string;
1648
+ }>;
1649
+ unassign?: string[]; // shift ids
1650
+ assign?: Array<{ shiftId: string; resourceId: string }>;
1651
+ }
1652
+
1653
+ // The fields of a violation its identity is built from
1654
+ export type CoverageViolationIdentityInput = Pick<
1655
+ CoverageViolationObj,
1656
+ 'kind' | 'ruleId' | 'resourceId' | 'shiftId' | 'code'
1657
+ >;
1658
+
1659
+ /**
1660
+ * Rule resolution (utils/rule.ts)
1661
+ */
1662
+
1663
+ // One applicable rule for one subject. rule = null is the implicit default of
1664
+ // an SCHEDULE_IMPLICIT_RULE_KINDS kind (ruleId null, key null, BLOCK).
1665
+ export interface ScheduleEffectiveRule {
1666
+ rule: CoverageRuleInput | null;
1667
+ ruleId: string | null;
1668
+ kind: ScheduleRuleKindEnum;
1669
+ key: string | null;
1670
+ severity: ScheduleRuleSeverityEnum;
1671
+ config: ScheduleRuleConfigObj; // validated and normalized
1672
+ }
1673
+
1674
+ // Per kind, per key (singleton kinds use the key ''): the calendar-or-org
1675
+ // winner and the per-subject (resource-scoped) replacements
1676
+ export interface ScheduleEffectiveRuleIndex {
1677
+ byKind: Map<
1678
+ ScheduleRuleKindEnum,
1679
+ Map<
1680
+ string,
1681
+ {
1682
+ fallback: ScheduleEffectiveRule | null;
1683
+ bySubject: Map<string, ScheduleEffectiveRule>;
1684
+ }
1685
+ >
1686
+ >;
1687
+ }
1688
+
1689
+ // How far around an evaluated range a person's other seats must be loaded
1690
+ // (whole days, before the range's first instant and after its last), not
1691
+ // counting the SCHEDULE_SHIFT_MAX_DURATION_DAYS shiftDate lookback of reads
1692
+ export interface SchedulePersonRuleWindow {
1693
+ lookbackDays: number;
1694
+ lookaheadDays: number;
1695
+ }
1696
+
1697
+ /**
1698
+ * Person rules over timelines (utils/laborRules.ts)
1699
+ */
1700
+
1701
+ export interface SchedulePersonRulesInput {
1702
+ resourceId: string;
1703
+ timeline: CoverageShiftInput[]; // every live seat of this person known to the caller, any calendar
1704
+ anchorShiftIds: ReadonlySet<string> | null; // seats that may carry a finding (the breaking seat); null = every seat
1705
+ rules: ScheduleEffectiveRule[]; // MAX_HOURS / MIN_REST / MAX_CONSECUTIVE_DAYS / SHIFT_LENGTH effective for this person
1706
+ timeZone: string; // the evaluated calendar's zone (MAX_HOURS DAY and PAY_WEEK; MAX_CONSECUTIVE_DAYS reads each seat's shiftDate)
1707
+ payWeekStart: number;
1708
+ }
1709
+
1710
+ export interface ScheduleNoticeRulesInput {
1711
+ now: Date | string;
1712
+ window: CoverageWindow;
1713
+ shifts: CoverageShiftInput[]; // the evaluated calendar's live seats
1714
+ shiftChanges: CoverageShiftChangeInput[];
1715
+ index: ScheduleEffectiveRuleIndex; // NOTICE_PERIOD looked up per seat assignee
1716
+ }
1717
+
1718
+ /**
1719
+ * Eligibility: one person x one seat (utils/eligibility.ts)
1720
+ */
1721
+
1722
+ export interface ScheduleEligibilityReasonObj {
1723
+ code: ScheduleEligibilityReasonEnum;
1724
+ severity: ScheduleRuleSeverityEnum;
1725
+ ruleId: string | null;
1726
+ detail: Record<string, unknown>; // ids only (roleId, qualification keys, otherShiftId, timeOffId, availabilityId, minutes); TIME_OFF: allDay for a whole-day time off
1727
+ startAt: Date | null;
1728
+ endAt: Date | null;
1729
+ }
1730
+
1731
+ export interface ScheduleEligibilityResult {
1732
+ eligible: boolean; // no BLOCK reason
1733
+ reasons: ScheduleEligibilityReasonObj[]; // deduped; BLOCK first, then SCHEDULE_ELIGIBILITY_REASON_ENUMS order, then startAt
1734
+ }
1735
+
1736
+ export interface ScheduleSwapEligibilityResult {
1737
+ eligible: boolean; // both sides eligible
1738
+ requester: ScheduleEligibilityResult; // the requester taking the counterparty's seat
1739
+ counterparty: ScheduleEligibilityResult; // the counterparty taking the requester's seat
1740
+ }
1741
+
1742
+ export interface ScheduleEligibilityContext {
1743
+ calendarId: string; // the seat's calendar: rule scope
1744
+ now: Date | string;
1745
+ timeZone: string; // the seat's calendar zone
1746
+ payWeekStart: number;
1747
+ roles: CoverageRoleInput[]; // at least the seat's role
1748
+ timeline: CoverageShiftInput[]; // the candidate's live seats in every calendar inside getSchedulePersonRuleWindow around the seat (the seat itself is ignored if present)
1749
+ timeOff: CoverageTimeOffInput[]; // the candidate's APPROVED time off
1750
+ availability: CoverageAvailabilityInput[]; // the candidate's windows
1751
+ rules: CoverageRuleInput[]; // org + calendar + the candidate's resource rules, active, unresolved
1752
+ }
1753
+
1754
+ // The structural checks of one held seat, shared by eligibility and the
1755
+ // coverage ELIGIBILITY evaluator (no person rules, no seat-state checks)
1756
+ export interface ScheduleShiftFindingsInput {
1757
+ shift: CoverageShiftInput;
1758
+ resource: CoverageResourceInput;
1759
+ rolesById: ReadonlyMap<string, CoverageRoleInput>;
1760
+ otherShifts: CoverageShiftInput[]; // the person's other live seats (overlap)
1761
+ timeOff: CoverageTimeOffInput[]; // the person's APPROVED time off
1762
+ availability: CoverageAvailabilityInput[]; // the person's windows
1763
+ rule: ScheduleEffectiveRule; // the effective ELIGIBILITY rule (implicit default when none)
1764
+ }
1765
+
1766
+ /**
1767
+ * Candidate ranking: who to offer an open seat to, best first
1768
+ * (utils/candidates.ts)
1769
+ */
1770
+
1771
+ export type ScheduleCandidateScoreReasonEnum =
1772
+ | 'PREFERRED_TIME'
1773
+ | 'UNDER_TARGET_HOURS'
1774
+ | 'OVER_TARGET_HOURS'
1775
+ | 'RULE_WARNING'
1776
+ | 'RECENT_DECLINES'
1777
+ | 'FAIRNESS'
1778
+ | 'RECENT_SLOT';
1779
+
1780
+ export interface ScheduleCandidateScoreReasonObj {
1781
+ code: ScheduleCandidateScoreReasonEnum;
1782
+ points: number; // an integer, never 0
1783
+ detail: Record<string, unknown>; // ids and numbers only: {fraction}, {weekMinutes, targetMinutes, overMinutes}, {code}, {count}, {days}
1784
+ }
1785
+
1786
+ export interface ScheduleCandidateScoreObj {
1787
+ total: number; // sum of points
1788
+ reasons: ScheduleCandidateScoreReasonObj[]; // by |points| descending, then code
1789
+ }
1790
+
1791
+ export interface ScheduleCandidateHistoryObj {
1792
+ declinedOfferCount: number; // OFFER asks this person answered NO within SCHEDULE_OFFER_DECLINE_LOOKBACK_DAYS
1793
+ lastShiftEndAt: Date | string | null; // their latest live seat at this calendar ending before the seat starts, within SCHEDULE_CANDIDATE_HISTORY_DAYS; null = none
1794
+ sameSlotCount: number; // their live seats at this calendar in that lookback with the seat's weekday and role, local start within SCHEDULE_CANDIDATE_SLOT_TOLERANCE_MINUTES
1795
+ }
1796
+
1797
+ export interface ScheduleCandidateInput {
1798
+ resource: CoverageResourceInput;
1799
+ context: ScheduleEligibilityContext; // timeline covers getScheduleCandidateWindow
1800
+ history: ScheduleCandidateHistoryObj;
1801
+ }
1802
+
1803
+ export interface ScheduleCandidateRankObj {
1804
+ resourceId: string;
1805
+ rank: number | null; // 1 = best eligible; null = ineligible
1806
+ eligibility: ScheduleEligibilityResult;
1807
+ score: ScheduleCandidateScoreObj; // computed for everyone (shown to the manager)
1808
+ }
1809
+
1810
+ /**
1811
+ * Templates, copy week and the standing schedule (utils/template.ts)
1812
+ */
1813
+
1814
+ export interface ScheduleTemplateRotationObj {
1815
+ rotationWeeks: number; // 1..SCHEDULE_ROTATION_MAX_WEEKS
1816
+ rotationAnchor: string | null; // a date of rotation week 1 (week A): the pay week containing it is week A, whatever payWeekStart is; required when rotationWeeks > 1
1817
+ }
1818
+
1819
+ export interface ScheduleTemplateItemInput {
1820
+ id: string;
1821
+ week: number;
1822
+ weekday: number;
1823
+ startTime: string;
1824
+ endTime: string;
1825
+ roleId: string | null;
1826
+ locationResourceId: string | null;
1827
+ assigneeResourceId: string | null;
1828
+ unpaidBreakMinutes: number;
1829
+ label: string | null;
1830
+ }
1831
+
1832
+ export type ScheduleTemplateItemSpec = Omit<ScheduleTemplateItemInput, 'id'>;
1833
+
1834
+ // A seat's current state, as the journal, copy week and net change read it
1835
+ export interface ScheduleShiftStateObj {
1836
+ id: string;
1837
+ calendarId: string;
1838
+ shiftDate: string;
1839
+ startAt: Date | string;
1840
+ endAt: Date | string;
1841
+ roleId: string | null;
1842
+ locationResourceId: string | null;
1843
+ assigneeResourceId: string | null;
1844
+ unpaidBreakMinutes: number;
1845
+ label: string | null;
1846
+ note: string | null;
1847
+ status: ScheduleShiftStatusEnum;
1848
+ templateItemId: string | null;
1849
+ }
1850
+
1851
+ // A seat to insert (template apply, copy week, create)
1852
+ export interface ScheduleShiftSpec {
1853
+ templateItemId: string | null;
1854
+ copiedFromShiftId: string | null;
1855
+ shiftDate: string;
1856
+ startAt: Date;
1857
+ endAt: Date;
1858
+ roleId: string | null;
1859
+ locationResourceId: string | null;
1860
+ assigneeResourceId: string | null;
1861
+ unpaidBreakMinutes: number;
1862
+ label: string | null;
1863
+ note: string | null;
1864
+ }
1865
+
1866
+ /**
1867
+ * The preparation cycle (utils/cycle.ts): periods, their weeks and the diff
1868
+ * baseline. Dates are calendar-local 'YYYY-MM-DD', inclusive.
1869
+ */
1870
+
1871
+ export interface SchedulePeriodObj {
1872
+ fromDate: string;
1873
+ toDate: string;
1874
+ }
1875
+
1876
+ export interface SchedulePeriodWeekObj {
1877
+ weekStart: string;
1878
+ rotationWeek: number | null; // null = no rotation of 2+ weeks
1879
+ }
1880
+
1881
+ export interface SchedulePeriodBaselineWeekObj {
1882
+ weekStart: string;
1883
+ dates: string[]; // the period's dates in this pay week
1884
+ baselineWeekStart: string | null; // null = nothing to compare
1885
+ baselineDates: string[]; // `dates` moved to the baseline week (same weekdays); [] when null
1886
+ }
1887
+
1888
+ /**
1889
+ * Auto-fill (utils/autofill.ts): fill a period's open draft seats, scarcest
1890
+ * seat first
1891
+ */
1892
+
1893
+ export interface ScheduleRosterInput {
1894
+ calendarId: string;
1895
+ timeZone: string;
1896
+ payWeekStart: number;
1897
+ now: Date | string;
1898
+ roles: CoverageRoleInput[];
1899
+ rules: CoverageRuleInput[]; // active org, calendar and resource-scoped rules the calendar applies (filtered per person like buildScheduleEligibilityContext)
1900
+ seats: CoverageShiftInput[]; // seats to fill; only DRAFT, open, of calendarId and starting after now are considered
1901
+ people: CoverageResourceInput[]; // the candidate pool
1902
+ timeline: CoverageShiftInput[]; // the pool's live seats in every calendar over the roster window (this period's assigned drafts included; ids in `seats` are ignored here)
1903
+ timeOff: CoverageTimeOffInput[]; // the pool's APPROVED time off
1904
+ availability: CoverageAvailabilityInput[];
1905
+ histories: Record<string, Record<string, ScheduleCandidateHistoryObj>>; // seat id -> resource id -> history; missing = { declinedOfferCount: 0, lastShiftEndAt: null, sameSlotCount: 0 }
1906
+ }
1907
+
1908
+ export interface ScheduleRosterProposalObj {
1909
+ shiftId: string;
1910
+ resourceId: string;
1911
+ rank: ScheduleCandidateRankObj; // the winner's rank 1 entry at the moment it was chosen
1912
+ candidateCount: number; // clean eligible candidates when chosen (scarcity)
1913
+ }
1914
+
1915
+ export interface ScheduleRosterUnfilledObj {
1916
+ shiftId: string;
1917
+ reason: ScheduleRosterUnfilledReasonEnum;
1918
+ candidateCount: number; // pool people holding the seat's role (all of the pool when it has none)
1919
+ blockCodes: Array<{
1920
+ code: ScheduleEligibilityReasonObj['code'];
1921
+ count: number;
1922
+ }>; // BLOCK codes among them at the last evaluation, count desc then code
1923
+ }
1924
+
1925
+ export interface ScheduleRosterResultObj {
1926
+ proposals: ScheduleRosterProposalObj[]; // in the order chosen
1927
+ unfilled: ScheduleRosterUnfilledObj[]; // by startAt, then id
1928
+ }
1929
+
1930
+ /**
1931
+ * The standing schedule kept current by scope (utils/standing.ts)
1932
+ */
1933
+
1934
+ export interface ScheduleStandingSeatLinkObj {
1935
+ shiftId: string;
1936
+ templateItemId: string;
1937
+ }
1938
+
1939
+ export interface ScheduleStandingItemEditObj {
1940
+ item: ScheduleTemplateItemSpec; // the item after the edit
1941
+ changed: ScheduleStandingFieldGroupEnum[]; // groups that differ from the item before (PERSON only from assign)
1942
+ }
1943
+
1944
+ export interface ScheduleStandingSeatValuesObj {
1945
+ startAt?: Date;
1946
+ endAt?: Date;
1947
+ roleId?: string | null;
1948
+ locationResourceId?: string | null;
1949
+ unpaidBreakMinutes?: number;
1950
+ label?: string | null;
1951
+ }
1952
+
1953
+ export interface ScheduleStandingRepeatObj {
1954
+ kind: 'COVER' | 'ALTERNATING';
1955
+ itemId: string;
1956
+ resourceIds: string[]; // COVER: [who worked it instead]; ALTERNATING: [the one due next (week A), the other]
1957
+ count: number; // COVER: the run length (>= 3); ALTERNATING: 4
1958
+ }
1959
+
1960
+ /**
1961
+ * Demand and availability expansion (utils/demand.ts, utils/availability.ts)
1962
+ */
1963
+
1964
+ export interface ScheduleDemandIntervalObj {
1965
+ resourceId: string; // the room
1966
+ key: string; // age group
1967
+ quantity: number;
1968
+ startAt: Date;
1969
+ endAt: Date;
1970
+ source: 'PATTERN' | 'OVERRIDE';
1971
+ sourceId: string;
1972
+ }
1973
+
1974
+ export interface ScheduleAvailabilityIntervalObj {
1975
+ availabilityId: string;
1976
+ resourceId: string;
1977
+ kind: ScheduleAvailabilityKindEnum;
1978
+ startAt: Date;
1979
+ endAt: Date;
1980
+ }
1981
+
1982
+ /**
1983
+ * The journal and change notices (utils/shiftChange.ts)
1984
+ */
1985
+
1986
+ // One journal row to insert for a write to a PUBLISHED seat
1987
+ export interface ScheduleShiftChangeEntryObj {
1988
+ kind: ScheduleShiftChangeKindEnum;
1989
+ fromResourceId: string | null;
1990
+ toResourceId: string | null;
1991
+ previousValues: ScheduleShiftValuesObj | null;
1992
+ nextValues: ScheduleShiftValuesObj | null;
1993
+ }
1994
+
1995
+ // A journal row as the net-change renderer reads it (ascending createdAt, id)
1996
+ export interface ScheduleShiftChangeRowInput {
1997
+ id: string;
1998
+ shiftId: string;
1999
+ kind: ScheduleShiftChangeKindEnum;
2000
+ fromResourceId: string | null;
2001
+ toResourceId: string | null;
2002
+ previousValues: ScheduleShiftValuesObj | null;
2003
+ nextValues: ScheduleShiftValuesObj | null;
2004
+ createdAt: Date | string;
2005
+ }
2006
+
2007
+ // The first previous values of a seat in a notice window against its current state
2008
+ export interface ScheduleShiftNetChangeObj {
2009
+ shiftId: string;
2010
+ before: ScheduleShiftStateObj;
2011
+ after: ScheduleShiftStateObj;
2012
+ changedFields: Array<
2013
+ ScheduleShiftJournalFieldEnum | 'assigneeResourceId' | 'status'
2014
+ >; // never empty
2015
+ }
2016
+
2017
+ // What one seat's net change means to one person
2018
+ export type ScheduleShiftRecipientChangeEnum =
2019
+ | 'ADDED'
2020
+ | 'REMOVED'
2021
+ | 'RETIMED'
2022
+ | 'EDITED'
2023
+ | 'CANCELED';
2024
+
2025
+ /**
2026
+ * Requests (utils/request.ts)
2027
+ */
2028
+
2029
+ export type ScheduleRequestActorEnum =
2030
+ | 'REQUESTER'
2031
+ | 'COUNTERPARTY'
2032
+ | 'MANAGER'
2033
+ | 'SYSTEM';
2034
+
2035
+ export type ScheduleRequestTransitionEnum =
2036
+ | 'CREATE'
2037
+ | 'AUTO_APPROVE'
2038
+ | 'CONSENT'
2039
+ | 'REFUSE_CONSENT'
2040
+ | 'WITHDRAW'
2041
+ | 'APPROVE'
2042
+ | 'DECLINE'
2043
+ | 'EXPIRE'
2044
+ | 'CASCADE_CANCEL';
2045
+
2046
+ // The seat change a request asks for
2047
+ export interface ScheduleRequestSubjectObj {
2048
+ kind: ScheduleRequestKindEnum;
2049
+ shiftId: string;
2050
+ targetShiftId: string | null;
2051
+ requesterResourceId: string;
2052
+ counterpartyResourceId: string | null;
2053
+ proposedStartAt: Date | string | null;
2054
+ proposedEndAt: Date | string | null;
2055
+ }
2056
+
2057
+ /**
2058
+ * Rule presets per vertical (utils/rulePresets.ts)
2059
+ */
2060
+
2061
+ export interface ScheduleRulePresetRuleObj {
2062
+ kind: ScheduleRuleKindEnum;
2063
+ key: string;
2064
+ label: string;
2065
+ severity: ScheduleRuleSeverityEnum;
2066
+ config: ScheduleRuleConfigObj; // valid under validateScheduleRuleConfig; never names an org-specific id
2067
+ }
2068
+
2069
+ export interface ScheduleRulePresetObj {
2070
+ name: string; // stable handle for set_schedule_rule (e.g. 'DAYCARE_LICENSING')
2071
+ label: string;
2072
+ description: string;
2073
+ ageGroups: ScheduleAgeGroupObj[] | null; // the catalog the preset's RATIO keys assume; null = none needed
2074
+ rules: ScheduleRulePresetRuleObj[];
2075
+ }
2076
+
2077
+ /**
2078
+ * Text previews (utils/scheduleText.ts). Every input is plain, already
2079
+ * resolved data: names instead of ids, times rendered in the calendar zone.
2080
+ */
2081
+
2082
+ export interface ScheduleTextContext {
2083
+ timeZone: string; // the calendar zone: every time is rendered in it
2084
+ calendarName: string | null;
2085
+ link: string | null; // absolute URL appended as the last line, or null
2086
+ }
2087
+
2088
+ export interface ScheduleTextShift {
2089
+ id: string;
2090
+ shiftDate: string;
2091
+ startAt: Date | string;
2092
+ endAt: Date | string;
2093
+ status: ScheduleShiftStatusEnum;
2094
+ roleName: string | null;
2095
+ locationName: string | null;
2096
+ assigneeResourceId: string | null; // null = open
2097
+ assigneeName: string | null;
2098
+ label: string | null;
2099
+ templateItemId: string | null;
2100
+ calendarName?: string | null; // a seat of another calendar (my shifts)
2101
+ timeZone?: string | null; // its calendar's zone, when it differs from the context
2102
+ }
2103
+
2104
+ // A persisted or fresh finding, message already rendered (formatViolationMessage)
2105
+ export interface ScheduleTextFinding {
2106
+ key: string;
2107
+ kind: ScheduleRuleKindEnum;
2108
+ code: ScheduleCoverageViolationCode | null;
2109
+ severity: ScheduleRuleSeverityEnum;
2110
+ startAt: Date | string;
2111
+ endAt: Date | string;
2112
+ message: string;
2113
+ acknowledged: boolean;
2114
+ }
2115
+
2116
+ // An evaluation diagnostic (why a rule could not be checked) with its names resolved
2117
+ export interface ScheduleTextDiagnostic {
2118
+ code: ScheduleCoverageDiagnosticCodeEnum;
2119
+ ruleLabel: string | null; // the rule it concerns
2120
+ resourceName: string | null; // the room or person it concerns
2121
+ detail: Record<string, unknown>; // the engine's detail: { key }, { error }, { maxDays }, { limit }
2122
+ }
2123
+
2124
+ export interface ScheduleTextPerson {
2125
+ resourceId: string;
2126
+ name: string;
2127
+ }
2128
+
2129
+ // Who is new, gone or moved between two periods
2130
+ export interface SchedulePeriodDiffObj {
2131
+ newPeople: Array<ScheduleTextPerson & { shiftCount: number }>; // work the next period, not the previous
2132
+ gonePeople: Array<ScheduleTextPerson & { shiftCount: number }>; // worked the previous, not the next
2133
+ moved: Array<
2134
+ ScheduleTextPerson & { from: ScheduleTextShift[]; to: ScheduleTextShift[] }
2135
+ >; // in both, on different seats
2136
+ }
2137
+
2138
+ export interface SchedulePeriodSummaryTextInput {
2139
+ context: ScheduleTextContext;
2140
+ fromDate: string;
2141
+ toDate: string; // inclusive
2142
+ weeks: Array<{ weekStart: string; rotationWeek: number | null }>; // null = no rotation
2143
+ shifts: ScheduleTextShift[]; // the period's live seats
2144
+ unpublishedDates: string[]; // dates of the period no publication covers yet; [] = all published
2145
+ findings: ScheduleTextFinding[];
2146
+ diagnostics?: ScheduleTextDiagnostic[] | null; // rules that could not be checked; any = incomplete
2147
+ diff: SchedulePeriodDiffObj | null; // against the baseline weeks (getSchedulePeriodWeekDiff); null = nothing to compare
2148
+ covers?: ScheduleCoverTextItem[] | null; // Phase 3: fixed people off, and who covers (the preparation's own summary)
2149
+ instructions?: {
2150
+ applied: string[]; // formatPreparePassEdit lines
2151
+ refused: string[]; // formatPreparePassEdit lines of refused edits ("Couldn't: ...")
2152
+ unmet: string[];
2153
+ failed: boolean; // the pass failed: nothing applied
2154
+ stale: boolean; // the schedule changed during the pass: nothing applied
2155
+ } | null; // Phase 3: "From your standing instructions"
2156
+ repeats?: ScheduleRepeatTextItem[] | null; // Phase 3: repeat-detection lines
2157
+ specialDays?: ScheduleSpecialDayTextItem[] | null; // the location's closures and special hours in the period
2158
+ unusableStandingCount?: number; // standing shifts preparing skips: their role is archived or their room retired
2159
+ }
2160
+
2161
+ // A date of a period on which the location is closed (hours []) or keeps special hours, with its live seats
2162
+ export interface ScheduleSpecialDayTextItem {
2163
+ date: string;
2164
+ hours: Array<[string, string]>; // [] = closed; else the open intervals, local HH:MM
2165
+ shiftCount: number; // live seats of the period on that date
2166
+ }
2167
+
2168
+ // A standing seat whose fixed person could not work it (preparation summary)
2169
+ export interface ScheduleCoverTextItem {
2170
+ shift: ScheduleTextShift; // the standing seat as prepared (open, or held by the cover)
2171
+ fixedName: string; // its fixed person, who could not work it
2172
+ reason: string; // a clause already rendered (formatEligibilityReason of the first BLOCK)
2173
+ }
2174
+
2175
+ // One edit of the standing-instructions pass, applied or refused
2176
+ export interface SchedulePreparePassEditTextInput {
2177
+ context: ScheduleTextContext;
2178
+ kind: SchedulePrepareEditKindEnum;
2179
+ shift: ScheduleTextShift; // after the edit (delete: before); a refused edit: the seat as the edit would have left it (assign: with the person; create: the seat it would have made)
2180
+ previousAssigneeName?: string | null; // assign over someone, unassign
2181
+ previous?: { startAt: Date | string; endAt: Date | string } | null; // retime
2182
+ reason: string; // the model's reason, already sanitized
2183
+ refusal?: string | null; // a refused edit: why, as a clause
2184
+ }
2185
+
2186
+ export interface ScheduleMyShiftsTextInput {
2187
+ context: ScheduleTextContext;
2188
+ personName: string | null;
2189
+ fromDate: string;
2190
+ toDate: string;
2191
+ shifts: ScheduleTextShift[]; // PUBLISHED seats of the person, any calendar
2192
+ openShifts: ScheduleTextShift[]; // open PUBLISHED seats the person may claim; [] = none listed
2193
+ }
2194
+
2195
+ export interface ScheduleShiftChangeTextItem {
2196
+ change: ScheduleShiftRecipientChangeEnum;
2197
+ before: ScheduleTextShift;
2198
+ after: ScheduleTextShift;
2199
+ }
2200
+
2201
+ export interface ScheduleShiftChangeTextInput {
2202
+ context: ScheduleTextContext;
2203
+ recipientName: string | null;
2204
+ changes: ScheduleShiftChangeTextItem[];
2205
+ }
2206
+
2207
+ export interface ScheduleRequestTextInput {
2208
+ context: ScheduleTextContext;
2209
+ audience: 'MANAGER' | 'REQUESTER' | 'COUNTERPARTY';
2210
+ // A notice (SMS, email, in-app) rather than a chat reply: until Phase 2 asks, no reply to a notice is matched
2211
+ // to its request, so the text says to ask the assistant instead of "Reply YES or NO"
2212
+ notice?: boolean;
2213
+ request: {
2214
+ id: string;
2215
+ kind: ScheduleRequestKindEnum;
2216
+ status: ScheduleRequestStatusEnum;
2217
+ requesterName: string;
2218
+ counterpartyName: string | null;
2219
+ shift: ScheduleTextShift;
2220
+ targetShift: ScheduleTextShift | null; // SWAP
2221
+ proposedStartAt: Date | string | null; // RETIME
2222
+ proposedEndAt: Date | string | null;
2223
+ reason: string | null;
2224
+ decisionNote: string | null; // a no carries its words
2225
+ autoApproved: boolean;
2226
+ };
2227
+ reasons: ScheduleEligibilityReasonObj[]; // eligibility and impact to mention; [] = none
2228
+ }
2229
+
2230
+ export interface ScheduleCandidateTextItem extends ScheduleTextPerson {
2231
+ eligible: boolean;
2232
+ reasons: ScheduleEligibilityReasonObj[];
2233
+ score: number | null; // the ranking total; null = unranked
2234
+ rank: number | null; // the engine rank (1 = best eligible); null = ineligible or unranked. Lines are numbered by list order.
2235
+ scoreReasons: ScheduleCandidateScoreReasonObj[]; // the ranking reasons; eligible lines show the top two (formatCandidateScoreClauses)
2236
+ }
2237
+
2238
+ export interface ScheduleCandidatesTextInput {
2239
+ context: ScheduleTextContext;
2240
+ shift: ScheduleTextShift;
2241
+ candidates: ScheduleCandidateTextItem[]; // already ordered
2242
+ }
2243
+
2244
+ export interface ScheduleCoverageFindingsTextInput {
2245
+ context: ScheduleTextContext;
2246
+ fromDate: string;
2247
+ toDate: string;
2248
+ findings: ScheduleTextFinding[];
2249
+ diagnostics: ScheduleTextDiagnostic[]; // why rules could not be checked; [] = the check was complete
2250
+ }
2251
+
2252
+ export interface ScheduleStandingTextItem {
2253
+ week: number;
2254
+ weekday: number;
2255
+ startTime: string;
2256
+ endTime: string;
2257
+ roleName: string | null;
2258
+ locationName: string | null;
2259
+ assigneeName: string | null; // null = open seat
2260
+ label: string | null;
2261
+ }
2262
+
2263
+ // Phase 3 repeat detection over one standing item's last published seats (IMPLEMENTATION §1.12), detected by the caller
2264
+ export interface ScheduleRepeatTextItem {
2265
+ kind: 'COVER' | 'ALTERNATING';
2266
+ item: ScheduleStandingTextItem; // the standing seat; assigneeName = its fixed person
2267
+ names: string[]; // COVER: who has worked it instead; ALTERNATING: the people alternating, in rotation order
2268
+ count: number; // COVER: how many periods running
2269
+ weekAStart?: string | null; // ALTERNATING: the first day of the pay week names[0] works (week A), named in the line
2270
+ }
2271
+
2272
+ export interface ScheduleStandingScheduleTextInput {
2273
+ context: ScheduleTextContext;
2274
+ name: string;
2275
+ rotationWeeks: number;
2276
+ rotationAnchor: string | null;
2277
+ payWeekStart: number; // the org's week start: each week's first listed day, and the week of the anchor named as week A
2278
+ items: ScheduleStandingTextItem[];
2279
+ nextRotationWeek: number | null; // which rotation week the next period starts on
2280
+ }
2281
+
2282
+ // Name resolvers for one violation message (formatViolationMessage)
2283
+ export interface ScheduleViolationMessageNames {
2284
+ timeZone: string;
2285
+ resource: (id: string) => string;
2286
+ shift: (id: string) => string;
2287
+ role: (id: string) => string;
2288
+ }
2289
+
2290
+ /**
2291
+ * Ask, offer and time-off texts (utils/scheduleText.ts, Phase 2). Names are
2292
+ * resolved and times render in the context zone.
2293
+ */
2294
+
2295
+ // An organization's scheduling type (the server maps its operation); SMS
2296
+ // consent texts name what the texts are about by it
2297
+ export type ScheduleSchedulingTypeEnum =
2298
+ | 'STAFF_SCHEDULES'
2299
+ | 'PROJECT_MANAGEMENT';
2300
+
2301
+ // The question an ask sends (formatAskText), by kind
2302
+ export type ScheduleAskTextInput =
2303
+ | {
2304
+ kind: 'OFFER';
2305
+ context: ScheduleTextContext;
2306
+ shift: ScheduleTextShift;
2307
+ message: string | null; // the manager's note
2308
+ autoApprove: boolean; // false: a yes asks for the seat and a manager confirms
2309
+ }
2310
+ | {
2311
+ kind: 'SWAP_CONSENT' | 'REQUEST_DECISION';
2312
+ request: ScheduleRequestTextInput; // rendered as COUNTERPARTY / MANAGER, never as a notice
2313
+ }
2314
+ | { kind: 'TIME_OFF_DECISION'; timeOff: ScheduleTimeOffTextInput } // rendered as MANAGER, never as a notice
2315
+ | { kind: 'PUBLISH_REVIEW'; summary: SchedulePeriodSummaryTextInput }
2316
+ | { kind: 'SHIFTS_CONFIRM'; myShifts: ScheduleMyShiftsTextInput } // its open seats are not listed
2317
+ | {
2318
+ kind: 'SMS_CONSENT';
2319
+ organizationName: string;
2320
+ schedulingType: ScheduleSchedulingTypeEnum | null; // null reads as STAFF_SCHEDULES
2321
+ }
2322
+ | { kind: 'PLAN_REVIEW'; summary: SchedulePlanSummaryTextInput } // rendered with audience ASK
2323
+ | { kind: 'PROGRESS_CHECK'; check: ScheduleProgressCheckTextInput };
2324
+
2325
+ // One line naming what an ask asks (formatAskLine): chat context and lists
2326
+ export interface ScheduleAskLineInput {
2327
+ kind: ScheduleAskKindEnum;
2328
+ context: ScheduleTextContext; // link ignored; calendarName names the location
2329
+ shift?: ScheduleTextShift | null; // OFFER; SWAP_CONSENT: the recipient's seat; REQUEST_DECISION: the request's seat
2330
+ targetShift?: ScheduleTextShift | null; // SWAP_CONSENT: the seat they would take; REQUEST_DECISION SWAP: the counterparty's seat (its assigneeName names them)
2331
+ requestKind?: ScheduleRequestKindEnum | null; // REQUEST_DECISION
2332
+ proposed?: { startAt: Date | string; endAt: Date | string } | null; // REQUEST_DECISION RETIME: the new hours
2333
+ personName?: string | null; // the requester / the time-off person
2334
+ timeOff?: {
2335
+ startAt: Date | string;
2336
+ endAt: Date | string;
2337
+ allDay: boolean;
2338
+ } | null;
2339
+ affectedShiftCount?: number | null; // TIME_OFF_DECISION: seats an approval releases
2340
+ period?: { fromDate: string; toDate: string } | null; // PUBLISH_REVIEW, SHIFTS_CONFIRM
2341
+ shiftCount?: number | null; // PUBLISH_REVIEW: the period's live seats; SHIFTS_CONFIRM: the person's seats
2342
+ warningCount?: number | null; // PUBLISH_REVIEW: unacknowledged warnings
2343
+ organizationName?: string | null; // SMS_CONSENT
2344
+ schedulingType?: ScheduleSchedulingTypeEnum | null; // SMS_CONSENT: what the texts are about
2345
+ projectName?: string | null; // PLAN_REVIEW, PROGRESS_CHECK (else context.calendarName)
2346
+ activityCount?: number | null; // PLAN_REVIEW: activities under review
2347
+ finishAt?: Date | string | null; // PLAN_REVIEW: the project's scheduled finish
2348
+ items?: string[] | null; // PROGRESS_CHECK: the item names in order
2349
+ }
2350
+
2351
+ export type ScheduleAskAnswerOutcome =
2352
+ | 'APPLIED'
2353
+ | 'REPLAYED'
2354
+ | 'TOO_LATE'
2355
+ | 'SUPERSEDED'
2356
+ | 'REFUSED';
2357
+
2358
+ // The reply to an answer (formatAskReply)
2359
+ export interface ScheduleAskReplyTextInput {
2360
+ kind: ScheduleAskKindEnum;
2361
+ answer: ScheduleAskAnswerEnum;
2362
+ outcome: Exclude<ScheduleAskAnswerOutcome, 'REPLAYED'>;
2363
+ context: ScheduleTextContext; // link ignored
2364
+ subjectLabel: string | null; // payload.subjectLabel
2365
+ personName?: string | null; // the requester (decisions, swaps)
2366
+ requestKind?: ScheduleRequestKindEnum | null; // REQUEST_DECISION: names what was decided
2367
+ organizationName?: string | null; // SMS_CONSENT
2368
+ schedulingType?: ScheduleSchedulingTypeEnum | null; // SMS_CONSENT: what the texts are about
2369
+ closed?: ScheduleAskStatusEnum | ScheduleAskReasonEnum | null; // TOO_LATE: ANSWERED (by you), EXPIRED, ANSWERED_BY_OTHER, SUBJECT_CLOSED, SUPERSEDED, ...
2370
+ filled?: boolean | null; // OFFER YES: true = theirs now, false = waiting for a manager
2371
+ swapped?: boolean | null; // SWAP_CONSENT YES: approved at once
2372
+ publishedCount?: number | null; // PUBLISH_REVIEW YES
2373
+ refusals?: string[]; // REFUSED: clauses already rendered (formatEligibilityReason, publish blockers, diagnostics)
2374
+ projectName?: string | null; // PLAN_REVIEW (else subjectLabel)
2375
+ acceptedCount?: number | null; // PLAN_REVIEW YES: activities marked reviewed
2376
+ rejectPreview?: {
2377
+ newNames: string[]; // "A1010 Framing", the first few
2378
+ newCount: number;
2379
+ changedNames: string[];
2380
+ changedCount: number;
2381
+ } | null; // PLAN_REVIEW NO: what rejecting the proposal would remove
2382
+ }
2383
+
2384
+ // An offer for the manager (formatOffer): tool text and the OFFER_FILLED /
2385
+ // OFFER_UNFILLED notice bodies
2386
+ export interface ScheduleOfferTextInput {
2387
+ context: ScheduleTextContext;
2388
+ shift: ScheduleTextShift;
2389
+ status: ScheduleOfferStatusEnum;
2390
+ event: 'CREATED' | 'FILLED' | 'UNFILLED' | 'STATUS';
2391
+ filledByName: string | null;
2392
+ now?: Date | string | null; // a wave due by now reads "now"; null = every wave by its time
2393
+ asks: Array<{
2394
+ name: string;
2395
+ rank: number;
2396
+ wave: number;
2397
+ status: ScheduleAskStatusEnum;
2398
+ answer: ScheduleAskAnswerEnum | null;
2399
+ reason: ScheduleAskReasonEnum | null;
2400
+ sendAt: Date | string;
2401
+ sentAt?: Date | string | null; // set once texted (or shown in the app)
2402
+ }>;
2403
+ }
2404
+
2405
+ // A time-off request (formatTimeOff): a notice, a tool text, or the
2406
+ // TIME_OFF_DECISION ask. context.timeZone is the time off's own zone.
2407
+ export interface ScheduleTimeOffTextInput {
2408
+ context: ScheduleTextContext;
2409
+ audience: 'REQUESTER' | 'MANAGER';
2410
+ notice?: boolean; // a notice: "Ask the assistant to approve or decline ..." instead of "Reply YES or NO"
2411
+ timeOff: {
2412
+ personName: string;
2413
+ startAt: Date | string;
2414
+ endAt: Date | string; // exclusive; an all-day time off ends at a local midnight
2415
+ allDay: boolean;
2416
+ status: ScheduleTimeOffStatusEnum;
2417
+ reason: string | null;
2418
+ decisionNote: string | null; // a no carries its words
2419
+ };
2420
+ conflictingShifts: ScheduleTextShift[]; // PENDING: seats an approval would release; APPROVED: the seats it released
2421
+ }
2422
+
2423
+ // Open asks and offers for list_schedule_requests (formatAskOverview)
2424
+ export interface ScheduleAskOverviewTextInput {
2425
+ context: ScheduleTextContext;
2426
+ mine: Array<{ readableId: string; line: string; expiresAt: Date | string }>;
2427
+ others: Array<{
2428
+ line: string;
2429
+ recipients: Array<{
2430
+ name: string;
2431
+ status: ScheduleAskStatusEnum;
2432
+ answer: ScheduleAskAnswerEnum | null;
2433
+ replyText: string | null;
2434
+ }>;
2435
+ }>;
2436
+ offers: Array<{ readableId: string; text: string }>; // formatOffer(event STATUS) per open offer
2437
+ }
2438
+
2439
+ /**
2440
+ * To-do and project texts (utils/scheduleText.ts, Phases 4 and 5). Names are
2441
+ * resolved; times render in the to-do's own zone or the project's zone.
2442
+ */
2443
+
2444
+ // One to-do in a list (formatTodoList)
2445
+ export interface ScheduleTodoTextItem {
2446
+ title: string;
2447
+ note: string | null;
2448
+ status: ScheduleTaskStatusEnum;
2449
+ dueAt: Date | string | null;
2450
+ dueAllDay: boolean;
2451
+ timeZone: string; // the to-do's own zone
2452
+ priority: number; // 0 NONE ... 3 HIGH
2453
+ assigneeName: string | null;
2454
+ scopeName: string | null; // the location or project, shown when a list spans several
2455
+ attachedLabel: string | null; // formatScheduleShiftLine of its seat, or "A1010 Framing"
2456
+ seatHidden?: boolean; // attached to a seat this reader may not see: reads "a shift"
2457
+ }
2458
+
2459
+ // A to-do list (tool text) or the TASK_ASSIGNED body (formatTodoList)
2460
+ export interface ScheduleTodoListTextInput {
2461
+ context: ScheduleTextContext;
2462
+ mode: 'LIST' | 'ASSIGNED'; // ASSIGNED renders todos[0] as the notice
2463
+ title: string | null; // LIST heading, e.g. "Your to-dos", "To-dos at Main St"; null = "To-dos"
2464
+ todos: ScheduleTodoTextItem[];
2465
+ totalCount: number; // more than listed adds "+N more"
2466
+ now: Date | string;
2467
+ assignedByName?: string | null; // ASSIGNED
2468
+ // LIST: the statuses the list read (its empty sentence names them); absent = the open ones
2469
+ statuses?: readonly ScheduleTaskStatusEnum[] | null;
2470
+ }
2471
+
2472
+ // A proposed plan (formatPlanSummary): the PLAN_REVIEW ask or a tool text.
2473
+ // context: the project's zone; calendarName = the project name; link = the Gantt.
2474
+ export interface SchedulePlanSummaryTextInput {
2475
+ context: ScheduleTextContext;
2476
+ audience: 'ASK' | 'TOOL'; // ASK ends with how to answer and fits the SMS budget; TOOL asks nothing
2477
+ activityCount: number;
2478
+ newCount: number;
2479
+ changedCount: number; // source.replacedExisting
2480
+ milestones: Array<{
2481
+ code: string;
2482
+ name: string;
2483
+ finishAt: Date | string | null;
2484
+ }>;
2485
+ calculated: boolean; // the latest complete run matches the network
2486
+ pending: boolean; // a run is queued or running: not calculated reads "being calculated", else "not calculated yet"
2487
+ finishAt: Date | string | null;
2488
+ mustFinishByAt: Date | string | null;
2489
+ criticalPath: Array<{ code: string; name: string }>; // by start: the critical activities, or the longest path
2490
+ criticalPathKind: ScheduleCriticalPathKindEnum;
2491
+ lowConfidence: Array<{ code: string; name: string; confidence: number }>; // lowest first
2492
+ }
2493
+
2494
+ // A PROGRESS_CHECK ask (formatProgressCheck). context: the project's zone and
2495
+ // name; link null.
2496
+ export interface ScheduleProgressCheckTextInput {
2497
+ context: ScheduleTextContext;
2498
+ items: Array<{
2499
+ name: string; // the activity name (its code only when the name is empty)
2500
+ status: 'NOT_STARTED' | 'IN_PROGRESS';
2501
+ startAt: Date | string | null;
2502
+ finishAt: Date | string | null;
2503
+ percentComplete: number; // 0-100
2504
+ }>; // numbered in this order: item n = payload.activityIds[n-1]
2505
+ moreCount: number; // due or running activities not listed this time
2506
+ }
2507
+
2508
+ // The PROJECT_DIGEST body (formatProjectDigest). context: the project's zone
2509
+ // and name; link = the Gantt.
2510
+ export interface ScheduleProjectDigestTextInput {
2511
+ context: ScheduleTextContext;
2512
+ digest: ScheduleProjectDigestPayloadObj;
2513
+ }
2514
+
2515
+ // The MILESTONE_AT_RISK body (formatProjectSlip). context: the project's zone
2516
+ // and name; link = the Gantt.
2517
+ export interface ScheduleProjectSlipTextInput {
2518
+ context: ScheduleTextContext;
2519
+ slip: ScheduleProjectSlipPayloadObj;
2520
+ }