-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhrisemployment.go
More file actions
557 lines (493 loc) · 21.1 KB
/
hrisemployment.go
File metadata and controls
557 lines (493 loc) · 21.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package finchgo
import (
"context"
"net/http"
"reflect"
"slices"
"github.com/Finch-API/finch-api-go/internal/apijson"
"github.com/Finch-API/finch-api-go/internal/param"
"github.com/Finch-API/finch-api-go/internal/requestconfig"
"github.com/Finch-API/finch-api-go/option"
"github.com/Finch-API/finch-api-go/packages/pagination"
"github.com/Finch-API/finch-api-go/shared"
"github.com/tidwall/gjson"
)
// HRISEmploymentService contains methods and other services that help with
// interacting with the Finch API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewHRISEmploymentService] method instead.
type HRISEmploymentService struct {
Options []option.RequestOption
}
// NewHRISEmploymentService generates a new service that applies the given options
// to each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewHRISEmploymentService(opts ...option.RequestOption) (r *HRISEmploymentService) {
r = &HRISEmploymentService{}
r.Options = opts
return
}
// Read individual employment and income data
func (r *HRISEmploymentService) GetMany(ctx context.Context, body HRISEmploymentGetManyParams, opts ...option.RequestOption) (res *pagination.ResponsesPage[EmploymentDataResponse], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "employer/employment"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodPost, path, body, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Read individual employment and income data
func (r *HRISEmploymentService) GetManyAutoPaging(ctx context.Context, body HRISEmploymentGetManyParams, opts ...option.RequestOption) *pagination.ResponsesPageAutoPager[EmploymentDataResponse] {
return pagination.NewResponsesPageAutoPager(r.GetMany(ctx, body, opts...))
}
type EmploymentData struct {
// A stable Finch `id` (UUID v4) for an individual in the company.
ID string `json:"id" format:"uuid"`
// Worker's compensation classification code for this employee
ClassCode string `json:"class_code,nullable"`
Code float64 `json:"code"`
// This field can have the runtime type of [[]EmploymentDataObjectCustomField].
CustomFields interface{} `json:"custom_fields"`
// This field can have the runtime type of [EmploymentDataObjectDepartment].
Department interface{} `json:"department"`
// This field can have the runtime type of [EmploymentDataObjectEmployment].
Employment interface{} `json:"employment"`
// The detailed employment status of the individual. Available options: `active`,
// `deceased`, `leave`, `onboarding`, `prehire`, `retired`, `terminated`.
EmploymentStatus EmploymentDataEmploymentStatus `json:"employment_status,nullable"`
EndDate string `json:"end_date,nullable"`
FinchCode string `json:"finch_code"`
// The legal first name of the individual.
FirstName string `json:"first_name,nullable"`
// The employee's income as reported by the provider. This may not always be
// annualized income, but may be in units of bi-weekly, semi-monthly, daily, etc,
// depending on what information the provider returns.
Income Income `json:"income,nullable"`
// This field can have the runtime type of [[]Income].
IncomeHistory interface{} `json:"income_history"`
// `true` if the individual an an active employee or contractor at the company.
IsActive bool `json:"is_active,nullable"`
// The legal last name of the individual.
LastName string `json:"last_name,nullable"`
LatestRehireDate string `json:"latest_rehire_date,nullable"`
Location Location `json:"location,nullable"`
// This field can have the runtime type of [EmploymentDataObjectManager].
Manager interface{} `json:"manager"`
Message string `json:"message"`
// The legal middle name of the individual.
MiddleName string `json:"middle_name,nullable"`
Name string `json:"name"`
// The source system's unique employment identifier for this individual
SourceID string `json:"source_id,nullable"`
StartDate string `json:"start_date,nullable"`
// The current title of the individual.
Title string `json:"title,nullable"`
// This field is deprecated in favour of `source_id`
//
// Deprecated: deprecated
WorkID string `json:"work_id,nullable"`
JSON employmentDataJSON `json:"-"`
union EmploymentDataUnion
}
// employmentDataJSON contains the JSON metadata for the struct [EmploymentData]
type employmentDataJSON struct {
ID apijson.Field
ClassCode apijson.Field
Code apijson.Field
CustomFields apijson.Field
Department apijson.Field
Employment apijson.Field
EmploymentStatus apijson.Field
EndDate apijson.Field
FinchCode apijson.Field
FirstName apijson.Field
Income apijson.Field
IncomeHistory apijson.Field
IsActive apijson.Field
LastName apijson.Field
LatestRehireDate apijson.Field
Location apijson.Field
Manager apijson.Field
Message apijson.Field
MiddleName apijson.Field
Name apijson.Field
SourceID apijson.Field
StartDate apijson.Field
Title apijson.Field
WorkID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r employmentDataJSON) RawJSON() string {
return r.raw
}
func (r *EmploymentData) UnmarshalJSON(data []byte) (err error) {
*r = EmploymentData{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
// AsUnion returns a [EmploymentDataUnion] interface which you can cast to the
// specific types for more type safety.
//
// Possible runtime types of the union are [EmploymentDataObject],
// [EmploymentDataBatchError].
func (r EmploymentData) AsUnion() EmploymentDataUnion {
return r.union
}
// Union satisfied by [EmploymentDataObject] or [EmploymentDataBatchError].
type EmploymentDataUnion interface {
implementsEmploymentData()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*EmploymentDataUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(EmploymentDataObject{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(EmploymentDataBatchError{}),
},
)
}
type EmploymentDataObject struct {
// A stable Finch `id` (UUID v4) for an individual in the company.
ID string `json:"id,required" format:"uuid"`
// Worker's compensation classification code for this employee
ClassCode string `json:"class_code,required,nullable"`
// The department object.
Department EmploymentDataObjectDepartment `json:"department,required,nullable"`
// The employment object.
Employment EmploymentDataObjectEmployment `json:"employment,required,nullable"`
// The detailed employment status of the individual. Available options: `active`,
// `deceased`, `leave`, `onboarding`, `prehire`, `retired`, `terminated`.
EmploymentStatus EmploymentDataObjectEmploymentStatus `json:"employment_status,required,nullable"`
EndDate string `json:"end_date,required,nullable"`
// The legal first name of the individual.
FirstName string `json:"first_name,required,nullable"`
// `true` if the individual an an active employee or contractor at the company.
IsActive bool `json:"is_active,required,nullable"`
// The legal last name of the individual.
LastName string `json:"last_name,required,nullable"`
LatestRehireDate string `json:"latest_rehire_date,required,nullable"`
Location Location `json:"location,required,nullable"`
// The manager object representing the manager of the individual within the org.
Manager EmploymentDataObjectManager `json:"manager,required,nullable"`
// The legal middle name of the individual.
MiddleName string `json:"middle_name,required,nullable"`
StartDate string `json:"start_date,required,nullable"`
// The current title of the individual.
Title string `json:"title,required,nullable"`
// Custom fields for the individual. These are fields which are defined by the
// employer in the system. Custom fields are not currently supported for assisted
// connections.
CustomFields []EmploymentDataObjectCustomField `json:"custom_fields,nullable"`
// The employee's income as reported by the provider. This may not always be
// annualized income, but may be in units of bi-weekly, semi-monthly, daily, etc,
// depending on what information the provider returns.
Income Income `json:"income,nullable"`
// The array of income history.
IncomeHistory []Income `json:"income_history,nullable"`
// The source system's unique employment identifier for this individual
SourceID string `json:"source_id,nullable"`
// This field is deprecated in favour of `source_id`
//
// Deprecated: deprecated
WorkID string `json:"work_id,nullable"`
JSON employmentDataObjectJSON `json:"-"`
}
// employmentDataObjectJSON contains the JSON metadata for the struct
// [EmploymentDataObject]
type employmentDataObjectJSON struct {
ID apijson.Field
ClassCode apijson.Field
Department apijson.Field
Employment apijson.Field
EmploymentStatus apijson.Field
EndDate apijson.Field
FirstName apijson.Field
IsActive apijson.Field
LastName apijson.Field
LatestRehireDate apijson.Field
Location apijson.Field
Manager apijson.Field
MiddleName apijson.Field
StartDate apijson.Field
Title apijson.Field
CustomFields apijson.Field
Income apijson.Field
IncomeHistory apijson.Field
SourceID apijson.Field
WorkID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *EmploymentDataObject) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r employmentDataObjectJSON) RawJSON() string {
return r.raw
}
func (r EmploymentDataObject) implementsEmploymentData() {}
// The department object.
type EmploymentDataObjectDepartment struct {
// The name of the department associated with the individual.
Name string `json:"name,required,nullable"`
JSON employmentDataObjectDepartmentJSON `json:"-"`
}
// employmentDataObjectDepartmentJSON contains the JSON metadata for the struct
// [EmploymentDataObjectDepartment]
type employmentDataObjectDepartmentJSON struct {
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *EmploymentDataObjectDepartment) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r employmentDataObjectDepartmentJSON) RawJSON() string {
return r.raw
}
// The employment object.
type EmploymentDataObjectEmployment struct {
// The secondary employment type of the individual. Options: `full_time`,
// `part_time`, `intern`, `temp`, `seasonal` and `individual_contractor`.
Subtype EmploymentDataObjectEmploymentSubtype `json:"subtype,required,nullable"`
// The main employment type of the individual.
Type EmploymentDataObjectEmploymentType `json:"type,required,nullable"`
JSON employmentDataObjectEmploymentJSON `json:"-"`
}
// employmentDataObjectEmploymentJSON contains the JSON metadata for the struct
// [EmploymentDataObjectEmployment]
type employmentDataObjectEmploymentJSON struct {
Subtype apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *EmploymentDataObjectEmployment) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r employmentDataObjectEmploymentJSON) RawJSON() string {
return r.raw
}
// The secondary employment type of the individual. Options: `full_time`,
// `part_time`, `intern`, `temp`, `seasonal` and `individual_contractor`.
type EmploymentDataObjectEmploymentSubtype string
const (
EmploymentDataObjectEmploymentSubtypeFullTime EmploymentDataObjectEmploymentSubtype = "full_time"
EmploymentDataObjectEmploymentSubtypeIntern EmploymentDataObjectEmploymentSubtype = "intern"
EmploymentDataObjectEmploymentSubtypePartTime EmploymentDataObjectEmploymentSubtype = "part_time"
EmploymentDataObjectEmploymentSubtypeTemp EmploymentDataObjectEmploymentSubtype = "temp"
EmploymentDataObjectEmploymentSubtypeSeasonal EmploymentDataObjectEmploymentSubtype = "seasonal"
EmploymentDataObjectEmploymentSubtypeIndividualContractor EmploymentDataObjectEmploymentSubtype = "individual_contractor"
)
func (r EmploymentDataObjectEmploymentSubtype) IsKnown() bool {
switch r {
case EmploymentDataObjectEmploymentSubtypeFullTime, EmploymentDataObjectEmploymentSubtypeIntern, EmploymentDataObjectEmploymentSubtypePartTime, EmploymentDataObjectEmploymentSubtypeTemp, EmploymentDataObjectEmploymentSubtypeSeasonal, EmploymentDataObjectEmploymentSubtypeIndividualContractor:
return true
}
return false
}
// The main employment type of the individual.
type EmploymentDataObjectEmploymentType string
const (
EmploymentDataObjectEmploymentTypeEmployee EmploymentDataObjectEmploymentType = "employee"
EmploymentDataObjectEmploymentTypeContractor EmploymentDataObjectEmploymentType = "contractor"
)
func (r EmploymentDataObjectEmploymentType) IsKnown() bool {
switch r {
case EmploymentDataObjectEmploymentTypeEmployee, EmploymentDataObjectEmploymentTypeContractor:
return true
}
return false
}
// The detailed employment status of the individual. Available options: `active`,
// `deceased`, `leave`, `onboarding`, `prehire`, `retired`, `terminated`.
type EmploymentDataObjectEmploymentStatus string
const (
EmploymentDataObjectEmploymentStatusActive EmploymentDataObjectEmploymentStatus = "active"
EmploymentDataObjectEmploymentStatusDeceased EmploymentDataObjectEmploymentStatus = "deceased"
EmploymentDataObjectEmploymentStatusLeave EmploymentDataObjectEmploymentStatus = "leave"
EmploymentDataObjectEmploymentStatusOnboarding EmploymentDataObjectEmploymentStatus = "onboarding"
EmploymentDataObjectEmploymentStatusPrehire EmploymentDataObjectEmploymentStatus = "prehire"
EmploymentDataObjectEmploymentStatusRetired EmploymentDataObjectEmploymentStatus = "retired"
EmploymentDataObjectEmploymentStatusTerminated EmploymentDataObjectEmploymentStatus = "terminated"
)
func (r EmploymentDataObjectEmploymentStatus) IsKnown() bool {
switch r {
case EmploymentDataObjectEmploymentStatusActive, EmploymentDataObjectEmploymentStatusDeceased, EmploymentDataObjectEmploymentStatusLeave, EmploymentDataObjectEmploymentStatusOnboarding, EmploymentDataObjectEmploymentStatusPrehire, EmploymentDataObjectEmploymentStatusRetired, EmploymentDataObjectEmploymentStatusTerminated:
return true
}
return false
}
// The manager object representing the manager of the individual within the org.
type EmploymentDataObjectManager struct {
// A stable Finch `id` (UUID v4) for an individual in the company.
ID string `json:"id,required" format:"uuid"`
JSON employmentDataObjectManagerJSON `json:"-"`
}
// employmentDataObjectManagerJSON contains the JSON metadata for the struct
// [EmploymentDataObjectManager]
type employmentDataObjectManagerJSON struct {
ID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *EmploymentDataObjectManager) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r employmentDataObjectManagerJSON) RawJSON() string {
return r.raw
}
type EmploymentDataObjectCustomField struct {
Name string `json:"name,nullable"`
Value EmploymentDataObjectCustomFieldsValueUnion `json:"value,nullable"`
JSON employmentDataObjectCustomFieldJSON `json:"-"`
}
// employmentDataObjectCustomFieldJSON contains the JSON metadata for the struct
// [EmploymentDataObjectCustomField]
type employmentDataObjectCustomFieldJSON struct {
Name apijson.Field
Value apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *EmploymentDataObjectCustomField) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r employmentDataObjectCustomFieldJSON) RawJSON() string {
return r.raw
}
// Union satisfied by [shared.UnionString],
// [EmploymentDataObjectCustomFieldsValueArray], [shared.UnionFloat] or
// [shared.UnionBool].
type EmploymentDataObjectCustomFieldsValueUnion interface {
ImplementsEmploymentDataObjectCustomFieldsValueUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*EmploymentDataObjectCustomFieldsValueUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(EmploymentDataObjectCustomFieldsValueArray{}),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
apijson.UnionVariant{
TypeFilter: gjson.True,
Type: reflect.TypeOf(shared.UnionBool(false)),
},
apijson.UnionVariant{
TypeFilter: gjson.False,
Type: reflect.TypeOf(shared.UnionBool(false)),
},
)
}
type EmploymentDataObjectCustomFieldsValueArray []interface{}
func (r EmploymentDataObjectCustomFieldsValueArray) ImplementsEmploymentDataObjectCustomFieldsValueUnion() {
}
type EmploymentDataBatchError struct {
Code float64 `json:"code,required"`
Message string `json:"message,required"`
Name string `json:"name,required"`
FinchCode string `json:"finch_code"`
JSON employmentDataBatchErrorJSON `json:"-"`
}
// employmentDataBatchErrorJSON contains the JSON metadata for the struct
// [EmploymentDataBatchError]
type employmentDataBatchErrorJSON struct {
Code apijson.Field
Message apijson.Field
Name apijson.Field
FinchCode apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *EmploymentDataBatchError) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r employmentDataBatchErrorJSON) RawJSON() string {
return r.raw
}
func (r EmploymentDataBatchError) implementsEmploymentData() {}
// The detailed employment status of the individual. Available options: `active`,
// `deceased`, `leave`, `onboarding`, `prehire`, `retired`, `terminated`.
type EmploymentDataEmploymentStatus string
const (
EmploymentDataEmploymentStatusActive EmploymentDataEmploymentStatus = "active"
EmploymentDataEmploymentStatusDeceased EmploymentDataEmploymentStatus = "deceased"
EmploymentDataEmploymentStatusLeave EmploymentDataEmploymentStatus = "leave"
EmploymentDataEmploymentStatusOnboarding EmploymentDataEmploymentStatus = "onboarding"
EmploymentDataEmploymentStatusPrehire EmploymentDataEmploymentStatus = "prehire"
EmploymentDataEmploymentStatusRetired EmploymentDataEmploymentStatus = "retired"
EmploymentDataEmploymentStatusTerminated EmploymentDataEmploymentStatus = "terminated"
)
func (r EmploymentDataEmploymentStatus) IsKnown() bool {
switch r {
case EmploymentDataEmploymentStatusActive, EmploymentDataEmploymentStatusDeceased, EmploymentDataEmploymentStatusLeave, EmploymentDataEmploymentStatusOnboarding, EmploymentDataEmploymentStatusPrehire, EmploymentDataEmploymentStatusRetired, EmploymentDataEmploymentStatusTerminated:
return true
}
return false
}
type EmploymentDataResponse struct {
Body EmploymentData `json:"body,required"`
Code int64 `json:"code,required"`
// A stable Finch `id` (UUID v4) for an individual in the company.
IndividualID string `json:"individual_id,required" format:"uuid"`
JSON employmentDataResponseJSON `json:"-"`
}
// employmentDataResponseJSON contains the JSON metadata for the struct
// [EmploymentDataResponse]
type employmentDataResponseJSON struct {
Body apijson.Field
Code apijson.Field
IndividualID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *EmploymentDataResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r employmentDataResponseJSON) RawJSON() string {
return r.raw
}
type HRISEmploymentGetManyParams struct {
// The array of batch requests.
Requests param.Field[[]HRISEmploymentGetManyParamsRequest] `json:"requests,required"`
}
func (r HRISEmploymentGetManyParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type HRISEmploymentGetManyParamsRequest struct {
// A stable Finch `id` (UUID v4) for an individual in the company. There is no
// limit to the number of `individual_id` to send per request. It is preferantial
// to send all ids in a single request for Finch to optimize provider rate-limits.
IndividualID param.Field[string] `json:"individual_id,required"`
}
func (r HRISEmploymentGetManyParamsRequest) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}