File size: 6,438 Bytes
1477a90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import "@typespec/http";
import "@typespec/openapi";
import "@typespec/openapi3";
import "../shared/index.tsp";
import "../common/error.tsp";
import "../common/pagination.tsp";
import "../common/parameters.tsp";
import "./subscription.tsp";
import "./subscriptionaddon.tsp";

using TypeSpec.Http;
using TypeSpec.OpenAPI;

namespace Subscriptions;

/**
 * Request for canceling a subscription.
 */
@friendlyName("BillingSubscriptionCancel")
model SubscriptionCancel {
  /**
   * If not provided the subscription is canceled immediately.
   */
  timing?: SubscriptionEditTiming = SubscriptionEditTimingEnum.Immediate;
}

/**
 * Request for changing a subscription.
 */
@friendlyName("BillingSubscriptionChange")
model SubscriptionChange {
  ...OmitProperties<SubscriptionCreate, "customer_id" | "customer_key">;

  /**
   * Timing configuration for the change, when the change should take effect. For
   * changing a subscription, the accepted values depend on the subscription
   * configuration.
   */
  timing: SubscriptionEditTiming;
}

/**
 * Response for changing a subscription.
 */
@friendlyName("BillingSubscriptionChangeResponse")
model SubscriptionChangeResponse {
  /**
   * The current subscription before the change.
   */
  current: Subscription;

  /**
   * The new state of the subscription after the change.
   */
  next: Subscription;
}

/**
 * Filter options for listing subscriptions.
 */
#suppress "@openmeter/api-spec-aip/repeated-prefix-grouping" "plan_id and plan_key should not be grouped"
@friendlyName("ListSubscriptionsParamsFilter")
model ListSubscriptionsParamsFilter {
  #suppress "@openmeter/api-spec-aip/doc-decorator" "shared model"
  id?: Common.ULIDFieldFilter;
  #suppress "@openmeter/api-spec-aip/doc-decorator" "shared model"
  customer_id?: Common.ULIDFieldFilter;
  #suppress "@openmeter/api-spec-aip/doc-decorator" "shared model"
  status?: Common.StringFieldFilterExact;
  #suppress "@openmeter/api-spec-aip/doc-decorator" "shared model"
  plan_id?: Common.ULIDFieldFilter;
  #suppress "@openmeter/api-spec-aip/doc-decorator" "shared model"
  plan_key?: Common.StringFieldFilterExact;
}

interface SubscriptionsOperations {
  @post
  @operationId("create-subscription")
  @summary("Create subscription")
  create(@body subscription: SubscriptionCreate):
    | Shared.CreateResponse<Subscription>
    | Common.NotFound
    | Common.Conflict
    | Common.ErrorResponses;

  @get
  @operationId("list-subscriptions")
  @summary("List subscriptions")
  list(
    ...Common.PagePaginationQuery,

    /**
     * Sort subscriptions returned in the response. Supported sort attributes are:
     *
     * - `id`
     * - `active_from` (default)
     * - `active_to`
     *
     * The `asc` suffix is optional as the default sort order is ascending. The `desc`
     * suffix is used to specify a descending order.
     */
    @query(#{ name: "sort" })
    sort?: Common.SortQuery,

    /**
     * Filter subscriptions.
     */
    @query(#{ style: "deepObject", explode: true })
    filter?: ListSubscriptionsParamsFilter,
  ):
    | Shared.PagePaginatedResponse<Subscription>
    | Common.NotFound
    | Common.ErrorResponses;

  @get
  @operationId("get-subscription")
  @summary("Get subscription")
  get(@path subscriptionId: Shared.ULID):
    | Shared.GetResponse<Subscription>
    | Common.NotFound
    | Common.ErrorResponses;

  /**
   * Cancels the subscription. Will result in a scheduling conflict if there are
   * other subscriptions scheduled to start after the cancelation time.
   */
  @post
  @operationId("cancel-subscription")
  @summary("Cancel subscription")
  @route("/{subscriptionId}/cancel")
  cancel(@path subscriptionId: Shared.ULID, @body body: SubscriptionCancel):
    | Shared.UpdateResponse<Subscription>
    | Common.NotFound
    | Common.Conflict
    | Common.ErrorResponses;

  /**
   * Unschedules the subscription cancelation.
   */
  @post
  @operationId("unschedule-cancelation")
  @summary("Unschedule subscription cancelation")
  @route("/{subscriptionId}/unschedule-cancelation")
  unscheduleCancelation(@path subscriptionId: Shared.ULID):
    | Shared.UpdateResponse<Subscription>
    | Common.NotFound
    | Common.Conflict
    | Common.ErrorResponses;

  /**
   * Closes a running subscription and starts a new one according to the
   * specification. Can be used for upgrades, downgrades, and plan changes.
   */
  @post
  @operationId("change-subscription")
  @summary("Change subscription")
  @route("/{subscriptionId}/change")
  change(
    @path subscriptionId: Shared.ULID,

    @body
    body: SubscriptionChange,
  ):
    | SubscriptionChangeResponse
    | Common.NotFound
    | Common.Conflict
    | Common.ErrorResponses;
}

interface SubscriptionAddonOperations {
  /**
   * Add add-on to a subscription.
   */
  @post
  @operationId("create-subscription-addon")
  @summary("Create a new subscription add-on")
  @extension(Shared.UnstableExtension, true)
  @extension(Shared.InternalExtension, true)
  create(
    @path subscriptionId: Shared.ULID,
    @body request: Shared.CreateRequest<SubscriptionAddon>,
  ):
    | Shared.CreateResponse<SubscriptionAddon>
    | Common.ErrorResponses
    | Common.NotFound
    | Common.Conflict;

  /**
   * List the add-ons of a subscription.
   */
  @get
  @operationId("list-subscription-addons")
  @summary("List subscription addons")
  @extension(Shared.UnstableExtension, true)
  list(
    @path subscriptionId: Shared.ULID,
    ...Common.PagePaginationQuery,

    /**
     * Sort subscription addons returned in the response. Supported sort attributes
     * are:
     *
     * - `id`
     * - `created_at` (default)
     * - `updated_at`
     *
     * The `asc` suffix is optional as the default sort order is ascending. The `desc`
     * suffix is used to specify a descending order.
     */
    @query(#{ name: "sort" })
    sort?: Common.SortQuery,
  ):
    | Shared.PagePaginatedResponse<SubscriptionAddon>
    | Common.NotFound
    | Common.ErrorResponses;

  /**
   * Get an add-on association for a subscription.
   */
  @get
  @route("/{subscriptionAddonId}")
  @operationId("get-subscription-addon")
  @summary("Get add-on association for subscription")
  @extension(Shared.UnstableExtension, true)
  getAddon(
    @path subscriptionId: Shared.ULID,
    @path subscriptionAddonId: Shared.ULID,
  ):
    | Shared.GetResponse<SubscriptionAddon>
    | Common.ErrorResponses
    | Common.NotFound;
}