22package taxcodes
33
44import (
5+ "errors"
6+
57 api "github.com/openmeterio/openmeter/api/v3"
68 "github.com/openmeterio/openmeter/api/v3/labels"
79 "github.com/openmeterio/openmeter/openmeter/app"
@@ -19,6 +21,9 @@ import (
1921// goverter:extend ToAPIBillingAppType
2022// goverter:extend ToAPIBillingTaxCodeAppMappings
2123// goverter:extend ConvertLabelsToMetadata
24+ // goverter:extend IDStringToTaxCodeReference
25+ // goverter:extend InvoicingTaxCodeReferenceToIDString
26+ // goverter:extend CreditGrantTaxCodeReferenceToIDString
2227var (
2328 // goverter:context namespace
2429 // goverter:map Namespace | NamespaceFromContext
4045 // goverter:map ManagedModel.DeletedAt DeletedAt
4146 // goverter:map AppMappings | ToAPIBillingTaxCodeAppMappings
4247 ToAPIBillingTaxCode func (taxcode.TaxCode ) (api.BillingTaxCode , error )
48+
49+ // goverter:map ManagedModel.CreatedAt CreatedAt
50+ // goverter:map ManagedModel.UpdatedAt UpdatedAt
51+ // goverter:map InvoicingTaxCodeID InvoicingTaxCode | IDStringToTaxCodeReference
52+ // goverter:map CreditGrantTaxCodeID CreditGrantTaxCode | IDStringToTaxCodeReference
53+ ToAPIOrganizationDefaultTaxCodes func (taxcode.OrganizationDefaultTaxCodes ) (api.OrganizationDefaultTaxCodes , error )
54+
55+ // goverter:context namespace
56+ // goverter:map Namespace | NamespaceFromContext
57+ // goverter:map InvoicingTaxCode InvoicingTaxCodeID | InvoicingTaxCodeReferenceToIDString
58+ // goverter:map CreditGrantTaxCode CreditGrantTaxCodeID | CreditGrantTaxCodeReferenceToIDString
59+ // goverter:ignore Expand
60+ FromAPIUpdateOrganizationDefaultTaxCodesRequest func (namespace string , body api.UpdateOrganizationDefaultTaxCodesRequest ) (taxcode.UpsertOrganizationDefaultTaxCodesInput , error )
4361)
4462
4563var ConvertLabelsToMetadata = labels .ToMetadata
@@ -76,6 +94,24 @@ func ToAPIBillingAppType(source app.AppType) api.BillingAppType {
7694 return api .BillingAppType (source )
7795}
7896
97+ func IDStringToTaxCodeReference (id string ) api.TaxCodeReference {
98+ return api.TaxCodeReference {Id : id }
99+ }
100+
101+ func InvoicingTaxCodeReferenceToIDString (ref * api.TaxCodeReference ) (string , error ) {
102+ if ref == nil || ref .Id == "" {
103+ return "" , models .NewGenericValidationError (errors .New ("invoicing_tax_code.id is required" ))
104+ }
105+ return ref .Id , nil
106+ }
107+
108+ func CreditGrantTaxCodeReferenceToIDString (ref * api.TaxCodeReference ) (string , error ) {
109+ if ref == nil || ref .Id == "" {
110+ return "" , models .NewGenericValidationError (errors .New ("credit_grant_tax_code.id is required" ))
111+ }
112+ return ref .Id , nil
113+ }
114+
79115// ToAPIBillingTaxCodeAppMappings converts domain app mappings to API app mappings.
80116// Ensures that nil is converted to an empty array instead of null.
81117func ToAPIBillingTaxCodeAppMappings (source taxcode.TaxCodeAppMappings ) []api.BillingTaxCodeAppMapping {
0 commit comments