| |
|
|
| package openmeter |
|
|
| import ( |
| "encoding/json" |
| "fmt" |
| "time" |
| ) |
|
|
| |
| |
| type CollectionAlignment string |
|
|
| const ( |
| CollectionAlignmentSubscription CollectionAlignment = "subscription" |
| CollectionAlignmentAnchored CollectionAlignment = "anchored" |
| ) |
|
|
| func (value CollectionAlignment) Valid() bool { |
| switch value { |
| case CollectionAlignmentSubscription, CollectionAlignmentAnchored: |
| return true |
| default: |
| return false |
| } |
| } |
|
|
| |
| type CreateBillingProfileRequest struct { |
| |
| |
| |
| Name string `json:"name"` |
| |
| |
| |
| Description *string `json:"description,omitempty"` |
| Labels *map[string]string `json:"labels,omitempty"` |
| |
| |
| Supplier Party `json:"supplier"` |
| |
| Workflow Workflow `json:"workflow"` |
| |
| Apps ProfileAppReferences `json:"apps"` |
| |
| Default bool `json:"default"` |
| } |
|
|
| |
| type Party struct { |
| |
| ID *string `json:"id,omitempty"` |
| |
| Key *string `json:"key,omitempty"` |
| |
| Name *string `json:"name,omitempty"` |
| |
| |
| TaxID *PartyTaxIdentity `json:"tax_id,omitempty"` |
| |
| Addresses *PartyAddresses `json:"addresses,omitempty"` |
| } |
|
|
| |
| |
| type Profile struct { |
| ID string `json:"id"` |
| |
| |
| |
| Name string `json:"name"` |
| |
| |
| |
| Description *string `json:"description,omitempty"` |
| Labels map[string]string `json:"labels,omitempty"` |
| |
| CreatedAt time.Time `json:"created_at"` |
| |
| UpdatedAt time.Time `json:"updated_at"` |
| |
| DeletedAt *time.Time `json:"deleted_at,omitempty"` |
| |
| |
| Supplier Party `json:"supplier"` |
| |
| Workflow Workflow `json:"workflow"` |
| |
| Apps ProfileAppReferences `json:"apps"` |
| |
| Default bool `json:"default"` |
| } |
|
|
| |
| type ProfileAppReferences struct { |
| |
| Tax AppReference `json:"tax"` |
| |
| Invoicing AppReference `json:"invoicing"` |
| |
| Payment AppReference `json:"payment"` |
| } |
|
|
| |
| type ProfilePagePaginatedResponse struct { |
| Data []Profile `json:"data"` |
| Meta PaginatedMeta `json:"meta"` |
| } |
|
|
| |
| type RecurringPeriod struct { |
| |
| Anchor time.Time `json:"anchor"` |
| |
| Interval string `json:"interval"` |
| } |
|
|
| |
| type UpsertBillingProfileRequest struct { |
| |
| |
| |
| Name string `json:"name"` |
| |
| |
| |
| Description *string `json:"description,omitempty"` |
| Labels *map[string]string `json:"labels,omitempty"` |
| |
| |
| Supplier Party `json:"supplier"` |
| |
| Workflow Workflow `json:"workflow"` |
| |
| Default bool `json:"default"` |
| } |
|
|
| |
| type Workflow struct { |
| |
| Collection *WorkflowCollectionSettings `json:"collection,omitempty"` |
| |
| Invoicing *WorkflowInvoicingSettings `json:"invoicing,omitempty"` |
| |
| Payment *WorkflowPaymentSettings `json:"payment,omitempty"` |
| |
| Tax *WorkflowTaxSettings `json:"tax,omitempty"` |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| type WorkflowCollectionAlignment struct { |
| Type string `json:"type"` |
| raw json.RawMessage |
| } |
|
|
| func (u *WorkflowCollectionAlignment) UnmarshalJSON(data []byte) error { |
| u.raw = append([]byte(nil), data...) |
| if string(data) == "null" { |
| u.Type = "" |
| return nil |
| } |
|
|
| var envelope struct { |
| Value string `json:"type"` |
| } |
| if err := json.Unmarshal(data, &envelope); err != nil { |
| return err |
| } |
| u.Type = envelope.Value |
| return nil |
| } |
|
|
| func (u WorkflowCollectionAlignment) MarshalJSON() ([]byte, error) { |
| if len(u.raw) == 0 { |
| return []byte("null"), nil |
| } |
| return append([]byte(nil), u.raw...), nil |
| } |
|
|
| func (u WorkflowCollectionAlignment) AsWorkflowCollectionAlignmentSubscription() (*WorkflowCollectionAlignmentSubscription, error) { |
| if u.Type != "subscription" { |
| return nil, fmt.Errorf("WorkflowCollectionAlignment: expected type %q, got %q", "subscription", u.Type) |
| } |
| var value WorkflowCollectionAlignmentSubscription |
| if err := json.Unmarshal(u.raw, &value); err != nil { |
| return nil, err |
| } |
| return &value, nil |
| } |
|
|
| func WorkflowCollectionAlignmentFromWorkflowCollectionAlignmentSubscription(value WorkflowCollectionAlignmentSubscription) (WorkflowCollectionAlignment, error) { |
| value.Type = "subscription" |
| raw, err := json.Marshal(value) |
| if err != nil { |
| return WorkflowCollectionAlignment{}, err |
| } |
| var result WorkflowCollectionAlignment |
| if err := result.UnmarshalJSON(raw); err != nil { |
| return WorkflowCollectionAlignment{}, err |
| } |
| return result, nil |
| } |
|
|
| func (u WorkflowCollectionAlignment) AsWorkflowCollectionAlignmentAnchored() (*WorkflowCollectionAlignmentAnchored, error) { |
| if u.Type != "anchored" { |
| return nil, fmt.Errorf("WorkflowCollectionAlignment: expected type %q, got %q", "anchored", u.Type) |
| } |
| var value WorkflowCollectionAlignmentAnchored |
| if err := json.Unmarshal(u.raw, &value); err != nil { |
| return nil, err |
| } |
| return &value, nil |
| } |
|
|
| func WorkflowCollectionAlignmentFromWorkflowCollectionAlignmentAnchored(value WorkflowCollectionAlignmentAnchored) (WorkflowCollectionAlignment, error) { |
| value.Type = "anchored" |
| raw, err := json.Marshal(value) |
| if err != nil { |
| return WorkflowCollectionAlignment{}, err |
| } |
| var result WorkflowCollectionAlignment |
| if err := result.UnmarshalJSON(raw); err != nil { |
| return WorkflowCollectionAlignment{}, err |
| } |
| return result, nil |
| } |
|
|
| |
| |
| type WorkflowCollectionAlignmentAnchored struct { |
| |
| Type CollectionAlignment `json:"type"` |
| |
| RecurringPeriod RecurringPeriod `json:"recurring_period"` |
| } |
|
|
| |
| |
| type WorkflowCollectionAlignmentSubscription struct { |
| |
| Type CollectionAlignment `json:"type"` |
| } |
|
|
| |
| |
| type WorkflowCollectionSettings struct { |
| |
| Alignment *WorkflowCollectionAlignment `json:"alignment,omitempty"` |
| |
| |
| |
| |
| |
| Interval *string `json:"interval,omitempty"` |
| } |
|
|
| |
| type WorkflowInvoicingSettings struct { |
| |
| AutoAdvance *bool `json:"auto_advance,omitempty"` |
| |
| DraftPeriod *string `json:"draft_period,omitempty"` |
| |
| ProgressiveBilling *bool `json:"progressive_billing,omitempty"` |
| |
| SubscriptionEndProrationMode *WorkflowInvoicingSubscriptionEndProrationMode `json:"subscription_end_proration_mode,omitempty"` |
| } |
|
|
| |
| type WorkflowInvoicingSubscriptionEndProrationMode string |
|
|
| const ( |
| WorkflowInvoicingSubscriptionEndProrationModeBillFullPeriod WorkflowInvoicingSubscriptionEndProrationMode = "bill_full_period" |
| WorkflowInvoicingSubscriptionEndProrationModeBillActualPeriod WorkflowInvoicingSubscriptionEndProrationMode = "bill_actual_period" |
| ) |
|
|
| func (value WorkflowInvoicingSubscriptionEndProrationMode) Valid() bool { |
| switch value { |
| case WorkflowInvoicingSubscriptionEndProrationModeBillFullPeriod, WorkflowInvoicingSubscriptionEndProrationModeBillActualPeriod: |
| return true |
| default: |
| return false |
| } |
| } |
|
|
| |
| type WorkflowTaxSettings struct { |
| |
| |
| Enabled *bool `json:"enabled,omitempty"` |
| |
| |
| |
| |
| Enforced *bool `json:"enforced,omitempty"` |
| |
| |
| |
| |
| |
| |
| DefaultTaxConfig *TaxConfig `json:"default_tax_config,omitempty"` |
| } |
|
|