From 937e9ce3b03090edd7f1bca7a40c66ec3ab154fd Mon Sep 17 00:00:00 2001 From: SDK Generator Bot Date: Thu, 19 Mar 2026 13:24:24 +0000 Subject: [PATCH] Generate cost --- go.work | 1 + services/cost/LICENSE.md | 201 +++++ services/cost/go.mod | 10 + services/cost/go.sum | 8 + services/cost/oas_commit | 1 + services/cost/package.go | 1 + services/cost/v3api/api_default.go | 708 ++++++++++++++++++ services/cost/v3api/api_default_mock.go | 84 +++ services/cost/v3api/client.go | 658 ++++++++++++++++ services/cost/v3api/configuration.go | 37 + services/cost/v3api/model_default_error.go | 203 +++++ .../cost/v3api/model_detailed_service_cost.go | 385 ++++++++++ services/cost/v3api/model_project_cost.go | 139 ++++ ...del_project_cost_with_detailed_services.go | 322 ++++++++ .../v3api/model_project_cost_with_reports.go | 322 ++++++++ ...l_project_cost_with_summarized_services.go | 322 ++++++++ services/cost/v3api/model_report_data.go | 256 +++++++ .../v3api/model_report_data_time_period.go | 190 +++++ .../v3api/model_summarized_project_cost.go | 284 +++++++ .../v3api/model_summarized_service_cost.go | 284 +++++++ services/cost/v3api/response.go | 47 ++ services/cost/v3api/utils.go | 361 +++++++++ 22 files changed, 4824 insertions(+) create mode 100644 services/cost/LICENSE.md create mode 100644 services/cost/go.mod create mode 100644 services/cost/go.sum create mode 100644 services/cost/oas_commit create mode 100644 services/cost/package.go create mode 100644 services/cost/v3api/api_default.go create mode 100644 services/cost/v3api/api_default_mock.go create mode 100644 services/cost/v3api/client.go create mode 100644 services/cost/v3api/configuration.go create mode 100644 services/cost/v3api/model_default_error.go create mode 100644 services/cost/v3api/model_detailed_service_cost.go create mode 100644 services/cost/v3api/model_project_cost.go create mode 100644 services/cost/v3api/model_project_cost_with_detailed_services.go create mode 100644 services/cost/v3api/model_project_cost_with_reports.go create mode 100644 services/cost/v3api/model_project_cost_with_summarized_services.go create mode 100644 services/cost/v3api/model_report_data.go create mode 100644 services/cost/v3api/model_report_data_time_period.go create mode 100644 services/cost/v3api/model_summarized_project_cost.go create mode 100644 services/cost/v3api/model_summarized_service_cost.go create mode 100644 services/cost/v3api/response.go create mode 100644 services/cost/v3api/utils.go diff --git a/go.work b/go.work index 5dcab61b3..e9ed5afb2 100644 --- a/go.work +++ b/go.work @@ -41,6 +41,7 @@ use ( ./services/authorization ./services/cdn ./services/certificates + ./services/cost ./services/dns ./services/edge ./services/git diff --git a/services/cost/LICENSE.md b/services/cost/LICENSE.md new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/services/cost/LICENSE.md @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/services/cost/go.mod b/services/cost/go.mod new file mode 100644 index 000000000..694b8314a --- /dev/null +++ b/services/cost/go.mod @@ -0,0 +1,10 @@ +module github.com/stackitcloud/stackit-sdk-go/services/cost + +go 1.21 + +require github.com/stackitcloud/stackit-sdk-go/core v0.23.0 + +require ( + github.com/golang-jwt/jwt/v5 v5.3.1 // indirect + github.com/google/uuid v1.6.0 // indirect +) diff --git a/services/cost/go.sum b/services/cost/go.sum new file mode 100644 index 000000000..fd638d0c8 --- /dev/null +++ b/services/cost/go.sum @@ -0,0 +1,8 @@ +github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= +github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/stackitcloud/stackit-sdk-go/core v0.23.0 h1:zPrOhf3Xe47rKRs1fg/AqKYUiJJRYjdcv+3qsS50mEs= +github.com/stackitcloud/stackit-sdk-go/core v0.23.0/go.mod h1:osMglDby4csGZ5sIfhNyYq1bS1TxIdPY88+skE/kkmI= diff --git a/services/cost/oas_commit b/services/cost/oas_commit new file mode 100644 index 000000000..e3544061b --- /dev/null +++ b/services/cost/oas_commit @@ -0,0 +1 @@ +dec116b21147ba0fccd2b4768d8dd83651a29158 diff --git a/services/cost/package.go b/services/cost/package.go new file mode 100644 index 000000000..950e6a941 --- /dev/null +++ b/services/cost/package.go @@ -0,0 +1 @@ +package cost diff --git a/services/cost/v3api/api_default.go b/services/cost/v3api/api_default.go new file mode 100644 index 000000000..fa898d1c5 --- /dev/null +++ b/services/cost/v3api/api_default.go @@ -0,0 +1,708 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. +package v3api + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" + + "github.com/stackitcloud/stackit-sdk-go/core/config" + "github.com/stackitcloud/stackit-sdk-go/core/oapierror" +) + +type DefaultAPI interface { + + /* + GetCostsForProject V3 Costs for a certain project + + Get costs for a certain project in a customer account + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param customerAccountId ID of a customer account + @param projectId ID of a project + @return ApiGetCostsForProjectRequest + */ + GetCostsForProject(ctx context.Context, customerAccountId string, projectId string) ApiGetCostsForProjectRequest + + // GetCostsForProjectExecute executes the request + // @return ProjectCost + GetCostsForProjectExecute(r ApiGetCostsForProjectRequest) (*ProjectCost, error) + + /* + ListCostsForCustomer V3 Costs for all projects + + Get costs for all projects in a customer account + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param customerAccountId ID of a customer account + @return ApiListCostsForCustomerRequest + */ + ListCostsForCustomer(ctx context.Context, customerAccountId string) ApiListCostsForCustomerRequest + + // ListCostsForCustomerExecute executes the request + // @return []ProjectCost + ListCostsForCustomerExecute(r ApiListCostsForCustomerRequest) ([]ProjectCost, error) + + /* + ListCostsForReseller V3 Costs for all projects of all related sub-customers + + Get costs for all projects of all related sub-customer accounts + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param customerAccountId ID of a customer account + @return ApiListCostsForResellerRequest + */ + ListCostsForReseller(ctx context.Context, customerAccountId string) ApiListCostsForResellerRequest + + // ListCostsForResellerExecute executes the request + // @return []ProjectCost + ListCostsForResellerExecute(r ApiListCostsForResellerRequest) ([]ProjectCost, error) +} + +// DefaultAPIService DefaultAPI service +type DefaultAPIService service + +type ApiGetCostsForProjectRequest struct { + ctx context.Context + ApiService DefaultAPI + customerAccountId string + projectId string + from *string + to *string + depth *string + granularity *string + includeZeroCosts *bool + accept *string +} + +// Inclusive start date of the selection range. Internally, usages are recorded in UTC. This means all usages starting on and after 00:00:00 UTC on the specified date are included. +func (r ApiGetCostsForProjectRequest) From(from string) ApiGetCostsForProjectRequest { + r.from = &from + return r +} + +// Inclusive end date of the selection range. Internally, usages are recorded in UTC. This means all usages starting up to and including 23:59:59 UTC on the specified date are included. +func (r ApiGetCostsForProjectRequest) To(to string) ApiGetCostsForProjectRequest { + r.to = &to + return r +} + +// Depth of desired cost information. \"project\" provides costs grouped by project, without services. \"service\" provides costs separated on service level. +func (r ApiGetCostsForProjectRequest) Depth(depth string) ApiGetCostsForProjectRequest { + r.depth = &depth + return r +} + +// Define granularity of costs – Default is \"none\" which does NOT include detailed report data. If \"monthly\", \"weekly\" or \"yearly\" is requested, the \"from\" parameter SHOULD be the first day and the \"to\" parameter SHOULD be the last day of that time period. If not, they are normalized accordingly. If \"daily\" is requested, the date range defined by \"from\" and \"to\" MUST NOT be longer than 92 days. +func (r ApiGetCostsForProjectRequest) Granularity(granularity string) ApiGetCostsForProjectRequest { + r.granularity = &granularity + return r +} + +// Whether costs of 0 should be included in the response +func (r ApiGetCostsForProjectRequest) IncludeZeroCosts(includeZeroCosts bool) ApiGetCostsForProjectRequest { + r.includeZeroCosts = &includeZeroCosts + return r +} + +// Desired content type +func (r ApiGetCostsForProjectRequest) Accept(accept string) ApiGetCostsForProjectRequest { + r.accept = &accept + return r +} + +func (r ApiGetCostsForProjectRequest) Execute() (*ProjectCost, error) { + return r.ApiService.GetCostsForProjectExecute(r) +} + +/* +GetCostsForProject V3 Costs for a certain project + +Get costs for a certain project in a customer account + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param customerAccountId ID of a customer account + @param projectId ID of a project + @return ApiGetCostsForProjectRequest +*/ +func (a *DefaultAPIService) GetCostsForProject(ctx context.Context, customerAccountId string, projectId string) ApiGetCostsForProjectRequest { + return ApiGetCostsForProjectRequest{ + ApiService: a, + ctx: ctx, + customerAccountId: customerAccountId, + projectId: projectId, + } +} + +// Execute executes the request +// +// @return ProjectCost +func (a *DefaultAPIService) GetCostsForProjectExecute(r ApiGetCostsForProjectRequest) (*ProjectCost, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ProjectCost + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.GetCostsForProject") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v3/costs/{customerAccountId}/projects/{projectId}" + localVarPath = strings.Replace(localVarPath, "{"+"customerAccountId"+"}", url.PathEscape(parameterValueToString(r.customerAccountId, "customerAccountId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(parameterValueToString(r.projectId, "projectId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.from == nil { + return localVarReturnValue, reportError("from is required and must be specified") + } + if r.to == nil { + return localVarReturnValue, reportError("to is required and must be specified") + } + + parameterAddToHeaderOrQuery(localVarQueryParams, "from", r.from, "form", "") + parameterAddToHeaderOrQuery(localVarQueryParams, "to", r.to, "form", "") + if r.depth != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "depth", r.depth, "form", "") + } else { + var defaultValue string = "auto" + parameterAddToHeaderOrQuery(localVarQueryParams, "depth", defaultValue, "form", "") + r.depth = &defaultValue + } + if r.granularity != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "granularity", r.granularity, "form", "") + } else { + var defaultValue string = "none" + parameterAddToHeaderOrQuery(localVarQueryParams, "granularity", defaultValue, "form", "") + r.granularity = &defaultValue + } + if r.includeZeroCosts != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "includeZeroCosts", r.includeZeroCosts, "form", "") + } else { + var defaultValue bool = false + parameterAddToHeaderOrQuery(localVarQueryParams, "includeZeroCosts", defaultValue, "form", "") + r.includeZeroCosts = &defaultValue + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json", "text/csv"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.accept != nil { + parameterAddToHeaderOrQuery(localVarHeaderParams, "Accept", r.accept, "simple", "") + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, err + } + + contextHTTPRequest, ok := r.ctx.Value(config.ContextHTTPRequest).(**http.Request) + if ok { + *contextHTTPRequest = req + } + + localVarHTTPResponse, err := a.client.callAPI(req) + contextHTTPResponse, ok := r.ctx.Value(config.ContextHTTPResponse).(**http.Response) + if ok { + *contextHTTPResponse = localVarHTTPResponse + } + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &oapierror.GenericOpenAPIError{ + Body: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + StatusCode: localVarHTTPResponse.StatusCode, + } + if localVarHTTPResponse.StatusCode == 401 { + var v map[string]interface{} + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + return localVarReturnValue, newErr + } + var v DefaultError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + return localVarReturnValue, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &oapierror.GenericOpenAPIError{ + StatusCode: localVarHTTPResponse.StatusCode, + Body: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, newErr + } + + return localVarReturnValue, nil +} + +type ApiListCostsForCustomerRequest struct { + ctx context.Context + ApiService DefaultAPI + customerAccountId string + from *string + to *string + depth *string + granularity *string + includeZeroCosts *bool + accept *string +} + +// Inclusive start date of the selection range. Internally, usages are recorded in UTC. This means all usages starting on and after 00:00:00 UTC on the specified date are included. +func (r ApiListCostsForCustomerRequest) From(from string) ApiListCostsForCustomerRequest { + r.from = &from + return r +} + +// Inclusive end date of the selection range. Internally, usages are recorded in UTC. This means all usages starting up to and including 23:59:59 UTC on the specified date are included. +func (r ApiListCostsForCustomerRequest) To(to string) ApiListCostsForCustomerRequest { + r.to = &to + return r +} + +// Depth of desired cost information. \"project\" provides costs grouped by project, without services. \"service\" provides costs separated on service level. +func (r ApiListCostsForCustomerRequest) Depth(depth string) ApiListCostsForCustomerRequest { + r.depth = &depth + return r +} + +// Define granularity of costs – Default is \"none\" which does NOT include detailed report data. If \"monthly\", \"weekly\" or \"yearly\" is requested, the \"from\" parameter SHOULD be the first day and the \"to\" parameter SHOULD be the last day of that time period. If not, they are normalized accordingly. If \"daily\" is requested, the date range defined by \"from\" and \"to\" MUST NOT be longer than 92 days. +func (r ApiListCostsForCustomerRequest) Granularity(granularity string) ApiListCostsForCustomerRequest { + r.granularity = &granularity + return r +} + +// Whether costs of 0 should be included in the response +func (r ApiListCostsForCustomerRequest) IncludeZeroCosts(includeZeroCosts bool) ApiListCostsForCustomerRequest { + r.includeZeroCosts = &includeZeroCosts + return r +} + +// Desired content type +func (r ApiListCostsForCustomerRequest) Accept(accept string) ApiListCostsForCustomerRequest { + r.accept = &accept + return r +} + +func (r ApiListCostsForCustomerRequest) Execute() ([]ProjectCost, error) { + return r.ApiService.ListCostsForCustomerExecute(r) +} + +/* +ListCostsForCustomer V3 Costs for all projects + +Get costs for all projects in a customer account + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param customerAccountId ID of a customer account + @return ApiListCostsForCustomerRequest +*/ +func (a *DefaultAPIService) ListCostsForCustomer(ctx context.Context, customerAccountId string) ApiListCostsForCustomerRequest { + return ApiListCostsForCustomerRequest{ + ApiService: a, + ctx: ctx, + customerAccountId: customerAccountId, + } +} + +// Execute executes the request +// +// @return []ProjectCost +func (a *DefaultAPIService) ListCostsForCustomerExecute(r ApiListCostsForCustomerRequest) ([]ProjectCost, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue []ProjectCost + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.ListCostsForCustomer") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v3/costs/{customerAccountId}" + localVarPath = strings.Replace(localVarPath, "{"+"customerAccountId"+"}", url.PathEscape(parameterValueToString(r.customerAccountId, "customerAccountId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.from == nil { + return localVarReturnValue, reportError("from is required and must be specified") + } + if r.to == nil { + return localVarReturnValue, reportError("to is required and must be specified") + } + + parameterAddToHeaderOrQuery(localVarQueryParams, "from", r.from, "form", "") + parameterAddToHeaderOrQuery(localVarQueryParams, "to", r.to, "form", "") + if r.depth != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "depth", r.depth, "form", "") + } else { + var defaultValue string = "auto" + parameterAddToHeaderOrQuery(localVarQueryParams, "depth", defaultValue, "form", "") + r.depth = &defaultValue + } + if r.granularity != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "granularity", r.granularity, "form", "") + } else { + var defaultValue string = "none" + parameterAddToHeaderOrQuery(localVarQueryParams, "granularity", defaultValue, "form", "") + r.granularity = &defaultValue + } + if r.includeZeroCosts != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "includeZeroCosts", r.includeZeroCosts, "form", "") + } else { + var defaultValue bool = false + parameterAddToHeaderOrQuery(localVarQueryParams, "includeZeroCosts", defaultValue, "form", "") + r.includeZeroCosts = &defaultValue + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json", "text/csv"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.accept != nil { + parameterAddToHeaderOrQuery(localVarHeaderParams, "Accept", r.accept, "simple", "") + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, err + } + + contextHTTPRequest, ok := r.ctx.Value(config.ContextHTTPRequest).(**http.Request) + if ok { + *contextHTTPRequest = req + } + + localVarHTTPResponse, err := a.client.callAPI(req) + contextHTTPResponse, ok := r.ctx.Value(config.ContextHTTPResponse).(**http.Response) + if ok { + *contextHTTPResponse = localVarHTTPResponse + } + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &oapierror.GenericOpenAPIError{ + Body: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + StatusCode: localVarHTTPResponse.StatusCode, + } + if localVarHTTPResponse.StatusCode == 401 { + var v map[string]interface{} + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + return localVarReturnValue, newErr + } + var v DefaultError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + return localVarReturnValue, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &oapierror.GenericOpenAPIError{ + StatusCode: localVarHTTPResponse.StatusCode, + Body: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, newErr + } + + return localVarReturnValue, nil +} + +type ApiListCostsForResellerRequest struct { + ctx context.Context + ApiService DefaultAPI + customerAccountId string + from *string + to *string + depth *string + granularity *string + includeZeroCosts *bool + accept *string +} + +// Inclusive start date of the selection range. Internally, usages are recorded in UTC. This means all usages starting on and after 00:00:00 UTC on the specified date are included. +func (r ApiListCostsForResellerRequest) From(from string) ApiListCostsForResellerRequest { + r.from = &from + return r +} + +// Inclusive end date of the selection range. Internally, usages are recorded in UTC. This means all usages starting up to and including 23:59:59 UTC on the specified date are included. +func (r ApiListCostsForResellerRequest) To(to string) ApiListCostsForResellerRequest { + r.to = &to + return r +} + +// Depth of desired cost information. \"project\" provides costs grouped by project, without services. \"service\" provides costs separated on service level. +func (r ApiListCostsForResellerRequest) Depth(depth string) ApiListCostsForResellerRequest { + r.depth = &depth + return r +} + +// Define granularity of costs – Default is \"none\" which does NOT include detailed report data. If \"monthly\", \"weekly\" or \"yearly\" is requested, the \"from\" parameter SHOULD be the first day and the \"to\" parameter SHOULD be the last day of that time period. If not, they are normalized accordingly. If \"daily\" is requested, the date range defined by \"from\" and \"to\" MUST NOT be longer than 92 days. +func (r ApiListCostsForResellerRequest) Granularity(granularity string) ApiListCostsForResellerRequest { + r.granularity = &granularity + return r +} + +// Whether costs of 0 should be included in the response +func (r ApiListCostsForResellerRequest) IncludeZeroCosts(includeZeroCosts bool) ApiListCostsForResellerRequest { + r.includeZeroCosts = &includeZeroCosts + return r +} + +// Desired content type +func (r ApiListCostsForResellerRequest) Accept(accept string) ApiListCostsForResellerRequest { + r.accept = &accept + return r +} + +func (r ApiListCostsForResellerRequest) Execute() ([]ProjectCost, error) { + return r.ApiService.ListCostsForResellerExecute(r) +} + +/* +ListCostsForReseller V3 Costs for all projects of all related sub-customers + +Get costs for all projects of all related sub-customer accounts + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param customerAccountId ID of a customer account + @return ApiListCostsForResellerRequest +*/ +func (a *DefaultAPIService) ListCostsForReseller(ctx context.Context, customerAccountId string) ApiListCostsForResellerRequest { + return ApiListCostsForResellerRequest{ + ApiService: a, + ctx: ctx, + customerAccountId: customerAccountId, + } +} + +// Execute executes the request +// +// @return []ProjectCost +func (a *DefaultAPIService) ListCostsForResellerExecute(r ApiListCostsForResellerRequest) ([]ProjectCost, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue []ProjectCost + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.ListCostsForReseller") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v3/costs/{customerAccountId}/customers" + localVarPath = strings.Replace(localVarPath, "{"+"customerAccountId"+"}", url.PathEscape(parameterValueToString(r.customerAccountId, "customerAccountId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.from == nil { + return localVarReturnValue, reportError("from is required and must be specified") + } + if r.to == nil { + return localVarReturnValue, reportError("to is required and must be specified") + } + + parameterAddToHeaderOrQuery(localVarQueryParams, "from", r.from, "form", "") + parameterAddToHeaderOrQuery(localVarQueryParams, "to", r.to, "form", "") + if r.depth != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "depth", r.depth, "form", "") + } else { + var defaultValue string = "auto" + parameterAddToHeaderOrQuery(localVarQueryParams, "depth", defaultValue, "form", "") + r.depth = &defaultValue + } + if r.granularity != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "granularity", r.granularity, "form", "") + } else { + var defaultValue string = "none" + parameterAddToHeaderOrQuery(localVarQueryParams, "granularity", defaultValue, "form", "") + r.granularity = &defaultValue + } + if r.includeZeroCosts != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "includeZeroCosts", r.includeZeroCosts, "form", "") + } else { + var defaultValue bool = false + parameterAddToHeaderOrQuery(localVarQueryParams, "includeZeroCosts", defaultValue, "form", "") + r.includeZeroCosts = &defaultValue + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json", "text/csv"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + if r.accept != nil { + parameterAddToHeaderOrQuery(localVarHeaderParams, "Accept", r.accept, "simple", "") + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, err + } + + contextHTTPRequest, ok := r.ctx.Value(config.ContextHTTPRequest).(**http.Request) + if ok { + *contextHTTPRequest = req + } + + localVarHTTPResponse, err := a.client.callAPI(req) + contextHTTPResponse, ok := r.ctx.Value(config.ContextHTTPResponse).(**http.Response) + if ok { + *contextHTTPResponse = localVarHTTPResponse + } + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &oapierror.GenericOpenAPIError{ + Body: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + StatusCode: localVarHTTPResponse.StatusCode, + } + if localVarHTTPResponse.StatusCode == 401 { + var v map[string]interface{} + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + return localVarReturnValue, newErr + } + var v DefaultError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + return localVarReturnValue, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &oapierror.GenericOpenAPIError{ + StatusCode: localVarHTTPResponse.StatusCode, + Body: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, newErr + } + + return localVarReturnValue, nil +} diff --git a/services/cost/v3api/api_default_mock.go b/services/cost/v3api/api_default_mock.go new file mode 100644 index 000000000..f851f067d --- /dev/null +++ b/services/cost/v3api/api_default_mock.go @@ -0,0 +1,84 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "context" +) + +// assert the implementation matches the interface +var _ DefaultAPI = &DefaultAPIServiceMock{} + +// DefaultAPIServiceMock is meant to be used for testing only as a replacement for DefaultAPIService. +// By default all FooExecute() implementations are a no-op. Behavior of the mock can be customized by populating the callbacks in this struct. +type DefaultAPIServiceMock struct { + // GetCostsForProjectExecuteMock can be populated to implement the behavior of the GetCostsForProjectExecute function of this mock + GetCostsForProjectExecuteMock *func(r ApiGetCostsForProjectRequest) (*ProjectCost, error) + // ListCostsForCustomerExecuteMock can be populated to implement the behavior of the ListCostsForCustomerExecute function of this mock + ListCostsForCustomerExecuteMock *func(r ApiListCostsForCustomerRequest) ([]ProjectCost, error) + // ListCostsForResellerExecuteMock can be populated to implement the behavior of the ListCostsForResellerExecute function of this mock + ListCostsForResellerExecuteMock *func(r ApiListCostsForResellerRequest) ([]ProjectCost, error) +} + +func (a DefaultAPIServiceMock) GetCostsForProject(ctx context.Context, customerAccountId string, projectId string) ApiGetCostsForProjectRequest { + return ApiGetCostsForProjectRequest{ + ApiService: a, + ctx: ctx, + customerAccountId: customerAccountId, + projectId: projectId, + } +} + +// GetCostsForProjectExecute is a no-op by default and will return only return nil values. Behavior can be controlled by populating the GetCostsForProjectExecuteMock field in the DefaultAPIServiceMock struct. +func (a DefaultAPIServiceMock) GetCostsForProjectExecute(r ApiGetCostsForProjectRequest) (*ProjectCost, error) { + if a.GetCostsForProjectExecuteMock == nil { + var localVarReturnValue *ProjectCost + return localVarReturnValue, nil + } + + return (*a.GetCostsForProjectExecuteMock)(r) +} + +func (a DefaultAPIServiceMock) ListCostsForCustomer(ctx context.Context, customerAccountId string) ApiListCostsForCustomerRequest { + return ApiListCostsForCustomerRequest{ + ApiService: a, + ctx: ctx, + customerAccountId: customerAccountId, + } +} + +// ListCostsForCustomerExecute is a no-op by default and will return only return nil values. Behavior can be controlled by populating the ListCostsForCustomerExecuteMock field in the DefaultAPIServiceMock struct. +func (a DefaultAPIServiceMock) ListCostsForCustomerExecute(r ApiListCostsForCustomerRequest) ([]ProjectCost, error) { + if a.ListCostsForCustomerExecuteMock == nil { + var localVarReturnValue []ProjectCost + return localVarReturnValue, nil + } + + return (*a.ListCostsForCustomerExecuteMock)(r) +} + +func (a DefaultAPIServiceMock) ListCostsForReseller(ctx context.Context, customerAccountId string) ApiListCostsForResellerRequest { + return ApiListCostsForResellerRequest{ + ApiService: a, + ctx: ctx, + customerAccountId: customerAccountId, + } +} + +// ListCostsForResellerExecute is a no-op by default and will return only return nil values. Behavior can be controlled by populating the ListCostsForResellerExecuteMock field in the DefaultAPIServiceMock struct. +func (a DefaultAPIServiceMock) ListCostsForResellerExecute(r ApiListCostsForResellerRequest) ([]ProjectCost, error) { + if a.ListCostsForResellerExecuteMock == nil { + var localVarReturnValue []ProjectCost + return localVarReturnValue, nil + } + + return (*a.ListCostsForResellerExecuteMock)(r) +} diff --git a/services/cost/v3api/client.go b/services/cost/v3api/client.go new file mode 100644 index 000000000..138cc8e45 --- /dev/null +++ b/services/cost/v3api/client.go @@ -0,0 +1,658 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. +package v3api + +import ( + "bytes" + "context" + "encoding/json" + "encoding/xml" + "errors" + "fmt" + "io" + "log" + "mime/multipart" + "net/http" + "net/http/httputil" + "net/url" + "os" + "path/filepath" + "reflect" + "regexp" + "strconv" + "strings" + "time" + "unicode/utf8" + + "github.com/stackitcloud/stackit-sdk-go/core/auth" + "github.com/stackitcloud/stackit-sdk-go/core/config" +) + +var ( + JsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?json)`) + XmlCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?xml)`) + queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) + queryDescape = strings.NewReplacer("%5B", "[", "%5D", "]") +) + +// APIClient manages communication with the STACKIT Cost API API v3.0 +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *config.Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + + // API Services + + DefaultAPI DefaultAPI +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. Requires a userAgent string describing your application. +// optionally a custom http.Client to allow for advanced features such as caching. +func NewAPIClient(opts ...config.ConfigurationOption) (*APIClient, error) { + cfg := NewConfiguration() + + for _, option := range opts { + err := option(cfg) + if err != nil { + return nil, fmt.Errorf("configuring the client: %w", err) + } + } + + err := config.ConfigureRegion(cfg) + if err != nil { + return nil, fmt.Errorf("configuring region: %w", err) + } + + if cfg.HTTPClient == nil { + cfg.HTTPClient = &http.Client{} + } + + authRoundTripper, err := auth.SetupAuth(cfg) + if err != nil { + return nil, fmt.Errorf("setting up authentication: %w", err) + } + + roundTripper := authRoundTripper + if cfg.Middleware != nil { + roundTripper = config.ChainMiddleware(roundTripper, cfg.Middleware...) + } + + cfg.HTTPClient.Transport = roundTripper + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + + // API Services + c.DefaultAPI = (*DefaultAPIService)(&c.common) + + return c, nil +} + +func atoi(in string) (int, error) { + return strconv.Atoi(in) +} + +// selectHeaderContentType select a content type from the available list. +func selectHeaderContentType(contentTypes []string) string { + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +// selectHeaderAccept join all accept types and return +func selectHeaderAccept(accepts []string) string { + if len(accepts) == 0 { + return "" + } + + if contains(accepts, "application/json") { + return "application/json" + } + + return strings.Join(accepts, ",") +} + +// contains is a case insensitive match, finding needle in a haystack +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.EqualFold(a, needle) { + return true + } + } + return false +} + +// Verify optional parameters are of the correct type. +func typeCheckParameter(obj interface{}, expected string, name string) error { + // Make sure there is an object. + if obj == nil { + return nil + } + + // Check the type is as expected. + if reflect.TypeOf(obj).String() != expected { + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) + } + return nil +} + +func parameterValueToString(obj interface{}, key string) string { + if reflect.TypeOf(obj).Kind() != reflect.Ptr { + if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok { + return fmt.Sprintf("%v", actualObj.GetActualInstanceValue()) + } + + return fmt.Sprintf("%v", obj) + } + var param, ok = obj.(MappedNullable) + if !ok { + return "" + } + dataMap, err := param.ToMap() + if err != nil { + return "" + } + return fmt.Sprintf("%v", dataMap[key]) +} + +// parameterAddToHeaderOrQuery adds the provided object to the request header or url query +// supporting deep object syntax +func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, style string, collectionType string) { + var v = reflect.ValueOf(obj) + var value = "" + if v == reflect.ValueOf(nil) { + value = "null" + } else { + switch v.Kind() { + case reflect.Invalid: + value = "invalid" + + case reflect.Struct: + if t, ok := obj.(MappedNullable); ok { + dataMap, err := t.ToMap() + if err != nil { + return + } + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, style, collectionType) + return + } + if t, ok := obj.(time.Time); ok { + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339Nano), style, collectionType) + return + } + value = v.Type().String() + " value" + case reflect.Slice: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + var lenIndValue = indValue.Len() + for i := 0; i < lenIndValue; i++ { + var arrayValue = indValue.Index(i) + var keyPrefixForCollectionType = keyPrefix + if style == "deepObject" { + keyPrefixForCollectionType = keyPrefix + "[" + strconv.Itoa(i) + "]" + } + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefixForCollectionType, arrayValue.Interface(), style, collectionType) + } + return + + case reflect.Map: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + iter := indValue.MapRange() + for iter.Next() { + k, v := iter.Key(), iter.Value() + parameterAddToHeaderOrQuery(headerOrQueryParams, fmt.Sprintf("%s[%s]", keyPrefix, k.String()), v.Interface(), style, collectionType) + } + return + + case reflect.Interface: + fallthrough + case reflect.Ptr: + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, v.Elem().Interface(), style, collectionType) + return + + case reflect.Int, reflect.Int8, reflect.Int16, + reflect.Int32, reflect.Int64: + value = strconv.FormatInt(v.Int(), 10) + case reflect.Uint, reflect.Uint8, reflect.Uint16, + reflect.Uint32, reflect.Uint64, reflect.Uintptr: + value = strconv.FormatUint(v.Uint(), 10) + case reflect.Float32, reflect.Float64: + value = strconv.FormatFloat(v.Float(), 'g', -1, 32) + case reflect.Bool: + value = strconv.FormatBool(v.Bool()) + case reflect.String: + value = v.String() + default: + value = v.Type().String() + " value" + } + } + + switch valuesMap := headerOrQueryParams.(type) { + case url.Values: + if collectionType == "csv" && valuesMap.Get(keyPrefix) != "" { + valuesMap.Set(keyPrefix, valuesMap.Get(keyPrefix)+","+value) + } else { + valuesMap.Add(keyPrefix, value) + } + break + case map[string]string: + valuesMap[keyPrefix] = value + break + } +} + +// helper for converting interface{} parameters to json strings +func parameterToJson(obj interface{}) (string, error) { + jsonBuf, err := json.Marshal(obj) + if err != nil { + return "", err + } + return string(jsonBuf), err +} + +// callAPI do the request. +func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { + if c.cfg.Debug { + dump, err := httputil.DumpRequestOut(request, true) + if err != nil { + return nil, err + } + log.Printf("\n%s\n", string(dump)) + } + + resp, err := c.cfg.HTTPClient.Do(request) + if err != nil { + return resp, err + } + + if c.cfg.Debug { + dump, err := httputil.DumpResponse(resp, true) + if err != nil { + return resp, err + } + log.Printf("\n%s\n", string(dump)) + } + return resp, err +} + +// Allow modification of underlying config for alternate implementations and testing +// Caution: modifying the configuration while live can cause data races and potentially unwanted behavior +func (c *APIClient) GetConfig() *config.Configuration { + return c.cfg +} + +type formFile struct { + fileBytes []byte + fileName string + formFileName string +} + +// prepareRequest build the request +func (c *APIClient) prepareRequest( + ctx context.Context, + path string, method string, + postBody interface{}, + headerParams map[string]string, + queryParams url.Values, + formParams url.Values, + formFiles []formFile) (localVarRequest *http.Request, err error) { + + var body *bytes.Buffer + + // Detect postBody type and post. + if postBody != nil { + contentType := headerParams["Content-Type"] + if contentType == "" { + contentType = detectContentType(postBody) + headerParams["Content-Type"] = contentType + } + + body, err = setBody(postBody, contentType) + if err != nil { + return nil, err + } + } + + // add form parameters and file if available. + if strings.HasPrefix(headerParams["Content-Type"], "multipart/form-data") && len(formParams) > 0 || (len(formFiles) > 0) { + if body != nil { + return nil, errors.New("Cannot specify postBody and multipart form at the same time.") + } + body = &bytes.Buffer{} + w := multipart.NewWriter(body) + + for k, v := range formParams { + for _, iv := range v { + if strings.HasPrefix(k, "@") { // file + err = addFile(w, k[1:], iv) + if err != nil { + return nil, err + } + } else { // form value + w.WriteField(k, iv) + } + } + } + for _, formFile := range formFiles { + if len(formFile.fileBytes) > 0 && formFile.fileName != "" { + w.Boundary() + part, err := w.CreateFormFile(formFile.formFileName, filepath.Base(formFile.fileName)) + if err != nil { + return nil, err + } + _, err = part.Write(formFile.fileBytes) + if err != nil { + return nil, err + } + } + } + + // Set the Boundary in the Content-Type + headerParams["Content-Type"] = w.FormDataContentType() + + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + w.Close() + } + + if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 { + if body != nil { + return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.") + } + body = &bytes.Buffer{} + body.WriteString(formParams.Encode()) + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + } + + // Setup path and query parameters + url, err := url.Parse(path) + if err != nil { + return nil, err + } + + // Override request host, if applicable + if c.cfg.Host != "" { + url.Host = c.cfg.Host + } + + // Override request scheme, if applicable + if c.cfg.Scheme != "" { + url.Scheme = c.cfg.Scheme + } + + // Adding Query Param + query := url.Query() + for k, v := range queryParams { + for _, iv := range v { + query.Add(k, iv) + } + } + + // Encode the parameters. + url.RawQuery = queryParamSplit.ReplaceAllStringFunc(query.Encode(), func(s string) string { + pieces := strings.Split(s, "=") + pieces[0] = queryDescape.Replace(pieces[0]) + return strings.Join(pieces, "=") + }) + + // Generate a new request + if body != nil { + localVarRequest, err = http.NewRequest(method, url.String(), body) + } else { + localVarRequest, err = http.NewRequest(method, url.String(), nil) + } + if err != nil { + return nil, err + } + + // add header parameters, if any + if len(headerParams) > 0 { + headers := http.Header{} + for h, v := range headerParams { + headers[h] = []string{v} + } + localVarRequest.Header = headers + } + + // Add the user agent to the request. + localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) + + if ctx != nil { + // add context to the request + localVarRequest = localVarRequest.WithContext(ctx) + + // Walk through any authentication. + + } + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + return localVarRequest, nil +} + +func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } + if s, ok := v.(*string); ok { + *s = string(b) + return nil + } + if f, ok := v.(*os.File); ok { + f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = f.Write(b) + if err != nil { + return + } + _, err = f.Seek(0, io.SeekStart) + return + } + if f, ok := v.(**os.File); ok { + *f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = (*f).Write(b) + if err != nil { + return + } + _, err = (*f).Seek(0, io.SeekStart) + return + } + if XmlCheck.MatchString(contentType) { + if err = xml.Unmarshal(b, v); err != nil { + return err + } + return nil + } + if JsonCheck.MatchString(contentType) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { // simple model + return err + } + return nil + } + return errors.New("undefined response type") +} + +// Add a file to the multipart request +func addFile(w *multipart.Writer, fieldName, path string) error { + file, err := os.Open(filepath.Clean(path)) + if err != nil { + return err + } + defer file.Close() + + part, err := w.CreateFormFile(fieldName, filepath.Base(path)) + if err != nil { + return err + } + _, err = io.Copy(part, file) + + return err +} + +// Set request body from an interface{} +func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { + if bodyBuf == nil { + bodyBuf = &bytes.Buffer{} + } + + if reader, ok := body.(io.Reader); ok { + _, err = bodyBuf.ReadFrom(reader) + } else if fp, ok := body.(*os.File); ok { + _, err = bodyBuf.ReadFrom(fp) + } else if b, ok := body.([]byte); ok { + _, err = bodyBuf.Write(b) + } else if s, ok := body.(string); ok { + _, err = bodyBuf.WriteString(s) + } else if s, ok := body.(*string); ok { + _, err = bodyBuf.WriteString(*s) + } else if JsonCheck.MatchString(contentType) { + err = json.NewEncoder(bodyBuf).Encode(body) + } else if XmlCheck.MatchString(contentType) { + var bs []byte + bs, err = xml.Marshal(body) + if err == nil { + bodyBuf.Write(bs) + } + } + + if err != nil { + return nil, err + } + + if bodyBuf.Len() == 0 { + err = fmt.Errorf("invalid body type %s\n", contentType) + return nil, err + } + return bodyBuf, nil +} + +// detectContentType method is used to figure out `Request.Body` content type for request header +func detectContentType(body interface{}) string { + contentType := "text/plain; charset=utf-8" + kind := reflect.TypeOf(body).Kind() + + switch kind { + case reflect.Struct, reflect.Map, reflect.Ptr: + contentType = "application/json; charset=utf-8" + case reflect.String: + contentType = "text/plain; charset=utf-8" + default: + if b, ok := body.([]byte); ok { + contentType = http.DetectContentType(b) + } else if kind == reflect.Slice { + contentType = "application/json; charset=utf-8" + } + } + + return contentType +} + +// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go +type cacheControl map[string]string + +func parseCacheControl(headers http.Header) cacheControl { + cc := cacheControl{} + ccHeader := headers.Get("Cache-Control") + for _, part := range strings.Split(ccHeader, ",") { + part = strings.Trim(part, " ") + if part == "" { + continue + } + if strings.ContainsRune(part, '=') { + keyval := strings.Split(part, "=") + cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") + } else { + cc[part] = "" + } + } + return cc +} + +// CacheExpires helper function to determine remaining time before repeating a request. +func CacheExpires(r *http.Response) time.Time { + // Figure out when the cache expires. + var expires time.Time + now, err := time.Parse(time.RFC1123, r.Header.Get("date")) + if err != nil { + return time.Now() + } + respCacheControl := parseCacheControl(r.Header) + + if maxAge, ok := respCacheControl["max-age"]; ok { + lifetime, err := time.ParseDuration(maxAge + "s") + if err != nil { + expires = now + } else { + expires = now.Add(lifetime) + } + } else { + expiresHeader := r.Header.Get("Expires") + if expiresHeader != "" { + expires, err = time.Parse(time.RFC1123, expiresHeader) + if err != nil { + expires = now + } + } + } + return expires +} + +func strlen(s string) int { + return utf8.RuneCountInString(s) +} + +// format error message using title and detail when model implements rfc7807 +func formatErrorMessage(status string, v interface{}) string { + str := "" + metaValue := reflect.ValueOf(v).Elem() + + if metaValue.Kind() == reflect.Struct { + field := metaValue.FieldByName("Title") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s", field.Interface()) + } + + field = metaValue.FieldByName("Detail") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s (%s)", str, field.Interface()) + } + } + + return strings.TrimSpace(fmt.Sprintf("%s %s", status, str)) +} diff --git a/services/cost/v3api/configuration.go b/services/cost/v3api/configuration.go new file mode 100644 index 000000000..969bca943 --- /dev/null +++ b/services/cost/v3api/configuration.go @@ -0,0 +1,37 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. +package v3api + +import ( + "github.com/stackitcloud/stackit-sdk-go/core/config" +) + +// NewConfiguration returns a new Configuration object +func NewConfiguration() *config.Configuration { + cfg := &config.Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "stackit-sdk-go/cost", + Debug: false, + Servers: config.ServerConfigurations{ + { + URL: "https://cost.api.stackit.cloud", + Description: "No description provided", + Variables: map[string]config.ServerVariable{ + "region": { + Description: "No description provided", + DefaultValue: "global", + }, + }, + }, + }, + OperationServers: map[string]config.ServerConfigurations{}, + } + return cfg +} diff --git a/services/cost/v3api/model_default_error.go b/services/cost/v3api/model_default_error.go new file mode 100644 index 000000000..792a0971e --- /dev/null +++ b/services/cost/v3api/model_default_error.go @@ -0,0 +1,203 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "encoding/json" + "fmt" +) + +// checks if the DefaultError type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DefaultError{} + +// DefaultError A standard error object. +type DefaultError struct { + Code string `json:"code"` + Message *string `json:"message,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _DefaultError DefaultError + +// NewDefaultError instantiates a new DefaultError object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewDefaultError(code string) *DefaultError { + this := DefaultError{} + this.Code = code + return &this +} + +// NewDefaultErrorWithDefaults instantiates a new DefaultError object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewDefaultErrorWithDefaults() *DefaultError { + this := DefaultError{} + return &this +} + +// GetCode returns the Code field value +func (o *DefaultError) GetCode() string { + if o == nil { + var ret string + return ret + } + + return o.Code +} + +// GetCodeOk returns a tuple with the Code field value +// and a boolean to check if the value has been set. +func (o *DefaultError) GetCodeOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Code, true +} + +// SetCode sets field value +func (o *DefaultError) SetCode(v string) { + o.Code = v +} + +// GetMessage returns the Message field value if set, zero value otherwise. +func (o *DefaultError) GetMessage() string { + if o == nil || IsNil(o.Message) { + var ret string + return ret + } + return *o.Message +} + +// GetMessageOk returns a tuple with the Message field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DefaultError) GetMessageOk() (*string, bool) { + if o == nil || IsNil(o.Message) { + return nil, false + } + return o.Message, true +} + +// HasMessage returns a boolean if a field has been set. +func (o *DefaultError) HasMessage() bool { + if o != nil && !IsNil(o.Message) { + return true + } + + return false +} + +// SetMessage gets a reference to the given string and assigns it to the Message field. +func (o *DefaultError) SetMessage(v string) { + o.Message = &v +} + +func (o DefaultError) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o DefaultError) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["code"] = o.Code + if !IsNil(o.Message) { + toSerialize["message"] = o.Message + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *DefaultError) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "code", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varDefaultError := _DefaultError{} + + err = json.Unmarshal(data, &varDefaultError) + + if err != nil { + return err + } + + *o = DefaultError(varDefaultError) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "code") + delete(additionalProperties, "message") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableDefaultError struct { + value *DefaultError + isSet bool +} + +func (v NullableDefaultError) Get() *DefaultError { + return v.value +} + +func (v *NullableDefaultError) Set(val *DefaultError) { + v.value = val + v.isSet = true +} + +func (v NullableDefaultError) IsSet() bool { + return v.isSet +} + +func (v *NullableDefaultError) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableDefaultError(val *DefaultError) *NullableDefaultError { + return &NullableDefaultError{value: val, isSet: true} +} + +func (v NullableDefaultError) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableDefaultError) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/services/cost/v3api/model_detailed_service_cost.go b/services/cost/v3api/model_detailed_service_cost.go new file mode 100644 index 000000000..cd8fd845b --- /dev/null +++ b/services/cost/v3api/model_detailed_service_cost.go @@ -0,0 +1,385 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "encoding/json" + "fmt" +) + +// checks if the DetailedServiceCost type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DetailedServiceCost{} + +// DetailedServiceCost Costs for a single service +type DetailedServiceCost struct { + // Detailed service costs which are ONLY included if granularity is provided + ReportData []ReportData `json:"reportData,omitempty"` + // Service category name + ServiceCategoryName string `json:"serviceCategoryName"` + // Name of the service + ServiceName string `json:"serviceName"` + // Service key + Sku string `json:"sku"` + // Total charge (including discounts) for all services and the whole requested date range (value in cents) + TotalCharge float64 `json:"totalCharge"` + // Total discount for all services and the whole requested date range (value in cents) + TotalDiscount float64 `json:"totalDiscount"` + // Total quantity + TotalQuantity int32 `json:"totalQuantity"` + // Label for unit + UnitLabel string `json:"unitLabel"` + AdditionalProperties map[string]interface{} +} + +type _DetailedServiceCost DetailedServiceCost + +// NewDetailedServiceCost instantiates a new DetailedServiceCost object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewDetailedServiceCost(serviceCategoryName string, serviceName string, sku string, totalCharge float64, totalDiscount float64, totalQuantity int32, unitLabel string) *DetailedServiceCost { + this := DetailedServiceCost{} + this.ServiceCategoryName = serviceCategoryName + this.ServiceName = serviceName + this.Sku = sku + this.TotalCharge = totalCharge + this.TotalDiscount = totalDiscount + this.TotalQuantity = totalQuantity + this.UnitLabel = unitLabel + return &this +} + +// NewDetailedServiceCostWithDefaults instantiates a new DetailedServiceCost object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewDetailedServiceCostWithDefaults() *DetailedServiceCost { + this := DetailedServiceCost{} + return &this +} + +// GetReportData returns the ReportData field value if set, zero value otherwise. +func (o *DetailedServiceCost) GetReportData() []ReportData { + if o == nil || IsNil(o.ReportData) { + var ret []ReportData + return ret + } + return o.ReportData +} + +// GetReportDataOk returns a tuple with the ReportData field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *DetailedServiceCost) GetReportDataOk() ([]ReportData, bool) { + if o == nil || IsNil(o.ReportData) { + return nil, false + } + return o.ReportData, true +} + +// HasReportData returns a boolean if a field has been set. +func (o *DetailedServiceCost) HasReportData() bool { + if o != nil && !IsNil(o.ReportData) { + return true + } + + return false +} + +// SetReportData gets a reference to the given []ReportData and assigns it to the ReportData field. +func (o *DetailedServiceCost) SetReportData(v []ReportData) { + o.ReportData = v +} + +// GetServiceCategoryName returns the ServiceCategoryName field value +func (o *DetailedServiceCost) GetServiceCategoryName() string { + if o == nil { + var ret string + return ret + } + + return o.ServiceCategoryName +} + +// GetServiceCategoryNameOk returns a tuple with the ServiceCategoryName field value +// and a boolean to check if the value has been set. +func (o *DetailedServiceCost) GetServiceCategoryNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ServiceCategoryName, true +} + +// SetServiceCategoryName sets field value +func (o *DetailedServiceCost) SetServiceCategoryName(v string) { + o.ServiceCategoryName = v +} + +// GetServiceName returns the ServiceName field value +func (o *DetailedServiceCost) GetServiceName() string { + if o == nil { + var ret string + return ret + } + + return o.ServiceName +} + +// GetServiceNameOk returns a tuple with the ServiceName field value +// and a boolean to check if the value has been set. +func (o *DetailedServiceCost) GetServiceNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ServiceName, true +} + +// SetServiceName sets field value +func (o *DetailedServiceCost) SetServiceName(v string) { + o.ServiceName = v +} + +// GetSku returns the Sku field value +func (o *DetailedServiceCost) GetSku() string { + if o == nil { + var ret string + return ret + } + + return o.Sku +} + +// GetSkuOk returns a tuple with the Sku field value +// and a boolean to check if the value has been set. +func (o *DetailedServiceCost) GetSkuOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Sku, true +} + +// SetSku sets field value +func (o *DetailedServiceCost) SetSku(v string) { + o.Sku = v +} + +// GetTotalCharge returns the TotalCharge field value +func (o *DetailedServiceCost) GetTotalCharge() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.TotalCharge +} + +// GetTotalChargeOk returns a tuple with the TotalCharge field value +// and a boolean to check if the value has been set. +func (o *DetailedServiceCost) GetTotalChargeOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.TotalCharge, true +} + +// SetTotalCharge sets field value +func (o *DetailedServiceCost) SetTotalCharge(v float64) { + o.TotalCharge = v +} + +// GetTotalDiscount returns the TotalDiscount field value +func (o *DetailedServiceCost) GetTotalDiscount() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.TotalDiscount +} + +// GetTotalDiscountOk returns a tuple with the TotalDiscount field value +// and a boolean to check if the value has been set. +func (o *DetailedServiceCost) GetTotalDiscountOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.TotalDiscount, true +} + +// SetTotalDiscount sets field value +func (o *DetailedServiceCost) SetTotalDiscount(v float64) { + o.TotalDiscount = v +} + +// GetTotalQuantity returns the TotalQuantity field value +func (o *DetailedServiceCost) GetTotalQuantity() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.TotalQuantity +} + +// GetTotalQuantityOk returns a tuple with the TotalQuantity field value +// and a boolean to check if the value has been set. +func (o *DetailedServiceCost) GetTotalQuantityOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.TotalQuantity, true +} + +// SetTotalQuantity sets field value +func (o *DetailedServiceCost) SetTotalQuantity(v int32) { + o.TotalQuantity = v +} + +// GetUnitLabel returns the UnitLabel field value +func (o *DetailedServiceCost) GetUnitLabel() string { + if o == nil { + var ret string + return ret + } + + return o.UnitLabel +} + +// GetUnitLabelOk returns a tuple with the UnitLabel field value +// and a boolean to check if the value has been set. +func (o *DetailedServiceCost) GetUnitLabelOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.UnitLabel, true +} + +// SetUnitLabel sets field value +func (o *DetailedServiceCost) SetUnitLabel(v string) { + o.UnitLabel = v +} + +func (o DetailedServiceCost) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o DetailedServiceCost) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.ReportData) { + toSerialize["reportData"] = o.ReportData + } + toSerialize["serviceCategoryName"] = o.ServiceCategoryName + toSerialize["serviceName"] = o.ServiceName + toSerialize["sku"] = o.Sku + toSerialize["totalCharge"] = o.TotalCharge + toSerialize["totalDiscount"] = o.TotalDiscount + toSerialize["totalQuantity"] = o.TotalQuantity + toSerialize["unitLabel"] = o.UnitLabel + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *DetailedServiceCost) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "serviceCategoryName", + "serviceName", + "sku", + "totalCharge", + "totalDiscount", + "totalQuantity", + "unitLabel", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varDetailedServiceCost := _DetailedServiceCost{} + + err = json.Unmarshal(data, &varDetailedServiceCost) + + if err != nil { + return err + } + + *o = DetailedServiceCost(varDetailedServiceCost) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "reportData") + delete(additionalProperties, "serviceCategoryName") + delete(additionalProperties, "serviceName") + delete(additionalProperties, "sku") + delete(additionalProperties, "totalCharge") + delete(additionalProperties, "totalDiscount") + delete(additionalProperties, "totalQuantity") + delete(additionalProperties, "unitLabel") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableDetailedServiceCost struct { + value *DetailedServiceCost + isSet bool +} + +func (v NullableDetailedServiceCost) Get() *DetailedServiceCost { + return v.value +} + +func (v *NullableDetailedServiceCost) Set(val *DetailedServiceCost) { + v.value = val + v.isSet = true +} + +func (v NullableDetailedServiceCost) IsSet() bool { + return v.isSet +} + +func (v *NullableDetailedServiceCost) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableDetailedServiceCost(val *DetailedServiceCost) *NullableDetailedServiceCost { + return &NullableDetailedServiceCost{value: val, isSet: true} +} + +func (v NullableDetailedServiceCost) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableDetailedServiceCost) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/services/cost/v3api/model_project_cost.go b/services/cost/v3api/model_project_cost.go new file mode 100644 index 000000000..88b5f3c8d --- /dev/null +++ b/services/cost/v3api/model_project_cost.go @@ -0,0 +1,139 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "encoding/json" + "fmt" +) + +// ProjectCost struct for ProjectCost +type ProjectCost struct { + ProjectCostWithDetailedServices *ProjectCostWithDetailedServices + ProjectCostWithReports *ProjectCostWithReports + ProjectCostWithSummarizedServices *ProjectCostWithSummarizedServices + SummarizedProjectCost *SummarizedProjectCost +} + +// Unmarshal JSON data into any of the pointers in the struct +func (dst *ProjectCost) UnmarshalJSON(data []byte) error { + var err error + // try to unmarshal JSON data into ProjectCostWithDetailedServices + err = json.Unmarshal(data, &dst.ProjectCostWithDetailedServices) + if err == nil { + jsonProjectCostWithDetailedServices, _ := json.Marshal(dst.ProjectCostWithDetailedServices) + if string(jsonProjectCostWithDetailedServices) == "{}" { // empty struct + dst.ProjectCostWithDetailedServices = nil + } else { + return nil // data stored in dst.ProjectCostWithDetailedServices, return on the first match + } + } else { + dst.ProjectCostWithDetailedServices = nil + } + + // try to unmarshal JSON data into ProjectCostWithReports + err = json.Unmarshal(data, &dst.ProjectCostWithReports) + if err == nil { + jsonProjectCostWithReports, _ := json.Marshal(dst.ProjectCostWithReports) + if string(jsonProjectCostWithReports) == "{}" { // empty struct + dst.ProjectCostWithReports = nil + } else { + return nil // data stored in dst.ProjectCostWithReports, return on the first match + } + } else { + dst.ProjectCostWithReports = nil + } + + // try to unmarshal JSON data into ProjectCostWithSummarizedServices + err = json.Unmarshal(data, &dst.ProjectCostWithSummarizedServices) + if err == nil { + jsonProjectCostWithSummarizedServices, _ := json.Marshal(dst.ProjectCostWithSummarizedServices) + if string(jsonProjectCostWithSummarizedServices) == "{}" { // empty struct + dst.ProjectCostWithSummarizedServices = nil + } else { + return nil // data stored in dst.ProjectCostWithSummarizedServices, return on the first match + } + } else { + dst.ProjectCostWithSummarizedServices = nil + } + + // try to unmarshal JSON data into SummarizedProjectCost + err = json.Unmarshal(data, &dst.SummarizedProjectCost) + if err == nil { + jsonSummarizedProjectCost, _ := json.Marshal(dst.SummarizedProjectCost) + if string(jsonSummarizedProjectCost) == "{}" { // empty struct + dst.SummarizedProjectCost = nil + } else { + return nil // data stored in dst.SummarizedProjectCost, return on the first match + } + } else { + dst.SummarizedProjectCost = nil + } + + return fmt.Errorf("data failed to match schemas in anyOf(ProjectCost)") +} + +// Marshal data from the first non-nil pointers in the struct to JSON +func (src ProjectCost) MarshalJSON() ([]byte, error) { + if src.ProjectCostWithDetailedServices != nil { + return json.Marshal(&src.ProjectCostWithDetailedServices) + } + + if src.ProjectCostWithReports != nil { + return json.Marshal(&src.ProjectCostWithReports) + } + + if src.ProjectCostWithSummarizedServices != nil { + return json.Marshal(&src.ProjectCostWithSummarizedServices) + } + + if src.SummarizedProjectCost != nil { + return json.Marshal(&src.SummarizedProjectCost) + } + + return nil, nil // no data in anyOf schemas +} + +type NullableProjectCost struct { + value *ProjectCost + isSet bool +} + +func (v NullableProjectCost) Get() *ProjectCost { + return v.value +} + +func (v *NullableProjectCost) Set(val *ProjectCost) { + v.value = val + v.isSet = true +} + +func (v NullableProjectCost) IsSet() bool { + return v.isSet +} + +func (v *NullableProjectCost) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableProjectCost(val *ProjectCost) *NullableProjectCost { + return &NullableProjectCost{value: val, isSet: true} +} + +func (v NullableProjectCost) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableProjectCost) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/services/cost/v3api/model_project_cost_with_detailed_services.go b/services/cost/v3api/model_project_cost_with_detailed_services.go new file mode 100644 index 000000000..f641a7349 --- /dev/null +++ b/services/cost/v3api/model_project_cost_with_detailed_services.go @@ -0,0 +1,322 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "encoding/json" + "fmt" +) + +// checks if the ProjectCostWithDetailedServices type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ProjectCostWithDetailedServices{} + +// ProjectCostWithDetailedServices Detailed costs for a project including service costs +type ProjectCostWithDetailedServices struct { + CustomerAccountId string `json:"customerAccountId"` + ProjectId string `json:"projectId"` + ProjectName string `json:"projectName"` + // Total discount for all services and the whole requested date range (value in cents). Please see \"depth\" parameter for more details. + Services []DetailedServiceCost `json:"services,omitempty"` + // Total charge (including discounts) for all services and the whole requested date range (value in cents) + TotalCharge float64 `json:"totalCharge"` + // Total discount for all services and the whole requested date range (value in cents) + TotalDiscount float64 `json:"totalDiscount"` + AdditionalProperties map[string]interface{} +} + +type _ProjectCostWithDetailedServices ProjectCostWithDetailedServices + +// NewProjectCostWithDetailedServices instantiates a new ProjectCostWithDetailedServices object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewProjectCostWithDetailedServices(customerAccountId string, projectId string, projectName string, totalCharge float64, totalDiscount float64) *ProjectCostWithDetailedServices { + this := ProjectCostWithDetailedServices{} + this.CustomerAccountId = customerAccountId + this.ProjectId = projectId + this.ProjectName = projectName + this.TotalCharge = totalCharge + this.TotalDiscount = totalDiscount + return &this +} + +// NewProjectCostWithDetailedServicesWithDefaults instantiates a new ProjectCostWithDetailedServices object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewProjectCostWithDetailedServicesWithDefaults() *ProjectCostWithDetailedServices { + this := ProjectCostWithDetailedServices{} + return &this +} + +// GetCustomerAccountId returns the CustomerAccountId field value +func (o *ProjectCostWithDetailedServices) GetCustomerAccountId() string { + if o == nil { + var ret string + return ret + } + + return o.CustomerAccountId +} + +// GetCustomerAccountIdOk returns a tuple with the CustomerAccountId field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithDetailedServices) GetCustomerAccountIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.CustomerAccountId, true +} + +// SetCustomerAccountId sets field value +func (o *ProjectCostWithDetailedServices) SetCustomerAccountId(v string) { + o.CustomerAccountId = v +} + +// GetProjectId returns the ProjectId field value +func (o *ProjectCostWithDetailedServices) GetProjectId() string { + if o == nil { + var ret string + return ret + } + + return o.ProjectId +} + +// GetProjectIdOk returns a tuple with the ProjectId field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithDetailedServices) GetProjectIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProjectId, true +} + +// SetProjectId sets field value +func (o *ProjectCostWithDetailedServices) SetProjectId(v string) { + o.ProjectId = v +} + +// GetProjectName returns the ProjectName field value +func (o *ProjectCostWithDetailedServices) GetProjectName() string { + if o == nil { + var ret string + return ret + } + + return o.ProjectName +} + +// GetProjectNameOk returns a tuple with the ProjectName field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithDetailedServices) GetProjectNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProjectName, true +} + +// SetProjectName sets field value +func (o *ProjectCostWithDetailedServices) SetProjectName(v string) { + o.ProjectName = v +} + +// GetServices returns the Services field value if set, zero value otherwise. +func (o *ProjectCostWithDetailedServices) GetServices() []DetailedServiceCost { + if o == nil || IsNil(o.Services) { + var ret []DetailedServiceCost + return ret + } + return o.Services +} + +// GetServicesOk returns a tuple with the Services field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ProjectCostWithDetailedServices) GetServicesOk() ([]DetailedServiceCost, bool) { + if o == nil || IsNil(o.Services) { + return nil, false + } + return o.Services, true +} + +// HasServices returns a boolean if a field has been set. +func (o *ProjectCostWithDetailedServices) HasServices() bool { + if o != nil && !IsNil(o.Services) { + return true + } + + return false +} + +// SetServices gets a reference to the given []DetailedServiceCost and assigns it to the Services field. +func (o *ProjectCostWithDetailedServices) SetServices(v []DetailedServiceCost) { + o.Services = v +} + +// GetTotalCharge returns the TotalCharge field value +func (o *ProjectCostWithDetailedServices) GetTotalCharge() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.TotalCharge +} + +// GetTotalChargeOk returns a tuple with the TotalCharge field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithDetailedServices) GetTotalChargeOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.TotalCharge, true +} + +// SetTotalCharge sets field value +func (o *ProjectCostWithDetailedServices) SetTotalCharge(v float64) { + o.TotalCharge = v +} + +// GetTotalDiscount returns the TotalDiscount field value +func (o *ProjectCostWithDetailedServices) GetTotalDiscount() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.TotalDiscount +} + +// GetTotalDiscountOk returns a tuple with the TotalDiscount field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithDetailedServices) GetTotalDiscountOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.TotalDiscount, true +} + +// SetTotalDiscount sets field value +func (o *ProjectCostWithDetailedServices) SetTotalDiscount(v float64) { + o.TotalDiscount = v +} + +func (o ProjectCostWithDetailedServices) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ProjectCostWithDetailedServices) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["customerAccountId"] = o.CustomerAccountId + toSerialize["projectId"] = o.ProjectId + toSerialize["projectName"] = o.ProjectName + if !IsNil(o.Services) { + toSerialize["services"] = o.Services + } + toSerialize["totalCharge"] = o.TotalCharge + toSerialize["totalDiscount"] = o.TotalDiscount + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *ProjectCostWithDetailedServices) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "customerAccountId", + "projectId", + "projectName", + "totalCharge", + "totalDiscount", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varProjectCostWithDetailedServices := _ProjectCostWithDetailedServices{} + + err = json.Unmarshal(data, &varProjectCostWithDetailedServices) + + if err != nil { + return err + } + + *o = ProjectCostWithDetailedServices(varProjectCostWithDetailedServices) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "customerAccountId") + delete(additionalProperties, "projectId") + delete(additionalProperties, "projectName") + delete(additionalProperties, "services") + delete(additionalProperties, "totalCharge") + delete(additionalProperties, "totalDiscount") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableProjectCostWithDetailedServices struct { + value *ProjectCostWithDetailedServices + isSet bool +} + +func (v NullableProjectCostWithDetailedServices) Get() *ProjectCostWithDetailedServices { + return v.value +} + +func (v *NullableProjectCostWithDetailedServices) Set(val *ProjectCostWithDetailedServices) { + v.value = val + v.isSet = true +} + +func (v NullableProjectCostWithDetailedServices) IsSet() bool { + return v.isSet +} + +func (v *NullableProjectCostWithDetailedServices) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableProjectCostWithDetailedServices(val *ProjectCostWithDetailedServices) *NullableProjectCostWithDetailedServices { + return &NullableProjectCostWithDetailedServices{value: val, isSet: true} +} + +func (v NullableProjectCostWithDetailedServices) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableProjectCostWithDetailedServices) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/services/cost/v3api/model_project_cost_with_reports.go b/services/cost/v3api/model_project_cost_with_reports.go new file mode 100644 index 000000000..a7197a66a --- /dev/null +++ b/services/cost/v3api/model_project_cost_with_reports.go @@ -0,0 +1,322 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "encoding/json" + "fmt" +) + +// checks if the ProjectCostWithReports type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ProjectCostWithReports{} + +// ProjectCostWithReports Detailed costs for a project +type ProjectCostWithReports struct { + CustomerAccountId string `json:"customerAccountId"` + ProjectId string `json:"projectId"` + ProjectName string `json:"projectName"` + // Detailed project costs which are ONLY included if granularity is provided AND depth is \"project\" + ReportData []ReportData `json:"reportData,omitempty"` + // Total charge (including discounts) for all services and the whole requested date range (value in cents) + TotalCharge float64 `json:"totalCharge"` + // Total discount for all services and the whole requested date range (value in cents) + TotalDiscount float64 `json:"totalDiscount"` + AdditionalProperties map[string]interface{} +} + +type _ProjectCostWithReports ProjectCostWithReports + +// NewProjectCostWithReports instantiates a new ProjectCostWithReports object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewProjectCostWithReports(customerAccountId string, projectId string, projectName string, totalCharge float64, totalDiscount float64) *ProjectCostWithReports { + this := ProjectCostWithReports{} + this.CustomerAccountId = customerAccountId + this.ProjectId = projectId + this.ProjectName = projectName + this.TotalCharge = totalCharge + this.TotalDiscount = totalDiscount + return &this +} + +// NewProjectCostWithReportsWithDefaults instantiates a new ProjectCostWithReports object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewProjectCostWithReportsWithDefaults() *ProjectCostWithReports { + this := ProjectCostWithReports{} + return &this +} + +// GetCustomerAccountId returns the CustomerAccountId field value +func (o *ProjectCostWithReports) GetCustomerAccountId() string { + if o == nil { + var ret string + return ret + } + + return o.CustomerAccountId +} + +// GetCustomerAccountIdOk returns a tuple with the CustomerAccountId field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithReports) GetCustomerAccountIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.CustomerAccountId, true +} + +// SetCustomerAccountId sets field value +func (o *ProjectCostWithReports) SetCustomerAccountId(v string) { + o.CustomerAccountId = v +} + +// GetProjectId returns the ProjectId field value +func (o *ProjectCostWithReports) GetProjectId() string { + if o == nil { + var ret string + return ret + } + + return o.ProjectId +} + +// GetProjectIdOk returns a tuple with the ProjectId field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithReports) GetProjectIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProjectId, true +} + +// SetProjectId sets field value +func (o *ProjectCostWithReports) SetProjectId(v string) { + o.ProjectId = v +} + +// GetProjectName returns the ProjectName field value +func (o *ProjectCostWithReports) GetProjectName() string { + if o == nil { + var ret string + return ret + } + + return o.ProjectName +} + +// GetProjectNameOk returns a tuple with the ProjectName field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithReports) GetProjectNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProjectName, true +} + +// SetProjectName sets field value +func (o *ProjectCostWithReports) SetProjectName(v string) { + o.ProjectName = v +} + +// GetReportData returns the ReportData field value if set, zero value otherwise. +func (o *ProjectCostWithReports) GetReportData() []ReportData { + if o == nil || IsNil(o.ReportData) { + var ret []ReportData + return ret + } + return o.ReportData +} + +// GetReportDataOk returns a tuple with the ReportData field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ProjectCostWithReports) GetReportDataOk() ([]ReportData, bool) { + if o == nil || IsNil(o.ReportData) { + return nil, false + } + return o.ReportData, true +} + +// HasReportData returns a boolean if a field has been set. +func (o *ProjectCostWithReports) HasReportData() bool { + if o != nil && !IsNil(o.ReportData) { + return true + } + + return false +} + +// SetReportData gets a reference to the given []ReportData and assigns it to the ReportData field. +func (o *ProjectCostWithReports) SetReportData(v []ReportData) { + o.ReportData = v +} + +// GetTotalCharge returns the TotalCharge field value +func (o *ProjectCostWithReports) GetTotalCharge() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.TotalCharge +} + +// GetTotalChargeOk returns a tuple with the TotalCharge field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithReports) GetTotalChargeOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.TotalCharge, true +} + +// SetTotalCharge sets field value +func (o *ProjectCostWithReports) SetTotalCharge(v float64) { + o.TotalCharge = v +} + +// GetTotalDiscount returns the TotalDiscount field value +func (o *ProjectCostWithReports) GetTotalDiscount() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.TotalDiscount +} + +// GetTotalDiscountOk returns a tuple with the TotalDiscount field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithReports) GetTotalDiscountOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.TotalDiscount, true +} + +// SetTotalDiscount sets field value +func (o *ProjectCostWithReports) SetTotalDiscount(v float64) { + o.TotalDiscount = v +} + +func (o ProjectCostWithReports) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ProjectCostWithReports) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["customerAccountId"] = o.CustomerAccountId + toSerialize["projectId"] = o.ProjectId + toSerialize["projectName"] = o.ProjectName + if !IsNil(o.ReportData) { + toSerialize["reportData"] = o.ReportData + } + toSerialize["totalCharge"] = o.TotalCharge + toSerialize["totalDiscount"] = o.TotalDiscount + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *ProjectCostWithReports) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "customerAccountId", + "projectId", + "projectName", + "totalCharge", + "totalDiscount", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varProjectCostWithReports := _ProjectCostWithReports{} + + err = json.Unmarshal(data, &varProjectCostWithReports) + + if err != nil { + return err + } + + *o = ProjectCostWithReports(varProjectCostWithReports) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "customerAccountId") + delete(additionalProperties, "projectId") + delete(additionalProperties, "projectName") + delete(additionalProperties, "reportData") + delete(additionalProperties, "totalCharge") + delete(additionalProperties, "totalDiscount") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableProjectCostWithReports struct { + value *ProjectCostWithReports + isSet bool +} + +func (v NullableProjectCostWithReports) Get() *ProjectCostWithReports { + return v.value +} + +func (v *NullableProjectCostWithReports) Set(val *ProjectCostWithReports) { + v.value = val + v.isSet = true +} + +func (v NullableProjectCostWithReports) IsSet() bool { + return v.isSet +} + +func (v *NullableProjectCostWithReports) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableProjectCostWithReports(val *ProjectCostWithReports) *NullableProjectCostWithReports { + return &NullableProjectCostWithReports{value: val, isSet: true} +} + +func (v NullableProjectCostWithReports) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableProjectCostWithReports) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/services/cost/v3api/model_project_cost_with_summarized_services.go b/services/cost/v3api/model_project_cost_with_summarized_services.go new file mode 100644 index 000000000..c1c196555 --- /dev/null +++ b/services/cost/v3api/model_project_cost_with_summarized_services.go @@ -0,0 +1,322 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "encoding/json" + "fmt" +) + +// checks if the ProjectCostWithSummarizedServices type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ProjectCostWithSummarizedServices{} + +// ProjectCostWithSummarizedServices Costs for a project including summarized service costs +type ProjectCostWithSummarizedServices struct { + CustomerAccountId string `json:"customerAccountId"` + ProjectId string `json:"projectId"` + ProjectName string `json:"projectName"` + // Summarized service costs + Services []SummarizedServiceCost `json:"services,omitempty"` + // Total charge (including discounts) for all services and the whole requested date range (value in cents) + TotalCharge float64 `json:"totalCharge"` + // Total discount for all services and the whole requested date range (value in cents) + TotalDiscount float64 `json:"totalDiscount"` + AdditionalProperties map[string]interface{} +} + +type _ProjectCostWithSummarizedServices ProjectCostWithSummarizedServices + +// NewProjectCostWithSummarizedServices instantiates a new ProjectCostWithSummarizedServices object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewProjectCostWithSummarizedServices(customerAccountId string, projectId string, projectName string, totalCharge float64, totalDiscount float64) *ProjectCostWithSummarizedServices { + this := ProjectCostWithSummarizedServices{} + this.CustomerAccountId = customerAccountId + this.ProjectId = projectId + this.ProjectName = projectName + this.TotalCharge = totalCharge + this.TotalDiscount = totalDiscount + return &this +} + +// NewProjectCostWithSummarizedServicesWithDefaults instantiates a new ProjectCostWithSummarizedServices object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewProjectCostWithSummarizedServicesWithDefaults() *ProjectCostWithSummarizedServices { + this := ProjectCostWithSummarizedServices{} + return &this +} + +// GetCustomerAccountId returns the CustomerAccountId field value +func (o *ProjectCostWithSummarizedServices) GetCustomerAccountId() string { + if o == nil { + var ret string + return ret + } + + return o.CustomerAccountId +} + +// GetCustomerAccountIdOk returns a tuple with the CustomerAccountId field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithSummarizedServices) GetCustomerAccountIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.CustomerAccountId, true +} + +// SetCustomerAccountId sets field value +func (o *ProjectCostWithSummarizedServices) SetCustomerAccountId(v string) { + o.CustomerAccountId = v +} + +// GetProjectId returns the ProjectId field value +func (o *ProjectCostWithSummarizedServices) GetProjectId() string { + if o == nil { + var ret string + return ret + } + + return o.ProjectId +} + +// GetProjectIdOk returns a tuple with the ProjectId field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithSummarizedServices) GetProjectIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProjectId, true +} + +// SetProjectId sets field value +func (o *ProjectCostWithSummarizedServices) SetProjectId(v string) { + o.ProjectId = v +} + +// GetProjectName returns the ProjectName field value +func (o *ProjectCostWithSummarizedServices) GetProjectName() string { + if o == nil { + var ret string + return ret + } + + return o.ProjectName +} + +// GetProjectNameOk returns a tuple with the ProjectName field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithSummarizedServices) GetProjectNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProjectName, true +} + +// SetProjectName sets field value +func (o *ProjectCostWithSummarizedServices) SetProjectName(v string) { + o.ProjectName = v +} + +// GetServices returns the Services field value if set, zero value otherwise. +func (o *ProjectCostWithSummarizedServices) GetServices() []SummarizedServiceCost { + if o == nil || IsNil(o.Services) { + var ret []SummarizedServiceCost + return ret + } + return o.Services +} + +// GetServicesOk returns a tuple with the Services field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ProjectCostWithSummarizedServices) GetServicesOk() ([]SummarizedServiceCost, bool) { + if o == nil || IsNil(o.Services) { + return nil, false + } + return o.Services, true +} + +// HasServices returns a boolean if a field has been set. +func (o *ProjectCostWithSummarizedServices) HasServices() bool { + if o != nil && !IsNil(o.Services) { + return true + } + + return false +} + +// SetServices gets a reference to the given []SummarizedServiceCost and assigns it to the Services field. +func (o *ProjectCostWithSummarizedServices) SetServices(v []SummarizedServiceCost) { + o.Services = v +} + +// GetTotalCharge returns the TotalCharge field value +func (o *ProjectCostWithSummarizedServices) GetTotalCharge() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.TotalCharge +} + +// GetTotalChargeOk returns a tuple with the TotalCharge field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithSummarizedServices) GetTotalChargeOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.TotalCharge, true +} + +// SetTotalCharge sets field value +func (o *ProjectCostWithSummarizedServices) SetTotalCharge(v float64) { + o.TotalCharge = v +} + +// GetTotalDiscount returns the TotalDiscount field value +func (o *ProjectCostWithSummarizedServices) GetTotalDiscount() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.TotalDiscount +} + +// GetTotalDiscountOk returns a tuple with the TotalDiscount field value +// and a boolean to check if the value has been set. +func (o *ProjectCostWithSummarizedServices) GetTotalDiscountOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.TotalDiscount, true +} + +// SetTotalDiscount sets field value +func (o *ProjectCostWithSummarizedServices) SetTotalDiscount(v float64) { + o.TotalDiscount = v +} + +func (o ProjectCostWithSummarizedServices) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ProjectCostWithSummarizedServices) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["customerAccountId"] = o.CustomerAccountId + toSerialize["projectId"] = o.ProjectId + toSerialize["projectName"] = o.ProjectName + if !IsNil(o.Services) { + toSerialize["services"] = o.Services + } + toSerialize["totalCharge"] = o.TotalCharge + toSerialize["totalDiscount"] = o.TotalDiscount + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *ProjectCostWithSummarizedServices) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "customerAccountId", + "projectId", + "projectName", + "totalCharge", + "totalDiscount", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varProjectCostWithSummarizedServices := _ProjectCostWithSummarizedServices{} + + err = json.Unmarshal(data, &varProjectCostWithSummarizedServices) + + if err != nil { + return err + } + + *o = ProjectCostWithSummarizedServices(varProjectCostWithSummarizedServices) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "customerAccountId") + delete(additionalProperties, "projectId") + delete(additionalProperties, "projectName") + delete(additionalProperties, "services") + delete(additionalProperties, "totalCharge") + delete(additionalProperties, "totalDiscount") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableProjectCostWithSummarizedServices struct { + value *ProjectCostWithSummarizedServices + isSet bool +} + +func (v NullableProjectCostWithSummarizedServices) Get() *ProjectCostWithSummarizedServices { + return v.value +} + +func (v *NullableProjectCostWithSummarizedServices) Set(val *ProjectCostWithSummarizedServices) { + v.value = val + v.isSet = true +} + +func (v NullableProjectCostWithSummarizedServices) IsSet() bool { + return v.isSet +} + +func (v *NullableProjectCostWithSummarizedServices) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableProjectCostWithSummarizedServices(val *ProjectCostWithSummarizedServices) *NullableProjectCostWithSummarizedServices { + return &NullableProjectCostWithSummarizedServices{value: val, isSet: true} +} + +func (v NullableProjectCostWithSummarizedServices) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableProjectCostWithSummarizedServices) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/services/cost/v3api/model_report_data.go b/services/cost/v3api/model_report_data.go new file mode 100644 index 000000000..3d5bef9d3 --- /dev/null +++ b/services/cost/v3api/model_report_data.go @@ -0,0 +1,256 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "encoding/json" + "fmt" +) + +// checks if the ReportData type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ReportData{} + +// ReportData Costs report for a certain period of time +type ReportData struct { + // Charge, value in cents + Charge float64 `json:"charge"` + // Discount, value in cents + Discount float64 `json:"discount"` + // Quantity + Quantity int32 `json:"quantity"` + TimePeriod ReportDataTimePeriod `json:"timePeriod"` + AdditionalProperties map[string]interface{} +} + +type _ReportData ReportData + +// NewReportData instantiates a new ReportData object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewReportData(charge float64, discount float64, quantity int32, timePeriod ReportDataTimePeriod) *ReportData { + this := ReportData{} + this.Charge = charge + this.Discount = discount + this.Quantity = quantity + this.TimePeriod = timePeriod + return &this +} + +// NewReportDataWithDefaults instantiates a new ReportData object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewReportDataWithDefaults() *ReportData { + this := ReportData{} + return &this +} + +// GetCharge returns the Charge field value +func (o *ReportData) GetCharge() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.Charge +} + +// GetChargeOk returns a tuple with the Charge field value +// and a boolean to check if the value has been set. +func (o *ReportData) GetChargeOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.Charge, true +} + +// SetCharge sets field value +func (o *ReportData) SetCharge(v float64) { + o.Charge = v +} + +// GetDiscount returns the Discount field value +func (o *ReportData) GetDiscount() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.Discount +} + +// GetDiscountOk returns a tuple with the Discount field value +// and a boolean to check if the value has been set. +func (o *ReportData) GetDiscountOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.Discount, true +} + +// SetDiscount sets field value +func (o *ReportData) SetDiscount(v float64) { + o.Discount = v +} + +// GetQuantity returns the Quantity field value +func (o *ReportData) GetQuantity() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.Quantity +} + +// GetQuantityOk returns a tuple with the Quantity field value +// and a boolean to check if the value has been set. +func (o *ReportData) GetQuantityOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.Quantity, true +} + +// SetQuantity sets field value +func (o *ReportData) SetQuantity(v int32) { + o.Quantity = v +} + +// GetTimePeriod returns the TimePeriod field value +func (o *ReportData) GetTimePeriod() ReportDataTimePeriod { + if o == nil { + var ret ReportDataTimePeriod + return ret + } + + return o.TimePeriod +} + +// GetTimePeriodOk returns a tuple with the TimePeriod field value +// and a boolean to check if the value has been set. +func (o *ReportData) GetTimePeriodOk() (*ReportDataTimePeriod, bool) { + if o == nil { + return nil, false + } + return &o.TimePeriod, true +} + +// SetTimePeriod sets field value +func (o *ReportData) SetTimePeriod(v ReportDataTimePeriod) { + o.TimePeriod = v +} + +func (o ReportData) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ReportData) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["charge"] = o.Charge + toSerialize["discount"] = o.Discount + toSerialize["quantity"] = o.Quantity + toSerialize["timePeriod"] = o.TimePeriod + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *ReportData) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "charge", + "discount", + "quantity", + "timePeriod", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varReportData := _ReportData{} + + err = json.Unmarshal(data, &varReportData) + + if err != nil { + return err + } + + *o = ReportData(varReportData) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "charge") + delete(additionalProperties, "discount") + delete(additionalProperties, "quantity") + delete(additionalProperties, "timePeriod") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableReportData struct { + value *ReportData + isSet bool +} + +func (v NullableReportData) Get() *ReportData { + return v.value +} + +func (v *NullableReportData) Set(val *ReportData) { + v.value = val + v.isSet = true +} + +func (v NullableReportData) IsSet() bool { + return v.isSet +} + +func (v *NullableReportData) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableReportData(val *ReportData) *NullableReportData { + return &NullableReportData{value: val, isSet: true} +} + +func (v NullableReportData) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableReportData) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/services/cost/v3api/model_report_data_time_period.go b/services/cost/v3api/model_report_data_time_period.go new file mode 100644 index 000000000..aa55f8a7e --- /dev/null +++ b/services/cost/v3api/model_report_data_time_period.go @@ -0,0 +1,190 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "encoding/json" +) + +// checks if the ReportDataTimePeriod type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ReportDataTimePeriod{} + +// ReportDataTimePeriod Time period according to desired granularity +type ReportDataTimePeriod struct { + End *string `json:"end,omitempty"` + Start *string `json:"start,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _ReportDataTimePeriod ReportDataTimePeriod + +// NewReportDataTimePeriod instantiates a new ReportDataTimePeriod object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewReportDataTimePeriod() *ReportDataTimePeriod { + this := ReportDataTimePeriod{} + return &this +} + +// NewReportDataTimePeriodWithDefaults instantiates a new ReportDataTimePeriod object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewReportDataTimePeriodWithDefaults() *ReportDataTimePeriod { + this := ReportDataTimePeriod{} + return &this +} + +// GetEnd returns the End field value if set, zero value otherwise. +func (o *ReportDataTimePeriod) GetEnd() string { + if o == nil || IsNil(o.End) { + var ret string + return ret + } + return *o.End +} + +// GetEndOk returns a tuple with the End field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ReportDataTimePeriod) GetEndOk() (*string, bool) { + if o == nil || IsNil(o.End) { + return nil, false + } + return o.End, true +} + +// HasEnd returns a boolean if a field has been set. +func (o *ReportDataTimePeriod) HasEnd() bool { + if o != nil && !IsNil(o.End) { + return true + } + + return false +} + +// SetEnd gets a reference to the given string and assigns it to the End field. +func (o *ReportDataTimePeriod) SetEnd(v string) { + o.End = &v +} + +// GetStart returns the Start field value if set, zero value otherwise. +func (o *ReportDataTimePeriod) GetStart() string { + if o == nil || IsNil(o.Start) { + var ret string + return ret + } + return *o.Start +} + +// GetStartOk returns a tuple with the Start field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ReportDataTimePeriod) GetStartOk() (*string, bool) { + if o == nil || IsNil(o.Start) { + return nil, false + } + return o.Start, true +} + +// HasStart returns a boolean if a field has been set. +func (o *ReportDataTimePeriod) HasStart() bool { + if o != nil && !IsNil(o.Start) { + return true + } + + return false +} + +// SetStart gets a reference to the given string and assigns it to the Start field. +func (o *ReportDataTimePeriod) SetStart(v string) { + o.Start = &v +} + +func (o ReportDataTimePeriod) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ReportDataTimePeriod) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.End) { + toSerialize["end"] = o.End + } + if !IsNil(o.Start) { + toSerialize["start"] = o.Start + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *ReportDataTimePeriod) UnmarshalJSON(data []byte) (err error) { + varReportDataTimePeriod := _ReportDataTimePeriod{} + + err = json.Unmarshal(data, &varReportDataTimePeriod) + + if err != nil { + return err + } + + *o = ReportDataTimePeriod(varReportDataTimePeriod) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "end") + delete(additionalProperties, "start") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableReportDataTimePeriod struct { + value *ReportDataTimePeriod + isSet bool +} + +func (v NullableReportDataTimePeriod) Get() *ReportDataTimePeriod { + return v.value +} + +func (v *NullableReportDataTimePeriod) Set(val *ReportDataTimePeriod) { + v.value = val + v.isSet = true +} + +func (v NullableReportDataTimePeriod) IsSet() bool { + return v.isSet +} + +func (v *NullableReportDataTimePeriod) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableReportDataTimePeriod(val *ReportDataTimePeriod) *NullableReportDataTimePeriod { + return &NullableReportDataTimePeriod{value: val, isSet: true} +} + +func (v NullableReportDataTimePeriod) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableReportDataTimePeriod) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/services/cost/v3api/model_summarized_project_cost.go b/services/cost/v3api/model_summarized_project_cost.go new file mode 100644 index 000000000..8f5793664 --- /dev/null +++ b/services/cost/v3api/model_summarized_project_cost.go @@ -0,0 +1,284 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "encoding/json" + "fmt" +) + +// checks if the SummarizedProjectCost type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &SummarizedProjectCost{} + +// SummarizedProjectCost Summarized costs for a project +type SummarizedProjectCost struct { + CustomerAccountId string `json:"customerAccountId"` + ProjectId string `json:"projectId"` + ProjectName string `json:"projectName"` + // Total charge (including discounts) for all services and the whole requested date range (value in cents) + TotalCharge float64 `json:"totalCharge"` + // Total discount for all services and the whole requested date range (value in cents) + TotalDiscount float64 `json:"totalDiscount"` + AdditionalProperties map[string]interface{} +} + +type _SummarizedProjectCost SummarizedProjectCost + +// NewSummarizedProjectCost instantiates a new SummarizedProjectCost object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewSummarizedProjectCost(customerAccountId string, projectId string, projectName string, totalCharge float64, totalDiscount float64) *SummarizedProjectCost { + this := SummarizedProjectCost{} + this.CustomerAccountId = customerAccountId + this.ProjectId = projectId + this.ProjectName = projectName + this.TotalCharge = totalCharge + this.TotalDiscount = totalDiscount + return &this +} + +// NewSummarizedProjectCostWithDefaults instantiates a new SummarizedProjectCost object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewSummarizedProjectCostWithDefaults() *SummarizedProjectCost { + this := SummarizedProjectCost{} + return &this +} + +// GetCustomerAccountId returns the CustomerAccountId field value +func (o *SummarizedProjectCost) GetCustomerAccountId() string { + if o == nil { + var ret string + return ret + } + + return o.CustomerAccountId +} + +// GetCustomerAccountIdOk returns a tuple with the CustomerAccountId field value +// and a boolean to check if the value has been set. +func (o *SummarizedProjectCost) GetCustomerAccountIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.CustomerAccountId, true +} + +// SetCustomerAccountId sets field value +func (o *SummarizedProjectCost) SetCustomerAccountId(v string) { + o.CustomerAccountId = v +} + +// GetProjectId returns the ProjectId field value +func (o *SummarizedProjectCost) GetProjectId() string { + if o == nil { + var ret string + return ret + } + + return o.ProjectId +} + +// GetProjectIdOk returns a tuple with the ProjectId field value +// and a boolean to check if the value has been set. +func (o *SummarizedProjectCost) GetProjectIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProjectId, true +} + +// SetProjectId sets field value +func (o *SummarizedProjectCost) SetProjectId(v string) { + o.ProjectId = v +} + +// GetProjectName returns the ProjectName field value +func (o *SummarizedProjectCost) GetProjectName() string { + if o == nil { + var ret string + return ret + } + + return o.ProjectName +} + +// GetProjectNameOk returns a tuple with the ProjectName field value +// and a boolean to check if the value has been set. +func (o *SummarizedProjectCost) GetProjectNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProjectName, true +} + +// SetProjectName sets field value +func (o *SummarizedProjectCost) SetProjectName(v string) { + o.ProjectName = v +} + +// GetTotalCharge returns the TotalCharge field value +func (o *SummarizedProjectCost) GetTotalCharge() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.TotalCharge +} + +// GetTotalChargeOk returns a tuple with the TotalCharge field value +// and a boolean to check if the value has been set. +func (o *SummarizedProjectCost) GetTotalChargeOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.TotalCharge, true +} + +// SetTotalCharge sets field value +func (o *SummarizedProjectCost) SetTotalCharge(v float64) { + o.TotalCharge = v +} + +// GetTotalDiscount returns the TotalDiscount field value +func (o *SummarizedProjectCost) GetTotalDiscount() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.TotalDiscount +} + +// GetTotalDiscountOk returns a tuple with the TotalDiscount field value +// and a boolean to check if the value has been set. +func (o *SummarizedProjectCost) GetTotalDiscountOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.TotalDiscount, true +} + +// SetTotalDiscount sets field value +func (o *SummarizedProjectCost) SetTotalDiscount(v float64) { + o.TotalDiscount = v +} + +func (o SummarizedProjectCost) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o SummarizedProjectCost) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["customerAccountId"] = o.CustomerAccountId + toSerialize["projectId"] = o.ProjectId + toSerialize["projectName"] = o.ProjectName + toSerialize["totalCharge"] = o.TotalCharge + toSerialize["totalDiscount"] = o.TotalDiscount + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *SummarizedProjectCost) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "customerAccountId", + "projectId", + "projectName", + "totalCharge", + "totalDiscount", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varSummarizedProjectCost := _SummarizedProjectCost{} + + err = json.Unmarshal(data, &varSummarizedProjectCost) + + if err != nil { + return err + } + + *o = SummarizedProjectCost(varSummarizedProjectCost) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "customerAccountId") + delete(additionalProperties, "projectId") + delete(additionalProperties, "projectName") + delete(additionalProperties, "totalCharge") + delete(additionalProperties, "totalDiscount") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableSummarizedProjectCost struct { + value *SummarizedProjectCost + isSet bool +} + +func (v NullableSummarizedProjectCost) Get() *SummarizedProjectCost { + return v.value +} + +func (v *NullableSummarizedProjectCost) Set(val *SummarizedProjectCost) { + v.value = val + v.isSet = true +} + +func (v NullableSummarizedProjectCost) IsSet() bool { + return v.isSet +} + +func (v *NullableSummarizedProjectCost) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableSummarizedProjectCost(val *SummarizedProjectCost) *NullableSummarizedProjectCost { + return &NullableSummarizedProjectCost{value: val, isSet: true} +} + +func (v NullableSummarizedProjectCost) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableSummarizedProjectCost) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/services/cost/v3api/model_summarized_service_cost.go b/services/cost/v3api/model_summarized_service_cost.go new file mode 100644 index 000000000..40844c5ba --- /dev/null +++ b/services/cost/v3api/model_summarized_service_cost.go @@ -0,0 +1,284 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "encoding/json" + "fmt" +) + +// checks if the SummarizedServiceCost type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &SummarizedServiceCost{} + +// SummarizedServiceCost Summarized costs for a project +type SummarizedServiceCost struct { + CustomerAccountId string `json:"customerAccountId"` + ProjectId string `json:"projectId"` + ProjectName string `json:"projectName"` + // Total charge (including discounts) for all services and the whole requested date range (value in cents) + TotalCharge float64 `json:"totalCharge"` + // Total discount for all services and the whole requested date range (value in cents) + TotalDiscount float64 `json:"totalDiscount"` + AdditionalProperties map[string]interface{} +} + +type _SummarizedServiceCost SummarizedServiceCost + +// NewSummarizedServiceCost instantiates a new SummarizedServiceCost object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewSummarizedServiceCost(customerAccountId string, projectId string, projectName string, totalCharge float64, totalDiscount float64) *SummarizedServiceCost { + this := SummarizedServiceCost{} + this.CustomerAccountId = customerAccountId + this.ProjectId = projectId + this.ProjectName = projectName + this.TotalCharge = totalCharge + this.TotalDiscount = totalDiscount + return &this +} + +// NewSummarizedServiceCostWithDefaults instantiates a new SummarizedServiceCost object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewSummarizedServiceCostWithDefaults() *SummarizedServiceCost { + this := SummarizedServiceCost{} + return &this +} + +// GetCustomerAccountId returns the CustomerAccountId field value +func (o *SummarizedServiceCost) GetCustomerAccountId() string { + if o == nil { + var ret string + return ret + } + + return o.CustomerAccountId +} + +// GetCustomerAccountIdOk returns a tuple with the CustomerAccountId field value +// and a boolean to check if the value has been set. +func (o *SummarizedServiceCost) GetCustomerAccountIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.CustomerAccountId, true +} + +// SetCustomerAccountId sets field value +func (o *SummarizedServiceCost) SetCustomerAccountId(v string) { + o.CustomerAccountId = v +} + +// GetProjectId returns the ProjectId field value +func (o *SummarizedServiceCost) GetProjectId() string { + if o == nil { + var ret string + return ret + } + + return o.ProjectId +} + +// GetProjectIdOk returns a tuple with the ProjectId field value +// and a boolean to check if the value has been set. +func (o *SummarizedServiceCost) GetProjectIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProjectId, true +} + +// SetProjectId sets field value +func (o *SummarizedServiceCost) SetProjectId(v string) { + o.ProjectId = v +} + +// GetProjectName returns the ProjectName field value +func (o *SummarizedServiceCost) GetProjectName() string { + if o == nil { + var ret string + return ret + } + + return o.ProjectName +} + +// GetProjectNameOk returns a tuple with the ProjectName field value +// and a boolean to check if the value has been set. +func (o *SummarizedServiceCost) GetProjectNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProjectName, true +} + +// SetProjectName sets field value +func (o *SummarizedServiceCost) SetProjectName(v string) { + o.ProjectName = v +} + +// GetTotalCharge returns the TotalCharge field value +func (o *SummarizedServiceCost) GetTotalCharge() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.TotalCharge +} + +// GetTotalChargeOk returns a tuple with the TotalCharge field value +// and a boolean to check if the value has been set. +func (o *SummarizedServiceCost) GetTotalChargeOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.TotalCharge, true +} + +// SetTotalCharge sets field value +func (o *SummarizedServiceCost) SetTotalCharge(v float64) { + o.TotalCharge = v +} + +// GetTotalDiscount returns the TotalDiscount field value +func (o *SummarizedServiceCost) GetTotalDiscount() float64 { + if o == nil { + var ret float64 + return ret + } + + return o.TotalDiscount +} + +// GetTotalDiscountOk returns a tuple with the TotalDiscount field value +// and a boolean to check if the value has been set. +func (o *SummarizedServiceCost) GetTotalDiscountOk() (*float64, bool) { + if o == nil { + return nil, false + } + return &o.TotalDiscount, true +} + +// SetTotalDiscount sets field value +func (o *SummarizedServiceCost) SetTotalDiscount(v float64) { + o.TotalDiscount = v +} + +func (o SummarizedServiceCost) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o SummarizedServiceCost) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["customerAccountId"] = o.CustomerAccountId + toSerialize["projectId"] = o.ProjectId + toSerialize["projectName"] = o.ProjectName + toSerialize["totalCharge"] = o.TotalCharge + toSerialize["totalDiscount"] = o.TotalDiscount + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *SummarizedServiceCost) UnmarshalJSON(data []byte) (err error) { + // This validates that all required properties are included in the JSON object + // by unmarshalling the object into a generic map with string keys and checking + // that every required field exists as a key in the generic map. + requiredProperties := []string{ + "customerAccountId", + "projectId", + "projectName", + "totalCharge", + "totalDiscount", + } + + allProperties := make(map[string]interface{}) + + err = json.Unmarshal(data, &allProperties) + + if err != nil { + return err + } + + for _, requiredProperty := range requiredProperties { + if _, exists := allProperties[requiredProperty]; !exists { + return fmt.Errorf("no value given for required property %v", requiredProperty) + } + } + + varSummarizedServiceCost := _SummarizedServiceCost{} + + err = json.Unmarshal(data, &varSummarizedServiceCost) + + if err != nil { + return err + } + + *o = SummarizedServiceCost(varSummarizedServiceCost) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(data, &additionalProperties); err == nil { + delete(additionalProperties, "customerAccountId") + delete(additionalProperties, "projectId") + delete(additionalProperties, "projectName") + delete(additionalProperties, "totalCharge") + delete(additionalProperties, "totalDiscount") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableSummarizedServiceCost struct { + value *SummarizedServiceCost + isSet bool +} + +func (v NullableSummarizedServiceCost) Get() *SummarizedServiceCost { + return v.value +} + +func (v *NullableSummarizedServiceCost) Set(val *SummarizedServiceCost) { + v.value = val + v.isSet = true +} + +func (v NullableSummarizedServiceCost) IsSet() bool { + return v.isSet +} + +func (v *NullableSummarizedServiceCost) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableSummarizedServiceCost(val *SummarizedServiceCost) *NullableSummarizedServiceCost { + return &NullableSummarizedServiceCost{value: val, isSet: true} +} + +func (v NullableSummarizedServiceCost) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableSummarizedServiceCost) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/services/cost/v3api/response.go b/services/cost/v3api/response.go new file mode 100644 index 000000000..1b74429b7 --- /dev/null +++ b/services/cost/v3api/response.go @@ -0,0 +1,47 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "net/http" +) + +// APIResponse stores the API response returned by the server. +type APIResponse struct { + *http.Response `json:"-"` + Message string `json:"message,omitempty"` + // Operation is the name of the OpenAPI operation. + Operation string `json:"operation,omitempty"` + // RequestURL is the request URL. This value is always available, even if the + // embedded *http.Response is nil. + RequestURL string `json:"url,omitempty"` + // Method is the HTTP method used for the request. This value is always + // available, even if the embedded *http.Response is nil. + Method string `json:"method,omitempty"` + // Payload holds the contents of the response body (which may be nil or empty). + // This is provided here as the raw response.Body() reader will have already + // been drained. + Payload []byte `json:"-"` +} + +// NewAPIResponse returns a new APIResponse object. +func NewAPIResponse(r *http.Response) *APIResponse { + + response := &APIResponse{Response: r} + return response +} + +// NewAPIResponseWithError returns a new APIResponse object with the provided error message. +func NewAPIResponseWithError(errorMessage string) *APIResponse { + + response := &APIResponse{Message: errorMessage} + return response +} diff --git a/services/cost/v3api/utils.go b/services/cost/v3api/utils.go new file mode 100644 index 000000000..e5cfedf16 --- /dev/null +++ b/services/cost/v3api/utils.go @@ -0,0 +1,361 @@ +/* +STACKIT Cost API + +The cost API provides detailed reports on the costs for a customer or project over a certain amount of time + +API version: 3.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v3api + +import ( + "bytes" + "encoding/json" + "fmt" + "reflect" + "time" +) + +// PtrBool is a helper routine that returns a pointer to given boolean value. +func PtrBool(v bool) *bool { return &v } + +// PtrInt is a helper routine that returns a pointer to given integer value. +func PtrInt(v int) *int { return &v } + +// PtrInt32 is a helper routine that returns a pointer to given integer value. +func PtrInt32(v int32) *int32 { return &v } + +// PtrInt64 is a helper routine that returns a pointer to given integer value. +func PtrInt64(v int64) *int64 { return &v } + +// PtrFloat32 is a helper routine that returns a pointer to given float value. +func PtrFloat32(v float32) *float32 { return &v } + +// PtrFloat64 is a helper routine that returns a pointer to given float value. +func PtrFloat64(v float64) *float64 { return &v } + +// PtrString is a helper routine that returns a pointer to given string value. +func PtrString(v string) *string { return &v } + +// PtrTime is helper routine that returns a pointer to given Time value. +func PtrTime(v time.Time) *time.Time { return &v } + +type NullableBool struct { + value *bool + isSet bool +} + +func (v NullableBool) Get() *bool { + return v.value +} + +func (v *NullableBool) Set(val *bool) { + v.value = val + v.isSet = true +} + +func (v NullableBool) IsSet() bool { + return v.isSet +} + +func (v *NullableBool) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBool(val *bool) *NullableBool { + return &NullableBool{value: val, isSet: true} +} + +func (v NullableBool) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBool) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt struct { + value *int + isSet bool +} + +func (v NullableInt) Get() *int { + return v.value +} + +func (v *NullableInt) Set(val *int) { + v.value = val + v.isSet = true +} + +func (v NullableInt) IsSet() bool { + return v.isSet +} + +func (v *NullableInt) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt(val *int) *NullableInt { + return &NullableInt{value: val, isSet: true} +} + +func (v NullableInt) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt32 struct { + value *int32 + isSet bool +} + +func (v NullableInt32) Get() *int32 { + return v.value +} + +func (v *NullableInt32) Set(val *int32) { + v.value = val + v.isSet = true +} + +func (v NullableInt32) IsSet() bool { + return v.isSet +} + +func (v *NullableInt32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt32(val *int32) *NullableInt32 { + return &NullableInt32{value: val, isSet: true} +} + +func (v NullableInt32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt64 struct { + value *int64 + isSet bool +} + +func (v NullableInt64) Get() *int64 { + return v.value +} + +func (v *NullableInt64) Set(val *int64) { + v.value = val + v.isSet = true +} + +func (v NullableInt64) IsSet() bool { + return v.isSet +} + +func (v *NullableInt64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt64(val *int64) *NullableInt64 { + return &NullableInt64{value: val, isSet: true} +} + +func (v NullableInt64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat32 struct { + value *float32 + isSet bool +} + +func (v NullableFloat32) Get() *float32 { + return v.value +} + +func (v *NullableFloat32) Set(val *float32) { + v.value = val + v.isSet = true +} + +func (v NullableFloat32) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat32(val *float32) *NullableFloat32 { + return &NullableFloat32{value: val, isSet: true} +} + +func (v NullableFloat32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat64 struct { + value *float64 + isSet bool +} + +func (v NullableFloat64) Get() *float64 { + return v.value +} + +func (v *NullableFloat64) Set(val *float64) { + v.value = val + v.isSet = true +} + +func (v NullableFloat64) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat64(val *float64) *NullableFloat64 { + return &NullableFloat64{value: val, isSet: true} +} + +func (v NullableFloat64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableString struct { + value *string + isSet bool +} + +func (v NullableString) Get() *string { + return v.value +} + +func (v *NullableString) Set(val *string) { + v.value = val + v.isSet = true +} + +func (v NullableString) IsSet() bool { + return v.isSet +} + +func (v *NullableString) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableString(val *string) *NullableString { + return &NullableString{value: val, isSet: true} +} + +func (v NullableString) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableString) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableTime struct { + value *time.Time + isSet bool +} + +func (v NullableTime) Get() *time.Time { + return v.value +} + +func (v *NullableTime) Set(val *time.Time) { + v.value = val + v.isSet = true +} + +func (v NullableTime) IsSet() bool { + return v.isSet +} + +func (v *NullableTime) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTime(val *time.Time) *NullableTime { + return &NullableTime{value: val, isSet: true} +} + +func (v NullableTime) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTime) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +// IsNil checks if an input is nil +func IsNil(i interface{}) bool { + if i == nil { + return true + } + switch reflect.TypeOf(i).Kind() { + case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: + return reflect.ValueOf(i).IsNil() + case reflect.Array: + return reflect.ValueOf(i).IsZero() + } + return false +} + +type MappedNullable interface { + ToMap() (map[string]interface{}, error) +} + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +}