-
Notifications
You must be signed in to change notification settings - Fork 0
/
hrisdocument.go
477 lines (411 loc) · 15.5 KB
/
hrisdocument.go
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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package finchgo
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"reflect"
"github.com/Finch-API/finch-api-go/internal/apijson"
"github.com/Finch-API/finch-api-go/internal/apiquery"
"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/shared"
"github.com/tidwall/gjson"
)
// HRISDocumentService 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 [NewHRISDocumentService] method instead.
type HRISDocumentService struct {
Options []option.RequestOption
}
// NewHRISDocumentService 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 NewHRISDocumentService(opts ...option.RequestOption) (r *HRISDocumentService) {
r = &HRISDocumentService{}
r.Options = opts
return
}
// **Beta:** This endpoint is in beta and may change.
// Retrieve a list of company-wide documents.
func (r *HRISDocumentService) List(ctx context.Context, query HRISDocumentListParams, opts ...option.RequestOption) (res *HRISDocumentListResponse, err error) {
opts = append(r.Options[:], opts...)
path := "employer/documents"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return
}
// **Beta:** This endpoint is in beta and may change.
// Retrieve details of a specific document by its ID.
func (r *HRISDocumentService) Retreive(ctx context.Context, documentID string, opts ...option.RequestOption) (res *HRISDocumentRetreiveResponse, err error) {
opts = append(r.Options[:], opts...)
if documentID == "" {
err = errors.New("missing required document_id parameter")
return
}
path := fmt.Sprintf("employer/documents/%s", documentID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
type DocumentResponse struct {
// A stable Finch id for the document.
ID string `json:"id" format:"uuid"`
// The ID of the individual associated with the document. This will be null for
// employer-level documents.
IndividualID string `json:"individual_id,nullable"`
// The type of document.
Type DocumentResponseType `json:"type"`
// A URL to access the document. Format:
// `https://api.tryfinch.com/employer/documents/:document_id`.
URL string `json:"url" format:"uri"`
// The year the document applies to, if available.
Year float64 `json:"year,nullable"`
JSON documentResponseJSON `json:"-"`
}
// documentResponseJSON contains the JSON metadata for the struct
// [DocumentResponse]
type documentResponseJSON struct {
ID apijson.Field
IndividualID apijson.Field
Type apijson.Field
URL apijson.Field
Year apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DocumentResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r documentResponseJSON) RawJSON() string {
return r.raw
}
// The type of document.
type DocumentResponseType string
const (
DocumentResponseTypeW4_2020 DocumentResponseType = "w4_2020"
DocumentResponseTypeW4_2005 DocumentResponseType = "w4_2005"
)
func (r DocumentResponseType) IsKnown() bool {
switch r {
case DocumentResponseTypeW4_2020, DocumentResponseTypeW4_2005:
return true
}
return false
}
// A 2005 version of the W-4 tax form containing information on an individual's
// filing status, dependents, and withholding details.
type W42005 struct {
// Detailed information specific to the 2005 W4 form.
Data W42005Data `json:"data"`
// Specifies the form type, indicating that this document is a 2005 W4 form.
Type W42005Type `json:"type"`
// The tax year this W4 document applies to.
Year float64 `json:"year,nullable"`
JSON w42005JSON `json:"-"`
}
// w42005JSON contains the JSON metadata for the struct [W42005]
type w42005JSON struct {
Data apijson.Field
Type apijson.Field
Year apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *W42005) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r w42005JSON) RawJSON() string {
return r.raw
}
func (r W42005) implementsHRISDocumentRetreiveResponse() {}
// Detailed information specific to the 2005 W4 form.
type W42005Data struct {
// Additional withholding amount (in cents).
AdditionalWithholding int64 `json:"additional_withholding,nullable"`
// Indicates exemption status from federal tax withholding.
Exemption W42005DataExemption `json:"exemption"`
// The individual's filing status for tax purposes.
FilingStatus W42005DataFilingStatus `json:"filing_status"`
// The unique identifier for the individual associated with this 2005 W4 form.
IndividualID string `json:"individual_id" format:"uuid"`
// Total number of allowances claimed (in cents).
TotalNumberOfAllowances int64 `json:"total_number_of_allowances,nullable"`
JSON w42005DataJSON `json:"-"`
}
// w42005DataJSON contains the JSON metadata for the struct [W42005Data]
type w42005DataJSON struct {
AdditionalWithholding apijson.Field
Exemption apijson.Field
FilingStatus apijson.Field
IndividualID apijson.Field
TotalNumberOfAllowances apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *W42005Data) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r w42005DataJSON) RawJSON() string {
return r.raw
}
// Indicates exemption status from federal tax withholding.
type W42005DataExemption string
const (
W42005DataExemptionExempt W42005DataExemption = "exempt"
W42005DataExemptionNonExempt W42005DataExemption = "non_exempt"
)
func (r W42005DataExemption) IsKnown() bool {
switch r {
case W42005DataExemptionExempt, W42005DataExemptionNonExempt:
return true
}
return false
}
// The individual's filing status for tax purposes.
type W42005DataFilingStatus string
const (
W42005DataFilingStatusMarried W42005DataFilingStatus = "married"
W42005DataFilingStatusMarriedButWithholdAtHigherSingleRate W42005DataFilingStatus = "married_but_withhold_at_higher_single_rate"
W42005DataFilingStatusSingle W42005DataFilingStatus = "single"
)
func (r W42005DataFilingStatus) IsKnown() bool {
switch r {
case W42005DataFilingStatusMarried, W42005DataFilingStatusMarriedButWithholdAtHigherSingleRate, W42005DataFilingStatusSingle:
return true
}
return false
}
// Specifies the form type, indicating that this document is a 2005 W4 form.
type W42005Type string
const (
W42005TypeW4_2005 W42005Type = "w4_2005"
)
func (r W42005Type) IsKnown() bool {
switch r {
case W42005TypeW4_2005:
return true
}
return false
}
// A 2020 version of the W-4 tax form containing information on an individual's
// filing status, dependents, and withholding details.
type W42020 struct {
// Detailed information specific to the 2020 W4 form.
Data W42020Data `json:"data"`
// Specifies the form type, indicating that this document is a 2020 W4 form.
Type W42020Type `json:"type"`
// The tax year this W4 document applies to.
Year float64 `json:"year,nullable"`
JSON w42020JSON `json:"-"`
}
// w42020JSON contains the JSON metadata for the struct [W42020]
type w42020JSON struct {
Data apijson.Field
Type apijson.Field
Year apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *W42020) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r w42020JSON) RawJSON() string {
return r.raw
}
func (r W42020) implementsHRISDocumentRetreiveResponse() {}
// Detailed information specific to the 2020 W4 form.
type W42020Data struct {
// Amount claimed for dependents other than qualifying children under 17 (in
// cents).
AmountForOtherDependents int64 `json:"amount_for_other_dependents,nullable"`
// Amount claimed for dependents under 17 years old (in cents).
AmountForQualifyingChildrenUnder17 int64 `json:"amount_for_qualifying_children_under_17,nullable"`
// Deductible expenses (in cents).
Deductions int64 `json:"deductions,nullable"`
// Additional withholding amount (in cents).
ExtraWithholding int64 `json:"extra_withholding,nullable"`
// The individual's filing status for tax purposes.
FilingStatus W42020DataFilingStatus `json:"filing_status,nullable"`
// The unique identifier for the individual associated with this document.
IndividualID string `json:"individual_id" format:"uuid"`
// Additional income from sources outside of primary employment (in cents).
OtherIncome int64 `json:"other_income,nullable"`
// Total amount claimed for dependents and other credits (in cents).
TotalClaimDependentAndOtherCredits int64 `json:"total_claim_dependent_and_other_credits,nullable"`
JSON w42020DataJSON `json:"-"`
}
// w42020DataJSON contains the JSON metadata for the struct [W42020Data]
type w42020DataJSON struct {
AmountForOtherDependents apijson.Field
AmountForQualifyingChildrenUnder17 apijson.Field
Deductions apijson.Field
ExtraWithholding apijson.Field
FilingStatus apijson.Field
IndividualID apijson.Field
OtherIncome apijson.Field
TotalClaimDependentAndOtherCredits apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *W42020Data) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r w42020DataJSON) RawJSON() string {
return r.raw
}
// The individual's filing status for tax purposes.
type W42020DataFilingStatus string
const (
W42020DataFilingStatusHeadOfHousehold W42020DataFilingStatus = "head_of_household"
W42020DataFilingStatusMarriedFilingJointlyOrQualifyingSurvivingSpouse W42020DataFilingStatus = "married_filing_jointly_or_qualifying_surviving_spouse"
W42020DataFilingStatusSingleOrMarriedFilingSeparately W42020DataFilingStatus = "single_or_married_filing_separately"
)
func (r W42020DataFilingStatus) IsKnown() bool {
switch r {
case W42020DataFilingStatusHeadOfHousehold, W42020DataFilingStatusMarriedFilingJointlyOrQualifyingSurvivingSpouse, W42020DataFilingStatusSingleOrMarriedFilingSeparately:
return true
}
return false
}
// Specifies the form type, indicating that this document is a 2020 W4 form.
type W42020Type string
const (
W42020TypeW4_2020 W42020Type = "w4_2020"
)
func (r W42020Type) IsKnown() bool {
switch r {
case W42020TypeW4_2020:
return true
}
return false
}
type HRISDocumentListResponse struct {
Documents []DocumentResponse `json:"documents,required"`
Paging shared.Paging `json:"paging,required"`
JSON hrisDocumentListResponseJSON `json:"-"`
}
// hrisDocumentListResponseJSON contains the JSON metadata for the struct
// [HRISDocumentListResponse]
type hrisDocumentListResponseJSON struct {
Documents apijson.Field
Paging apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *HRISDocumentListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r hrisDocumentListResponseJSON) RawJSON() string {
return r.raw
}
// A 2020 version of the W-4 tax form containing information on an individual's
// filing status, dependents, and withholding details.
type HRISDocumentRetreiveResponse struct {
// This field can have the runtime type of [W42020Data], [W42005Data].
Data interface{} `json:"data"`
// Specifies the form type, indicating that this document is a 2020 W4 form.
Type HRISDocumentRetreiveResponseType `json:"type"`
// The tax year this W4 document applies to.
Year float64 `json:"year,nullable"`
JSON hrisDocumentRetreiveResponseJSON `json:"-"`
union HRISDocumentRetreiveResponseUnion
}
// hrisDocumentRetreiveResponseJSON contains the JSON metadata for the struct
// [HRISDocumentRetreiveResponse]
type hrisDocumentRetreiveResponseJSON struct {
Data apijson.Field
Type apijson.Field
Year apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r hrisDocumentRetreiveResponseJSON) RawJSON() string {
return r.raw
}
func (r *HRISDocumentRetreiveResponse) UnmarshalJSON(data []byte) (err error) {
*r = HRISDocumentRetreiveResponse{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
// AsUnion returns a [HRISDocumentRetreiveResponseUnion] interface which you can
// cast to the specific types for more type safety.
//
// Possible runtime types of the union are [W42020], [W42005].
func (r HRISDocumentRetreiveResponse) AsUnion() HRISDocumentRetreiveResponseUnion {
return r.union
}
// A 2020 version of the W-4 tax form containing information on an individual's
// filing status, dependents, and withholding details.
//
// Union satisfied by [W42020] or [W42005].
type HRISDocumentRetreiveResponseUnion interface {
implementsHRISDocumentRetreiveResponse()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*HRISDocumentRetreiveResponseUnion)(nil)).Elem(),
"type",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(W42020{}),
DiscriminatorValue: "w4_2020",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(W42005{}),
DiscriminatorValue: "w4_2005",
},
)
}
// Specifies the form type, indicating that this document is a 2020 W4 form.
type HRISDocumentRetreiveResponseType string
const (
HRISDocumentRetreiveResponseTypeW4_2020 HRISDocumentRetreiveResponseType = "w4_2020"
HRISDocumentRetreiveResponseTypeW4_2005 HRISDocumentRetreiveResponseType = "w4_2005"
)
func (r HRISDocumentRetreiveResponseType) IsKnown() bool {
switch r {
case HRISDocumentRetreiveResponseTypeW4_2020, HRISDocumentRetreiveResponseTypeW4_2005:
return true
}
return false
}
type HRISDocumentListParams struct {
// Comma-delimited list of stable Finch uuids for each individual. If empty,
// defaults to all individuals
IndividualIDs param.Field[[]string] `query:"individual_ids"`
// Number of documents to return (defaults to all)
Limit param.Field[int64] `query:"limit"`
// Index to start from (defaults to 0)
Offset param.Field[int64] `query:"offset"`
// Comma-delimited list of document types to filter on. If empty, defaults to all
// types
Types param.Field[[]HRISDocumentListParamsType] `query:"types"`
}
// URLQuery serializes [HRISDocumentListParams]'s query parameters as `url.Values`.
func (r HRISDocumentListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type HRISDocumentListParamsType string
const (
HRISDocumentListParamsTypeW4_2020 HRISDocumentListParamsType = "w4_2020"
HRISDocumentListParamsTypeW4_2005 HRISDocumentListParamsType = "w4_2005"
)
func (r HRISDocumentListParamsType) IsKnown() bool {
switch r {
case HRISDocumentListParamsTypeW4_2020, HRISDocumentListParamsTypeW4_2005:
return true
}
return false
}