From 63a6e2228d518da523a16becf642beed7784b2af Mon Sep 17 00:00:00 2001 From: Peter Turi Date: Thu, 16 Jul 2026 07:11:44 +0200 Subject: [PATCH 1/4] feat: add gathering invoice line schema --- .../ent/db/billinggatheringinvoiceline.go | 639 +++ .../billinggatheringinvoiceline.go | 503 +++ .../db/billinggatheringinvoiceline/where.go | 1835 +++++++++ .../db/billinggatheringinvoiceline_create.go | 2664 ++++++++++++ .../db/billinggatheringinvoiceline_delete.go | 88 + .../db/billinggatheringinvoiceline_query.go | 1111 +++++ .../db/billinggatheringinvoiceline_update.go | 2004 ++++++++++ openmeter/ent/db/billinginvoice.go | 34 +- .../ent/db/billinginvoice/billinginvoice.go | 30 + openmeter/ent/db/billinginvoice/where.go | 23 + openmeter/ent/db/billinginvoice_create.go | 32 + openmeter/ent/db/billinginvoice_query.go | 78 +- openmeter/ent/db/billinginvoice_update.go | 163 + .../ent/db/billinginvoicesplitlinegroup.go | 26 +- .../billinginvoicesplitlinegroup.go | 30 + .../db/billinginvoicesplitlinegroup/where.go | 23 + .../db/billinginvoicesplitlinegroup_create.go | 32 + .../db/billinginvoicesplitlinegroup_query.go | 123 +- .../db/billinginvoicesplitlinegroup_update.go | 163 + openmeter/ent/db/charge.go | 22 +- openmeter/ent/db/charge/charge.go | 30 + openmeter/ent/db/charge/where.go | 23 + openmeter/ent/db/charge_create.go | 32 + openmeter/ent/db/charge_query.go | 125 +- openmeter/ent/db/charge_update.go | 163 + openmeter/ent/db/client.go | 379 +- openmeter/ent/db/cursor.go | 51 + openmeter/ent/db/ent.go | 2 + openmeter/ent/db/entmixinaccessor.go | 104 + openmeter/ent/db/expose.go | 2 + openmeter/ent/db/hook/hook.go | 12 + openmeter/ent/db/migrate/schema.go | 153 + openmeter/ent/db/mutation.go | 3561 ++++++++++++++++- openmeter/ent/db/paginate.go | 58 + openmeter/ent/db/predicate/predicate.go | 14 + openmeter/ent/db/runtime.go | 39 + openmeter/ent/db/setorclear.go | 252 ++ openmeter/ent/db/subscription.go | 30 +- openmeter/ent/db/subscription/subscription.go | 30 + openmeter/ent/db/subscription/where.go | 23 + openmeter/ent/db/subscription_create.go | 32 + openmeter/ent/db/subscription_query.go | 141 +- openmeter/ent/db/subscription_update.go | 163 + openmeter/ent/db/subscriptionitem.go | 28 +- .../db/subscriptionitem/subscriptionitem.go | 30 + openmeter/ent/db/subscriptionitem/where.go | 23 + openmeter/ent/db/subscriptionitem_create.go | 32 + openmeter/ent/db/subscriptionitem_query.go | 133 +- openmeter/ent/db/subscriptionitem_update.go | 163 + openmeter/ent/db/subscriptionphase.go | 26 +- .../db/subscriptionphase/subscriptionphase.go | 30 + openmeter/ent/db/subscriptionphase/where.go | 23 + openmeter/ent/db/subscriptionphase_create.go | 32 + openmeter/ent/db/subscriptionphase_query.go | 129 +- openmeter/ent/db/subscriptionphase_update.go | 163 + openmeter/ent/db/taxcode.go | 38 +- openmeter/ent/db/taxcode/taxcode.go | 30 + openmeter/ent/db/taxcode/where.go | 23 + openmeter/ent/db/taxcode_create.go | 32 + openmeter/ent/db/taxcode_query.go | 81 +- openmeter/ent/db/taxcode_update.go | 163 + openmeter/ent/db/tx.go | 3 + openmeter/ent/schema/billing.go | 175 + openmeter/ent/schema/charges.go | 2 + openmeter/ent/schema/subscription.go | 6 + openmeter/ent/schema/taxcode.go | 2 + ...e_billing_gathering_invoice_lines.down.sql | 22 + ...ate_billing_gathering_invoice_lines.up.sql | 63 + tools/migrate/migrations/atlas.sum | 3 +- 69 files changed, 16146 insertions(+), 351 deletions(-) create mode 100644 openmeter/ent/db/billinggatheringinvoiceline.go create mode 100644 openmeter/ent/db/billinggatheringinvoiceline/billinggatheringinvoiceline.go create mode 100644 openmeter/ent/db/billinggatheringinvoiceline/where.go create mode 100644 openmeter/ent/db/billinggatheringinvoiceline_create.go create mode 100644 openmeter/ent/db/billinggatheringinvoiceline_delete.go create mode 100644 openmeter/ent/db/billinggatheringinvoiceline_query.go create mode 100644 openmeter/ent/db/billinggatheringinvoiceline_update.go create mode 100644 tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.down.sql create mode 100644 tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.up.sql diff --git a/openmeter/ent/db/billinggatheringinvoiceline.go b/openmeter/ent/db/billinggatheringinvoiceline.go new file mode 100644 index 0000000000..d165ecd7de --- /dev/null +++ b/openmeter/ent/db/billinggatheringinvoiceline.go @@ -0,0 +1,639 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "encoding/json" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/openmeterio/openmeter/openmeter/billing" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" + "github.com/openmeterio/openmeter/openmeter/ent/db/charge" + "github.com/openmeterio/openmeter/openmeter/ent/db/subscription" + "github.com/openmeterio/openmeter/openmeter/ent/db/subscriptionitem" + "github.com/openmeterio/openmeter/openmeter/ent/db/subscriptionphase" + dbtaxcode "github.com/openmeterio/openmeter/openmeter/ent/db/taxcode" + "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/pkg/currencyx" + "github.com/openmeterio/openmeter/pkg/models" +) + +// BillingGatheringInvoiceLine is the model entity for the BillingGatheringInvoiceLine schema. +type BillingGatheringInvoiceLine struct { + config `json:"-"` + // ID of the ent. + ID string `json:"id,omitempty"` + // Annotations holds the value of the "annotations" field. + Annotations models.Annotations `json:"annotations,omitempty"` + // Namespace holds the value of the "namespace" field. + Namespace string `json:"namespace,omitempty"` + // Metadata holds the value of the "metadata" field. + Metadata map[string]string `json:"metadata,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // DeletedAt holds the value of the "deleted_at" field. + DeletedAt *time.Time `json:"deleted_at,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` + // Description holds the value of the "description" field. + Description *string `json:"description,omitempty"` + // Currency holds the value of the "currency" field. + Currency currencyx.Code `json:"currency,omitempty"` + // ServicePeriodStart holds the value of the "service_period_start" field. + ServicePeriodStart time.Time `json:"service_period_start,omitempty"` + // ServicePeriodEnd holds the value of the "service_period_end" field. + ServicePeriodEnd time.Time `json:"service_period_end,omitempty"` + // TaxConfig holds the value of the "tax_config" field. + TaxConfig billing.TaxConfig `json:"tax_config,omitempty"` + // PriceType holds the value of the "price_type" field. + PriceType productcatalog.PriceType `json:"price_type,omitempty"` + // FeatureKey holds the value of the "feature_key" field. + FeatureKey *string `json:"feature_key,omitempty"` + // Price holds the value of the "price" field. + Price *productcatalog.Price `json:"price,omitempty"` + // UnitConfig holds the value of the "unit_config" field. + UnitConfig *productcatalog.UnitConfig `json:"unit_config,omitempty"` + // RatecardDiscounts holds the value of the "ratecard_discounts" field. + RatecardDiscounts *billing.Discounts `json:"ratecard_discounts,omitempty"` + // ChildUniqueReferenceID holds the value of the "child_unique_reference_id" field. + ChildUniqueReferenceID *string `json:"child_unique_reference_id,omitempty"` + // SubscriptionID holds the value of the "subscription_id" field. + SubscriptionID *string `json:"subscription_id,omitempty"` + // SubscriptionPhaseID holds the value of the "subscription_phase_id" field. + SubscriptionPhaseID *string `json:"subscription_phase_id,omitempty"` + // SubscriptionItemID holds the value of the "subscription_item_id" field. + SubscriptionItemID *string `json:"subscription_item_id,omitempty"` + // SubscriptionBillingPeriodFrom holds the value of the "subscription_billing_period_from" field. + SubscriptionBillingPeriodFrom *time.Time `json:"subscription_billing_period_from,omitempty"` + // SubscriptionBillingPeriodTo holds the value of the "subscription_billing_period_to" field. + SubscriptionBillingPeriodTo *time.Time `json:"subscription_billing_period_to,omitempty"` + // TaxCodeID holds the value of the "tax_code_id" field. + TaxCodeID *string `json:"tax_code_id,omitempty"` + // TaxBehavior holds the value of the "tax_behavior" field. + TaxBehavior *productcatalog.TaxBehavior `json:"tax_behavior,omitempty"` + // InvoiceID holds the value of the "invoice_id" field. + InvoiceID string `json:"invoice_id,omitempty"` + // InvoiceAt holds the value of the "invoice_at" field. + InvoiceAt time.Time `json:"invoice_at,omitempty"` + // ManagedBy holds the value of the "managed_by" field. + ManagedBy billing.InvoiceLineManagedBy `json:"managed_by,omitempty"` + // Engine holds the value of the "engine" field. + Engine billing.LineEngineType `json:"engine,omitempty"` + // SplitLineGroupID holds the value of the "split_line_group_id" field. + SplitLineGroupID *string `json:"split_line_group_id,omitempty"` + // ChargeID holds the value of the "charge_id" field. + ChargeID *string `json:"charge_id,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the BillingGatheringInvoiceLineQuery when eager-loading is set. + Edges BillingGatheringInvoiceLineEdges `json:"edges"` + selectValues sql.SelectValues +} + +// BillingGatheringInvoiceLineEdges holds the relations/edges for other nodes in the graph. +type BillingGatheringInvoiceLineEdges struct { + // BillingInvoice holds the value of the billing_invoice edge. + BillingInvoice *BillingInvoice `json:"billing_invoice,omitempty"` + // SplitLineGroup holds the value of the split_line_group edge. + SplitLineGroup *BillingInvoiceSplitLineGroup `json:"split_line_group,omitempty"` + // Subscription holds the value of the subscription edge. + Subscription *Subscription `json:"subscription,omitempty"` + // SubscriptionPhase holds the value of the subscription_phase edge. + SubscriptionPhase *SubscriptionPhase `json:"subscription_phase,omitempty"` + // SubscriptionItem holds the value of the subscription_item edge. + SubscriptionItem *SubscriptionItem `json:"subscription_item,omitempty"` + // Charge holds the value of the charge edge. + Charge *Charge `json:"charge,omitempty"` + // TaxCode holds the value of the tax_code edge. + TaxCode *TaxCode `json:"tax_code,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [7]bool +} + +// BillingInvoiceOrErr returns the BillingInvoice value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e BillingGatheringInvoiceLineEdges) BillingInvoiceOrErr() (*BillingInvoice, error) { + if e.BillingInvoice != nil { + return e.BillingInvoice, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: billinginvoice.Label} + } + return nil, &NotLoadedError{edge: "billing_invoice"} +} + +// SplitLineGroupOrErr returns the SplitLineGroup value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e BillingGatheringInvoiceLineEdges) SplitLineGroupOrErr() (*BillingInvoiceSplitLineGroup, error) { + if e.SplitLineGroup != nil { + return e.SplitLineGroup, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: billinginvoicesplitlinegroup.Label} + } + return nil, &NotLoadedError{edge: "split_line_group"} +} + +// SubscriptionOrErr returns the Subscription value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e BillingGatheringInvoiceLineEdges) SubscriptionOrErr() (*Subscription, error) { + if e.Subscription != nil { + return e.Subscription, nil + } else if e.loadedTypes[2] { + return nil, &NotFoundError{label: subscription.Label} + } + return nil, &NotLoadedError{edge: "subscription"} +} + +// SubscriptionPhaseOrErr returns the SubscriptionPhase value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e BillingGatheringInvoiceLineEdges) SubscriptionPhaseOrErr() (*SubscriptionPhase, error) { + if e.SubscriptionPhase != nil { + return e.SubscriptionPhase, nil + } else if e.loadedTypes[3] { + return nil, &NotFoundError{label: subscriptionphase.Label} + } + return nil, &NotLoadedError{edge: "subscription_phase"} +} + +// SubscriptionItemOrErr returns the SubscriptionItem value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e BillingGatheringInvoiceLineEdges) SubscriptionItemOrErr() (*SubscriptionItem, error) { + if e.SubscriptionItem != nil { + return e.SubscriptionItem, nil + } else if e.loadedTypes[4] { + return nil, &NotFoundError{label: subscriptionitem.Label} + } + return nil, &NotLoadedError{edge: "subscription_item"} +} + +// ChargeOrErr returns the Charge value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e BillingGatheringInvoiceLineEdges) ChargeOrErr() (*Charge, error) { + if e.Charge != nil { + return e.Charge, nil + } else if e.loadedTypes[5] { + return nil, &NotFoundError{label: charge.Label} + } + return nil, &NotLoadedError{edge: "charge"} +} + +// TaxCodeOrErr returns the TaxCode value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e BillingGatheringInvoiceLineEdges) TaxCodeOrErr() (*TaxCode, error) { + if e.TaxCode != nil { + return e.TaxCode, nil + } else if e.loadedTypes[6] { + return nil, &NotFoundError{label: dbtaxcode.Label} + } + return nil, &NotLoadedError{edge: "tax_code"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*BillingGatheringInvoiceLine) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case billinggatheringinvoiceline.FieldAnnotations, billinggatheringinvoiceline.FieldMetadata, billinggatheringinvoiceline.FieldTaxConfig: + values[i] = new([]byte) + case billinggatheringinvoiceline.FieldID, billinggatheringinvoiceline.FieldNamespace, billinggatheringinvoiceline.FieldName, billinggatheringinvoiceline.FieldDescription, billinggatheringinvoiceline.FieldCurrency, billinggatheringinvoiceline.FieldPriceType, billinggatheringinvoiceline.FieldFeatureKey, billinggatheringinvoiceline.FieldChildUniqueReferenceID, billinggatheringinvoiceline.FieldSubscriptionID, billinggatheringinvoiceline.FieldSubscriptionPhaseID, billinggatheringinvoiceline.FieldSubscriptionItemID, billinggatheringinvoiceline.FieldTaxCodeID, billinggatheringinvoiceline.FieldTaxBehavior, billinggatheringinvoiceline.FieldInvoiceID, billinggatheringinvoiceline.FieldManagedBy, billinggatheringinvoiceline.FieldEngine, billinggatheringinvoiceline.FieldSplitLineGroupID, billinggatheringinvoiceline.FieldChargeID: + values[i] = new(sql.NullString) + case billinggatheringinvoiceline.FieldCreatedAt, billinggatheringinvoiceline.FieldUpdatedAt, billinggatheringinvoiceline.FieldDeletedAt, billinggatheringinvoiceline.FieldServicePeriodStart, billinggatheringinvoiceline.FieldServicePeriodEnd, billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom, billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo, billinggatheringinvoiceline.FieldInvoiceAt: + values[i] = new(sql.NullTime) + case billinggatheringinvoiceline.FieldPrice: + values[i] = billinggatheringinvoiceline.ValueScanner.Price.ScanValue() + case billinggatheringinvoiceline.FieldUnitConfig: + values[i] = billinggatheringinvoiceline.ValueScanner.UnitConfig.ScanValue() + case billinggatheringinvoiceline.FieldRatecardDiscounts: + values[i] = billinggatheringinvoiceline.ValueScanner.RatecardDiscounts.ScanValue() + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the BillingGatheringInvoiceLine fields. +func (_m *BillingGatheringInvoiceLine) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case billinggatheringinvoiceline.FieldID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value.Valid { + _m.ID = value.String + } + case billinggatheringinvoiceline.FieldAnnotations: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field annotations", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.Annotations); err != nil { + return fmt.Errorf("unmarshal field annotations: %w", err) + } + } + case billinggatheringinvoiceline.FieldNamespace: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field namespace", values[i]) + } else if value.Valid { + _m.Namespace = value.String + } + case billinggatheringinvoiceline.FieldMetadata: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field metadata", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.Metadata); err != nil { + return fmt.Errorf("unmarshal field metadata: %w", err) + } + } + case billinggatheringinvoiceline.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + case billinggatheringinvoiceline.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Time + } + case billinggatheringinvoiceline.FieldDeletedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field deleted_at", values[i]) + } else if value.Valid { + _m.DeletedAt = new(time.Time) + *_m.DeletedAt = value.Time + } + case billinggatheringinvoiceline.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case billinggatheringinvoiceline.FieldDescription: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field description", values[i]) + } else if value.Valid { + _m.Description = new(string) + *_m.Description = value.String + } + case billinggatheringinvoiceline.FieldCurrency: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field currency", values[i]) + } else if value.Valid { + _m.Currency = currencyx.Code(value.String) + } + case billinggatheringinvoiceline.FieldServicePeriodStart: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field service_period_start", values[i]) + } else if value.Valid { + _m.ServicePeriodStart = value.Time + } + case billinggatheringinvoiceline.FieldServicePeriodEnd: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field service_period_end", values[i]) + } else if value.Valid { + _m.ServicePeriodEnd = value.Time + } + case billinggatheringinvoiceline.FieldTaxConfig: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field tax_config", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.TaxConfig); err != nil { + return fmt.Errorf("unmarshal field tax_config: %w", err) + } + } + case billinggatheringinvoiceline.FieldPriceType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field price_type", values[i]) + } else if value.Valid { + _m.PriceType = productcatalog.PriceType(value.String) + } + case billinggatheringinvoiceline.FieldFeatureKey: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field feature_key", values[i]) + } else if value.Valid { + _m.FeatureKey = new(string) + *_m.FeatureKey = value.String + } + case billinggatheringinvoiceline.FieldPrice: + if value, err := billinggatheringinvoiceline.ValueScanner.Price.FromValue(values[i]); err != nil { + return err + } else { + _m.Price = value + } + case billinggatheringinvoiceline.FieldUnitConfig: + if value, err := billinggatheringinvoiceline.ValueScanner.UnitConfig.FromValue(values[i]); err != nil { + return err + } else { + _m.UnitConfig = value + } + case billinggatheringinvoiceline.FieldRatecardDiscounts: + if value, err := billinggatheringinvoiceline.ValueScanner.RatecardDiscounts.FromValue(values[i]); err != nil { + return err + } else { + _m.RatecardDiscounts = value + } + case billinggatheringinvoiceline.FieldChildUniqueReferenceID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field child_unique_reference_id", values[i]) + } else if value.Valid { + _m.ChildUniqueReferenceID = new(string) + *_m.ChildUniqueReferenceID = value.String + } + case billinggatheringinvoiceline.FieldSubscriptionID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field subscription_id", values[i]) + } else if value.Valid { + _m.SubscriptionID = new(string) + *_m.SubscriptionID = value.String + } + case billinggatheringinvoiceline.FieldSubscriptionPhaseID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field subscription_phase_id", values[i]) + } else if value.Valid { + _m.SubscriptionPhaseID = new(string) + *_m.SubscriptionPhaseID = value.String + } + case billinggatheringinvoiceline.FieldSubscriptionItemID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field subscription_item_id", values[i]) + } else if value.Valid { + _m.SubscriptionItemID = new(string) + *_m.SubscriptionItemID = value.String + } + case billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field subscription_billing_period_from", values[i]) + } else if value.Valid { + _m.SubscriptionBillingPeriodFrom = new(time.Time) + *_m.SubscriptionBillingPeriodFrom = value.Time + } + case billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field subscription_billing_period_to", values[i]) + } else if value.Valid { + _m.SubscriptionBillingPeriodTo = new(time.Time) + *_m.SubscriptionBillingPeriodTo = value.Time + } + case billinggatheringinvoiceline.FieldTaxCodeID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field tax_code_id", values[i]) + } else if value.Valid { + _m.TaxCodeID = new(string) + *_m.TaxCodeID = value.String + } + case billinggatheringinvoiceline.FieldTaxBehavior: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field tax_behavior", values[i]) + } else if value.Valid { + _m.TaxBehavior = new(productcatalog.TaxBehavior) + *_m.TaxBehavior = productcatalog.TaxBehavior(value.String) + } + case billinggatheringinvoiceline.FieldInvoiceID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field invoice_id", values[i]) + } else if value.Valid { + _m.InvoiceID = value.String + } + case billinggatheringinvoiceline.FieldInvoiceAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field invoice_at", values[i]) + } else if value.Valid { + _m.InvoiceAt = value.Time + } + case billinggatheringinvoiceline.FieldManagedBy: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field managed_by", values[i]) + } else if value.Valid { + _m.ManagedBy = billing.InvoiceLineManagedBy(value.String) + } + case billinggatheringinvoiceline.FieldEngine: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field engine", values[i]) + } else if value.Valid { + _m.Engine = billing.LineEngineType(value.String) + } + case billinggatheringinvoiceline.FieldSplitLineGroupID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field split_line_group_id", values[i]) + } else if value.Valid { + _m.SplitLineGroupID = new(string) + *_m.SplitLineGroupID = value.String + } + case billinggatheringinvoiceline.FieldChargeID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field charge_id", values[i]) + } else if value.Valid { + _m.ChargeID = new(string) + *_m.ChargeID = value.String + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the BillingGatheringInvoiceLine. +// This includes values selected through modifiers, order, etc. +func (_m *BillingGatheringInvoiceLine) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryBillingInvoice queries the "billing_invoice" edge of the BillingGatheringInvoiceLine entity. +func (_m *BillingGatheringInvoiceLine) QueryBillingInvoice() *BillingInvoiceQuery { + return NewBillingGatheringInvoiceLineClient(_m.config).QueryBillingInvoice(_m) +} + +// QuerySplitLineGroup queries the "split_line_group" edge of the BillingGatheringInvoiceLine entity. +func (_m *BillingGatheringInvoiceLine) QuerySplitLineGroup() *BillingInvoiceSplitLineGroupQuery { + return NewBillingGatheringInvoiceLineClient(_m.config).QuerySplitLineGroup(_m) +} + +// QuerySubscription queries the "subscription" edge of the BillingGatheringInvoiceLine entity. +func (_m *BillingGatheringInvoiceLine) QuerySubscription() *SubscriptionQuery { + return NewBillingGatheringInvoiceLineClient(_m.config).QuerySubscription(_m) +} + +// QuerySubscriptionPhase queries the "subscription_phase" edge of the BillingGatheringInvoiceLine entity. +func (_m *BillingGatheringInvoiceLine) QuerySubscriptionPhase() *SubscriptionPhaseQuery { + return NewBillingGatheringInvoiceLineClient(_m.config).QuerySubscriptionPhase(_m) +} + +// QuerySubscriptionItem queries the "subscription_item" edge of the BillingGatheringInvoiceLine entity. +func (_m *BillingGatheringInvoiceLine) QuerySubscriptionItem() *SubscriptionItemQuery { + return NewBillingGatheringInvoiceLineClient(_m.config).QuerySubscriptionItem(_m) +} + +// QueryCharge queries the "charge" edge of the BillingGatheringInvoiceLine entity. +func (_m *BillingGatheringInvoiceLine) QueryCharge() *ChargeQuery { + return NewBillingGatheringInvoiceLineClient(_m.config).QueryCharge(_m) +} + +// QueryTaxCode queries the "tax_code" edge of the BillingGatheringInvoiceLine entity. +func (_m *BillingGatheringInvoiceLine) QueryTaxCode() *TaxCodeQuery { + return NewBillingGatheringInvoiceLineClient(_m.config).QueryTaxCode(_m) +} + +// Update returns a builder for updating this BillingGatheringInvoiceLine. +// Note that you need to call BillingGatheringInvoiceLine.Unwrap() before calling this method if this BillingGatheringInvoiceLine +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *BillingGatheringInvoiceLine) Update() *BillingGatheringInvoiceLineUpdateOne { + return NewBillingGatheringInvoiceLineClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the BillingGatheringInvoiceLine entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *BillingGatheringInvoiceLine) Unwrap() *BillingGatheringInvoiceLine { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("db: BillingGatheringInvoiceLine is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *BillingGatheringInvoiceLine) String() string { + var builder strings.Builder + builder.WriteString("BillingGatheringInvoiceLine(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("annotations=") + builder.WriteString(fmt.Sprintf("%v", _m.Annotations)) + builder.WriteString(", ") + builder.WriteString("namespace=") + builder.WriteString(_m.Namespace) + builder.WriteString(", ") + builder.WriteString("metadata=") + builder.WriteString(fmt.Sprintf("%v", _m.Metadata)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + if v := _m.DeletedAt; v != nil { + builder.WriteString("deleted_at=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + if v := _m.Description; v != nil { + builder.WriteString("description=") + builder.WriteString(*v) + } + builder.WriteString(", ") + builder.WriteString("currency=") + builder.WriteString(fmt.Sprintf("%v", _m.Currency)) + builder.WriteString(", ") + builder.WriteString("service_period_start=") + builder.WriteString(_m.ServicePeriodStart.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("service_period_end=") + builder.WriteString(_m.ServicePeriodEnd.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("tax_config=") + builder.WriteString(fmt.Sprintf("%v", _m.TaxConfig)) + builder.WriteString(", ") + builder.WriteString("price_type=") + builder.WriteString(fmt.Sprintf("%v", _m.PriceType)) + builder.WriteString(", ") + if v := _m.FeatureKey; v != nil { + builder.WriteString("feature_key=") + builder.WriteString(*v) + } + builder.WriteString(", ") + builder.WriteString("price=") + builder.WriteString(fmt.Sprintf("%v", _m.Price)) + builder.WriteString(", ") + if v := _m.UnitConfig; v != nil { + builder.WriteString("unit_config=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + if v := _m.RatecardDiscounts; v != nil { + builder.WriteString("ratecard_discounts=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + if v := _m.ChildUniqueReferenceID; v != nil { + builder.WriteString("child_unique_reference_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.SubscriptionID; v != nil { + builder.WriteString("subscription_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.SubscriptionPhaseID; v != nil { + builder.WriteString("subscription_phase_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.SubscriptionItemID; v != nil { + builder.WriteString("subscription_item_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.SubscriptionBillingPeriodFrom; v != nil { + builder.WriteString("subscription_billing_period_from=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteString(", ") + if v := _m.SubscriptionBillingPeriodTo; v != nil { + builder.WriteString("subscription_billing_period_to=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteString(", ") + if v := _m.TaxCodeID; v != nil { + builder.WriteString("tax_code_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.TaxBehavior; v != nil { + builder.WriteString("tax_behavior=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + builder.WriteString("invoice_id=") + builder.WriteString(_m.InvoiceID) + builder.WriteString(", ") + builder.WriteString("invoice_at=") + builder.WriteString(_m.InvoiceAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("managed_by=") + builder.WriteString(fmt.Sprintf("%v", _m.ManagedBy)) + builder.WriteString(", ") + builder.WriteString("engine=") + builder.WriteString(fmt.Sprintf("%v", _m.Engine)) + builder.WriteString(", ") + if v := _m.SplitLineGroupID; v != nil { + builder.WriteString("split_line_group_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.ChargeID; v != nil { + builder.WriteString("charge_id=") + builder.WriteString(*v) + } + builder.WriteByte(')') + return builder.String() +} + +// BillingGatheringInvoiceLines is a parsable slice of BillingGatheringInvoiceLine. +type BillingGatheringInvoiceLines []*BillingGatheringInvoiceLine diff --git a/openmeter/ent/db/billinggatheringinvoiceline/billinggatheringinvoiceline.go b/openmeter/ent/db/billinggatheringinvoiceline/billinggatheringinvoiceline.go new file mode 100644 index 0000000000..a612174d54 --- /dev/null +++ b/openmeter/ent/db/billinggatheringinvoiceline/billinggatheringinvoiceline.go @@ -0,0 +1,503 @@ +// Code generated by ent, DO NOT EDIT. + +package billinggatheringinvoiceline + +import ( + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/billing" + "github.com/openmeterio/openmeter/openmeter/productcatalog" +) + +const ( + // Label holds the string label denoting the billinggatheringinvoiceline type in the database. + Label = "billing_gathering_invoice_line" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldAnnotations holds the string denoting the annotations field in the database. + FieldAnnotations = "annotations" + // FieldNamespace holds the string denoting the namespace field in the database. + FieldNamespace = "namespace" + // FieldMetadata holds the string denoting the metadata field in the database. + FieldMetadata = "metadata" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // FieldDeletedAt holds the string denoting the deleted_at field in the database. + FieldDeletedAt = "deleted_at" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldDescription holds the string denoting the description field in the database. + FieldDescription = "description" + // FieldCurrency holds the string denoting the currency field in the database. + FieldCurrency = "currency" + // FieldServicePeriodStart holds the string denoting the service_period_start field in the database. + FieldServicePeriodStart = "service_period_start" + // FieldServicePeriodEnd holds the string denoting the service_period_end field in the database. + FieldServicePeriodEnd = "service_period_end" + // FieldTaxConfig holds the string denoting the tax_config field in the database. + FieldTaxConfig = "tax_config" + // FieldPriceType holds the string denoting the price_type field in the database. + FieldPriceType = "price_type" + // FieldFeatureKey holds the string denoting the feature_key field in the database. + FieldFeatureKey = "feature_key" + // FieldPrice holds the string denoting the price field in the database. + FieldPrice = "price" + // FieldUnitConfig holds the string denoting the unit_config field in the database. + FieldUnitConfig = "unit_config" + // FieldRatecardDiscounts holds the string denoting the ratecard_discounts field in the database. + FieldRatecardDiscounts = "ratecard_discounts" + // FieldChildUniqueReferenceID holds the string denoting the child_unique_reference_id field in the database. + FieldChildUniqueReferenceID = "child_unique_reference_id" + // FieldSubscriptionID holds the string denoting the subscription_id field in the database. + FieldSubscriptionID = "subscription_id" + // FieldSubscriptionPhaseID holds the string denoting the subscription_phase_id field in the database. + FieldSubscriptionPhaseID = "subscription_phase_id" + // FieldSubscriptionItemID holds the string denoting the subscription_item_id field in the database. + FieldSubscriptionItemID = "subscription_item_id" + // FieldSubscriptionBillingPeriodFrom holds the string denoting the subscription_billing_period_from field in the database. + FieldSubscriptionBillingPeriodFrom = "subscription_billing_period_from" + // FieldSubscriptionBillingPeriodTo holds the string denoting the subscription_billing_period_to field in the database. + FieldSubscriptionBillingPeriodTo = "subscription_billing_period_to" + // FieldTaxCodeID holds the string denoting the tax_code_id field in the database. + FieldTaxCodeID = "tax_code_id" + // FieldTaxBehavior holds the string denoting the tax_behavior field in the database. + FieldTaxBehavior = "tax_behavior" + // FieldInvoiceID holds the string denoting the invoice_id field in the database. + FieldInvoiceID = "invoice_id" + // FieldInvoiceAt holds the string denoting the invoice_at field in the database. + FieldInvoiceAt = "invoice_at" + // FieldManagedBy holds the string denoting the managed_by field in the database. + FieldManagedBy = "managed_by" + // FieldEngine holds the string denoting the engine field in the database. + FieldEngine = "engine" + // FieldSplitLineGroupID holds the string denoting the split_line_group_id field in the database. + FieldSplitLineGroupID = "split_line_group_id" + // FieldChargeID holds the string denoting the charge_id field in the database. + FieldChargeID = "charge_id" + // EdgeBillingInvoice holds the string denoting the billing_invoice edge name in mutations. + EdgeBillingInvoice = "billing_invoice" + // EdgeSplitLineGroup holds the string denoting the split_line_group edge name in mutations. + EdgeSplitLineGroup = "split_line_group" + // EdgeSubscription holds the string denoting the subscription edge name in mutations. + EdgeSubscription = "subscription" + // EdgeSubscriptionPhase holds the string denoting the subscription_phase edge name in mutations. + EdgeSubscriptionPhase = "subscription_phase" + // EdgeSubscriptionItem holds the string denoting the subscription_item edge name in mutations. + EdgeSubscriptionItem = "subscription_item" + // EdgeCharge holds the string denoting the charge edge name in mutations. + EdgeCharge = "charge" + // EdgeTaxCode holds the string denoting the tax_code edge name in mutations. + EdgeTaxCode = "tax_code" + // Table holds the table name of the billinggatheringinvoiceline in the database. + Table = "billing_gathering_invoice_lines" + // BillingInvoiceTable is the table that holds the billing_invoice relation/edge. + BillingInvoiceTable = "billing_gathering_invoice_lines" + // BillingInvoiceInverseTable is the table name for the BillingInvoice entity. + // It exists in this package in order to avoid circular dependency with the "billinginvoice" package. + BillingInvoiceInverseTable = "billing_invoices" + // BillingInvoiceColumn is the table column denoting the billing_invoice relation/edge. + BillingInvoiceColumn = "invoice_id" + // SplitLineGroupTable is the table that holds the split_line_group relation/edge. + SplitLineGroupTable = "billing_gathering_invoice_lines" + // SplitLineGroupInverseTable is the table name for the BillingInvoiceSplitLineGroup entity. + // It exists in this package in order to avoid circular dependency with the "billinginvoicesplitlinegroup" package. + SplitLineGroupInverseTable = "billing_invoice_split_line_groups" + // SplitLineGroupColumn is the table column denoting the split_line_group relation/edge. + SplitLineGroupColumn = "split_line_group_id" + // SubscriptionTable is the table that holds the subscription relation/edge. + SubscriptionTable = "billing_gathering_invoice_lines" + // SubscriptionInverseTable is the table name for the Subscription entity. + // It exists in this package in order to avoid circular dependency with the "subscription" package. + SubscriptionInverseTable = "subscriptions" + // SubscriptionColumn is the table column denoting the subscription relation/edge. + SubscriptionColumn = "subscription_id" + // SubscriptionPhaseTable is the table that holds the subscription_phase relation/edge. + SubscriptionPhaseTable = "billing_gathering_invoice_lines" + // SubscriptionPhaseInverseTable is the table name for the SubscriptionPhase entity. + // It exists in this package in order to avoid circular dependency with the "subscriptionphase" package. + SubscriptionPhaseInverseTable = "subscription_phases" + // SubscriptionPhaseColumn is the table column denoting the subscription_phase relation/edge. + SubscriptionPhaseColumn = "subscription_phase_id" + // SubscriptionItemTable is the table that holds the subscription_item relation/edge. + SubscriptionItemTable = "billing_gathering_invoice_lines" + // SubscriptionItemInverseTable is the table name for the SubscriptionItem entity. + // It exists in this package in order to avoid circular dependency with the "subscriptionitem" package. + SubscriptionItemInverseTable = "subscription_items" + // SubscriptionItemColumn is the table column denoting the subscription_item relation/edge. + SubscriptionItemColumn = "subscription_item_id" + // ChargeTable is the table that holds the charge relation/edge. + ChargeTable = "billing_gathering_invoice_lines" + // ChargeInverseTable is the table name for the Charge entity. + // It exists in this package in order to avoid circular dependency with the "charge" package. + ChargeInverseTable = "charges" + // ChargeColumn is the table column denoting the charge relation/edge. + ChargeColumn = "charge_id" + // TaxCodeTable is the table that holds the tax_code relation/edge. + TaxCodeTable = "billing_gathering_invoice_lines" + // TaxCodeInverseTable is the table name for the TaxCode entity. + // It exists in this package in order to avoid circular dependency with the "dbtaxcode" package. + TaxCodeInverseTable = "tax_codes" + // TaxCodeColumn is the table column denoting the tax_code relation/edge. + TaxCodeColumn = "tax_code_id" +) + +// Columns holds all SQL columns for billinggatheringinvoiceline fields. +var Columns = []string{ + FieldID, + FieldAnnotations, + FieldNamespace, + FieldMetadata, + FieldCreatedAt, + FieldUpdatedAt, + FieldDeletedAt, + FieldName, + FieldDescription, + FieldCurrency, + FieldServicePeriodStart, + FieldServicePeriodEnd, + FieldTaxConfig, + FieldPriceType, + FieldFeatureKey, + FieldPrice, + FieldUnitConfig, + FieldRatecardDiscounts, + FieldChildUniqueReferenceID, + FieldSubscriptionID, + FieldSubscriptionPhaseID, + FieldSubscriptionItemID, + FieldSubscriptionBillingPeriodFrom, + FieldSubscriptionBillingPeriodTo, + FieldTaxCodeID, + FieldTaxBehavior, + FieldInvoiceID, + FieldInvoiceAt, + FieldManagedBy, + FieldEngine, + FieldSplitLineGroupID, + FieldChargeID, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // NamespaceValidator is a validator for the "namespace" field. It is called by the builders before save. + NamespaceValidator func(string) error + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // CurrencyValidator is a validator for the "currency" field. It is called by the builders before save. + CurrencyValidator func(string) error + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() string + // ValueScanner of all BillingGatheringInvoiceLine fields. + ValueScanner struct { + Price field.TypeValueScanner[*productcatalog.Price] + UnitConfig field.TypeValueScanner[*productcatalog.UnitConfig] + RatecardDiscounts field.TypeValueScanner[*billing.Discounts] + } +) + +// PriceTypeValidator is a validator for the "price_type" field enum values. It is called by the builders before save. +func PriceTypeValidator(pt productcatalog.PriceType) error { + switch pt { + case "flat", "unit", "tiered", "dynamic", "package": + return nil + default: + return fmt.Errorf("billinggatheringinvoiceline: invalid enum value for price_type field: %q", pt) + } +} + +// TaxBehaviorValidator is a validator for the "tax_behavior" field enum values. It is called by the builders before save. +func TaxBehaviorValidator(tb productcatalog.TaxBehavior) error { + switch tb { + case "inclusive", "exclusive": + return nil + default: + return fmt.Errorf("billinggatheringinvoiceline: invalid enum value for tax_behavior field: %q", tb) + } +} + +// ManagedByValidator is a validator for the "managed_by" field enum values. It is called by the builders before save. +func ManagedByValidator(mb billing.InvoiceLineManagedBy) error { + switch mb { + case "subscription", "system", "manual": + return nil + default: + return fmt.Errorf("billinggatheringinvoiceline: invalid enum value for managed_by field: %q", mb) + } +} + +const DefaultEngine billing.LineEngineType = "invoicing" + +// EngineValidator is a validator for the "engine" field enum values. It is called by the builders before save. +func EngineValidator(e billing.LineEngineType) error { + switch e { + case "invoicing", "charge_flatfee", "charge_usagebased", "charge_creditpurchase": + return nil + default: + return fmt.Errorf("billinggatheringinvoiceline: invalid enum value for engine field: %q", e) + } +} + +// OrderOption defines the ordering options for the BillingGatheringInvoiceLine queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByNamespace orders the results by the namespace field. +func ByNamespace(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNamespace, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByDeletedAt orders the results by the deleted_at field. +func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByDescription orders the results by the description field. +func ByDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDescription, opts...).ToFunc() +} + +// ByCurrency orders the results by the currency field. +func ByCurrency(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCurrency, opts...).ToFunc() +} + +// ByServicePeriodStart orders the results by the service_period_start field. +func ByServicePeriodStart(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldServicePeriodStart, opts...).ToFunc() +} + +// ByServicePeriodEnd orders the results by the service_period_end field. +func ByServicePeriodEnd(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldServicePeriodEnd, opts...).ToFunc() +} + +// ByPriceType orders the results by the price_type field. +func ByPriceType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPriceType, opts...).ToFunc() +} + +// ByFeatureKey orders the results by the feature_key field. +func ByFeatureKey(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldFeatureKey, opts...).ToFunc() +} + +// ByPrice orders the results by the price field. +func ByPrice(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPrice, opts...).ToFunc() +} + +// ByUnitConfig orders the results by the unit_config field. +func ByUnitConfig(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUnitConfig, opts...).ToFunc() +} + +// ByRatecardDiscounts orders the results by the ratecard_discounts field. +func ByRatecardDiscounts(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRatecardDiscounts, opts...).ToFunc() +} + +// ByChildUniqueReferenceID orders the results by the child_unique_reference_id field. +func ByChildUniqueReferenceID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldChildUniqueReferenceID, opts...).ToFunc() +} + +// BySubscriptionID orders the results by the subscription_id field. +func BySubscriptionID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSubscriptionID, opts...).ToFunc() +} + +// BySubscriptionPhaseID orders the results by the subscription_phase_id field. +func BySubscriptionPhaseID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSubscriptionPhaseID, opts...).ToFunc() +} + +// BySubscriptionItemID orders the results by the subscription_item_id field. +func BySubscriptionItemID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSubscriptionItemID, opts...).ToFunc() +} + +// BySubscriptionBillingPeriodFrom orders the results by the subscription_billing_period_from field. +func BySubscriptionBillingPeriodFrom(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSubscriptionBillingPeriodFrom, opts...).ToFunc() +} + +// BySubscriptionBillingPeriodTo orders the results by the subscription_billing_period_to field. +func BySubscriptionBillingPeriodTo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSubscriptionBillingPeriodTo, opts...).ToFunc() +} + +// ByTaxCodeID orders the results by the tax_code_id field. +func ByTaxCodeID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTaxCodeID, opts...).ToFunc() +} + +// ByTaxBehavior orders the results by the tax_behavior field. +func ByTaxBehavior(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTaxBehavior, opts...).ToFunc() +} + +// ByInvoiceID orders the results by the invoice_id field. +func ByInvoiceID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldInvoiceID, opts...).ToFunc() +} + +// ByInvoiceAt orders the results by the invoice_at field. +func ByInvoiceAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldInvoiceAt, opts...).ToFunc() +} + +// ByManagedBy orders the results by the managed_by field. +func ByManagedBy(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldManagedBy, opts...).ToFunc() +} + +// ByEngine orders the results by the engine field. +func ByEngine(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldEngine, opts...).ToFunc() +} + +// BySplitLineGroupID orders the results by the split_line_group_id field. +func BySplitLineGroupID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSplitLineGroupID, opts...).ToFunc() +} + +// ByChargeID orders the results by the charge_id field. +func ByChargeID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldChargeID, opts...).ToFunc() +} + +// ByBillingInvoiceField orders the results by billing_invoice field. +func ByBillingInvoiceField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newBillingInvoiceStep(), sql.OrderByField(field, opts...)) + } +} + +// BySplitLineGroupField orders the results by split_line_group field. +func BySplitLineGroupField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSplitLineGroupStep(), sql.OrderByField(field, opts...)) + } +} + +// BySubscriptionField orders the results by subscription field. +func BySubscriptionField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSubscriptionStep(), sql.OrderByField(field, opts...)) + } +} + +// BySubscriptionPhaseField orders the results by subscription_phase field. +func BySubscriptionPhaseField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSubscriptionPhaseStep(), sql.OrderByField(field, opts...)) + } +} + +// BySubscriptionItemField orders the results by subscription_item field. +func BySubscriptionItemField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSubscriptionItemStep(), sql.OrderByField(field, opts...)) + } +} + +// ByChargeField orders the results by charge field. +func ByChargeField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newChargeStep(), sql.OrderByField(field, opts...)) + } +} + +// ByTaxCodeField orders the results by tax_code field. +func ByTaxCodeField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTaxCodeStep(), sql.OrderByField(field, opts...)) + } +} +func newBillingInvoiceStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(BillingInvoiceInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, BillingInvoiceTable, BillingInvoiceColumn), + ) +} +func newSplitLineGroupStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SplitLineGroupInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, SplitLineGroupTable, SplitLineGroupColumn), + ) +} +func newSubscriptionStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SubscriptionInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, SubscriptionTable, SubscriptionColumn), + ) +} +func newSubscriptionPhaseStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SubscriptionPhaseInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, SubscriptionPhaseTable, SubscriptionPhaseColumn), + ) +} +func newSubscriptionItemStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SubscriptionItemInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, SubscriptionItemTable, SubscriptionItemColumn), + ) +} +func newChargeStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(ChargeInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ChargeTable, ChargeColumn), + ) +} +func newTaxCodeStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TaxCodeInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, TaxCodeTable, TaxCodeColumn), + ) +} diff --git a/openmeter/ent/db/billinggatheringinvoiceline/where.go b/openmeter/ent/db/billinggatheringinvoiceline/where.go new file mode 100644 index 0000000000..241e525f89 --- /dev/null +++ b/openmeter/ent/db/billinggatheringinvoiceline/where.go @@ -0,0 +1,1835 @@ +// Code generated by ent, DO NOT EDIT. + +package billinggatheringinvoiceline + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/openmeterio/openmeter/openmeter/billing" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" + "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/pkg/currencyx" +) + +// ID filters vertices based on their ID field. +func ID(id string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldID, id)) +} + +// IDEqualFold applies the EqualFold predicate on the ID field. +func IDEqualFold(id string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldID, id)) +} + +// IDContainsFold applies the ContainsFold predicate on the ID field. +func IDContainsFold(id string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldID, id)) +} + +// Namespace applies equality check predicate on the "namespace" field. It's identical to NamespaceEQ. +func Namespace(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldNamespace, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ. +func DeletedAt(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldDeletedAt, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldName, v)) +} + +// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. +func Description(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldDescription, v)) +} + +// Currency applies equality check predicate on the "currency" field. It's identical to CurrencyEQ. +func Currency(v currencyx.Code) predicate.BillingGatheringInvoiceLine { + vc := string(v) + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldCurrency, vc)) +} + +// ServicePeriodStart applies equality check predicate on the "service_period_start" field. It's identical to ServicePeriodStartEQ. +func ServicePeriodStart(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldServicePeriodStart, v)) +} + +// ServicePeriodEnd applies equality check predicate on the "service_period_end" field. It's identical to ServicePeriodEndEQ. +func ServicePeriodEnd(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldServicePeriodEnd, v)) +} + +// FeatureKey applies equality check predicate on the "feature_key" field. It's identical to FeatureKeyEQ. +func FeatureKey(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldFeatureKey, v)) +} + +// ChildUniqueReferenceID applies equality check predicate on the "child_unique_reference_id" field. It's identical to ChildUniqueReferenceIDEQ. +func ChildUniqueReferenceID(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldChildUniqueReferenceID, v)) +} + +// SubscriptionID applies equality check predicate on the "subscription_id" field. It's identical to SubscriptionIDEQ. +func SubscriptionID(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldSubscriptionID, v)) +} + +// SubscriptionPhaseID applies equality check predicate on the "subscription_phase_id" field. It's identical to SubscriptionPhaseIDEQ. +func SubscriptionPhaseID(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldSubscriptionPhaseID, v)) +} + +// SubscriptionItemID applies equality check predicate on the "subscription_item_id" field. It's identical to SubscriptionItemIDEQ. +func SubscriptionItemID(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldSubscriptionItemID, v)) +} + +// SubscriptionBillingPeriodFrom applies equality check predicate on the "subscription_billing_period_from" field. It's identical to SubscriptionBillingPeriodFromEQ. +func SubscriptionBillingPeriodFrom(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldSubscriptionBillingPeriodFrom, v)) +} + +// SubscriptionBillingPeriodTo applies equality check predicate on the "subscription_billing_period_to" field. It's identical to SubscriptionBillingPeriodToEQ. +func SubscriptionBillingPeriodTo(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldSubscriptionBillingPeriodTo, v)) +} + +// TaxCodeID applies equality check predicate on the "tax_code_id" field. It's identical to TaxCodeIDEQ. +func TaxCodeID(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldTaxCodeID, v)) +} + +// InvoiceID applies equality check predicate on the "invoice_id" field. It's identical to InvoiceIDEQ. +func InvoiceID(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldInvoiceID, v)) +} + +// InvoiceAt applies equality check predicate on the "invoice_at" field. It's identical to InvoiceAtEQ. +func InvoiceAt(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldInvoiceAt, v)) +} + +// SplitLineGroupID applies equality check predicate on the "split_line_group_id" field. It's identical to SplitLineGroupIDEQ. +func SplitLineGroupID(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldSplitLineGroupID, v)) +} + +// ChargeID applies equality check predicate on the "charge_id" field. It's identical to ChargeIDEQ. +func ChargeID(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldChargeID, v)) +} + +// AnnotationsIsNil applies the IsNil predicate on the "annotations" field. +func AnnotationsIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldAnnotations)) +} + +// AnnotationsNotNil applies the NotNil predicate on the "annotations" field. +func AnnotationsNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldAnnotations)) +} + +// NamespaceEQ applies the EQ predicate on the "namespace" field. +func NamespaceEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldNamespace, v)) +} + +// NamespaceNEQ applies the NEQ predicate on the "namespace" field. +func NamespaceNEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldNamespace, v)) +} + +// NamespaceIn applies the In predicate on the "namespace" field. +func NamespaceIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldNamespace, vs...)) +} + +// NamespaceNotIn applies the NotIn predicate on the "namespace" field. +func NamespaceNotIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldNamespace, vs...)) +} + +// NamespaceGT applies the GT predicate on the "namespace" field. +func NamespaceGT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldNamespace, v)) +} + +// NamespaceGTE applies the GTE predicate on the "namespace" field. +func NamespaceGTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldNamespace, v)) +} + +// NamespaceLT applies the LT predicate on the "namespace" field. +func NamespaceLT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldNamespace, v)) +} + +// NamespaceLTE applies the LTE predicate on the "namespace" field. +func NamespaceLTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldNamespace, v)) +} + +// NamespaceContains applies the Contains predicate on the "namespace" field. +func NamespaceContains(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldNamespace, v)) +} + +// NamespaceHasPrefix applies the HasPrefix predicate on the "namespace" field. +func NamespaceHasPrefix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldNamespace, v)) +} + +// NamespaceHasSuffix applies the HasSuffix predicate on the "namespace" field. +func NamespaceHasSuffix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldNamespace, v)) +} + +// NamespaceEqualFold applies the EqualFold predicate on the "namespace" field. +func NamespaceEqualFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldNamespace, v)) +} + +// NamespaceContainsFold applies the ContainsFold predicate on the "namespace" field. +func NamespaceContainsFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldNamespace, v)) +} + +// MetadataIsNil applies the IsNil predicate on the "metadata" field. +func MetadataIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldMetadata)) +} + +// MetadataNotNil applies the NotNil predicate on the "metadata" field. +func MetadataNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldMetadata)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// DeletedAtEQ applies the EQ predicate on the "deleted_at" field. +func DeletedAtEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldDeletedAt, v)) +} + +// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field. +func DeletedAtNEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldDeletedAt, v)) +} + +// DeletedAtIn applies the In predicate on the "deleted_at" field. +func DeletedAtIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldDeletedAt, vs...)) +} + +// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field. +func DeletedAtNotIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldDeletedAt, vs...)) +} + +// DeletedAtGT applies the GT predicate on the "deleted_at" field. +func DeletedAtGT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldDeletedAt, v)) +} + +// DeletedAtGTE applies the GTE predicate on the "deleted_at" field. +func DeletedAtGTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldDeletedAt, v)) +} + +// DeletedAtLT applies the LT predicate on the "deleted_at" field. +func DeletedAtLT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldDeletedAt, v)) +} + +// DeletedAtLTE applies the LTE predicate on the "deleted_at" field. +func DeletedAtLTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldDeletedAt, v)) +} + +// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field. +func DeletedAtIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldDeletedAt)) +} + +// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field. +func DeletedAtNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldDeletedAt)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldName, v)) +} + +// DescriptionEQ applies the EQ predicate on the "description" field. +func DescriptionEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldDescription, v)) +} + +// DescriptionNEQ applies the NEQ predicate on the "description" field. +func DescriptionNEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldDescription, v)) +} + +// DescriptionIn applies the In predicate on the "description" field. +func DescriptionIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldDescription, vs...)) +} + +// DescriptionNotIn applies the NotIn predicate on the "description" field. +func DescriptionNotIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldDescription, vs...)) +} + +// DescriptionGT applies the GT predicate on the "description" field. +func DescriptionGT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldDescription, v)) +} + +// DescriptionGTE applies the GTE predicate on the "description" field. +func DescriptionGTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldDescription, v)) +} + +// DescriptionLT applies the LT predicate on the "description" field. +func DescriptionLT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldDescription, v)) +} + +// DescriptionLTE applies the LTE predicate on the "description" field. +func DescriptionLTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldDescription, v)) +} + +// DescriptionContains applies the Contains predicate on the "description" field. +func DescriptionContains(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldDescription, v)) +} + +// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. +func DescriptionHasPrefix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldDescription, v)) +} + +// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. +func DescriptionHasSuffix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldDescription, v)) +} + +// DescriptionIsNil applies the IsNil predicate on the "description" field. +func DescriptionIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldDescription)) +} + +// DescriptionNotNil applies the NotNil predicate on the "description" field. +func DescriptionNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldDescription)) +} + +// DescriptionEqualFold applies the EqualFold predicate on the "description" field. +func DescriptionEqualFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldDescription, v)) +} + +// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. +func DescriptionContainsFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldDescription, v)) +} + +// CurrencyEQ applies the EQ predicate on the "currency" field. +func CurrencyEQ(v currencyx.Code) predicate.BillingGatheringInvoiceLine { + vc := string(v) + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldCurrency, vc)) +} + +// CurrencyNEQ applies the NEQ predicate on the "currency" field. +func CurrencyNEQ(v currencyx.Code) predicate.BillingGatheringInvoiceLine { + vc := string(v) + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldCurrency, vc)) +} + +// CurrencyIn applies the In predicate on the "currency" field. +func CurrencyIn(vs ...currencyx.Code) predicate.BillingGatheringInvoiceLine { + v := make([]any, len(vs)) + for i := range v { + v[i] = string(vs[i]) + } + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldCurrency, v...)) +} + +// CurrencyNotIn applies the NotIn predicate on the "currency" field. +func CurrencyNotIn(vs ...currencyx.Code) predicate.BillingGatheringInvoiceLine { + v := make([]any, len(vs)) + for i := range v { + v[i] = string(vs[i]) + } + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldCurrency, v...)) +} + +// CurrencyGT applies the GT predicate on the "currency" field. +func CurrencyGT(v currencyx.Code) predicate.BillingGatheringInvoiceLine { + vc := string(v) + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldCurrency, vc)) +} + +// CurrencyGTE applies the GTE predicate on the "currency" field. +func CurrencyGTE(v currencyx.Code) predicate.BillingGatheringInvoiceLine { + vc := string(v) + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldCurrency, vc)) +} + +// CurrencyLT applies the LT predicate on the "currency" field. +func CurrencyLT(v currencyx.Code) predicate.BillingGatheringInvoiceLine { + vc := string(v) + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldCurrency, vc)) +} + +// CurrencyLTE applies the LTE predicate on the "currency" field. +func CurrencyLTE(v currencyx.Code) predicate.BillingGatheringInvoiceLine { + vc := string(v) + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldCurrency, vc)) +} + +// CurrencyContains applies the Contains predicate on the "currency" field. +func CurrencyContains(v currencyx.Code) predicate.BillingGatheringInvoiceLine { + vc := string(v) + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldCurrency, vc)) +} + +// CurrencyHasPrefix applies the HasPrefix predicate on the "currency" field. +func CurrencyHasPrefix(v currencyx.Code) predicate.BillingGatheringInvoiceLine { + vc := string(v) + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldCurrency, vc)) +} + +// CurrencyHasSuffix applies the HasSuffix predicate on the "currency" field. +func CurrencyHasSuffix(v currencyx.Code) predicate.BillingGatheringInvoiceLine { + vc := string(v) + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldCurrency, vc)) +} + +// CurrencyEqualFold applies the EqualFold predicate on the "currency" field. +func CurrencyEqualFold(v currencyx.Code) predicate.BillingGatheringInvoiceLine { + vc := string(v) + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldCurrency, vc)) +} + +// CurrencyContainsFold applies the ContainsFold predicate on the "currency" field. +func CurrencyContainsFold(v currencyx.Code) predicate.BillingGatheringInvoiceLine { + vc := string(v) + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldCurrency, vc)) +} + +// ServicePeriodStartEQ applies the EQ predicate on the "service_period_start" field. +func ServicePeriodStartEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldServicePeriodStart, v)) +} + +// ServicePeriodStartNEQ applies the NEQ predicate on the "service_period_start" field. +func ServicePeriodStartNEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldServicePeriodStart, v)) +} + +// ServicePeriodStartIn applies the In predicate on the "service_period_start" field. +func ServicePeriodStartIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldServicePeriodStart, vs...)) +} + +// ServicePeriodStartNotIn applies the NotIn predicate on the "service_period_start" field. +func ServicePeriodStartNotIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldServicePeriodStart, vs...)) +} + +// ServicePeriodStartGT applies the GT predicate on the "service_period_start" field. +func ServicePeriodStartGT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldServicePeriodStart, v)) +} + +// ServicePeriodStartGTE applies the GTE predicate on the "service_period_start" field. +func ServicePeriodStartGTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldServicePeriodStart, v)) +} + +// ServicePeriodStartLT applies the LT predicate on the "service_period_start" field. +func ServicePeriodStartLT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldServicePeriodStart, v)) +} + +// ServicePeriodStartLTE applies the LTE predicate on the "service_period_start" field. +func ServicePeriodStartLTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldServicePeriodStart, v)) +} + +// ServicePeriodEndEQ applies the EQ predicate on the "service_period_end" field. +func ServicePeriodEndEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldServicePeriodEnd, v)) +} + +// ServicePeriodEndNEQ applies the NEQ predicate on the "service_period_end" field. +func ServicePeriodEndNEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldServicePeriodEnd, v)) +} + +// ServicePeriodEndIn applies the In predicate on the "service_period_end" field. +func ServicePeriodEndIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldServicePeriodEnd, vs...)) +} + +// ServicePeriodEndNotIn applies the NotIn predicate on the "service_period_end" field. +func ServicePeriodEndNotIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldServicePeriodEnd, vs...)) +} + +// ServicePeriodEndGT applies the GT predicate on the "service_period_end" field. +func ServicePeriodEndGT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldServicePeriodEnd, v)) +} + +// ServicePeriodEndGTE applies the GTE predicate on the "service_period_end" field. +func ServicePeriodEndGTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldServicePeriodEnd, v)) +} + +// ServicePeriodEndLT applies the LT predicate on the "service_period_end" field. +func ServicePeriodEndLT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldServicePeriodEnd, v)) +} + +// ServicePeriodEndLTE applies the LTE predicate on the "service_period_end" field. +func ServicePeriodEndLTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldServicePeriodEnd, v)) +} + +// TaxConfigIsNil applies the IsNil predicate on the "tax_config" field. +func TaxConfigIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldTaxConfig)) +} + +// TaxConfigNotNil applies the NotNil predicate on the "tax_config" field. +func TaxConfigNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldTaxConfig)) +} + +// PriceTypeEQ applies the EQ predicate on the "price_type" field. +func PriceTypeEQ(v productcatalog.PriceType) predicate.BillingGatheringInvoiceLine { + vc := v + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldPriceType, vc)) +} + +// PriceTypeNEQ applies the NEQ predicate on the "price_type" field. +func PriceTypeNEQ(v productcatalog.PriceType) predicate.BillingGatheringInvoiceLine { + vc := v + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldPriceType, vc)) +} + +// PriceTypeIn applies the In predicate on the "price_type" field. +func PriceTypeIn(vs ...productcatalog.PriceType) predicate.BillingGatheringInvoiceLine { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldPriceType, v...)) +} + +// PriceTypeNotIn applies the NotIn predicate on the "price_type" field. +func PriceTypeNotIn(vs ...productcatalog.PriceType) predicate.BillingGatheringInvoiceLine { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldPriceType, v...)) +} + +// FeatureKeyEQ applies the EQ predicate on the "feature_key" field. +func FeatureKeyEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldFeatureKey, v)) +} + +// FeatureKeyNEQ applies the NEQ predicate on the "feature_key" field. +func FeatureKeyNEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldFeatureKey, v)) +} + +// FeatureKeyIn applies the In predicate on the "feature_key" field. +func FeatureKeyIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldFeatureKey, vs...)) +} + +// FeatureKeyNotIn applies the NotIn predicate on the "feature_key" field. +func FeatureKeyNotIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldFeatureKey, vs...)) +} + +// FeatureKeyGT applies the GT predicate on the "feature_key" field. +func FeatureKeyGT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldFeatureKey, v)) +} + +// FeatureKeyGTE applies the GTE predicate on the "feature_key" field. +func FeatureKeyGTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldFeatureKey, v)) +} + +// FeatureKeyLT applies the LT predicate on the "feature_key" field. +func FeatureKeyLT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldFeatureKey, v)) +} + +// FeatureKeyLTE applies the LTE predicate on the "feature_key" field. +func FeatureKeyLTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldFeatureKey, v)) +} + +// FeatureKeyContains applies the Contains predicate on the "feature_key" field. +func FeatureKeyContains(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldFeatureKey, v)) +} + +// FeatureKeyHasPrefix applies the HasPrefix predicate on the "feature_key" field. +func FeatureKeyHasPrefix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldFeatureKey, v)) +} + +// FeatureKeyHasSuffix applies the HasSuffix predicate on the "feature_key" field. +func FeatureKeyHasSuffix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldFeatureKey, v)) +} + +// FeatureKeyIsNil applies the IsNil predicate on the "feature_key" field. +func FeatureKeyIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldFeatureKey)) +} + +// FeatureKeyNotNil applies the NotNil predicate on the "feature_key" field. +func FeatureKeyNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldFeatureKey)) +} + +// FeatureKeyEqualFold applies the EqualFold predicate on the "feature_key" field. +func FeatureKeyEqualFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldFeatureKey, v)) +} + +// FeatureKeyContainsFold applies the ContainsFold predicate on the "feature_key" field. +func FeatureKeyContainsFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldFeatureKey, v)) +} + +// UnitConfigIsNil applies the IsNil predicate on the "unit_config" field. +func UnitConfigIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldUnitConfig)) +} + +// UnitConfigNotNil applies the NotNil predicate on the "unit_config" field. +func UnitConfigNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldUnitConfig)) +} + +// RatecardDiscountsIsNil applies the IsNil predicate on the "ratecard_discounts" field. +func RatecardDiscountsIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldRatecardDiscounts)) +} + +// RatecardDiscountsNotNil applies the NotNil predicate on the "ratecard_discounts" field. +func RatecardDiscountsNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldRatecardDiscounts)) +} + +// ChildUniqueReferenceIDEQ applies the EQ predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldChildUniqueReferenceID, v)) +} + +// ChildUniqueReferenceIDNEQ applies the NEQ predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDNEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldChildUniqueReferenceID, v)) +} + +// ChildUniqueReferenceIDIn applies the In predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldChildUniqueReferenceID, vs...)) +} + +// ChildUniqueReferenceIDNotIn applies the NotIn predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDNotIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldChildUniqueReferenceID, vs...)) +} + +// ChildUniqueReferenceIDGT applies the GT predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDGT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldChildUniqueReferenceID, v)) +} + +// ChildUniqueReferenceIDGTE applies the GTE predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDGTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldChildUniqueReferenceID, v)) +} + +// ChildUniqueReferenceIDLT applies the LT predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDLT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldChildUniqueReferenceID, v)) +} + +// ChildUniqueReferenceIDLTE applies the LTE predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDLTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldChildUniqueReferenceID, v)) +} + +// ChildUniqueReferenceIDContains applies the Contains predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDContains(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldChildUniqueReferenceID, v)) +} + +// ChildUniqueReferenceIDHasPrefix applies the HasPrefix predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDHasPrefix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldChildUniqueReferenceID, v)) +} + +// ChildUniqueReferenceIDHasSuffix applies the HasSuffix predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDHasSuffix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldChildUniqueReferenceID, v)) +} + +// ChildUniqueReferenceIDIsNil applies the IsNil predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldChildUniqueReferenceID)) +} + +// ChildUniqueReferenceIDNotNil applies the NotNil predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldChildUniqueReferenceID)) +} + +// ChildUniqueReferenceIDEqualFold applies the EqualFold predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDEqualFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldChildUniqueReferenceID, v)) +} + +// ChildUniqueReferenceIDContainsFold applies the ContainsFold predicate on the "child_unique_reference_id" field. +func ChildUniqueReferenceIDContainsFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldChildUniqueReferenceID, v)) +} + +// SubscriptionIDEQ applies the EQ predicate on the "subscription_id" field. +func SubscriptionIDEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldSubscriptionID, v)) +} + +// SubscriptionIDNEQ applies the NEQ predicate on the "subscription_id" field. +func SubscriptionIDNEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldSubscriptionID, v)) +} + +// SubscriptionIDIn applies the In predicate on the "subscription_id" field. +func SubscriptionIDIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldSubscriptionID, vs...)) +} + +// SubscriptionIDNotIn applies the NotIn predicate on the "subscription_id" field. +func SubscriptionIDNotIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldSubscriptionID, vs...)) +} + +// SubscriptionIDGT applies the GT predicate on the "subscription_id" field. +func SubscriptionIDGT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldSubscriptionID, v)) +} + +// SubscriptionIDGTE applies the GTE predicate on the "subscription_id" field. +func SubscriptionIDGTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldSubscriptionID, v)) +} + +// SubscriptionIDLT applies the LT predicate on the "subscription_id" field. +func SubscriptionIDLT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldSubscriptionID, v)) +} + +// SubscriptionIDLTE applies the LTE predicate on the "subscription_id" field. +func SubscriptionIDLTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldSubscriptionID, v)) +} + +// SubscriptionIDContains applies the Contains predicate on the "subscription_id" field. +func SubscriptionIDContains(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldSubscriptionID, v)) +} + +// SubscriptionIDHasPrefix applies the HasPrefix predicate on the "subscription_id" field. +func SubscriptionIDHasPrefix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldSubscriptionID, v)) +} + +// SubscriptionIDHasSuffix applies the HasSuffix predicate on the "subscription_id" field. +func SubscriptionIDHasSuffix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldSubscriptionID, v)) +} + +// SubscriptionIDIsNil applies the IsNil predicate on the "subscription_id" field. +func SubscriptionIDIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldSubscriptionID)) +} + +// SubscriptionIDNotNil applies the NotNil predicate on the "subscription_id" field. +func SubscriptionIDNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldSubscriptionID)) +} + +// SubscriptionIDEqualFold applies the EqualFold predicate on the "subscription_id" field. +func SubscriptionIDEqualFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldSubscriptionID, v)) +} + +// SubscriptionIDContainsFold applies the ContainsFold predicate on the "subscription_id" field. +func SubscriptionIDContainsFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldSubscriptionID, v)) +} + +// SubscriptionPhaseIDEQ applies the EQ predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldSubscriptionPhaseID, v)) +} + +// SubscriptionPhaseIDNEQ applies the NEQ predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDNEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldSubscriptionPhaseID, v)) +} + +// SubscriptionPhaseIDIn applies the In predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldSubscriptionPhaseID, vs...)) +} + +// SubscriptionPhaseIDNotIn applies the NotIn predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDNotIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldSubscriptionPhaseID, vs...)) +} + +// SubscriptionPhaseIDGT applies the GT predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDGT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldSubscriptionPhaseID, v)) +} + +// SubscriptionPhaseIDGTE applies the GTE predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDGTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldSubscriptionPhaseID, v)) +} + +// SubscriptionPhaseIDLT applies the LT predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDLT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldSubscriptionPhaseID, v)) +} + +// SubscriptionPhaseIDLTE applies the LTE predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDLTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldSubscriptionPhaseID, v)) +} + +// SubscriptionPhaseIDContains applies the Contains predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDContains(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldSubscriptionPhaseID, v)) +} + +// SubscriptionPhaseIDHasPrefix applies the HasPrefix predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDHasPrefix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldSubscriptionPhaseID, v)) +} + +// SubscriptionPhaseIDHasSuffix applies the HasSuffix predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDHasSuffix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldSubscriptionPhaseID, v)) +} + +// SubscriptionPhaseIDIsNil applies the IsNil predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldSubscriptionPhaseID)) +} + +// SubscriptionPhaseIDNotNil applies the NotNil predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldSubscriptionPhaseID)) +} + +// SubscriptionPhaseIDEqualFold applies the EqualFold predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDEqualFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldSubscriptionPhaseID, v)) +} + +// SubscriptionPhaseIDContainsFold applies the ContainsFold predicate on the "subscription_phase_id" field. +func SubscriptionPhaseIDContainsFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldSubscriptionPhaseID, v)) +} + +// SubscriptionItemIDEQ applies the EQ predicate on the "subscription_item_id" field. +func SubscriptionItemIDEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldSubscriptionItemID, v)) +} + +// SubscriptionItemIDNEQ applies the NEQ predicate on the "subscription_item_id" field. +func SubscriptionItemIDNEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldSubscriptionItemID, v)) +} + +// SubscriptionItemIDIn applies the In predicate on the "subscription_item_id" field. +func SubscriptionItemIDIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldSubscriptionItemID, vs...)) +} + +// SubscriptionItemIDNotIn applies the NotIn predicate on the "subscription_item_id" field. +func SubscriptionItemIDNotIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldSubscriptionItemID, vs...)) +} + +// SubscriptionItemIDGT applies the GT predicate on the "subscription_item_id" field. +func SubscriptionItemIDGT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldSubscriptionItemID, v)) +} + +// SubscriptionItemIDGTE applies the GTE predicate on the "subscription_item_id" field. +func SubscriptionItemIDGTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldSubscriptionItemID, v)) +} + +// SubscriptionItemIDLT applies the LT predicate on the "subscription_item_id" field. +func SubscriptionItemIDLT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldSubscriptionItemID, v)) +} + +// SubscriptionItemIDLTE applies the LTE predicate on the "subscription_item_id" field. +func SubscriptionItemIDLTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldSubscriptionItemID, v)) +} + +// SubscriptionItemIDContains applies the Contains predicate on the "subscription_item_id" field. +func SubscriptionItemIDContains(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldSubscriptionItemID, v)) +} + +// SubscriptionItemIDHasPrefix applies the HasPrefix predicate on the "subscription_item_id" field. +func SubscriptionItemIDHasPrefix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldSubscriptionItemID, v)) +} + +// SubscriptionItemIDHasSuffix applies the HasSuffix predicate on the "subscription_item_id" field. +func SubscriptionItemIDHasSuffix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldSubscriptionItemID, v)) +} + +// SubscriptionItemIDIsNil applies the IsNil predicate on the "subscription_item_id" field. +func SubscriptionItemIDIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldSubscriptionItemID)) +} + +// SubscriptionItemIDNotNil applies the NotNil predicate on the "subscription_item_id" field. +func SubscriptionItemIDNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldSubscriptionItemID)) +} + +// SubscriptionItemIDEqualFold applies the EqualFold predicate on the "subscription_item_id" field. +func SubscriptionItemIDEqualFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldSubscriptionItemID, v)) +} + +// SubscriptionItemIDContainsFold applies the ContainsFold predicate on the "subscription_item_id" field. +func SubscriptionItemIDContainsFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldSubscriptionItemID, v)) +} + +// SubscriptionBillingPeriodFromEQ applies the EQ predicate on the "subscription_billing_period_from" field. +func SubscriptionBillingPeriodFromEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldSubscriptionBillingPeriodFrom, v)) +} + +// SubscriptionBillingPeriodFromNEQ applies the NEQ predicate on the "subscription_billing_period_from" field. +func SubscriptionBillingPeriodFromNEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldSubscriptionBillingPeriodFrom, v)) +} + +// SubscriptionBillingPeriodFromIn applies the In predicate on the "subscription_billing_period_from" field. +func SubscriptionBillingPeriodFromIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldSubscriptionBillingPeriodFrom, vs...)) +} + +// SubscriptionBillingPeriodFromNotIn applies the NotIn predicate on the "subscription_billing_period_from" field. +func SubscriptionBillingPeriodFromNotIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldSubscriptionBillingPeriodFrom, vs...)) +} + +// SubscriptionBillingPeriodFromGT applies the GT predicate on the "subscription_billing_period_from" field. +func SubscriptionBillingPeriodFromGT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldSubscriptionBillingPeriodFrom, v)) +} + +// SubscriptionBillingPeriodFromGTE applies the GTE predicate on the "subscription_billing_period_from" field. +func SubscriptionBillingPeriodFromGTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldSubscriptionBillingPeriodFrom, v)) +} + +// SubscriptionBillingPeriodFromLT applies the LT predicate on the "subscription_billing_period_from" field. +func SubscriptionBillingPeriodFromLT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldSubscriptionBillingPeriodFrom, v)) +} + +// SubscriptionBillingPeriodFromLTE applies the LTE predicate on the "subscription_billing_period_from" field. +func SubscriptionBillingPeriodFromLTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldSubscriptionBillingPeriodFrom, v)) +} + +// SubscriptionBillingPeriodFromIsNil applies the IsNil predicate on the "subscription_billing_period_from" field. +func SubscriptionBillingPeriodFromIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldSubscriptionBillingPeriodFrom)) +} + +// SubscriptionBillingPeriodFromNotNil applies the NotNil predicate on the "subscription_billing_period_from" field. +func SubscriptionBillingPeriodFromNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldSubscriptionBillingPeriodFrom)) +} + +// SubscriptionBillingPeriodToEQ applies the EQ predicate on the "subscription_billing_period_to" field. +func SubscriptionBillingPeriodToEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldSubscriptionBillingPeriodTo, v)) +} + +// SubscriptionBillingPeriodToNEQ applies the NEQ predicate on the "subscription_billing_period_to" field. +func SubscriptionBillingPeriodToNEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldSubscriptionBillingPeriodTo, v)) +} + +// SubscriptionBillingPeriodToIn applies the In predicate on the "subscription_billing_period_to" field. +func SubscriptionBillingPeriodToIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldSubscriptionBillingPeriodTo, vs...)) +} + +// SubscriptionBillingPeriodToNotIn applies the NotIn predicate on the "subscription_billing_period_to" field. +func SubscriptionBillingPeriodToNotIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldSubscriptionBillingPeriodTo, vs...)) +} + +// SubscriptionBillingPeriodToGT applies the GT predicate on the "subscription_billing_period_to" field. +func SubscriptionBillingPeriodToGT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldSubscriptionBillingPeriodTo, v)) +} + +// SubscriptionBillingPeriodToGTE applies the GTE predicate on the "subscription_billing_period_to" field. +func SubscriptionBillingPeriodToGTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldSubscriptionBillingPeriodTo, v)) +} + +// SubscriptionBillingPeriodToLT applies the LT predicate on the "subscription_billing_period_to" field. +func SubscriptionBillingPeriodToLT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldSubscriptionBillingPeriodTo, v)) +} + +// SubscriptionBillingPeriodToLTE applies the LTE predicate on the "subscription_billing_period_to" field. +func SubscriptionBillingPeriodToLTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldSubscriptionBillingPeriodTo, v)) +} + +// SubscriptionBillingPeriodToIsNil applies the IsNil predicate on the "subscription_billing_period_to" field. +func SubscriptionBillingPeriodToIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldSubscriptionBillingPeriodTo)) +} + +// SubscriptionBillingPeriodToNotNil applies the NotNil predicate on the "subscription_billing_period_to" field. +func SubscriptionBillingPeriodToNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldSubscriptionBillingPeriodTo)) +} + +// TaxCodeIDEQ applies the EQ predicate on the "tax_code_id" field. +func TaxCodeIDEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldTaxCodeID, v)) +} + +// TaxCodeIDNEQ applies the NEQ predicate on the "tax_code_id" field. +func TaxCodeIDNEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldTaxCodeID, v)) +} + +// TaxCodeIDIn applies the In predicate on the "tax_code_id" field. +func TaxCodeIDIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldTaxCodeID, vs...)) +} + +// TaxCodeIDNotIn applies the NotIn predicate on the "tax_code_id" field. +func TaxCodeIDNotIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldTaxCodeID, vs...)) +} + +// TaxCodeIDGT applies the GT predicate on the "tax_code_id" field. +func TaxCodeIDGT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldTaxCodeID, v)) +} + +// TaxCodeIDGTE applies the GTE predicate on the "tax_code_id" field. +func TaxCodeIDGTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldTaxCodeID, v)) +} + +// TaxCodeIDLT applies the LT predicate on the "tax_code_id" field. +func TaxCodeIDLT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldTaxCodeID, v)) +} + +// TaxCodeIDLTE applies the LTE predicate on the "tax_code_id" field. +func TaxCodeIDLTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldTaxCodeID, v)) +} + +// TaxCodeIDContains applies the Contains predicate on the "tax_code_id" field. +func TaxCodeIDContains(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldTaxCodeID, v)) +} + +// TaxCodeIDHasPrefix applies the HasPrefix predicate on the "tax_code_id" field. +func TaxCodeIDHasPrefix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldTaxCodeID, v)) +} + +// TaxCodeIDHasSuffix applies the HasSuffix predicate on the "tax_code_id" field. +func TaxCodeIDHasSuffix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldTaxCodeID, v)) +} + +// TaxCodeIDIsNil applies the IsNil predicate on the "tax_code_id" field. +func TaxCodeIDIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldTaxCodeID)) +} + +// TaxCodeIDNotNil applies the NotNil predicate on the "tax_code_id" field. +func TaxCodeIDNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldTaxCodeID)) +} + +// TaxCodeIDEqualFold applies the EqualFold predicate on the "tax_code_id" field. +func TaxCodeIDEqualFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldTaxCodeID, v)) +} + +// TaxCodeIDContainsFold applies the ContainsFold predicate on the "tax_code_id" field. +func TaxCodeIDContainsFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldTaxCodeID, v)) +} + +// TaxBehaviorEQ applies the EQ predicate on the "tax_behavior" field. +func TaxBehaviorEQ(v productcatalog.TaxBehavior) predicate.BillingGatheringInvoiceLine { + vc := v + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldTaxBehavior, vc)) +} + +// TaxBehaviorNEQ applies the NEQ predicate on the "tax_behavior" field. +func TaxBehaviorNEQ(v productcatalog.TaxBehavior) predicate.BillingGatheringInvoiceLine { + vc := v + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldTaxBehavior, vc)) +} + +// TaxBehaviorIn applies the In predicate on the "tax_behavior" field. +func TaxBehaviorIn(vs ...productcatalog.TaxBehavior) predicate.BillingGatheringInvoiceLine { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldTaxBehavior, v...)) +} + +// TaxBehaviorNotIn applies the NotIn predicate on the "tax_behavior" field. +func TaxBehaviorNotIn(vs ...productcatalog.TaxBehavior) predicate.BillingGatheringInvoiceLine { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldTaxBehavior, v...)) +} + +// TaxBehaviorIsNil applies the IsNil predicate on the "tax_behavior" field. +func TaxBehaviorIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldTaxBehavior)) +} + +// TaxBehaviorNotNil applies the NotNil predicate on the "tax_behavior" field. +func TaxBehaviorNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldTaxBehavior)) +} + +// InvoiceIDEQ applies the EQ predicate on the "invoice_id" field. +func InvoiceIDEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldInvoiceID, v)) +} + +// InvoiceIDNEQ applies the NEQ predicate on the "invoice_id" field. +func InvoiceIDNEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldInvoiceID, v)) +} + +// InvoiceIDIn applies the In predicate on the "invoice_id" field. +func InvoiceIDIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldInvoiceID, vs...)) +} + +// InvoiceIDNotIn applies the NotIn predicate on the "invoice_id" field. +func InvoiceIDNotIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldInvoiceID, vs...)) +} + +// InvoiceIDGT applies the GT predicate on the "invoice_id" field. +func InvoiceIDGT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldInvoiceID, v)) +} + +// InvoiceIDGTE applies the GTE predicate on the "invoice_id" field. +func InvoiceIDGTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldInvoiceID, v)) +} + +// InvoiceIDLT applies the LT predicate on the "invoice_id" field. +func InvoiceIDLT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldInvoiceID, v)) +} + +// InvoiceIDLTE applies the LTE predicate on the "invoice_id" field. +func InvoiceIDLTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldInvoiceID, v)) +} + +// InvoiceIDContains applies the Contains predicate on the "invoice_id" field. +func InvoiceIDContains(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldInvoiceID, v)) +} + +// InvoiceIDHasPrefix applies the HasPrefix predicate on the "invoice_id" field. +func InvoiceIDHasPrefix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldInvoiceID, v)) +} + +// InvoiceIDHasSuffix applies the HasSuffix predicate on the "invoice_id" field. +func InvoiceIDHasSuffix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldInvoiceID, v)) +} + +// InvoiceIDEqualFold applies the EqualFold predicate on the "invoice_id" field. +func InvoiceIDEqualFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldInvoiceID, v)) +} + +// InvoiceIDContainsFold applies the ContainsFold predicate on the "invoice_id" field. +func InvoiceIDContainsFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldInvoiceID, v)) +} + +// InvoiceAtEQ applies the EQ predicate on the "invoice_at" field. +func InvoiceAtEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldInvoiceAt, v)) +} + +// InvoiceAtNEQ applies the NEQ predicate on the "invoice_at" field. +func InvoiceAtNEQ(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldInvoiceAt, v)) +} + +// InvoiceAtIn applies the In predicate on the "invoice_at" field. +func InvoiceAtIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldInvoiceAt, vs...)) +} + +// InvoiceAtNotIn applies the NotIn predicate on the "invoice_at" field. +func InvoiceAtNotIn(vs ...time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldInvoiceAt, vs...)) +} + +// InvoiceAtGT applies the GT predicate on the "invoice_at" field. +func InvoiceAtGT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldInvoiceAt, v)) +} + +// InvoiceAtGTE applies the GTE predicate on the "invoice_at" field. +func InvoiceAtGTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldInvoiceAt, v)) +} + +// InvoiceAtLT applies the LT predicate on the "invoice_at" field. +func InvoiceAtLT(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldInvoiceAt, v)) +} + +// InvoiceAtLTE applies the LTE predicate on the "invoice_at" field. +func InvoiceAtLTE(v time.Time) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldInvoiceAt, v)) +} + +// ManagedByEQ applies the EQ predicate on the "managed_by" field. +func ManagedByEQ(v billing.InvoiceLineManagedBy) predicate.BillingGatheringInvoiceLine { + vc := v + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldManagedBy, vc)) +} + +// ManagedByNEQ applies the NEQ predicate on the "managed_by" field. +func ManagedByNEQ(v billing.InvoiceLineManagedBy) predicate.BillingGatheringInvoiceLine { + vc := v + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldManagedBy, vc)) +} + +// ManagedByIn applies the In predicate on the "managed_by" field. +func ManagedByIn(vs ...billing.InvoiceLineManagedBy) predicate.BillingGatheringInvoiceLine { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldManagedBy, v...)) +} + +// ManagedByNotIn applies the NotIn predicate on the "managed_by" field. +func ManagedByNotIn(vs ...billing.InvoiceLineManagedBy) predicate.BillingGatheringInvoiceLine { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldManagedBy, v...)) +} + +// EngineEQ applies the EQ predicate on the "engine" field. +func EngineEQ(v billing.LineEngineType) predicate.BillingGatheringInvoiceLine { + vc := v + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldEngine, vc)) +} + +// EngineNEQ applies the NEQ predicate on the "engine" field. +func EngineNEQ(v billing.LineEngineType) predicate.BillingGatheringInvoiceLine { + vc := v + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldEngine, vc)) +} + +// EngineIn applies the In predicate on the "engine" field. +func EngineIn(vs ...billing.LineEngineType) predicate.BillingGatheringInvoiceLine { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldEngine, v...)) +} + +// EngineNotIn applies the NotIn predicate on the "engine" field. +func EngineNotIn(vs ...billing.LineEngineType) predicate.BillingGatheringInvoiceLine { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldEngine, v...)) +} + +// SplitLineGroupIDEQ applies the EQ predicate on the "split_line_group_id" field. +func SplitLineGroupIDEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldSplitLineGroupID, v)) +} + +// SplitLineGroupIDNEQ applies the NEQ predicate on the "split_line_group_id" field. +func SplitLineGroupIDNEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldSplitLineGroupID, v)) +} + +// SplitLineGroupIDIn applies the In predicate on the "split_line_group_id" field. +func SplitLineGroupIDIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldSplitLineGroupID, vs...)) +} + +// SplitLineGroupIDNotIn applies the NotIn predicate on the "split_line_group_id" field. +func SplitLineGroupIDNotIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldSplitLineGroupID, vs...)) +} + +// SplitLineGroupIDGT applies the GT predicate on the "split_line_group_id" field. +func SplitLineGroupIDGT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldSplitLineGroupID, v)) +} + +// SplitLineGroupIDGTE applies the GTE predicate on the "split_line_group_id" field. +func SplitLineGroupIDGTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldSplitLineGroupID, v)) +} + +// SplitLineGroupIDLT applies the LT predicate on the "split_line_group_id" field. +func SplitLineGroupIDLT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldSplitLineGroupID, v)) +} + +// SplitLineGroupIDLTE applies the LTE predicate on the "split_line_group_id" field. +func SplitLineGroupIDLTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldSplitLineGroupID, v)) +} + +// SplitLineGroupIDContains applies the Contains predicate on the "split_line_group_id" field. +func SplitLineGroupIDContains(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldSplitLineGroupID, v)) +} + +// SplitLineGroupIDHasPrefix applies the HasPrefix predicate on the "split_line_group_id" field. +func SplitLineGroupIDHasPrefix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldSplitLineGroupID, v)) +} + +// SplitLineGroupIDHasSuffix applies the HasSuffix predicate on the "split_line_group_id" field. +func SplitLineGroupIDHasSuffix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldSplitLineGroupID, v)) +} + +// SplitLineGroupIDIsNil applies the IsNil predicate on the "split_line_group_id" field. +func SplitLineGroupIDIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldSplitLineGroupID)) +} + +// SplitLineGroupIDNotNil applies the NotNil predicate on the "split_line_group_id" field. +func SplitLineGroupIDNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldSplitLineGroupID)) +} + +// SplitLineGroupIDEqualFold applies the EqualFold predicate on the "split_line_group_id" field. +func SplitLineGroupIDEqualFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldSplitLineGroupID, v)) +} + +// SplitLineGroupIDContainsFold applies the ContainsFold predicate on the "split_line_group_id" field. +func SplitLineGroupIDContainsFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldSplitLineGroupID, v)) +} + +// ChargeIDEQ applies the EQ predicate on the "charge_id" field. +func ChargeIDEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEQ(FieldChargeID, v)) +} + +// ChargeIDNEQ applies the NEQ predicate on the "charge_id" field. +func ChargeIDNEQ(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNEQ(FieldChargeID, v)) +} + +// ChargeIDIn applies the In predicate on the "charge_id" field. +func ChargeIDIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIn(FieldChargeID, vs...)) +} + +// ChargeIDNotIn applies the NotIn predicate on the "charge_id" field. +func ChargeIDNotIn(vs ...string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotIn(FieldChargeID, vs...)) +} + +// ChargeIDGT applies the GT predicate on the "charge_id" field. +func ChargeIDGT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGT(FieldChargeID, v)) +} + +// ChargeIDGTE applies the GTE predicate on the "charge_id" field. +func ChargeIDGTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldGTE(FieldChargeID, v)) +} + +// ChargeIDLT applies the LT predicate on the "charge_id" field. +func ChargeIDLT(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLT(FieldChargeID, v)) +} + +// ChargeIDLTE applies the LTE predicate on the "charge_id" field. +func ChargeIDLTE(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldLTE(FieldChargeID, v)) +} + +// ChargeIDContains applies the Contains predicate on the "charge_id" field. +func ChargeIDContains(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContains(FieldChargeID, v)) +} + +// ChargeIDHasPrefix applies the HasPrefix predicate on the "charge_id" field. +func ChargeIDHasPrefix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasPrefix(FieldChargeID, v)) +} + +// ChargeIDHasSuffix applies the HasSuffix predicate on the "charge_id" field. +func ChargeIDHasSuffix(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldHasSuffix(FieldChargeID, v)) +} + +// ChargeIDIsNil applies the IsNil predicate on the "charge_id" field. +func ChargeIDIsNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldIsNull(FieldChargeID)) +} + +// ChargeIDNotNil applies the NotNil predicate on the "charge_id" field. +func ChargeIDNotNil() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldNotNull(FieldChargeID)) +} + +// ChargeIDEqualFold applies the EqualFold predicate on the "charge_id" field. +func ChargeIDEqualFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldEqualFold(FieldChargeID, v)) +} + +// ChargeIDContainsFold applies the ContainsFold predicate on the "charge_id" field. +func ChargeIDContainsFold(v string) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.FieldContainsFold(FieldChargeID, v)) +} + +// HasBillingInvoice applies the HasEdge predicate on the "billing_invoice" edge. +func HasBillingInvoice() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, BillingInvoiceTable, BillingInvoiceColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasBillingInvoiceWith applies the HasEdge predicate on the "billing_invoice" edge with a given conditions (other predicates). +func HasBillingInvoiceWith(preds ...predicate.BillingInvoice) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := newBillingInvoiceStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasSplitLineGroup applies the HasEdge predicate on the "split_line_group" edge. +func HasSplitLineGroup() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, SplitLineGroupTable, SplitLineGroupColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSplitLineGroupWith applies the HasEdge predicate on the "split_line_group" edge with a given conditions (other predicates). +func HasSplitLineGroupWith(preds ...predicate.BillingInvoiceSplitLineGroup) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := newSplitLineGroupStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasSubscription applies the HasEdge predicate on the "subscription" edge. +func HasSubscription() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, SubscriptionTable, SubscriptionColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSubscriptionWith applies the HasEdge predicate on the "subscription" edge with a given conditions (other predicates). +func HasSubscriptionWith(preds ...predicate.Subscription) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := newSubscriptionStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasSubscriptionPhase applies the HasEdge predicate on the "subscription_phase" edge. +func HasSubscriptionPhase() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, SubscriptionPhaseTable, SubscriptionPhaseColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSubscriptionPhaseWith applies the HasEdge predicate on the "subscription_phase" edge with a given conditions (other predicates). +func HasSubscriptionPhaseWith(preds ...predicate.SubscriptionPhase) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := newSubscriptionPhaseStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasSubscriptionItem applies the HasEdge predicate on the "subscription_item" edge. +func HasSubscriptionItem() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, SubscriptionItemTable, SubscriptionItemColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSubscriptionItemWith applies the HasEdge predicate on the "subscription_item" edge with a given conditions (other predicates). +func HasSubscriptionItemWith(preds ...predicate.SubscriptionItem) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := newSubscriptionItemStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasCharge applies the HasEdge predicate on the "charge" edge. +func HasCharge() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ChargeTable, ChargeColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasChargeWith applies the HasEdge predicate on the "charge" edge with a given conditions (other predicates). +func HasChargeWith(preds ...predicate.Charge) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := newChargeStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasTaxCode applies the HasEdge predicate on the "tax_code" edge. +func HasTaxCode() predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, TaxCodeTable, TaxCodeColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasTaxCodeWith applies the HasEdge predicate on the "tax_code" edge with a given conditions (other predicates). +func HasTaxCodeWith(preds ...predicate.TaxCode) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + step := newTaxCodeStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.BillingGatheringInvoiceLine) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.BillingGatheringInvoiceLine) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.BillingGatheringInvoiceLine) predicate.BillingGatheringInvoiceLine { + return predicate.BillingGatheringInvoiceLine(sql.NotPredicates(p)) +} diff --git a/openmeter/ent/db/billinggatheringinvoiceline_create.go b/openmeter/ent/db/billinggatheringinvoiceline_create.go new file mode 100644 index 0000000000..64435f6812 --- /dev/null +++ b/openmeter/ent/db/billinggatheringinvoiceline_create.go @@ -0,0 +1,2664 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/billing" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" + "github.com/openmeterio/openmeter/openmeter/ent/db/charge" + "github.com/openmeterio/openmeter/openmeter/ent/db/subscription" + "github.com/openmeterio/openmeter/openmeter/ent/db/subscriptionitem" + "github.com/openmeterio/openmeter/openmeter/ent/db/subscriptionphase" + dbtaxcode "github.com/openmeterio/openmeter/openmeter/ent/db/taxcode" + "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/pkg/currencyx" + "github.com/openmeterio/openmeter/pkg/models" +) + +// BillingGatheringInvoiceLineCreate is the builder for creating a BillingGatheringInvoiceLine entity. +type BillingGatheringInvoiceLineCreate struct { + config + mutation *BillingGatheringInvoiceLineMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetAnnotations sets the "annotations" field. +func (_c *BillingGatheringInvoiceLineCreate) SetAnnotations(v models.Annotations) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetAnnotations(v) + return _c +} + +// SetNamespace sets the "namespace" field. +func (_c *BillingGatheringInvoiceLineCreate) SetNamespace(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetNamespace(v) + return _c +} + +// SetMetadata sets the "metadata" field. +func (_c *BillingGatheringInvoiceLineCreate) SetMetadata(v map[string]string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetMetadata(v) + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *BillingGatheringInvoiceLineCreate) SetCreatedAt(v time.Time) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableCreatedAt(v *time.Time) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *BillingGatheringInvoiceLineCreate) SetUpdatedAt(v time.Time) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableUpdatedAt(v *time.Time) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetDeletedAt sets the "deleted_at" field. +func (_c *BillingGatheringInvoiceLineCreate) SetDeletedAt(v time.Time) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetDeletedAt(v) + return _c +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableDeletedAt(v *time.Time) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetDeletedAt(*v) + } + return _c +} + +// SetName sets the "name" field. +func (_c *BillingGatheringInvoiceLineCreate) SetName(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetName(v) + return _c +} + +// SetDescription sets the "description" field. +func (_c *BillingGatheringInvoiceLineCreate) SetDescription(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetDescription(v) + return _c +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableDescription(v *string) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetDescription(*v) + } + return _c +} + +// SetCurrency sets the "currency" field. +func (_c *BillingGatheringInvoiceLineCreate) SetCurrency(v currencyx.Code) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetCurrency(v) + return _c +} + +// SetServicePeriodStart sets the "service_period_start" field. +func (_c *BillingGatheringInvoiceLineCreate) SetServicePeriodStart(v time.Time) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetServicePeriodStart(v) + return _c +} + +// SetServicePeriodEnd sets the "service_period_end" field. +func (_c *BillingGatheringInvoiceLineCreate) SetServicePeriodEnd(v time.Time) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetServicePeriodEnd(v) + return _c +} + +// SetTaxConfig sets the "tax_config" field. +func (_c *BillingGatheringInvoiceLineCreate) SetTaxConfig(v billing.TaxConfig) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetTaxConfig(v) + return _c +} + +// SetNillableTaxConfig sets the "tax_config" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableTaxConfig(v *billing.TaxConfig) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetTaxConfig(*v) + } + return _c +} + +// SetPriceType sets the "price_type" field. +func (_c *BillingGatheringInvoiceLineCreate) SetPriceType(v productcatalog.PriceType) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetPriceType(v) + return _c +} + +// SetFeatureKey sets the "feature_key" field. +func (_c *BillingGatheringInvoiceLineCreate) SetFeatureKey(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetFeatureKey(v) + return _c +} + +// SetNillableFeatureKey sets the "feature_key" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableFeatureKey(v *string) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetFeatureKey(*v) + } + return _c +} + +// SetPrice sets the "price" field. +func (_c *BillingGatheringInvoiceLineCreate) SetPrice(v *productcatalog.Price) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetPrice(v) + return _c +} + +// SetUnitConfig sets the "unit_config" field. +func (_c *BillingGatheringInvoiceLineCreate) SetUnitConfig(v *productcatalog.UnitConfig) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetUnitConfig(v) + return _c +} + +// SetRatecardDiscounts sets the "ratecard_discounts" field. +func (_c *BillingGatheringInvoiceLineCreate) SetRatecardDiscounts(v *billing.Discounts) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetRatecardDiscounts(v) + return _c +} + +// SetChildUniqueReferenceID sets the "child_unique_reference_id" field. +func (_c *BillingGatheringInvoiceLineCreate) SetChildUniqueReferenceID(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetChildUniqueReferenceID(v) + return _c +} + +// SetNillableChildUniqueReferenceID sets the "child_unique_reference_id" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableChildUniqueReferenceID(v *string) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetChildUniqueReferenceID(*v) + } + return _c +} + +// SetSubscriptionID sets the "subscription_id" field. +func (_c *BillingGatheringInvoiceLineCreate) SetSubscriptionID(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetSubscriptionID(v) + return _c +} + +// SetNillableSubscriptionID sets the "subscription_id" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableSubscriptionID(v *string) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetSubscriptionID(*v) + } + return _c +} + +// SetSubscriptionPhaseID sets the "subscription_phase_id" field. +func (_c *BillingGatheringInvoiceLineCreate) SetSubscriptionPhaseID(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetSubscriptionPhaseID(v) + return _c +} + +// SetNillableSubscriptionPhaseID sets the "subscription_phase_id" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableSubscriptionPhaseID(v *string) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetSubscriptionPhaseID(*v) + } + return _c +} + +// SetSubscriptionItemID sets the "subscription_item_id" field. +func (_c *BillingGatheringInvoiceLineCreate) SetSubscriptionItemID(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetSubscriptionItemID(v) + return _c +} + +// SetNillableSubscriptionItemID sets the "subscription_item_id" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableSubscriptionItemID(v *string) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetSubscriptionItemID(*v) + } + return _c +} + +// SetSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field. +func (_c *BillingGatheringInvoiceLineCreate) SetSubscriptionBillingPeriodFrom(v time.Time) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetSubscriptionBillingPeriodFrom(v) + return _c +} + +// SetNillableSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableSubscriptionBillingPeriodFrom(v *time.Time) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetSubscriptionBillingPeriodFrom(*v) + } + return _c +} + +// SetSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field. +func (_c *BillingGatheringInvoiceLineCreate) SetSubscriptionBillingPeriodTo(v time.Time) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetSubscriptionBillingPeriodTo(v) + return _c +} + +// SetNillableSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableSubscriptionBillingPeriodTo(v *time.Time) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetSubscriptionBillingPeriodTo(*v) + } + return _c +} + +// SetTaxCodeID sets the "tax_code_id" field. +func (_c *BillingGatheringInvoiceLineCreate) SetTaxCodeID(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetTaxCodeID(v) + return _c +} + +// SetNillableTaxCodeID sets the "tax_code_id" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableTaxCodeID(v *string) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetTaxCodeID(*v) + } + return _c +} + +// SetTaxBehavior sets the "tax_behavior" field. +func (_c *BillingGatheringInvoiceLineCreate) SetTaxBehavior(v productcatalog.TaxBehavior) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetTaxBehavior(v) + return _c +} + +// SetNillableTaxBehavior sets the "tax_behavior" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableTaxBehavior(v *productcatalog.TaxBehavior) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetTaxBehavior(*v) + } + return _c +} + +// SetInvoiceID sets the "invoice_id" field. +func (_c *BillingGatheringInvoiceLineCreate) SetInvoiceID(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetInvoiceID(v) + return _c +} + +// SetInvoiceAt sets the "invoice_at" field. +func (_c *BillingGatheringInvoiceLineCreate) SetInvoiceAt(v time.Time) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetInvoiceAt(v) + return _c +} + +// SetManagedBy sets the "managed_by" field. +func (_c *BillingGatheringInvoiceLineCreate) SetManagedBy(v billing.InvoiceLineManagedBy) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetManagedBy(v) + return _c +} + +// SetEngine sets the "engine" field. +func (_c *BillingGatheringInvoiceLineCreate) SetEngine(v billing.LineEngineType) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetEngine(v) + return _c +} + +// SetNillableEngine sets the "engine" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableEngine(v *billing.LineEngineType) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetEngine(*v) + } + return _c +} + +// SetSplitLineGroupID sets the "split_line_group_id" field. +func (_c *BillingGatheringInvoiceLineCreate) SetSplitLineGroupID(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetSplitLineGroupID(v) + return _c +} + +// SetNillableSplitLineGroupID sets the "split_line_group_id" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableSplitLineGroupID(v *string) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetSplitLineGroupID(*v) + } + return _c +} + +// SetChargeID sets the "charge_id" field. +func (_c *BillingGatheringInvoiceLineCreate) SetChargeID(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetChargeID(v) + return _c +} + +// SetNillableChargeID sets the "charge_id" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableChargeID(v *string) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetChargeID(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *BillingGatheringInvoiceLineCreate) SetID(v string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *BillingGatheringInvoiceLineCreate) SetNillableID(v *string) *BillingGatheringInvoiceLineCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// SetBillingInvoiceID sets the "billing_invoice" edge to the BillingInvoice entity by ID. +func (_c *BillingGatheringInvoiceLineCreate) SetBillingInvoiceID(id string) *BillingGatheringInvoiceLineCreate { + _c.mutation.SetBillingInvoiceID(id) + return _c +} + +// SetBillingInvoice sets the "billing_invoice" edge to the BillingInvoice entity. +func (_c *BillingGatheringInvoiceLineCreate) SetBillingInvoice(v *BillingInvoice) *BillingGatheringInvoiceLineCreate { + return _c.SetBillingInvoiceID(v.ID) +} + +// SetSplitLineGroup sets the "split_line_group" edge to the BillingInvoiceSplitLineGroup entity. +func (_c *BillingGatheringInvoiceLineCreate) SetSplitLineGroup(v *BillingInvoiceSplitLineGroup) *BillingGatheringInvoiceLineCreate { + return _c.SetSplitLineGroupID(v.ID) +} + +// SetSubscription sets the "subscription" edge to the Subscription entity. +func (_c *BillingGatheringInvoiceLineCreate) SetSubscription(v *Subscription) *BillingGatheringInvoiceLineCreate { + return _c.SetSubscriptionID(v.ID) +} + +// SetSubscriptionPhase sets the "subscription_phase" edge to the SubscriptionPhase entity. +func (_c *BillingGatheringInvoiceLineCreate) SetSubscriptionPhase(v *SubscriptionPhase) *BillingGatheringInvoiceLineCreate { + return _c.SetSubscriptionPhaseID(v.ID) +} + +// SetSubscriptionItem sets the "subscription_item" edge to the SubscriptionItem entity. +func (_c *BillingGatheringInvoiceLineCreate) SetSubscriptionItem(v *SubscriptionItem) *BillingGatheringInvoiceLineCreate { + return _c.SetSubscriptionItemID(v.ID) +} + +// SetCharge sets the "charge" edge to the Charge entity. +func (_c *BillingGatheringInvoiceLineCreate) SetCharge(v *Charge) *BillingGatheringInvoiceLineCreate { + return _c.SetChargeID(v.ID) +} + +// SetTaxCode sets the "tax_code" edge to the TaxCode entity. +func (_c *BillingGatheringInvoiceLineCreate) SetTaxCode(v *TaxCode) *BillingGatheringInvoiceLineCreate { + return _c.SetTaxCodeID(v.ID) +} + +// Mutation returns the BillingGatheringInvoiceLineMutation object of the builder. +func (_c *BillingGatheringInvoiceLineCreate) Mutation() *BillingGatheringInvoiceLineMutation { + return _c.mutation +} + +// Save creates the BillingGatheringInvoiceLine in the database. +func (_c *BillingGatheringInvoiceLineCreate) Save(ctx context.Context) (*BillingGatheringInvoiceLine, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *BillingGatheringInvoiceLineCreate) SaveX(ctx context.Context) *BillingGatheringInvoiceLine { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *BillingGatheringInvoiceLineCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *BillingGatheringInvoiceLineCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *BillingGatheringInvoiceLineCreate) defaults() { + if _, ok := _c.mutation.CreatedAt(); !ok { + v := billinggatheringinvoiceline.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := billinggatheringinvoiceline.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.Engine(); !ok { + v := billinggatheringinvoiceline.DefaultEngine + _c.mutation.SetEngine(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := billinggatheringinvoiceline.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *BillingGatheringInvoiceLineCreate) check() error { + if _, ok := _c.mutation.Namespace(); !ok { + return &ValidationError{Name: "namespace", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.namespace"`)} + } + if v, ok := _c.mutation.Namespace(); ok { + if err := billinggatheringinvoiceline.NamespaceValidator(v); err != nil { + return &ValidationError{Name: "namespace", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.namespace": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.updated_at"`)} + } + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.name"`)} + } + if _, ok := _c.mutation.Currency(); !ok { + return &ValidationError{Name: "currency", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.currency"`)} + } + if v, ok := _c.mutation.Currency(); ok { + if err := billinggatheringinvoiceline.CurrencyValidator(string(v)); err != nil { + return &ValidationError{Name: "currency", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.currency": %w`, err)} + } + } + if _, ok := _c.mutation.ServicePeriodStart(); !ok { + return &ValidationError{Name: "service_period_start", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.service_period_start"`)} + } + if _, ok := _c.mutation.ServicePeriodEnd(); !ok { + return &ValidationError{Name: "service_period_end", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.service_period_end"`)} + } + if v, ok := _c.mutation.TaxConfig(); ok { + if err := v.Validate(); err != nil { + return &ValidationError{Name: "tax_config", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.tax_config": %w`, err)} + } + } + if _, ok := _c.mutation.PriceType(); !ok { + return &ValidationError{Name: "price_type", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.price_type"`)} + } + if v, ok := _c.mutation.PriceType(); ok { + if err := billinggatheringinvoiceline.PriceTypeValidator(v); err != nil { + return &ValidationError{Name: "price_type", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.price_type": %w`, err)} + } + } + if _, ok := _c.mutation.Price(); !ok { + return &ValidationError{Name: "price", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.price"`)} + } + if v, ok := _c.mutation.Price(); ok { + if err := v.Validate(); err != nil { + return &ValidationError{Name: "price", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.price": %w`, err)} + } + } + if v, ok := _c.mutation.UnitConfig(); ok { + if err := v.Validate(); err != nil { + return &ValidationError{Name: "unit_config", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.unit_config": %w`, err)} + } + } + if v, ok := _c.mutation.RatecardDiscounts(); ok { + if err := v.Validate(); err != nil { + return &ValidationError{Name: "ratecard_discounts", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.ratecard_discounts": %w`, err)} + } + } + if v, ok := _c.mutation.TaxBehavior(); ok { + if err := billinggatheringinvoiceline.TaxBehaviorValidator(v); err != nil { + return &ValidationError{Name: "tax_behavior", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.tax_behavior": %w`, err)} + } + } + if _, ok := _c.mutation.InvoiceID(); !ok { + return &ValidationError{Name: "invoice_id", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.invoice_id"`)} + } + if _, ok := _c.mutation.InvoiceAt(); !ok { + return &ValidationError{Name: "invoice_at", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.invoice_at"`)} + } + if _, ok := _c.mutation.ManagedBy(); !ok { + return &ValidationError{Name: "managed_by", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.managed_by"`)} + } + if v, ok := _c.mutation.ManagedBy(); ok { + if err := billinggatheringinvoiceline.ManagedByValidator(v); err != nil { + return &ValidationError{Name: "managed_by", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.managed_by": %w`, err)} + } + } + if _, ok := _c.mutation.Engine(); !ok { + return &ValidationError{Name: "engine", err: errors.New(`db: missing required field "BillingGatheringInvoiceLine.engine"`)} + } + if v, ok := _c.mutation.Engine(); ok { + if err := billinggatheringinvoiceline.EngineValidator(v); err != nil { + return &ValidationError{Name: "engine", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.engine": %w`, err)} + } + } + if len(_c.mutation.BillingInvoiceIDs()) == 0 { + return &ValidationError{Name: "billing_invoice", err: errors.New(`db: missing required edge "BillingGatheringInvoiceLine.billing_invoice"`)} + } + return nil +} + +func (_c *BillingGatheringInvoiceLineCreate) sqlSave(ctx context.Context) (*BillingGatheringInvoiceLine, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec, err := _c.createSpec() + if err != nil { + return nil, err + } + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(string); ok { + _node.ID = id + } else { + return nil, fmt.Errorf("unexpected BillingGatheringInvoiceLine.ID type: %T", _spec.ID.Value) + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *BillingGatheringInvoiceLineCreate) createSpec() (*BillingGatheringInvoiceLine, *sqlgraph.CreateSpec, error) { + var ( + _node = &BillingGatheringInvoiceLine{config: _c.config} + _spec = sqlgraph.NewCreateSpec(billinggatheringinvoiceline.Table, sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString)) + ) + _spec.OnConflict = _c.conflict + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := _c.mutation.Annotations(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldAnnotations, field.TypeJSON, value) + _node.Annotations = value + } + if value, ok := _c.mutation.Namespace(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldNamespace, field.TypeString, value) + _node.Namespace = value + } + if value, ok := _c.mutation.Metadata(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldMetadata, field.TypeJSON, value) + _node.Metadata = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := _c.mutation.DeletedAt(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldDeletedAt, field.TypeTime, value) + _node.DeletedAt = &value + } + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.Description(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldDescription, field.TypeString, value) + _node.Description = &value + } + if value, ok := _c.mutation.Currency(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldCurrency, field.TypeString, value) + _node.Currency = value + } + if value, ok := _c.mutation.ServicePeriodStart(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldServicePeriodStart, field.TypeTime, value) + _node.ServicePeriodStart = value + } + if value, ok := _c.mutation.ServicePeriodEnd(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldServicePeriodEnd, field.TypeTime, value) + _node.ServicePeriodEnd = value + } + if value, ok := _c.mutation.TaxConfig(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldTaxConfig, field.TypeJSON, value) + _node.TaxConfig = value + } + if value, ok := _c.mutation.PriceType(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldPriceType, field.TypeEnum, value) + _node.PriceType = value + } + if value, ok := _c.mutation.FeatureKey(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldFeatureKey, field.TypeString, value) + _node.FeatureKey = &value + } + if value, ok := _c.mutation.Price(); ok { + vv, err := billinggatheringinvoiceline.ValueScanner.Price.Value(value) + if err != nil { + return nil, nil, err + } + _spec.SetField(billinggatheringinvoiceline.FieldPrice, field.TypeString, vv) + _node.Price = value + } + if value, ok := _c.mutation.UnitConfig(); ok { + vv, err := billinggatheringinvoiceline.ValueScanner.UnitConfig.Value(value) + if err != nil { + return nil, nil, err + } + _spec.SetField(billinggatheringinvoiceline.FieldUnitConfig, field.TypeString, vv) + _node.UnitConfig = value + } + if value, ok := _c.mutation.RatecardDiscounts(); ok { + vv, err := billinggatheringinvoiceline.ValueScanner.RatecardDiscounts.Value(value) + if err != nil { + return nil, nil, err + } + _spec.SetField(billinggatheringinvoiceline.FieldRatecardDiscounts, field.TypeString, vv) + _node.RatecardDiscounts = value + } + if value, ok := _c.mutation.ChildUniqueReferenceID(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldChildUniqueReferenceID, field.TypeString, value) + _node.ChildUniqueReferenceID = &value + } + if value, ok := _c.mutation.SubscriptionBillingPeriodFrom(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom, field.TypeTime, value) + _node.SubscriptionBillingPeriodFrom = &value + } + if value, ok := _c.mutation.SubscriptionBillingPeriodTo(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo, field.TypeTime, value) + _node.SubscriptionBillingPeriodTo = &value + } + if value, ok := _c.mutation.TaxBehavior(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldTaxBehavior, field.TypeEnum, value) + _node.TaxBehavior = &value + } + if value, ok := _c.mutation.InvoiceAt(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldInvoiceAt, field.TypeTime, value) + _node.InvoiceAt = value + } + if value, ok := _c.mutation.ManagedBy(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldManagedBy, field.TypeEnum, value) + _node.ManagedBy = value + } + if value, ok := _c.mutation.Engine(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldEngine, field.TypeEnum, value) + _node.Engine = value + } + if nodes := _c.mutation.BillingInvoiceIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.BillingInvoiceTable, + Columns: []string{billinggatheringinvoiceline.BillingInvoiceColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinginvoice.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.InvoiceID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.SplitLineGroupIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SplitLineGroupTable, + Columns: []string{billinggatheringinvoiceline.SplitLineGroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinginvoicesplitlinegroup.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.SplitLineGroupID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.SubscriptionIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscription.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.SubscriptionID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.SubscriptionPhaseIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionPhaseTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionPhaseColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscriptionphase.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.SubscriptionPhaseID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.SubscriptionItemIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionItemTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionItemColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscriptionitem.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.SubscriptionItemID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.ChargeIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.ChargeTable, + Columns: []string{billinggatheringinvoiceline.ChargeColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(charge.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.ChargeID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.TaxCodeIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.TaxCodeTable, + Columns: []string{billinggatheringinvoiceline.TaxCodeColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(dbtaxcode.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.TaxCodeID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec, nil +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.BillingGatheringInvoiceLine.Create(). +// SetAnnotations(v). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.BillingGatheringInvoiceLineUpsert) { +// SetAnnotations(v+v). +// }). +// Exec(ctx) +func (_c *BillingGatheringInvoiceLineCreate) OnConflict(opts ...sql.ConflictOption) *BillingGatheringInvoiceLineUpsertOne { + _c.conflict = opts + return &BillingGatheringInvoiceLineUpsertOne{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.BillingGatheringInvoiceLine.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *BillingGatheringInvoiceLineCreate) OnConflictColumns(columns ...string) *BillingGatheringInvoiceLineUpsertOne { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &BillingGatheringInvoiceLineUpsertOne{ + create: _c, + } +} + +type ( + // BillingGatheringInvoiceLineUpsertOne is the builder for "upsert"-ing + // one BillingGatheringInvoiceLine node. + BillingGatheringInvoiceLineUpsertOne struct { + create *BillingGatheringInvoiceLineCreate + } + + // BillingGatheringInvoiceLineUpsert is the "OnConflict" setter. + BillingGatheringInvoiceLineUpsert struct { + *sql.UpdateSet + } +) + +// SetAnnotations sets the "annotations" field. +func (u *BillingGatheringInvoiceLineUpsert) SetAnnotations(v models.Annotations) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldAnnotations, v) + return u +} + +// UpdateAnnotations sets the "annotations" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateAnnotations() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldAnnotations) + return u +} + +// ClearAnnotations clears the value of the "annotations" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearAnnotations() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldAnnotations) + return u +} + +// SetMetadata sets the "metadata" field. +func (u *BillingGatheringInvoiceLineUpsert) SetMetadata(v map[string]string) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldMetadata, v) + return u +} + +// UpdateMetadata sets the "metadata" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateMetadata() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldMetadata) + return u +} + +// ClearMetadata clears the value of the "metadata" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearMetadata() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldMetadata) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *BillingGatheringInvoiceLineUpsert) SetUpdatedAt(v time.Time) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateUpdatedAt() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldUpdatedAt) + return u +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *BillingGatheringInvoiceLineUpsert) SetDeletedAt(v time.Time) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldDeletedAt, v) + return u +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateDeletedAt() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldDeletedAt) + return u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearDeletedAt() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldDeletedAt) + return u +} + +// SetName sets the "name" field. +func (u *BillingGatheringInvoiceLineUpsert) SetName(v string) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldName, v) + return u +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateName() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldName) + return u +} + +// SetDescription sets the "description" field. +func (u *BillingGatheringInvoiceLineUpsert) SetDescription(v string) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldDescription, v) + return u +} + +// UpdateDescription sets the "description" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateDescription() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldDescription) + return u +} + +// ClearDescription clears the value of the "description" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearDescription() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldDescription) + return u +} + +// SetServicePeriodStart sets the "service_period_start" field. +func (u *BillingGatheringInvoiceLineUpsert) SetServicePeriodStart(v time.Time) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldServicePeriodStart, v) + return u +} + +// UpdateServicePeriodStart sets the "service_period_start" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateServicePeriodStart() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldServicePeriodStart) + return u +} + +// SetServicePeriodEnd sets the "service_period_end" field. +func (u *BillingGatheringInvoiceLineUpsert) SetServicePeriodEnd(v time.Time) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldServicePeriodEnd, v) + return u +} + +// UpdateServicePeriodEnd sets the "service_period_end" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateServicePeriodEnd() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldServicePeriodEnd) + return u +} + +// SetTaxConfig sets the "tax_config" field. +func (u *BillingGatheringInvoiceLineUpsert) SetTaxConfig(v billing.TaxConfig) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldTaxConfig, v) + return u +} + +// UpdateTaxConfig sets the "tax_config" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateTaxConfig() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldTaxConfig) + return u +} + +// ClearTaxConfig clears the value of the "tax_config" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearTaxConfig() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldTaxConfig) + return u +} + +// SetPriceType sets the "price_type" field. +func (u *BillingGatheringInvoiceLineUpsert) SetPriceType(v productcatalog.PriceType) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldPriceType, v) + return u +} + +// UpdatePriceType sets the "price_type" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdatePriceType() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldPriceType) + return u +} + +// SetFeatureKey sets the "feature_key" field. +func (u *BillingGatheringInvoiceLineUpsert) SetFeatureKey(v string) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldFeatureKey, v) + return u +} + +// UpdateFeatureKey sets the "feature_key" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateFeatureKey() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldFeatureKey) + return u +} + +// ClearFeatureKey clears the value of the "feature_key" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearFeatureKey() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldFeatureKey) + return u +} + +// SetPrice sets the "price" field. +func (u *BillingGatheringInvoiceLineUpsert) SetPrice(v *productcatalog.Price) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldPrice, v) + return u +} + +// UpdatePrice sets the "price" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdatePrice() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldPrice) + return u +} + +// SetUnitConfig sets the "unit_config" field. +func (u *BillingGatheringInvoiceLineUpsert) SetUnitConfig(v *productcatalog.UnitConfig) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldUnitConfig, v) + return u +} + +// UpdateUnitConfig sets the "unit_config" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateUnitConfig() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldUnitConfig) + return u +} + +// ClearUnitConfig clears the value of the "unit_config" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearUnitConfig() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldUnitConfig) + return u +} + +// SetRatecardDiscounts sets the "ratecard_discounts" field. +func (u *BillingGatheringInvoiceLineUpsert) SetRatecardDiscounts(v *billing.Discounts) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldRatecardDiscounts, v) + return u +} + +// UpdateRatecardDiscounts sets the "ratecard_discounts" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateRatecardDiscounts() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldRatecardDiscounts) + return u +} + +// ClearRatecardDiscounts clears the value of the "ratecard_discounts" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearRatecardDiscounts() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldRatecardDiscounts) + return u +} + +// SetChildUniqueReferenceID sets the "child_unique_reference_id" field. +func (u *BillingGatheringInvoiceLineUpsert) SetChildUniqueReferenceID(v string) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldChildUniqueReferenceID, v) + return u +} + +// UpdateChildUniqueReferenceID sets the "child_unique_reference_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateChildUniqueReferenceID() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldChildUniqueReferenceID) + return u +} + +// ClearChildUniqueReferenceID clears the value of the "child_unique_reference_id" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearChildUniqueReferenceID() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldChildUniqueReferenceID) + return u +} + +// SetSubscriptionID sets the "subscription_id" field. +func (u *BillingGatheringInvoiceLineUpsert) SetSubscriptionID(v string) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldSubscriptionID, v) + return u +} + +// UpdateSubscriptionID sets the "subscription_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateSubscriptionID() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldSubscriptionID) + return u +} + +// ClearSubscriptionID clears the value of the "subscription_id" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearSubscriptionID() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldSubscriptionID) + return u +} + +// SetSubscriptionPhaseID sets the "subscription_phase_id" field. +func (u *BillingGatheringInvoiceLineUpsert) SetSubscriptionPhaseID(v string) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldSubscriptionPhaseID, v) + return u +} + +// UpdateSubscriptionPhaseID sets the "subscription_phase_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateSubscriptionPhaseID() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldSubscriptionPhaseID) + return u +} + +// ClearSubscriptionPhaseID clears the value of the "subscription_phase_id" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearSubscriptionPhaseID() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldSubscriptionPhaseID) + return u +} + +// SetSubscriptionItemID sets the "subscription_item_id" field. +func (u *BillingGatheringInvoiceLineUpsert) SetSubscriptionItemID(v string) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldSubscriptionItemID, v) + return u +} + +// UpdateSubscriptionItemID sets the "subscription_item_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateSubscriptionItemID() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldSubscriptionItemID) + return u +} + +// ClearSubscriptionItemID clears the value of the "subscription_item_id" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearSubscriptionItemID() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldSubscriptionItemID) + return u +} + +// SetSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field. +func (u *BillingGatheringInvoiceLineUpsert) SetSubscriptionBillingPeriodFrom(v time.Time) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom, v) + return u +} + +// UpdateSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateSubscriptionBillingPeriodFrom() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom) + return u +} + +// ClearSubscriptionBillingPeriodFrom clears the value of the "subscription_billing_period_from" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearSubscriptionBillingPeriodFrom() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom) + return u +} + +// SetSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field. +func (u *BillingGatheringInvoiceLineUpsert) SetSubscriptionBillingPeriodTo(v time.Time) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo, v) + return u +} + +// UpdateSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateSubscriptionBillingPeriodTo() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo) + return u +} + +// ClearSubscriptionBillingPeriodTo clears the value of the "subscription_billing_period_to" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearSubscriptionBillingPeriodTo() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo) + return u +} + +// SetTaxCodeID sets the "tax_code_id" field. +func (u *BillingGatheringInvoiceLineUpsert) SetTaxCodeID(v string) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldTaxCodeID, v) + return u +} + +// UpdateTaxCodeID sets the "tax_code_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateTaxCodeID() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldTaxCodeID) + return u +} + +// ClearTaxCodeID clears the value of the "tax_code_id" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearTaxCodeID() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldTaxCodeID) + return u +} + +// SetTaxBehavior sets the "tax_behavior" field. +func (u *BillingGatheringInvoiceLineUpsert) SetTaxBehavior(v productcatalog.TaxBehavior) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldTaxBehavior, v) + return u +} + +// UpdateTaxBehavior sets the "tax_behavior" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateTaxBehavior() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldTaxBehavior) + return u +} + +// ClearTaxBehavior clears the value of the "tax_behavior" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearTaxBehavior() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldTaxBehavior) + return u +} + +// SetInvoiceID sets the "invoice_id" field. +func (u *BillingGatheringInvoiceLineUpsert) SetInvoiceID(v string) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldInvoiceID, v) + return u +} + +// UpdateInvoiceID sets the "invoice_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateInvoiceID() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldInvoiceID) + return u +} + +// SetInvoiceAt sets the "invoice_at" field. +func (u *BillingGatheringInvoiceLineUpsert) SetInvoiceAt(v time.Time) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldInvoiceAt, v) + return u +} + +// UpdateInvoiceAt sets the "invoice_at" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateInvoiceAt() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldInvoiceAt) + return u +} + +// SetManagedBy sets the "managed_by" field. +func (u *BillingGatheringInvoiceLineUpsert) SetManagedBy(v billing.InvoiceLineManagedBy) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldManagedBy, v) + return u +} + +// UpdateManagedBy sets the "managed_by" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateManagedBy() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldManagedBy) + return u +} + +// SetEngine sets the "engine" field. +func (u *BillingGatheringInvoiceLineUpsert) SetEngine(v billing.LineEngineType) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldEngine, v) + return u +} + +// UpdateEngine sets the "engine" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateEngine() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldEngine) + return u +} + +// SetSplitLineGroupID sets the "split_line_group_id" field. +func (u *BillingGatheringInvoiceLineUpsert) SetSplitLineGroupID(v string) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldSplitLineGroupID, v) + return u +} + +// UpdateSplitLineGroupID sets the "split_line_group_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateSplitLineGroupID() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldSplitLineGroupID) + return u +} + +// ClearSplitLineGroupID clears the value of the "split_line_group_id" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearSplitLineGroupID() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldSplitLineGroupID) + return u +} + +// SetChargeID sets the "charge_id" field. +func (u *BillingGatheringInvoiceLineUpsert) SetChargeID(v string) *BillingGatheringInvoiceLineUpsert { + u.Set(billinggatheringinvoiceline.FieldChargeID, v) + return u +} + +// UpdateChargeID sets the "charge_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsert) UpdateChargeID() *BillingGatheringInvoiceLineUpsert { + u.SetExcluded(billinggatheringinvoiceline.FieldChargeID) + return u +} + +// ClearChargeID clears the value of the "charge_id" field. +func (u *BillingGatheringInvoiceLineUpsert) ClearChargeID() *BillingGatheringInvoiceLineUpsert { + u.SetNull(billinggatheringinvoiceline.FieldChargeID) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. +// Using this option is equivalent to using: +// +// client.BillingGatheringInvoiceLine.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(billinggatheringinvoiceline.FieldID) +// }), +// ). +// Exec(ctx) +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateNewValues() *BillingGatheringInvoiceLineUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + if _, exists := u.create.mutation.ID(); exists { + s.SetIgnore(billinggatheringinvoiceline.FieldID) + } + if _, exists := u.create.mutation.Namespace(); exists { + s.SetIgnore(billinggatheringinvoiceline.FieldNamespace) + } + if _, exists := u.create.mutation.CreatedAt(); exists { + s.SetIgnore(billinggatheringinvoiceline.FieldCreatedAt) + } + if _, exists := u.create.mutation.Currency(); exists { + s.SetIgnore(billinggatheringinvoiceline.FieldCurrency) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.BillingGatheringInvoiceLine.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *BillingGatheringInvoiceLineUpsertOne) Ignore() *BillingGatheringInvoiceLineUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *BillingGatheringInvoiceLineUpsertOne) DoNothing() *BillingGatheringInvoiceLineUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the BillingGatheringInvoiceLineCreate.OnConflict +// documentation for more info. +func (u *BillingGatheringInvoiceLineUpsertOne) Update(set func(*BillingGatheringInvoiceLineUpsert)) *BillingGatheringInvoiceLineUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&BillingGatheringInvoiceLineUpsert{UpdateSet: update}) + })) + return u +} + +// SetAnnotations sets the "annotations" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetAnnotations(v models.Annotations) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetAnnotations(v) + }) +} + +// UpdateAnnotations sets the "annotations" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateAnnotations() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateAnnotations() + }) +} + +// ClearAnnotations clears the value of the "annotations" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearAnnotations() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearAnnotations() + }) +} + +// SetMetadata sets the "metadata" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetMetadata(v map[string]string) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetMetadata(v) + }) +} + +// UpdateMetadata sets the "metadata" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateMetadata() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateMetadata() + }) +} + +// ClearMetadata clears the value of the "metadata" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearMetadata() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearMetadata() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetUpdatedAt(v time.Time) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateUpdatedAt() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetDeletedAt(v time.Time) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetDeletedAt(v) + }) +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateDeletedAt() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateDeletedAt() + }) +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearDeletedAt() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearDeletedAt() + }) +} + +// SetName sets the "name" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetName(v string) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateName() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateName() + }) +} + +// SetDescription sets the "description" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetDescription(v string) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetDescription(v) + }) +} + +// UpdateDescription sets the "description" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateDescription() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateDescription() + }) +} + +// ClearDescription clears the value of the "description" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearDescription() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearDescription() + }) +} + +// SetServicePeriodStart sets the "service_period_start" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetServicePeriodStart(v time.Time) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetServicePeriodStart(v) + }) +} + +// UpdateServicePeriodStart sets the "service_period_start" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateServicePeriodStart() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateServicePeriodStart() + }) +} + +// SetServicePeriodEnd sets the "service_period_end" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetServicePeriodEnd(v time.Time) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetServicePeriodEnd(v) + }) +} + +// UpdateServicePeriodEnd sets the "service_period_end" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateServicePeriodEnd() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateServicePeriodEnd() + }) +} + +// SetTaxConfig sets the "tax_config" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetTaxConfig(v billing.TaxConfig) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetTaxConfig(v) + }) +} + +// UpdateTaxConfig sets the "tax_config" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateTaxConfig() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateTaxConfig() + }) +} + +// ClearTaxConfig clears the value of the "tax_config" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearTaxConfig() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearTaxConfig() + }) +} + +// SetPriceType sets the "price_type" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetPriceType(v productcatalog.PriceType) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetPriceType(v) + }) +} + +// UpdatePriceType sets the "price_type" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdatePriceType() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdatePriceType() + }) +} + +// SetFeatureKey sets the "feature_key" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetFeatureKey(v string) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetFeatureKey(v) + }) +} + +// UpdateFeatureKey sets the "feature_key" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateFeatureKey() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateFeatureKey() + }) +} + +// ClearFeatureKey clears the value of the "feature_key" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearFeatureKey() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearFeatureKey() + }) +} + +// SetPrice sets the "price" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetPrice(v *productcatalog.Price) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetPrice(v) + }) +} + +// UpdatePrice sets the "price" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdatePrice() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdatePrice() + }) +} + +// SetUnitConfig sets the "unit_config" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetUnitConfig(v *productcatalog.UnitConfig) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetUnitConfig(v) + }) +} + +// UpdateUnitConfig sets the "unit_config" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateUnitConfig() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateUnitConfig() + }) +} + +// ClearUnitConfig clears the value of the "unit_config" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearUnitConfig() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearUnitConfig() + }) +} + +// SetRatecardDiscounts sets the "ratecard_discounts" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetRatecardDiscounts(v *billing.Discounts) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetRatecardDiscounts(v) + }) +} + +// UpdateRatecardDiscounts sets the "ratecard_discounts" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateRatecardDiscounts() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateRatecardDiscounts() + }) +} + +// ClearRatecardDiscounts clears the value of the "ratecard_discounts" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearRatecardDiscounts() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearRatecardDiscounts() + }) +} + +// SetChildUniqueReferenceID sets the "child_unique_reference_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetChildUniqueReferenceID(v string) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetChildUniqueReferenceID(v) + }) +} + +// UpdateChildUniqueReferenceID sets the "child_unique_reference_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateChildUniqueReferenceID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateChildUniqueReferenceID() + }) +} + +// ClearChildUniqueReferenceID clears the value of the "child_unique_reference_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearChildUniqueReferenceID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearChildUniqueReferenceID() + }) +} + +// SetSubscriptionID sets the "subscription_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetSubscriptionID(v string) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetSubscriptionID(v) + }) +} + +// UpdateSubscriptionID sets the "subscription_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateSubscriptionID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateSubscriptionID() + }) +} + +// ClearSubscriptionID clears the value of the "subscription_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearSubscriptionID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearSubscriptionID() + }) +} + +// SetSubscriptionPhaseID sets the "subscription_phase_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetSubscriptionPhaseID(v string) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetSubscriptionPhaseID(v) + }) +} + +// UpdateSubscriptionPhaseID sets the "subscription_phase_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateSubscriptionPhaseID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateSubscriptionPhaseID() + }) +} + +// ClearSubscriptionPhaseID clears the value of the "subscription_phase_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearSubscriptionPhaseID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearSubscriptionPhaseID() + }) +} + +// SetSubscriptionItemID sets the "subscription_item_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetSubscriptionItemID(v string) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetSubscriptionItemID(v) + }) +} + +// UpdateSubscriptionItemID sets the "subscription_item_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateSubscriptionItemID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateSubscriptionItemID() + }) +} + +// ClearSubscriptionItemID clears the value of the "subscription_item_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearSubscriptionItemID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearSubscriptionItemID() + }) +} + +// SetSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetSubscriptionBillingPeriodFrom(v time.Time) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetSubscriptionBillingPeriodFrom(v) + }) +} + +// UpdateSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateSubscriptionBillingPeriodFrom() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateSubscriptionBillingPeriodFrom() + }) +} + +// ClearSubscriptionBillingPeriodFrom clears the value of the "subscription_billing_period_from" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearSubscriptionBillingPeriodFrom() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearSubscriptionBillingPeriodFrom() + }) +} + +// SetSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetSubscriptionBillingPeriodTo(v time.Time) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetSubscriptionBillingPeriodTo(v) + }) +} + +// UpdateSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateSubscriptionBillingPeriodTo() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateSubscriptionBillingPeriodTo() + }) +} + +// ClearSubscriptionBillingPeriodTo clears the value of the "subscription_billing_period_to" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearSubscriptionBillingPeriodTo() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearSubscriptionBillingPeriodTo() + }) +} + +// SetTaxCodeID sets the "tax_code_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetTaxCodeID(v string) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetTaxCodeID(v) + }) +} + +// UpdateTaxCodeID sets the "tax_code_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateTaxCodeID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateTaxCodeID() + }) +} + +// ClearTaxCodeID clears the value of the "tax_code_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearTaxCodeID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearTaxCodeID() + }) +} + +// SetTaxBehavior sets the "tax_behavior" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetTaxBehavior(v productcatalog.TaxBehavior) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetTaxBehavior(v) + }) +} + +// UpdateTaxBehavior sets the "tax_behavior" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateTaxBehavior() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateTaxBehavior() + }) +} + +// ClearTaxBehavior clears the value of the "tax_behavior" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearTaxBehavior() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearTaxBehavior() + }) +} + +// SetInvoiceID sets the "invoice_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetInvoiceID(v string) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetInvoiceID(v) + }) +} + +// UpdateInvoiceID sets the "invoice_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateInvoiceID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateInvoiceID() + }) +} + +// SetInvoiceAt sets the "invoice_at" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetInvoiceAt(v time.Time) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetInvoiceAt(v) + }) +} + +// UpdateInvoiceAt sets the "invoice_at" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateInvoiceAt() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateInvoiceAt() + }) +} + +// SetManagedBy sets the "managed_by" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetManagedBy(v billing.InvoiceLineManagedBy) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetManagedBy(v) + }) +} + +// UpdateManagedBy sets the "managed_by" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateManagedBy() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateManagedBy() + }) +} + +// SetEngine sets the "engine" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetEngine(v billing.LineEngineType) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetEngine(v) + }) +} + +// UpdateEngine sets the "engine" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateEngine() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateEngine() + }) +} + +// SetSplitLineGroupID sets the "split_line_group_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetSplitLineGroupID(v string) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetSplitLineGroupID(v) + }) +} + +// UpdateSplitLineGroupID sets the "split_line_group_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateSplitLineGroupID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateSplitLineGroupID() + }) +} + +// ClearSplitLineGroupID clears the value of the "split_line_group_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearSplitLineGroupID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearSplitLineGroupID() + }) +} + +// SetChargeID sets the "charge_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) SetChargeID(v string) *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetChargeID(v) + }) +} + +// UpdateChargeID sets the "charge_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertOne) UpdateChargeID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateChargeID() + }) +} + +// ClearChargeID clears the value of the "charge_id" field. +func (u *BillingGatheringInvoiceLineUpsertOne) ClearChargeID() *BillingGatheringInvoiceLineUpsertOne { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearChargeID() + }) +} + +// Exec executes the query. +func (u *BillingGatheringInvoiceLineUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for BillingGatheringInvoiceLineCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *BillingGatheringInvoiceLineUpsertOne) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} + +// Exec executes the UPSERT query and returns the inserted/updated ID. +func (u *BillingGatheringInvoiceLineUpsertOne) ID(ctx context.Context) (id string, err error) { + if u.create.driver.Dialect() == dialect.MySQL { + // In case of "ON CONFLICT", there is no way to get back non-numeric ID + // fields from the database since MySQL does not support the RETURNING clause. + return id, errors.New("db: BillingGatheringInvoiceLineUpsertOne.ID is not supported by MySQL driver. Use BillingGatheringInvoiceLineUpsertOne.Exec instead") + } + node, err := u.create.Save(ctx) + if err != nil { + return id, err + } + return node.ID, nil +} + +// IDX is like ID, but panics if an error occurs. +func (u *BillingGatheringInvoiceLineUpsertOne) IDX(ctx context.Context) string { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// BillingGatheringInvoiceLineCreateBulk is the builder for creating many BillingGatheringInvoiceLine entities in bulk. +type BillingGatheringInvoiceLineCreateBulk struct { + config + err error + builders []*BillingGatheringInvoiceLineCreate + conflict []sql.ConflictOption +} + +// Save creates the BillingGatheringInvoiceLine entities in the database. +func (_c *BillingGatheringInvoiceLineCreateBulk) Save(ctx context.Context) ([]*BillingGatheringInvoiceLine, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*BillingGatheringInvoiceLine, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*BillingGatheringInvoiceLineMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i], err = builder.createSpec() + if err != nil { + return nil, err + } + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = _c.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *BillingGatheringInvoiceLineCreateBulk) SaveX(ctx context.Context) []*BillingGatheringInvoiceLine { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *BillingGatheringInvoiceLineCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *BillingGatheringInvoiceLineCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.BillingGatheringInvoiceLine.CreateBulk(builders...). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.BillingGatheringInvoiceLineUpsert) { +// SetAnnotations(v+v). +// }). +// Exec(ctx) +func (_c *BillingGatheringInvoiceLineCreateBulk) OnConflict(opts ...sql.ConflictOption) *BillingGatheringInvoiceLineUpsertBulk { + _c.conflict = opts + return &BillingGatheringInvoiceLineUpsertBulk{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.BillingGatheringInvoiceLine.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *BillingGatheringInvoiceLineCreateBulk) OnConflictColumns(columns ...string) *BillingGatheringInvoiceLineUpsertBulk { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &BillingGatheringInvoiceLineUpsertBulk{ + create: _c, + } +} + +// BillingGatheringInvoiceLineUpsertBulk is the builder for "upsert"-ing +// a bulk of BillingGatheringInvoiceLine nodes. +type BillingGatheringInvoiceLineUpsertBulk struct { + create *BillingGatheringInvoiceLineCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.BillingGatheringInvoiceLine.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(billinggatheringinvoiceline.FieldID) +// }), +// ). +// Exec(ctx) +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateNewValues() *BillingGatheringInvoiceLineUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + for _, b := range u.create.builders { + if _, exists := b.mutation.ID(); exists { + s.SetIgnore(billinggatheringinvoiceline.FieldID) + } + if _, exists := b.mutation.Namespace(); exists { + s.SetIgnore(billinggatheringinvoiceline.FieldNamespace) + } + if _, exists := b.mutation.CreatedAt(); exists { + s.SetIgnore(billinggatheringinvoiceline.FieldCreatedAt) + } + if _, exists := b.mutation.Currency(); exists { + s.SetIgnore(billinggatheringinvoiceline.FieldCurrency) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.BillingGatheringInvoiceLine.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *BillingGatheringInvoiceLineUpsertBulk) Ignore() *BillingGatheringInvoiceLineUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *BillingGatheringInvoiceLineUpsertBulk) DoNothing() *BillingGatheringInvoiceLineUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the BillingGatheringInvoiceLineCreateBulk.OnConflict +// documentation for more info. +func (u *BillingGatheringInvoiceLineUpsertBulk) Update(set func(*BillingGatheringInvoiceLineUpsert)) *BillingGatheringInvoiceLineUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&BillingGatheringInvoiceLineUpsert{UpdateSet: update}) + })) + return u +} + +// SetAnnotations sets the "annotations" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetAnnotations(v models.Annotations) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetAnnotations(v) + }) +} + +// UpdateAnnotations sets the "annotations" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateAnnotations() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateAnnotations() + }) +} + +// ClearAnnotations clears the value of the "annotations" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearAnnotations() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearAnnotations() + }) +} + +// SetMetadata sets the "metadata" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetMetadata(v map[string]string) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetMetadata(v) + }) +} + +// UpdateMetadata sets the "metadata" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateMetadata() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateMetadata() + }) +} + +// ClearMetadata clears the value of the "metadata" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearMetadata() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearMetadata() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetUpdatedAt(v time.Time) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateUpdatedAt() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetDeletedAt(v time.Time) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetDeletedAt(v) + }) +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateDeletedAt() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateDeletedAt() + }) +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearDeletedAt() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearDeletedAt() + }) +} + +// SetName sets the "name" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetName(v string) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateName() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateName() + }) +} + +// SetDescription sets the "description" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetDescription(v string) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetDescription(v) + }) +} + +// UpdateDescription sets the "description" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateDescription() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateDescription() + }) +} + +// ClearDescription clears the value of the "description" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearDescription() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearDescription() + }) +} + +// SetServicePeriodStart sets the "service_period_start" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetServicePeriodStart(v time.Time) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetServicePeriodStart(v) + }) +} + +// UpdateServicePeriodStart sets the "service_period_start" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateServicePeriodStart() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateServicePeriodStart() + }) +} + +// SetServicePeriodEnd sets the "service_period_end" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetServicePeriodEnd(v time.Time) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetServicePeriodEnd(v) + }) +} + +// UpdateServicePeriodEnd sets the "service_period_end" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateServicePeriodEnd() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateServicePeriodEnd() + }) +} + +// SetTaxConfig sets the "tax_config" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetTaxConfig(v billing.TaxConfig) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetTaxConfig(v) + }) +} + +// UpdateTaxConfig sets the "tax_config" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateTaxConfig() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateTaxConfig() + }) +} + +// ClearTaxConfig clears the value of the "tax_config" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearTaxConfig() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearTaxConfig() + }) +} + +// SetPriceType sets the "price_type" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetPriceType(v productcatalog.PriceType) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetPriceType(v) + }) +} + +// UpdatePriceType sets the "price_type" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdatePriceType() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdatePriceType() + }) +} + +// SetFeatureKey sets the "feature_key" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetFeatureKey(v string) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetFeatureKey(v) + }) +} + +// UpdateFeatureKey sets the "feature_key" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateFeatureKey() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateFeatureKey() + }) +} + +// ClearFeatureKey clears the value of the "feature_key" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearFeatureKey() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearFeatureKey() + }) +} + +// SetPrice sets the "price" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetPrice(v *productcatalog.Price) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetPrice(v) + }) +} + +// UpdatePrice sets the "price" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdatePrice() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdatePrice() + }) +} + +// SetUnitConfig sets the "unit_config" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetUnitConfig(v *productcatalog.UnitConfig) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetUnitConfig(v) + }) +} + +// UpdateUnitConfig sets the "unit_config" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateUnitConfig() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateUnitConfig() + }) +} + +// ClearUnitConfig clears the value of the "unit_config" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearUnitConfig() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearUnitConfig() + }) +} + +// SetRatecardDiscounts sets the "ratecard_discounts" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetRatecardDiscounts(v *billing.Discounts) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetRatecardDiscounts(v) + }) +} + +// UpdateRatecardDiscounts sets the "ratecard_discounts" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateRatecardDiscounts() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateRatecardDiscounts() + }) +} + +// ClearRatecardDiscounts clears the value of the "ratecard_discounts" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearRatecardDiscounts() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearRatecardDiscounts() + }) +} + +// SetChildUniqueReferenceID sets the "child_unique_reference_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetChildUniqueReferenceID(v string) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetChildUniqueReferenceID(v) + }) +} + +// UpdateChildUniqueReferenceID sets the "child_unique_reference_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateChildUniqueReferenceID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateChildUniqueReferenceID() + }) +} + +// ClearChildUniqueReferenceID clears the value of the "child_unique_reference_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearChildUniqueReferenceID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearChildUniqueReferenceID() + }) +} + +// SetSubscriptionID sets the "subscription_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetSubscriptionID(v string) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetSubscriptionID(v) + }) +} + +// UpdateSubscriptionID sets the "subscription_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateSubscriptionID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateSubscriptionID() + }) +} + +// ClearSubscriptionID clears the value of the "subscription_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearSubscriptionID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearSubscriptionID() + }) +} + +// SetSubscriptionPhaseID sets the "subscription_phase_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetSubscriptionPhaseID(v string) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetSubscriptionPhaseID(v) + }) +} + +// UpdateSubscriptionPhaseID sets the "subscription_phase_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateSubscriptionPhaseID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateSubscriptionPhaseID() + }) +} + +// ClearSubscriptionPhaseID clears the value of the "subscription_phase_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearSubscriptionPhaseID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearSubscriptionPhaseID() + }) +} + +// SetSubscriptionItemID sets the "subscription_item_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetSubscriptionItemID(v string) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetSubscriptionItemID(v) + }) +} + +// UpdateSubscriptionItemID sets the "subscription_item_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateSubscriptionItemID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateSubscriptionItemID() + }) +} + +// ClearSubscriptionItemID clears the value of the "subscription_item_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearSubscriptionItemID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearSubscriptionItemID() + }) +} + +// SetSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetSubscriptionBillingPeriodFrom(v time.Time) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetSubscriptionBillingPeriodFrom(v) + }) +} + +// UpdateSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateSubscriptionBillingPeriodFrom() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateSubscriptionBillingPeriodFrom() + }) +} + +// ClearSubscriptionBillingPeriodFrom clears the value of the "subscription_billing_period_from" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearSubscriptionBillingPeriodFrom() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearSubscriptionBillingPeriodFrom() + }) +} + +// SetSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetSubscriptionBillingPeriodTo(v time.Time) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetSubscriptionBillingPeriodTo(v) + }) +} + +// UpdateSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateSubscriptionBillingPeriodTo() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateSubscriptionBillingPeriodTo() + }) +} + +// ClearSubscriptionBillingPeriodTo clears the value of the "subscription_billing_period_to" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearSubscriptionBillingPeriodTo() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearSubscriptionBillingPeriodTo() + }) +} + +// SetTaxCodeID sets the "tax_code_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetTaxCodeID(v string) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetTaxCodeID(v) + }) +} + +// UpdateTaxCodeID sets the "tax_code_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateTaxCodeID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateTaxCodeID() + }) +} + +// ClearTaxCodeID clears the value of the "tax_code_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearTaxCodeID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearTaxCodeID() + }) +} + +// SetTaxBehavior sets the "tax_behavior" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetTaxBehavior(v productcatalog.TaxBehavior) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetTaxBehavior(v) + }) +} + +// UpdateTaxBehavior sets the "tax_behavior" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateTaxBehavior() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateTaxBehavior() + }) +} + +// ClearTaxBehavior clears the value of the "tax_behavior" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearTaxBehavior() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearTaxBehavior() + }) +} + +// SetInvoiceID sets the "invoice_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetInvoiceID(v string) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetInvoiceID(v) + }) +} + +// UpdateInvoiceID sets the "invoice_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateInvoiceID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateInvoiceID() + }) +} + +// SetInvoiceAt sets the "invoice_at" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetInvoiceAt(v time.Time) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetInvoiceAt(v) + }) +} + +// UpdateInvoiceAt sets the "invoice_at" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateInvoiceAt() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateInvoiceAt() + }) +} + +// SetManagedBy sets the "managed_by" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetManagedBy(v billing.InvoiceLineManagedBy) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetManagedBy(v) + }) +} + +// UpdateManagedBy sets the "managed_by" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateManagedBy() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateManagedBy() + }) +} + +// SetEngine sets the "engine" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetEngine(v billing.LineEngineType) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetEngine(v) + }) +} + +// UpdateEngine sets the "engine" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateEngine() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateEngine() + }) +} + +// SetSplitLineGroupID sets the "split_line_group_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetSplitLineGroupID(v string) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetSplitLineGroupID(v) + }) +} + +// UpdateSplitLineGroupID sets the "split_line_group_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateSplitLineGroupID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateSplitLineGroupID() + }) +} + +// ClearSplitLineGroupID clears the value of the "split_line_group_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearSplitLineGroupID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearSplitLineGroupID() + }) +} + +// SetChargeID sets the "charge_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) SetChargeID(v string) *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.SetChargeID(v) + }) +} + +// UpdateChargeID sets the "charge_id" field to the value that was provided on create. +func (u *BillingGatheringInvoiceLineUpsertBulk) UpdateChargeID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.UpdateChargeID() + }) +} + +// ClearChargeID clears the value of the "charge_id" field. +func (u *BillingGatheringInvoiceLineUpsertBulk) ClearChargeID() *BillingGatheringInvoiceLineUpsertBulk { + return u.Update(func(s *BillingGatheringInvoiceLineUpsert) { + s.ClearChargeID() + }) +} + +// Exec executes the query. +func (u *BillingGatheringInvoiceLineUpsertBulk) Exec(ctx context.Context) error { + if u.create.err != nil { + return u.create.err + } + for i, b := range u.create.builders { + if len(b.conflict) != 0 { + return fmt.Errorf("db: OnConflict was set for builder %d. Set it on the BillingGatheringInvoiceLineCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for BillingGatheringInvoiceLineCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *BillingGatheringInvoiceLineUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/openmeter/ent/db/billinggatheringinvoiceline_delete.go b/openmeter/ent/db/billinggatheringinvoiceline_delete.go new file mode 100644 index 0000000000..03872f7a2b --- /dev/null +++ b/openmeter/ent/db/billinggatheringinvoiceline_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" +) + +// BillingGatheringInvoiceLineDelete is the builder for deleting a BillingGatheringInvoiceLine entity. +type BillingGatheringInvoiceLineDelete struct { + config + hooks []Hook + mutation *BillingGatheringInvoiceLineMutation +} + +// Where appends a list predicates to the BillingGatheringInvoiceLineDelete builder. +func (_d *BillingGatheringInvoiceLineDelete) Where(ps ...predicate.BillingGatheringInvoiceLine) *BillingGatheringInvoiceLineDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *BillingGatheringInvoiceLineDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *BillingGatheringInvoiceLineDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *BillingGatheringInvoiceLineDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(billinggatheringinvoiceline.Table, sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// BillingGatheringInvoiceLineDeleteOne is the builder for deleting a single BillingGatheringInvoiceLine entity. +type BillingGatheringInvoiceLineDeleteOne struct { + _d *BillingGatheringInvoiceLineDelete +} + +// Where appends a list predicates to the BillingGatheringInvoiceLineDelete builder. +func (_d *BillingGatheringInvoiceLineDeleteOne) Where(ps ...predicate.BillingGatheringInvoiceLine) *BillingGatheringInvoiceLineDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *BillingGatheringInvoiceLineDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{billinggatheringinvoiceline.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *BillingGatheringInvoiceLineDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/openmeter/ent/db/billinggatheringinvoiceline_query.go b/openmeter/ent/db/billinggatheringinvoiceline_query.go new file mode 100644 index 0000000000..80bb0a51c2 --- /dev/null +++ b/openmeter/ent/db/billinggatheringinvoiceline_query.go @@ -0,0 +1,1111 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" + "github.com/openmeterio/openmeter/openmeter/ent/db/charge" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" + "github.com/openmeterio/openmeter/openmeter/ent/db/subscription" + "github.com/openmeterio/openmeter/openmeter/ent/db/subscriptionitem" + "github.com/openmeterio/openmeter/openmeter/ent/db/subscriptionphase" + dbtaxcode "github.com/openmeterio/openmeter/openmeter/ent/db/taxcode" +) + +// BillingGatheringInvoiceLineQuery is the builder for querying BillingGatheringInvoiceLine entities. +type BillingGatheringInvoiceLineQuery struct { + config + ctx *QueryContext + order []billinggatheringinvoiceline.OrderOption + inters []Interceptor + predicates []predicate.BillingGatheringInvoiceLine + withBillingInvoice *BillingInvoiceQuery + withSplitLineGroup *BillingInvoiceSplitLineGroupQuery + withSubscription *SubscriptionQuery + withSubscriptionPhase *SubscriptionPhaseQuery + withSubscriptionItem *SubscriptionItemQuery + withCharge *ChargeQuery + withTaxCode *TaxCodeQuery + modifiers []func(*sql.Selector) + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the BillingGatheringInvoiceLineQuery builder. +func (_q *BillingGatheringInvoiceLineQuery) Where(ps ...predicate.BillingGatheringInvoiceLine) *BillingGatheringInvoiceLineQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *BillingGatheringInvoiceLineQuery) Limit(limit int) *BillingGatheringInvoiceLineQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *BillingGatheringInvoiceLineQuery) Offset(offset int) *BillingGatheringInvoiceLineQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *BillingGatheringInvoiceLineQuery) Unique(unique bool) *BillingGatheringInvoiceLineQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *BillingGatheringInvoiceLineQuery) Order(o ...billinggatheringinvoiceline.OrderOption) *BillingGatheringInvoiceLineQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryBillingInvoice chains the current query on the "billing_invoice" edge. +func (_q *BillingGatheringInvoiceLineQuery) QueryBillingInvoice() *BillingInvoiceQuery { + query := (&BillingInvoiceClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, selector), + sqlgraph.To(billinginvoice.Table, billinginvoice.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.BillingInvoiceTable, billinggatheringinvoiceline.BillingInvoiceColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QuerySplitLineGroup chains the current query on the "split_line_group" edge. +func (_q *BillingGatheringInvoiceLineQuery) QuerySplitLineGroup() *BillingInvoiceSplitLineGroupQuery { + query := (&BillingInvoiceSplitLineGroupClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, selector), + sqlgraph.To(billinginvoicesplitlinegroup.Table, billinginvoicesplitlinegroup.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.SplitLineGroupTable, billinggatheringinvoiceline.SplitLineGroupColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QuerySubscription chains the current query on the "subscription" edge. +func (_q *BillingGatheringInvoiceLineQuery) QuerySubscription() *SubscriptionQuery { + query := (&SubscriptionClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, selector), + sqlgraph.To(subscription.Table, subscription.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.SubscriptionTable, billinggatheringinvoiceline.SubscriptionColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QuerySubscriptionPhase chains the current query on the "subscription_phase" edge. +func (_q *BillingGatheringInvoiceLineQuery) QuerySubscriptionPhase() *SubscriptionPhaseQuery { + query := (&SubscriptionPhaseClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, selector), + sqlgraph.To(subscriptionphase.Table, subscriptionphase.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.SubscriptionPhaseTable, billinggatheringinvoiceline.SubscriptionPhaseColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QuerySubscriptionItem chains the current query on the "subscription_item" edge. +func (_q *BillingGatheringInvoiceLineQuery) QuerySubscriptionItem() *SubscriptionItemQuery { + query := (&SubscriptionItemClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, selector), + sqlgraph.To(subscriptionitem.Table, subscriptionitem.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.SubscriptionItemTable, billinggatheringinvoiceline.SubscriptionItemColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryCharge chains the current query on the "charge" edge. +func (_q *BillingGatheringInvoiceLineQuery) QueryCharge() *ChargeQuery { + query := (&ChargeClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, selector), + sqlgraph.To(charge.Table, charge.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.ChargeTable, billinggatheringinvoiceline.ChargeColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryTaxCode chains the current query on the "tax_code" edge. +func (_q *BillingGatheringInvoiceLineQuery) QueryTaxCode() *TaxCodeQuery { + query := (&TaxCodeClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, selector), + sqlgraph.To(dbtaxcode.Table, dbtaxcode.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.TaxCodeTable, billinggatheringinvoiceline.TaxCodeColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first BillingGatheringInvoiceLine entity from the query. +// Returns a *NotFoundError when no BillingGatheringInvoiceLine was found. +func (_q *BillingGatheringInvoiceLineQuery) First(ctx context.Context) (*BillingGatheringInvoiceLine, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{billinggatheringinvoiceline.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *BillingGatheringInvoiceLineQuery) FirstX(ctx context.Context) *BillingGatheringInvoiceLine { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first BillingGatheringInvoiceLine ID from the query. +// Returns a *NotFoundError when no BillingGatheringInvoiceLine ID was found. +func (_q *BillingGatheringInvoiceLineQuery) FirstID(ctx context.Context) (id string, err error) { + var ids []string + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{billinggatheringinvoiceline.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *BillingGatheringInvoiceLineQuery) FirstIDX(ctx context.Context) string { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single BillingGatheringInvoiceLine entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one BillingGatheringInvoiceLine entity is found. +// Returns a *NotFoundError when no BillingGatheringInvoiceLine entities are found. +func (_q *BillingGatheringInvoiceLineQuery) Only(ctx context.Context) (*BillingGatheringInvoiceLine, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{billinggatheringinvoiceline.Label} + default: + return nil, &NotSingularError{billinggatheringinvoiceline.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *BillingGatheringInvoiceLineQuery) OnlyX(ctx context.Context) *BillingGatheringInvoiceLine { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only BillingGatheringInvoiceLine ID in the query. +// Returns a *NotSingularError when more than one BillingGatheringInvoiceLine ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *BillingGatheringInvoiceLineQuery) OnlyID(ctx context.Context) (id string, err error) { + var ids []string + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{billinggatheringinvoiceline.Label} + default: + err = &NotSingularError{billinggatheringinvoiceline.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *BillingGatheringInvoiceLineQuery) OnlyIDX(ctx context.Context) string { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of BillingGatheringInvoiceLines. +func (_q *BillingGatheringInvoiceLineQuery) All(ctx context.Context) ([]*BillingGatheringInvoiceLine, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*BillingGatheringInvoiceLine, *BillingGatheringInvoiceLineQuery]() + return withInterceptors[[]*BillingGatheringInvoiceLine](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *BillingGatheringInvoiceLineQuery) AllX(ctx context.Context) []*BillingGatheringInvoiceLine { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of BillingGatheringInvoiceLine IDs. +func (_q *BillingGatheringInvoiceLineQuery) IDs(ctx context.Context) (ids []string, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(billinggatheringinvoiceline.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *BillingGatheringInvoiceLineQuery) IDsX(ctx context.Context) []string { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *BillingGatheringInvoiceLineQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*BillingGatheringInvoiceLineQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *BillingGatheringInvoiceLineQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *BillingGatheringInvoiceLineQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *BillingGatheringInvoiceLineQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the BillingGatheringInvoiceLineQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *BillingGatheringInvoiceLineQuery) Clone() *BillingGatheringInvoiceLineQuery { + if _q == nil { + return nil + } + return &BillingGatheringInvoiceLineQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]billinggatheringinvoiceline.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.BillingGatheringInvoiceLine{}, _q.predicates...), + withBillingInvoice: _q.withBillingInvoice.Clone(), + withSplitLineGroup: _q.withSplitLineGroup.Clone(), + withSubscription: _q.withSubscription.Clone(), + withSubscriptionPhase: _q.withSubscriptionPhase.Clone(), + withSubscriptionItem: _q.withSubscriptionItem.Clone(), + withCharge: _q.withCharge.Clone(), + withTaxCode: _q.withTaxCode.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithBillingInvoice tells the query-builder to eager-load the nodes that are connected to +// the "billing_invoice" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *BillingGatheringInvoiceLineQuery) WithBillingInvoice(opts ...func(*BillingInvoiceQuery)) *BillingGatheringInvoiceLineQuery { + query := (&BillingInvoiceClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withBillingInvoice = query + return _q +} + +// WithSplitLineGroup tells the query-builder to eager-load the nodes that are connected to +// the "split_line_group" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *BillingGatheringInvoiceLineQuery) WithSplitLineGroup(opts ...func(*BillingInvoiceSplitLineGroupQuery)) *BillingGatheringInvoiceLineQuery { + query := (&BillingInvoiceSplitLineGroupClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withSplitLineGroup = query + return _q +} + +// WithSubscription tells the query-builder to eager-load the nodes that are connected to +// the "subscription" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *BillingGatheringInvoiceLineQuery) WithSubscription(opts ...func(*SubscriptionQuery)) *BillingGatheringInvoiceLineQuery { + query := (&SubscriptionClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withSubscription = query + return _q +} + +// WithSubscriptionPhase tells the query-builder to eager-load the nodes that are connected to +// the "subscription_phase" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *BillingGatheringInvoiceLineQuery) WithSubscriptionPhase(opts ...func(*SubscriptionPhaseQuery)) *BillingGatheringInvoiceLineQuery { + query := (&SubscriptionPhaseClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withSubscriptionPhase = query + return _q +} + +// WithSubscriptionItem tells the query-builder to eager-load the nodes that are connected to +// the "subscription_item" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *BillingGatheringInvoiceLineQuery) WithSubscriptionItem(opts ...func(*SubscriptionItemQuery)) *BillingGatheringInvoiceLineQuery { + query := (&SubscriptionItemClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withSubscriptionItem = query + return _q +} + +// WithCharge tells the query-builder to eager-load the nodes that are connected to +// the "charge" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *BillingGatheringInvoiceLineQuery) WithCharge(opts ...func(*ChargeQuery)) *BillingGatheringInvoiceLineQuery { + query := (&ChargeClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withCharge = query + return _q +} + +// WithTaxCode tells the query-builder to eager-load the nodes that are connected to +// the "tax_code" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *BillingGatheringInvoiceLineQuery) WithTaxCode(opts ...func(*TaxCodeQuery)) *BillingGatheringInvoiceLineQuery { + query := (&TaxCodeClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withTaxCode = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Annotations models.Annotations `json:"annotations,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.BillingGatheringInvoiceLine.Query(). +// GroupBy(billinggatheringinvoiceline.FieldAnnotations). +// Aggregate(db.Count()). +// Scan(ctx, &v) +func (_q *BillingGatheringInvoiceLineQuery) GroupBy(field string, fields ...string) *BillingGatheringInvoiceLineGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &BillingGatheringInvoiceLineGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = billinggatheringinvoiceline.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Annotations models.Annotations `json:"annotations,omitempty"` +// } +// +// client.BillingGatheringInvoiceLine.Query(). +// Select(billinggatheringinvoiceline.FieldAnnotations). +// Scan(ctx, &v) +func (_q *BillingGatheringInvoiceLineQuery) Select(fields ...string) *BillingGatheringInvoiceLineSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &BillingGatheringInvoiceLineSelect{BillingGatheringInvoiceLineQuery: _q} + sbuild.label = billinggatheringinvoiceline.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a BillingGatheringInvoiceLineSelect configured with the given aggregations. +func (_q *BillingGatheringInvoiceLineQuery) Aggregate(fns ...AggregateFunc) *BillingGatheringInvoiceLineSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *BillingGatheringInvoiceLineQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !billinggatheringinvoiceline.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *BillingGatheringInvoiceLineQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*BillingGatheringInvoiceLine, error) { + var ( + nodes = []*BillingGatheringInvoiceLine{} + _spec = _q.querySpec() + loadedTypes = [7]bool{ + _q.withBillingInvoice != nil, + _q.withSplitLineGroup != nil, + _q.withSubscription != nil, + _q.withSubscriptionPhase != nil, + _q.withSubscriptionItem != nil, + _q.withCharge != nil, + _q.withTaxCode != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*BillingGatheringInvoiceLine).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &BillingGatheringInvoiceLine{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withBillingInvoice; query != nil { + if err := _q.loadBillingInvoice(ctx, query, nodes, nil, + func(n *BillingGatheringInvoiceLine, e *BillingInvoice) { n.Edges.BillingInvoice = e }); err != nil { + return nil, err + } + } + if query := _q.withSplitLineGroup; query != nil { + if err := _q.loadSplitLineGroup(ctx, query, nodes, nil, + func(n *BillingGatheringInvoiceLine, e *BillingInvoiceSplitLineGroup) { n.Edges.SplitLineGroup = e }); err != nil { + return nil, err + } + } + if query := _q.withSubscription; query != nil { + if err := _q.loadSubscription(ctx, query, nodes, nil, + func(n *BillingGatheringInvoiceLine, e *Subscription) { n.Edges.Subscription = e }); err != nil { + return nil, err + } + } + if query := _q.withSubscriptionPhase; query != nil { + if err := _q.loadSubscriptionPhase(ctx, query, nodes, nil, + func(n *BillingGatheringInvoiceLine, e *SubscriptionPhase) { n.Edges.SubscriptionPhase = e }); err != nil { + return nil, err + } + } + if query := _q.withSubscriptionItem; query != nil { + if err := _q.loadSubscriptionItem(ctx, query, nodes, nil, + func(n *BillingGatheringInvoiceLine, e *SubscriptionItem) { n.Edges.SubscriptionItem = e }); err != nil { + return nil, err + } + } + if query := _q.withCharge; query != nil { + if err := _q.loadCharge(ctx, query, nodes, nil, + func(n *BillingGatheringInvoiceLine, e *Charge) { n.Edges.Charge = e }); err != nil { + return nil, err + } + } + if query := _q.withTaxCode; query != nil { + if err := _q.loadTaxCode(ctx, query, nodes, nil, + func(n *BillingGatheringInvoiceLine, e *TaxCode) { n.Edges.TaxCode = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *BillingGatheringInvoiceLineQuery) loadBillingInvoice(ctx context.Context, query *BillingInvoiceQuery, nodes []*BillingGatheringInvoiceLine, init func(*BillingGatheringInvoiceLine), assign func(*BillingGatheringInvoiceLine, *BillingInvoice)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*BillingGatheringInvoiceLine) + for i := range nodes { + fk := nodes[i].InvoiceID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(billinginvoice.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "invoice_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *BillingGatheringInvoiceLineQuery) loadSplitLineGroup(ctx context.Context, query *BillingInvoiceSplitLineGroupQuery, nodes []*BillingGatheringInvoiceLine, init func(*BillingGatheringInvoiceLine), assign func(*BillingGatheringInvoiceLine, *BillingInvoiceSplitLineGroup)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*BillingGatheringInvoiceLine) + for i := range nodes { + if nodes[i].SplitLineGroupID == nil { + continue + } + fk := *nodes[i].SplitLineGroupID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(billinginvoicesplitlinegroup.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "split_line_group_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *BillingGatheringInvoiceLineQuery) loadSubscription(ctx context.Context, query *SubscriptionQuery, nodes []*BillingGatheringInvoiceLine, init func(*BillingGatheringInvoiceLine), assign func(*BillingGatheringInvoiceLine, *Subscription)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*BillingGatheringInvoiceLine) + for i := range nodes { + if nodes[i].SubscriptionID == nil { + continue + } + fk := *nodes[i].SubscriptionID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(subscription.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "subscription_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *BillingGatheringInvoiceLineQuery) loadSubscriptionPhase(ctx context.Context, query *SubscriptionPhaseQuery, nodes []*BillingGatheringInvoiceLine, init func(*BillingGatheringInvoiceLine), assign func(*BillingGatheringInvoiceLine, *SubscriptionPhase)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*BillingGatheringInvoiceLine) + for i := range nodes { + if nodes[i].SubscriptionPhaseID == nil { + continue + } + fk := *nodes[i].SubscriptionPhaseID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(subscriptionphase.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "subscription_phase_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *BillingGatheringInvoiceLineQuery) loadSubscriptionItem(ctx context.Context, query *SubscriptionItemQuery, nodes []*BillingGatheringInvoiceLine, init func(*BillingGatheringInvoiceLine), assign func(*BillingGatheringInvoiceLine, *SubscriptionItem)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*BillingGatheringInvoiceLine) + for i := range nodes { + if nodes[i].SubscriptionItemID == nil { + continue + } + fk := *nodes[i].SubscriptionItemID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(subscriptionitem.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "subscription_item_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *BillingGatheringInvoiceLineQuery) loadCharge(ctx context.Context, query *ChargeQuery, nodes []*BillingGatheringInvoiceLine, init func(*BillingGatheringInvoiceLine), assign func(*BillingGatheringInvoiceLine, *Charge)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*BillingGatheringInvoiceLine) + for i := range nodes { + if nodes[i].ChargeID == nil { + continue + } + fk := *nodes[i].ChargeID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(charge.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "charge_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *BillingGatheringInvoiceLineQuery) loadTaxCode(ctx context.Context, query *TaxCodeQuery, nodes []*BillingGatheringInvoiceLine, init func(*BillingGatheringInvoiceLine), assign func(*BillingGatheringInvoiceLine, *TaxCode)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*BillingGatheringInvoiceLine) + for i := range nodes { + if nodes[i].TaxCodeID == nil { + continue + } + fk := *nodes[i].TaxCodeID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(dbtaxcode.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "tax_code_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (_q *BillingGatheringInvoiceLineQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *BillingGatheringInvoiceLineQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.Columns, sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, billinggatheringinvoiceline.FieldID) + for i := range fields { + if fields[i] != billinggatheringinvoiceline.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withBillingInvoice != nil { + _spec.Node.AddColumnOnce(billinggatheringinvoiceline.FieldInvoiceID) + } + if _q.withSplitLineGroup != nil { + _spec.Node.AddColumnOnce(billinggatheringinvoiceline.FieldSplitLineGroupID) + } + if _q.withSubscription != nil { + _spec.Node.AddColumnOnce(billinggatheringinvoiceline.FieldSubscriptionID) + } + if _q.withSubscriptionPhase != nil { + _spec.Node.AddColumnOnce(billinggatheringinvoiceline.FieldSubscriptionPhaseID) + } + if _q.withSubscriptionItem != nil { + _spec.Node.AddColumnOnce(billinggatheringinvoiceline.FieldSubscriptionItemID) + } + if _q.withCharge != nil { + _spec.Node.AddColumnOnce(billinggatheringinvoiceline.FieldChargeID) + } + if _q.withTaxCode != nil { + _spec.Node.AddColumnOnce(billinggatheringinvoiceline.FieldTaxCodeID) + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *BillingGatheringInvoiceLineQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(billinggatheringinvoiceline.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = billinggatheringinvoiceline.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, m := range _q.modifiers { + m(selector) + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// ForUpdate locks the selected rows against concurrent updates, and prevent them from being +// updated, deleted or "selected ... for update" by other sessions, until the transaction is +// either committed or rolled-back. +func (_q *BillingGatheringInvoiceLineQuery) ForUpdate(opts ...sql.LockOption) *BillingGatheringInvoiceLineQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForUpdate(opts...) + }) + return _q +} + +// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock +// on any rows that are read. Other sessions can read the rows, but cannot modify them +// until your transaction commits. +func (_q *BillingGatheringInvoiceLineQuery) ForShare(opts ...sql.LockOption) *BillingGatheringInvoiceLineQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForShare(opts...) + }) + return _q +} + +// BillingGatheringInvoiceLineGroupBy is the group-by builder for BillingGatheringInvoiceLine entities. +type BillingGatheringInvoiceLineGroupBy struct { + selector + build *BillingGatheringInvoiceLineQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *BillingGatheringInvoiceLineGroupBy) Aggregate(fns ...AggregateFunc) *BillingGatheringInvoiceLineGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *BillingGatheringInvoiceLineGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*BillingGatheringInvoiceLineQuery, *BillingGatheringInvoiceLineGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *BillingGatheringInvoiceLineGroupBy) sqlScan(ctx context.Context, root *BillingGatheringInvoiceLineQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// BillingGatheringInvoiceLineSelect is the builder for selecting fields of BillingGatheringInvoiceLine entities. +type BillingGatheringInvoiceLineSelect struct { + *BillingGatheringInvoiceLineQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *BillingGatheringInvoiceLineSelect) Aggregate(fns ...AggregateFunc) *BillingGatheringInvoiceLineSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *BillingGatheringInvoiceLineSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*BillingGatheringInvoiceLineQuery, *BillingGatheringInvoiceLineSelect](ctx, _s.BillingGatheringInvoiceLineQuery, _s, _s.inters, v) +} + +func (_s *BillingGatheringInvoiceLineSelect) sqlScan(ctx context.Context, root *BillingGatheringInvoiceLineQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/openmeter/ent/db/billinggatheringinvoiceline_update.go b/openmeter/ent/db/billinggatheringinvoiceline_update.go new file mode 100644 index 0000000000..131dbd4e8b --- /dev/null +++ b/openmeter/ent/db/billinggatheringinvoiceline_update.go @@ -0,0 +1,2004 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/billing" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" + "github.com/openmeterio/openmeter/openmeter/ent/db/charge" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" + "github.com/openmeterio/openmeter/openmeter/ent/db/subscription" + "github.com/openmeterio/openmeter/openmeter/ent/db/subscriptionitem" + "github.com/openmeterio/openmeter/openmeter/ent/db/subscriptionphase" + dbtaxcode "github.com/openmeterio/openmeter/openmeter/ent/db/taxcode" + "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/pkg/models" +) + +// BillingGatheringInvoiceLineUpdate is the builder for updating BillingGatheringInvoiceLine entities. +type BillingGatheringInvoiceLineUpdate struct { + config + hooks []Hook + mutation *BillingGatheringInvoiceLineMutation +} + +// Where appends a list predicates to the BillingGatheringInvoiceLineUpdate builder. +func (_u *BillingGatheringInvoiceLineUpdate) Where(ps ...predicate.BillingGatheringInvoiceLine) *BillingGatheringInvoiceLineUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetAnnotations sets the "annotations" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetAnnotations(v models.Annotations) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetAnnotations(v) + return _u +} + +// ClearAnnotations clears the value of the "annotations" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearAnnotations() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearAnnotations() + return _u +} + +// SetMetadata sets the "metadata" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetMetadata(v map[string]string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetMetadata(v) + return _u +} + +// ClearMetadata clears the value of the "metadata" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearMetadata() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearMetadata() + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetUpdatedAt(v time.Time) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetDeletedAt sets the "deleted_at" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetDeletedAt(v time.Time) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetDeletedAt(v) + return _u +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableDeletedAt(v *time.Time) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetDeletedAt(*v) + } + return _u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearDeletedAt() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearDeletedAt() + return _u +} + +// SetName sets the "name" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetName(v string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableName(v *string) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetDescription sets the "description" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetDescription(v string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableDescription(v *string) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearDescription() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearDescription() + return _u +} + +// SetServicePeriodStart sets the "service_period_start" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetServicePeriodStart(v time.Time) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetServicePeriodStart(v) + return _u +} + +// SetNillableServicePeriodStart sets the "service_period_start" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableServicePeriodStart(v *time.Time) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetServicePeriodStart(*v) + } + return _u +} + +// SetServicePeriodEnd sets the "service_period_end" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetServicePeriodEnd(v time.Time) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetServicePeriodEnd(v) + return _u +} + +// SetNillableServicePeriodEnd sets the "service_period_end" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableServicePeriodEnd(v *time.Time) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetServicePeriodEnd(*v) + } + return _u +} + +// SetTaxConfig sets the "tax_config" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetTaxConfig(v billing.TaxConfig) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetTaxConfig(v) + return _u +} + +// SetNillableTaxConfig sets the "tax_config" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableTaxConfig(v *billing.TaxConfig) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetTaxConfig(*v) + } + return _u +} + +// ClearTaxConfig clears the value of the "tax_config" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearTaxConfig() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearTaxConfig() + return _u +} + +// SetPriceType sets the "price_type" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetPriceType(v productcatalog.PriceType) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetPriceType(v) + return _u +} + +// SetNillablePriceType sets the "price_type" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillablePriceType(v *productcatalog.PriceType) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetPriceType(*v) + } + return _u +} + +// SetFeatureKey sets the "feature_key" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetFeatureKey(v string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetFeatureKey(v) + return _u +} + +// SetNillableFeatureKey sets the "feature_key" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableFeatureKey(v *string) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetFeatureKey(*v) + } + return _u +} + +// ClearFeatureKey clears the value of the "feature_key" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearFeatureKey() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearFeatureKey() + return _u +} + +// SetPrice sets the "price" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetPrice(v *productcatalog.Price) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetPrice(v) + return _u +} + +// SetUnitConfig sets the "unit_config" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetUnitConfig(v *productcatalog.UnitConfig) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetUnitConfig(v) + return _u +} + +// ClearUnitConfig clears the value of the "unit_config" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearUnitConfig() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearUnitConfig() + return _u +} + +// SetRatecardDiscounts sets the "ratecard_discounts" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetRatecardDiscounts(v *billing.Discounts) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetRatecardDiscounts(v) + return _u +} + +// ClearRatecardDiscounts clears the value of the "ratecard_discounts" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearRatecardDiscounts() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearRatecardDiscounts() + return _u +} + +// SetChildUniqueReferenceID sets the "child_unique_reference_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetChildUniqueReferenceID(v string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetChildUniqueReferenceID(v) + return _u +} + +// SetNillableChildUniqueReferenceID sets the "child_unique_reference_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableChildUniqueReferenceID(v *string) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetChildUniqueReferenceID(*v) + } + return _u +} + +// ClearChildUniqueReferenceID clears the value of the "child_unique_reference_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearChildUniqueReferenceID() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearChildUniqueReferenceID() + return _u +} + +// SetSubscriptionID sets the "subscription_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetSubscriptionID(v string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetSubscriptionID(v) + return _u +} + +// SetNillableSubscriptionID sets the "subscription_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableSubscriptionID(v *string) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetSubscriptionID(*v) + } + return _u +} + +// ClearSubscriptionID clears the value of the "subscription_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearSubscriptionID() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearSubscriptionID() + return _u +} + +// SetSubscriptionPhaseID sets the "subscription_phase_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetSubscriptionPhaseID(v string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetSubscriptionPhaseID(v) + return _u +} + +// SetNillableSubscriptionPhaseID sets the "subscription_phase_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableSubscriptionPhaseID(v *string) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetSubscriptionPhaseID(*v) + } + return _u +} + +// ClearSubscriptionPhaseID clears the value of the "subscription_phase_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearSubscriptionPhaseID() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearSubscriptionPhaseID() + return _u +} + +// SetSubscriptionItemID sets the "subscription_item_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetSubscriptionItemID(v string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetSubscriptionItemID(v) + return _u +} + +// SetNillableSubscriptionItemID sets the "subscription_item_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableSubscriptionItemID(v *string) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetSubscriptionItemID(*v) + } + return _u +} + +// ClearSubscriptionItemID clears the value of the "subscription_item_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearSubscriptionItemID() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearSubscriptionItemID() + return _u +} + +// SetSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetSubscriptionBillingPeriodFrom(v time.Time) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetSubscriptionBillingPeriodFrom(v) + return _u +} + +// SetNillableSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableSubscriptionBillingPeriodFrom(v *time.Time) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetSubscriptionBillingPeriodFrom(*v) + } + return _u +} + +// ClearSubscriptionBillingPeriodFrom clears the value of the "subscription_billing_period_from" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearSubscriptionBillingPeriodFrom() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearSubscriptionBillingPeriodFrom() + return _u +} + +// SetSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetSubscriptionBillingPeriodTo(v time.Time) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetSubscriptionBillingPeriodTo(v) + return _u +} + +// SetNillableSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableSubscriptionBillingPeriodTo(v *time.Time) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetSubscriptionBillingPeriodTo(*v) + } + return _u +} + +// ClearSubscriptionBillingPeriodTo clears the value of the "subscription_billing_period_to" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearSubscriptionBillingPeriodTo() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearSubscriptionBillingPeriodTo() + return _u +} + +// SetTaxCodeID sets the "tax_code_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetTaxCodeID(v string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetTaxCodeID(v) + return _u +} + +// SetNillableTaxCodeID sets the "tax_code_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableTaxCodeID(v *string) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetTaxCodeID(*v) + } + return _u +} + +// ClearTaxCodeID clears the value of the "tax_code_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearTaxCodeID() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearTaxCodeID() + return _u +} + +// SetTaxBehavior sets the "tax_behavior" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetTaxBehavior(v productcatalog.TaxBehavior) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetTaxBehavior(v) + return _u +} + +// SetNillableTaxBehavior sets the "tax_behavior" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableTaxBehavior(v *productcatalog.TaxBehavior) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetTaxBehavior(*v) + } + return _u +} + +// ClearTaxBehavior clears the value of the "tax_behavior" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearTaxBehavior() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearTaxBehavior() + return _u +} + +// SetInvoiceID sets the "invoice_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetInvoiceID(v string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetInvoiceID(v) + return _u +} + +// SetNillableInvoiceID sets the "invoice_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableInvoiceID(v *string) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetInvoiceID(*v) + } + return _u +} + +// SetInvoiceAt sets the "invoice_at" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetInvoiceAt(v time.Time) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetInvoiceAt(v) + return _u +} + +// SetNillableInvoiceAt sets the "invoice_at" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableInvoiceAt(v *time.Time) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetInvoiceAt(*v) + } + return _u +} + +// SetManagedBy sets the "managed_by" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetManagedBy(v billing.InvoiceLineManagedBy) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetManagedBy(v) + return _u +} + +// SetNillableManagedBy sets the "managed_by" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableManagedBy(v *billing.InvoiceLineManagedBy) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetManagedBy(*v) + } + return _u +} + +// SetEngine sets the "engine" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetEngine(v billing.LineEngineType) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetEngine(v) + return _u +} + +// SetNillableEngine sets the "engine" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableEngine(v *billing.LineEngineType) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetEngine(*v) + } + return _u +} + +// SetSplitLineGroupID sets the "split_line_group_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetSplitLineGroupID(v string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetSplitLineGroupID(v) + return _u +} + +// SetNillableSplitLineGroupID sets the "split_line_group_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableSplitLineGroupID(v *string) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetSplitLineGroupID(*v) + } + return _u +} + +// ClearSplitLineGroupID clears the value of the "split_line_group_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearSplitLineGroupID() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearSplitLineGroupID() + return _u +} + +// SetChargeID sets the "charge_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) SetChargeID(v string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetChargeID(v) + return _u +} + +// SetNillableChargeID sets the "charge_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdate) SetNillableChargeID(v *string) *BillingGatheringInvoiceLineUpdate { + if v != nil { + _u.SetChargeID(*v) + } + return _u +} + +// ClearChargeID clears the value of the "charge_id" field. +func (_u *BillingGatheringInvoiceLineUpdate) ClearChargeID() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearChargeID() + return _u +} + +// SetBillingInvoiceID sets the "billing_invoice" edge to the BillingInvoice entity by ID. +func (_u *BillingGatheringInvoiceLineUpdate) SetBillingInvoiceID(id string) *BillingGatheringInvoiceLineUpdate { + _u.mutation.SetBillingInvoiceID(id) + return _u +} + +// SetBillingInvoice sets the "billing_invoice" edge to the BillingInvoice entity. +func (_u *BillingGatheringInvoiceLineUpdate) SetBillingInvoice(v *BillingInvoice) *BillingGatheringInvoiceLineUpdate { + return _u.SetBillingInvoiceID(v.ID) +} + +// SetSplitLineGroup sets the "split_line_group" edge to the BillingInvoiceSplitLineGroup entity. +func (_u *BillingGatheringInvoiceLineUpdate) SetSplitLineGroup(v *BillingInvoiceSplitLineGroup) *BillingGatheringInvoiceLineUpdate { + return _u.SetSplitLineGroupID(v.ID) +} + +// SetSubscription sets the "subscription" edge to the Subscription entity. +func (_u *BillingGatheringInvoiceLineUpdate) SetSubscription(v *Subscription) *BillingGatheringInvoiceLineUpdate { + return _u.SetSubscriptionID(v.ID) +} + +// SetSubscriptionPhase sets the "subscription_phase" edge to the SubscriptionPhase entity. +func (_u *BillingGatheringInvoiceLineUpdate) SetSubscriptionPhase(v *SubscriptionPhase) *BillingGatheringInvoiceLineUpdate { + return _u.SetSubscriptionPhaseID(v.ID) +} + +// SetSubscriptionItem sets the "subscription_item" edge to the SubscriptionItem entity. +func (_u *BillingGatheringInvoiceLineUpdate) SetSubscriptionItem(v *SubscriptionItem) *BillingGatheringInvoiceLineUpdate { + return _u.SetSubscriptionItemID(v.ID) +} + +// SetCharge sets the "charge" edge to the Charge entity. +func (_u *BillingGatheringInvoiceLineUpdate) SetCharge(v *Charge) *BillingGatheringInvoiceLineUpdate { + return _u.SetChargeID(v.ID) +} + +// SetTaxCode sets the "tax_code" edge to the TaxCode entity. +func (_u *BillingGatheringInvoiceLineUpdate) SetTaxCode(v *TaxCode) *BillingGatheringInvoiceLineUpdate { + return _u.SetTaxCodeID(v.ID) +} + +// Mutation returns the BillingGatheringInvoiceLineMutation object of the builder. +func (_u *BillingGatheringInvoiceLineUpdate) Mutation() *BillingGatheringInvoiceLineMutation { + return _u.mutation +} + +// ClearBillingInvoice clears the "billing_invoice" edge to the BillingInvoice entity. +func (_u *BillingGatheringInvoiceLineUpdate) ClearBillingInvoice() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearBillingInvoice() + return _u +} + +// ClearSplitLineGroup clears the "split_line_group" edge to the BillingInvoiceSplitLineGroup entity. +func (_u *BillingGatheringInvoiceLineUpdate) ClearSplitLineGroup() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearSplitLineGroup() + return _u +} + +// ClearSubscription clears the "subscription" edge to the Subscription entity. +func (_u *BillingGatheringInvoiceLineUpdate) ClearSubscription() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearSubscription() + return _u +} + +// ClearSubscriptionPhase clears the "subscription_phase" edge to the SubscriptionPhase entity. +func (_u *BillingGatheringInvoiceLineUpdate) ClearSubscriptionPhase() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearSubscriptionPhase() + return _u +} + +// ClearSubscriptionItem clears the "subscription_item" edge to the SubscriptionItem entity. +func (_u *BillingGatheringInvoiceLineUpdate) ClearSubscriptionItem() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearSubscriptionItem() + return _u +} + +// ClearCharge clears the "charge" edge to the Charge entity. +func (_u *BillingGatheringInvoiceLineUpdate) ClearCharge() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearCharge() + return _u +} + +// ClearTaxCode clears the "tax_code" edge to the TaxCode entity. +func (_u *BillingGatheringInvoiceLineUpdate) ClearTaxCode() *BillingGatheringInvoiceLineUpdate { + _u.mutation.ClearTaxCode() + return _u +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *BillingGatheringInvoiceLineUpdate) Save(ctx context.Context) (int, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *BillingGatheringInvoiceLineUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *BillingGatheringInvoiceLineUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *BillingGatheringInvoiceLineUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *BillingGatheringInvoiceLineUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := billinggatheringinvoiceline.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *BillingGatheringInvoiceLineUpdate) check() error { + if v, ok := _u.mutation.TaxConfig(); ok { + if err := v.Validate(); err != nil { + return &ValidationError{Name: "tax_config", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.tax_config": %w`, err)} + } + } + if v, ok := _u.mutation.PriceType(); ok { + if err := billinggatheringinvoiceline.PriceTypeValidator(v); err != nil { + return &ValidationError{Name: "price_type", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.price_type": %w`, err)} + } + } + if v, ok := _u.mutation.Price(); ok { + if err := v.Validate(); err != nil { + return &ValidationError{Name: "price", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.price": %w`, err)} + } + } + if v, ok := _u.mutation.UnitConfig(); ok { + if err := v.Validate(); err != nil { + return &ValidationError{Name: "unit_config", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.unit_config": %w`, err)} + } + } + if v, ok := _u.mutation.RatecardDiscounts(); ok { + if err := v.Validate(); err != nil { + return &ValidationError{Name: "ratecard_discounts", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.ratecard_discounts": %w`, err)} + } + } + if v, ok := _u.mutation.TaxBehavior(); ok { + if err := billinggatheringinvoiceline.TaxBehaviorValidator(v); err != nil { + return &ValidationError{Name: "tax_behavior", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.tax_behavior": %w`, err)} + } + } + if v, ok := _u.mutation.ManagedBy(); ok { + if err := billinggatheringinvoiceline.ManagedByValidator(v); err != nil { + return &ValidationError{Name: "managed_by", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.managed_by": %w`, err)} + } + } + if v, ok := _u.mutation.Engine(); ok { + if err := billinggatheringinvoiceline.EngineValidator(v); err != nil { + return &ValidationError{Name: "engine", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.engine": %w`, err)} + } + } + if _u.mutation.BillingInvoiceCleared() && len(_u.mutation.BillingInvoiceIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "BillingGatheringInvoiceLine.billing_invoice"`) + } + return nil +} + +func (_u *BillingGatheringInvoiceLineUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.Columns, sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Annotations(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldAnnotations, field.TypeJSON, value) + } + if _u.mutation.AnnotationsCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldAnnotations, field.TypeJSON) + } + if value, ok := _u.mutation.Metadata(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldMetadata, field.TypeJSON, value) + } + if _u.mutation.MetadataCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldMetadata, field.TypeJSON) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.DeletedAt(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldDeletedAt, field.TypeTime, value) + } + if _u.mutation.DeletedAtCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldDeletedAt, field.TypeTime) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.ServicePeriodStart(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldServicePeriodStart, field.TypeTime, value) + } + if value, ok := _u.mutation.ServicePeriodEnd(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldServicePeriodEnd, field.TypeTime, value) + } + if value, ok := _u.mutation.TaxConfig(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldTaxConfig, field.TypeJSON, value) + } + if _u.mutation.TaxConfigCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldTaxConfig, field.TypeJSON) + } + if value, ok := _u.mutation.PriceType(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldPriceType, field.TypeEnum, value) + } + if value, ok := _u.mutation.FeatureKey(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldFeatureKey, field.TypeString, value) + } + if _u.mutation.FeatureKeyCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldFeatureKey, field.TypeString) + } + if value, ok := _u.mutation.Price(); ok { + vv, err := billinggatheringinvoiceline.ValueScanner.Price.Value(value) + if err != nil { + return 0, err + } + _spec.SetField(billinggatheringinvoiceline.FieldPrice, field.TypeString, vv) + } + if value, ok := _u.mutation.UnitConfig(); ok { + vv, err := billinggatheringinvoiceline.ValueScanner.UnitConfig.Value(value) + if err != nil { + return 0, err + } + _spec.SetField(billinggatheringinvoiceline.FieldUnitConfig, field.TypeString, vv) + } + if _u.mutation.UnitConfigCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldUnitConfig, field.TypeString) + } + if value, ok := _u.mutation.RatecardDiscounts(); ok { + vv, err := billinggatheringinvoiceline.ValueScanner.RatecardDiscounts.Value(value) + if err != nil { + return 0, err + } + _spec.SetField(billinggatheringinvoiceline.FieldRatecardDiscounts, field.TypeString, vv) + } + if _u.mutation.RatecardDiscountsCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldRatecardDiscounts, field.TypeString) + } + if value, ok := _u.mutation.ChildUniqueReferenceID(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldChildUniqueReferenceID, field.TypeString, value) + } + if _u.mutation.ChildUniqueReferenceIDCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldChildUniqueReferenceID, field.TypeString) + } + if value, ok := _u.mutation.SubscriptionBillingPeriodFrom(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom, field.TypeTime, value) + } + if _u.mutation.SubscriptionBillingPeriodFromCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom, field.TypeTime) + } + if value, ok := _u.mutation.SubscriptionBillingPeriodTo(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo, field.TypeTime, value) + } + if _u.mutation.SubscriptionBillingPeriodToCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo, field.TypeTime) + } + if value, ok := _u.mutation.TaxBehavior(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldTaxBehavior, field.TypeEnum, value) + } + if _u.mutation.TaxBehaviorCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldTaxBehavior, field.TypeEnum) + } + if value, ok := _u.mutation.InvoiceAt(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldInvoiceAt, field.TypeTime, value) + } + if value, ok := _u.mutation.ManagedBy(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldManagedBy, field.TypeEnum, value) + } + if value, ok := _u.mutation.Engine(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldEngine, field.TypeEnum, value) + } + if _u.mutation.BillingInvoiceCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.BillingInvoiceTable, + Columns: []string{billinggatheringinvoiceline.BillingInvoiceColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinginvoice.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingInvoiceIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.BillingInvoiceTable, + Columns: []string{billinggatheringinvoiceline.BillingInvoiceColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinginvoice.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.SplitLineGroupCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SplitLineGroupTable, + Columns: []string{billinggatheringinvoiceline.SplitLineGroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinginvoicesplitlinegroup.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SplitLineGroupIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SplitLineGroupTable, + Columns: []string{billinggatheringinvoiceline.SplitLineGroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinginvoicesplitlinegroup.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.SubscriptionCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscription.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SubscriptionIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscription.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.SubscriptionPhaseCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionPhaseTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionPhaseColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscriptionphase.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SubscriptionPhaseIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionPhaseTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionPhaseColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscriptionphase.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.SubscriptionItemCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionItemTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionItemColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscriptionitem.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SubscriptionItemIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionItemTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionItemColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscriptionitem.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.ChargeCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.ChargeTable, + Columns: []string{billinggatheringinvoiceline.ChargeColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(charge.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ChargeIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.ChargeTable, + Columns: []string{billinggatheringinvoiceline.ChargeColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(charge.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.TaxCodeCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.TaxCodeTable, + Columns: []string{billinggatheringinvoiceline.TaxCodeColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(dbtaxcode.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TaxCodeIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.TaxCodeTable, + Columns: []string{billinggatheringinvoiceline.TaxCodeColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(dbtaxcode.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{billinggatheringinvoiceline.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// BillingGatheringInvoiceLineUpdateOne is the builder for updating a single BillingGatheringInvoiceLine entity. +type BillingGatheringInvoiceLineUpdateOne struct { + config + fields []string + hooks []Hook + mutation *BillingGatheringInvoiceLineMutation +} + +// SetAnnotations sets the "annotations" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetAnnotations(v models.Annotations) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetAnnotations(v) + return _u +} + +// ClearAnnotations clears the value of the "annotations" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearAnnotations() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearAnnotations() + return _u +} + +// SetMetadata sets the "metadata" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetMetadata(v map[string]string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetMetadata(v) + return _u +} + +// ClearMetadata clears the value of the "metadata" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearMetadata() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearMetadata() + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetUpdatedAt(v time.Time) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetDeletedAt sets the "deleted_at" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetDeletedAt(v time.Time) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetDeletedAt(v) + return _u +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableDeletedAt(v *time.Time) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetDeletedAt(*v) + } + return _u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearDeletedAt() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearDeletedAt() + return _u +} + +// SetName sets the "name" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetName(v string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableName(v *string) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetDescription sets the "description" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetDescription(v string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetDescription(v) + return _u +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableDescription(v *string) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetDescription(*v) + } + return _u +} + +// ClearDescription clears the value of the "description" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearDescription() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearDescription() + return _u +} + +// SetServicePeriodStart sets the "service_period_start" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetServicePeriodStart(v time.Time) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetServicePeriodStart(v) + return _u +} + +// SetNillableServicePeriodStart sets the "service_period_start" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableServicePeriodStart(v *time.Time) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetServicePeriodStart(*v) + } + return _u +} + +// SetServicePeriodEnd sets the "service_period_end" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetServicePeriodEnd(v time.Time) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetServicePeriodEnd(v) + return _u +} + +// SetNillableServicePeriodEnd sets the "service_period_end" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableServicePeriodEnd(v *time.Time) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetServicePeriodEnd(*v) + } + return _u +} + +// SetTaxConfig sets the "tax_config" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetTaxConfig(v billing.TaxConfig) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetTaxConfig(v) + return _u +} + +// SetNillableTaxConfig sets the "tax_config" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableTaxConfig(v *billing.TaxConfig) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetTaxConfig(*v) + } + return _u +} + +// ClearTaxConfig clears the value of the "tax_config" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearTaxConfig() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearTaxConfig() + return _u +} + +// SetPriceType sets the "price_type" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetPriceType(v productcatalog.PriceType) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetPriceType(v) + return _u +} + +// SetNillablePriceType sets the "price_type" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillablePriceType(v *productcatalog.PriceType) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetPriceType(*v) + } + return _u +} + +// SetFeatureKey sets the "feature_key" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetFeatureKey(v string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetFeatureKey(v) + return _u +} + +// SetNillableFeatureKey sets the "feature_key" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableFeatureKey(v *string) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetFeatureKey(*v) + } + return _u +} + +// ClearFeatureKey clears the value of the "feature_key" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearFeatureKey() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearFeatureKey() + return _u +} + +// SetPrice sets the "price" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetPrice(v *productcatalog.Price) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetPrice(v) + return _u +} + +// SetUnitConfig sets the "unit_config" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetUnitConfig(v *productcatalog.UnitConfig) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetUnitConfig(v) + return _u +} + +// ClearUnitConfig clears the value of the "unit_config" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearUnitConfig() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearUnitConfig() + return _u +} + +// SetRatecardDiscounts sets the "ratecard_discounts" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetRatecardDiscounts(v *billing.Discounts) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetRatecardDiscounts(v) + return _u +} + +// ClearRatecardDiscounts clears the value of the "ratecard_discounts" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearRatecardDiscounts() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearRatecardDiscounts() + return _u +} + +// SetChildUniqueReferenceID sets the "child_unique_reference_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetChildUniqueReferenceID(v string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetChildUniqueReferenceID(v) + return _u +} + +// SetNillableChildUniqueReferenceID sets the "child_unique_reference_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableChildUniqueReferenceID(v *string) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetChildUniqueReferenceID(*v) + } + return _u +} + +// ClearChildUniqueReferenceID clears the value of the "child_unique_reference_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearChildUniqueReferenceID() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearChildUniqueReferenceID() + return _u +} + +// SetSubscriptionID sets the "subscription_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetSubscriptionID(v string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetSubscriptionID(v) + return _u +} + +// SetNillableSubscriptionID sets the "subscription_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableSubscriptionID(v *string) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetSubscriptionID(*v) + } + return _u +} + +// ClearSubscriptionID clears the value of the "subscription_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearSubscriptionID() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearSubscriptionID() + return _u +} + +// SetSubscriptionPhaseID sets the "subscription_phase_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetSubscriptionPhaseID(v string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetSubscriptionPhaseID(v) + return _u +} + +// SetNillableSubscriptionPhaseID sets the "subscription_phase_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableSubscriptionPhaseID(v *string) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetSubscriptionPhaseID(*v) + } + return _u +} + +// ClearSubscriptionPhaseID clears the value of the "subscription_phase_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearSubscriptionPhaseID() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearSubscriptionPhaseID() + return _u +} + +// SetSubscriptionItemID sets the "subscription_item_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetSubscriptionItemID(v string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetSubscriptionItemID(v) + return _u +} + +// SetNillableSubscriptionItemID sets the "subscription_item_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableSubscriptionItemID(v *string) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetSubscriptionItemID(*v) + } + return _u +} + +// ClearSubscriptionItemID clears the value of the "subscription_item_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearSubscriptionItemID() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearSubscriptionItemID() + return _u +} + +// SetSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetSubscriptionBillingPeriodFrom(v time.Time) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetSubscriptionBillingPeriodFrom(v) + return _u +} + +// SetNillableSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableSubscriptionBillingPeriodFrom(v *time.Time) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetSubscriptionBillingPeriodFrom(*v) + } + return _u +} + +// ClearSubscriptionBillingPeriodFrom clears the value of the "subscription_billing_period_from" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearSubscriptionBillingPeriodFrom() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearSubscriptionBillingPeriodFrom() + return _u +} + +// SetSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetSubscriptionBillingPeriodTo(v time.Time) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetSubscriptionBillingPeriodTo(v) + return _u +} + +// SetNillableSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableSubscriptionBillingPeriodTo(v *time.Time) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetSubscriptionBillingPeriodTo(*v) + } + return _u +} + +// ClearSubscriptionBillingPeriodTo clears the value of the "subscription_billing_period_to" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearSubscriptionBillingPeriodTo() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearSubscriptionBillingPeriodTo() + return _u +} + +// SetTaxCodeID sets the "tax_code_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetTaxCodeID(v string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetTaxCodeID(v) + return _u +} + +// SetNillableTaxCodeID sets the "tax_code_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableTaxCodeID(v *string) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetTaxCodeID(*v) + } + return _u +} + +// ClearTaxCodeID clears the value of the "tax_code_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearTaxCodeID() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearTaxCodeID() + return _u +} + +// SetTaxBehavior sets the "tax_behavior" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetTaxBehavior(v productcatalog.TaxBehavior) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetTaxBehavior(v) + return _u +} + +// SetNillableTaxBehavior sets the "tax_behavior" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableTaxBehavior(v *productcatalog.TaxBehavior) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetTaxBehavior(*v) + } + return _u +} + +// ClearTaxBehavior clears the value of the "tax_behavior" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearTaxBehavior() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearTaxBehavior() + return _u +} + +// SetInvoiceID sets the "invoice_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetInvoiceID(v string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetInvoiceID(v) + return _u +} + +// SetNillableInvoiceID sets the "invoice_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableInvoiceID(v *string) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetInvoiceID(*v) + } + return _u +} + +// SetInvoiceAt sets the "invoice_at" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetInvoiceAt(v time.Time) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetInvoiceAt(v) + return _u +} + +// SetNillableInvoiceAt sets the "invoice_at" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableInvoiceAt(v *time.Time) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetInvoiceAt(*v) + } + return _u +} + +// SetManagedBy sets the "managed_by" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetManagedBy(v billing.InvoiceLineManagedBy) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetManagedBy(v) + return _u +} + +// SetNillableManagedBy sets the "managed_by" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableManagedBy(v *billing.InvoiceLineManagedBy) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetManagedBy(*v) + } + return _u +} + +// SetEngine sets the "engine" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetEngine(v billing.LineEngineType) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetEngine(v) + return _u +} + +// SetNillableEngine sets the "engine" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableEngine(v *billing.LineEngineType) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetEngine(*v) + } + return _u +} + +// SetSplitLineGroupID sets the "split_line_group_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetSplitLineGroupID(v string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetSplitLineGroupID(v) + return _u +} + +// SetNillableSplitLineGroupID sets the "split_line_group_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableSplitLineGroupID(v *string) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetSplitLineGroupID(*v) + } + return _u +} + +// ClearSplitLineGroupID clears the value of the "split_line_group_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearSplitLineGroupID() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearSplitLineGroupID() + return _u +} + +// SetChargeID sets the "charge_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetChargeID(v string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetChargeID(v) + return _u +} + +// SetNillableChargeID sets the "charge_id" field if the given value is not nil. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetNillableChargeID(v *string) *BillingGatheringInvoiceLineUpdateOne { + if v != nil { + _u.SetChargeID(*v) + } + return _u +} + +// ClearChargeID clears the value of the "charge_id" field. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearChargeID() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearChargeID() + return _u +} + +// SetBillingInvoiceID sets the "billing_invoice" edge to the BillingInvoice entity by ID. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetBillingInvoiceID(id string) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.SetBillingInvoiceID(id) + return _u +} + +// SetBillingInvoice sets the "billing_invoice" edge to the BillingInvoice entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetBillingInvoice(v *BillingInvoice) *BillingGatheringInvoiceLineUpdateOne { + return _u.SetBillingInvoiceID(v.ID) +} + +// SetSplitLineGroup sets the "split_line_group" edge to the BillingInvoiceSplitLineGroup entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetSplitLineGroup(v *BillingInvoiceSplitLineGroup) *BillingGatheringInvoiceLineUpdateOne { + return _u.SetSplitLineGroupID(v.ID) +} + +// SetSubscription sets the "subscription" edge to the Subscription entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetSubscription(v *Subscription) *BillingGatheringInvoiceLineUpdateOne { + return _u.SetSubscriptionID(v.ID) +} + +// SetSubscriptionPhase sets the "subscription_phase" edge to the SubscriptionPhase entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetSubscriptionPhase(v *SubscriptionPhase) *BillingGatheringInvoiceLineUpdateOne { + return _u.SetSubscriptionPhaseID(v.ID) +} + +// SetSubscriptionItem sets the "subscription_item" edge to the SubscriptionItem entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetSubscriptionItem(v *SubscriptionItem) *BillingGatheringInvoiceLineUpdateOne { + return _u.SetSubscriptionItemID(v.ID) +} + +// SetCharge sets the "charge" edge to the Charge entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetCharge(v *Charge) *BillingGatheringInvoiceLineUpdateOne { + return _u.SetChargeID(v.ID) +} + +// SetTaxCode sets the "tax_code" edge to the TaxCode entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) SetTaxCode(v *TaxCode) *BillingGatheringInvoiceLineUpdateOne { + return _u.SetTaxCodeID(v.ID) +} + +// Mutation returns the BillingGatheringInvoiceLineMutation object of the builder. +func (_u *BillingGatheringInvoiceLineUpdateOne) Mutation() *BillingGatheringInvoiceLineMutation { + return _u.mutation +} + +// ClearBillingInvoice clears the "billing_invoice" edge to the BillingInvoice entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearBillingInvoice() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearBillingInvoice() + return _u +} + +// ClearSplitLineGroup clears the "split_line_group" edge to the BillingInvoiceSplitLineGroup entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearSplitLineGroup() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearSplitLineGroup() + return _u +} + +// ClearSubscription clears the "subscription" edge to the Subscription entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearSubscription() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearSubscription() + return _u +} + +// ClearSubscriptionPhase clears the "subscription_phase" edge to the SubscriptionPhase entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearSubscriptionPhase() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearSubscriptionPhase() + return _u +} + +// ClearSubscriptionItem clears the "subscription_item" edge to the SubscriptionItem entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearSubscriptionItem() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearSubscriptionItem() + return _u +} + +// ClearCharge clears the "charge" edge to the Charge entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearCharge() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearCharge() + return _u +} + +// ClearTaxCode clears the "tax_code" edge to the TaxCode entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) ClearTaxCode() *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.ClearTaxCode() + return _u +} + +// Where appends a list predicates to the BillingGatheringInvoiceLineUpdate builder. +func (_u *BillingGatheringInvoiceLineUpdateOne) Where(ps ...predicate.BillingGatheringInvoiceLine) *BillingGatheringInvoiceLineUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *BillingGatheringInvoiceLineUpdateOne) Select(field string, fields ...string) *BillingGatheringInvoiceLineUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated BillingGatheringInvoiceLine entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) Save(ctx context.Context) (*BillingGatheringInvoiceLine, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *BillingGatheringInvoiceLineUpdateOne) SaveX(ctx context.Context) *BillingGatheringInvoiceLine { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *BillingGatheringInvoiceLineUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *BillingGatheringInvoiceLineUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *BillingGatheringInvoiceLineUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := billinggatheringinvoiceline.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *BillingGatheringInvoiceLineUpdateOne) check() error { + if v, ok := _u.mutation.TaxConfig(); ok { + if err := v.Validate(); err != nil { + return &ValidationError{Name: "tax_config", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.tax_config": %w`, err)} + } + } + if v, ok := _u.mutation.PriceType(); ok { + if err := billinggatheringinvoiceline.PriceTypeValidator(v); err != nil { + return &ValidationError{Name: "price_type", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.price_type": %w`, err)} + } + } + if v, ok := _u.mutation.Price(); ok { + if err := v.Validate(); err != nil { + return &ValidationError{Name: "price", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.price": %w`, err)} + } + } + if v, ok := _u.mutation.UnitConfig(); ok { + if err := v.Validate(); err != nil { + return &ValidationError{Name: "unit_config", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.unit_config": %w`, err)} + } + } + if v, ok := _u.mutation.RatecardDiscounts(); ok { + if err := v.Validate(); err != nil { + return &ValidationError{Name: "ratecard_discounts", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.ratecard_discounts": %w`, err)} + } + } + if v, ok := _u.mutation.TaxBehavior(); ok { + if err := billinggatheringinvoiceline.TaxBehaviorValidator(v); err != nil { + return &ValidationError{Name: "tax_behavior", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.tax_behavior": %w`, err)} + } + } + if v, ok := _u.mutation.ManagedBy(); ok { + if err := billinggatheringinvoiceline.ManagedByValidator(v); err != nil { + return &ValidationError{Name: "managed_by", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.managed_by": %w`, err)} + } + } + if v, ok := _u.mutation.Engine(); ok { + if err := billinggatheringinvoiceline.EngineValidator(v); err != nil { + return &ValidationError{Name: "engine", err: fmt.Errorf(`db: validator failed for field "BillingGatheringInvoiceLine.engine": %w`, err)} + } + } + if _u.mutation.BillingInvoiceCleared() && len(_u.mutation.BillingInvoiceIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "BillingGatheringInvoiceLine.billing_invoice"`) + } + return nil +} + +func (_u *BillingGatheringInvoiceLineUpdateOne) sqlSave(ctx context.Context) (_node *BillingGatheringInvoiceLine, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.Columns, sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "BillingGatheringInvoiceLine.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, billinggatheringinvoiceline.FieldID) + for _, f := range fields { + if !billinggatheringinvoiceline.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + if f != billinggatheringinvoiceline.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Annotations(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldAnnotations, field.TypeJSON, value) + } + if _u.mutation.AnnotationsCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldAnnotations, field.TypeJSON) + } + if value, ok := _u.mutation.Metadata(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldMetadata, field.TypeJSON, value) + } + if _u.mutation.MetadataCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldMetadata, field.TypeJSON) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.DeletedAt(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldDeletedAt, field.TypeTime, value) + } + if _u.mutation.DeletedAtCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldDeletedAt, field.TypeTime) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Description(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldDescription, field.TypeString, value) + } + if _u.mutation.DescriptionCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldDescription, field.TypeString) + } + if value, ok := _u.mutation.ServicePeriodStart(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldServicePeriodStart, field.TypeTime, value) + } + if value, ok := _u.mutation.ServicePeriodEnd(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldServicePeriodEnd, field.TypeTime, value) + } + if value, ok := _u.mutation.TaxConfig(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldTaxConfig, field.TypeJSON, value) + } + if _u.mutation.TaxConfigCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldTaxConfig, field.TypeJSON) + } + if value, ok := _u.mutation.PriceType(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldPriceType, field.TypeEnum, value) + } + if value, ok := _u.mutation.FeatureKey(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldFeatureKey, field.TypeString, value) + } + if _u.mutation.FeatureKeyCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldFeatureKey, field.TypeString) + } + if value, ok := _u.mutation.Price(); ok { + vv, err := billinggatheringinvoiceline.ValueScanner.Price.Value(value) + if err != nil { + return nil, err + } + _spec.SetField(billinggatheringinvoiceline.FieldPrice, field.TypeString, vv) + } + if value, ok := _u.mutation.UnitConfig(); ok { + vv, err := billinggatheringinvoiceline.ValueScanner.UnitConfig.Value(value) + if err != nil { + return nil, err + } + _spec.SetField(billinggatheringinvoiceline.FieldUnitConfig, field.TypeString, vv) + } + if _u.mutation.UnitConfigCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldUnitConfig, field.TypeString) + } + if value, ok := _u.mutation.RatecardDiscounts(); ok { + vv, err := billinggatheringinvoiceline.ValueScanner.RatecardDiscounts.Value(value) + if err != nil { + return nil, err + } + _spec.SetField(billinggatheringinvoiceline.FieldRatecardDiscounts, field.TypeString, vv) + } + if _u.mutation.RatecardDiscountsCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldRatecardDiscounts, field.TypeString) + } + if value, ok := _u.mutation.ChildUniqueReferenceID(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldChildUniqueReferenceID, field.TypeString, value) + } + if _u.mutation.ChildUniqueReferenceIDCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldChildUniqueReferenceID, field.TypeString) + } + if value, ok := _u.mutation.SubscriptionBillingPeriodFrom(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom, field.TypeTime, value) + } + if _u.mutation.SubscriptionBillingPeriodFromCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom, field.TypeTime) + } + if value, ok := _u.mutation.SubscriptionBillingPeriodTo(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo, field.TypeTime, value) + } + if _u.mutation.SubscriptionBillingPeriodToCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo, field.TypeTime) + } + if value, ok := _u.mutation.TaxBehavior(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldTaxBehavior, field.TypeEnum, value) + } + if _u.mutation.TaxBehaviorCleared() { + _spec.ClearField(billinggatheringinvoiceline.FieldTaxBehavior, field.TypeEnum) + } + if value, ok := _u.mutation.InvoiceAt(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldInvoiceAt, field.TypeTime, value) + } + if value, ok := _u.mutation.ManagedBy(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldManagedBy, field.TypeEnum, value) + } + if value, ok := _u.mutation.Engine(); ok { + _spec.SetField(billinggatheringinvoiceline.FieldEngine, field.TypeEnum, value) + } + if _u.mutation.BillingInvoiceCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.BillingInvoiceTable, + Columns: []string{billinggatheringinvoiceline.BillingInvoiceColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinginvoice.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingInvoiceIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.BillingInvoiceTable, + Columns: []string{billinggatheringinvoiceline.BillingInvoiceColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinginvoice.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.SplitLineGroupCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SplitLineGroupTable, + Columns: []string{billinggatheringinvoiceline.SplitLineGroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinginvoicesplitlinegroup.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SplitLineGroupIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SplitLineGroupTable, + Columns: []string{billinggatheringinvoiceline.SplitLineGroupColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinginvoicesplitlinegroup.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.SubscriptionCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscription.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SubscriptionIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscription.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.SubscriptionPhaseCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionPhaseTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionPhaseColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscriptionphase.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SubscriptionPhaseIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionPhaseTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionPhaseColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscriptionphase.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.SubscriptionItemCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionItemTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionItemColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscriptionitem.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.SubscriptionItemIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.SubscriptionItemTable, + Columns: []string{billinggatheringinvoiceline.SubscriptionItemColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(subscriptionitem.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.ChargeCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.ChargeTable, + Columns: []string{billinggatheringinvoiceline.ChargeColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(charge.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ChargeIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.ChargeTable, + Columns: []string{billinggatheringinvoiceline.ChargeColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(charge.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if _u.mutation.TaxCodeCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.TaxCodeTable, + Columns: []string{billinggatheringinvoiceline.TaxCodeColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(dbtaxcode.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TaxCodeIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: billinggatheringinvoiceline.TaxCodeTable, + Columns: []string{billinggatheringinvoiceline.TaxCodeColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(dbtaxcode.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &BillingGatheringInvoiceLine{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{billinggatheringinvoiceline.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/openmeter/ent/db/billinginvoice.go b/openmeter/ent/db/billinginvoice.go index ba7a0cba82..4f8433abd5 100644 --- a/openmeter/ent/db/billinginvoice.go +++ b/openmeter/ent/db/billinginvoice.go @@ -158,6 +158,8 @@ type BillingInvoiceEdges struct { BillingWorkflowConfig *BillingWorkflowConfig `json:"billing_workflow_config,omitempty"` // BillingInvoiceLines holds the value of the billing_invoice_lines edge. BillingInvoiceLines []*BillingInvoiceLine `json:"billing_invoice_lines,omitempty"` + // BillingGatheringInvoiceLines holds the value of the billing_gathering_invoice_lines edge. + BillingGatheringInvoiceLines []*BillingGatheringInvoiceLine `json:"billing_gathering_invoice_lines,omitempty"` // BillingInvoiceDetailedLines holds the value of the billing_invoice_detailed_lines edge. BillingInvoiceDetailedLines []*BillingStandardInvoiceDetailedLine `json:"billing_invoice_detailed_lines,omitempty"` // BillingInvoiceValidationIssues holds the value of the billing_invoice_validation_issues edge. @@ -176,7 +178,7 @@ type BillingInvoiceEdges struct { PaymentApp *App `json:"payment_app,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [11]bool + loadedTypes [12]bool } // SourceBillingProfileOrErr returns the SourceBillingProfile value or an error if the edge @@ -210,10 +212,19 @@ func (e BillingInvoiceEdges) BillingInvoiceLinesOrErr() ([]*BillingInvoiceLine, return nil, &NotLoadedError{edge: "billing_invoice_lines"} } +// BillingGatheringInvoiceLinesOrErr returns the BillingGatheringInvoiceLines value or an error if the edge +// was not loaded in eager-loading. +func (e BillingInvoiceEdges) BillingGatheringInvoiceLinesOrErr() ([]*BillingGatheringInvoiceLine, error) { + if e.loadedTypes[3] { + return e.BillingGatheringInvoiceLines, nil + } + return nil, &NotLoadedError{edge: "billing_gathering_invoice_lines"} +} + // BillingInvoiceDetailedLinesOrErr returns the BillingInvoiceDetailedLines value or an error if the edge // was not loaded in eager-loading. func (e BillingInvoiceEdges) BillingInvoiceDetailedLinesOrErr() ([]*BillingStandardInvoiceDetailedLine, error) { - if e.loadedTypes[3] { + if e.loadedTypes[4] { return e.BillingInvoiceDetailedLines, nil } return nil, &NotLoadedError{edge: "billing_invoice_detailed_lines"} @@ -222,7 +233,7 @@ func (e BillingInvoiceEdges) BillingInvoiceDetailedLinesOrErr() ([]*BillingStand // BillingInvoiceValidationIssuesOrErr returns the BillingInvoiceValidationIssues value or an error if the edge // was not loaded in eager-loading. func (e BillingInvoiceEdges) BillingInvoiceValidationIssuesOrErr() ([]*BillingInvoiceValidationIssue, error) { - if e.loadedTypes[4] { + if e.loadedTypes[5] { return e.BillingInvoiceValidationIssues, nil } return nil, &NotLoadedError{edge: "billing_invoice_validation_issues"} @@ -231,7 +242,7 @@ func (e BillingInvoiceEdges) BillingInvoiceValidationIssuesOrErr() ([]*BillingIn // ChargeFlatFeeRunsOrErr returns the ChargeFlatFeeRuns value or an error if the edge // was not loaded in eager-loading. func (e BillingInvoiceEdges) ChargeFlatFeeRunsOrErr() ([]*ChargeFlatFeeRun, error) { - if e.loadedTypes[5] { + if e.loadedTypes[6] { return e.ChargeFlatFeeRuns, nil } return nil, &NotLoadedError{edge: "charge_flat_fee_runs"} @@ -240,7 +251,7 @@ func (e BillingInvoiceEdges) ChargeFlatFeeRunsOrErr() ([]*ChargeFlatFeeRun, erro // ChargeUsageBasedRunsOrErr returns the ChargeUsageBasedRuns value or an error if the edge // was not loaded in eager-loading. func (e BillingInvoiceEdges) ChargeUsageBasedRunsOrErr() ([]*ChargeUsageBasedRuns, error) { - if e.loadedTypes[6] { + if e.loadedTypes[7] { return e.ChargeUsageBasedRuns, nil } return nil, &NotLoadedError{edge: "charge_usage_based_runs"} @@ -251,7 +262,7 @@ func (e BillingInvoiceEdges) ChargeUsageBasedRunsOrErr() ([]*ChargeUsageBasedRun func (e BillingInvoiceEdges) BillingInvoiceCustomerOrErr() (*Customer, error) { if e.BillingInvoiceCustomer != nil { return e.BillingInvoiceCustomer, nil - } else if e.loadedTypes[7] { + } else if e.loadedTypes[8] { return nil, &NotFoundError{label: customer.Label} } return nil, &NotLoadedError{edge: "billing_invoice_customer"} @@ -262,7 +273,7 @@ func (e BillingInvoiceEdges) BillingInvoiceCustomerOrErr() (*Customer, error) { func (e BillingInvoiceEdges) TaxAppOrErr() (*App, error) { if e.TaxApp != nil { return e.TaxApp, nil - } else if e.loadedTypes[8] { + } else if e.loadedTypes[9] { return nil, &NotFoundError{label: dbapp.Label} } return nil, &NotLoadedError{edge: "tax_app"} @@ -273,7 +284,7 @@ func (e BillingInvoiceEdges) TaxAppOrErr() (*App, error) { func (e BillingInvoiceEdges) InvoicingAppOrErr() (*App, error) { if e.InvoicingApp != nil { return e.InvoicingApp, nil - } else if e.loadedTypes[9] { + } else if e.loadedTypes[10] { return nil, &NotFoundError{label: dbapp.Label} } return nil, &NotLoadedError{edge: "invoicing_app"} @@ -284,7 +295,7 @@ func (e BillingInvoiceEdges) InvoicingAppOrErr() (*App, error) { func (e BillingInvoiceEdges) PaymentAppOrErr() (*App, error) { if e.PaymentApp != nil { return e.PaymentApp, nil - } else if e.loadedTypes[10] { + } else if e.loadedTypes[11] { return nil, &NotFoundError{label: dbapp.Label} } return nil, &NotLoadedError{edge: "payment_app"} @@ -746,6 +757,11 @@ func (_m *BillingInvoice) QueryBillingInvoiceLines() *BillingInvoiceLineQuery { return NewBillingInvoiceClient(_m.config).QueryBillingInvoiceLines(_m) } +// QueryBillingGatheringInvoiceLines queries the "billing_gathering_invoice_lines" edge of the BillingInvoice entity. +func (_m *BillingInvoice) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + return NewBillingInvoiceClient(_m.config).QueryBillingGatheringInvoiceLines(_m) +} + // QueryBillingInvoiceDetailedLines queries the "billing_invoice_detailed_lines" edge of the BillingInvoice entity. func (_m *BillingInvoice) QueryBillingInvoiceDetailedLines() *BillingStandardInvoiceDetailedLineQuery { return NewBillingInvoiceClient(_m.config).QueryBillingInvoiceDetailedLines(_m) diff --git a/openmeter/ent/db/billinginvoice/billinginvoice.go b/openmeter/ent/db/billinginvoice/billinginvoice.go index a68b6ea521..2fbb874cf7 100644 --- a/openmeter/ent/db/billinginvoice/billinginvoice.go +++ b/openmeter/ent/db/billinginvoice/billinginvoice.go @@ -140,6 +140,8 @@ const ( EdgeBillingWorkflowConfig = "billing_workflow_config" // EdgeBillingInvoiceLines holds the string denoting the billing_invoice_lines edge name in mutations. EdgeBillingInvoiceLines = "billing_invoice_lines" + // EdgeBillingGatheringInvoiceLines holds the string denoting the billing_gathering_invoice_lines edge name in mutations. + EdgeBillingGatheringInvoiceLines = "billing_gathering_invoice_lines" // EdgeBillingInvoiceDetailedLines holds the string denoting the billing_invoice_detailed_lines edge name in mutations. EdgeBillingInvoiceDetailedLines = "billing_invoice_detailed_lines" // EdgeBillingInvoiceValidationIssues holds the string denoting the billing_invoice_validation_issues edge name in mutations. @@ -179,6 +181,13 @@ const ( BillingInvoiceLinesInverseTable = "billing_invoice_lines" // BillingInvoiceLinesColumn is the table column denoting the billing_invoice_lines relation/edge. BillingInvoiceLinesColumn = "invoice_id" + // BillingGatheringInvoiceLinesTable is the table that holds the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesInverseTable is the table name for the BillingGatheringInvoiceLine entity. + // It exists in this package in order to avoid circular dependency with the "billinggatheringinvoiceline" package. + BillingGatheringInvoiceLinesInverseTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesColumn is the table column denoting the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesColumn = "invoice_id" // BillingInvoiceDetailedLinesTable is the table that holds the billing_invoice_detailed_lines relation/edge. BillingInvoiceDetailedLinesTable = "billing_standard_invoice_detailed_lines" // BillingInvoiceDetailedLinesInverseTable is the table name for the BillingStandardInvoiceDetailedLine entity. @@ -686,6 +695,20 @@ func ByBillingInvoiceLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOpti } } +// ByBillingGatheringInvoiceLinesCount orders the results by billing_gathering_invoice_lines count. +func ByBillingGatheringInvoiceLinesCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newBillingGatheringInvoiceLinesStep(), opts...) + } +} + +// ByBillingGatheringInvoiceLines orders the results by billing_gathering_invoice_lines terms. +func ByBillingGatheringInvoiceLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newBillingGatheringInvoiceLinesStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + // ByBillingInvoiceDetailedLinesCount orders the results by billing_invoice_detailed_lines count. func ByBillingInvoiceDetailedLinesCount(opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -790,6 +813,13 @@ func newBillingInvoiceLinesStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, BillingInvoiceLinesTable, BillingInvoiceLinesColumn), ) } +func newBillingGatheringInvoiceLinesStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(BillingGatheringInvoiceLinesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) +} func newBillingInvoiceDetailedLinesStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/openmeter/ent/db/billinginvoice/where.go b/openmeter/ent/db/billinginvoice/where.go index 945c5495fe..caf01aa5c9 100644 --- a/openmeter/ent/db/billinginvoice/where.go +++ b/openmeter/ent/db/billinginvoice/where.go @@ -3798,6 +3798,29 @@ func HasBillingInvoiceLinesWith(preds ...predicate.BillingInvoiceLine) predicate }) } +// HasBillingGatheringInvoiceLines applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge. +func HasBillingGatheringInvoiceLines() predicate.BillingInvoice { + return predicate.BillingInvoice(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasBillingGatheringInvoiceLinesWith applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge with a given conditions (other predicates). +func HasBillingGatheringInvoiceLinesWith(preds ...predicate.BillingGatheringInvoiceLine) predicate.BillingInvoice { + return predicate.BillingInvoice(func(s *sql.Selector) { + step := newBillingGatheringInvoiceLinesStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // HasBillingInvoiceDetailedLines applies the HasEdge predicate on the "billing_invoice_detailed_lines" edge. func HasBillingInvoiceDetailedLines() predicate.BillingInvoice { return predicate.BillingInvoice(func(s *sql.Selector) { diff --git a/openmeter/ent/db/billinginvoice_create.go b/openmeter/ent/db/billinginvoice_create.go index f8f59bcef9..257f44a82d 100644 --- a/openmeter/ent/db/billinginvoice_create.go +++ b/openmeter/ent/db/billinginvoice_create.go @@ -15,6 +15,7 @@ import ( "github.com/alpacahq/alpacadecimal" "github.com/openmeterio/openmeter/openmeter/billing" dbapp "github.com/openmeterio/openmeter/openmeter/ent/db/app" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicevalidationissue" @@ -723,6 +724,21 @@ func (_c *BillingInvoiceCreate) AddBillingInvoiceLines(v ...*BillingInvoiceLine) return _c.AddBillingInvoiceLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_c *BillingInvoiceCreate) AddBillingGatheringInvoiceLineIDs(ids ...string) *BillingInvoiceCreate { + _c.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _c +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_c *BillingInvoiceCreate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *BillingInvoiceCreate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingInvoiceDetailedLineIDs adds the "billing_invoice_detailed_lines" edge to the BillingStandardInvoiceDetailedLine entity by IDs. func (_c *BillingInvoiceCreate) AddBillingInvoiceDetailedLineIDs(ids ...string) *BillingInvoiceCreate { _c.mutation.AddBillingInvoiceDetailedLineIDs(ids...) @@ -1312,6 +1328,22 @@ func (_c *BillingInvoiceCreate) createSpec() (*BillingInvoice, *sqlgraph.CreateS } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoice.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoice.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.BillingInvoiceDetailedLinesIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/openmeter/ent/db/billinginvoice_query.go b/openmeter/ent/db/billinginvoice_query.go index 38760bde47..bc658ff295 100644 --- a/openmeter/ent/db/billinginvoice_query.go +++ b/openmeter/ent/db/billinginvoice_query.go @@ -14,6 +14,7 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" dbapp "github.com/openmeterio/openmeter/openmeter/ent/db/app" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicevalidationissue" @@ -36,6 +37,7 @@ type BillingInvoiceQuery struct { withSourceBillingProfile *BillingProfileQuery withBillingWorkflowConfig *BillingWorkflowConfigQuery withBillingInvoiceLines *BillingInvoiceLineQuery + withBillingGatheringInvoiceLines *BillingGatheringInvoiceLineQuery withBillingInvoiceDetailedLines *BillingStandardInvoiceDetailedLineQuery withBillingInvoiceValidationIssues *BillingInvoiceValidationIssueQuery withChargeFlatFeeRuns *ChargeFlatFeeRunQuery @@ -147,6 +149,28 @@ func (_q *BillingInvoiceQuery) QueryBillingInvoiceLines() *BillingInvoiceLineQue return query } +// QueryBillingGatheringInvoiceLines chains the current query on the "billing_gathering_invoice_lines" edge. +func (_q *BillingInvoiceQuery) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(billinginvoice.Table, billinginvoice.FieldID, selector), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, billinginvoice.BillingGatheringInvoiceLinesTable, billinginvoice.BillingGatheringInvoiceLinesColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryBillingInvoiceDetailedLines chains the current query on the "billing_invoice_detailed_lines" edge. func (_q *BillingInvoiceQuery) QueryBillingInvoiceDetailedLines() *BillingStandardInvoiceDetailedLineQuery { query := (&BillingStandardInvoiceDetailedLineClient{config: _q.config}).Query() @@ -518,6 +542,7 @@ func (_q *BillingInvoiceQuery) Clone() *BillingInvoiceQuery { withSourceBillingProfile: _q.withSourceBillingProfile.Clone(), withBillingWorkflowConfig: _q.withBillingWorkflowConfig.Clone(), withBillingInvoiceLines: _q.withBillingInvoiceLines.Clone(), + withBillingGatheringInvoiceLines: _q.withBillingGatheringInvoiceLines.Clone(), withBillingInvoiceDetailedLines: _q.withBillingInvoiceDetailedLines.Clone(), withBillingInvoiceValidationIssues: _q.withBillingInvoiceValidationIssues.Clone(), withChargeFlatFeeRuns: _q.withChargeFlatFeeRuns.Clone(), @@ -565,6 +590,17 @@ func (_q *BillingInvoiceQuery) WithBillingInvoiceLines(opts ...func(*BillingInvo return _q } +// WithBillingGatheringInvoiceLines tells the query-builder to eager-load the nodes that are connected to +// the "billing_gathering_invoice_lines" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *BillingInvoiceQuery) WithBillingGatheringInvoiceLines(opts ...func(*BillingGatheringInvoiceLineQuery)) *BillingInvoiceQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withBillingGatheringInvoiceLines = query + return _q +} + // WithBillingInvoiceDetailedLines tells the query-builder to eager-load the nodes that are connected to // the "billing_invoice_detailed_lines" edge. The optional arguments are used to configure the query builder of the edge. func (_q *BillingInvoiceQuery) WithBillingInvoiceDetailedLines(opts ...func(*BillingStandardInvoiceDetailedLineQuery)) *BillingInvoiceQuery { @@ -731,10 +767,11 @@ func (_q *BillingInvoiceQuery) sqlAll(ctx context.Context, hooks ...queryHook) ( var ( nodes = []*BillingInvoice{} _spec = _q.querySpec() - loadedTypes = [11]bool{ + loadedTypes = [12]bool{ _q.withSourceBillingProfile != nil, _q.withBillingWorkflowConfig != nil, _q.withBillingInvoiceLines != nil, + _q.withBillingGatheringInvoiceLines != nil, _q.withBillingInvoiceDetailedLines != nil, _q.withBillingInvoiceValidationIssues != nil, _q.withChargeFlatFeeRuns != nil, @@ -787,6 +824,15 @@ func (_q *BillingInvoiceQuery) sqlAll(ctx context.Context, hooks ...queryHook) ( return nil, err } } + if query := _q.withBillingGatheringInvoiceLines; query != nil { + if err := _q.loadBillingGatheringInvoiceLines(ctx, query, nodes, + func(n *BillingInvoice) { n.Edges.BillingGatheringInvoiceLines = []*BillingGatheringInvoiceLine{} }, + func(n *BillingInvoice, e *BillingGatheringInvoiceLine) { + n.Edges.BillingGatheringInvoiceLines = append(n.Edges.BillingGatheringInvoiceLines, e) + }); err != nil { + return nil, err + } + } if query := _q.withBillingInvoiceDetailedLines; query != nil { if err := _q.loadBillingInvoiceDetailedLines(ctx, query, nodes, func(n *BillingInvoice) { n.Edges.BillingInvoiceDetailedLines = []*BillingStandardInvoiceDetailedLine{} }, @@ -939,6 +985,36 @@ func (_q *BillingInvoiceQuery) loadBillingInvoiceLines(ctx context.Context, quer } return nil } +func (_q *BillingInvoiceQuery) loadBillingGatheringInvoiceLines(ctx context.Context, query *BillingGatheringInvoiceLineQuery, nodes []*BillingInvoice, init func(*BillingInvoice), assign func(*BillingInvoice, *BillingGatheringInvoiceLine)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[string]*BillingInvoice) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(billinggatheringinvoiceline.FieldInvoiceID) + } + query.Where(predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(billinginvoice.BillingGatheringInvoiceLinesColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.InvoiceID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "invoice_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} func (_q *BillingInvoiceQuery) loadBillingInvoiceDetailedLines(ctx context.Context, query *BillingStandardInvoiceDetailedLineQuery, nodes []*BillingInvoice, init func(*BillingInvoice), assign func(*BillingInvoice, *BillingStandardInvoiceDetailedLine)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[string]*BillingInvoice) diff --git a/openmeter/ent/db/billinginvoice_update.go b/openmeter/ent/db/billinginvoice_update.go index 5fb4e1b894..3853f91b53 100644 --- a/openmeter/ent/db/billinginvoice_update.go +++ b/openmeter/ent/db/billinginvoice_update.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/schema/field" "github.com/alpacahq/alpacadecimal" "github.com/openmeterio/openmeter/openmeter/billing" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicevalidationissue" @@ -970,6 +971,21 @@ func (_u *BillingInvoiceUpdate) AddBillingInvoiceLines(v ...*BillingInvoiceLine) return _u.AddBillingInvoiceLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *BillingInvoiceUpdate) AddBillingGatheringInvoiceLineIDs(ids ...string) *BillingInvoiceUpdate { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *BillingInvoiceUpdate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *BillingInvoiceUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingInvoiceDetailedLineIDs adds the "billing_invoice_detailed_lines" edge to the BillingStandardInvoiceDetailedLine entity by IDs. func (_u *BillingInvoiceUpdate) AddBillingInvoiceDetailedLineIDs(ids ...string) *BillingInvoiceUpdate { _u.mutation.AddBillingInvoiceDetailedLineIDs(ids...) @@ -1062,6 +1078,27 @@ func (_u *BillingInvoiceUpdate) RemoveBillingInvoiceLines(v ...*BillingInvoiceLi return _u.RemoveBillingInvoiceLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *BillingInvoiceUpdate) ClearBillingGatheringInvoiceLines() *BillingInvoiceUpdate { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *BillingInvoiceUpdate) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *BillingInvoiceUpdate { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *BillingInvoiceUpdate) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *BillingInvoiceUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearBillingInvoiceDetailedLines clears all "billing_invoice_detailed_lines" edges to the BillingStandardInvoiceDetailedLine entity. func (_u *BillingInvoiceUpdate) ClearBillingInvoiceDetailedLines() *BillingInvoiceUpdate { _u.mutation.ClearBillingInvoiceDetailedLines() @@ -1589,6 +1626,51 @@ func (_u *BillingInvoiceUpdate) sqlSave(ctx context.Context) (_node int, err err } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoice.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoice.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoice.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoice.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoice.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoice.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.BillingInvoiceDetailedLinesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -2722,6 +2804,21 @@ func (_u *BillingInvoiceUpdateOne) AddBillingInvoiceLines(v ...*BillingInvoiceLi return _u.AddBillingInvoiceLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *BillingInvoiceUpdateOne) AddBillingGatheringInvoiceLineIDs(ids ...string) *BillingInvoiceUpdateOne { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *BillingInvoiceUpdateOne) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *BillingInvoiceUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingInvoiceDetailedLineIDs adds the "billing_invoice_detailed_lines" edge to the BillingStandardInvoiceDetailedLine entity by IDs. func (_u *BillingInvoiceUpdateOne) AddBillingInvoiceDetailedLineIDs(ids ...string) *BillingInvoiceUpdateOne { _u.mutation.AddBillingInvoiceDetailedLineIDs(ids...) @@ -2814,6 +2911,27 @@ func (_u *BillingInvoiceUpdateOne) RemoveBillingInvoiceLines(v ...*BillingInvoic return _u.RemoveBillingInvoiceLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *BillingInvoiceUpdateOne) ClearBillingGatheringInvoiceLines() *BillingInvoiceUpdateOne { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *BillingInvoiceUpdateOne) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *BillingInvoiceUpdateOne { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *BillingInvoiceUpdateOne) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *BillingInvoiceUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearBillingInvoiceDetailedLines clears all "billing_invoice_detailed_lines" edges to the BillingStandardInvoiceDetailedLine entity. func (_u *BillingInvoiceUpdateOne) ClearBillingInvoiceDetailedLines() *BillingInvoiceUpdateOne { _u.mutation.ClearBillingInvoiceDetailedLines() @@ -3371,6 +3489,51 @@ func (_u *BillingInvoiceUpdateOne) sqlSave(ctx context.Context) (_node *BillingI } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoice.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoice.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoice.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoice.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoice.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoice.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.BillingInvoiceDetailedLinesCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/openmeter/ent/db/billinginvoicesplitlinegroup.go b/openmeter/ent/db/billinginvoicesplitlinegroup.go index 91cd8cac03..13c41fa499 100644 --- a/openmeter/ent/db/billinginvoicesplitlinegroup.go +++ b/openmeter/ent/db/billinginvoicesplitlinegroup.go @@ -75,6 +75,8 @@ type BillingInvoiceSplitLineGroup struct { type BillingInvoiceSplitLineGroupEdges struct { // BillingInvoiceLines holds the value of the billing_invoice_lines edge. BillingInvoiceLines []*BillingInvoiceLine `json:"billing_invoice_lines,omitempty"` + // BillingGatheringInvoiceLines holds the value of the billing_gathering_invoice_lines edge. + BillingGatheringInvoiceLines []*BillingGatheringInvoiceLine `json:"billing_gathering_invoice_lines,omitempty"` // Subscription holds the value of the subscription edge. Subscription *Subscription `json:"subscription,omitempty"` // SubscriptionPhase holds the value of the subscription_phase edge. @@ -85,7 +87,7 @@ type BillingInvoiceSplitLineGroupEdges struct { Charge *Charge `json:"charge,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [5]bool + loadedTypes [6]bool } // BillingInvoiceLinesOrErr returns the BillingInvoiceLines value or an error if the edge @@ -97,12 +99,21 @@ func (e BillingInvoiceSplitLineGroupEdges) BillingInvoiceLinesOrErr() ([]*Billin return nil, &NotLoadedError{edge: "billing_invoice_lines"} } +// BillingGatheringInvoiceLinesOrErr returns the BillingGatheringInvoiceLines value or an error if the edge +// was not loaded in eager-loading. +func (e BillingInvoiceSplitLineGroupEdges) BillingGatheringInvoiceLinesOrErr() ([]*BillingGatheringInvoiceLine, error) { + if e.loadedTypes[1] { + return e.BillingGatheringInvoiceLines, nil + } + return nil, &NotLoadedError{edge: "billing_gathering_invoice_lines"} +} + // SubscriptionOrErr returns the Subscription value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e BillingInvoiceSplitLineGroupEdges) SubscriptionOrErr() (*Subscription, error) { if e.Subscription != nil { return e.Subscription, nil - } else if e.loadedTypes[1] { + } else if e.loadedTypes[2] { return nil, &NotFoundError{label: subscription.Label} } return nil, &NotLoadedError{edge: "subscription"} @@ -113,7 +124,7 @@ func (e BillingInvoiceSplitLineGroupEdges) SubscriptionOrErr() (*Subscription, e func (e BillingInvoiceSplitLineGroupEdges) SubscriptionPhaseOrErr() (*SubscriptionPhase, error) { if e.SubscriptionPhase != nil { return e.SubscriptionPhase, nil - } else if e.loadedTypes[2] { + } else if e.loadedTypes[3] { return nil, &NotFoundError{label: subscriptionphase.Label} } return nil, &NotLoadedError{edge: "subscription_phase"} @@ -124,7 +135,7 @@ func (e BillingInvoiceSplitLineGroupEdges) SubscriptionPhaseOrErr() (*Subscripti func (e BillingInvoiceSplitLineGroupEdges) SubscriptionItemOrErr() (*SubscriptionItem, error) { if e.SubscriptionItem != nil { return e.SubscriptionItem, nil - } else if e.loadedTypes[3] { + } else if e.loadedTypes[4] { return nil, &NotFoundError{label: subscriptionitem.Label} } return nil, &NotLoadedError{edge: "subscription_item"} @@ -135,7 +146,7 @@ func (e BillingInvoiceSplitLineGroupEdges) SubscriptionItemOrErr() (*Subscriptio func (e BillingInvoiceSplitLineGroupEdges) ChargeOrErr() (*Charge, error) { if e.Charge != nil { return e.Charge, nil - } else if e.loadedTypes[4] { + } else if e.loadedTypes[5] { return nil, &NotFoundError{label: charge.Label} } return nil, &NotLoadedError{edge: "charge"} @@ -327,6 +338,11 @@ func (_m *BillingInvoiceSplitLineGroup) QueryBillingInvoiceLines() *BillingInvoi return NewBillingInvoiceSplitLineGroupClient(_m.config).QueryBillingInvoiceLines(_m) } +// QueryBillingGatheringInvoiceLines queries the "billing_gathering_invoice_lines" edge of the BillingInvoiceSplitLineGroup entity. +func (_m *BillingInvoiceSplitLineGroup) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + return NewBillingInvoiceSplitLineGroupClient(_m.config).QueryBillingGatheringInvoiceLines(_m) +} + // QuerySubscription queries the "subscription" edge of the BillingInvoiceSplitLineGroup entity. func (_m *BillingInvoiceSplitLineGroup) QuerySubscription() *SubscriptionQuery { return NewBillingInvoiceSplitLineGroupClient(_m.config).QuerySubscription(_m) diff --git a/openmeter/ent/db/billinginvoicesplitlinegroup/billinginvoicesplitlinegroup.go b/openmeter/ent/db/billinginvoicesplitlinegroup/billinginvoicesplitlinegroup.go index a87f7b0738..ca7373d47d 100644 --- a/openmeter/ent/db/billinginvoicesplitlinegroup/billinginvoicesplitlinegroup.go +++ b/openmeter/ent/db/billinginvoicesplitlinegroup/billinginvoicesplitlinegroup.go @@ -59,6 +59,8 @@ const ( FieldChargeID = "charge_id" // EdgeBillingInvoiceLines holds the string denoting the billing_invoice_lines edge name in mutations. EdgeBillingInvoiceLines = "billing_invoice_lines" + // EdgeBillingGatheringInvoiceLines holds the string denoting the billing_gathering_invoice_lines edge name in mutations. + EdgeBillingGatheringInvoiceLines = "billing_gathering_invoice_lines" // EdgeSubscription holds the string denoting the subscription edge name in mutations. EdgeSubscription = "subscription" // EdgeSubscriptionPhase holds the string denoting the subscription_phase edge name in mutations. @@ -76,6 +78,13 @@ const ( BillingInvoiceLinesInverseTable = "billing_invoice_lines" // BillingInvoiceLinesColumn is the table column denoting the billing_invoice_lines relation/edge. BillingInvoiceLinesColumn = "split_line_group_id" + // BillingGatheringInvoiceLinesTable is the table that holds the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesInverseTable is the table name for the BillingGatheringInvoiceLine entity. + // It exists in this package in order to avoid circular dependency with the "billinggatheringinvoiceline" package. + BillingGatheringInvoiceLinesInverseTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesColumn is the table column denoting the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesColumn = "split_line_group_id" // SubscriptionTable is the table that holds the subscription relation/edge. SubscriptionTable = "billing_invoice_split_line_groups" // SubscriptionInverseTable is the table name for the Subscription entity. @@ -278,6 +287,20 @@ func ByBillingInvoiceLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOpti } } +// ByBillingGatheringInvoiceLinesCount orders the results by billing_gathering_invoice_lines count. +func ByBillingGatheringInvoiceLinesCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newBillingGatheringInvoiceLinesStep(), opts...) + } +} + +// ByBillingGatheringInvoiceLines orders the results by billing_gathering_invoice_lines terms. +func ByBillingGatheringInvoiceLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newBillingGatheringInvoiceLinesStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + // BySubscriptionField orders the results by subscription field. func BySubscriptionField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -312,6 +335,13 @@ func newBillingInvoiceLinesStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, BillingInvoiceLinesTable, BillingInvoiceLinesColumn), ) } +func newBillingGatheringInvoiceLinesStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(BillingGatheringInvoiceLinesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) +} func newSubscriptionStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/openmeter/ent/db/billinginvoicesplitlinegroup/where.go b/openmeter/ent/db/billinginvoicesplitlinegroup/where.go index 75d8462aca..a02dc27b27 100644 --- a/openmeter/ent/db/billinginvoicesplitlinegroup/where.go +++ b/openmeter/ent/db/billinginvoicesplitlinegroup/where.go @@ -1244,6 +1244,29 @@ func HasBillingInvoiceLinesWith(preds ...predicate.BillingInvoiceLine) predicate }) } +// HasBillingGatheringInvoiceLines applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge. +func HasBillingGatheringInvoiceLines() predicate.BillingInvoiceSplitLineGroup { + return predicate.BillingInvoiceSplitLineGroup(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasBillingGatheringInvoiceLinesWith applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge with a given conditions (other predicates). +func HasBillingGatheringInvoiceLinesWith(preds ...predicate.BillingGatheringInvoiceLine) predicate.BillingInvoiceSplitLineGroup { + return predicate.BillingInvoiceSplitLineGroup(func(s *sql.Selector) { + step := newBillingGatheringInvoiceLinesStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // HasSubscription applies the HasEdge predicate on the "subscription" edge. func HasSubscription() predicate.BillingInvoiceSplitLineGroup { return predicate.BillingInvoiceSplitLineGroup(func(s *sql.Selector) { diff --git a/openmeter/ent/db/billinginvoicesplitlinegroup_create.go b/openmeter/ent/db/billinginvoicesplitlinegroup_create.go index afc07bfc4f..6a3bbdcbe3 100644 --- a/openmeter/ent/db/billinginvoicesplitlinegroup_create.go +++ b/openmeter/ent/db/billinginvoicesplitlinegroup_create.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/openmeterio/openmeter/openmeter/billing" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" @@ -276,6 +277,21 @@ func (_c *BillingInvoiceSplitLineGroupCreate) AddBillingInvoiceLines(v ...*Billi return _c.AddBillingInvoiceLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_c *BillingInvoiceSplitLineGroupCreate) AddBillingGatheringInvoiceLineIDs(ids ...string) *BillingInvoiceSplitLineGroupCreate { + _c.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _c +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_c *BillingInvoiceSplitLineGroupCreate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *BillingInvoiceSplitLineGroupCreate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddBillingGatheringInvoiceLineIDs(ids...) +} + // SetSubscription sets the "subscription" edge to the Subscription entity. func (_c *BillingInvoiceSplitLineGroupCreate) SetSubscription(v *Subscription) *BillingInvoiceSplitLineGroupCreate { return _c.SetSubscriptionID(v.ID) @@ -518,6 +534,22 @@ func (_c *BillingInvoiceSplitLineGroupCreate) createSpec() (*BillingInvoiceSplit } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.SubscriptionIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/openmeter/ent/db/billinginvoicesplitlinegroup_query.go b/openmeter/ent/db/billinginvoicesplitlinegroup_query.go index 0aabc08378..77d8560cc8 100644 --- a/openmeter/ent/db/billinginvoicesplitlinegroup_query.go +++ b/openmeter/ent/db/billinginvoicesplitlinegroup_query.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" @@ -25,16 +26,17 @@ import ( // BillingInvoiceSplitLineGroupQuery is the builder for querying BillingInvoiceSplitLineGroup entities. type BillingInvoiceSplitLineGroupQuery struct { config - ctx *QueryContext - order []billinginvoicesplitlinegroup.OrderOption - inters []Interceptor - predicates []predicate.BillingInvoiceSplitLineGroup - withBillingInvoiceLines *BillingInvoiceLineQuery - withSubscription *SubscriptionQuery - withSubscriptionPhase *SubscriptionPhaseQuery - withSubscriptionItem *SubscriptionItemQuery - withCharge *ChargeQuery - modifiers []func(*sql.Selector) + ctx *QueryContext + order []billinginvoicesplitlinegroup.OrderOption + inters []Interceptor + predicates []predicate.BillingInvoiceSplitLineGroup + withBillingInvoiceLines *BillingInvoiceLineQuery + withBillingGatheringInvoiceLines *BillingGatheringInvoiceLineQuery + withSubscription *SubscriptionQuery + withSubscriptionPhase *SubscriptionPhaseQuery + withSubscriptionItem *SubscriptionItemQuery + withCharge *ChargeQuery + modifiers []func(*sql.Selector) // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -93,6 +95,28 @@ func (_q *BillingInvoiceSplitLineGroupQuery) QueryBillingInvoiceLines() *Billing return query } +// QueryBillingGatheringInvoiceLines chains the current query on the "billing_gathering_invoice_lines" edge. +func (_q *BillingInvoiceSplitLineGroupQuery) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(billinginvoicesplitlinegroup.Table, billinginvoicesplitlinegroup.FieldID, selector), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesTable, billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QuerySubscription chains the current query on the "subscription" edge. func (_q *BillingInvoiceSplitLineGroupQuery) QuerySubscription() *SubscriptionQuery { query := (&SubscriptionClient{config: _q.config}).Query() @@ -368,16 +392,17 @@ func (_q *BillingInvoiceSplitLineGroupQuery) Clone() *BillingInvoiceSplitLineGro return nil } return &BillingInvoiceSplitLineGroupQuery{ - config: _q.config, - ctx: _q.ctx.Clone(), - order: append([]billinginvoicesplitlinegroup.OrderOption{}, _q.order...), - inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.BillingInvoiceSplitLineGroup{}, _q.predicates...), - withBillingInvoiceLines: _q.withBillingInvoiceLines.Clone(), - withSubscription: _q.withSubscription.Clone(), - withSubscriptionPhase: _q.withSubscriptionPhase.Clone(), - withSubscriptionItem: _q.withSubscriptionItem.Clone(), - withCharge: _q.withCharge.Clone(), + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]billinginvoicesplitlinegroup.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.BillingInvoiceSplitLineGroup{}, _q.predicates...), + withBillingInvoiceLines: _q.withBillingInvoiceLines.Clone(), + withBillingGatheringInvoiceLines: _q.withBillingGatheringInvoiceLines.Clone(), + withSubscription: _q.withSubscription.Clone(), + withSubscriptionPhase: _q.withSubscriptionPhase.Clone(), + withSubscriptionItem: _q.withSubscriptionItem.Clone(), + withCharge: _q.withCharge.Clone(), // clone intermediate query. sql: _q.sql.Clone(), path: _q.path, @@ -395,6 +420,17 @@ func (_q *BillingInvoiceSplitLineGroupQuery) WithBillingInvoiceLines(opts ...fun return _q } +// WithBillingGatheringInvoiceLines tells the query-builder to eager-load the nodes that are connected to +// the "billing_gathering_invoice_lines" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *BillingInvoiceSplitLineGroupQuery) WithBillingGatheringInvoiceLines(opts ...func(*BillingGatheringInvoiceLineQuery)) *BillingInvoiceSplitLineGroupQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withBillingGatheringInvoiceLines = query + return _q +} + // WithSubscription tells the query-builder to eager-load the nodes that are connected to // the "subscription" edge. The optional arguments are used to configure the query builder of the edge. func (_q *BillingInvoiceSplitLineGroupQuery) WithSubscription(opts ...func(*SubscriptionQuery)) *BillingInvoiceSplitLineGroupQuery { @@ -517,8 +553,9 @@ func (_q *BillingInvoiceSplitLineGroupQuery) sqlAll(ctx context.Context, hooks . var ( nodes = []*BillingInvoiceSplitLineGroup{} _spec = _q.querySpec() - loadedTypes = [5]bool{ + loadedTypes = [6]bool{ _q.withBillingInvoiceLines != nil, + _q.withBillingGatheringInvoiceLines != nil, _q.withSubscription != nil, _q.withSubscriptionPhase != nil, _q.withSubscriptionItem != nil, @@ -555,6 +592,17 @@ func (_q *BillingInvoiceSplitLineGroupQuery) sqlAll(ctx context.Context, hooks . return nil, err } } + if query := _q.withBillingGatheringInvoiceLines; query != nil { + if err := _q.loadBillingGatheringInvoiceLines(ctx, query, nodes, + func(n *BillingInvoiceSplitLineGroup) { + n.Edges.BillingGatheringInvoiceLines = []*BillingGatheringInvoiceLine{} + }, + func(n *BillingInvoiceSplitLineGroup, e *BillingGatheringInvoiceLine) { + n.Edges.BillingGatheringInvoiceLines = append(n.Edges.BillingGatheringInvoiceLines, e) + }); err != nil { + return nil, err + } + } if query := _q.withSubscription; query != nil { if err := _q.loadSubscription(ctx, query, nodes, nil, func(n *BillingInvoiceSplitLineGroup, e *Subscription) { n.Edges.Subscription = e }); err != nil { @@ -616,6 +664,39 @@ func (_q *BillingInvoiceSplitLineGroupQuery) loadBillingInvoiceLines(ctx context } return nil } +func (_q *BillingInvoiceSplitLineGroupQuery) loadBillingGatheringInvoiceLines(ctx context.Context, query *BillingGatheringInvoiceLineQuery, nodes []*BillingInvoiceSplitLineGroup, init func(*BillingInvoiceSplitLineGroup), assign func(*BillingInvoiceSplitLineGroup, *BillingGatheringInvoiceLine)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[string]*BillingInvoiceSplitLineGroup) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(billinggatheringinvoiceline.FieldSplitLineGroupID) + } + query.Where(predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.SplitLineGroupID + if fk == nil { + return fmt.Errorf(`foreign-key "split_line_group_id" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "split_line_group_id" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} func (_q *BillingInvoiceSplitLineGroupQuery) loadSubscription(ctx context.Context, query *SubscriptionQuery, nodes []*BillingInvoiceSplitLineGroup, init func(*BillingInvoiceSplitLineGroup), assign func(*BillingInvoiceSplitLineGroup, *Subscription)) error { ids := make([]string, 0, len(nodes)) nodeids := make(map[string][]*BillingInvoiceSplitLineGroup) diff --git a/openmeter/ent/db/billinginvoicesplitlinegroup_update.go b/openmeter/ent/db/billinginvoicesplitlinegroup_update.go index a45a4bae70..0368d63f97 100644 --- a/openmeter/ent/db/billinginvoicesplitlinegroup_update.go +++ b/openmeter/ent/db/billinginvoicesplitlinegroup_update.go @@ -12,6 +12,7 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/openmeterio/openmeter/openmeter/billing" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" @@ -218,6 +219,21 @@ func (_u *BillingInvoiceSplitLineGroupUpdate) AddBillingInvoiceLines(v ...*Billi return _u.AddBillingInvoiceLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *BillingInvoiceSplitLineGroupUpdate) AddBillingGatheringInvoiceLineIDs(ids ...string) *BillingInvoiceSplitLineGroupUpdate { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *BillingInvoiceSplitLineGroupUpdate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *BillingInvoiceSplitLineGroupUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // SetCharge sets the "charge" edge to the Charge entity. func (_u *BillingInvoiceSplitLineGroupUpdate) SetCharge(v *Charge) *BillingInvoiceSplitLineGroupUpdate { return _u.SetChargeID(v.ID) @@ -249,6 +265,27 @@ func (_u *BillingInvoiceSplitLineGroupUpdate) RemoveBillingInvoiceLines(v ...*Bi return _u.RemoveBillingInvoiceLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *BillingInvoiceSplitLineGroupUpdate) ClearBillingGatheringInvoiceLines() *BillingInvoiceSplitLineGroupUpdate { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *BillingInvoiceSplitLineGroupUpdate) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *BillingInvoiceSplitLineGroupUpdate { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *BillingInvoiceSplitLineGroupUpdate) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *BillingInvoiceSplitLineGroupUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearCharge clears the "charge" edge to the Charge entity. func (_u *BillingInvoiceSplitLineGroupUpdate) ClearCharge() *BillingInvoiceSplitLineGroupUpdate { _u.mutation.ClearCharge() @@ -403,6 +440,51 @@ func (_u *BillingInvoiceSplitLineGroupUpdate) sqlSave(ctx context.Context) (_nod } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.ChargeCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -639,6 +721,21 @@ func (_u *BillingInvoiceSplitLineGroupUpdateOne) AddBillingInvoiceLines(v ...*Bi return _u.AddBillingInvoiceLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *BillingInvoiceSplitLineGroupUpdateOne) AddBillingGatheringInvoiceLineIDs(ids ...string) *BillingInvoiceSplitLineGroupUpdateOne { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *BillingInvoiceSplitLineGroupUpdateOne) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *BillingInvoiceSplitLineGroupUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // SetCharge sets the "charge" edge to the Charge entity. func (_u *BillingInvoiceSplitLineGroupUpdateOne) SetCharge(v *Charge) *BillingInvoiceSplitLineGroupUpdateOne { return _u.SetChargeID(v.ID) @@ -670,6 +767,27 @@ func (_u *BillingInvoiceSplitLineGroupUpdateOne) RemoveBillingInvoiceLines(v ... return _u.RemoveBillingInvoiceLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *BillingInvoiceSplitLineGroupUpdateOne) ClearBillingGatheringInvoiceLines() *BillingInvoiceSplitLineGroupUpdateOne { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *BillingInvoiceSplitLineGroupUpdateOne) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *BillingInvoiceSplitLineGroupUpdateOne { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *BillingInvoiceSplitLineGroupUpdateOne) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *BillingInvoiceSplitLineGroupUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearCharge clears the "charge" edge to the Charge entity. func (_u *BillingInvoiceSplitLineGroupUpdateOne) ClearCharge() *BillingInvoiceSplitLineGroupUpdateOne { _u.mutation.ClearCharge() @@ -854,6 +972,51 @@ func (_u *BillingInvoiceSplitLineGroupUpdateOne) sqlSave(ctx context.Context) (_ } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesTable, + Columns: []string{billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.ChargeCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/openmeter/ent/db/charge.go b/openmeter/ent/db/charge.go index d8f9db58f9..759ca68752 100644 --- a/openmeter/ent/db/charge.go +++ b/openmeter/ent/db/charge.go @@ -53,13 +53,15 @@ type ChargeEdges struct { UsageBased *ChargeUsageBased `json:"usage_based,omitempty"` // BillingInvoiceLines holds the value of the billing_invoice_lines edge. BillingInvoiceLines []*BillingInvoiceLine `json:"billing_invoice_lines,omitempty"` + // BillingGatheringInvoiceLines holds the value of the billing_gathering_invoice_lines edge. + BillingGatheringInvoiceLines []*BillingGatheringInvoiceLine `json:"billing_gathering_invoice_lines,omitempty"` // BillingSplitLineGroups holds the value of the billing_split_line_groups edge. BillingSplitLineGroups []*BillingInvoiceSplitLineGroup `json:"billing_split_line_groups,omitempty"` // CreditRealizationLineages holds the value of the credit_realization_lineages edge. CreditRealizationLineages []*CreditRealizationLineage `json:"credit_realization_lineages,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [6]bool + loadedTypes [7]bool } // FlatFeeOrErr returns the FlatFee value or an error if the edge @@ -104,10 +106,19 @@ func (e ChargeEdges) BillingInvoiceLinesOrErr() ([]*BillingInvoiceLine, error) { return nil, &NotLoadedError{edge: "billing_invoice_lines"} } +// BillingGatheringInvoiceLinesOrErr returns the BillingGatheringInvoiceLines value or an error if the edge +// was not loaded in eager-loading. +func (e ChargeEdges) BillingGatheringInvoiceLinesOrErr() ([]*BillingGatheringInvoiceLine, error) { + if e.loadedTypes[4] { + return e.BillingGatheringInvoiceLines, nil + } + return nil, &NotLoadedError{edge: "billing_gathering_invoice_lines"} +} + // BillingSplitLineGroupsOrErr returns the BillingSplitLineGroups value or an error if the edge // was not loaded in eager-loading. func (e ChargeEdges) BillingSplitLineGroupsOrErr() ([]*BillingInvoiceSplitLineGroup, error) { - if e.loadedTypes[4] { + if e.loadedTypes[5] { return e.BillingSplitLineGroups, nil } return nil, &NotLoadedError{edge: "billing_split_line_groups"} @@ -116,7 +127,7 @@ func (e ChargeEdges) BillingSplitLineGroupsOrErr() ([]*BillingInvoiceSplitLineGr // CreditRealizationLineagesOrErr returns the CreditRealizationLineages value or an error if the edge // was not loaded in eager-loading. func (e ChargeEdges) CreditRealizationLineagesOrErr() ([]*CreditRealizationLineage, error) { - if e.loadedTypes[5] { + if e.loadedTypes[6] { return e.CreditRealizationLineages, nil } return nil, &NotLoadedError{edge: "credit_realization_lineages"} @@ -238,6 +249,11 @@ func (_m *Charge) QueryBillingInvoiceLines() *BillingInvoiceLineQuery { return NewChargeClient(_m.config).QueryBillingInvoiceLines(_m) } +// QueryBillingGatheringInvoiceLines queries the "billing_gathering_invoice_lines" edge of the Charge entity. +func (_m *Charge) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + return NewChargeClient(_m.config).QueryBillingGatheringInvoiceLines(_m) +} + // QueryBillingSplitLineGroups queries the "billing_split_line_groups" edge of the Charge entity. func (_m *Charge) QueryBillingSplitLineGroups() *BillingInvoiceSplitLineGroupQuery { return NewChargeClient(_m.config).QueryBillingSplitLineGroups(_m) diff --git a/openmeter/ent/db/charge/charge.go b/openmeter/ent/db/charge/charge.go index d17e43e076..afc1c2d50d 100644 --- a/openmeter/ent/db/charge/charge.go +++ b/openmeter/ent/db/charge/charge.go @@ -38,6 +38,8 @@ const ( EdgeUsageBased = "usage_based" // EdgeBillingInvoiceLines holds the string denoting the billing_invoice_lines edge name in mutations. EdgeBillingInvoiceLines = "billing_invoice_lines" + // EdgeBillingGatheringInvoiceLines holds the string denoting the billing_gathering_invoice_lines edge name in mutations. + EdgeBillingGatheringInvoiceLines = "billing_gathering_invoice_lines" // EdgeBillingSplitLineGroups holds the string denoting the billing_split_line_groups edge name in mutations. EdgeBillingSplitLineGroups = "billing_split_line_groups" // EdgeCreditRealizationLineages holds the string denoting the credit_realization_lineages edge name in mutations. @@ -72,6 +74,13 @@ const ( BillingInvoiceLinesInverseTable = "billing_invoice_lines" // BillingInvoiceLinesColumn is the table column denoting the billing_invoice_lines relation/edge. BillingInvoiceLinesColumn = "charge_id" + // BillingGatheringInvoiceLinesTable is the table that holds the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesInverseTable is the table name for the BillingGatheringInvoiceLine entity. + // It exists in this package in order to avoid circular dependency with the "billinggatheringinvoiceline" package. + BillingGatheringInvoiceLinesInverseTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesColumn is the table column denoting the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesColumn = "charge_id" // BillingSplitLineGroupsTable is the table that holds the billing_split_line_groups relation/edge. BillingSplitLineGroupsTable = "billing_invoice_split_line_groups" // BillingSplitLineGroupsInverseTable is the table name for the BillingInvoiceSplitLineGroup entity. @@ -205,6 +214,20 @@ func ByBillingInvoiceLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOpti } } +// ByBillingGatheringInvoiceLinesCount orders the results by billing_gathering_invoice_lines count. +func ByBillingGatheringInvoiceLinesCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newBillingGatheringInvoiceLinesStep(), opts...) + } +} + +// ByBillingGatheringInvoiceLines orders the results by billing_gathering_invoice_lines terms. +func ByBillingGatheringInvoiceLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newBillingGatheringInvoiceLinesStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + // ByBillingSplitLineGroupsCount orders the results by billing_split_line_groups count. func ByBillingSplitLineGroupsCount(opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -260,6 +283,13 @@ func newBillingInvoiceLinesStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, BillingInvoiceLinesTable, BillingInvoiceLinesColumn), ) } +func newBillingGatheringInvoiceLinesStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(BillingGatheringInvoiceLinesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) +} func newBillingSplitLineGroupsStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/openmeter/ent/db/charge/where.go b/openmeter/ent/db/charge/where.go index bef7849baa..f97a8eac99 100644 --- a/openmeter/ent/db/charge/where.go +++ b/openmeter/ent/db/charge/where.go @@ -738,6 +738,29 @@ func HasBillingInvoiceLinesWith(preds ...predicate.BillingInvoiceLine) predicate }) } +// HasBillingGatheringInvoiceLines applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge. +func HasBillingGatheringInvoiceLines() predicate.Charge { + return predicate.Charge(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasBillingGatheringInvoiceLinesWith applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge with a given conditions (other predicates). +func HasBillingGatheringInvoiceLinesWith(preds ...predicate.BillingGatheringInvoiceLine) predicate.Charge { + return predicate.Charge(func(s *sql.Selector) { + step := newBillingGatheringInvoiceLinesStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // HasBillingSplitLineGroups applies the HasEdge predicate on the "billing_split_line_groups" edge. func HasBillingSplitLineGroups() predicate.Charge { return predicate.Charge(func(s *sql.Selector) { diff --git a/openmeter/ent/db/charge_create.go b/openmeter/ent/db/charge_create.go index a698ec5666..4ad12d4fd3 100644 --- a/openmeter/ent/db/charge_create.go +++ b/openmeter/ent/db/charge_create.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" @@ -212,6 +213,21 @@ func (_c *ChargeCreate) AddBillingInvoiceLines(v ...*BillingInvoiceLine) *Charge return _c.AddBillingInvoiceLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_c *ChargeCreate) AddBillingGatheringInvoiceLineIDs(ids ...string) *ChargeCreate { + _c.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _c +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_c *ChargeCreate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *ChargeCreate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by IDs. func (_c *ChargeCreate) AddBillingSplitLineGroupIDs(ids ...string) *ChargeCreate { _c.mutation.AddBillingSplitLineGroupIDs(ids...) @@ -436,6 +452,22 @@ func (_c *ChargeCreate) createSpec() (*Charge, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: charge.BillingGatheringInvoiceLinesTable, + Columns: []string{charge.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.BillingSplitLineGroupsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/openmeter/ent/db/charge_query.go b/openmeter/ent/db/charge_query.go index 0596d13840..667c4f07c1 100644 --- a/openmeter/ent/db/charge_query.go +++ b/openmeter/ent/db/charge_query.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" @@ -26,17 +27,18 @@ import ( // ChargeQuery is the builder for querying Charge entities. type ChargeQuery struct { config - ctx *QueryContext - order []charge.OrderOption - inters []Interceptor - predicates []predicate.Charge - withFlatFee *ChargeFlatFeeQuery - withCreditPurchase *ChargeCreditPurchaseQuery - withUsageBased *ChargeUsageBasedQuery - withBillingInvoiceLines *BillingInvoiceLineQuery - withBillingSplitLineGroups *BillingInvoiceSplitLineGroupQuery - withCreditRealizationLineages *CreditRealizationLineageQuery - modifiers []func(*sql.Selector) + ctx *QueryContext + order []charge.OrderOption + inters []Interceptor + predicates []predicate.Charge + withFlatFee *ChargeFlatFeeQuery + withCreditPurchase *ChargeCreditPurchaseQuery + withUsageBased *ChargeUsageBasedQuery + withBillingInvoiceLines *BillingInvoiceLineQuery + withBillingGatheringInvoiceLines *BillingGatheringInvoiceLineQuery + withBillingSplitLineGroups *BillingInvoiceSplitLineGroupQuery + withCreditRealizationLineages *CreditRealizationLineageQuery + modifiers []func(*sql.Selector) // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -161,6 +163,28 @@ func (_q *ChargeQuery) QueryBillingInvoiceLines() *BillingInvoiceLineQuery { return query } +// QueryBillingGatheringInvoiceLines chains the current query on the "billing_gathering_invoice_lines" edge. +func (_q *ChargeQuery) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(charge.Table, charge.FieldID, selector), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, charge.BillingGatheringInvoiceLinesTable, charge.BillingGatheringInvoiceLinesColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryBillingSplitLineGroups chains the current query on the "billing_split_line_groups" edge. func (_q *ChargeQuery) QueryBillingSplitLineGroups() *BillingInvoiceSplitLineGroupQuery { query := (&BillingInvoiceSplitLineGroupClient{config: _q.config}).Query() @@ -392,17 +416,18 @@ func (_q *ChargeQuery) Clone() *ChargeQuery { return nil } return &ChargeQuery{ - config: _q.config, - ctx: _q.ctx.Clone(), - order: append([]charge.OrderOption{}, _q.order...), - inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.Charge{}, _q.predicates...), - withFlatFee: _q.withFlatFee.Clone(), - withCreditPurchase: _q.withCreditPurchase.Clone(), - withUsageBased: _q.withUsageBased.Clone(), - withBillingInvoiceLines: _q.withBillingInvoiceLines.Clone(), - withBillingSplitLineGroups: _q.withBillingSplitLineGroups.Clone(), - withCreditRealizationLineages: _q.withCreditRealizationLineages.Clone(), + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]charge.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.Charge{}, _q.predicates...), + withFlatFee: _q.withFlatFee.Clone(), + withCreditPurchase: _q.withCreditPurchase.Clone(), + withUsageBased: _q.withUsageBased.Clone(), + withBillingInvoiceLines: _q.withBillingInvoiceLines.Clone(), + withBillingGatheringInvoiceLines: _q.withBillingGatheringInvoiceLines.Clone(), + withBillingSplitLineGroups: _q.withBillingSplitLineGroups.Clone(), + withCreditRealizationLineages: _q.withCreditRealizationLineages.Clone(), // clone intermediate query. sql: _q.sql.Clone(), path: _q.path, @@ -453,6 +478,17 @@ func (_q *ChargeQuery) WithBillingInvoiceLines(opts ...func(*BillingInvoiceLineQ return _q } +// WithBillingGatheringInvoiceLines tells the query-builder to eager-load the nodes that are connected to +// the "billing_gathering_invoice_lines" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeQuery) WithBillingGatheringInvoiceLines(opts ...func(*BillingGatheringInvoiceLineQuery)) *ChargeQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withBillingGatheringInvoiceLines = query + return _q +} + // WithBillingSplitLineGroups tells the query-builder to eager-load the nodes that are connected to // the "billing_split_line_groups" edge. The optional arguments are used to configure the query builder of the edge. func (_q *ChargeQuery) WithBillingSplitLineGroups(opts ...func(*BillingInvoiceSplitLineGroupQuery)) *ChargeQuery { @@ -553,11 +589,12 @@ func (_q *ChargeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Charg var ( nodes = []*Charge{} _spec = _q.querySpec() - loadedTypes = [6]bool{ + loadedTypes = [7]bool{ _q.withFlatFee != nil, _q.withCreditPurchase != nil, _q.withUsageBased != nil, _q.withBillingInvoiceLines != nil, + _q.withBillingGatheringInvoiceLines != nil, _q.withBillingSplitLineGroups != nil, _q.withCreditRealizationLineages != nil, } @@ -610,6 +647,15 @@ func (_q *ChargeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Charg return nil, err } } + if query := _q.withBillingGatheringInvoiceLines; query != nil { + if err := _q.loadBillingGatheringInvoiceLines(ctx, query, nodes, + func(n *Charge) { n.Edges.BillingGatheringInvoiceLines = []*BillingGatheringInvoiceLine{} }, + func(n *Charge, e *BillingGatheringInvoiceLine) { + n.Edges.BillingGatheringInvoiceLines = append(n.Edges.BillingGatheringInvoiceLines, e) + }); err != nil { + return nil, err + } + } if query := _q.withBillingSplitLineGroups; query != nil { if err := _q.loadBillingSplitLineGroups(ctx, query, nodes, func(n *Charge) { n.Edges.BillingSplitLineGroups = []*BillingInvoiceSplitLineGroup{} }, @@ -761,6 +807,39 @@ func (_q *ChargeQuery) loadBillingInvoiceLines(ctx context.Context, query *Billi } return nil } +func (_q *ChargeQuery) loadBillingGatheringInvoiceLines(ctx context.Context, query *BillingGatheringInvoiceLineQuery, nodes []*Charge, init func(*Charge), assign func(*Charge, *BillingGatheringInvoiceLine)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[string]*Charge) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(billinggatheringinvoiceline.FieldChargeID) + } + query.Where(predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(charge.BillingGatheringInvoiceLinesColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.ChargeID + if fk == nil { + return fmt.Errorf(`foreign-key "charge_id" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "charge_id" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} func (_q *ChargeQuery) loadBillingSplitLineGroups(ctx context.Context, query *BillingInvoiceSplitLineGroupQuery, nodes []*Charge, init func(*Charge), assign func(*Charge, *BillingInvoiceSplitLineGroup)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[string]*Charge) diff --git a/openmeter/ent/db/charge_update.go b/openmeter/ent/db/charge_update.go index b3efd1752d..7219b34e69 100644 --- a/openmeter/ent/db/charge_update.go +++ b/openmeter/ent/db/charge_update.go @@ -11,6 +11,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" @@ -66,6 +67,21 @@ func (_u *ChargeUpdate) AddBillingInvoiceLines(v ...*BillingInvoiceLine) *Charge return _u.AddBillingInvoiceLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *ChargeUpdate) AddBillingGatheringInvoiceLineIDs(ids ...string) *ChargeUpdate { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *ChargeUpdate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *ChargeUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by IDs. func (_u *ChargeUpdate) AddBillingSplitLineGroupIDs(ids ...string) *ChargeUpdate { _u.mutation.AddBillingSplitLineGroupIDs(ids...) @@ -122,6 +138,27 @@ func (_u *ChargeUpdate) RemoveBillingInvoiceLines(v ...*BillingInvoiceLine) *Cha return _u.RemoveBillingInvoiceLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *ChargeUpdate) ClearBillingGatheringInvoiceLines() *ChargeUpdate { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *ChargeUpdate) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *ChargeUpdate { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *ChargeUpdate) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *ChargeUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearBillingSplitLineGroups clears all "billing_split_line_groups" edges to the BillingInvoiceSplitLineGroup entity. func (_u *ChargeUpdate) ClearBillingSplitLineGroups() *ChargeUpdate { _u.mutation.ClearBillingSplitLineGroups() @@ -254,6 +291,51 @@ func (_u *ChargeUpdate) sqlSave(ctx context.Context) (_node int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: charge.BillingGatheringInvoiceLinesTable, + Columns: []string{charge.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: charge.BillingGatheringInvoiceLinesTable, + Columns: []string{charge.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: charge.BillingGatheringInvoiceLinesTable, + Columns: []string{charge.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.BillingSplitLineGroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -399,6 +481,21 @@ func (_u *ChargeUpdateOne) AddBillingInvoiceLines(v ...*BillingInvoiceLine) *Cha return _u.AddBillingInvoiceLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *ChargeUpdateOne) AddBillingGatheringInvoiceLineIDs(ids ...string) *ChargeUpdateOne { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *ChargeUpdateOne) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *ChargeUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by IDs. func (_u *ChargeUpdateOne) AddBillingSplitLineGroupIDs(ids ...string) *ChargeUpdateOne { _u.mutation.AddBillingSplitLineGroupIDs(ids...) @@ -455,6 +552,27 @@ func (_u *ChargeUpdateOne) RemoveBillingInvoiceLines(v ...*BillingInvoiceLine) * return _u.RemoveBillingInvoiceLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *ChargeUpdateOne) ClearBillingGatheringInvoiceLines() *ChargeUpdateOne { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *ChargeUpdateOne) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *ChargeUpdateOne { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *ChargeUpdateOne) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *ChargeUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearBillingSplitLineGroups clears all "billing_split_line_groups" edges to the BillingInvoiceSplitLineGroup entity. func (_u *ChargeUpdateOne) ClearBillingSplitLineGroups() *ChargeUpdateOne { _u.mutation.ClearBillingSplitLineGroups() @@ -617,6 +735,51 @@ func (_u *ChargeUpdateOne) sqlSave(ctx context.Context) (_node *Charge, err erro } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: charge.BillingGatheringInvoiceLinesTable, + Columns: []string{charge.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: charge.BillingGatheringInvoiceLinesTable, + Columns: []string{charge.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: charge.BillingGatheringInvoiceLinesTable, + Columns: []string{charge.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.BillingSplitLineGroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/openmeter/ent/db/client.go b/openmeter/ent/db/client.go index 439611c943..c80cd085c1 100644 --- a/openmeter/ent/db/client.go +++ b/openmeter/ent/db/client.go @@ -26,6 +26,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/ent/db/balancesnapshot" "github.com/openmeterio/openmeter/openmeter/ent/db/billingcustomerlock" "github.com/openmeterio/openmeter/openmeter/ent/db/billingcustomeroverride" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceflatfeelineconfig" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" @@ -128,6 +129,8 @@ type Client struct { BillingCustomerLock *BillingCustomerLockClient // BillingCustomerOverride is the client for interacting with the BillingCustomerOverride builders. BillingCustomerOverride *BillingCustomerOverrideClient + // BillingGatheringInvoiceLine is the client for interacting with the BillingGatheringInvoiceLine builders. + BillingGatheringInvoiceLine *BillingGatheringInvoiceLineClient // BillingInvoice is the client for interacting with the BillingInvoice builders. BillingInvoice *BillingInvoiceClient // BillingInvoiceFlatFeeLineConfig is the client for interacting with the BillingInvoiceFlatFeeLineConfig builders. @@ -294,6 +297,7 @@ func (c *Client) init() { c.BalanceSnapshot = NewBalanceSnapshotClient(c.config) c.BillingCustomerLock = NewBillingCustomerLockClient(c.config) c.BillingCustomerOverride = NewBillingCustomerOverrideClient(c.config) + c.BillingGatheringInvoiceLine = NewBillingGatheringInvoiceLineClient(c.config) c.BillingInvoice = NewBillingInvoiceClient(c.config) c.BillingInvoiceFlatFeeLineConfig = NewBillingInvoiceFlatFeeLineConfigClient(c.config) c.BillingInvoiceLine = NewBillingInvoiceLineClient(c.config) @@ -469,6 +473,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { BalanceSnapshot: NewBalanceSnapshotClient(cfg), BillingCustomerLock: NewBillingCustomerLockClient(cfg), BillingCustomerOverride: NewBillingCustomerOverrideClient(cfg), + BillingGatheringInvoiceLine: NewBillingGatheringInvoiceLineClient(cfg), BillingInvoice: NewBillingInvoiceClient(cfg), BillingInvoiceFlatFeeLineConfig: NewBillingInvoiceFlatFeeLineConfigClient(cfg), BillingInvoiceLine: NewBillingInvoiceLineClient(cfg), @@ -571,6 +576,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) BalanceSnapshot: NewBalanceSnapshotClient(cfg), BillingCustomerLock: NewBillingCustomerLockClient(cfg), BillingCustomerOverride: NewBillingCustomerOverrideClient(cfg), + BillingGatheringInvoiceLine: NewBillingGatheringInvoiceLineClient(cfg), BillingInvoice: NewBillingInvoiceClient(cfg), BillingInvoiceFlatFeeLineConfig: NewBillingInvoiceFlatFeeLineConfigClient(cfg), BillingInvoiceLine: NewBillingInvoiceLineClient(cfg), @@ -675,7 +681,8 @@ func (c *Client) Use(hooks ...Hook) { c.Addon, c.AddonRateCard, c.App, c.AppCustomInvoicing, c.AppCustomInvoicingCustomer, c.AppCustomer, c.AppStripe, c.AppStripeCustomer, c.BalanceSnapshot, c.BillingCustomerLock, c.BillingCustomerOverride, - c.BillingInvoice, c.BillingInvoiceFlatFeeLineConfig, c.BillingInvoiceLine, + c.BillingGatheringInvoiceLine, c.BillingInvoice, + c.BillingInvoiceFlatFeeLineConfig, c.BillingInvoiceLine, c.BillingInvoiceLineDiscount, c.BillingInvoiceLineUsageDiscount, c.BillingInvoiceSplitLineGroup, c.BillingInvoiceUsageBasedLineConfig, c.BillingInvoiceValidationIssue, c.BillingInvoiceWriteSchemaLevel, @@ -713,7 +720,8 @@ func (c *Client) Intercept(interceptors ...Interceptor) { c.Addon, c.AddonRateCard, c.App, c.AppCustomInvoicing, c.AppCustomInvoicingCustomer, c.AppCustomer, c.AppStripe, c.AppStripeCustomer, c.BalanceSnapshot, c.BillingCustomerLock, c.BillingCustomerOverride, - c.BillingInvoice, c.BillingInvoiceFlatFeeLineConfig, c.BillingInvoiceLine, + c.BillingGatheringInvoiceLine, c.BillingInvoice, + c.BillingInvoiceFlatFeeLineConfig, c.BillingInvoiceLine, c.BillingInvoiceLineDiscount, c.BillingInvoiceLineUsageDiscount, c.BillingInvoiceSplitLineGroup, c.BillingInvoiceUsageBasedLineConfig, c.BillingInvoiceValidationIssue, c.BillingInvoiceWriteSchemaLevel, @@ -769,6 +777,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.BillingCustomerLock.mutate(ctx, m) case *BillingCustomerOverrideMutation: return c.BillingCustomerOverride.mutate(ctx, m) + case *BillingGatheringInvoiceLineMutation: + return c.BillingGatheringInvoiceLine.mutate(ctx, m) case *BillingInvoiceMutation: return c.BillingInvoice.mutate(ctx, m) case *BillingInvoiceFlatFeeLineConfigMutation: @@ -2811,6 +2821,251 @@ func (c *BillingCustomerOverrideClient) mutate(ctx context.Context, m *BillingCu } } +// BillingGatheringInvoiceLineClient is a client for the BillingGatheringInvoiceLine schema. +type BillingGatheringInvoiceLineClient struct { + config +} + +// NewBillingGatheringInvoiceLineClient returns a client for the BillingGatheringInvoiceLine from the given config. +func NewBillingGatheringInvoiceLineClient(c config) *BillingGatheringInvoiceLineClient { + return &BillingGatheringInvoiceLineClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `billinggatheringinvoiceline.Hooks(f(g(h())))`. +func (c *BillingGatheringInvoiceLineClient) Use(hooks ...Hook) { + c.hooks.BillingGatheringInvoiceLine = append(c.hooks.BillingGatheringInvoiceLine, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `billinggatheringinvoiceline.Intercept(f(g(h())))`. +func (c *BillingGatheringInvoiceLineClient) Intercept(interceptors ...Interceptor) { + c.inters.BillingGatheringInvoiceLine = append(c.inters.BillingGatheringInvoiceLine, interceptors...) +} + +// Create returns a builder for creating a BillingGatheringInvoiceLine entity. +func (c *BillingGatheringInvoiceLineClient) Create() *BillingGatheringInvoiceLineCreate { + mutation := newBillingGatheringInvoiceLineMutation(c.config, OpCreate) + return &BillingGatheringInvoiceLineCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of BillingGatheringInvoiceLine entities. +func (c *BillingGatheringInvoiceLineClient) CreateBulk(builders ...*BillingGatheringInvoiceLineCreate) *BillingGatheringInvoiceLineCreateBulk { + return &BillingGatheringInvoiceLineCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *BillingGatheringInvoiceLineClient) MapCreateBulk(slice any, setFunc func(*BillingGatheringInvoiceLineCreate, int)) *BillingGatheringInvoiceLineCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &BillingGatheringInvoiceLineCreateBulk{err: fmt.Errorf("calling to BillingGatheringInvoiceLineClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*BillingGatheringInvoiceLineCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &BillingGatheringInvoiceLineCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for BillingGatheringInvoiceLine. +func (c *BillingGatheringInvoiceLineClient) Update() *BillingGatheringInvoiceLineUpdate { + mutation := newBillingGatheringInvoiceLineMutation(c.config, OpUpdate) + return &BillingGatheringInvoiceLineUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *BillingGatheringInvoiceLineClient) UpdateOne(_m *BillingGatheringInvoiceLine) *BillingGatheringInvoiceLineUpdateOne { + mutation := newBillingGatheringInvoiceLineMutation(c.config, OpUpdateOne, withBillingGatheringInvoiceLine(_m)) + return &BillingGatheringInvoiceLineUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *BillingGatheringInvoiceLineClient) UpdateOneID(id string) *BillingGatheringInvoiceLineUpdateOne { + mutation := newBillingGatheringInvoiceLineMutation(c.config, OpUpdateOne, withBillingGatheringInvoiceLineID(id)) + return &BillingGatheringInvoiceLineUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for BillingGatheringInvoiceLine. +func (c *BillingGatheringInvoiceLineClient) Delete() *BillingGatheringInvoiceLineDelete { + mutation := newBillingGatheringInvoiceLineMutation(c.config, OpDelete) + return &BillingGatheringInvoiceLineDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *BillingGatheringInvoiceLineClient) DeleteOne(_m *BillingGatheringInvoiceLine) *BillingGatheringInvoiceLineDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *BillingGatheringInvoiceLineClient) DeleteOneID(id string) *BillingGatheringInvoiceLineDeleteOne { + builder := c.Delete().Where(billinggatheringinvoiceline.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &BillingGatheringInvoiceLineDeleteOne{builder} +} + +// Query returns a query builder for BillingGatheringInvoiceLine. +func (c *BillingGatheringInvoiceLineClient) Query() *BillingGatheringInvoiceLineQuery { + return &BillingGatheringInvoiceLineQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeBillingGatheringInvoiceLine}, + inters: c.Interceptors(), + } +} + +// Get returns a BillingGatheringInvoiceLine entity by its id. +func (c *BillingGatheringInvoiceLineClient) Get(ctx context.Context, id string) (*BillingGatheringInvoiceLine, error) { + return c.Query().Where(billinggatheringinvoiceline.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *BillingGatheringInvoiceLineClient) GetX(ctx context.Context, id string) *BillingGatheringInvoiceLine { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryBillingInvoice queries the billing_invoice edge of a BillingGatheringInvoiceLine. +func (c *BillingGatheringInvoiceLineClient) QueryBillingInvoice(_m *BillingGatheringInvoiceLine) *BillingInvoiceQuery { + query := (&BillingInvoiceClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, id), + sqlgraph.To(billinginvoice.Table, billinginvoice.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.BillingInvoiceTable, billinggatheringinvoiceline.BillingInvoiceColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QuerySplitLineGroup queries the split_line_group edge of a BillingGatheringInvoiceLine. +func (c *BillingGatheringInvoiceLineClient) QuerySplitLineGroup(_m *BillingGatheringInvoiceLine) *BillingInvoiceSplitLineGroupQuery { + query := (&BillingInvoiceSplitLineGroupClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, id), + sqlgraph.To(billinginvoicesplitlinegroup.Table, billinginvoicesplitlinegroup.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.SplitLineGroupTable, billinggatheringinvoiceline.SplitLineGroupColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QuerySubscription queries the subscription edge of a BillingGatheringInvoiceLine. +func (c *BillingGatheringInvoiceLineClient) QuerySubscription(_m *BillingGatheringInvoiceLine) *SubscriptionQuery { + query := (&SubscriptionClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, id), + sqlgraph.To(subscription.Table, subscription.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.SubscriptionTable, billinggatheringinvoiceline.SubscriptionColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QuerySubscriptionPhase queries the subscription_phase edge of a BillingGatheringInvoiceLine. +func (c *BillingGatheringInvoiceLineClient) QuerySubscriptionPhase(_m *BillingGatheringInvoiceLine) *SubscriptionPhaseQuery { + query := (&SubscriptionPhaseClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, id), + sqlgraph.To(subscriptionphase.Table, subscriptionphase.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.SubscriptionPhaseTable, billinggatheringinvoiceline.SubscriptionPhaseColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QuerySubscriptionItem queries the subscription_item edge of a BillingGatheringInvoiceLine. +func (c *BillingGatheringInvoiceLineClient) QuerySubscriptionItem(_m *BillingGatheringInvoiceLine) *SubscriptionItemQuery { + query := (&SubscriptionItemClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, id), + sqlgraph.To(subscriptionitem.Table, subscriptionitem.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.SubscriptionItemTable, billinggatheringinvoiceline.SubscriptionItemColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryCharge queries the charge edge of a BillingGatheringInvoiceLine. +func (c *BillingGatheringInvoiceLineClient) QueryCharge(_m *BillingGatheringInvoiceLine) *ChargeQuery { + query := (&ChargeClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, id), + sqlgraph.To(charge.Table, charge.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.ChargeTable, billinggatheringinvoiceline.ChargeColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryTaxCode queries the tax_code edge of a BillingGatheringInvoiceLine. +func (c *BillingGatheringInvoiceLineClient) QueryTaxCode(_m *BillingGatheringInvoiceLine) *TaxCodeQuery { + query := (&TaxCodeClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID, id), + sqlgraph.To(dbtaxcode.Table, dbtaxcode.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, billinggatheringinvoiceline.TaxCodeTable, billinggatheringinvoiceline.TaxCodeColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *BillingGatheringInvoiceLineClient) Hooks() []Hook { + return c.hooks.BillingGatheringInvoiceLine +} + +// Interceptors returns the client interceptors. +func (c *BillingGatheringInvoiceLineClient) Interceptors() []Interceptor { + return c.inters.BillingGatheringInvoiceLine +} + +func (c *BillingGatheringInvoiceLineClient) mutate(ctx context.Context, m *BillingGatheringInvoiceLineMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&BillingGatheringInvoiceLineCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&BillingGatheringInvoiceLineUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&BillingGatheringInvoiceLineUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&BillingGatheringInvoiceLineDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown BillingGatheringInvoiceLine mutation op: %q", m.Op()) + } +} + // BillingInvoiceClient is a client for the BillingInvoice schema. type BillingInvoiceClient struct { config @@ -2967,6 +3222,22 @@ func (c *BillingInvoiceClient) QueryBillingInvoiceLines(_m *BillingInvoice) *Bil return query } +// QueryBillingGatheringInvoiceLines queries the billing_gathering_invoice_lines edge of a BillingInvoice. +func (c *BillingInvoiceClient) QueryBillingGatheringInvoiceLines(_m *BillingInvoice) *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(billinginvoice.Table, billinginvoice.FieldID, id), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, billinginvoice.BillingGatheringInvoiceLinesTable, billinginvoice.BillingGatheringInvoiceLinesColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryBillingInvoiceDetailedLines queries the billing_invoice_detailed_lines edge of a BillingInvoice. func (c *BillingInvoiceClient) QueryBillingInvoiceDetailedLines(_m *BillingInvoice) *BillingStandardInvoiceDetailedLineQuery { query := (&BillingStandardInvoiceDetailedLineClient{config: c.config}).Query() @@ -4112,6 +4383,22 @@ func (c *BillingInvoiceSplitLineGroupClient) QueryBillingInvoiceLines(_m *Billin return query } +// QueryBillingGatheringInvoiceLines queries the billing_gathering_invoice_lines edge of a BillingInvoiceSplitLineGroup. +func (c *BillingInvoiceSplitLineGroupClient) QueryBillingGatheringInvoiceLines(_m *BillingInvoiceSplitLineGroup) *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(billinginvoicesplitlinegroup.Table, billinginvoicesplitlinegroup.FieldID, id), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesTable, billinginvoicesplitlinegroup.BillingGatheringInvoiceLinesColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QuerySubscription queries the subscription edge of a BillingInvoiceSplitLineGroup. func (c *BillingInvoiceSplitLineGroupClient) QuerySubscription(_m *BillingInvoiceSplitLineGroup) *SubscriptionQuery { query := (&SubscriptionClient{config: c.config}).Query() @@ -5661,6 +5948,22 @@ func (c *ChargeClient) QueryBillingInvoiceLines(_m *Charge) *BillingInvoiceLineQ return query } +// QueryBillingGatheringInvoiceLines queries the billing_gathering_invoice_lines edge of a Charge. +func (c *ChargeClient) QueryBillingGatheringInvoiceLines(_m *Charge) *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(charge.Table, charge.FieldID, id), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, charge.BillingGatheringInvoiceLinesTable, charge.BillingGatheringInvoiceLinesColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryBillingSplitLineGroups queries the billing_split_line_groups edge of a Charge. func (c *ChargeClient) QueryBillingSplitLineGroups(_m *Charge) *BillingInvoiceSplitLineGroupQuery { query := (&BillingInvoiceSplitLineGroupClient{config: c.config}).Query() @@ -14704,6 +15007,22 @@ func (c *SubscriptionClient) QueryBillingLines(_m *Subscription) *BillingInvoice return query } +// QueryBillingGatheringInvoiceLines queries the billing_gathering_invoice_lines edge of a Subscription. +func (c *SubscriptionClient) QueryBillingGatheringInvoiceLines(_m *Subscription) *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(subscription.Table, subscription.FieldID, id), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, subscription.BillingGatheringInvoiceLinesTable, subscription.BillingGatheringInvoiceLinesColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryBillingSplitLineGroups queries the billing_split_line_groups edge of a Subscription. func (c *SubscriptionClient) QueryBillingSplitLineGroups(_m *Subscription) *BillingInvoiceSplitLineGroupQuery { query := (&BillingInvoiceSplitLineGroupClient{config: c.config}).Query() @@ -15460,6 +15779,22 @@ func (c *SubscriptionItemClient) QueryBillingLines(_m *SubscriptionItem) *Billin return query } +// QueryBillingGatheringInvoiceLines queries the billing_gathering_invoice_lines edge of a SubscriptionItem. +func (c *SubscriptionItemClient) QueryBillingGatheringInvoiceLines(_m *SubscriptionItem) *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(subscriptionitem.Table, subscriptionitem.FieldID, id), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, subscriptionitem.BillingGatheringInvoiceLinesTable, subscriptionitem.BillingGatheringInvoiceLinesColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryBillingSplitLineGroups queries the billing_split_line_groups edge of a SubscriptionItem. func (c *SubscriptionItemClient) QueryBillingSplitLineGroups(_m *SubscriptionItem) *BillingInvoiceSplitLineGroupQuery { query := (&BillingInvoiceSplitLineGroupClient{config: c.config}).Query() @@ -15721,6 +16056,22 @@ func (c *SubscriptionPhaseClient) QueryBillingLines(_m *SubscriptionPhase) *Bill return query } +// QueryBillingGatheringInvoiceLines queries the billing_gathering_invoice_lines edge of a SubscriptionPhase. +func (c *SubscriptionPhaseClient) QueryBillingGatheringInvoiceLines(_m *SubscriptionPhase) *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(subscriptionphase.Table, subscriptionphase.FieldID, id), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, subscriptionphase.BillingGatheringInvoiceLinesTable, subscriptionphase.BillingGatheringInvoiceLinesColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryBillingSplitLineGroups queries the billing_split_line_groups edge of a SubscriptionPhase. func (c *SubscriptionPhaseClient) QueryBillingSplitLineGroups(_m *SubscriptionPhase) *BillingInvoiceSplitLineGroupQuery { query := (&BillingInvoiceSplitLineGroupClient{config: c.config}).Query() @@ -15966,6 +16317,22 @@ func (c *TaxCodeClient) QueryBillingInvoiceLines(_m *TaxCode) *BillingInvoiceLin return query } +// QueryBillingGatheringInvoiceLines queries the billing_gathering_invoice_lines edge of a TaxCode. +func (c *TaxCodeClient) QueryBillingGatheringInvoiceLines(_m *TaxCode) *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(dbtaxcode.Table, dbtaxcode.FieldID, id), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, dbtaxcode.BillingGatheringInvoiceLinesTable, dbtaxcode.BillingGatheringInvoiceLinesColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QuerySubscriptionItems queries the subscription_items edge of a TaxCode. func (c *TaxCodeClient) QuerySubscriptionItems(_m *TaxCode) *SubscriptionItemQuery { query := (&SubscriptionItemClient{config: c.config}).Query() @@ -16305,8 +16672,8 @@ type ( hooks struct { Addon, AddonRateCard, App, AppCustomInvoicing, AppCustomInvoicingCustomer, AppCustomer, AppStripe, AppStripeCustomer, BalanceSnapshot, - BillingCustomerLock, BillingCustomerOverride, BillingInvoice, - BillingInvoiceFlatFeeLineConfig, BillingInvoiceLine, + BillingCustomerLock, BillingCustomerOverride, BillingGatheringInvoiceLine, + BillingInvoice, BillingInvoiceFlatFeeLineConfig, BillingInvoiceLine, BillingInvoiceLineDiscount, BillingInvoiceLineUsageDiscount, BillingInvoiceSplitLineGroup, BillingInvoiceUsageBasedLineConfig, BillingInvoiceValidationIssue, BillingInvoiceWriteSchemaLevel, BillingProfile, @@ -16333,8 +16700,8 @@ type ( inters struct { Addon, AddonRateCard, App, AppCustomInvoicing, AppCustomInvoicingCustomer, AppCustomer, AppStripe, AppStripeCustomer, BalanceSnapshot, - BillingCustomerLock, BillingCustomerOverride, BillingInvoice, - BillingInvoiceFlatFeeLineConfig, BillingInvoiceLine, + BillingCustomerLock, BillingCustomerOverride, BillingGatheringInvoiceLine, + BillingInvoice, BillingInvoiceFlatFeeLineConfig, BillingInvoiceLine, BillingInvoiceLineDiscount, BillingInvoiceLineUsageDiscount, BillingInvoiceSplitLineGroup, BillingInvoiceUsageBasedLineConfig, BillingInvoiceValidationIssue, BillingInvoiceWriteSchemaLevel, BillingProfile, diff --git a/openmeter/ent/db/cursor.go b/openmeter/ent/db/cursor.go index b06c64cd14..a4e7145586 100644 --- a/openmeter/ent/db/cursor.go +++ b/openmeter/ent/db/cursor.go @@ -521,6 +521,57 @@ func (_m *BillingCustomerOverrideQuery) Cursor(ctx context.Context, cursor *pagi return result, nil } +// Cursor runs the query and returns a cursor-paginated response. +// Ordering is always by created_at asc, id asc. +func (_m *BillingGatheringInvoiceLineQuery) Cursor(ctx context.Context, cursor *pagination.Cursor) (pagination.Result[*BillingGatheringInvoiceLine], error) { + if cursor != nil { + if err := cursor.Validate(); err != nil { + return pagination.Result[*BillingGatheringInvoiceLine]{}, fmt.Errorf("invalid cursor: %w", err) + } + + _m.Where(func(s *sql.Selector) { + s.Where( + sql.Or( + sql.GT(s.C("created_at"), cursor.Time), + sql.And( + sql.EQ(s.C("created_at"), cursor.Time), + sql.P(func(b *sql.Builder) { + b.WriteString("CAST(") + b.WriteString(s.C("id")) + b.WriteString(" AS TEXT) > ") + b.Args(cursor.ID) + }), + ), + ), + ) + }) + } + + _m.Order(func(s *sql.Selector) { + s.OrderBy(sql.Asc(s.C("created_at")), sql.Asc(s.C("id"))) + }) + + items, err := _m.All(ctx) + if err != nil { + return pagination.Result[*BillingGatheringInvoiceLine]{}, err + } + + if items == nil { + items = make([]*BillingGatheringInvoiceLine, 0) + } + + result := pagination.Result[*BillingGatheringInvoiceLine]{ + Items: items, + } + + if len(items) > 0 { + last := items[len(items)-1] + result.NextCursor = lo.ToPtr(pagination.NewCursor(last.CreatedAt, fmt.Sprint(last.ID))) + } + + return result, nil +} + // Cursor runs the query and returns a cursor-paginated response. // Ordering is always by created_at asc, id asc. func (_m *BillingInvoiceQuery) Cursor(ctx context.Context, cursor *pagination.Cursor) (pagination.Result[*BillingInvoice], error) { diff --git a/openmeter/ent/db/ent.go b/openmeter/ent/db/ent.go index 43d484e43c..72c7b11c54 100644 --- a/openmeter/ent/db/ent.go +++ b/openmeter/ent/db/ent.go @@ -24,6 +24,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/ent/db/balancesnapshot" "github.com/openmeterio/openmeter/openmeter/ent/db/billingcustomerlock" "github.com/openmeterio/openmeter/openmeter/ent/db/billingcustomeroverride" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceflatfeelineconfig" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" @@ -171,6 +172,7 @@ func checkColumn(t, c string) error { balancesnapshot.Table: balancesnapshot.ValidColumn, billingcustomerlock.Table: billingcustomerlock.ValidColumn, billingcustomeroverride.Table: billingcustomeroverride.ValidColumn, + billinggatheringinvoiceline.Table: billinggatheringinvoiceline.ValidColumn, billinginvoice.Table: billinginvoice.ValidColumn, billinginvoiceflatfeelineconfig.Table: billinginvoiceflatfeelineconfig.ValidColumn, billinginvoiceline.Table: billinginvoiceline.ValidColumn, diff --git a/openmeter/ent/db/entmixinaccessor.go b/openmeter/ent/db/entmixinaccessor.go index 63c874edf9..1b5b7f0772 100644 --- a/openmeter/ent/db/entmixinaccessor.go +++ b/openmeter/ent/db/entmixinaccessor.go @@ -273,6 +273,110 @@ func (e *BillingCustomerOverride) GetTaxBehavior() *productcatalog.TaxBehavior { return e.TaxBehavior } +func (e *BillingGatheringInvoiceLine) GetID() string { + return e.ID +} + +func (e *BillingGatheringInvoiceLine) GetAnnotations() models.Annotations { + return e.Annotations +} + +func (e *BillingGatheringInvoiceLine) GetNamespace() string { + return e.Namespace +} + +func (e *BillingGatheringInvoiceLine) GetMetadata() map[string]string { + return e.Metadata +} + +func (e *BillingGatheringInvoiceLine) GetCreatedAt() time.Time { + return e.CreatedAt +} + +func (e *BillingGatheringInvoiceLine) GetUpdatedAt() time.Time { + return e.UpdatedAt +} + +func (e *BillingGatheringInvoiceLine) GetDeletedAt() *time.Time { + return e.DeletedAt +} + +func (e *BillingGatheringInvoiceLine) GetName() string { + return e.Name +} + +func (e *BillingGatheringInvoiceLine) GetDescription() *string { + return e.Description +} + +func (e *BillingGatheringInvoiceLine) GetCurrency() currencyx.Code { + return e.Currency +} + +func (e *BillingGatheringInvoiceLine) GetServicePeriodStart() time.Time { + return e.ServicePeriodStart +} + +func (e *BillingGatheringInvoiceLine) GetServicePeriodEnd() time.Time { + return e.ServicePeriodEnd +} + +func (e *BillingGatheringInvoiceLine) GetTaxConfig() billing.TaxConfig { + return e.TaxConfig +} + +func (e *BillingGatheringInvoiceLine) GetPriceType() productcatalog.PriceType { + return e.PriceType +} + +func (e *BillingGatheringInvoiceLine) GetFeatureKey() *string { + return e.FeatureKey +} + +func (e *BillingGatheringInvoiceLine) GetPrice() *productcatalog.Price { + return e.Price +} + +func (e *BillingGatheringInvoiceLine) GetUnitConfig() *productcatalog.UnitConfig { + return e.UnitConfig +} + +func (e *BillingGatheringInvoiceLine) GetRatecardDiscounts() *billing.Discounts { + return e.RatecardDiscounts +} + +func (e *BillingGatheringInvoiceLine) GetChildUniqueReferenceID() *string { + return e.ChildUniqueReferenceID +} + +func (e *BillingGatheringInvoiceLine) GetSubscriptionID() *string { + return e.SubscriptionID +} + +func (e *BillingGatheringInvoiceLine) GetSubscriptionPhaseID() *string { + return e.SubscriptionPhaseID +} + +func (e *BillingGatheringInvoiceLine) GetSubscriptionItemID() *string { + return e.SubscriptionItemID +} + +func (e *BillingGatheringInvoiceLine) GetSubscriptionBillingPeriodFrom() *time.Time { + return e.SubscriptionBillingPeriodFrom +} + +func (e *BillingGatheringInvoiceLine) GetSubscriptionBillingPeriodTo() *time.Time { + return e.SubscriptionBillingPeriodTo +} + +func (e *BillingGatheringInvoiceLine) GetTaxCodeID() *string { + return e.TaxCodeID +} + +func (e *BillingGatheringInvoiceLine) GetTaxBehavior() *productcatalog.TaxBehavior { + return e.TaxBehavior +} + func (e *BillingInvoice) GetID() string { return e.ID } diff --git a/openmeter/ent/db/expose.go b/openmeter/ent/db/expose.go index a3d2ce4046..08ca187a4b 100644 --- a/openmeter/ent/db/expose.go +++ b/openmeter/ent/db/expose.go @@ -111,6 +111,8 @@ func NewTxClientFromRawConfig(ctx context.Context, cfg entutils.RawEntConfig) *T BillingCustomerOverride: NewBillingCustomerOverrideClient(config), + BillingGatheringInvoiceLine: NewBillingGatheringInvoiceLineClient(config), + BillingInvoice: NewBillingInvoiceClient(config), BillingInvoiceFlatFeeLineConfig: NewBillingInvoiceFlatFeeLineConfigClient(config), diff --git a/openmeter/ent/db/hook/hook.go b/openmeter/ent/db/hook/hook.go index f93c242cc1..77aa9eaafc 100644 --- a/openmeter/ent/db/hook/hook.go +++ b/openmeter/ent/db/hook/hook.go @@ -141,6 +141,18 @@ func (f BillingCustomerOverrideFunc) Mutate(ctx context.Context, m db.Mutation) return nil, fmt.Errorf("unexpected mutation type %T. expect *db.BillingCustomerOverrideMutation", m) } +// The BillingGatheringInvoiceLineFunc type is an adapter to allow the use of ordinary +// function as BillingGatheringInvoiceLine mutator. +type BillingGatheringInvoiceLineFunc func(context.Context, *db.BillingGatheringInvoiceLineMutation) (db.Value, error) + +// Mutate calls f(ctx, m). +func (f BillingGatheringInvoiceLineFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { + if mv, ok := m.(*db.BillingGatheringInvoiceLineMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.BillingGatheringInvoiceLineMutation", m) +} + // The BillingInvoiceFunc type is an adapter to allow the use of ordinary // function as BillingInvoice mutator. type BillingInvoiceFunc func(context.Context, *db.BillingInvoiceMutation) (db.Value, error) diff --git a/openmeter/ent/db/migrate/schema.go b/openmeter/ent/db/migrate/schema.go index 8427239fe5..1ffabf6577 100644 --- a/openmeter/ent/db/migrate/schema.go +++ b/openmeter/ent/db/migrate/schema.go @@ -588,6 +588,151 @@ var ( }, }, } + // BillingGatheringInvoiceLinesColumns holds the columns for the "billing_gathering_invoice_lines" table. + BillingGatheringInvoiceLinesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeString, Unique: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "annotations", Type: field.TypeJSON, Nullable: true, SchemaType: map[string]string{"postgres": "jsonb"}}, + {Name: "namespace", Type: field.TypeString}, + {Name: "metadata", Type: field.TypeJSON, Nullable: true, SchemaType: map[string]string{"postgres": "jsonb"}}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "deleted_at", Type: field.TypeTime, Nullable: true}, + {Name: "name", Type: field.TypeString}, + {Name: "description", Type: field.TypeString, Nullable: true}, + {Name: "currency", Type: field.TypeString, SchemaType: map[string]string{"postgres": "varchar(3)"}}, + {Name: "service_period_start", Type: field.TypeTime}, + {Name: "service_period_end", Type: field.TypeTime}, + {Name: "tax_config", Type: field.TypeJSON, Nullable: true, SchemaType: map[string]string{"postgres": "jsonb"}}, + {Name: "price_type", Type: field.TypeEnum, Enums: []string{"flat", "unit", "tiered", "dynamic", "package"}}, + {Name: "feature_key", Type: field.TypeString, Nullable: true}, + {Name: "price", Type: field.TypeString, SchemaType: map[string]string{"postgres": "jsonb"}}, + {Name: "unit_config", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "jsonb"}}, + {Name: "ratecard_discounts", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "jsonb"}}, + {Name: "child_unique_reference_id", Type: field.TypeString, Nullable: true}, + {Name: "subscription_billing_period_from", Type: field.TypeTime, Nullable: true}, + {Name: "subscription_billing_period_to", Type: field.TypeTime, Nullable: true}, + {Name: "tax_behavior", Type: field.TypeEnum, Nullable: true, Enums: []string{"inclusive", "exclusive"}}, + {Name: "invoice_at", Type: field.TypeTime}, + {Name: "managed_by", Type: field.TypeEnum, Enums: []string{"subscription", "system", "manual"}}, + {Name: "engine", Type: field.TypeEnum, Enums: []string{"invoicing", "charge_flatfee", "charge_usagebased", "charge_creditpurchase"}, Default: "invoicing"}, + {Name: "invoice_id", Type: field.TypeString, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "split_line_group_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "charge_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "subscription_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "subscription_item_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "subscription_phase_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "tax_code_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + } + // BillingGatheringInvoiceLinesTable holds the schema information for the "billing_gathering_invoice_lines" table. + BillingGatheringInvoiceLinesTable = &schema.Table{ + Name: "billing_gathering_invoice_lines", + Columns: BillingGatheringInvoiceLinesColumns, + PrimaryKey: []*schema.Column{BillingGatheringInvoiceLinesColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "billing_gathering_line_invoice_fk", + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[25]}, + RefColumns: []*schema.Column{BillingInvoicesColumns[0]}, + OnDelete: schema.Cascade, + }, + { + Symbol: "billing_gathering_line_split_group_fk", + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[26]}, + RefColumns: []*schema.Column{BillingInvoiceSplitLineGroupsColumns[0]}, + OnDelete: schema.SetNull, + }, + { + Symbol: "billing_gathering_line_charge_fk", + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[27]}, + RefColumns: []*schema.Column{ChargesColumns[0]}, + OnDelete: schema.SetNull, + }, + { + Symbol: "billing_gathering_line_subscription_fk", + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[28]}, + RefColumns: []*schema.Column{SubscriptionsColumns[0]}, + OnDelete: schema.SetNull, + }, + { + Symbol: "billing_gathering_line_subscription_item_fk", + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[29]}, + RefColumns: []*schema.Column{SubscriptionItemsColumns[0]}, + OnDelete: schema.SetNull, + }, + { + Symbol: "billing_gathering_line_subscription_phase_fk", + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[30]}, + RefColumns: []*schema.Column{SubscriptionPhasesColumns[0]}, + OnDelete: schema.SetNull, + }, + { + Symbol: "billing_gathering_line_tax_code_fk", + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[31]}, + RefColumns: []*schema.Column{TaxCodesColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + Indexes: []*schema.Index{ + { + Name: "billinggatheringinvoiceline_annotations", + Unique: false, + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[1]}, + Annotation: &entsql.IndexAnnotation{ + Types: map[string]string{ + "postgres": "GIN", + }, + }, + }, + { + Name: "billinggatheringinvoiceline_id", + Unique: true, + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[0]}, + }, + { + Name: "billinggatheringinvoiceline_namespace", + Unique: false, + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[2]}, + }, + { + Name: "billinggatheringinvoiceline_namespace_id", + Unique: true, + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[2], BillingGatheringInvoiceLinesColumns[0]}, + }, + { + Name: "billinggatheringinvoiceline_tax_code_id", + Unique: false, + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[31]}, + }, + { + Name: "billinggatheringinvoiceline_namespace_invoice_id", + Unique: false, + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[2], BillingGatheringInvoiceLinesColumns[25]}, + }, + { + Name: "billinggatheringinvoiceline_namespace_split_line_group_id", + Unique: false, + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[2], BillingGatheringInvoiceLinesColumns[26]}, + }, + { + Name: "billinggatheringinvoiceline_namespace_charge_id", + Unique: false, + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[2], BillingGatheringInvoiceLinesColumns[27]}, + }, + { + Name: "billinggatheringline_ns_invoice_child_id", + Unique: true, + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[2], BillingGatheringInvoiceLinesColumns[25], BillingGatheringInvoiceLinesColumns[18]}, + Annotation: &entsql.IndexAnnotation{ + Where: "child_unique_reference_id IS NOT NULL AND deleted_at IS NULL", + }, + }, + { + Name: "billinggatheringline_ns_subscription_ref", + Unique: false, + Columns: []*schema.Column{BillingGatheringInvoiceLinesColumns[2], BillingGatheringInvoiceLinesColumns[28], BillingGatheringInvoiceLinesColumns[30], BillingGatheringInvoiceLinesColumns[29]}, + }, + }, + } // BillingInvoicesColumns holds the columns for the "billing_invoices" table. BillingInvoicesColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true, SchemaType: map[string]string{"postgres": "char(26)"}}, @@ -5440,6 +5585,7 @@ var ( BalanceSnapshotsTable, BillingCustomerLocksTable, BillingCustomerOverridesTable, + BillingGatheringInvoiceLinesTable, BillingInvoicesTable, BillingInvoiceFlatFeeLineConfigsTable, BillingInvoiceLinesTable, @@ -5532,6 +5678,13 @@ func init() { BillingCustomerOverridesTable.ForeignKeys[0].RefTable = BillingProfilesTable BillingCustomerOverridesTable.ForeignKeys[1].RefTable = CustomersTable BillingCustomerOverridesTable.ForeignKeys[2].RefTable = TaxCodesTable + BillingGatheringInvoiceLinesTable.ForeignKeys[0].RefTable = BillingInvoicesTable + BillingGatheringInvoiceLinesTable.ForeignKeys[1].RefTable = BillingInvoiceSplitLineGroupsTable + BillingGatheringInvoiceLinesTable.ForeignKeys[2].RefTable = ChargesTable + BillingGatheringInvoiceLinesTable.ForeignKeys[3].RefTable = SubscriptionsTable + BillingGatheringInvoiceLinesTable.ForeignKeys[4].RefTable = SubscriptionItemsTable + BillingGatheringInvoiceLinesTable.ForeignKeys[5].RefTable = SubscriptionPhasesTable + BillingGatheringInvoiceLinesTable.ForeignKeys[6].RefTable = TaxCodesTable BillingInvoicesTable.ForeignKeys[0].RefTable = AppsTable BillingInvoicesTable.ForeignKeys[1].RefTable = AppsTable BillingInvoicesTable.ForeignKeys[2].RefTable = AppsTable diff --git a/openmeter/ent/db/mutation.go b/openmeter/ent/db/mutation.go index e8cecd860f..bd3cd48f27 100644 --- a/openmeter/ent/db/mutation.go +++ b/openmeter/ent/db/mutation.go @@ -36,6 +36,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/ent/db/balancesnapshot" "github.com/openmeterio/openmeter/openmeter/ent/db/billingcustomerlock" "github.com/openmeterio/openmeter/openmeter/ent/db/billingcustomeroverride" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceflatfeelineconfig" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" @@ -140,6 +141,7 @@ const ( TypeBalanceSnapshot = "BalanceSnapshot" TypeBillingCustomerLock = "BillingCustomerLock" TypeBillingCustomerOverride = "BillingCustomerOverride" + TypeBillingGatheringInvoiceLine = "BillingGatheringInvoiceLine" TypeBillingInvoice = "BillingInvoice" TypeBillingInvoiceFlatFeeLineConfig = "BillingInvoiceFlatFeeLineConfig" TypeBillingInvoiceLine = "BillingInvoiceLine" @@ -11957,6 +11959,2646 @@ func (m *BillingCustomerOverrideMutation) ResetEdge(name string) error { return fmt.Errorf("unknown BillingCustomerOverride edge %s", name) } +// BillingGatheringInvoiceLineMutation represents an operation that mutates the BillingGatheringInvoiceLine nodes in the graph. +type BillingGatheringInvoiceLineMutation struct { + config + op Op + typ string + id *string + annotations *models.Annotations + namespace *string + metadata *map[string]string + created_at *time.Time + updated_at *time.Time + deleted_at *time.Time + name *string + description *string + currency *currencyx.Code + service_period_start *time.Time + service_period_end *time.Time + tax_config *billing.TaxConfig + price_type *productcatalog.PriceType + feature_key *string + price **productcatalog.Price + unit_config **productcatalog.UnitConfig + ratecard_discounts **billing.Discounts + child_unique_reference_id *string + subscription_billing_period_from *time.Time + subscription_billing_period_to *time.Time + tax_behavior *productcatalog.TaxBehavior + invoice_at *time.Time + managed_by *billing.InvoiceLineManagedBy + engine *billing.LineEngineType + clearedFields map[string]struct{} + billing_invoice *string + clearedbilling_invoice bool + split_line_group *string + clearedsplit_line_group bool + subscription *string + clearedsubscription bool + subscription_phase *string + clearedsubscription_phase bool + subscription_item *string + clearedsubscription_item bool + charge *string + clearedcharge bool + tax_code *string + clearedtax_code bool + done bool + oldValue func(context.Context) (*BillingGatheringInvoiceLine, error) + predicates []predicate.BillingGatheringInvoiceLine +} + +var _ ent.Mutation = (*BillingGatheringInvoiceLineMutation)(nil) + +// billinggatheringinvoicelineOption allows management of the mutation configuration using functional options. +type billinggatheringinvoicelineOption func(*BillingGatheringInvoiceLineMutation) + +// newBillingGatheringInvoiceLineMutation creates new mutation for the BillingGatheringInvoiceLine entity. +func newBillingGatheringInvoiceLineMutation(c config, op Op, opts ...billinggatheringinvoicelineOption) *BillingGatheringInvoiceLineMutation { + m := &BillingGatheringInvoiceLineMutation{ + config: c, + op: op, + typ: TypeBillingGatheringInvoiceLine, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withBillingGatheringInvoiceLineID sets the ID field of the mutation. +func withBillingGatheringInvoiceLineID(id string) billinggatheringinvoicelineOption { + return func(m *BillingGatheringInvoiceLineMutation) { + var ( + err error + once sync.Once + value *BillingGatheringInvoiceLine + ) + m.oldValue = func(ctx context.Context) (*BillingGatheringInvoiceLine, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().BillingGatheringInvoiceLine.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withBillingGatheringInvoiceLine sets the old BillingGatheringInvoiceLine of the mutation. +func withBillingGatheringInvoiceLine(node *BillingGatheringInvoiceLine) billinggatheringinvoicelineOption { + return func(m *BillingGatheringInvoiceLineMutation) { + m.oldValue = func(context.Context) (*BillingGatheringInvoiceLine, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m BillingGatheringInvoiceLineMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m BillingGatheringInvoiceLineMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("db: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of BillingGatheringInvoiceLine entities. +func (m *BillingGatheringInvoiceLineMutation) SetID(id string) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *BillingGatheringInvoiceLineMutation) ID() (id string, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *BillingGatheringInvoiceLineMutation) IDs(ctx context.Context) ([]string, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []string{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().BillingGatheringInvoiceLine.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetAnnotations sets the "annotations" field. +func (m *BillingGatheringInvoiceLineMutation) SetAnnotations(value models.Annotations) { + m.annotations = &value +} + +// Annotations returns the value of the "annotations" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) Annotations() (r models.Annotations, exists bool) { + v := m.annotations + if v == nil { + return + } + return *v, true +} + +// OldAnnotations returns the old "annotations" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldAnnotations(ctx context.Context) (v models.Annotations, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAnnotations is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAnnotations requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAnnotations: %w", err) + } + return oldValue.Annotations, nil +} + +// ClearAnnotations clears the value of the "annotations" field. +func (m *BillingGatheringInvoiceLineMutation) ClearAnnotations() { + m.annotations = nil + m.clearedFields[billinggatheringinvoiceline.FieldAnnotations] = struct{}{} +} + +// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) AnnotationsCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldAnnotations] + return ok +} + +// ResetAnnotations resets all changes to the "annotations" field. +func (m *BillingGatheringInvoiceLineMutation) ResetAnnotations() { + m.annotations = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldAnnotations) +} + +// SetNamespace sets the "namespace" field. +func (m *BillingGatheringInvoiceLineMutation) SetNamespace(s string) { + m.namespace = &s +} + +// Namespace returns the value of the "namespace" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) Namespace() (r string, exists bool) { + v := m.namespace + if v == nil { + return + } + return *v, true +} + +// OldNamespace returns the old "namespace" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldNamespace(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNamespace is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNamespace requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNamespace: %w", err) + } + return oldValue.Namespace, nil +} + +// ResetNamespace resets all changes to the "namespace" field. +func (m *BillingGatheringInvoiceLineMutation) ResetNamespace() { + m.namespace = nil +} + +// SetMetadata sets the "metadata" field. +func (m *BillingGatheringInvoiceLineMutation) SetMetadata(value map[string]string) { + m.metadata = &value +} + +// Metadata returns the value of the "metadata" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) Metadata() (r map[string]string, exists bool) { + v := m.metadata + if v == nil { + return + } + return *v, true +} + +// OldMetadata returns the old "metadata" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldMetadata(ctx context.Context) (v map[string]string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMetadata is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMetadata requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMetadata: %w", err) + } + return oldValue.Metadata, nil +} + +// ClearMetadata clears the value of the "metadata" field. +func (m *BillingGatheringInvoiceLineMutation) ClearMetadata() { + m.metadata = nil + m.clearedFields[billinggatheringinvoiceline.FieldMetadata] = struct{}{} +} + +// MetadataCleared returns if the "metadata" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) MetadataCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldMetadata] + return ok +} + +// ResetMetadata resets all changes to the "metadata" field. +func (m *BillingGatheringInvoiceLineMutation) ResetMetadata() { + m.metadata = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldMetadata) +} + +// SetCreatedAt sets the "created_at" field. +func (m *BillingGatheringInvoiceLineMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *BillingGatheringInvoiceLineMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *BillingGatheringInvoiceLineMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *BillingGatheringInvoiceLineMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// SetDeletedAt sets the "deleted_at" field. +func (m *BillingGatheringInvoiceLineMutation) SetDeletedAt(t time.Time) { + m.deleted_at = &t +} + +// DeletedAt returns the value of the "deleted_at" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) DeletedAt() (r time.Time, exists bool) { + v := m.deleted_at + if v == nil { + return + } + return *v, true +} + +// OldDeletedAt returns the old "deleted_at" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDeletedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) + } + return oldValue.DeletedAt, nil +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (m *BillingGatheringInvoiceLineMutation) ClearDeletedAt() { + m.deleted_at = nil + m.clearedFields[billinggatheringinvoiceline.FieldDeletedAt] = struct{}{} +} + +// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldDeletedAt] + return ok +} + +// ResetDeletedAt resets all changes to the "deleted_at" field. +func (m *BillingGatheringInvoiceLineMutation) ResetDeletedAt() { + m.deleted_at = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldDeletedAt) +} + +// SetName sets the "name" field. +func (m *BillingGatheringInvoiceLineMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *BillingGatheringInvoiceLineMutation) ResetName() { + m.name = nil +} + +// SetDescription sets the "description" field. +func (m *BillingGatheringInvoiceLineMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return + } + return *v, true +} + +// OldDescription returns the old "description" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldDescription(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) + } + return oldValue.Description, nil +} + +// ClearDescription clears the value of the "description" field. +func (m *BillingGatheringInvoiceLineMutation) ClearDescription() { + m.description = nil + m.clearedFields[billinggatheringinvoiceline.FieldDescription] = struct{}{} +} + +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldDescription] + return ok +} + +// ResetDescription resets all changes to the "description" field. +func (m *BillingGatheringInvoiceLineMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldDescription) +} + +// SetCurrency sets the "currency" field. +func (m *BillingGatheringInvoiceLineMutation) SetCurrency(c currencyx.Code) { + m.currency = &c +} + +// Currency returns the value of the "currency" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) Currency() (r currencyx.Code, exists bool) { + v := m.currency + if v == nil { + return + } + return *v, true +} + +// OldCurrency returns the old "currency" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldCurrency(ctx context.Context) (v currencyx.Code, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCurrency is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCurrency requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCurrency: %w", err) + } + return oldValue.Currency, nil +} + +// ResetCurrency resets all changes to the "currency" field. +func (m *BillingGatheringInvoiceLineMutation) ResetCurrency() { + m.currency = nil +} + +// SetServicePeriodStart sets the "service_period_start" field. +func (m *BillingGatheringInvoiceLineMutation) SetServicePeriodStart(t time.Time) { + m.service_period_start = &t +} + +// ServicePeriodStart returns the value of the "service_period_start" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) ServicePeriodStart() (r time.Time, exists bool) { + v := m.service_period_start + if v == nil { + return + } + return *v, true +} + +// OldServicePeriodStart returns the old "service_period_start" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldServicePeriodStart(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldServicePeriodStart is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldServicePeriodStart requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldServicePeriodStart: %w", err) + } + return oldValue.ServicePeriodStart, nil +} + +// ResetServicePeriodStart resets all changes to the "service_period_start" field. +func (m *BillingGatheringInvoiceLineMutation) ResetServicePeriodStart() { + m.service_period_start = nil +} + +// SetServicePeriodEnd sets the "service_period_end" field. +func (m *BillingGatheringInvoiceLineMutation) SetServicePeriodEnd(t time.Time) { + m.service_period_end = &t +} + +// ServicePeriodEnd returns the value of the "service_period_end" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) ServicePeriodEnd() (r time.Time, exists bool) { + v := m.service_period_end + if v == nil { + return + } + return *v, true +} + +// OldServicePeriodEnd returns the old "service_period_end" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldServicePeriodEnd(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldServicePeriodEnd is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldServicePeriodEnd requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldServicePeriodEnd: %w", err) + } + return oldValue.ServicePeriodEnd, nil +} + +// ResetServicePeriodEnd resets all changes to the "service_period_end" field. +func (m *BillingGatheringInvoiceLineMutation) ResetServicePeriodEnd() { + m.service_period_end = nil +} + +// SetTaxConfig sets the "tax_config" field. +func (m *BillingGatheringInvoiceLineMutation) SetTaxConfig(bc billing.TaxConfig) { + m.tax_config = &bc +} + +// TaxConfig returns the value of the "tax_config" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) TaxConfig() (r billing.TaxConfig, exists bool) { + v := m.tax_config + if v == nil { + return + } + return *v, true +} + +// OldTaxConfig returns the old "tax_config" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldTaxConfig(ctx context.Context) (v billing.TaxConfig, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTaxConfig is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTaxConfig requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTaxConfig: %w", err) + } + return oldValue.TaxConfig, nil +} + +// ClearTaxConfig clears the value of the "tax_config" field. +func (m *BillingGatheringInvoiceLineMutation) ClearTaxConfig() { + m.tax_config = nil + m.clearedFields[billinggatheringinvoiceline.FieldTaxConfig] = struct{}{} +} + +// TaxConfigCleared returns if the "tax_config" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) TaxConfigCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldTaxConfig] + return ok +} + +// ResetTaxConfig resets all changes to the "tax_config" field. +func (m *BillingGatheringInvoiceLineMutation) ResetTaxConfig() { + m.tax_config = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldTaxConfig) +} + +// SetPriceType sets the "price_type" field. +func (m *BillingGatheringInvoiceLineMutation) SetPriceType(pt productcatalog.PriceType) { + m.price_type = &pt +} + +// PriceType returns the value of the "price_type" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) PriceType() (r productcatalog.PriceType, exists bool) { + v := m.price_type + if v == nil { + return + } + return *v, true +} + +// OldPriceType returns the old "price_type" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldPriceType(ctx context.Context) (v productcatalog.PriceType, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPriceType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPriceType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPriceType: %w", err) + } + return oldValue.PriceType, nil +} + +// ResetPriceType resets all changes to the "price_type" field. +func (m *BillingGatheringInvoiceLineMutation) ResetPriceType() { + m.price_type = nil +} + +// SetFeatureKey sets the "feature_key" field. +func (m *BillingGatheringInvoiceLineMutation) SetFeatureKey(s string) { + m.feature_key = &s +} + +// FeatureKey returns the value of the "feature_key" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) FeatureKey() (r string, exists bool) { + v := m.feature_key + if v == nil { + return + } + return *v, true +} + +// OldFeatureKey returns the old "feature_key" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldFeatureKey(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFeatureKey is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFeatureKey requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFeatureKey: %w", err) + } + return oldValue.FeatureKey, nil +} + +// ClearFeatureKey clears the value of the "feature_key" field. +func (m *BillingGatheringInvoiceLineMutation) ClearFeatureKey() { + m.feature_key = nil + m.clearedFields[billinggatheringinvoiceline.FieldFeatureKey] = struct{}{} +} + +// FeatureKeyCleared returns if the "feature_key" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) FeatureKeyCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldFeatureKey] + return ok +} + +// ResetFeatureKey resets all changes to the "feature_key" field. +func (m *BillingGatheringInvoiceLineMutation) ResetFeatureKey() { + m.feature_key = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldFeatureKey) +} + +// SetPrice sets the "price" field. +func (m *BillingGatheringInvoiceLineMutation) SetPrice(pr *productcatalog.Price) { + m.price = &pr +} + +// Price returns the value of the "price" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) Price() (r *productcatalog.Price, exists bool) { + v := m.price + if v == nil { + return + } + return *v, true +} + +// OldPrice returns the old "price" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldPrice(ctx context.Context) (v *productcatalog.Price, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPrice is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPrice requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPrice: %w", err) + } + return oldValue.Price, nil +} + +// ResetPrice resets all changes to the "price" field. +func (m *BillingGatheringInvoiceLineMutation) ResetPrice() { + m.price = nil +} + +// SetUnitConfig sets the "unit_config" field. +func (m *BillingGatheringInvoiceLineMutation) SetUnitConfig(pc *productcatalog.UnitConfig) { + m.unit_config = &pc +} + +// UnitConfig returns the value of the "unit_config" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) UnitConfig() (r *productcatalog.UnitConfig, exists bool) { + v := m.unit_config + if v == nil { + return + } + return *v, true +} + +// OldUnitConfig returns the old "unit_config" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldUnitConfig(ctx context.Context) (v *productcatalog.UnitConfig, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUnitConfig is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUnitConfig requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUnitConfig: %w", err) + } + return oldValue.UnitConfig, nil +} + +// ClearUnitConfig clears the value of the "unit_config" field. +func (m *BillingGatheringInvoiceLineMutation) ClearUnitConfig() { + m.unit_config = nil + m.clearedFields[billinggatheringinvoiceline.FieldUnitConfig] = struct{}{} +} + +// UnitConfigCleared returns if the "unit_config" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) UnitConfigCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldUnitConfig] + return ok +} + +// ResetUnitConfig resets all changes to the "unit_config" field. +func (m *BillingGatheringInvoiceLineMutation) ResetUnitConfig() { + m.unit_config = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldUnitConfig) +} + +// SetRatecardDiscounts sets the "ratecard_discounts" field. +func (m *BillingGatheringInvoiceLineMutation) SetRatecardDiscounts(b *billing.Discounts) { + m.ratecard_discounts = &b +} + +// RatecardDiscounts returns the value of the "ratecard_discounts" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) RatecardDiscounts() (r *billing.Discounts, exists bool) { + v := m.ratecard_discounts + if v == nil { + return + } + return *v, true +} + +// OldRatecardDiscounts returns the old "ratecard_discounts" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldRatecardDiscounts(ctx context.Context) (v *billing.Discounts, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRatecardDiscounts is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRatecardDiscounts requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRatecardDiscounts: %w", err) + } + return oldValue.RatecardDiscounts, nil +} + +// ClearRatecardDiscounts clears the value of the "ratecard_discounts" field. +func (m *BillingGatheringInvoiceLineMutation) ClearRatecardDiscounts() { + m.ratecard_discounts = nil + m.clearedFields[billinggatheringinvoiceline.FieldRatecardDiscounts] = struct{}{} +} + +// RatecardDiscountsCleared returns if the "ratecard_discounts" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) RatecardDiscountsCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldRatecardDiscounts] + return ok +} + +// ResetRatecardDiscounts resets all changes to the "ratecard_discounts" field. +func (m *BillingGatheringInvoiceLineMutation) ResetRatecardDiscounts() { + m.ratecard_discounts = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldRatecardDiscounts) +} + +// SetChildUniqueReferenceID sets the "child_unique_reference_id" field. +func (m *BillingGatheringInvoiceLineMutation) SetChildUniqueReferenceID(s string) { + m.child_unique_reference_id = &s +} + +// ChildUniqueReferenceID returns the value of the "child_unique_reference_id" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) ChildUniqueReferenceID() (r string, exists bool) { + v := m.child_unique_reference_id + if v == nil { + return + } + return *v, true +} + +// OldChildUniqueReferenceID returns the old "child_unique_reference_id" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldChildUniqueReferenceID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldChildUniqueReferenceID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldChildUniqueReferenceID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldChildUniqueReferenceID: %w", err) + } + return oldValue.ChildUniqueReferenceID, nil +} + +// ClearChildUniqueReferenceID clears the value of the "child_unique_reference_id" field. +func (m *BillingGatheringInvoiceLineMutation) ClearChildUniqueReferenceID() { + m.child_unique_reference_id = nil + m.clearedFields[billinggatheringinvoiceline.FieldChildUniqueReferenceID] = struct{}{} +} + +// ChildUniqueReferenceIDCleared returns if the "child_unique_reference_id" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) ChildUniqueReferenceIDCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldChildUniqueReferenceID] + return ok +} + +// ResetChildUniqueReferenceID resets all changes to the "child_unique_reference_id" field. +func (m *BillingGatheringInvoiceLineMutation) ResetChildUniqueReferenceID() { + m.child_unique_reference_id = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldChildUniqueReferenceID) +} + +// SetSubscriptionID sets the "subscription_id" field. +func (m *BillingGatheringInvoiceLineMutation) SetSubscriptionID(s string) { + m.subscription = &s +} + +// SubscriptionID returns the value of the "subscription_id" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionID() (r string, exists bool) { + v := m.subscription + if v == nil { + return + } + return *v, true +} + +// OldSubscriptionID returns the old "subscription_id" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldSubscriptionID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSubscriptionID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSubscriptionID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSubscriptionID: %w", err) + } + return oldValue.SubscriptionID, nil +} + +// ClearSubscriptionID clears the value of the "subscription_id" field. +func (m *BillingGatheringInvoiceLineMutation) ClearSubscriptionID() { + m.subscription = nil + m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionID] = struct{}{} +} + +// SubscriptionIDCleared returns if the "subscription_id" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionIDCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionID] + return ok +} + +// ResetSubscriptionID resets all changes to the "subscription_id" field. +func (m *BillingGatheringInvoiceLineMutation) ResetSubscriptionID() { + m.subscription = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldSubscriptionID) +} + +// SetSubscriptionPhaseID sets the "subscription_phase_id" field. +func (m *BillingGatheringInvoiceLineMutation) SetSubscriptionPhaseID(s string) { + m.subscription_phase = &s +} + +// SubscriptionPhaseID returns the value of the "subscription_phase_id" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionPhaseID() (r string, exists bool) { + v := m.subscription_phase + if v == nil { + return + } + return *v, true +} + +// OldSubscriptionPhaseID returns the old "subscription_phase_id" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldSubscriptionPhaseID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSubscriptionPhaseID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSubscriptionPhaseID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSubscriptionPhaseID: %w", err) + } + return oldValue.SubscriptionPhaseID, nil +} + +// ClearSubscriptionPhaseID clears the value of the "subscription_phase_id" field. +func (m *BillingGatheringInvoiceLineMutation) ClearSubscriptionPhaseID() { + m.subscription_phase = nil + m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionPhaseID] = struct{}{} +} + +// SubscriptionPhaseIDCleared returns if the "subscription_phase_id" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionPhaseIDCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionPhaseID] + return ok +} + +// ResetSubscriptionPhaseID resets all changes to the "subscription_phase_id" field. +func (m *BillingGatheringInvoiceLineMutation) ResetSubscriptionPhaseID() { + m.subscription_phase = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldSubscriptionPhaseID) +} + +// SetSubscriptionItemID sets the "subscription_item_id" field. +func (m *BillingGatheringInvoiceLineMutation) SetSubscriptionItemID(s string) { + m.subscription_item = &s +} + +// SubscriptionItemID returns the value of the "subscription_item_id" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionItemID() (r string, exists bool) { + v := m.subscription_item + if v == nil { + return + } + return *v, true +} + +// OldSubscriptionItemID returns the old "subscription_item_id" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldSubscriptionItemID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSubscriptionItemID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSubscriptionItemID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSubscriptionItemID: %w", err) + } + return oldValue.SubscriptionItemID, nil +} + +// ClearSubscriptionItemID clears the value of the "subscription_item_id" field. +func (m *BillingGatheringInvoiceLineMutation) ClearSubscriptionItemID() { + m.subscription_item = nil + m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionItemID] = struct{}{} +} + +// SubscriptionItemIDCleared returns if the "subscription_item_id" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionItemIDCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionItemID] + return ok +} + +// ResetSubscriptionItemID resets all changes to the "subscription_item_id" field. +func (m *BillingGatheringInvoiceLineMutation) ResetSubscriptionItemID() { + m.subscription_item = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldSubscriptionItemID) +} + +// SetSubscriptionBillingPeriodFrom sets the "subscription_billing_period_from" field. +func (m *BillingGatheringInvoiceLineMutation) SetSubscriptionBillingPeriodFrom(t time.Time) { + m.subscription_billing_period_from = &t +} + +// SubscriptionBillingPeriodFrom returns the value of the "subscription_billing_period_from" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionBillingPeriodFrom() (r time.Time, exists bool) { + v := m.subscription_billing_period_from + if v == nil { + return + } + return *v, true +} + +// OldSubscriptionBillingPeriodFrom returns the old "subscription_billing_period_from" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldSubscriptionBillingPeriodFrom(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSubscriptionBillingPeriodFrom is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSubscriptionBillingPeriodFrom requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSubscriptionBillingPeriodFrom: %w", err) + } + return oldValue.SubscriptionBillingPeriodFrom, nil +} + +// ClearSubscriptionBillingPeriodFrom clears the value of the "subscription_billing_period_from" field. +func (m *BillingGatheringInvoiceLineMutation) ClearSubscriptionBillingPeriodFrom() { + m.subscription_billing_period_from = nil + m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom] = struct{}{} +} + +// SubscriptionBillingPeriodFromCleared returns if the "subscription_billing_period_from" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionBillingPeriodFromCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom] + return ok +} + +// ResetSubscriptionBillingPeriodFrom resets all changes to the "subscription_billing_period_from" field. +func (m *BillingGatheringInvoiceLineMutation) ResetSubscriptionBillingPeriodFrom() { + m.subscription_billing_period_from = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom) +} + +// SetSubscriptionBillingPeriodTo sets the "subscription_billing_period_to" field. +func (m *BillingGatheringInvoiceLineMutation) SetSubscriptionBillingPeriodTo(t time.Time) { + m.subscription_billing_period_to = &t +} + +// SubscriptionBillingPeriodTo returns the value of the "subscription_billing_period_to" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionBillingPeriodTo() (r time.Time, exists bool) { + v := m.subscription_billing_period_to + if v == nil { + return + } + return *v, true +} + +// OldSubscriptionBillingPeriodTo returns the old "subscription_billing_period_to" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldSubscriptionBillingPeriodTo(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSubscriptionBillingPeriodTo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSubscriptionBillingPeriodTo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSubscriptionBillingPeriodTo: %w", err) + } + return oldValue.SubscriptionBillingPeriodTo, nil +} + +// ClearSubscriptionBillingPeriodTo clears the value of the "subscription_billing_period_to" field. +func (m *BillingGatheringInvoiceLineMutation) ClearSubscriptionBillingPeriodTo() { + m.subscription_billing_period_to = nil + m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo] = struct{}{} +} + +// SubscriptionBillingPeriodToCleared returns if the "subscription_billing_period_to" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionBillingPeriodToCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo] + return ok +} + +// ResetSubscriptionBillingPeriodTo resets all changes to the "subscription_billing_period_to" field. +func (m *BillingGatheringInvoiceLineMutation) ResetSubscriptionBillingPeriodTo() { + m.subscription_billing_period_to = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo) +} + +// SetTaxCodeID sets the "tax_code_id" field. +func (m *BillingGatheringInvoiceLineMutation) SetTaxCodeID(s string) { + m.tax_code = &s +} + +// TaxCodeID returns the value of the "tax_code_id" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) TaxCodeID() (r string, exists bool) { + v := m.tax_code + if v == nil { + return + } + return *v, true +} + +// OldTaxCodeID returns the old "tax_code_id" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldTaxCodeID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTaxCodeID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTaxCodeID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTaxCodeID: %w", err) + } + return oldValue.TaxCodeID, nil +} + +// ClearTaxCodeID clears the value of the "tax_code_id" field. +func (m *BillingGatheringInvoiceLineMutation) ClearTaxCodeID() { + m.tax_code = nil + m.clearedFields[billinggatheringinvoiceline.FieldTaxCodeID] = struct{}{} +} + +// TaxCodeIDCleared returns if the "tax_code_id" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) TaxCodeIDCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldTaxCodeID] + return ok +} + +// ResetTaxCodeID resets all changes to the "tax_code_id" field. +func (m *BillingGatheringInvoiceLineMutation) ResetTaxCodeID() { + m.tax_code = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldTaxCodeID) +} + +// SetTaxBehavior sets the "tax_behavior" field. +func (m *BillingGatheringInvoiceLineMutation) SetTaxBehavior(pb productcatalog.TaxBehavior) { + m.tax_behavior = &pb +} + +// TaxBehavior returns the value of the "tax_behavior" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) TaxBehavior() (r productcatalog.TaxBehavior, exists bool) { + v := m.tax_behavior + if v == nil { + return + } + return *v, true +} + +// OldTaxBehavior returns the old "tax_behavior" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldTaxBehavior(ctx context.Context) (v *productcatalog.TaxBehavior, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTaxBehavior is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTaxBehavior requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTaxBehavior: %w", err) + } + return oldValue.TaxBehavior, nil +} + +// ClearTaxBehavior clears the value of the "tax_behavior" field. +func (m *BillingGatheringInvoiceLineMutation) ClearTaxBehavior() { + m.tax_behavior = nil + m.clearedFields[billinggatheringinvoiceline.FieldTaxBehavior] = struct{}{} +} + +// TaxBehaviorCleared returns if the "tax_behavior" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) TaxBehaviorCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldTaxBehavior] + return ok +} + +// ResetTaxBehavior resets all changes to the "tax_behavior" field. +func (m *BillingGatheringInvoiceLineMutation) ResetTaxBehavior() { + m.tax_behavior = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldTaxBehavior) +} + +// SetInvoiceID sets the "invoice_id" field. +func (m *BillingGatheringInvoiceLineMutation) SetInvoiceID(s string) { + m.billing_invoice = &s +} + +// InvoiceID returns the value of the "invoice_id" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) InvoiceID() (r string, exists bool) { + v := m.billing_invoice + if v == nil { + return + } + return *v, true +} + +// OldInvoiceID returns the old "invoice_id" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldInvoiceID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldInvoiceID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldInvoiceID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldInvoiceID: %w", err) + } + return oldValue.InvoiceID, nil +} + +// ResetInvoiceID resets all changes to the "invoice_id" field. +func (m *BillingGatheringInvoiceLineMutation) ResetInvoiceID() { + m.billing_invoice = nil +} + +// SetInvoiceAt sets the "invoice_at" field. +func (m *BillingGatheringInvoiceLineMutation) SetInvoiceAt(t time.Time) { + m.invoice_at = &t +} + +// InvoiceAt returns the value of the "invoice_at" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) InvoiceAt() (r time.Time, exists bool) { + v := m.invoice_at + if v == nil { + return + } + return *v, true +} + +// OldInvoiceAt returns the old "invoice_at" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldInvoiceAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldInvoiceAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldInvoiceAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldInvoiceAt: %w", err) + } + return oldValue.InvoiceAt, nil +} + +// ResetInvoiceAt resets all changes to the "invoice_at" field. +func (m *BillingGatheringInvoiceLineMutation) ResetInvoiceAt() { + m.invoice_at = nil +} + +// SetManagedBy sets the "managed_by" field. +func (m *BillingGatheringInvoiceLineMutation) SetManagedBy(blmb billing.InvoiceLineManagedBy) { + m.managed_by = &blmb +} + +// ManagedBy returns the value of the "managed_by" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) ManagedBy() (r billing.InvoiceLineManagedBy, exists bool) { + v := m.managed_by + if v == nil { + return + } + return *v, true +} + +// OldManagedBy returns the old "managed_by" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldManagedBy(ctx context.Context) (v billing.InvoiceLineManagedBy, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldManagedBy is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldManagedBy requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldManagedBy: %w", err) + } + return oldValue.ManagedBy, nil +} + +// ResetManagedBy resets all changes to the "managed_by" field. +func (m *BillingGatheringInvoiceLineMutation) ResetManagedBy() { + m.managed_by = nil +} + +// SetEngine sets the "engine" field. +func (m *BillingGatheringInvoiceLineMutation) SetEngine(bet billing.LineEngineType) { + m.engine = &bet +} + +// Engine returns the value of the "engine" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) Engine() (r billing.LineEngineType, exists bool) { + v := m.engine + if v == nil { + return + } + return *v, true +} + +// OldEngine returns the old "engine" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldEngine(ctx context.Context) (v billing.LineEngineType, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldEngine is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldEngine requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEngine: %w", err) + } + return oldValue.Engine, nil +} + +// ResetEngine resets all changes to the "engine" field. +func (m *BillingGatheringInvoiceLineMutation) ResetEngine() { + m.engine = nil +} + +// SetSplitLineGroupID sets the "split_line_group_id" field. +func (m *BillingGatheringInvoiceLineMutation) SetSplitLineGroupID(s string) { + m.split_line_group = &s +} + +// SplitLineGroupID returns the value of the "split_line_group_id" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) SplitLineGroupID() (r string, exists bool) { + v := m.split_line_group + if v == nil { + return + } + return *v, true +} + +// OldSplitLineGroupID returns the old "split_line_group_id" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldSplitLineGroupID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSplitLineGroupID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSplitLineGroupID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSplitLineGroupID: %w", err) + } + return oldValue.SplitLineGroupID, nil +} + +// ClearSplitLineGroupID clears the value of the "split_line_group_id" field. +func (m *BillingGatheringInvoiceLineMutation) ClearSplitLineGroupID() { + m.split_line_group = nil + m.clearedFields[billinggatheringinvoiceline.FieldSplitLineGroupID] = struct{}{} +} + +// SplitLineGroupIDCleared returns if the "split_line_group_id" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) SplitLineGroupIDCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldSplitLineGroupID] + return ok +} + +// ResetSplitLineGroupID resets all changes to the "split_line_group_id" field. +func (m *BillingGatheringInvoiceLineMutation) ResetSplitLineGroupID() { + m.split_line_group = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldSplitLineGroupID) +} + +// SetChargeID sets the "charge_id" field. +func (m *BillingGatheringInvoiceLineMutation) SetChargeID(s string) { + m.charge = &s +} + +// ChargeID returns the value of the "charge_id" field in the mutation. +func (m *BillingGatheringInvoiceLineMutation) ChargeID() (r string, exists bool) { + v := m.charge + if v == nil { + return + } + return *v, true +} + +// OldChargeID returns the old "charge_id" field's value of the BillingGatheringInvoiceLine entity. +// If the BillingGatheringInvoiceLine object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *BillingGatheringInvoiceLineMutation) OldChargeID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldChargeID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldChargeID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldChargeID: %w", err) + } + return oldValue.ChargeID, nil +} + +// ClearChargeID clears the value of the "charge_id" field. +func (m *BillingGatheringInvoiceLineMutation) ClearChargeID() { + m.charge = nil + m.clearedFields[billinggatheringinvoiceline.FieldChargeID] = struct{}{} +} + +// ChargeIDCleared returns if the "charge_id" field was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) ChargeIDCleared() bool { + _, ok := m.clearedFields[billinggatheringinvoiceline.FieldChargeID] + return ok +} + +// ResetChargeID resets all changes to the "charge_id" field. +func (m *BillingGatheringInvoiceLineMutation) ResetChargeID() { + m.charge = nil + delete(m.clearedFields, billinggatheringinvoiceline.FieldChargeID) +} + +// SetBillingInvoiceID sets the "billing_invoice" edge to the BillingInvoice entity by id. +func (m *BillingGatheringInvoiceLineMutation) SetBillingInvoiceID(id string) { + m.billing_invoice = &id +} + +// ClearBillingInvoice clears the "billing_invoice" edge to the BillingInvoice entity. +func (m *BillingGatheringInvoiceLineMutation) ClearBillingInvoice() { + m.clearedbilling_invoice = true + m.clearedFields[billinggatheringinvoiceline.FieldInvoiceID] = struct{}{} +} + +// BillingInvoiceCleared reports if the "billing_invoice" edge to the BillingInvoice entity was cleared. +func (m *BillingGatheringInvoiceLineMutation) BillingInvoiceCleared() bool { + return m.clearedbilling_invoice +} + +// BillingInvoiceID returns the "billing_invoice" edge ID in the mutation. +func (m *BillingGatheringInvoiceLineMutation) BillingInvoiceID() (id string, exists bool) { + if m.billing_invoice != nil { + return *m.billing_invoice, true + } + return +} + +// BillingInvoiceIDs returns the "billing_invoice" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// BillingInvoiceID instead. It exists only for internal usage by the builders. +func (m *BillingGatheringInvoiceLineMutation) BillingInvoiceIDs() (ids []string) { + if id := m.billing_invoice; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetBillingInvoice resets all changes to the "billing_invoice" edge. +func (m *BillingGatheringInvoiceLineMutation) ResetBillingInvoice() { + m.billing_invoice = nil + m.clearedbilling_invoice = false +} + +// ClearSplitLineGroup clears the "split_line_group" edge to the BillingInvoiceSplitLineGroup entity. +func (m *BillingGatheringInvoiceLineMutation) ClearSplitLineGroup() { + m.clearedsplit_line_group = true + m.clearedFields[billinggatheringinvoiceline.FieldSplitLineGroupID] = struct{}{} +} + +// SplitLineGroupCleared reports if the "split_line_group" edge to the BillingInvoiceSplitLineGroup entity was cleared. +func (m *BillingGatheringInvoiceLineMutation) SplitLineGroupCleared() bool { + return m.SplitLineGroupIDCleared() || m.clearedsplit_line_group +} + +// SplitLineGroupIDs returns the "split_line_group" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// SplitLineGroupID instead. It exists only for internal usage by the builders. +func (m *BillingGatheringInvoiceLineMutation) SplitLineGroupIDs() (ids []string) { + if id := m.split_line_group; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetSplitLineGroup resets all changes to the "split_line_group" edge. +func (m *BillingGatheringInvoiceLineMutation) ResetSplitLineGroup() { + m.split_line_group = nil + m.clearedsplit_line_group = false +} + +// ClearSubscription clears the "subscription" edge to the Subscription entity. +func (m *BillingGatheringInvoiceLineMutation) ClearSubscription() { + m.clearedsubscription = true + m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionID] = struct{}{} +} + +// SubscriptionCleared reports if the "subscription" edge to the Subscription entity was cleared. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionCleared() bool { + return m.SubscriptionIDCleared() || m.clearedsubscription +} + +// SubscriptionIDs returns the "subscription" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// SubscriptionID instead. It exists only for internal usage by the builders. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionIDs() (ids []string) { + if id := m.subscription; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetSubscription resets all changes to the "subscription" edge. +func (m *BillingGatheringInvoiceLineMutation) ResetSubscription() { + m.subscription = nil + m.clearedsubscription = false +} + +// ClearSubscriptionPhase clears the "subscription_phase" edge to the SubscriptionPhase entity. +func (m *BillingGatheringInvoiceLineMutation) ClearSubscriptionPhase() { + m.clearedsubscription_phase = true + m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionPhaseID] = struct{}{} +} + +// SubscriptionPhaseCleared reports if the "subscription_phase" edge to the SubscriptionPhase entity was cleared. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionPhaseCleared() bool { + return m.SubscriptionPhaseIDCleared() || m.clearedsubscription_phase +} + +// SubscriptionPhaseIDs returns the "subscription_phase" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// SubscriptionPhaseID instead. It exists only for internal usage by the builders. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionPhaseIDs() (ids []string) { + if id := m.subscription_phase; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetSubscriptionPhase resets all changes to the "subscription_phase" edge. +func (m *BillingGatheringInvoiceLineMutation) ResetSubscriptionPhase() { + m.subscription_phase = nil + m.clearedsubscription_phase = false +} + +// ClearSubscriptionItem clears the "subscription_item" edge to the SubscriptionItem entity. +func (m *BillingGatheringInvoiceLineMutation) ClearSubscriptionItem() { + m.clearedsubscription_item = true + m.clearedFields[billinggatheringinvoiceline.FieldSubscriptionItemID] = struct{}{} +} + +// SubscriptionItemCleared reports if the "subscription_item" edge to the SubscriptionItem entity was cleared. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionItemCleared() bool { + return m.SubscriptionItemIDCleared() || m.clearedsubscription_item +} + +// SubscriptionItemIDs returns the "subscription_item" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// SubscriptionItemID instead. It exists only for internal usage by the builders. +func (m *BillingGatheringInvoiceLineMutation) SubscriptionItemIDs() (ids []string) { + if id := m.subscription_item; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetSubscriptionItem resets all changes to the "subscription_item" edge. +func (m *BillingGatheringInvoiceLineMutation) ResetSubscriptionItem() { + m.subscription_item = nil + m.clearedsubscription_item = false +} + +// ClearCharge clears the "charge" edge to the Charge entity. +func (m *BillingGatheringInvoiceLineMutation) ClearCharge() { + m.clearedcharge = true + m.clearedFields[billinggatheringinvoiceline.FieldChargeID] = struct{}{} +} + +// ChargeCleared reports if the "charge" edge to the Charge entity was cleared. +func (m *BillingGatheringInvoiceLineMutation) ChargeCleared() bool { + return m.ChargeIDCleared() || m.clearedcharge +} + +// ChargeIDs returns the "charge" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ChargeID instead. It exists only for internal usage by the builders. +func (m *BillingGatheringInvoiceLineMutation) ChargeIDs() (ids []string) { + if id := m.charge; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetCharge resets all changes to the "charge" edge. +func (m *BillingGatheringInvoiceLineMutation) ResetCharge() { + m.charge = nil + m.clearedcharge = false +} + +// ClearTaxCode clears the "tax_code" edge to the TaxCode entity. +func (m *BillingGatheringInvoiceLineMutation) ClearTaxCode() { + m.clearedtax_code = true + m.clearedFields[billinggatheringinvoiceline.FieldTaxCodeID] = struct{}{} +} + +// TaxCodeCleared reports if the "tax_code" edge to the TaxCode entity was cleared. +func (m *BillingGatheringInvoiceLineMutation) TaxCodeCleared() bool { + return m.TaxCodeIDCleared() || m.clearedtax_code +} + +// TaxCodeIDs returns the "tax_code" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// TaxCodeID instead. It exists only for internal usage by the builders. +func (m *BillingGatheringInvoiceLineMutation) TaxCodeIDs() (ids []string) { + if id := m.tax_code; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetTaxCode resets all changes to the "tax_code" edge. +func (m *BillingGatheringInvoiceLineMutation) ResetTaxCode() { + m.tax_code = nil + m.clearedtax_code = false +} + +// Where appends a list predicates to the BillingGatheringInvoiceLineMutation builder. +func (m *BillingGatheringInvoiceLineMutation) Where(ps ...predicate.BillingGatheringInvoiceLine) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the BillingGatheringInvoiceLineMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *BillingGatheringInvoiceLineMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.BillingGatheringInvoiceLine, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *BillingGatheringInvoiceLineMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *BillingGatheringInvoiceLineMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (BillingGatheringInvoiceLine). +func (m *BillingGatheringInvoiceLineMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *BillingGatheringInvoiceLineMutation) Fields() []string { + fields := make([]string, 0, 31) + if m.annotations != nil { + fields = append(fields, billinggatheringinvoiceline.FieldAnnotations) + } + if m.namespace != nil { + fields = append(fields, billinggatheringinvoiceline.FieldNamespace) + } + if m.metadata != nil { + fields = append(fields, billinggatheringinvoiceline.FieldMetadata) + } + if m.created_at != nil { + fields = append(fields, billinggatheringinvoiceline.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, billinggatheringinvoiceline.FieldUpdatedAt) + } + if m.deleted_at != nil { + fields = append(fields, billinggatheringinvoiceline.FieldDeletedAt) + } + if m.name != nil { + fields = append(fields, billinggatheringinvoiceline.FieldName) + } + if m.description != nil { + fields = append(fields, billinggatheringinvoiceline.FieldDescription) + } + if m.currency != nil { + fields = append(fields, billinggatheringinvoiceline.FieldCurrency) + } + if m.service_period_start != nil { + fields = append(fields, billinggatheringinvoiceline.FieldServicePeriodStart) + } + if m.service_period_end != nil { + fields = append(fields, billinggatheringinvoiceline.FieldServicePeriodEnd) + } + if m.tax_config != nil { + fields = append(fields, billinggatheringinvoiceline.FieldTaxConfig) + } + if m.price_type != nil { + fields = append(fields, billinggatheringinvoiceline.FieldPriceType) + } + if m.feature_key != nil { + fields = append(fields, billinggatheringinvoiceline.FieldFeatureKey) + } + if m.price != nil { + fields = append(fields, billinggatheringinvoiceline.FieldPrice) + } + if m.unit_config != nil { + fields = append(fields, billinggatheringinvoiceline.FieldUnitConfig) + } + if m.ratecard_discounts != nil { + fields = append(fields, billinggatheringinvoiceline.FieldRatecardDiscounts) + } + if m.child_unique_reference_id != nil { + fields = append(fields, billinggatheringinvoiceline.FieldChildUniqueReferenceID) + } + if m.subscription != nil { + fields = append(fields, billinggatheringinvoiceline.FieldSubscriptionID) + } + if m.subscription_phase != nil { + fields = append(fields, billinggatheringinvoiceline.FieldSubscriptionPhaseID) + } + if m.subscription_item != nil { + fields = append(fields, billinggatheringinvoiceline.FieldSubscriptionItemID) + } + if m.subscription_billing_period_from != nil { + fields = append(fields, billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom) + } + if m.subscription_billing_period_to != nil { + fields = append(fields, billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo) + } + if m.tax_code != nil { + fields = append(fields, billinggatheringinvoiceline.FieldTaxCodeID) + } + if m.tax_behavior != nil { + fields = append(fields, billinggatheringinvoiceline.FieldTaxBehavior) + } + if m.billing_invoice != nil { + fields = append(fields, billinggatheringinvoiceline.FieldInvoiceID) + } + if m.invoice_at != nil { + fields = append(fields, billinggatheringinvoiceline.FieldInvoiceAt) + } + if m.managed_by != nil { + fields = append(fields, billinggatheringinvoiceline.FieldManagedBy) + } + if m.engine != nil { + fields = append(fields, billinggatheringinvoiceline.FieldEngine) + } + if m.split_line_group != nil { + fields = append(fields, billinggatheringinvoiceline.FieldSplitLineGroupID) + } + if m.charge != nil { + fields = append(fields, billinggatheringinvoiceline.FieldChargeID) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *BillingGatheringInvoiceLineMutation) Field(name string) (ent.Value, bool) { + switch name { + case billinggatheringinvoiceline.FieldAnnotations: + return m.Annotations() + case billinggatheringinvoiceline.FieldNamespace: + return m.Namespace() + case billinggatheringinvoiceline.FieldMetadata: + return m.Metadata() + case billinggatheringinvoiceline.FieldCreatedAt: + return m.CreatedAt() + case billinggatheringinvoiceline.FieldUpdatedAt: + return m.UpdatedAt() + case billinggatheringinvoiceline.FieldDeletedAt: + return m.DeletedAt() + case billinggatheringinvoiceline.FieldName: + return m.Name() + case billinggatheringinvoiceline.FieldDescription: + return m.Description() + case billinggatheringinvoiceline.FieldCurrency: + return m.Currency() + case billinggatheringinvoiceline.FieldServicePeriodStart: + return m.ServicePeriodStart() + case billinggatheringinvoiceline.FieldServicePeriodEnd: + return m.ServicePeriodEnd() + case billinggatheringinvoiceline.FieldTaxConfig: + return m.TaxConfig() + case billinggatheringinvoiceline.FieldPriceType: + return m.PriceType() + case billinggatheringinvoiceline.FieldFeatureKey: + return m.FeatureKey() + case billinggatheringinvoiceline.FieldPrice: + return m.Price() + case billinggatheringinvoiceline.FieldUnitConfig: + return m.UnitConfig() + case billinggatheringinvoiceline.FieldRatecardDiscounts: + return m.RatecardDiscounts() + case billinggatheringinvoiceline.FieldChildUniqueReferenceID: + return m.ChildUniqueReferenceID() + case billinggatheringinvoiceline.FieldSubscriptionID: + return m.SubscriptionID() + case billinggatheringinvoiceline.FieldSubscriptionPhaseID: + return m.SubscriptionPhaseID() + case billinggatheringinvoiceline.FieldSubscriptionItemID: + return m.SubscriptionItemID() + case billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom: + return m.SubscriptionBillingPeriodFrom() + case billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo: + return m.SubscriptionBillingPeriodTo() + case billinggatheringinvoiceline.FieldTaxCodeID: + return m.TaxCodeID() + case billinggatheringinvoiceline.FieldTaxBehavior: + return m.TaxBehavior() + case billinggatheringinvoiceline.FieldInvoiceID: + return m.InvoiceID() + case billinggatheringinvoiceline.FieldInvoiceAt: + return m.InvoiceAt() + case billinggatheringinvoiceline.FieldManagedBy: + return m.ManagedBy() + case billinggatheringinvoiceline.FieldEngine: + return m.Engine() + case billinggatheringinvoiceline.FieldSplitLineGroupID: + return m.SplitLineGroupID() + case billinggatheringinvoiceline.FieldChargeID: + return m.ChargeID() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *BillingGatheringInvoiceLineMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case billinggatheringinvoiceline.FieldAnnotations: + return m.OldAnnotations(ctx) + case billinggatheringinvoiceline.FieldNamespace: + return m.OldNamespace(ctx) + case billinggatheringinvoiceline.FieldMetadata: + return m.OldMetadata(ctx) + case billinggatheringinvoiceline.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case billinggatheringinvoiceline.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case billinggatheringinvoiceline.FieldDeletedAt: + return m.OldDeletedAt(ctx) + case billinggatheringinvoiceline.FieldName: + return m.OldName(ctx) + case billinggatheringinvoiceline.FieldDescription: + return m.OldDescription(ctx) + case billinggatheringinvoiceline.FieldCurrency: + return m.OldCurrency(ctx) + case billinggatheringinvoiceline.FieldServicePeriodStart: + return m.OldServicePeriodStart(ctx) + case billinggatheringinvoiceline.FieldServicePeriodEnd: + return m.OldServicePeriodEnd(ctx) + case billinggatheringinvoiceline.FieldTaxConfig: + return m.OldTaxConfig(ctx) + case billinggatheringinvoiceline.FieldPriceType: + return m.OldPriceType(ctx) + case billinggatheringinvoiceline.FieldFeatureKey: + return m.OldFeatureKey(ctx) + case billinggatheringinvoiceline.FieldPrice: + return m.OldPrice(ctx) + case billinggatheringinvoiceline.FieldUnitConfig: + return m.OldUnitConfig(ctx) + case billinggatheringinvoiceline.FieldRatecardDiscounts: + return m.OldRatecardDiscounts(ctx) + case billinggatheringinvoiceline.FieldChildUniqueReferenceID: + return m.OldChildUniqueReferenceID(ctx) + case billinggatheringinvoiceline.FieldSubscriptionID: + return m.OldSubscriptionID(ctx) + case billinggatheringinvoiceline.FieldSubscriptionPhaseID: + return m.OldSubscriptionPhaseID(ctx) + case billinggatheringinvoiceline.FieldSubscriptionItemID: + return m.OldSubscriptionItemID(ctx) + case billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom: + return m.OldSubscriptionBillingPeriodFrom(ctx) + case billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo: + return m.OldSubscriptionBillingPeriodTo(ctx) + case billinggatheringinvoiceline.FieldTaxCodeID: + return m.OldTaxCodeID(ctx) + case billinggatheringinvoiceline.FieldTaxBehavior: + return m.OldTaxBehavior(ctx) + case billinggatheringinvoiceline.FieldInvoiceID: + return m.OldInvoiceID(ctx) + case billinggatheringinvoiceline.FieldInvoiceAt: + return m.OldInvoiceAt(ctx) + case billinggatheringinvoiceline.FieldManagedBy: + return m.OldManagedBy(ctx) + case billinggatheringinvoiceline.FieldEngine: + return m.OldEngine(ctx) + case billinggatheringinvoiceline.FieldSplitLineGroupID: + return m.OldSplitLineGroupID(ctx) + case billinggatheringinvoiceline.FieldChargeID: + return m.OldChargeID(ctx) + } + return nil, fmt.Errorf("unknown BillingGatheringInvoiceLine field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *BillingGatheringInvoiceLineMutation) SetField(name string, value ent.Value) error { + switch name { + case billinggatheringinvoiceline.FieldAnnotations: + v, ok := value.(models.Annotations) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAnnotations(v) + return nil + case billinggatheringinvoiceline.FieldNamespace: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNamespace(v) + return nil + case billinggatheringinvoiceline.FieldMetadata: + v, ok := value.(map[string]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMetadata(v) + return nil + case billinggatheringinvoiceline.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case billinggatheringinvoiceline.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case billinggatheringinvoiceline.FieldDeletedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDeletedAt(v) + return nil + case billinggatheringinvoiceline.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case billinggatheringinvoiceline.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + case billinggatheringinvoiceline.FieldCurrency: + v, ok := value.(currencyx.Code) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCurrency(v) + return nil + case billinggatheringinvoiceline.FieldServicePeriodStart: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServicePeriodStart(v) + return nil + case billinggatheringinvoiceline.FieldServicePeriodEnd: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServicePeriodEnd(v) + return nil + case billinggatheringinvoiceline.FieldTaxConfig: + v, ok := value.(billing.TaxConfig) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTaxConfig(v) + return nil + case billinggatheringinvoiceline.FieldPriceType: + v, ok := value.(productcatalog.PriceType) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPriceType(v) + return nil + case billinggatheringinvoiceline.FieldFeatureKey: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFeatureKey(v) + return nil + case billinggatheringinvoiceline.FieldPrice: + v, ok := value.(*productcatalog.Price) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPrice(v) + return nil + case billinggatheringinvoiceline.FieldUnitConfig: + v, ok := value.(*productcatalog.UnitConfig) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUnitConfig(v) + return nil + case billinggatheringinvoiceline.FieldRatecardDiscounts: + v, ok := value.(*billing.Discounts) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRatecardDiscounts(v) + return nil + case billinggatheringinvoiceline.FieldChildUniqueReferenceID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetChildUniqueReferenceID(v) + return nil + case billinggatheringinvoiceline.FieldSubscriptionID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubscriptionID(v) + return nil + case billinggatheringinvoiceline.FieldSubscriptionPhaseID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubscriptionPhaseID(v) + return nil + case billinggatheringinvoiceline.FieldSubscriptionItemID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubscriptionItemID(v) + return nil + case billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubscriptionBillingPeriodFrom(v) + return nil + case billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubscriptionBillingPeriodTo(v) + return nil + case billinggatheringinvoiceline.FieldTaxCodeID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTaxCodeID(v) + return nil + case billinggatheringinvoiceline.FieldTaxBehavior: + v, ok := value.(productcatalog.TaxBehavior) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTaxBehavior(v) + return nil + case billinggatheringinvoiceline.FieldInvoiceID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetInvoiceID(v) + return nil + case billinggatheringinvoiceline.FieldInvoiceAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetInvoiceAt(v) + return nil + case billinggatheringinvoiceline.FieldManagedBy: + v, ok := value.(billing.InvoiceLineManagedBy) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetManagedBy(v) + return nil + case billinggatheringinvoiceline.FieldEngine: + v, ok := value.(billing.LineEngineType) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEngine(v) + return nil + case billinggatheringinvoiceline.FieldSplitLineGroupID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSplitLineGroupID(v) + return nil + case billinggatheringinvoiceline.FieldChargeID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetChargeID(v) + return nil + } + return fmt.Errorf("unknown BillingGatheringInvoiceLine field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *BillingGatheringInvoiceLineMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *BillingGatheringInvoiceLineMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *BillingGatheringInvoiceLineMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown BillingGatheringInvoiceLine numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *BillingGatheringInvoiceLineMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(billinggatheringinvoiceline.FieldAnnotations) { + fields = append(fields, billinggatheringinvoiceline.FieldAnnotations) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldMetadata) { + fields = append(fields, billinggatheringinvoiceline.FieldMetadata) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldDeletedAt) { + fields = append(fields, billinggatheringinvoiceline.FieldDeletedAt) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldDescription) { + fields = append(fields, billinggatheringinvoiceline.FieldDescription) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldTaxConfig) { + fields = append(fields, billinggatheringinvoiceline.FieldTaxConfig) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldFeatureKey) { + fields = append(fields, billinggatheringinvoiceline.FieldFeatureKey) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldUnitConfig) { + fields = append(fields, billinggatheringinvoiceline.FieldUnitConfig) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldRatecardDiscounts) { + fields = append(fields, billinggatheringinvoiceline.FieldRatecardDiscounts) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldChildUniqueReferenceID) { + fields = append(fields, billinggatheringinvoiceline.FieldChildUniqueReferenceID) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldSubscriptionID) { + fields = append(fields, billinggatheringinvoiceline.FieldSubscriptionID) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldSubscriptionPhaseID) { + fields = append(fields, billinggatheringinvoiceline.FieldSubscriptionPhaseID) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldSubscriptionItemID) { + fields = append(fields, billinggatheringinvoiceline.FieldSubscriptionItemID) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom) { + fields = append(fields, billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo) { + fields = append(fields, billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldTaxCodeID) { + fields = append(fields, billinggatheringinvoiceline.FieldTaxCodeID) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldTaxBehavior) { + fields = append(fields, billinggatheringinvoiceline.FieldTaxBehavior) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldSplitLineGroupID) { + fields = append(fields, billinggatheringinvoiceline.FieldSplitLineGroupID) + } + if m.FieldCleared(billinggatheringinvoiceline.FieldChargeID) { + fields = append(fields, billinggatheringinvoiceline.FieldChargeID) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *BillingGatheringInvoiceLineMutation) ClearField(name string) error { + switch name { + case billinggatheringinvoiceline.FieldAnnotations: + m.ClearAnnotations() + return nil + case billinggatheringinvoiceline.FieldMetadata: + m.ClearMetadata() + return nil + case billinggatheringinvoiceline.FieldDeletedAt: + m.ClearDeletedAt() + return nil + case billinggatheringinvoiceline.FieldDescription: + m.ClearDescription() + return nil + case billinggatheringinvoiceline.FieldTaxConfig: + m.ClearTaxConfig() + return nil + case billinggatheringinvoiceline.FieldFeatureKey: + m.ClearFeatureKey() + return nil + case billinggatheringinvoiceline.FieldUnitConfig: + m.ClearUnitConfig() + return nil + case billinggatheringinvoiceline.FieldRatecardDiscounts: + m.ClearRatecardDiscounts() + return nil + case billinggatheringinvoiceline.FieldChildUniqueReferenceID: + m.ClearChildUniqueReferenceID() + return nil + case billinggatheringinvoiceline.FieldSubscriptionID: + m.ClearSubscriptionID() + return nil + case billinggatheringinvoiceline.FieldSubscriptionPhaseID: + m.ClearSubscriptionPhaseID() + return nil + case billinggatheringinvoiceline.FieldSubscriptionItemID: + m.ClearSubscriptionItemID() + return nil + case billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom: + m.ClearSubscriptionBillingPeriodFrom() + return nil + case billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo: + m.ClearSubscriptionBillingPeriodTo() + return nil + case billinggatheringinvoiceline.FieldTaxCodeID: + m.ClearTaxCodeID() + return nil + case billinggatheringinvoiceline.FieldTaxBehavior: + m.ClearTaxBehavior() + return nil + case billinggatheringinvoiceline.FieldSplitLineGroupID: + m.ClearSplitLineGroupID() + return nil + case billinggatheringinvoiceline.FieldChargeID: + m.ClearChargeID() + return nil + } + return fmt.Errorf("unknown BillingGatheringInvoiceLine nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *BillingGatheringInvoiceLineMutation) ResetField(name string) error { + switch name { + case billinggatheringinvoiceline.FieldAnnotations: + m.ResetAnnotations() + return nil + case billinggatheringinvoiceline.FieldNamespace: + m.ResetNamespace() + return nil + case billinggatheringinvoiceline.FieldMetadata: + m.ResetMetadata() + return nil + case billinggatheringinvoiceline.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case billinggatheringinvoiceline.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case billinggatheringinvoiceline.FieldDeletedAt: + m.ResetDeletedAt() + return nil + case billinggatheringinvoiceline.FieldName: + m.ResetName() + return nil + case billinggatheringinvoiceline.FieldDescription: + m.ResetDescription() + return nil + case billinggatheringinvoiceline.FieldCurrency: + m.ResetCurrency() + return nil + case billinggatheringinvoiceline.FieldServicePeriodStart: + m.ResetServicePeriodStart() + return nil + case billinggatheringinvoiceline.FieldServicePeriodEnd: + m.ResetServicePeriodEnd() + return nil + case billinggatheringinvoiceline.FieldTaxConfig: + m.ResetTaxConfig() + return nil + case billinggatheringinvoiceline.FieldPriceType: + m.ResetPriceType() + return nil + case billinggatheringinvoiceline.FieldFeatureKey: + m.ResetFeatureKey() + return nil + case billinggatheringinvoiceline.FieldPrice: + m.ResetPrice() + return nil + case billinggatheringinvoiceline.FieldUnitConfig: + m.ResetUnitConfig() + return nil + case billinggatheringinvoiceline.FieldRatecardDiscounts: + m.ResetRatecardDiscounts() + return nil + case billinggatheringinvoiceline.FieldChildUniqueReferenceID: + m.ResetChildUniqueReferenceID() + return nil + case billinggatheringinvoiceline.FieldSubscriptionID: + m.ResetSubscriptionID() + return nil + case billinggatheringinvoiceline.FieldSubscriptionPhaseID: + m.ResetSubscriptionPhaseID() + return nil + case billinggatheringinvoiceline.FieldSubscriptionItemID: + m.ResetSubscriptionItemID() + return nil + case billinggatheringinvoiceline.FieldSubscriptionBillingPeriodFrom: + m.ResetSubscriptionBillingPeriodFrom() + return nil + case billinggatheringinvoiceline.FieldSubscriptionBillingPeriodTo: + m.ResetSubscriptionBillingPeriodTo() + return nil + case billinggatheringinvoiceline.FieldTaxCodeID: + m.ResetTaxCodeID() + return nil + case billinggatheringinvoiceline.FieldTaxBehavior: + m.ResetTaxBehavior() + return nil + case billinggatheringinvoiceline.FieldInvoiceID: + m.ResetInvoiceID() + return nil + case billinggatheringinvoiceline.FieldInvoiceAt: + m.ResetInvoiceAt() + return nil + case billinggatheringinvoiceline.FieldManagedBy: + m.ResetManagedBy() + return nil + case billinggatheringinvoiceline.FieldEngine: + m.ResetEngine() + return nil + case billinggatheringinvoiceline.FieldSplitLineGroupID: + m.ResetSplitLineGroupID() + return nil + case billinggatheringinvoiceline.FieldChargeID: + m.ResetChargeID() + return nil + } + return fmt.Errorf("unknown BillingGatheringInvoiceLine field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *BillingGatheringInvoiceLineMutation) AddedEdges() []string { + edges := make([]string, 0, 7) + if m.billing_invoice != nil { + edges = append(edges, billinggatheringinvoiceline.EdgeBillingInvoice) + } + if m.split_line_group != nil { + edges = append(edges, billinggatheringinvoiceline.EdgeSplitLineGroup) + } + if m.subscription != nil { + edges = append(edges, billinggatheringinvoiceline.EdgeSubscription) + } + if m.subscription_phase != nil { + edges = append(edges, billinggatheringinvoiceline.EdgeSubscriptionPhase) + } + if m.subscription_item != nil { + edges = append(edges, billinggatheringinvoiceline.EdgeSubscriptionItem) + } + if m.charge != nil { + edges = append(edges, billinggatheringinvoiceline.EdgeCharge) + } + if m.tax_code != nil { + edges = append(edges, billinggatheringinvoiceline.EdgeTaxCode) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *BillingGatheringInvoiceLineMutation) AddedIDs(name string) []ent.Value { + switch name { + case billinggatheringinvoiceline.EdgeBillingInvoice: + if id := m.billing_invoice; id != nil { + return []ent.Value{*id} + } + case billinggatheringinvoiceline.EdgeSplitLineGroup: + if id := m.split_line_group; id != nil { + return []ent.Value{*id} + } + case billinggatheringinvoiceline.EdgeSubscription: + if id := m.subscription; id != nil { + return []ent.Value{*id} + } + case billinggatheringinvoiceline.EdgeSubscriptionPhase: + if id := m.subscription_phase; id != nil { + return []ent.Value{*id} + } + case billinggatheringinvoiceline.EdgeSubscriptionItem: + if id := m.subscription_item; id != nil { + return []ent.Value{*id} + } + case billinggatheringinvoiceline.EdgeCharge: + if id := m.charge; id != nil { + return []ent.Value{*id} + } + case billinggatheringinvoiceline.EdgeTaxCode: + if id := m.tax_code; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *BillingGatheringInvoiceLineMutation) RemovedEdges() []string { + edges := make([]string, 0, 7) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *BillingGatheringInvoiceLineMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) ClearedEdges() []string { + edges := make([]string, 0, 7) + if m.clearedbilling_invoice { + edges = append(edges, billinggatheringinvoiceline.EdgeBillingInvoice) + } + if m.clearedsplit_line_group { + edges = append(edges, billinggatheringinvoiceline.EdgeSplitLineGroup) + } + if m.clearedsubscription { + edges = append(edges, billinggatheringinvoiceline.EdgeSubscription) + } + if m.clearedsubscription_phase { + edges = append(edges, billinggatheringinvoiceline.EdgeSubscriptionPhase) + } + if m.clearedsubscription_item { + edges = append(edges, billinggatheringinvoiceline.EdgeSubscriptionItem) + } + if m.clearedcharge { + edges = append(edges, billinggatheringinvoiceline.EdgeCharge) + } + if m.clearedtax_code { + edges = append(edges, billinggatheringinvoiceline.EdgeTaxCode) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *BillingGatheringInvoiceLineMutation) EdgeCleared(name string) bool { + switch name { + case billinggatheringinvoiceline.EdgeBillingInvoice: + return m.clearedbilling_invoice + case billinggatheringinvoiceline.EdgeSplitLineGroup: + return m.clearedsplit_line_group + case billinggatheringinvoiceline.EdgeSubscription: + return m.clearedsubscription + case billinggatheringinvoiceline.EdgeSubscriptionPhase: + return m.clearedsubscription_phase + case billinggatheringinvoiceline.EdgeSubscriptionItem: + return m.clearedsubscription_item + case billinggatheringinvoiceline.EdgeCharge: + return m.clearedcharge + case billinggatheringinvoiceline.EdgeTaxCode: + return m.clearedtax_code + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *BillingGatheringInvoiceLineMutation) ClearEdge(name string) error { + switch name { + case billinggatheringinvoiceline.EdgeBillingInvoice: + m.ClearBillingInvoice() + return nil + case billinggatheringinvoiceline.EdgeSplitLineGroup: + m.ClearSplitLineGroup() + return nil + case billinggatheringinvoiceline.EdgeSubscription: + m.ClearSubscription() + return nil + case billinggatheringinvoiceline.EdgeSubscriptionPhase: + m.ClearSubscriptionPhase() + return nil + case billinggatheringinvoiceline.EdgeSubscriptionItem: + m.ClearSubscriptionItem() + return nil + case billinggatheringinvoiceline.EdgeCharge: + m.ClearCharge() + return nil + case billinggatheringinvoiceline.EdgeTaxCode: + m.ClearTaxCode() + return nil + } + return fmt.Errorf("unknown BillingGatheringInvoiceLine unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *BillingGatheringInvoiceLineMutation) ResetEdge(name string) error { + switch name { + case billinggatheringinvoiceline.EdgeBillingInvoice: + m.ResetBillingInvoice() + return nil + case billinggatheringinvoiceline.EdgeSplitLineGroup: + m.ResetSplitLineGroup() + return nil + case billinggatheringinvoiceline.EdgeSubscription: + m.ResetSubscription() + return nil + case billinggatheringinvoiceline.EdgeSubscriptionPhase: + m.ResetSubscriptionPhase() + return nil + case billinggatheringinvoiceline.EdgeSubscriptionItem: + m.ResetSubscriptionItem() + return nil + case billinggatheringinvoiceline.EdgeCharge: + m.ResetCharge() + return nil + case billinggatheringinvoiceline.EdgeTaxCode: + m.ResetTaxCode() + return nil + } + return fmt.Errorf("unknown BillingGatheringInvoiceLine edge %s", name) +} + // BillingInvoiceMutation represents an operation that mutates the BillingInvoice nodes in the graph. type BillingInvoiceMutation struct { config @@ -12025,6 +14667,9 @@ type BillingInvoiceMutation struct { billing_invoice_lines map[string]struct{} removedbilling_invoice_lines map[string]struct{} clearedbilling_invoice_lines bool + billing_gathering_invoice_lines map[string]struct{} + removedbilling_gathering_invoice_lines map[string]struct{} + clearedbilling_gathering_invoice_lines bool billing_invoice_detailed_lines map[string]struct{} removedbilling_invoice_detailed_lines map[string]struct{} clearedbilling_invoice_detailed_lines bool @@ -14874,6 +17519,60 @@ func (m *BillingInvoiceMutation) ResetBillingInvoiceLines() { m.removedbilling_invoice_lines = nil } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by ids. +func (m *BillingInvoiceMutation) AddBillingGatheringInvoiceLineIDs(ids ...string) { + if m.billing_gathering_invoice_lines == nil { + m.billing_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + m.billing_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// ClearBillingGatheringInvoiceLines clears the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *BillingInvoiceMutation) ClearBillingGatheringInvoiceLines() { + m.clearedbilling_gathering_invoice_lines = true +} + +// BillingGatheringInvoiceLinesCleared reports if the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity was cleared. +func (m *BillingInvoiceMutation) BillingGatheringInvoiceLinesCleared() bool { + return m.clearedbilling_gathering_invoice_lines +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (m *BillingInvoiceMutation) RemoveBillingGatheringInvoiceLineIDs(ids ...string) { + if m.removedbilling_gathering_invoice_lines == nil { + m.removedbilling_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + delete(m.billing_gathering_invoice_lines, ids[i]) + m.removedbilling_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// RemovedBillingGatheringInvoiceLines returns the removed IDs of the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *BillingInvoiceMutation) RemovedBillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// BillingGatheringInvoiceLinesIDs returns the "billing_gathering_invoice_lines" edge IDs in the mutation. +func (m *BillingInvoiceMutation) BillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// ResetBillingGatheringInvoiceLines resets all changes to the "billing_gathering_invoice_lines" edge. +func (m *BillingInvoiceMutation) ResetBillingGatheringInvoiceLines() { + m.billing_gathering_invoice_lines = nil + m.clearedbilling_gathering_invoice_lines = false + m.removedbilling_gathering_invoice_lines = nil +} + // AddBillingInvoiceDetailedLineIDs adds the "billing_invoice_detailed_lines" edge to the BillingStandardInvoiceDetailedLine entity by ids. func (m *BillingInvoiceMutation) AddBillingInvoiceDetailedLineIDs(ids ...string) { if m.billing_invoice_detailed_lines == nil { @@ -16558,7 +19257,7 @@ func (m *BillingInvoiceMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *BillingInvoiceMutation) AddedEdges() []string { - edges := make([]string, 0, 11) + edges := make([]string, 0, 12) if m.source_billing_profile != nil { edges = append(edges, billinginvoice.EdgeSourceBillingProfile) } @@ -16568,6 +19267,9 @@ func (m *BillingInvoiceMutation) AddedEdges() []string { if m.billing_invoice_lines != nil { edges = append(edges, billinginvoice.EdgeBillingInvoiceLines) } + if m.billing_gathering_invoice_lines != nil { + edges = append(edges, billinginvoice.EdgeBillingGatheringInvoiceLines) + } if m.billing_invoice_detailed_lines != nil { edges = append(edges, billinginvoice.EdgeBillingInvoiceDetailedLines) } @@ -16613,6 +19315,12 @@ func (m *BillingInvoiceMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case billinginvoice.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.billing_gathering_invoice_lines)) + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case billinginvoice.EdgeBillingInvoiceDetailedLines: ids := make([]ent.Value, 0, len(m.billing_invoice_detailed_lines)) for id := range m.billing_invoice_detailed_lines { @@ -16659,10 +19367,13 @@ func (m *BillingInvoiceMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *BillingInvoiceMutation) RemovedEdges() []string { - edges := make([]string, 0, 11) + edges := make([]string, 0, 12) if m.removedbilling_invoice_lines != nil { edges = append(edges, billinginvoice.EdgeBillingInvoiceLines) } + if m.removedbilling_gathering_invoice_lines != nil { + edges = append(edges, billinginvoice.EdgeBillingGatheringInvoiceLines) + } if m.removedbilling_invoice_detailed_lines != nil { edges = append(edges, billinginvoice.EdgeBillingInvoiceDetailedLines) } @@ -16688,6 +19399,12 @@ func (m *BillingInvoiceMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case billinginvoice.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.removedbilling_gathering_invoice_lines)) + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case billinginvoice.EdgeBillingInvoiceDetailedLines: ids := make([]ent.Value, 0, len(m.removedbilling_invoice_detailed_lines)) for id := range m.removedbilling_invoice_detailed_lines { @@ -16718,7 +19435,7 @@ func (m *BillingInvoiceMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *BillingInvoiceMutation) ClearedEdges() []string { - edges := make([]string, 0, 11) + edges := make([]string, 0, 12) if m.clearedsource_billing_profile { edges = append(edges, billinginvoice.EdgeSourceBillingProfile) } @@ -16728,6 +19445,9 @@ func (m *BillingInvoiceMutation) ClearedEdges() []string { if m.clearedbilling_invoice_lines { edges = append(edges, billinginvoice.EdgeBillingInvoiceLines) } + if m.clearedbilling_gathering_invoice_lines { + edges = append(edges, billinginvoice.EdgeBillingGatheringInvoiceLines) + } if m.clearedbilling_invoice_detailed_lines { edges = append(edges, billinginvoice.EdgeBillingInvoiceDetailedLines) } @@ -16765,6 +19485,8 @@ func (m *BillingInvoiceMutation) EdgeCleared(name string) bool { return m.clearedbilling_workflow_config case billinginvoice.EdgeBillingInvoiceLines: return m.clearedbilling_invoice_lines + case billinginvoice.EdgeBillingGatheringInvoiceLines: + return m.clearedbilling_gathering_invoice_lines case billinginvoice.EdgeBillingInvoiceDetailedLines: return m.clearedbilling_invoice_detailed_lines case billinginvoice.EdgeBillingInvoiceValidationIssues: @@ -16824,6 +19546,9 @@ func (m *BillingInvoiceMutation) ResetEdge(name string) error { case billinginvoice.EdgeBillingInvoiceLines: m.ResetBillingInvoiceLines() return nil + case billinginvoice.EdgeBillingGatheringInvoiceLines: + m.ResetBillingGatheringInvoiceLines() + return nil case billinginvoice.EdgeBillingInvoiceDetailedLines: m.ResetBillingInvoiceDetailedLines() return nil @@ -23790,40 +26515,43 @@ func (m *BillingInvoiceLineUsageDiscountMutation) ResetEdge(name string) error { // BillingInvoiceSplitLineGroupMutation represents an operation that mutates the BillingInvoiceSplitLineGroup nodes in the graph. type BillingInvoiceSplitLineGroupMutation struct { config - op Op - typ string - id *string - namespace *string - metadata *map[string]string - created_at *time.Time - updated_at *time.Time - deleted_at *time.Time - name *string - description *string - currency *currencyx.Code - service_period_start *time.Time - service_period_end *time.Time - unique_reference_id *string - ratecard_discounts **billing.Discounts - feature_key *string - price **productcatalog.Price - subscription_billing_period_from *time.Time - subscription_billing_period_to *time.Time - clearedFields map[string]struct{} - billing_invoice_lines map[string]struct{} - removedbilling_invoice_lines map[string]struct{} - clearedbilling_invoice_lines bool - subscription *string - clearedsubscription bool - subscription_phase *string - clearedsubscription_phase bool - subscription_item *string - clearedsubscription_item bool - charge *string - clearedcharge bool - done bool - oldValue func(context.Context) (*BillingInvoiceSplitLineGroup, error) - predicates []predicate.BillingInvoiceSplitLineGroup + op Op + typ string + id *string + namespace *string + metadata *map[string]string + created_at *time.Time + updated_at *time.Time + deleted_at *time.Time + name *string + description *string + currency *currencyx.Code + service_period_start *time.Time + service_period_end *time.Time + unique_reference_id *string + ratecard_discounts **billing.Discounts + feature_key *string + price **productcatalog.Price + subscription_billing_period_from *time.Time + subscription_billing_period_to *time.Time + clearedFields map[string]struct{} + billing_invoice_lines map[string]struct{} + removedbilling_invoice_lines map[string]struct{} + clearedbilling_invoice_lines bool + billing_gathering_invoice_lines map[string]struct{} + removedbilling_gathering_invoice_lines map[string]struct{} + clearedbilling_gathering_invoice_lines bool + subscription *string + clearedsubscription bool + subscription_phase *string + clearedsubscription_phase bool + subscription_item *string + clearedsubscription_item bool + charge *string + clearedcharge bool + done bool + oldValue func(context.Context) (*BillingInvoiceSplitLineGroup, error) + predicates []predicate.BillingInvoiceSplitLineGroup } var _ ent.Mutation = (*BillingInvoiceSplitLineGroupMutation)(nil) @@ -24860,6 +27588,60 @@ func (m *BillingInvoiceSplitLineGroupMutation) ResetBillingInvoiceLines() { m.removedbilling_invoice_lines = nil } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by ids. +func (m *BillingInvoiceSplitLineGroupMutation) AddBillingGatheringInvoiceLineIDs(ids ...string) { + if m.billing_gathering_invoice_lines == nil { + m.billing_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + m.billing_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// ClearBillingGatheringInvoiceLines clears the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *BillingInvoiceSplitLineGroupMutation) ClearBillingGatheringInvoiceLines() { + m.clearedbilling_gathering_invoice_lines = true +} + +// BillingGatheringInvoiceLinesCleared reports if the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity was cleared. +func (m *BillingInvoiceSplitLineGroupMutation) BillingGatheringInvoiceLinesCleared() bool { + return m.clearedbilling_gathering_invoice_lines +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (m *BillingInvoiceSplitLineGroupMutation) RemoveBillingGatheringInvoiceLineIDs(ids ...string) { + if m.removedbilling_gathering_invoice_lines == nil { + m.removedbilling_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + delete(m.billing_gathering_invoice_lines, ids[i]) + m.removedbilling_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// RemovedBillingGatheringInvoiceLines returns the removed IDs of the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *BillingInvoiceSplitLineGroupMutation) RemovedBillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// BillingGatheringInvoiceLinesIDs returns the "billing_gathering_invoice_lines" edge IDs in the mutation. +func (m *BillingInvoiceSplitLineGroupMutation) BillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// ResetBillingGatheringInvoiceLines resets all changes to the "billing_gathering_invoice_lines" edge. +func (m *BillingInvoiceSplitLineGroupMutation) ResetBillingGatheringInvoiceLines() { + m.billing_gathering_invoice_lines = nil + m.clearedbilling_gathering_invoice_lines = false + m.removedbilling_gathering_invoice_lines = nil +} + // ClearSubscription clears the "subscription" edge to the Subscription entity. func (m *BillingInvoiceSplitLineGroupMutation) ClearSubscription() { m.clearedsubscription = true @@ -25499,10 +28281,13 @@ func (m *BillingInvoiceSplitLineGroupMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *BillingInvoiceSplitLineGroupMutation) AddedEdges() []string { - edges := make([]string, 0, 5) + edges := make([]string, 0, 6) if m.billing_invoice_lines != nil { edges = append(edges, billinginvoicesplitlinegroup.EdgeBillingInvoiceLines) } + if m.billing_gathering_invoice_lines != nil { + edges = append(edges, billinginvoicesplitlinegroup.EdgeBillingGatheringInvoiceLines) + } if m.subscription != nil { edges = append(edges, billinginvoicesplitlinegroup.EdgeSubscription) } @@ -25528,6 +28313,12 @@ func (m *BillingInvoiceSplitLineGroupMutation) AddedIDs(name string) []ent.Value ids = append(ids, id) } return ids + case billinginvoicesplitlinegroup.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.billing_gathering_invoice_lines)) + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case billinginvoicesplitlinegroup.EdgeSubscription: if id := m.subscription; id != nil { return []ent.Value{*id} @@ -25550,10 +28341,13 @@ func (m *BillingInvoiceSplitLineGroupMutation) AddedIDs(name string) []ent.Value // RemovedEdges returns all edge names that were removed in this mutation. func (m *BillingInvoiceSplitLineGroupMutation) RemovedEdges() []string { - edges := make([]string, 0, 5) + edges := make([]string, 0, 6) if m.removedbilling_invoice_lines != nil { edges = append(edges, billinginvoicesplitlinegroup.EdgeBillingInvoiceLines) } + if m.removedbilling_gathering_invoice_lines != nil { + edges = append(edges, billinginvoicesplitlinegroup.EdgeBillingGatheringInvoiceLines) + } return edges } @@ -25567,16 +28361,25 @@ func (m *BillingInvoiceSplitLineGroupMutation) RemovedIDs(name string) []ent.Val ids = append(ids, id) } return ids + case billinginvoicesplitlinegroup.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.removedbilling_gathering_invoice_lines)) + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *BillingInvoiceSplitLineGroupMutation) ClearedEdges() []string { - edges := make([]string, 0, 5) + edges := make([]string, 0, 6) if m.clearedbilling_invoice_lines { edges = append(edges, billinginvoicesplitlinegroup.EdgeBillingInvoiceLines) } + if m.clearedbilling_gathering_invoice_lines { + edges = append(edges, billinginvoicesplitlinegroup.EdgeBillingGatheringInvoiceLines) + } if m.clearedsubscription { edges = append(edges, billinginvoicesplitlinegroup.EdgeSubscription) } @@ -25598,6 +28401,8 @@ func (m *BillingInvoiceSplitLineGroupMutation) EdgeCleared(name string) bool { switch name { case billinginvoicesplitlinegroup.EdgeBillingInvoiceLines: return m.clearedbilling_invoice_lines + case billinginvoicesplitlinegroup.EdgeBillingGatheringInvoiceLines: + return m.clearedbilling_gathering_invoice_lines case billinginvoicesplitlinegroup.EdgeSubscription: return m.clearedsubscription case billinginvoicesplitlinegroup.EdgeSubscriptionPhase: @@ -25637,6 +28442,9 @@ func (m *BillingInvoiceSplitLineGroupMutation) ResetEdge(name string) error { case billinginvoicesplitlinegroup.EdgeBillingInvoiceLines: m.ResetBillingInvoiceLines() return nil + case billinginvoicesplitlinegroup.EdgeBillingGatheringInvoiceLines: + m.ResetBillingGatheringInvoiceLines() + return nil case billinginvoicesplitlinegroup.EdgeSubscription: m.ResetSubscription() return nil @@ -35107,33 +37915,36 @@ func (m *BillingWorkflowConfigMutation) ResetEdge(name string) error { // ChargeMutation represents an operation that mutates the Charge nodes in the graph. type ChargeMutation struct { config - op Op - typ string - id *string - namespace *string - created_at *time.Time - deleted_at *time.Time - unique_reference_id *string - _type *meta.ChargeType - clearedFields map[string]struct{} - flat_fee *string - clearedflat_fee bool - credit_purchase *string - clearedcredit_purchase bool - usage_based *string - clearedusage_based bool - billing_invoice_lines map[string]struct{} - removedbilling_invoice_lines map[string]struct{} - clearedbilling_invoice_lines bool - billing_split_line_groups map[string]struct{} - removedbilling_split_line_groups map[string]struct{} - clearedbilling_split_line_groups bool - credit_realization_lineages map[string]struct{} - removedcredit_realization_lineages map[string]struct{} - clearedcredit_realization_lineages bool - done bool - oldValue func(context.Context) (*Charge, error) - predicates []predicate.Charge + op Op + typ string + id *string + namespace *string + created_at *time.Time + deleted_at *time.Time + unique_reference_id *string + _type *meta.ChargeType + clearedFields map[string]struct{} + flat_fee *string + clearedflat_fee bool + credit_purchase *string + clearedcredit_purchase bool + usage_based *string + clearedusage_based bool + billing_invoice_lines map[string]struct{} + removedbilling_invoice_lines map[string]struct{} + clearedbilling_invoice_lines bool + billing_gathering_invoice_lines map[string]struct{} + removedbilling_gathering_invoice_lines map[string]struct{} + clearedbilling_gathering_invoice_lines bool + billing_split_line_groups map[string]struct{} + removedbilling_split_line_groups map[string]struct{} + clearedbilling_split_line_groups bool + credit_realization_lineages map[string]struct{} + removedcredit_realization_lineages map[string]struct{} + clearedcredit_realization_lineages bool + done bool + oldValue func(context.Context) (*Charge, error) + predicates []predicate.Charge } var _ ent.Mutation = (*ChargeMutation)(nil) @@ -35767,6 +38578,60 @@ func (m *ChargeMutation) ResetBillingInvoiceLines() { m.removedbilling_invoice_lines = nil } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by ids. +func (m *ChargeMutation) AddBillingGatheringInvoiceLineIDs(ids ...string) { + if m.billing_gathering_invoice_lines == nil { + m.billing_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + m.billing_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// ClearBillingGatheringInvoiceLines clears the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *ChargeMutation) ClearBillingGatheringInvoiceLines() { + m.clearedbilling_gathering_invoice_lines = true +} + +// BillingGatheringInvoiceLinesCleared reports if the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity was cleared. +func (m *ChargeMutation) BillingGatheringInvoiceLinesCleared() bool { + return m.clearedbilling_gathering_invoice_lines +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (m *ChargeMutation) RemoveBillingGatheringInvoiceLineIDs(ids ...string) { + if m.removedbilling_gathering_invoice_lines == nil { + m.removedbilling_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + delete(m.billing_gathering_invoice_lines, ids[i]) + m.removedbilling_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// RemovedBillingGatheringInvoiceLines returns the removed IDs of the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *ChargeMutation) RemovedBillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// BillingGatheringInvoiceLinesIDs returns the "billing_gathering_invoice_lines" edge IDs in the mutation. +func (m *ChargeMutation) BillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// ResetBillingGatheringInvoiceLines resets all changes to the "billing_gathering_invoice_lines" edge. +func (m *ChargeMutation) ResetBillingGatheringInvoiceLines() { + m.billing_gathering_invoice_lines = nil + m.clearedbilling_gathering_invoice_lines = false + m.removedbilling_gathering_invoice_lines = nil +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by ids. func (m *ChargeMutation) AddBillingSplitLineGroupIDs(ids ...string) { if m.billing_split_line_groups == nil { @@ -36160,7 +39025,7 @@ func (m *ChargeMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *ChargeMutation) AddedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 7) if m.flat_fee != nil { edges = append(edges, charge.EdgeFlatFee) } @@ -36173,6 +39038,9 @@ func (m *ChargeMutation) AddedEdges() []string { if m.billing_invoice_lines != nil { edges = append(edges, charge.EdgeBillingInvoiceLines) } + if m.billing_gathering_invoice_lines != nil { + edges = append(edges, charge.EdgeBillingGatheringInvoiceLines) + } if m.billing_split_line_groups != nil { edges = append(edges, charge.EdgeBillingSplitLineGroups) } @@ -36204,6 +39072,12 @@ func (m *ChargeMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case charge.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.billing_gathering_invoice_lines)) + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case charge.EdgeBillingSplitLineGroups: ids := make([]ent.Value, 0, len(m.billing_split_line_groups)) for id := range m.billing_split_line_groups { @@ -36222,10 +39096,13 @@ func (m *ChargeMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *ChargeMutation) RemovedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 7) if m.removedbilling_invoice_lines != nil { edges = append(edges, charge.EdgeBillingInvoiceLines) } + if m.removedbilling_gathering_invoice_lines != nil { + edges = append(edges, charge.EdgeBillingGatheringInvoiceLines) + } if m.removedbilling_split_line_groups != nil { edges = append(edges, charge.EdgeBillingSplitLineGroups) } @@ -36245,6 +39122,12 @@ func (m *ChargeMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case charge.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.removedbilling_gathering_invoice_lines)) + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case charge.EdgeBillingSplitLineGroups: ids := make([]ent.Value, 0, len(m.removedbilling_split_line_groups)) for id := range m.removedbilling_split_line_groups { @@ -36263,7 +39146,7 @@ func (m *ChargeMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *ChargeMutation) ClearedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 7) if m.clearedflat_fee { edges = append(edges, charge.EdgeFlatFee) } @@ -36276,6 +39159,9 @@ func (m *ChargeMutation) ClearedEdges() []string { if m.clearedbilling_invoice_lines { edges = append(edges, charge.EdgeBillingInvoiceLines) } + if m.clearedbilling_gathering_invoice_lines { + edges = append(edges, charge.EdgeBillingGatheringInvoiceLines) + } if m.clearedbilling_split_line_groups { edges = append(edges, charge.EdgeBillingSplitLineGroups) } @@ -36297,6 +39183,8 @@ func (m *ChargeMutation) EdgeCleared(name string) bool { return m.clearedusage_based case charge.EdgeBillingInvoiceLines: return m.clearedbilling_invoice_lines + case charge.EdgeBillingGatheringInvoiceLines: + return m.clearedbilling_gathering_invoice_lines case charge.EdgeBillingSplitLineGroups: return m.clearedbilling_split_line_groups case charge.EdgeCreditRealizationLineages: @@ -36338,6 +39226,9 @@ func (m *ChargeMutation) ResetEdge(name string) error { case charge.EdgeBillingInvoiceLines: m.ResetBillingInvoiceLines() return nil + case charge.EdgeBillingGatheringInvoiceLines: + m.ResetBillingGatheringInvoiceLines() + return nil case charge.EdgeBillingSplitLineGroups: m.ResetBillingSplitLineGroups() return nil @@ -104793,55 +107684,58 @@ func (m *SubjectMutation) ResetEdge(name string) error { // SubscriptionMutation represents an operation that mutates the Subscription nodes in the graph. type SubscriptionMutation struct { config - op Op - typ string - id *string - namespace *string - annotations *models.Annotations - created_at *time.Time - updated_at *time.Time - deleted_at *time.Time - metadata *map[string]string - active_from *time.Time - active_to *time.Time - name *string - description *string - currency *currencyx.Code - billing_anchor *time.Time - billing_cadence *datetime.ISODurationString - pro_rating_config *productcatalog.ProRatingConfig - settlement_mode *productcatalog.SettlementMode - clearedFields map[string]struct{} - plan *string - clearedplan bool - customer *string - clearedcustomer bool - phases map[string]struct{} - removedphases map[string]struct{} - clearedphases bool - billing_lines map[string]struct{} - removedbilling_lines map[string]struct{} - clearedbilling_lines bool - billing_split_line_groups map[string]struct{} - removedbilling_split_line_groups map[string]struct{} - clearedbilling_split_line_groups bool - charges_usage_based map[string]struct{} - removedcharges_usage_based map[string]struct{} - clearedcharges_usage_based bool - charges_credit_purchase map[string]struct{} - removedcharges_credit_purchase map[string]struct{} - clearedcharges_credit_purchase bool - charges_flat_fee map[string]struct{} - removedcharges_flat_fee map[string]struct{} - clearedcharges_flat_fee bool - addons map[string]struct{} - removedaddons map[string]struct{} - clearedaddons bool - billing_sync_state *string - clearedbilling_sync_state bool - done bool - oldValue func(context.Context) (*Subscription, error) - predicates []predicate.Subscription + op Op + typ string + id *string + namespace *string + annotations *models.Annotations + created_at *time.Time + updated_at *time.Time + deleted_at *time.Time + metadata *map[string]string + active_from *time.Time + active_to *time.Time + name *string + description *string + currency *currencyx.Code + billing_anchor *time.Time + billing_cadence *datetime.ISODurationString + pro_rating_config *productcatalog.ProRatingConfig + settlement_mode *productcatalog.SettlementMode + clearedFields map[string]struct{} + plan *string + clearedplan bool + customer *string + clearedcustomer bool + phases map[string]struct{} + removedphases map[string]struct{} + clearedphases bool + billing_lines map[string]struct{} + removedbilling_lines map[string]struct{} + clearedbilling_lines bool + billing_gathering_invoice_lines map[string]struct{} + removedbilling_gathering_invoice_lines map[string]struct{} + clearedbilling_gathering_invoice_lines bool + billing_split_line_groups map[string]struct{} + removedbilling_split_line_groups map[string]struct{} + clearedbilling_split_line_groups bool + charges_usage_based map[string]struct{} + removedcharges_usage_based map[string]struct{} + clearedcharges_usage_based bool + charges_credit_purchase map[string]struct{} + removedcharges_credit_purchase map[string]struct{} + clearedcharges_credit_purchase bool + charges_flat_fee map[string]struct{} + removedcharges_flat_fee map[string]struct{} + clearedcharges_flat_fee bool + addons map[string]struct{} + removedaddons map[string]struct{} + clearedaddons bool + billing_sync_state *string + clearedbilling_sync_state bool + done bool + oldValue func(context.Context) (*Subscription, error) + predicates []predicate.Subscription } var _ ent.Mutation = (*SubscriptionMutation)(nil) @@ -105800,6 +108694,60 @@ func (m *SubscriptionMutation) ResetBillingLines() { m.removedbilling_lines = nil } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by ids. +func (m *SubscriptionMutation) AddBillingGatheringInvoiceLineIDs(ids ...string) { + if m.billing_gathering_invoice_lines == nil { + m.billing_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + m.billing_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// ClearBillingGatheringInvoiceLines clears the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *SubscriptionMutation) ClearBillingGatheringInvoiceLines() { + m.clearedbilling_gathering_invoice_lines = true +} + +// BillingGatheringInvoiceLinesCleared reports if the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity was cleared. +func (m *SubscriptionMutation) BillingGatheringInvoiceLinesCleared() bool { + return m.clearedbilling_gathering_invoice_lines +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (m *SubscriptionMutation) RemoveBillingGatheringInvoiceLineIDs(ids ...string) { + if m.removedbilling_gathering_invoice_lines == nil { + m.removedbilling_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + delete(m.billing_gathering_invoice_lines, ids[i]) + m.removedbilling_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// RemovedBillingGatheringInvoiceLines returns the removed IDs of the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *SubscriptionMutation) RemovedBillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// BillingGatheringInvoiceLinesIDs returns the "billing_gathering_invoice_lines" edge IDs in the mutation. +func (m *SubscriptionMutation) BillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// ResetBillingGatheringInvoiceLines resets all changes to the "billing_gathering_invoice_lines" edge. +func (m *SubscriptionMutation) ResetBillingGatheringInvoiceLines() { + m.billing_gathering_invoice_lines = nil + m.clearedbilling_gathering_invoice_lines = false + m.removedbilling_gathering_invoice_lines = nil +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by ids. func (m *SubscriptionMutation) AddBillingSplitLineGroupIDs(ids ...string) { if m.billing_split_line_groups == nil { @@ -106553,7 +109501,7 @@ func (m *SubscriptionMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *SubscriptionMutation) AddedEdges() []string { - edges := make([]string, 0, 10) + edges := make([]string, 0, 11) if m.plan != nil { edges = append(edges, subscription.EdgePlan) } @@ -106566,6 +109514,9 @@ func (m *SubscriptionMutation) AddedEdges() []string { if m.billing_lines != nil { edges = append(edges, subscription.EdgeBillingLines) } + if m.billing_gathering_invoice_lines != nil { + edges = append(edges, subscription.EdgeBillingGatheringInvoiceLines) + } if m.billing_split_line_groups != nil { edges = append(edges, subscription.EdgeBillingSplitLineGroups) } @@ -106611,6 +109562,12 @@ func (m *SubscriptionMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case subscription.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.billing_gathering_invoice_lines)) + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case subscription.EdgeBillingSplitLineGroups: ids := make([]ent.Value, 0, len(m.billing_split_line_groups)) for id := range m.billing_split_line_groups { @@ -106651,13 +109608,16 @@ func (m *SubscriptionMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *SubscriptionMutation) RemovedEdges() []string { - edges := make([]string, 0, 10) + edges := make([]string, 0, 11) if m.removedphases != nil { edges = append(edges, subscription.EdgePhases) } if m.removedbilling_lines != nil { edges = append(edges, subscription.EdgeBillingLines) } + if m.removedbilling_gathering_invoice_lines != nil { + edges = append(edges, subscription.EdgeBillingGatheringInvoiceLines) + } if m.removedbilling_split_line_groups != nil { edges = append(edges, subscription.EdgeBillingSplitLineGroups) } @@ -106692,6 +109652,12 @@ func (m *SubscriptionMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case subscription.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.removedbilling_gathering_invoice_lines)) + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case subscription.EdgeBillingSplitLineGroups: ids := make([]ent.Value, 0, len(m.removedbilling_split_line_groups)) for id := range m.removedbilling_split_line_groups { @@ -106728,7 +109694,7 @@ func (m *SubscriptionMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SubscriptionMutation) ClearedEdges() []string { - edges := make([]string, 0, 10) + edges := make([]string, 0, 11) if m.clearedplan { edges = append(edges, subscription.EdgePlan) } @@ -106741,6 +109707,9 @@ func (m *SubscriptionMutation) ClearedEdges() []string { if m.clearedbilling_lines { edges = append(edges, subscription.EdgeBillingLines) } + if m.clearedbilling_gathering_invoice_lines { + edges = append(edges, subscription.EdgeBillingGatheringInvoiceLines) + } if m.clearedbilling_split_line_groups { edges = append(edges, subscription.EdgeBillingSplitLineGroups) } @@ -106774,6 +109743,8 @@ func (m *SubscriptionMutation) EdgeCleared(name string) bool { return m.clearedphases case subscription.EdgeBillingLines: return m.clearedbilling_lines + case subscription.EdgeBillingGatheringInvoiceLines: + return m.clearedbilling_gathering_invoice_lines case subscription.EdgeBillingSplitLineGroups: return m.clearedbilling_split_line_groups case subscription.EdgeChargesUsageBased: @@ -106823,6 +109794,9 @@ func (m *SubscriptionMutation) ResetEdge(name string) error { case subscription.EdgeBillingLines: m.ResetBillingLines() return nil + case subscription.EdgeBillingGatheringInvoiceLines: + m.ResetBillingGatheringInvoiceLines() + return nil case subscription.EdgeBillingSplitLineGroups: m.ResetBillingSplitLineGroups() return nil @@ -109155,6 +112129,9 @@ type SubscriptionItemMutation struct { billing_lines map[string]struct{} removedbilling_lines map[string]struct{} clearedbilling_lines bool + billing_gathering_invoice_lines map[string]struct{} + removedbilling_gathering_invoice_lines map[string]struct{} + clearedbilling_gathering_invoice_lines bool billing_split_line_groups map[string]struct{} removedbilling_split_line_groups map[string]struct{} clearedbilling_split_line_groups bool @@ -110520,6 +113497,60 @@ func (m *SubscriptionItemMutation) ResetBillingLines() { m.removedbilling_lines = nil } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by ids. +func (m *SubscriptionItemMutation) AddBillingGatheringInvoiceLineIDs(ids ...string) { + if m.billing_gathering_invoice_lines == nil { + m.billing_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + m.billing_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// ClearBillingGatheringInvoiceLines clears the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *SubscriptionItemMutation) ClearBillingGatheringInvoiceLines() { + m.clearedbilling_gathering_invoice_lines = true +} + +// BillingGatheringInvoiceLinesCleared reports if the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity was cleared. +func (m *SubscriptionItemMutation) BillingGatheringInvoiceLinesCleared() bool { + return m.clearedbilling_gathering_invoice_lines +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (m *SubscriptionItemMutation) RemoveBillingGatheringInvoiceLineIDs(ids ...string) { + if m.removedbilling_gathering_invoice_lines == nil { + m.removedbilling_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + delete(m.billing_gathering_invoice_lines, ids[i]) + m.removedbilling_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// RemovedBillingGatheringInvoiceLines returns the removed IDs of the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *SubscriptionItemMutation) RemovedBillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// BillingGatheringInvoiceLinesIDs returns the "billing_gathering_invoice_lines" edge IDs in the mutation. +func (m *SubscriptionItemMutation) BillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// ResetBillingGatheringInvoiceLines resets all changes to the "billing_gathering_invoice_lines" edge. +func (m *SubscriptionItemMutation) ResetBillingGatheringInvoiceLines() { + m.billing_gathering_invoice_lines = nil + m.clearedbilling_gathering_invoice_lines = false + m.removedbilling_gathering_invoice_lines = nil +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by ids. func (m *SubscriptionItemMutation) AddBillingSplitLineGroupIDs(ids ...string) { if m.billing_split_line_groups == nil { @@ -111415,7 +114446,7 @@ func (m *SubscriptionItemMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *SubscriptionItemMutation) AddedEdges() []string { - edges := make([]string, 0, 8) + edges := make([]string, 0, 9) if m.phase != nil { edges = append(edges, subscriptionitem.EdgePhase) } @@ -111425,6 +114456,9 @@ func (m *SubscriptionItemMutation) AddedEdges() []string { if m.billing_lines != nil { edges = append(edges, subscriptionitem.EdgeBillingLines) } + if m.billing_gathering_invoice_lines != nil { + edges = append(edges, subscriptionitem.EdgeBillingGatheringInvoiceLines) + } if m.billing_split_line_groups != nil { edges = append(edges, subscriptionitem.EdgeBillingSplitLineGroups) } @@ -111461,6 +114495,12 @@ func (m *SubscriptionItemMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case subscriptionitem.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.billing_gathering_invoice_lines)) + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case subscriptionitem.EdgeBillingSplitLineGroups: ids := make([]ent.Value, 0, len(m.billing_split_line_groups)) for id := range m.billing_split_line_groups { @@ -111495,10 +114535,13 @@ func (m *SubscriptionItemMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *SubscriptionItemMutation) RemovedEdges() []string { - edges := make([]string, 0, 8) + edges := make([]string, 0, 9) if m.removedbilling_lines != nil { edges = append(edges, subscriptionitem.EdgeBillingLines) } + if m.removedbilling_gathering_invoice_lines != nil { + edges = append(edges, subscriptionitem.EdgeBillingGatheringInvoiceLines) + } if m.removedbilling_split_line_groups != nil { edges = append(edges, subscriptionitem.EdgeBillingSplitLineGroups) } @@ -111524,6 +114567,12 @@ func (m *SubscriptionItemMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case subscriptionitem.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.removedbilling_gathering_invoice_lines)) + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case subscriptionitem.EdgeBillingSplitLineGroups: ids := make([]ent.Value, 0, len(m.removedbilling_split_line_groups)) for id := range m.removedbilling_split_line_groups { @@ -111554,7 +114603,7 @@ func (m *SubscriptionItemMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SubscriptionItemMutation) ClearedEdges() []string { - edges := make([]string, 0, 8) + edges := make([]string, 0, 9) if m.clearedphase { edges = append(edges, subscriptionitem.EdgePhase) } @@ -111564,6 +114613,9 @@ func (m *SubscriptionItemMutation) ClearedEdges() []string { if m.clearedbilling_lines { edges = append(edges, subscriptionitem.EdgeBillingLines) } + if m.clearedbilling_gathering_invoice_lines { + edges = append(edges, subscriptionitem.EdgeBillingGatheringInvoiceLines) + } if m.clearedbilling_split_line_groups { edges = append(edges, subscriptionitem.EdgeBillingSplitLineGroups) } @@ -111592,6 +114644,8 @@ func (m *SubscriptionItemMutation) EdgeCleared(name string) bool { return m.clearedentitlement case subscriptionitem.EdgeBillingLines: return m.clearedbilling_lines + case subscriptionitem.EdgeBillingGatheringInvoiceLines: + return m.clearedbilling_gathering_invoice_lines case subscriptionitem.EdgeBillingSplitLineGroups: return m.clearedbilling_split_line_groups case subscriptionitem.EdgeChargesUsageBased: @@ -111636,6 +114690,9 @@ func (m *SubscriptionItemMutation) ResetEdge(name string) error { case subscriptionitem.EdgeBillingLines: m.ResetBillingLines() return nil + case subscriptionitem.EdgeBillingGatheringInvoiceLines: + m.ResetBillingGatheringInvoiceLines() + return nil case subscriptionitem.EdgeBillingSplitLineGroups: m.ResetBillingSplitLineGroups() return nil @@ -111658,44 +114715,47 @@ func (m *SubscriptionItemMutation) ResetEdge(name string) error { // SubscriptionPhaseMutation represents an operation that mutates the SubscriptionPhase nodes in the graph. type SubscriptionPhaseMutation struct { config - op Op - typ string - id *string - namespace *string - created_at *time.Time - updated_at *time.Time - deleted_at *time.Time - metadata *map[string]string - key *string - name *string - description *string - active_from *time.Time - sort_hint *uint8 - addsort_hint *int8 - clearedFields map[string]struct{} - subscription *string - clearedsubscription bool - items map[string]struct{} - removeditems map[string]struct{} - cleareditems bool - billing_lines map[string]struct{} - removedbilling_lines map[string]struct{} - clearedbilling_lines bool - billing_split_line_groups map[string]struct{} - removedbilling_split_line_groups map[string]struct{} - clearedbilling_split_line_groups bool - charges_usage_based map[string]struct{} - removedcharges_usage_based map[string]struct{} - clearedcharges_usage_based bool - charges_credit_purchase map[string]struct{} - removedcharges_credit_purchase map[string]struct{} - clearedcharges_credit_purchase bool - charges_flat_fee map[string]struct{} - removedcharges_flat_fee map[string]struct{} - clearedcharges_flat_fee bool - done bool - oldValue func(context.Context) (*SubscriptionPhase, error) - predicates []predicate.SubscriptionPhase + op Op + typ string + id *string + namespace *string + created_at *time.Time + updated_at *time.Time + deleted_at *time.Time + metadata *map[string]string + key *string + name *string + description *string + active_from *time.Time + sort_hint *uint8 + addsort_hint *int8 + clearedFields map[string]struct{} + subscription *string + clearedsubscription bool + items map[string]struct{} + removeditems map[string]struct{} + cleareditems bool + billing_lines map[string]struct{} + removedbilling_lines map[string]struct{} + clearedbilling_lines bool + billing_gathering_invoice_lines map[string]struct{} + removedbilling_gathering_invoice_lines map[string]struct{} + clearedbilling_gathering_invoice_lines bool + billing_split_line_groups map[string]struct{} + removedbilling_split_line_groups map[string]struct{} + clearedbilling_split_line_groups bool + charges_usage_based map[string]struct{} + removedcharges_usage_based map[string]struct{} + clearedcharges_usage_based bool + charges_credit_purchase map[string]struct{} + removedcharges_credit_purchase map[string]struct{} + clearedcharges_credit_purchase bool + charges_flat_fee map[string]struct{} + removedcharges_flat_fee map[string]struct{} + clearedcharges_flat_fee bool + done bool + oldValue func(context.Context) (*SubscriptionPhase, error) + predicates []predicate.SubscriptionPhase } var _ ent.Mutation = (*SubscriptionPhaseMutation)(nil) @@ -112406,6 +115466,60 @@ func (m *SubscriptionPhaseMutation) ResetBillingLines() { m.removedbilling_lines = nil } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by ids. +func (m *SubscriptionPhaseMutation) AddBillingGatheringInvoiceLineIDs(ids ...string) { + if m.billing_gathering_invoice_lines == nil { + m.billing_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + m.billing_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// ClearBillingGatheringInvoiceLines clears the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *SubscriptionPhaseMutation) ClearBillingGatheringInvoiceLines() { + m.clearedbilling_gathering_invoice_lines = true +} + +// BillingGatheringInvoiceLinesCleared reports if the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity was cleared. +func (m *SubscriptionPhaseMutation) BillingGatheringInvoiceLinesCleared() bool { + return m.clearedbilling_gathering_invoice_lines +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (m *SubscriptionPhaseMutation) RemoveBillingGatheringInvoiceLineIDs(ids ...string) { + if m.removedbilling_gathering_invoice_lines == nil { + m.removedbilling_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + delete(m.billing_gathering_invoice_lines, ids[i]) + m.removedbilling_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// RemovedBillingGatheringInvoiceLines returns the removed IDs of the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *SubscriptionPhaseMutation) RemovedBillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// BillingGatheringInvoiceLinesIDs returns the "billing_gathering_invoice_lines" edge IDs in the mutation. +func (m *SubscriptionPhaseMutation) BillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// ResetBillingGatheringInvoiceLines resets all changes to the "billing_gathering_invoice_lines" edge. +func (m *SubscriptionPhaseMutation) ResetBillingGatheringInvoiceLines() { + m.billing_gathering_invoice_lines = nil + m.clearedbilling_gathering_invoice_lines = false + m.removedbilling_gathering_invoice_lines = nil +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by ids. func (m *SubscriptionPhaseMutation) AddBillingSplitLineGroupIDs(ids ...string) { if m.billing_split_line_groups == nil { @@ -112967,7 +116081,7 @@ func (m *SubscriptionPhaseMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *SubscriptionPhaseMutation) AddedEdges() []string { - edges := make([]string, 0, 7) + edges := make([]string, 0, 8) if m.subscription != nil { edges = append(edges, subscriptionphase.EdgeSubscription) } @@ -112977,6 +116091,9 @@ func (m *SubscriptionPhaseMutation) AddedEdges() []string { if m.billing_lines != nil { edges = append(edges, subscriptionphase.EdgeBillingLines) } + if m.billing_gathering_invoice_lines != nil { + edges = append(edges, subscriptionphase.EdgeBillingGatheringInvoiceLines) + } if m.billing_split_line_groups != nil { edges = append(edges, subscriptionphase.EdgeBillingSplitLineGroups) } @@ -113012,6 +116129,12 @@ func (m *SubscriptionPhaseMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case subscriptionphase.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.billing_gathering_invoice_lines)) + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case subscriptionphase.EdgeBillingSplitLineGroups: ids := make([]ent.Value, 0, len(m.billing_split_line_groups)) for id := range m.billing_split_line_groups { @@ -113042,13 +116165,16 @@ func (m *SubscriptionPhaseMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *SubscriptionPhaseMutation) RemovedEdges() []string { - edges := make([]string, 0, 7) + edges := make([]string, 0, 8) if m.removeditems != nil { edges = append(edges, subscriptionphase.EdgeItems) } if m.removedbilling_lines != nil { edges = append(edges, subscriptionphase.EdgeBillingLines) } + if m.removedbilling_gathering_invoice_lines != nil { + edges = append(edges, subscriptionphase.EdgeBillingGatheringInvoiceLines) + } if m.removedbilling_split_line_groups != nil { edges = append(edges, subscriptionphase.EdgeBillingSplitLineGroups) } @@ -113080,6 +116206,12 @@ func (m *SubscriptionPhaseMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case subscriptionphase.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.removedbilling_gathering_invoice_lines)) + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case subscriptionphase.EdgeBillingSplitLineGroups: ids := make([]ent.Value, 0, len(m.removedbilling_split_line_groups)) for id := range m.removedbilling_split_line_groups { @@ -113110,7 +116242,7 @@ func (m *SubscriptionPhaseMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SubscriptionPhaseMutation) ClearedEdges() []string { - edges := make([]string, 0, 7) + edges := make([]string, 0, 8) if m.clearedsubscription { edges = append(edges, subscriptionphase.EdgeSubscription) } @@ -113120,6 +116252,9 @@ func (m *SubscriptionPhaseMutation) ClearedEdges() []string { if m.clearedbilling_lines { edges = append(edges, subscriptionphase.EdgeBillingLines) } + if m.clearedbilling_gathering_invoice_lines { + edges = append(edges, subscriptionphase.EdgeBillingGatheringInvoiceLines) + } if m.clearedbilling_split_line_groups { edges = append(edges, subscriptionphase.EdgeBillingSplitLineGroups) } @@ -113145,6 +116280,8 @@ func (m *SubscriptionPhaseMutation) EdgeCleared(name string) bool { return m.cleareditems case subscriptionphase.EdgeBillingLines: return m.clearedbilling_lines + case subscriptionphase.EdgeBillingGatheringInvoiceLines: + return m.clearedbilling_gathering_invoice_lines case subscriptionphase.EdgeBillingSplitLineGroups: return m.clearedbilling_split_line_groups case subscriptionphase.EdgeChargesUsageBased: @@ -113181,6 +116318,9 @@ func (m *SubscriptionPhaseMutation) ResetEdge(name string) error { case subscriptionphase.EdgeBillingLines: m.ResetBillingLines() return nil + case subscriptionphase.EdgeBillingGatheringInvoiceLines: + m.ResetBillingGatheringInvoiceLines() + return nil case subscriptionphase.EdgeBillingSplitLineGroups: m.ResetBillingSplitLineGroups() return nil @@ -113223,6 +116363,9 @@ type TaxCodeMutation struct { billing_invoice_lines map[string]struct{} removedbilling_invoice_lines map[string]struct{} clearedbilling_invoice_lines bool + billing_gathering_invoice_lines map[string]struct{} + removedbilling_gathering_invoice_lines map[string]struct{} + clearedbilling_gathering_invoice_lines bool subscription_items map[string]struct{} removedsubscription_items map[string]struct{} clearedsubscription_items bool @@ -113949,6 +117092,60 @@ func (m *TaxCodeMutation) ResetBillingInvoiceLines() { m.removedbilling_invoice_lines = nil } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by ids. +func (m *TaxCodeMutation) AddBillingGatheringInvoiceLineIDs(ids ...string) { + if m.billing_gathering_invoice_lines == nil { + m.billing_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + m.billing_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// ClearBillingGatheringInvoiceLines clears the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *TaxCodeMutation) ClearBillingGatheringInvoiceLines() { + m.clearedbilling_gathering_invoice_lines = true +} + +// BillingGatheringInvoiceLinesCleared reports if the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity was cleared. +func (m *TaxCodeMutation) BillingGatheringInvoiceLinesCleared() bool { + return m.clearedbilling_gathering_invoice_lines +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (m *TaxCodeMutation) RemoveBillingGatheringInvoiceLineIDs(ids ...string) { + if m.removedbilling_gathering_invoice_lines == nil { + m.removedbilling_gathering_invoice_lines = make(map[string]struct{}) + } + for i := range ids { + delete(m.billing_gathering_invoice_lines, ids[i]) + m.removedbilling_gathering_invoice_lines[ids[i]] = struct{}{} + } +} + +// RemovedBillingGatheringInvoiceLines returns the removed IDs of the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity. +func (m *TaxCodeMutation) RemovedBillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// BillingGatheringInvoiceLinesIDs returns the "billing_gathering_invoice_lines" edge IDs in the mutation. +func (m *TaxCodeMutation) BillingGatheringInvoiceLinesIDs() (ids []string) { + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return +} + +// ResetBillingGatheringInvoiceLines resets all changes to the "billing_gathering_invoice_lines" edge. +func (m *TaxCodeMutation) ResetBillingGatheringInvoiceLines() { + m.billing_gathering_invoice_lines = nil + m.clearedbilling_gathering_invoice_lines = false + m.removedbilling_gathering_invoice_lines = nil +} + // AddSubscriptionItemIDs adds the "subscription_items" edge to the SubscriptionItem entity by ids. func (m *TaxCodeMutation) AddSubscriptionItemIDs(ids ...string) { if m.subscription_items == nil { @@ -114808,7 +118005,7 @@ func (m *TaxCodeMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *TaxCodeMutation) AddedEdges() []string { - edges := make([]string, 0, 13) + edges := make([]string, 0, 14) if m.billing_workflow_configs != nil { edges = append(edges, dbtaxcode.EdgeBillingWorkflowConfigs) } @@ -114818,6 +118015,9 @@ func (m *TaxCodeMutation) AddedEdges() []string { if m.billing_invoice_lines != nil { edges = append(edges, dbtaxcode.EdgeBillingInvoiceLines) } + if m.billing_gathering_invoice_lines != nil { + edges = append(edges, dbtaxcode.EdgeBillingGatheringInvoiceLines) + } if m.subscription_items != nil { edges = append(edges, dbtaxcode.EdgeSubscriptionItems) } @@ -114873,6 +118073,12 @@ func (m *TaxCodeMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case dbtaxcode.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.billing_gathering_invoice_lines)) + for id := range m.billing_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case dbtaxcode.EdgeSubscriptionItems: ids := make([]ent.Value, 0, len(m.subscription_items)) for id := range m.subscription_items { @@ -114939,7 +118145,7 @@ func (m *TaxCodeMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *TaxCodeMutation) RemovedEdges() []string { - edges := make([]string, 0, 13) + edges := make([]string, 0, 14) if m.removedbilling_workflow_configs != nil { edges = append(edges, dbtaxcode.EdgeBillingWorkflowConfigs) } @@ -114949,6 +118155,9 @@ func (m *TaxCodeMutation) RemovedEdges() []string { if m.removedbilling_invoice_lines != nil { edges = append(edges, dbtaxcode.EdgeBillingInvoiceLines) } + if m.removedbilling_gathering_invoice_lines != nil { + edges = append(edges, dbtaxcode.EdgeBillingGatheringInvoiceLines) + } if m.removedsubscription_items != nil { edges = append(edges, dbtaxcode.EdgeSubscriptionItems) } @@ -115004,6 +118213,12 @@ func (m *TaxCodeMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case dbtaxcode.EdgeBillingGatheringInvoiceLines: + ids := make([]ent.Value, 0, len(m.removedbilling_gathering_invoice_lines)) + for id := range m.removedbilling_gathering_invoice_lines { + ids = append(ids, id) + } + return ids case dbtaxcode.EdgeSubscriptionItems: ids := make([]ent.Value, 0, len(m.removedsubscription_items)) for id := range m.removedsubscription_items { @@ -115070,7 +118285,7 @@ func (m *TaxCodeMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *TaxCodeMutation) ClearedEdges() []string { - edges := make([]string, 0, 13) + edges := make([]string, 0, 14) if m.clearedbilling_workflow_configs { edges = append(edges, dbtaxcode.EdgeBillingWorkflowConfigs) } @@ -115080,6 +118295,9 @@ func (m *TaxCodeMutation) ClearedEdges() []string { if m.clearedbilling_invoice_lines { edges = append(edges, dbtaxcode.EdgeBillingInvoiceLines) } + if m.clearedbilling_gathering_invoice_lines { + edges = append(edges, dbtaxcode.EdgeBillingGatheringInvoiceLines) + } if m.clearedsubscription_items { edges = append(edges, dbtaxcode.EdgeSubscriptionItems) } @@ -115123,6 +118341,8 @@ func (m *TaxCodeMutation) EdgeCleared(name string) bool { return m.clearedbilling_customer_overrides case dbtaxcode.EdgeBillingInvoiceLines: return m.clearedbilling_invoice_lines + case dbtaxcode.EdgeBillingGatheringInvoiceLines: + return m.clearedbilling_gathering_invoice_lines case dbtaxcode.EdgeSubscriptionItems: return m.clearedsubscription_items case dbtaxcode.EdgePlanRateCards: @@ -115168,6 +118388,9 @@ func (m *TaxCodeMutation) ResetEdge(name string) error { case dbtaxcode.EdgeBillingInvoiceLines: m.ResetBillingInvoiceLines() return nil + case dbtaxcode.EdgeBillingGatheringInvoiceLines: + m.ResetBillingGatheringInvoiceLines() + return nil case dbtaxcode.EdgeSubscriptionItems: m.ResetSubscriptionItems() return nil diff --git a/openmeter/ent/db/paginate.go b/openmeter/ent/db/paginate.go index bd7a7c9ce5..3ad0f3fd89 100644 --- a/openmeter/ent/db/paginate.go +++ b/openmeter/ent/db/paginate.go @@ -647,6 +647,64 @@ func (_m *BillingCustomerOverrideQuery) Paginate(ctx context.Context, page pagin // type check var _ pagination.Paginator[*BillingCustomerOverride] = (*BillingCustomerOverrideQuery)(nil) +// Paginate runs the query and returns a paginated response. +// If page is its 0 value then it will return all the items and populate the response page accordingly. +func (_m *BillingGatheringInvoiceLineQuery) Paginate(ctx context.Context, page pagination.Page) (pagination.Result[*BillingGatheringInvoiceLine], error) { + // Get the limit and offset + limit, offset := page.Limit(), page.Offset() + + // Unset previous pagination settings + zero := 0 + _m.ctx.Offset = &zero + _m.ctx.Limit = &zero + + // Create duplicate of the query to run for + countQuery := _m.Clone() + pagedQuery := _m + + // Unset select for count query + countQuery.ctx.Fields = []string{} + + // Unset ordering for count query + countQuery.order = nil + + pagedResponse := pagination.Result[*BillingGatheringInvoiceLine]{ + Page: page, + } + + // Get the total count + count, err := countQuery.Count(ctx) + if err != nil { + return pagedResponse, fmt.Errorf("failed to get count: %w", err) + } + pagedResponse.TotalCount = count + + // If there are no items, return the empty response early + if count == 0 { + // Items should be [] not null. + pagedResponse.Items = make([]*BillingGatheringInvoiceLine, 0) + return pagedResponse, nil + } + + // If page is its 0 value then return all the items + if page.IsZero() { + offset = 0 + limit = count + } + + // Set the limit and offset + pagedQuery.ctx.Limit = &limit + pagedQuery.ctx.Offset = &offset + + // Get the paged items + items, err := pagedQuery.All(ctx) + pagedResponse.Items = items + return pagedResponse, err +} + +// type check +var _ pagination.Paginator[*BillingGatheringInvoiceLine] = (*BillingGatheringInvoiceLineQuery)(nil) + // Paginate runs the query and returns a paginated response. // If page is its 0 value then it will return all the items and populate the response page accordingly. func (_m *BillingInvoiceQuery) Paginate(ctx context.Context, page pagination.Page) (pagination.Result[*BillingInvoice], error) { diff --git a/openmeter/ent/db/predicate/predicate.go b/openmeter/ent/db/predicate/predicate.go index 49f0762a83..0b3d65d810 100644 --- a/openmeter/ent/db/predicate/predicate.go +++ b/openmeter/ent/db/predicate/predicate.go @@ -61,6 +61,20 @@ type BillingCustomerLock func(*sql.Selector) // BillingCustomerOverride is the predicate function for billingcustomeroverride builders. type BillingCustomerOverride func(*sql.Selector) +// BillingGatheringInvoiceLine is the predicate function for billinggatheringinvoiceline builders. +type BillingGatheringInvoiceLine func(*sql.Selector) + +// BillingGatheringInvoiceLineOrErr calls the predicate only if the error is not nit. +func BillingGatheringInvoiceLineOrErr(p BillingGatheringInvoiceLine, err error) BillingGatheringInvoiceLine { + return func(s *sql.Selector) { + if err != nil { + s.AddError(err) + return + } + p(s) + } +} + // BillingInvoice is the predicate function for billinginvoice builders. type BillingInvoice func(*sql.Selector) diff --git a/openmeter/ent/db/runtime.go b/openmeter/ent/db/runtime.go index f76ebd9611..54e193f35c 100644 --- a/openmeter/ent/db/runtime.go +++ b/openmeter/ent/db/runtime.go @@ -20,6 +20,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/ent/db/balancesnapshot" "github.com/openmeterio/openmeter/openmeter/ent/db/billingcustomerlock" "github.com/openmeterio/openmeter/openmeter/ent/db/billingcustomeroverride" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceflatfeelineconfig" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" @@ -447,6 +448,44 @@ func init() { billingcustomeroverrideDescID := billingcustomeroverrideMixinFields0[0].Descriptor() // billingcustomeroverride.DefaultID holds the default value on creation for the id field. billingcustomeroverride.DefaultID = billingcustomeroverrideDescID.Default.(func() string) + billinggatheringinvoicelineMixin := schema.BillingGatheringInvoiceLine{}.Mixin() + billinggatheringinvoicelineMixinFields1 := billinggatheringinvoicelineMixin[1].Fields() + _ = billinggatheringinvoicelineMixinFields1 + billinggatheringinvoicelineMixinFields2 := billinggatheringinvoicelineMixin[2].Fields() + _ = billinggatheringinvoicelineMixinFields2 + billinggatheringinvoicelineFields := schema.BillingGatheringInvoiceLine{}.Fields() + _ = billinggatheringinvoicelineFields + // billinggatheringinvoicelineDescNamespace is the schema descriptor for namespace field. + billinggatheringinvoicelineDescNamespace := billinggatheringinvoicelineMixinFields1[1].Descriptor() + // billinggatheringinvoiceline.NamespaceValidator is a validator for the "namespace" field. It is called by the builders before save. + billinggatheringinvoiceline.NamespaceValidator = billinggatheringinvoicelineDescNamespace.Validators[0].(func(string) error) + // billinggatheringinvoicelineDescCreatedAt is the schema descriptor for created_at field. + billinggatheringinvoicelineDescCreatedAt := billinggatheringinvoicelineMixinFields1[3].Descriptor() + // billinggatheringinvoiceline.DefaultCreatedAt holds the default value on creation for the created_at field. + billinggatheringinvoiceline.DefaultCreatedAt = billinggatheringinvoicelineDescCreatedAt.Default.(func() time.Time) + // billinggatheringinvoicelineDescUpdatedAt is the schema descriptor for updated_at field. + billinggatheringinvoicelineDescUpdatedAt := billinggatheringinvoicelineMixinFields1[4].Descriptor() + // billinggatheringinvoiceline.DefaultUpdatedAt holds the default value on creation for the updated_at field. + billinggatheringinvoiceline.DefaultUpdatedAt = billinggatheringinvoicelineDescUpdatedAt.Default.(func() time.Time) + // billinggatheringinvoiceline.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + billinggatheringinvoiceline.UpdateDefaultUpdatedAt = billinggatheringinvoicelineDescUpdatedAt.UpdateDefault.(func() time.Time) + // billinggatheringinvoicelineDescCurrency is the schema descriptor for currency field. + billinggatheringinvoicelineDescCurrency := billinggatheringinvoicelineMixinFields2[0].Descriptor() + // billinggatheringinvoiceline.CurrencyValidator is a validator for the "currency" field. It is called by the builders before save. + billinggatheringinvoiceline.CurrencyValidator = billinggatheringinvoicelineDescCurrency.Validators[0].(func(string) error) + // billinggatheringinvoicelineDescPrice is the schema descriptor for price field. + billinggatheringinvoicelineDescPrice := billinggatheringinvoicelineMixinFields2[6].Descriptor() + billinggatheringinvoiceline.ValueScanner.Price = billinggatheringinvoicelineDescPrice.ValueScanner.(field.TypeValueScanner[*productcatalog.Price]) + // billinggatheringinvoicelineDescUnitConfig is the schema descriptor for unit_config field. + billinggatheringinvoicelineDescUnitConfig := billinggatheringinvoicelineMixinFields2[7].Descriptor() + billinggatheringinvoiceline.ValueScanner.UnitConfig = billinggatheringinvoicelineDescUnitConfig.ValueScanner.(field.TypeValueScanner[*productcatalog.UnitConfig]) + // billinggatheringinvoicelineDescRatecardDiscounts is the schema descriptor for ratecard_discounts field. + billinggatheringinvoicelineDescRatecardDiscounts := billinggatheringinvoicelineMixinFields2[8].Descriptor() + billinggatheringinvoiceline.ValueScanner.RatecardDiscounts = billinggatheringinvoicelineDescRatecardDiscounts.ValueScanner.(field.TypeValueScanner[*billing.Discounts]) + // billinggatheringinvoicelineDescID is the schema descriptor for id field. + billinggatheringinvoicelineDescID := billinggatheringinvoicelineMixinFields1[0].Descriptor() + // billinggatheringinvoiceline.DefaultID holds the default value on creation for the id field. + billinggatheringinvoiceline.DefaultID = billinggatheringinvoicelineDescID.Default.(func() string) billinginvoiceMixin := schema.BillingInvoice{}.Mixin() billinginvoiceMixinFields0 := billinginvoiceMixin[0].Fields() _ = billinginvoiceMixinFields0 diff --git a/openmeter/ent/db/setorclear.go b/openmeter/ent/db/setorclear.go index d30ac522a5..c3a1c3bba8 100644 --- a/openmeter/ent/db/setorclear.go +++ b/openmeter/ent/db/setorclear.go @@ -621,6 +621,258 @@ func (u *BillingCustomerOverrideUpdateOne) SetOrClearInvoiceDefaultTaxConfig(val return u.SetInvoiceDefaultTaxConfig(*value) } +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearAnnotations(value *models.Annotations) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearAnnotations() + } + return u.SetAnnotations(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearAnnotations(value *models.Annotations) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearAnnotations() + } + return u.SetAnnotations(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearMetadata(value *map[string]string) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearMetadata() + } + return u.SetMetadata(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearMetadata(value *map[string]string) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearMetadata() + } + return u.SetMetadata(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearDeletedAt(value *time.Time) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearDeletedAt() + } + return u.SetDeletedAt(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearDeletedAt(value *time.Time) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearDeletedAt() + } + return u.SetDeletedAt(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearDescription(value *string) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearDescription() + } + return u.SetDescription(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearDescription(value *string) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearDescription() + } + return u.SetDescription(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearTaxConfig(value *billing.TaxConfig) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearTaxConfig() + } + return u.SetTaxConfig(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearTaxConfig(value *billing.TaxConfig) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearTaxConfig() + } + return u.SetTaxConfig(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearFeatureKey(value *string) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearFeatureKey() + } + return u.SetFeatureKey(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearFeatureKey(value *string) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearFeatureKey() + } + return u.SetFeatureKey(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearUnitConfig(value **productcatalog.UnitConfig) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearUnitConfig() + } + return u.SetUnitConfig(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearUnitConfig(value **productcatalog.UnitConfig) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearUnitConfig() + } + return u.SetUnitConfig(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearRatecardDiscounts(value **billing.Discounts) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearRatecardDiscounts() + } + return u.SetRatecardDiscounts(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearRatecardDiscounts(value **billing.Discounts) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearRatecardDiscounts() + } + return u.SetRatecardDiscounts(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearChildUniqueReferenceID(value *string) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearChildUniqueReferenceID() + } + return u.SetChildUniqueReferenceID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearChildUniqueReferenceID(value *string) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearChildUniqueReferenceID() + } + return u.SetChildUniqueReferenceID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearSubscriptionID(value *string) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearSubscriptionID() + } + return u.SetSubscriptionID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearSubscriptionID(value *string) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearSubscriptionID() + } + return u.SetSubscriptionID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearSubscriptionPhaseID(value *string) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearSubscriptionPhaseID() + } + return u.SetSubscriptionPhaseID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearSubscriptionPhaseID(value *string) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearSubscriptionPhaseID() + } + return u.SetSubscriptionPhaseID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearSubscriptionItemID(value *string) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearSubscriptionItemID() + } + return u.SetSubscriptionItemID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearSubscriptionItemID(value *string) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearSubscriptionItemID() + } + return u.SetSubscriptionItemID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearSubscriptionBillingPeriodFrom(value *time.Time) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearSubscriptionBillingPeriodFrom() + } + return u.SetSubscriptionBillingPeriodFrom(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearSubscriptionBillingPeriodFrom(value *time.Time) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearSubscriptionBillingPeriodFrom() + } + return u.SetSubscriptionBillingPeriodFrom(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearSubscriptionBillingPeriodTo(value *time.Time) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearSubscriptionBillingPeriodTo() + } + return u.SetSubscriptionBillingPeriodTo(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearSubscriptionBillingPeriodTo(value *time.Time) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearSubscriptionBillingPeriodTo() + } + return u.SetSubscriptionBillingPeriodTo(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearTaxCodeID(value *string) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearTaxCodeID() + } + return u.SetTaxCodeID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearTaxCodeID(value *string) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearTaxCodeID() + } + return u.SetTaxCodeID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearTaxBehavior(value *productcatalog.TaxBehavior) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearTaxBehavior() + } + return u.SetTaxBehavior(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearTaxBehavior(value *productcatalog.TaxBehavior) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearTaxBehavior() + } + return u.SetTaxBehavior(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearSplitLineGroupID(value *string) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearSplitLineGroupID() + } + return u.SetSplitLineGroupID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearSplitLineGroupID(value *string) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearSplitLineGroupID() + } + return u.SetSplitLineGroupID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdate) SetOrClearChargeID(value *string) *BillingGatheringInvoiceLineUpdate { + if value == nil { + return u.ClearChargeID() + } + return u.SetChargeID(*value) +} + +func (u *BillingGatheringInvoiceLineUpdateOne) SetOrClearChargeID(value *string) *BillingGatheringInvoiceLineUpdateOne { + if value == nil { + return u.ClearChargeID() + } + return u.SetChargeID(*value) +} + func (u *BillingInvoiceUpdate) SetOrClearMetadata(value *map[string]string) *BillingInvoiceUpdate { if value == nil { return u.ClearMetadata() diff --git a/openmeter/ent/db/subscription.go b/openmeter/ent/db/subscription.go index 6d9c9c12bf..b142828bca 100644 --- a/openmeter/ent/db/subscription.go +++ b/openmeter/ent/db/subscription.go @@ -75,6 +75,8 @@ type SubscriptionEdges struct { Phases []*SubscriptionPhase `json:"phases,omitempty"` // BillingLines holds the value of the billing_lines edge. BillingLines []*BillingInvoiceLine `json:"billing_lines,omitempty"` + // BillingGatheringInvoiceLines holds the value of the billing_gathering_invoice_lines edge. + BillingGatheringInvoiceLines []*BillingGatheringInvoiceLine `json:"billing_gathering_invoice_lines,omitempty"` // BillingSplitLineGroups holds the value of the billing_split_line_groups edge. BillingSplitLineGroups []*BillingInvoiceSplitLineGroup `json:"billing_split_line_groups,omitempty"` // ChargesUsageBased holds the value of the charges_usage_based edge. @@ -89,7 +91,7 @@ type SubscriptionEdges struct { BillingSyncState *SubscriptionBillingSyncState `json:"billing_sync_state,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [10]bool + loadedTypes [11]bool } // PlanOrErr returns the Plan value or an error if the edge @@ -132,10 +134,19 @@ func (e SubscriptionEdges) BillingLinesOrErr() ([]*BillingInvoiceLine, error) { return nil, &NotLoadedError{edge: "billing_lines"} } +// BillingGatheringInvoiceLinesOrErr returns the BillingGatheringInvoiceLines value or an error if the edge +// was not loaded in eager-loading. +func (e SubscriptionEdges) BillingGatheringInvoiceLinesOrErr() ([]*BillingGatheringInvoiceLine, error) { + if e.loadedTypes[4] { + return e.BillingGatheringInvoiceLines, nil + } + return nil, &NotLoadedError{edge: "billing_gathering_invoice_lines"} +} + // BillingSplitLineGroupsOrErr returns the BillingSplitLineGroups value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionEdges) BillingSplitLineGroupsOrErr() ([]*BillingInvoiceSplitLineGroup, error) { - if e.loadedTypes[4] { + if e.loadedTypes[5] { return e.BillingSplitLineGroups, nil } return nil, &NotLoadedError{edge: "billing_split_line_groups"} @@ -144,7 +155,7 @@ func (e SubscriptionEdges) BillingSplitLineGroupsOrErr() ([]*BillingInvoiceSplit // ChargesUsageBasedOrErr returns the ChargesUsageBased value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionEdges) ChargesUsageBasedOrErr() ([]*ChargeUsageBased, error) { - if e.loadedTypes[5] { + if e.loadedTypes[6] { return e.ChargesUsageBased, nil } return nil, &NotLoadedError{edge: "charges_usage_based"} @@ -153,7 +164,7 @@ func (e SubscriptionEdges) ChargesUsageBasedOrErr() ([]*ChargeUsageBased, error) // ChargesCreditPurchaseOrErr returns the ChargesCreditPurchase value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionEdges) ChargesCreditPurchaseOrErr() ([]*ChargeCreditPurchase, error) { - if e.loadedTypes[6] { + if e.loadedTypes[7] { return e.ChargesCreditPurchase, nil } return nil, &NotLoadedError{edge: "charges_credit_purchase"} @@ -162,7 +173,7 @@ func (e SubscriptionEdges) ChargesCreditPurchaseOrErr() ([]*ChargeCreditPurchase // ChargesFlatFeeOrErr returns the ChargesFlatFee value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionEdges) ChargesFlatFeeOrErr() ([]*ChargeFlatFee, error) { - if e.loadedTypes[7] { + if e.loadedTypes[8] { return e.ChargesFlatFee, nil } return nil, &NotLoadedError{edge: "charges_flat_fee"} @@ -171,7 +182,7 @@ func (e SubscriptionEdges) ChargesFlatFeeOrErr() ([]*ChargeFlatFee, error) { // AddonsOrErr returns the Addons value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionEdges) AddonsOrErr() ([]*SubscriptionAddon, error) { - if e.loadedTypes[8] { + if e.loadedTypes[9] { return e.Addons, nil } return nil, &NotLoadedError{edge: "addons"} @@ -182,7 +193,7 @@ func (e SubscriptionEdges) AddonsOrErr() ([]*SubscriptionAddon, error) { func (e SubscriptionEdges) BillingSyncStateOrErr() (*SubscriptionBillingSyncState, error) { if e.BillingSyncState != nil { return e.BillingSyncState, nil - } else if e.loadedTypes[9] { + } else if e.loadedTypes[10] { return nil, &NotFoundError{label: subscriptionbillingsyncstate.Label} } return nil, &NotLoadedError{edge: "billing_sync_state"} @@ -365,6 +376,11 @@ func (_m *Subscription) QueryBillingLines() *BillingInvoiceLineQuery { return NewSubscriptionClient(_m.config).QueryBillingLines(_m) } +// QueryBillingGatheringInvoiceLines queries the "billing_gathering_invoice_lines" edge of the Subscription entity. +func (_m *Subscription) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + return NewSubscriptionClient(_m.config).QueryBillingGatheringInvoiceLines(_m) +} + // QueryBillingSplitLineGroups queries the "billing_split_line_groups" edge of the Subscription entity. func (_m *Subscription) QueryBillingSplitLineGroups() *BillingInvoiceSplitLineGroupQuery { return NewSubscriptionClient(_m.config).QueryBillingSplitLineGroups(_m) diff --git a/openmeter/ent/db/subscription/subscription.go b/openmeter/ent/db/subscription/subscription.go index 518e0053ce..5562384e5e 100644 --- a/openmeter/ent/db/subscription/subscription.go +++ b/openmeter/ent/db/subscription/subscription.go @@ -59,6 +59,8 @@ const ( EdgePhases = "phases" // EdgeBillingLines holds the string denoting the billing_lines edge name in mutations. EdgeBillingLines = "billing_lines" + // EdgeBillingGatheringInvoiceLines holds the string denoting the billing_gathering_invoice_lines edge name in mutations. + EdgeBillingGatheringInvoiceLines = "billing_gathering_invoice_lines" // EdgeBillingSplitLineGroups holds the string denoting the billing_split_line_groups edge name in mutations. EdgeBillingSplitLineGroups = "billing_split_line_groups" // EdgeChargesUsageBased holds the string denoting the charges_usage_based edge name in mutations. @@ -101,6 +103,13 @@ const ( BillingLinesInverseTable = "billing_invoice_lines" // BillingLinesColumn is the table column denoting the billing_lines relation/edge. BillingLinesColumn = "subscription_id" + // BillingGatheringInvoiceLinesTable is the table that holds the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesInverseTable is the table name for the BillingGatheringInvoiceLine entity. + // It exists in this package in order to avoid circular dependency with the "billinggatheringinvoiceline" package. + BillingGatheringInvoiceLinesInverseTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesColumn is the table column denoting the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesColumn = "subscription_id" // BillingSplitLineGroupsTable is the table that holds the billing_split_line_groups relation/edge. BillingSplitLineGroupsTable = "billing_invoice_split_line_groups" // BillingSplitLineGroupsInverseTable is the table name for the BillingInvoiceSplitLineGroup entity. @@ -341,6 +350,20 @@ func ByBillingLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { } } +// ByBillingGatheringInvoiceLinesCount orders the results by billing_gathering_invoice_lines count. +func ByBillingGatheringInvoiceLinesCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newBillingGatheringInvoiceLinesStep(), opts...) + } +} + +// ByBillingGatheringInvoiceLines orders the results by billing_gathering_invoice_lines terms. +func ByBillingGatheringInvoiceLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newBillingGatheringInvoiceLinesStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + // ByBillingSplitLineGroupsCount orders the results by billing_split_line_groups count. func ByBillingSplitLineGroupsCount(opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -445,6 +468,13 @@ func newBillingLinesStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, BillingLinesTable, BillingLinesColumn), ) } +func newBillingGatheringInvoiceLinesStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(BillingGatheringInvoiceLinesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) +} func newBillingSplitLineGroupsStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/openmeter/ent/db/subscription/where.go b/openmeter/ent/db/subscription/where.go index 81a1e08a3a..8179101bc6 100644 --- a/openmeter/ent/db/subscription/where.go +++ b/openmeter/ent/db/subscription/where.go @@ -1050,6 +1050,29 @@ func HasBillingLinesWith(preds ...predicate.BillingInvoiceLine) predicate.Subscr }) } +// HasBillingGatheringInvoiceLines applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge. +func HasBillingGatheringInvoiceLines() predicate.Subscription { + return predicate.Subscription(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasBillingGatheringInvoiceLinesWith applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge with a given conditions (other predicates). +func HasBillingGatheringInvoiceLinesWith(preds ...predicate.BillingGatheringInvoiceLine) predicate.Subscription { + return predicate.Subscription(func(s *sql.Selector) { + step := newBillingGatheringInvoiceLinesStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // HasBillingSplitLineGroups applies the HasEdge predicate on the "billing_split_line_groups" edge. func HasBillingSplitLineGroups() predicate.Subscription { return predicate.Subscription(func(s *sql.Selector) { diff --git a/openmeter/ent/db/subscription_create.go b/openmeter/ent/db/subscription_create.go index ff1d74edf7..85a69dac66 100644 --- a/openmeter/ent/db/subscription_create.go +++ b/openmeter/ent/db/subscription_create.go @@ -12,6 +12,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" @@ -265,6 +266,21 @@ func (_c *SubscriptionCreate) AddBillingLines(v ...*BillingInvoiceLine) *Subscri return _c.AddBillingLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_c *SubscriptionCreate) AddBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionCreate { + _c.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _c +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_c *SubscriptionCreate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionCreate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by IDs. func (_c *SubscriptionCreate) AddBillingSplitLineGroupIDs(ids ...string) *SubscriptionCreate { _c.mutation.AddBillingSplitLineGroupIDs(ids...) @@ -657,6 +673,22 @@ func (_c *SubscriptionCreate) createSpec() (*Subscription, *sqlgraph.CreateSpec, } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscription.BillingGatheringInvoiceLinesTable, + Columns: []string{subscription.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.BillingSplitLineGroupsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/openmeter/ent/db/subscription_query.go b/openmeter/ent/db/subscription_query.go index a04fa31a01..46c70c71ab 100644 --- a/openmeter/ent/db/subscription_query.go +++ b/openmeter/ent/db/subscription_query.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" @@ -30,21 +31,22 @@ import ( // SubscriptionQuery is the builder for querying Subscription entities. type SubscriptionQuery struct { config - ctx *QueryContext - order []subscription.OrderOption - inters []Interceptor - predicates []predicate.Subscription - withPlan *PlanQuery - withCustomer *CustomerQuery - withPhases *SubscriptionPhaseQuery - withBillingLines *BillingInvoiceLineQuery - withBillingSplitLineGroups *BillingInvoiceSplitLineGroupQuery - withChargesUsageBased *ChargeUsageBasedQuery - withChargesCreditPurchase *ChargeCreditPurchaseQuery - withChargesFlatFee *ChargeFlatFeeQuery - withAddons *SubscriptionAddonQuery - withBillingSyncState *SubscriptionBillingSyncStateQuery - modifiers []func(*sql.Selector) + ctx *QueryContext + order []subscription.OrderOption + inters []Interceptor + predicates []predicate.Subscription + withPlan *PlanQuery + withCustomer *CustomerQuery + withPhases *SubscriptionPhaseQuery + withBillingLines *BillingInvoiceLineQuery + withBillingGatheringInvoiceLines *BillingGatheringInvoiceLineQuery + withBillingSplitLineGroups *BillingInvoiceSplitLineGroupQuery + withChargesUsageBased *ChargeUsageBasedQuery + withChargesCreditPurchase *ChargeCreditPurchaseQuery + withChargesFlatFee *ChargeFlatFeeQuery + withAddons *SubscriptionAddonQuery + withBillingSyncState *SubscriptionBillingSyncStateQuery + modifiers []func(*sql.Selector) // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -169,6 +171,28 @@ func (_q *SubscriptionQuery) QueryBillingLines() *BillingInvoiceLineQuery { return query } +// QueryBillingGatheringInvoiceLines chains the current query on the "billing_gathering_invoice_lines" edge. +func (_q *SubscriptionQuery) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(subscription.Table, subscription.FieldID, selector), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, subscription.BillingGatheringInvoiceLinesTable, subscription.BillingGatheringInvoiceLinesColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryBillingSplitLineGroups chains the current query on the "billing_split_line_groups" edge. func (_q *SubscriptionQuery) QueryBillingSplitLineGroups() *BillingInvoiceSplitLineGroupQuery { query := (&BillingInvoiceSplitLineGroupClient{config: _q.config}).Query() @@ -488,21 +512,22 @@ func (_q *SubscriptionQuery) Clone() *SubscriptionQuery { return nil } return &SubscriptionQuery{ - config: _q.config, - ctx: _q.ctx.Clone(), - order: append([]subscription.OrderOption{}, _q.order...), - inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.Subscription{}, _q.predicates...), - withPlan: _q.withPlan.Clone(), - withCustomer: _q.withCustomer.Clone(), - withPhases: _q.withPhases.Clone(), - withBillingLines: _q.withBillingLines.Clone(), - withBillingSplitLineGroups: _q.withBillingSplitLineGroups.Clone(), - withChargesUsageBased: _q.withChargesUsageBased.Clone(), - withChargesCreditPurchase: _q.withChargesCreditPurchase.Clone(), - withChargesFlatFee: _q.withChargesFlatFee.Clone(), - withAddons: _q.withAddons.Clone(), - withBillingSyncState: _q.withBillingSyncState.Clone(), + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]subscription.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.Subscription{}, _q.predicates...), + withPlan: _q.withPlan.Clone(), + withCustomer: _q.withCustomer.Clone(), + withPhases: _q.withPhases.Clone(), + withBillingLines: _q.withBillingLines.Clone(), + withBillingGatheringInvoiceLines: _q.withBillingGatheringInvoiceLines.Clone(), + withBillingSplitLineGroups: _q.withBillingSplitLineGroups.Clone(), + withChargesUsageBased: _q.withChargesUsageBased.Clone(), + withChargesCreditPurchase: _q.withChargesCreditPurchase.Clone(), + withChargesFlatFee: _q.withChargesFlatFee.Clone(), + withAddons: _q.withAddons.Clone(), + withBillingSyncState: _q.withBillingSyncState.Clone(), // clone intermediate query. sql: _q.sql.Clone(), path: _q.path, @@ -553,6 +578,17 @@ func (_q *SubscriptionQuery) WithBillingLines(opts ...func(*BillingInvoiceLineQu return _q } +// WithBillingGatheringInvoiceLines tells the query-builder to eager-load the nodes that are connected to +// the "billing_gathering_invoice_lines" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *SubscriptionQuery) WithBillingGatheringInvoiceLines(opts ...func(*BillingGatheringInvoiceLineQuery)) *SubscriptionQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withBillingGatheringInvoiceLines = query + return _q +} + // WithBillingSplitLineGroups tells the query-builder to eager-load the nodes that are connected to // the "billing_split_line_groups" edge. The optional arguments are used to configure the query builder of the edge. func (_q *SubscriptionQuery) WithBillingSplitLineGroups(opts ...func(*BillingInvoiceSplitLineGroupQuery)) *SubscriptionQuery { @@ -697,11 +733,12 @@ func (_q *SubscriptionQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([] var ( nodes = []*Subscription{} _spec = _q.querySpec() - loadedTypes = [10]bool{ + loadedTypes = [11]bool{ _q.withPlan != nil, _q.withCustomer != nil, _q.withPhases != nil, _q.withBillingLines != nil, + _q.withBillingGatheringInvoiceLines != nil, _q.withBillingSplitLineGroups != nil, _q.withChargesUsageBased != nil, _q.withChargesCreditPurchase != nil, @@ -757,6 +794,15 @@ func (_q *SubscriptionQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([] return nil, err } } + if query := _q.withBillingGatheringInvoiceLines; query != nil { + if err := _q.loadBillingGatheringInvoiceLines(ctx, query, nodes, + func(n *Subscription) { n.Edges.BillingGatheringInvoiceLines = []*BillingGatheringInvoiceLine{} }, + func(n *Subscription, e *BillingGatheringInvoiceLine) { + n.Edges.BillingGatheringInvoiceLines = append(n.Edges.BillingGatheringInvoiceLines, e) + }); err != nil { + return nil, err + } + } if query := _q.withBillingSplitLineGroups; query != nil { if err := _q.loadBillingSplitLineGroups(ctx, query, nodes, func(n *Subscription) { n.Edges.BillingSplitLineGroups = []*BillingInvoiceSplitLineGroup{} }, @@ -932,6 +978,39 @@ func (_q *SubscriptionQuery) loadBillingLines(ctx context.Context, query *Billin } return nil } +func (_q *SubscriptionQuery) loadBillingGatheringInvoiceLines(ctx context.Context, query *BillingGatheringInvoiceLineQuery, nodes []*Subscription, init func(*Subscription), assign func(*Subscription, *BillingGatheringInvoiceLine)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[string]*Subscription) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(billinggatheringinvoiceline.FieldSubscriptionID) + } + query.Where(predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(subscription.BillingGatheringInvoiceLinesColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.SubscriptionID + if fk == nil { + return fmt.Errorf(`foreign-key "subscription_id" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "subscription_id" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} func (_q *SubscriptionQuery) loadBillingSplitLineGroups(ctx context.Context, query *BillingInvoiceSplitLineGroupQuery, nodes []*Subscription, init func(*Subscription), assign func(*Subscription, *BillingInvoiceSplitLineGroup)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[string]*Subscription) diff --git a/openmeter/ent/db/subscription_update.go b/openmeter/ent/db/subscription_update.go index 505194b75a..378f83fc25 100644 --- a/openmeter/ent/db/subscription_update.go +++ b/openmeter/ent/db/subscription_update.go @@ -11,6 +11,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" @@ -241,6 +242,21 @@ func (_u *SubscriptionUpdate) AddBillingLines(v ...*BillingInvoiceLine) *Subscri return _u.AddBillingLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *SubscriptionUpdate) AddBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionUpdate { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *SubscriptionUpdate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by IDs. func (_u *SubscriptionUpdate) AddBillingSplitLineGroupIDs(ids ...string) *SubscriptionUpdate { _u.mutation.AddBillingSplitLineGroupIDs(ids...) @@ -388,6 +404,27 @@ func (_u *SubscriptionUpdate) RemoveBillingLines(v ...*BillingInvoiceLine) *Subs return _u.RemoveBillingLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *SubscriptionUpdate) ClearBillingGatheringInvoiceLines() *SubscriptionUpdate { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *SubscriptionUpdate) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionUpdate { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *SubscriptionUpdate) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearBillingSplitLineGroups clears all "billing_split_line_groups" edges to the BillingInvoiceSplitLineGroup entity. func (_u *SubscriptionUpdate) ClearBillingSplitLineGroups() *SubscriptionUpdate { _u.mutation.ClearBillingSplitLineGroups() @@ -733,6 +770,51 @@ func (_u *SubscriptionUpdate) sqlSave(ctx context.Context) (_node int, err error } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscription.BillingGatheringInvoiceLinesTable, + Columns: []string{subscription.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscription.BillingGatheringInvoiceLinesTable, + Columns: []string{subscription.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscription.BillingGatheringInvoiceLinesTable, + Columns: []string{subscription.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.BillingSplitLineGroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -1208,6 +1290,21 @@ func (_u *SubscriptionUpdateOne) AddBillingLines(v ...*BillingInvoiceLine) *Subs return _u.AddBillingLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *SubscriptionUpdateOne) AddBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionUpdateOne { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *SubscriptionUpdateOne) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by IDs. func (_u *SubscriptionUpdateOne) AddBillingSplitLineGroupIDs(ids ...string) *SubscriptionUpdateOne { _u.mutation.AddBillingSplitLineGroupIDs(ids...) @@ -1355,6 +1452,27 @@ func (_u *SubscriptionUpdateOne) RemoveBillingLines(v ...*BillingInvoiceLine) *S return _u.RemoveBillingLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *SubscriptionUpdateOne) ClearBillingGatheringInvoiceLines() *SubscriptionUpdateOne { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *SubscriptionUpdateOne) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionUpdateOne { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *SubscriptionUpdateOne) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearBillingSplitLineGroups clears all "billing_split_line_groups" edges to the BillingInvoiceSplitLineGroup entity. func (_u *SubscriptionUpdateOne) ClearBillingSplitLineGroups() *SubscriptionUpdateOne { _u.mutation.ClearBillingSplitLineGroups() @@ -1730,6 +1848,51 @@ func (_u *SubscriptionUpdateOne) sqlSave(ctx context.Context) (_node *Subscripti } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscription.BillingGatheringInvoiceLinesTable, + Columns: []string{subscription.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscription.BillingGatheringInvoiceLinesTable, + Columns: []string{subscription.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscription.BillingGatheringInvoiceLinesTable, + Columns: []string{subscription.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.BillingSplitLineGroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/openmeter/ent/db/subscriptionitem.go b/openmeter/ent/db/subscriptionitem.go index 55666014ed..2a151f3a2b 100644 --- a/openmeter/ent/db/subscriptionitem.go +++ b/openmeter/ent/db/subscriptionitem.go @@ -88,6 +88,8 @@ type SubscriptionItemEdges struct { Entitlement *Entitlement `json:"entitlement,omitempty"` // BillingLines holds the value of the billing_lines edge. BillingLines []*BillingInvoiceLine `json:"billing_lines,omitempty"` + // BillingGatheringInvoiceLines holds the value of the billing_gathering_invoice_lines edge. + BillingGatheringInvoiceLines []*BillingGatheringInvoiceLine `json:"billing_gathering_invoice_lines,omitempty"` // BillingSplitLineGroups holds the value of the billing_split_line_groups edge. BillingSplitLineGroups []*BillingInvoiceSplitLineGroup `json:"billing_split_line_groups,omitempty"` // ChargesUsageBased holds the value of the charges_usage_based edge. @@ -100,7 +102,7 @@ type SubscriptionItemEdges struct { TaxCode *TaxCode `json:"tax_code,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [8]bool + loadedTypes [9]bool } // PhaseOrErr returns the Phase value or an error if the edge @@ -134,10 +136,19 @@ func (e SubscriptionItemEdges) BillingLinesOrErr() ([]*BillingInvoiceLine, error return nil, &NotLoadedError{edge: "billing_lines"} } +// BillingGatheringInvoiceLinesOrErr returns the BillingGatheringInvoiceLines value or an error if the edge +// was not loaded in eager-loading. +func (e SubscriptionItemEdges) BillingGatheringInvoiceLinesOrErr() ([]*BillingGatheringInvoiceLine, error) { + if e.loadedTypes[3] { + return e.BillingGatheringInvoiceLines, nil + } + return nil, &NotLoadedError{edge: "billing_gathering_invoice_lines"} +} + // BillingSplitLineGroupsOrErr returns the BillingSplitLineGroups value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionItemEdges) BillingSplitLineGroupsOrErr() ([]*BillingInvoiceSplitLineGroup, error) { - if e.loadedTypes[3] { + if e.loadedTypes[4] { return e.BillingSplitLineGroups, nil } return nil, &NotLoadedError{edge: "billing_split_line_groups"} @@ -146,7 +157,7 @@ func (e SubscriptionItemEdges) BillingSplitLineGroupsOrErr() ([]*BillingInvoiceS // ChargesUsageBasedOrErr returns the ChargesUsageBased value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionItemEdges) ChargesUsageBasedOrErr() ([]*ChargeUsageBased, error) { - if e.loadedTypes[4] { + if e.loadedTypes[5] { return e.ChargesUsageBased, nil } return nil, &NotLoadedError{edge: "charges_usage_based"} @@ -155,7 +166,7 @@ func (e SubscriptionItemEdges) ChargesUsageBasedOrErr() ([]*ChargeUsageBased, er // ChargesCreditPurchaseOrErr returns the ChargesCreditPurchase value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionItemEdges) ChargesCreditPurchaseOrErr() ([]*ChargeCreditPurchase, error) { - if e.loadedTypes[5] { + if e.loadedTypes[6] { return e.ChargesCreditPurchase, nil } return nil, &NotLoadedError{edge: "charges_credit_purchase"} @@ -164,7 +175,7 @@ func (e SubscriptionItemEdges) ChargesCreditPurchaseOrErr() ([]*ChargeCreditPurc // ChargesFlatFeeOrErr returns the ChargesFlatFee value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionItemEdges) ChargesFlatFeeOrErr() ([]*ChargeFlatFee, error) { - if e.loadedTypes[6] { + if e.loadedTypes[7] { return e.ChargesFlatFee, nil } return nil, &NotLoadedError{edge: "charges_flat_fee"} @@ -175,7 +186,7 @@ func (e SubscriptionItemEdges) ChargesFlatFeeOrErr() ([]*ChargeFlatFee, error) { func (e SubscriptionItemEdges) TaxCodeOrErr() (*TaxCode, error) { if e.TaxCode != nil { return e.TaxCode, nil - } else if e.loadedTypes[7] { + } else if e.loadedTypes[8] { return nil, &NotFoundError{label: dbtaxcode.Label} } return nil, &NotLoadedError{edge: "tax_code"} @@ -418,6 +429,11 @@ func (_m *SubscriptionItem) QueryBillingLines() *BillingInvoiceLineQuery { return NewSubscriptionItemClient(_m.config).QueryBillingLines(_m) } +// QueryBillingGatheringInvoiceLines queries the "billing_gathering_invoice_lines" edge of the SubscriptionItem entity. +func (_m *SubscriptionItem) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + return NewSubscriptionItemClient(_m.config).QueryBillingGatheringInvoiceLines(_m) +} + // QueryBillingSplitLineGroups queries the "billing_split_line_groups" edge of the SubscriptionItem entity. func (_m *SubscriptionItem) QueryBillingSplitLineGroups() *BillingInvoiceSplitLineGroupQuery { return NewSubscriptionItemClient(_m.config).QueryBillingSplitLineGroups(_m) diff --git a/openmeter/ent/db/subscriptionitem/subscriptionitem.go b/openmeter/ent/db/subscriptionitem/subscriptionitem.go index 1b8e0074a4..a82675f252 100644 --- a/openmeter/ent/db/subscriptionitem/subscriptionitem.go +++ b/openmeter/ent/db/subscriptionitem/subscriptionitem.go @@ -74,6 +74,8 @@ const ( EdgeEntitlement = "entitlement" // EdgeBillingLines holds the string denoting the billing_lines edge name in mutations. EdgeBillingLines = "billing_lines" + // EdgeBillingGatheringInvoiceLines holds the string denoting the billing_gathering_invoice_lines edge name in mutations. + EdgeBillingGatheringInvoiceLines = "billing_gathering_invoice_lines" // EdgeBillingSplitLineGroups holds the string denoting the billing_split_line_groups edge name in mutations. EdgeBillingSplitLineGroups = "billing_split_line_groups" // EdgeChargesUsageBased holds the string denoting the charges_usage_based edge name in mutations. @@ -107,6 +109,13 @@ const ( BillingLinesInverseTable = "billing_invoice_lines" // BillingLinesColumn is the table column denoting the billing_lines relation/edge. BillingLinesColumn = "subscription_item_id" + // BillingGatheringInvoiceLinesTable is the table that holds the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesInverseTable is the table name for the BillingGatheringInvoiceLine entity. + // It exists in this package in order to avoid circular dependency with the "billinggatheringinvoiceline" package. + BillingGatheringInvoiceLinesInverseTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesColumn is the table column denoting the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesColumn = "subscription_item_id" // BillingSplitLineGroupsTable is the table that holds the billing_split_line_groups relation/edge. BillingSplitLineGroupsTable = "billing_invoice_split_line_groups" // BillingSplitLineGroupsInverseTable is the table name for the BillingInvoiceSplitLineGroup entity. @@ -378,6 +387,20 @@ func ByBillingLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { } } +// ByBillingGatheringInvoiceLinesCount orders the results by billing_gathering_invoice_lines count. +func ByBillingGatheringInvoiceLinesCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newBillingGatheringInvoiceLinesStep(), opts...) + } +} + +// ByBillingGatheringInvoiceLines orders the results by billing_gathering_invoice_lines terms. +func ByBillingGatheringInvoiceLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newBillingGatheringInvoiceLinesStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + // ByBillingSplitLineGroupsCount orders the results by billing_split_line_groups count. func ByBillingSplitLineGroupsCount(opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -461,6 +484,13 @@ func newBillingLinesStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, BillingLinesTable, BillingLinesColumn), ) } +func newBillingGatheringInvoiceLinesStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(BillingGatheringInvoiceLinesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) +} func newBillingSplitLineGroupsStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/openmeter/ent/db/subscriptionitem/where.go b/openmeter/ent/db/subscriptionitem/where.go index de18bb45f0..2c75c454ed 100644 --- a/openmeter/ent/db/subscriptionitem/where.go +++ b/openmeter/ent/db/subscriptionitem/where.go @@ -1416,6 +1416,29 @@ func HasBillingLinesWith(preds ...predicate.BillingInvoiceLine) predicate.Subscr }) } +// HasBillingGatheringInvoiceLines applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge. +func HasBillingGatheringInvoiceLines() predicate.SubscriptionItem { + return predicate.SubscriptionItem(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasBillingGatheringInvoiceLinesWith applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge with a given conditions (other predicates). +func HasBillingGatheringInvoiceLinesWith(preds ...predicate.BillingGatheringInvoiceLine) predicate.SubscriptionItem { + return predicate.SubscriptionItem(func(s *sql.Selector) { + step := newBillingGatheringInvoiceLinesStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // HasBillingSplitLineGroups applies the HasEdge predicate on the "billing_split_line_groups" edge. func HasBillingSplitLineGroups() predicate.SubscriptionItem { return predicate.SubscriptionItem(func(s *sql.Selector) { diff --git a/openmeter/ent/db/subscriptionitem_create.go b/openmeter/ent/db/subscriptionitem_create.go index e9f28c18a4..42681e6e9b 100644 --- a/openmeter/ent/db/subscriptionitem_create.go +++ b/openmeter/ent/db/subscriptionitem_create.go @@ -12,6 +12,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" @@ -327,6 +328,21 @@ func (_c *SubscriptionItemCreate) AddBillingLines(v ...*BillingInvoiceLine) *Sub return _c.AddBillingLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_c *SubscriptionItemCreate) AddBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionItemCreate { + _c.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _c +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_c *SubscriptionItemCreate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionItemCreate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by IDs. func (_c *SubscriptionItemCreate) AddBillingSplitLineGroupIDs(ids ...string) *SubscriptionItemCreate { _c.mutation.AddBillingSplitLineGroupIDs(ids...) @@ -718,6 +734,22 @@ func (_c *SubscriptionItemCreate) createSpec() (*SubscriptionItem, *sqlgraph.Cre } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionitem.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionitem.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.BillingSplitLineGroupsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/openmeter/ent/db/subscriptionitem_query.go b/openmeter/ent/db/subscriptionitem_query.go index 3e96c7a763..235f7c205f 100644 --- a/openmeter/ent/db/subscriptionitem_query.go +++ b/openmeter/ent/db/subscriptionitem_query.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" @@ -28,19 +29,20 @@ import ( // SubscriptionItemQuery is the builder for querying SubscriptionItem entities. type SubscriptionItemQuery struct { config - ctx *QueryContext - order []subscriptionitem.OrderOption - inters []Interceptor - predicates []predicate.SubscriptionItem - withPhase *SubscriptionPhaseQuery - withEntitlement *EntitlementQuery - withBillingLines *BillingInvoiceLineQuery - withBillingSplitLineGroups *BillingInvoiceSplitLineGroupQuery - withChargesUsageBased *ChargeUsageBasedQuery - withChargesCreditPurchase *ChargeCreditPurchaseQuery - withChargesFlatFee *ChargeFlatFeeQuery - withTaxCode *TaxCodeQuery - modifiers []func(*sql.Selector) + ctx *QueryContext + order []subscriptionitem.OrderOption + inters []Interceptor + predicates []predicate.SubscriptionItem + withPhase *SubscriptionPhaseQuery + withEntitlement *EntitlementQuery + withBillingLines *BillingInvoiceLineQuery + withBillingGatheringInvoiceLines *BillingGatheringInvoiceLineQuery + withBillingSplitLineGroups *BillingInvoiceSplitLineGroupQuery + withChargesUsageBased *ChargeUsageBasedQuery + withChargesCreditPurchase *ChargeCreditPurchaseQuery + withChargesFlatFee *ChargeFlatFeeQuery + withTaxCode *TaxCodeQuery + modifiers []func(*sql.Selector) // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -143,6 +145,28 @@ func (_q *SubscriptionItemQuery) QueryBillingLines() *BillingInvoiceLineQuery { return query } +// QueryBillingGatheringInvoiceLines chains the current query on the "billing_gathering_invoice_lines" edge. +func (_q *SubscriptionItemQuery) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(subscriptionitem.Table, subscriptionitem.FieldID, selector), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, subscriptionitem.BillingGatheringInvoiceLinesTable, subscriptionitem.BillingGatheringInvoiceLinesColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryBillingSplitLineGroups chains the current query on the "billing_split_line_groups" edge. func (_q *SubscriptionItemQuery) QueryBillingSplitLineGroups() *BillingInvoiceSplitLineGroupQuery { query := (&BillingInvoiceSplitLineGroupClient{config: _q.config}).Query() @@ -440,19 +464,20 @@ func (_q *SubscriptionItemQuery) Clone() *SubscriptionItemQuery { return nil } return &SubscriptionItemQuery{ - config: _q.config, - ctx: _q.ctx.Clone(), - order: append([]subscriptionitem.OrderOption{}, _q.order...), - inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.SubscriptionItem{}, _q.predicates...), - withPhase: _q.withPhase.Clone(), - withEntitlement: _q.withEntitlement.Clone(), - withBillingLines: _q.withBillingLines.Clone(), - withBillingSplitLineGroups: _q.withBillingSplitLineGroups.Clone(), - withChargesUsageBased: _q.withChargesUsageBased.Clone(), - withChargesCreditPurchase: _q.withChargesCreditPurchase.Clone(), - withChargesFlatFee: _q.withChargesFlatFee.Clone(), - withTaxCode: _q.withTaxCode.Clone(), + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]subscriptionitem.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.SubscriptionItem{}, _q.predicates...), + withPhase: _q.withPhase.Clone(), + withEntitlement: _q.withEntitlement.Clone(), + withBillingLines: _q.withBillingLines.Clone(), + withBillingGatheringInvoiceLines: _q.withBillingGatheringInvoiceLines.Clone(), + withBillingSplitLineGroups: _q.withBillingSplitLineGroups.Clone(), + withChargesUsageBased: _q.withChargesUsageBased.Clone(), + withChargesCreditPurchase: _q.withChargesCreditPurchase.Clone(), + withChargesFlatFee: _q.withChargesFlatFee.Clone(), + withTaxCode: _q.withTaxCode.Clone(), // clone intermediate query. sql: _q.sql.Clone(), path: _q.path, @@ -492,6 +517,17 @@ func (_q *SubscriptionItemQuery) WithBillingLines(opts ...func(*BillingInvoiceLi return _q } +// WithBillingGatheringInvoiceLines tells the query-builder to eager-load the nodes that are connected to +// the "billing_gathering_invoice_lines" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *SubscriptionItemQuery) WithBillingGatheringInvoiceLines(opts ...func(*BillingGatheringInvoiceLineQuery)) *SubscriptionItemQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withBillingGatheringInvoiceLines = query + return _q +} + // WithBillingSplitLineGroups tells the query-builder to eager-load the nodes that are connected to // the "billing_split_line_groups" edge. The optional arguments are used to configure the query builder of the edge. func (_q *SubscriptionItemQuery) WithBillingSplitLineGroups(opts ...func(*BillingInvoiceSplitLineGroupQuery)) *SubscriptionItemQuery { @@ -625,10 +661,11 @@ func (_q *SubscriptionItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) var ( nodes = []*SubscriptionItem{} _spec = _q.querySpec() - loadedTypes = [8]bool{ + loadedTypes = [9]bool{ _q.withPhase != nil, _q.withEntitlement != nil, _q.withBillingLines != nil, + _q.withBillingGatheringInvoiceLines != nil, _q.withBillingSplitLineGroups != nil, _q.withChargesUsageBased != nil, _q.withChargesCreditPurchase != nil, @@ -678,6 +715,15 @@ func (_q *SubscriptionItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) return nil, err } } + if query := _q.withBillingGatheringInvoiceLines; query != nil { + if err := _q.loadBillingGatheringInvoiceLines(ctx, query, nodes, + func(n *SubscriptionItem) { n.Edges.BillingGatheringInvoiceLines = []*BillingGatheringInvoiceLine{} }, + func(n *SubscriptionItem, e *BillingGatheringInvoiceLine) { + n.Edges.BillingGatheringInvoiceLines = append(n.Edges.BillingGatheringInvoiceLines, e) + }); err != nil { + return nil, err + } + } if query := _q.withBillingSplitLineGroups; query != nil { if err := _q.loadBillingSplitLineGroups(ctx, query, nodes, func(n *SubscriptionItem) { n.Edges.BillingSplitLineGroups = []*BillingInvoiceSplitLineGroup{} }, @@ -818,6 +864,39 @@ func (_q *SubscriptionItemQuery) loadBillingLines(ctx context.Context, query *Bi } return nil } +func (_q *SubscriptionItemQuery) loadBillingGatheringInvoiceLines(ctx context.Context, query *BillingGatheringInvoiceLineQuery, nodes []*SubscriptionItem, init func(*SubscriptionItem), assign func(*SubscriptionItem, *BillingGatheringInvoiceLine)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[string]*SubscriptionItem) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(billinggatheringinvoiceline.FieldSubscriptionItemID) + } + query.Where(predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(subscriptionitem.BillingGatheringInvoiceLinesColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.SubscriptionItemID + if fk == nil { + return fmt.Errorf(`foreign-key "subscription_item_id" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "subscription_item_id" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} func (_q *SubscriptionItemQuery) loadBillingSplitLineGroups(ctx context.Context, query *BillingInvoiceSplitLineGroupQuery, nodes []*SubscriptionItem, init func(*SubscriptionItem), assign func(*SubscriptionItem, *BillingInvoiceSplitLineGroup)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[string]*SubscriptionItem) diff --git a/openmeter/ent/db/subscriptionitem_update.go b/openmeter/ent/db/subscriptionitem_update.go index 8db1b7cdff..66c0def8a4 100644 --- a/openmeter/ent/db/subscriptionitem_update.go +++ b/openmeter/ent/db/subscriptionitem_update.go @@ -11,6 +11,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" @@ -396,6 +397,21 @@ func (_u *SubscriptionItemUpdate) AddBillingLines(v ...*BillingInvoiceLine) *Sub return _u.AddBillingLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *SubscriptionItemUpdate) AddBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionItemUpdate { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *SubscriptionItemUpdate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionItemUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by IDs. func (_u *SubscriptionItemUpdate) AddBillingSplitLineGroupIDs(ids ...string) *SubscriptionItemUpdate { _u.mutation.AddBillingSplitLineGroupIDs(ids...) @@ -493,6 +509,27 @@ func (_u *SubscriptionItemUpdate) RemoveBillingLines(v ...*BillingInvoiceLine) * return _u.RemoveBillingLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *SubscriptionItemUpdate) ClearBillingGatheringInvoiceLines() *SubscriptionItemUpdate { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *SubscriptionItemUpdate) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionItemUpdate { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *SubscriptionItemUpdate) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionItemUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearBillingSplitLineGroups clears all "billing_split_line_groups" edges to the BillingInvoiceSplitLineGroup entity. func (_u *SubscriptionItemUpdate) ClearBillingSplitLineGroups() *SubscriptionItemUpdate { _u.mutation.ClearBillingSplitLineGroups() @@ -877,6 +914,51 @@ func (_u *SubscriptionItemUpdate) sqlSave(ctx context.Context) (_node int, err e } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionitem.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionitem.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionitem.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionitem.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionitem.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionitem.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.BillingSplitLineGroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -1464,6 +1546,21 @@ func (_u *SubscriptionItemUpdateOne) AddBillingLines(v ...*BillingInvoiceLine) * return _u.AddBillingLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *SubscriptionItemUpdateOne) AddBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionItemUpdateOne { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *SubscriptionItemUpdateOne) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionItemUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by IDs. func (_u *SubscriptionItemUpdateOne) AddBillingSplitLineGroupIDs(ids ...string) *SubscriptionItemUpdateOne { _u.mutation.AddBillingSplitLineGroupIDs(ids...) @@ -1561,6 +1658,27 @@ func (_u *SubscriptionItemUpdateOne) RemoveBillingLines(v ...*BillingInvoiceLine return _u.RemoveBillingLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *SubscriptionItemUpdateOne) ClearBillingGatheringInvoiceLines() *SubscriptionItemUpdateOne { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *SubscriptionItemUpdateOne) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionItemUpdateOne { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *SubscriptionItemUpdateOne) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionItemUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearBillingSplitLineGroups clears all "billing_split_line_groups" edges to the BillingInvoiceSplitLineGroup entity. func (_u *SubscriptionItemUpdateOne) ClearBillingSplitLineGroups() *SubscriptionItemUpdateOne { _u.mutation.ClearBillingSplitLineGroups() @@ -1975,6 +2093,51 @@ func (_u *SubscriptionItemUpdateOne) sqlSave(ctx context.Context) (_node *Subscr } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionitem.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionitem.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionitem.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionitem.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionitem.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionitem.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.BillingSplitLineGroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/openmeter/ent/db/subscriptionphase.go b/openmeter/ent/db/subscriptionphase.go index e16ae85b6b..4c0b382552 100644 --- a/openmeter/ent/db/subscriptionphase.go +++ b/openmeter/ent/db/subscriptionphase.go @@ -55,6 +55,8 @@ type SubscriptionPhaseEdges struct { Items []*SubscriptionItem `json:"items,omitempty"` // BillingLines holds the value of the billing_lines edge. BillingLines []*BillingInvoiceLine `json:"billing_lines,omitempty"` + // BillingGatheringInvoiceLines holds the value of the billing_gathering_invoice_lines edge. + BillingGatheringInvoiceLines []*BillingGatheringInvoiceLine `json:"billing_gathering_invoice_lines,omitempty"` // BillingSplitLineGroups holds the value of the billing_split_line_groups edge. BillingSplitLineGroups []*BillingInvoiceSplitLineGroup `json:"billing_split_line_groups,omitempty"` // ChargesUsageBased holds the value of the charges_usage_based edge. @@ -65,7 +67,7 @@ type SubscriptionPhaseEdges struct { ChargesFlatFee []*ChargeFlatFee `json:"charges_flat_fee,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [7]bool + loadedTypes [8]bool } // SubscriptionOrErr returns the Subscription value or an error if the edge @@ -97,10 +99,19 @@ func (e SubscriptionPhaseEdges) BillingLinesOrErr() ([]*BillingInvoiceLine, erro return nil, &NotLoadedError{edge: "billing_lines"} } +// BillingGatheringInvoiceLinesOrErr returns the BillingGatheringInvoiceLines value or an error if the edge +// was not loaded in eager-loading. +func (e SubscriptionPhaseEdges) BillingGatheringInvoiceLinesOrErr() ([]*BillingGatheringInvoiceLine, error) { + if e.loadedTypes[3] { + return e.BillingGatheringInvoiceLines, nil + } + return nil, &NotLoadedError{edge: "billing_gathering_invoice_lines"} +} + // BillingSplitLineGroupsOrErr returns the BillingSplitLineGroups value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionPhaseEdges) BillingSplitLineGroupsOrErr() ([]*BillingInvoiceSplitLineGroup, error) { - if e.loadedTypes[3] { + if e.loadedTypes[4] { return e.BillingSplitLineGroups, nil } return nil, &NotLoadedError{edge: "billing_split_line_groups"} @@ -109,7 +120,7 @@ func (e SubscriptionPhaseEdges) BillingSplitLineGroupsOrErr() ([]*BillingInvoice // ChargesUsageBasedOrErr returns the ChargesUsageBased value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionPhaseEdges) ChargesUsageBasedOrErr() ([]*ChargeUsageBased, error) { - if e.loadedTypes[4] { + if e.loadedTypes[5] { return e.ChargesUsageBased, nil } return nil, &NotLoadedError{edge: "charges_usage_based"} @@ -118,7 +129,7 @@ func (e SubscriptionPhaseEdges) ChargesUsageBasedOrErr() ([]*ChargeUsageBased, e // ChargesCreditPurchaseOrErr returns the ChargesCreditPurchase value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionPhaseEdges) ChargesCreditPurchaseOrErr() ([]*ChargeCreditPurchase, error) { - if e.loadedTypes[5] { + if e.loadedTypes[6] { return e.ChargesCreditPurchase, nil } return nil, &NotLoadedError{edge: "charges_credit_purchase"} @@ -127,7 +138,7 @@ func (e SubscriptionPhaseEdges) ChargesCreditPurchaseOrErr() ([]*ChargeCreditPur // ChargesFlatFeeOrErr returns the ChargesFlatFee value or an error if the edge // was not loaded in eager-loading. func (e SubscriptionPhaseEdges) ChargesFlatFeeOrErr() ([]*ChargeFlatFee, error) { - if e.loadedTypes[6] { + if e.loadedTypes[7] { return e.ChargesFlatFee, nil } return nil, &NotLoadedError{edge: "charges_flat_fee"} @@ -266,6 +277,11 @@ func (_m *SubscriptionPhase) QueryBillingLines() *BillingInvoiceLineQuery { return NewSubscriptionPhaseClient(_m.config).QueryBillingLines(_m) } +// QueryBillingGatheringInvoiceLines queries the "billing_gathering_invoice_lines" edge of the SubscriptionPhase entity. +func (_m *SubscriptionPhase) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + return NewSubscriptionPhaseClient(_m.config).QueryBillingGatheringInvoiceLines(_m) +} + // QueryBillingSplitLineGroups queries the "billing_split_line_groups" edge of the SubscriptionPhase entity. func (_m *SubscriptionPhase) QueryBillingSplitLineGroups() *BillingInvoiceSplitLineGroupQuery { return NewSubscriptionPhaseClient(_m.config).QueryBillingSplitLineGroups(_m) diff --git a/openmeter/ent/db/subscriptionphase/subscriptionphase.go b/openmeter/ent/db/subscriptionphase/subscriptionphase.go index b6bc803a27..3882db4cf3 100644 --- a/openmeter/ent/db/subscriptionphase/subscriptionphase.go +++ b/openmeter/ent/db/subscriptionphase/subscriptionphase.go @@ -42,6 +42,8 @@ const ( EdgeItems = "items" // EdgeBillingLines holds the string denoting the billing_lines edge name in mutations. EdgeBillingLines = "billing_lines" + // EdgeBillingGatheringInvoiceLines holds the string denoting the billing_gathering_invoice_lines edge name in mutations. + EdgeBillingGatheringInvoiceLines = "billing_gathering_invoice_lines" // EdgeBillingSplitLineGroups holds the string denoting the billing_split_line_groups edge name in mutations. EdgeBillingSplitLineGroups = "billing_split_line_groups" // EdgeChargesUsageBased holds the string denoting the charges_usage_based edge name in mutations. @@ -73,6 +75,13 @@ const ( BillingLinesInverseTable = "billing_invoice_lines" // BillingLinesColumn is the table column denoting the billing_lines relation/edge. BillingLinesColumn = "subscription_phase_id" + // BillingGatheringInvoiceLinesTable is the table that holds the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesInverseTable is the table name for the BillingGatheringInvoiceLine entity. + // It exists in this package in order to avoid circular dependency with the "billinggatheringinvoiceline" package. + BillingGatheringInvoiceLinesInverseTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesColumn is the table column denoting the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesColumn = "subscription_phase_id" // BillingSplitLineGroupsTable is the table that holds the billing_split_line_groups relation/edge. BillingSplitLineGroupsTable = "billing_invoice_split_line_groups" // BillingSplitLineGroupsInverseTable is the table name for the BillingInvoiceSplitLineGroup entity. @@ -241,6 +250,20 @@ func ByBillingLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { } } +// ByBillingGatheringInvoiceLinesCount orders the results by billing_gathering_invoice_lines count. +func ByBillingGatheringInvoiceLinesCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newBillingGatheringInvoiceLinesStep(), opts...) + } +} + +// ByBillingGatheringInvoiceLines orders the results by billing_gathering_invoice_lines terms. +func ByBillingGatheringInvoiceLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newBillingGatheringInvoiceLinesStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + // ByBillingSplitLineGroupsCount orders the results by billing_split_line_groups count. func ByBillingSplitLineGroupsCount(opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -317,6 +340,13 @@ func newBillingLinesStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, BillingLinesTable, BillingLinesColumn), ) } +func newBillingGatheringInvoiceLinesStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(BillingGatheringInvoiceLinesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) +} func newBillingSplitLineGroupsStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/openmeter/ent/db/subscriptionphase/where.go b/openmeter/ent/db/subscriptionphase/where.go index b75c5ef423..e84be3d9d8 100644 --- a/openmeter/ent/db/subscriptionphase/where.go +++ b/openmeter/ent/db/subscriptionphase/where.go @@ -749,6 +749,29 @@ func HasBillingLinesWith(preds ...predicate.BillingInvoiceLine) predicate.Subscr }) } +// HasBillingGatheringInvoiceLines applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge. +func HasBillingGatheringInvoiceLines() predicate.SubscriptionPhase { + return predicate.SubscriptionPhase(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasBillingGatheringInvoiceLinesWith applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge with a given conditions (other predicates). +func HasBillingGatheringInvoiceLinesWith(preds ...predicate.BillingGatheringInvoiceLine) predicate.SubscriptionPhase { + return predicate.SubscriptionPhase(func(s *sql.Selector) { + step := newBillingGatheringInvoiceLinesStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // HasBillingSplitLineGroups applies the HasEdge predicate on the "billing_split_line_groups" edge. func HasBillingSplitLineGroups() predicate.SubscriptionPhase { return predicate.SubscriptionPhase(func(s *sql.Selector) { diff --git a/openmeter/ent/db/subscriptionphase_create.go b/openmeter/ent/db/subscriptionphase_create.go index 7c5fb71dbb..88cf0e42fc 100644 --- a/openmeter/ent/db/subscriptionphase_create.go +++ b/openmeter/ent/db/subscriptionphase_create.go @@ -12,6 +12,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" @@ -185,6 +186,21 @@ func (_c *SubscriptionPhaseCreate) AddBillingLines(v ...*BillingInvoiceLine) *Su return _c.AddBillingLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_c *SubscriptionPhaseCreate) AddBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionPhaseCreate { + _c.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _c +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_c *SubscriptionPhaseCreate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionPhaseCreate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by IDs. func (_c *SubscriptionPhaseCreate) AddBillingSplitLineGroupIDs(ids ...string) *SubscriptionPhaseCreate { _c.mutation.AddBillingSplitLineGroupIDs(ids...) @@ -465,6 +481,22 @@ func (_c *SubscriptionPhaseCreate) createSpec() (*SubscriptionPhase, *sqlgraph.C } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionphase.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionphase.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.BillingSplitLineGroupsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/openmeter/ent/db/subscriptionphase_query.go b/openmeter/ent/db/subscriptionphase_query.go index feeb963f9c..fef7390f37 100644 --- a/openmeter/ent/db/subscriptionphase_query.go +++ b/openmeter/ent/db/subscriptionphase_query.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" @@ -27,18 +28,19 @@ import ( // SubscriptionPhaseQuery is the builder for querying SubscriptionPhase entities. type SubscriptionPhaseQuery struct { config - ctx *QueryContext - order []subscriptionphase.OrderOption - inters []Interceptor - predicates []predicate.SubscriptionPhase - withSubscription *SubscriptionQuery - withItems *SubscriptionItemQuery - withBillingLines *BillingInvoiceLineQuery - withBillingSplitLineGroups *BillingInvoiceSplitLineGroupQuery - withChargesUsageBased *ChargeUsageBasedQuery - withChargesCreditPurchase *ChargeCreditPurchaseQuery - withChargesFlatFee *ChargeFlatFeeQuery - modifiers []func(*sql.Selector) + ctx *QueryContext + order []subscriptionphase.OrderOption + inters []Interceptor + predicates []predicate.SubscriptionPhase + withSubscription *SubscriptionQuery + withItems *SubscriptionItemQuery + withBillingLines *BillingInvoiceLineQuery + withBillingGatheringInvoiceLines *BillingGatheringInvoiceLineQuery + withBillingSplitLineGroups *BillingInvoiceSplitLineGroupQuery + withChargesUsageBased *ChargeUsageBasedQuery + withChargesCreditPurchase *ChargeCreditPurchaseQuery + withChargesFlatFee *ChargeFlatFeeQuery + modifiers []func(*sql.Selector) // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -141,6 +143,28 @@ func (_q *SubscriptionPhaseQuery) QueryBillingLines() *BillingInvoiceLineQuery { return query } +// QueryBillingGatheringInvoiceLines chains the current query on the "billing_gathering_invoice_lines" edge. +func (_q *SubscriptionPhaseQuery) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(subscriptionphase.Table, subscriptionphase.FieldID, selector), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, subscriptionphase.BillingGatheringInvoiceLinesTable, subscriptionphase.BillingGatheringInvoiceLinesColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryBillingSplitLineGroups chains the current query on the "billing_split_line_groups" edge. func (_q *SubscriptionPhaseQuery) QueryBillingSplitLineGroups() *BillingInvoiceSplitLineGroupQuery { query := (&BillingInvoiceSplitLineGroupClient{config: _q.config}).Query() @@ -416,18 +440,19 @@ func (_q *SubscriptionPhaseQuery) Clone() *SubscriptionPhaseQuery { return nil } return &SubscriptionPhaseQuery{ - config: _q.config, - ctx: _q.ctx.Clone(), - order: append([]subscriptionphase.OrderOption{}, _q.order...), - inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.SubscriptionPhase{}, _q.predicates...), - withSubscription: _q.withSubscription.Clone(), - withItems: _q.withItems.Clone(), - withBillingLines: _q.withBillingLines.Clone(), - withBillingSplitLineGroups: _q.withBillingSplitLineGroups.Clone(), - withChargesUsageBased: _q.withChargesUsageBased.Clone(), - withChargesCreditPurchase: _q.withChargesCreditPurchase.Clone(), - withChargesFlatFee: _q.withChargesFlatFee.Clone(), + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]subscriptionphase.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.SubscriptionPhase{}, _q.predicates...), + withSubscription: _q.withSubscription.Clone(), + withItems: _q.withItems.Clone(), + withBillingLines: _q.withBillingLines.Clone(), + withBillingGatheringInvoiceLines: _q.withBillingGatheringInvoiceLines.Clone(), + withBillingSplitLineGroups: _q.withBillingSplitLineGroups.Clone(), + withChargesUsageBased: _q.withChargesUsageBased.Clone(), + withChargesCreditPurchase: _q.withChargesCreditPurchase.Clone(), + withChargesFlatFee: _q.withChargesFlatFee.Clone(), // clone intermediate query. sql: _q.sql.Clone(), path: _q.path, @@ -467,6 +492,17 @@ func (_q *SubscriptionPhaseQuery) WithBillingLines(opts ...func(*BillingInvoiceL return _q } +// WithBillingGatheringInvoiceLines tells the query-builder to eager-load the nodes that are connected to +// the "billing_gathering_invoice_lines" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *SubscriptionPhaseQuery) WithBillingGatheringInvoiceLines(opts ...func(*BillingGatheringInvoiceLineQuery)) *SubscriptionPhaseQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withBillingGatheringInvoiceLines = query + return _q +} + // WithBillingSplitLineGroups tells the query-builder to eager-load the nodes that are connected to // the "billing_split_line_groups" edge. The optional arguments are used to configure the query builder of the edge. func (_q *SubscriptionPhaseQuery) WithBillingSplitLineGroups(opts ...func(*BillingInvoiceSplitLineGroupQuery)) *SubscriptionPhaseQuery { @@ -589,10 +625,11 @@ func (_q *SubscriptionPhaseQuery) sqlAll(ctx context.Context, hooks ...queryHook var ( nodes = []*SubscriptionPhase{} _spec = _q.querySpec() - loadedTypes = [7]bool{ + loadedTypes = [8]bool{ _q.withSubscription != nil, _q.withItems != nil, _q.withBillingLines != nil, + _q.withBillingGatheringInvoiceLines != nil, _q.withBillingSplitLineGroups != nil, _q.withChargesUsageBased != nil, _q.withChargesCreditPurchase != nil, @@ -642,6 +679,15 @@ func (_q *SubscriptionPhaseQuery) sqlAll(ctx context.Context, hooks ...queryHook return nil, err } } + if query := _q.withBillingGatheringInvoiceLines; query != nil { + if err := _q.loadBillingGatheringInvoiceLines(ctx, query, nodes, + func(n *SubscriptionPhase) { n.Edges.BillingGatheringInvoiceLines = []*BillingGatheringInvoiceLine{} }, + func(n *SubscriptionPhase, e *BillingGatheringInvoiceLine) { + n.Edges.BillingGatheringInvoiceLines = append(n.Edges.BillingGatheringInvoiceLines, e) + }); err != nil { + return nil, err + } + } if query := _q.withBillingSplitLineGroups; query != nil { if err := _q.loadBillingSplitLineGroups(ctx, query, nodes, func(n *SubscriptionPhase) { n.Edges.BillingSplitLineGroups = []*BillingInvoiceSplitLineGroup{} }, @@ -774,6 +820,39 @@ func (_q *SubscriptionPhaseQuery) loadBillingLines(ctx context.Context, query *B } return nil } +func (_q *SubscriptionPhaseQuery) loadBillingGatheringInvoiceLines(ctx context.Context, query *BillingGatheringInvoiceLineQuery, nodes []*SubscriptionPhase, init func(*SubscriptionPhase), assign func(*SubscriptionPhase, *BillingGatheringInvoiceLine)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[string]*SubscriptionPhase) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(billinggatheringinvoiceline.FieldSubscriptionPhaseID) + } + query.Where(predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(subscriptionphase.BillingGatheringInvoiceLinesColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.SubscriptionPhaseID + if fk == nil { + return fmt.Errorf(`foreign-key "subscription_phase_id" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "subscription_phase_id" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} func (_q *SubscriptionPhaseQuery) loadBillingSplitLineGroups(ctx context.Context, query *BillingInvoiceSplitLineGroupQuery, nodes []*SubscriptionPhase, init func(*SubscriptionPhase), assign func(*SubscriptionPhase, *BillingInvoiceSplitLineGroup)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[string]*SubscriptionPhase) diff --git a/openmeter/ent/db/subscriptionphase_update.go b/openmeter/ent/db/subscriptionphase_update.go index 4dc27443b8..d454314536 100644 --- a/openmeter/ent/db/subscriptionphase_update.go +++ b/openmeter/ent/db/subscriptionphase_update.go @@ -11,6 +11,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoicesplitlinegroup" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" @@ -163,6 +164,21 @@ func (_u *SubscriptionPhaseUpdate) AddBillingLines(v ...*BillingInvoiceLine) *Su return _u.AddBillingLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *SubscriptionPhaseUpdate) AddBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionPhaseUpdate { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *SubscriptionPhaseUpdate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionPhaseUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by IDs. func (_u *SubscriptionPhaseUpdate) AddBillingSplitLineGroupIDs(ids ...string) *SubscriptionPhaseUpdate { _u.mutation.AddBillingSplitLineGroupIDs(ids...) @@ -270,6 +286,27 @@ func (_u *SubscriptionPhaseUpdate) RemoveBillingLines(v ...*BillingInvoiceLine) return _u.RemoveBillingLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *SubscriptionPhaseUpdate) ClearBillingGatheringInvoiceLines() *SubscriptionPhaseUpdate { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *SubscriptionPhaseUpdate) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionPhaseUpdate { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *SubscriptionPhaseUpdate) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionPhaseUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearBillingSplitLineGroups clears all "billing_split_line_groups" edges to the BillingInvoiceSplitLineGroup entity. func (_u *SubscriptionPhaseUpdate) ClearBillingSplitLineGroups() *SubscriptionPhaseUpdate { _u.mutation.ClearBillingSplitLineGroups() @@ -538,6 +575,51 @@ func (_u *SubscriptionPhaseUpdate) sqlSave(ctx context.Context) (_node int, err } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionphase.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionphase.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionphase.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionphase.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionphase.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionphase.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.BillingSplitLineGroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -867,6 +949,21 @@ func (_u *SubscriptionPhaseUpdateOne) AddBillingLines(v ...*BillingInvoiceLine) return _u.AddBillingLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *SubscriptionPhaseUpdateOne) AddBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionPhaseUpdateOne { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *SubscriptionPhaseUpdateOne) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionPhaseUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddBillingSplitLineGroupIDs adds the "billing_split_line_groups" edge to the BillingInvoiceSplitLineGroup entity by IDs. func (_u *SubscriptionPhaseUpdateOne) AddBillingSplitLineGroupIDs(ids ...string) *SubscriptionPhaseUpdateOne { _u.mutation.AddBillingSplitLineGroupIDs(ids...) @@ -974,6 +1071,27 @@ func (_u *SubscriptionPhaseUpdateOne) RemoveBillingLines(v ...*BillingInvoiceLin return _u.RemoveBillingLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *SubscriptionPhaseUpdateOne) ClearBillingGatheringInvoiceLines() *SubscriptionPhaseUpdateOne { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *SubscriptionPhaseUpdateOne) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *SubscriptionPhaseUpdateOne { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *SubscriptionPhaseUpdateOne) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *SubscriptionPhaseUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearBillingSplitLineGroups clears all "billing_split_line_groups" edges to the BillingInvoiceSplitLineGroup entity. func (_u *SubscriptionPhaseUpdateOne) ClearBillingSplitLineGroups() *SubscriptionPhaseUpdateOne { _u.mutation.ClearBillingSplitLineGroups() @@ -1272,6 +1390,51 @@ func (_u *SubscriptionPhaseUpdateOne) sqlSave(ctx context.Context) (_node *Subsc } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionphase.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionphase.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionphase.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionphase.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: subscriptionphase.BillingGatheringInvoiceLinesTable, + Columns: []string{subscriptionphase.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.BillingSplitLineGroupsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/openmeter/ent/db/taxcode.go b/openmeter/ent/db/taxcode.go index 7afb77896e..181d5a262a 100644 --- a/openmeter/ent/db/taxcode.go +++ b/openmeter/ent/db/taxcode.go @@ -54,6 +54,8 @@ type TaxCodeEdges struct { BillingCustomerOverrides []*BillingCustomerOverride `json:"billing_customer_overrides,omitempty"` // BillingInvoiceLines holds the value of the billing_invoice_lines edge. BillingInvoiceLines []*BillingInvoiceLine `json:"billing_invoice_lines,omitempty"` + // BillingGatheringInvoiceLines holds the value of the billing_gathering_invoice_lines edge. + BillingGatheringInvoiceLines []*BillingGatheringInvoiceLine `json:"billing_gathering_invoice_lines,omitempty"` // SubscriptionItems holds the value of the subscription_items edge. SubscriptionItems []*SubscriptionItem `json:"subscription_items,omitempty"` // PlanRateCards holds the value of the plan_rate_cards edge. @@ -76,7 +78,7 @@ type TaxCodeEdges struct { OrganizationDefaultCreditGrant []*OrganizationDefaultTaxCodes `json:"organization_default_credit_grant,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [13]bool + loadedTypes [14]bool } // BillingWorkflowConfigsOrErr returns the BillingWorkflowConfigs value or an error if the edge @@ -106,10 +108,19 @@ func (e TaxCodeEdges) BillingInvoiceLinesOrErr() ([]*BillingInvoiceLine, error) return nil, &NotLoadedError{edge: "billing_invoice_lines"} } +// BillingGatheringInvoiceLinesOrErr returns the BillingGatheringInvoiceLines value or an error if the edge +// was not loaded in eager-loading. +func (e TaxCodeEdges) BillingGatheringInvoiceLinesOrErr() ([]*BillingGatheringInvoiceLine, error) { + if e.loadedTypes[3] { + return e.BillingGatheringInvoiceLines, nil + } + return nil, &NotLoadedError{edge: "billing_gathering_invoice_lines"} +} + // SubscriptionItemsOrErr returns the SubscriptionItems value or an error if the edge // was not loaded in eager-loading. func (e TaxCodeEdges) SubscriptionItemsOrErr() ([]*SubscriptionItem, error) { - if e.loadedTypes[3] { + if e.loadedTypes[4] { return e.SubscriptionItems, nil } return nil, &NotLoadedError{edge: "subscription_items"} @@ -118,7 +129,7 @@ func (e TaxCodeEdges) SubscriptionItemsOrErr() ([]*SubscriptionItem, error) { // PlanRateCardsOrErr returns the PlanRateCards value or an error if the edge // was not loaded in eager-loading. func (e TaxCodeEdges) PlanRateCardsOrErr() ([]*PlanRateCard, error) { - if e.loadedTypes[4] { + if e.loadedTypes[5] { return e.PlanRateCards, nil } return nil, &NotLoadedError{edge: "plan_rate_cards"} @@ -127,7 +138,7 @@ func (e TaxCodeEdges) PlanRateCardsOrErr() ([]*PlanRateCard, error) { // AddonRateCardsOrErr returns the AddonRateCards value or an error if the edge // was not loaded in eager-loading. func (e TaxCodeEdges) AddonRateCardsOrErr() ([]*AddonRateCard, error) { - if e.loadedTypes[5] { + if e.loadedTypes[6] { return e.AddonRateCards, nil } return nil, &NotLoadedError{edge: "addon_rate_cards"} @@ -136,7 +147,7 @@ func (e TaxCodeEdges) AddonRateCardsOrErr() ([]*AddonRateCard, error) { // ChargeFlatFeesOrErr returns the ChargeFlatFees value or an error if the edge // was not loaded in eager-loading. func (e TaxCodeEdges) ChargeFlatFeesOrErr() ([]*ChargeFlatFee, error) { - if e.loadedTypes[6] { + if e.loadedTypes[7] { return e.ChargeFlatFees, nil } return nil, &NotLoadedError{edge: "charge_flat_fees"} @@ -145,7 +156,7 @@ func (e TaxCodeEdges) ChargeFlatFeesOrErr() ([]*ChargeFlatFee, error) { // ChargeFlatFeeOverridesOrErr returns the ChargeFlatFeeOverrides value or an error if the edge // was not loaded in eager-loading. func (e TaxCodeEdges) ChargeFlatFeeOverridesOrErr() ([]*ChargeFlatFeeOverride, error) { - if e.loadedTypes[7] { + if e.loadedTypes[8] { return e.ChargeFlatFeeOverrides, nil } return nil, &NotLoadedError{edge: "charge_flat_fee_overrides"} @@ -154,7 +165,7 @@ func (e TaxCodeEdges) ChargeFlatFeeOverridesOrErr() ([]*ChargeFlatFeeOverride, e // ChargeUsageBasedOrErr returns the ChargeUsageBased value or an error if the edge // was not loaded in eager-loading. func (e TaxCodeEdges) ChargeUsageBasedOrErr() ([]*ChargeUsageBased, error) { - if e.loadedTypes[8] { + if e.loadedTypes[9] { return e.ChargeUsageBased, nil } return nil, &NotLoadedError{edge: "charge_usage_based"} @@ -163,7 +174,7 @@ func (e TaxCodeEdges) ChargeUsageBasedOrErr() ([]*ChargeUsageBased, error) { // ChargeUsageBasedOverridesOrErr returns the ChargeUsageBasedOverrides value or an error if the edge // was not loaded in eager-loading. func (e TaxCodeEdges) ChargeUsageBasedOverridesOrErr() ([]*ChargeUsageBasedOverride, error) { - if e.loadedTypes[9] { + if e.loadedTypes[10] { return e.ChargeUsageBasedOverrides, nil } return nil, &NotLoadedError{edge: "charge_usage_based_overrides"} @@ -172,7 +183,7 @@ func (e TaxCodeEdges) ChargeUsageBasedOverridesOrErr() ([]*ChargeUsageBasedOverr // ChargeCreditPurchasesOrErr returns the ChargeCreditPurchases value or an error if the edge // was not loaded in eager-loading. func (e TaxCodeEdges) ChargeCreditPurchasesOrErr() ([]*ChargeCreditPurchase, error) { - if e.loadedTypes[10] { + if e.loadedTypes[11] { return e.ChargeCreditPurchases, nil } return nil, &NotLoadedError{edge: "charge_credit_purchases"} @@ -181,7 +192,7 @@ func (e TaxCodeEdges) ChargeCreditPurchasesOrErr() ([]*ChargeCreditPurchase, err // OrganizationDefaultInvoicingOrErr returns the OrganizationDefaultInvoicing value or an error if the edge // was not loaded in eager-loading. func (e TaxCodeEdges) OrganizationDefaultInvoicingOrErr() ([]*OrganizationDefaultTaxCodes, error) { - if e.loadedTypes[11] { + if e.loadedTypes[12] { return e.OrganizationDefaultInvoicing, nil } return nil, &NotLoadedError{edge: "organization_default_invoicing"} @@ -190,7 +201,7 @@ func (e TaxCodeEdges) OrganizationDefaultInvoicingOrErr() ([]*OrganizationDefaul // OrganizationDefaultCreditGrantOrErr returns the OrganizationDefaultCreditGrant value or an error if the edge // was not loaded in eager-loading. func (e TaxCodeEdges) OrganizationDefaultCreditGrantOrErr() ([]*OrganizationDefaultTaxCodes, error) { - if e.loadedTypes[12] { + if e.loadedTypes[13] { return e.OrganizationDefaultCreditGrant, nil } return nil, &NotLoadedError{edge: "organization_default_credit_grant"} @@ -324,6 +335,11 @@ func (_m *TaxCode) QueryBillingInvoiceLines() *BillingInvoiceLineQuery { return NewTaxCodeClient(_m.config).QueryBillingInvoiceLines(_m) } +// QueryBillingGatheringInvoiceLines queries the "billing_gathering_invoice_lines" edge of the TaxCode entity. +func (_m *TaxCode) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + return NewTaxCodeClient(_m.config).QueryBillingGatheringInvoiceLines(_m) +} + // QuerySubscriptionItems queries the "subscription_items" edge of the TaxCode entity. func (_m *TaxCode) QuerySubscriptionItems() *SubscriptionItemQuery { return NewTaxCodeClient(_m.config).QuerySubscriptionItems(_m) diff --git a/openmeter/ent/db/taxcode/taxcode.go b/openmeter/ent/db/taxcode/taxcode.go index 9dea0ccf4b..ddffc55c07 100644 --- a/openmeter/ent/db/taxcode/taxcode.go +++ b/openmeter/ent/db/taxcode/taxcode.go @@ -42,6 +42,8 @@ const ( EdgeBillingCustomerOverrides = "billing_customer_overrides" // EdgeBillingInvoiceLines holds the string denoting the billing_invoice_lines edge name in mutations. EdgeBillingInvoiceLines = "billing_invoice_lines" + // EdgeBillingGatheringInvoiceLines holds the string denoting the billing_gathering_invoice_lines edge name in mutations. + EdgeBillingGatheringInvoiceLines = "billing_gathering_invoice_lines" // EdgeSubscriptionItems holds the string denoting the subscription_items edge name in mutations. EdgeSubscriptionItems = "subscription_items" // EdgePlanRateCards holds the string denoting the plan_rate_cards edge name in mutations. @@ -85,6 +87,13 @@ const ( BillingInvoiceLinesInverseTable = "billing_invoice_lines" // BillingInvoiceLinesColumn is the table column denoting the billing_invoice_lines relation/edge. BillingInvoiceLinesColumn = "tax_code_id" + // BillingGatheringInvoiceLinesTable is the table that holds the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesInverseTable is the table name for the BillingGatheringInvoiceLine entity. + // It exists in this package in order to avoid circular dependency with the "billinggatheringinvoiceline" package. + BillingGatheringInvoiceLinesInverseTable = "billing_gathering_invoice_lines" + // BillingGatheringInvoiceLinesColumn is the table column denoting the billing_gathering_invoice_lines relation/edge. + BillingGatheringInvoiceLinesColumn = "tax_code_id" // SubscriptionItemsTable is the table that holds the subscription_items relation/edge. SubscriptionItemsTable = "subscription_items" // SubscriptionItemsInverseTable is the table name for the SubscriptionItem entity. @@ -291,6 +300,20 @@ func ByBillingInvoiceLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOpti } } +// ByBillingGatheringInvoiceLinesCount orders the results by billing_gathering_invoice_lines count. +func ByBillingGatheringInvoiceLinesCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newBillingGatheringInvoiceLinesStep(), opts...) + } +} + +// ByBillingGatheringInvoiceLines orders the results by billing_gathering_invoice_lines terms. +func ByBillingGatheringInvoiceLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newBillingGatheringInvoiceLinesStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + // BySubscriptionItemsCount orders the results by subscription_items count. func BySubscriptionItemsCount(opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -451,6 +474,13 @@ func newBillingInvoiceLinesStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, BillingInvoiceLinesTable, BillingInvoiceLinesColumn), ) } +func newBillingGatheringInvoiceLinesStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(BillingGatheringInvoiceLinesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) +} func newSubscriptionItemsStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/openmeter/ent/db/taxcode/where.go b/openmeter/ent/db/taxcode/where.go index 3eb682a46c..f99428ff31 100644 --- a/openmeter/ent/db/taxcode/where.go +++ b/openmeter/ent/db/taxcode/where.go @@ -599,6 +599,29 @@ func HasBillingInvoiceLinesWith(preds ...predicate.BillingInvoiceLine) predicate }) } +// HasBillingGatheringInvoiceLines applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge. +func HasBillingGatheringInvoiceLines() predicate.TaxCode { + return predicate.TaxCode(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, BillingGatheringInvoiceLinesTable, BillingGatheringInvoiceLinesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasBillingGatheringInvoiceLinesWith applies the HasEdge predicate on the "billing_gathering_invoice_lines" edge with a given conditions (other predicates). +func HasBillingGatheringInvoiceLinesWith(preds ...predicate.BillingGatheringInvoiceLine) predicate.TaxCode { + return predicate.TaxCode(func(s *sql.Selector) { + step := newBillingGatheringInvoiceLinesStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // HasSubscriptionItems applies the HasEdge predicate on the "subscription_items" edge. func HasSubscriptionItems() predicate.TaxCode { return predicate.TaxCode(func(s *sql.Selector) { diff --git a/openmeter/ent/db/taxcode_create.go b/openmeter/ent/db/taxcode_create.go index 5898f5195d..ce804926ff 100644 --- a/openmeter/ent/db/taxcode_create.go +++ b/openmeter/ent/db/taxcode_create.go @@ -14,6 +14,7 @@ import ( "entgo.io/ent/schema/field" "github.com/openmeterio/openmeter/openmeter/ent/db/addonratecard" "github.com/openmeterio/openmeter/openmeter/ent/db/billingcustomeroverride" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billingworkflowconfig" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" @@ -188,6 +189,21 @@ func (_c *TaxCodeCreate) AddBillingInvoiceLines(v ...*BillingInvoiceLine) *TaxCo return _c.AddBillingInvoiceLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_c *TaxCodeCreate) AddBillingGatheringInvoiceLineIDs(ids ...string) *TaxCodeCreate { + _c.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _c +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_c *TaxCodeCreate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *TaxCodeCreate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _c.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddSubscriptionItemIDs adds the "subscription_items" edge to the SubscriptionItem entity by IDs. func (_c *TaxCodeCreate) AddSubscriptionItemIDs(ids ...string) *TaxCodeCreate { _c.mutation.AddSubscriptionItemIDs(ids...) @@ -550,6 +566,22 @@ func (_c *TaxCodeCreate) createSpec() (*TaxCode, *sqlgraph.CreateSpec, error) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: dbtaxcode.BillingGatheringInvoiceLinesTable, + Columns: []string{dbtaxcode.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.SubscriptionItemsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/openmeter/ent/db/taxcode_query.go b/openmeter/ent/db/taxcode_query.go index 5abbc1e02a..82008dabe9 100644 --- a/openmeter/ent/db/taxcode_query.go +++ b/openmeter/ent/db/taxcode_query.go @@ -15,6 +15,7 @@ import ( "entgo.io/ent/schema/field" "github.com/openmeterio/openmeter/openmeter/ent/db/addonratecard" "github.com/openmeterio/openmeter/openmeter/ent/db/billingcustomeroverride" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billingworkflowconfig" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" @@ -39,6 +40,7 @@ type TaxCodeQuery struct { withBillingWorkflowConfigs *BillingWorkflowConfigQuery withBillingCustomerOverrides *BillingCustomerOverrideQuery withBillingInvoiceLines *BillingInvoiceLineQuery + withBillingGatheringInvoiceLines *BillingGatheringInvoiceLineQuery withSubscriptionItems *SubscriptionItemQuery withPlanRateCards *PlanRateCardQuery withAddonRateCards *AddonRateCardQuery @@ -152,6 +154,28 @@ func (_q *TaxCodeQuery) QueryBillingInvoiceLines() *BillingInvoiceLineQuery { return query } +// QueryBillingGatheringInvoiceLines chains the current query on the "billing_gathering_invoice_lines" edge. +func (_q *TaxCodeQuery) QueryBillingGatheringInvoiceLines() *BillingGatheringInvoiceLineQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(dbtaxcode.Table, dbtaxcode.FieldID, selector), + sqlgraph.To(billinggatheringinvoiceline.Table, billinggatheringinvoiceline.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, dbtaxcode.BillingGatheringInvoiceLinesTable, dbtaxcode.BillingGatheringInvoiceLinesColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QuerySubscriptionItems chains the current query on the "subscription_items" edge. func (_q *TaxCodeQuery) QuerySubscriptionItems() *SubscriptionItemQuery { query := (&SubscriptionItemClient{config: _q.config}).Query() @@ -567,6 +591,7 @@ func (_q *TaxCodeQuery) Clone() *TaxCodeQuery { withBillingWorkflowConfigs: _q.withBillingWorkflowConfigs.Clone(), withBillingCustomerOverrides: _q.withBillingCustomerOverrides.Clone(), withBillingInvoiceLines: _q.withBillingInvoiceLines.Clone(), + withBillingGatheringInvoiceLines: _q.withBillingGatheringInvoiceLines.Clone(), withSubscriptionItems: _q.withSubscriptionItems.Clone(), withPlanRateCards: _q.withPlanRateCards.Clone(), withAddonRateCards: _q.withAddonRateCards.Clone(), @@ -616,6 +641,17 @@ func (_q *TaxCodeQuery) WithBillingInvoiceLines(opts ...func(*BillingInvoiceLine return _q } +// WithBillingGatheringInvoiceLines tells the query-builder to eager-load the nodes that are connected to +// the "billing_gathering_invoice_lines" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *TaxCodeQuery) WithBillingGatheringInvoiceLines(opts ...func(*BillingGatheringInvoiceLineQuery)) *TaxCodeQuery { + query := (&BillingGatheringInvoiceLineClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withBillingGatheringInvoiceLines = query + return _q +} + // WithSubscriptionItems tells the query-builder to eager-load the nodes that are connected to // the "subscription_items" edge. The optional arguments are used to configure the query builder of the edge. func (_q *TaxCodeQuery) WithSubscriptionItems(opts ...func(*SubscriptionItemQuery)) *TaxCodeQuery { @@ -804,10 +840,11 @@ func (_q *TaxCodeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*TaxC var ( nodes = []*TaxCode{} _spec = _q.querySpec() - loadedTypes = [13]bool{ + loadedTypes = [14]bool{ _q.withBillingWorkflowConfigs != nil, _q.withBillingCustomerOverrides != nil, _q.withBillingInvoiceLines != nil, + _q.withBillingGatheringInvoiceLines != nil, _q.withSubscriptionItems != nil, _q.withPlanRateCards != nil, _q.withAddonRateCards != nil, @@ -868,6 +905,15 @@ func (_q *TaxCodeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*TaxC return nil, err } } + if query := _q.withBillingGatheringInvoiceLines; query != nil { + if err := _q.loadBillingGatheringInvoiceLines(ctx, query, nodes, + func(n *TaxCode) { n.Edges.BillingGatheringInvoiceLines = []*BillingGatheringInvoiceLine{} }, + func(n *TaxCode, e *BillingGatheringInvoiceLine) { + n.Edges.BillingGatheringInvoiceLines = append(n.Edges.BillingGatheringInvoiceLines, e) + }); err != nil { + return nil, err + } + } if query := _q.withSubscriptionItems; query != nil { if err := _q.loadSubscriptionItems(ctx, query, nodes, func(n *TaxCode) { n.Edges.SubscriptionItems = []*SubscriptionItem{} }, @@ -1053,6 +1099,39 @@ func (_q *TaxCodeQuery) loadBillingInvoiceLines(ctx context.Context, query *Bill } return nil } +func (_q *TaxCodeQuery) loadBillingGatheringInvoiceLines(ctx context.Context, query *BillingGatheringInvoiceLineQuery, nodes []*TaxCode, init func(*TaxCode), assign func(*TaxCode, *BillingGatheringInvoiceLine)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[string]*TaxCode) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(billinggatheringinvoiceline.FieldTaxCodeID) + } + query.Where(predicate.BillingGatheringInvoiceLine(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(dbtaxcode.BillingGatheringInvoiceLinesColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.TaxCodeID + if fk == nil { + return fmt.Errorf(`foreign-key "tax_code_id" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "tax_code_id" returned %v for node %v`, *fk, n.ID) + } + assign(node, n) + } + return nil +} func (_q *TaxCodeQuery) loadSubscriptionItems(ctx context.Context, query *SubscriptionItemQuery, nodes []*TaxCode, init func(*TaxCode), assign func(*TaxCode, *SubscriptionItem)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[string]*TaxCode) diff --git a/openmeter/ent/db/taxcode_update.go b/openmeter/ent/db/taxcode_update.go index dbaf18c585..d8f7d43cdd 100644 --- a/openmeter/ent/db/taxcode_update.go +++ b/openmeter/ent/db/taxcode_update.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/schema/field" "github.com/openmeterio/openmeter/openmeter/ent/db/addonratecard" "github.com/openmeterio/openmeter/openmeter/ent/db/billingcustomeroverride" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billingworkflowconfig" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" @@ -183,6 +184,21 @@ func (_u *TaxCodeUpdate) AddBillingInvoiceLines(v ...*BillingInvoiceLine) *TaxCo return _u.AddBillingInvoiceLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *TaxCodeUpdate) AddBillingGatheringInvoiceLineIDs(ids ...string) *TaxCodeUpdate { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *TaxCodeUpdate) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *TaxCodeUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddSubscriptionItemIDs adds the "subscription_items" edge to the SubscriptionItem entity by IDs. func (_u *TaxCodeUpdate) AddSubscriptionItemIDs(ids ...string) *TaxCodeUpdate { _u.mutation.AddSubscriptionItemIDs(ids...) @@ -401,6 +417,27 @@ func (_u *TaxCodeUpdate) RemoveBillingInvoiceLines(v ...*BillingInvoiceLine) *Ta return _u.RemoveBillingInvoiceLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *TaxCodeUpdate) ClearBillingGatheringInvoiceLines() *TaxCodeUpdate { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *TaxCodeUpdate) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *TaxCodeUpdate { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *TaxCodeUpdate) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *TaxCodeUpdate { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearSubscriptionItems clears all "subscription_items" edges to the SubscriptionItem entity. func (_u *TaxCodeUpdate) ClearSubscriptionItems() *TaxCodeUpdate { _u.mutation.ClearSubscriptionItems() @@ -831,6 +868,51 @@ func (_u *TaxCodeUpdate) sqlSave(ctx context.Context) (_node int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: dbtaxcode.BillingGatheringInvoiceLinesTable, + Columns: []string{dbtaxcode.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: dbtaxcode.BillingGatheringInvoiceLinesTable, + Columns: []string{dbtaxcode.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: dbtaxcode.BillingGatheringInvoiceLinesTable, + Columns: []string{dbtaxcode.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.SubscriptionItemsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -1442,6 +1524,21 @@ func (_u *TaxCodeUpdateOne) AddBillingInvoiceLines(v ...*BillingInvoiceLine) *Ta return _u.AddBillingInvoiceLineIDs(ids...) } +// AddBillingGatheringInvoiceLineIDs adds the "billing_gathering_invoice_lines" edge to the BillingGatheringInvoiceLine entity by IDs. +func (_u *TaxCodeUpdateOne) AddBillingGatheringInvoiceLineIDs(ids ...string) *TaxCodeUpdateOne { + _u.mutation.AddBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// AddBillingGatheringInvoiceLines adds the "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *TaxCodeUpdateOne) AddBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *TaxCodeUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.AddBillingGatheringInvoiceLineIDs(ids...) +} + // AddSubscriptionItemIDs adds the "subscription_items" edge to the SubscriptionItem entity by IDs. func (_u *TaxCodeUpdateOne) AddSubscriptionItemIDs(ids ...string) *TaxCodeUpdateOne { _u.mutation.AddSubscriptionItemIDs(ids...) @@ -1660,6 +1757,27 @@ func (_u *TaxCodeUpdateOne) RemoveBillingInvoiceLines(v ...*BillingInvoiceLine) return _u.RemoveBillingInvoiceLineIDs(ids...) } +// ClearBillingGatheringInvoiceLines clears all "billing_gathering_invoice_lines" edges to the BillingGatheringInvoiceLine entity. +func (_u *TaxCodeUpdateOne) ClearBillingGatheringInvoiceLines() *TaxCodeUpdateOne { + _u.mutation.ClearBillingGatheringInvoiceLines() + return _u +} + +// RemoveBillingGatheringInvoiceLineIDs removes the "billing_gathering_invoice_lines" edge to BillingGatheringInvoiceLine entities by IDs. +func (_u *TaxCodeUpdateOne) RemoveBillingGatheringInvoiceLineIDs(ids ...string) *TaxCodeUpdateOne { + _u.mutation.RemoveBillingGatheringInvoiceLineIDs(ids...) + return _u +} + +// RemoveBillingGatheringInvoiceLines removes "billing_gathering_invoice_lines" edges to BillingGatheringInvoiceLine entities. +func (_u *TaxCodeUpdateOne) RemoveBillingGatheringInvoiceLines(v ...*BillingGatheringInvoiceLine) *TaxCodeUpdateOne { + ids := make([]string, len(v)) + for i := range v { + ids[i] = v[i].ID + } + return _u.RemoveBillingGatheringInvoiceLineIDs(ids...) +} + // ClearSubscriptionItems clears all "subscription_items" edges to the SubscriptionItem entity. func (_u *TaxCodeUpdateOne) ClearSubscriptionItems() *TaxCodeUpdateOne { _u.mutation.ClearSubscriptionItems() @@ -2120,6 +2238,51 @@ func (_u *TaxCodeUpdateOne) sqlSave(ctx context.Context) (_node *TaxCode, err er } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: dbtaxcode.BillingGatheringInvoiceLinesTable, + Columns: []string{dbtaxcode.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.RemovedBillingGatheringInvoiceLinesIDs(); len(nodes) > 0 && !_u.mutation.BillingGatheringInvoiceLinesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: dbtaxcode.BillingGatheringInvoiceLinesTable, + Columns: []string{dbtaxcode.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.BillingGatheringInvoiceLinesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: dbtaxcode.BillingGatheringInvoiceLinesTable, + Columns: []string{dbtaxcode.BillingGatheringInvoiceLinesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(billinggatheringinvoiceline.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.SubscriptionItemsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/openmeter/ent/db/tx.go b/openmeter/ent/db/tx.go index 8fa58057f6..91b3b1a346 100644 --- a/openmeter/ent/db/tx.go +++ b/openmeter/ent/db/tx.go @@ -36,6 +36,8 @@ type Tx struct { BillingCustomerLock *BillingCustomerLockClient // BillingCustomerOverride is the client for interacting with the BillingCustomerOverride builders. BillingCustomerOverride *BillingCustomerOverrideClient + // BillingGatheringInvoiceLine is the client for interacting with the BillingGatheringInvoiceLine builders. + BillingGatheringInvoiceLine *BillingGatheringInvoiceLineClient // BillingInvoice is the client for interacting with the BillingInvoice builders. BillingInvoice *BillingInvoiceClient // BillingInvoiceFlatFeeLineConfig is the client for interacting with the BillingInvoiceFlatFeeLineConfig builders. @@ -322,6 +324,7 @@ func (tx *Tx) init() { tx.BalanceSnapshot = NewBalanceSnapshotClient(tx.config) tx.BillingCustomerLock = NewBillingCustomerLockClient(tx.config) tx.BillingCustomerOverride = NewBillingCustomerOverrideClient(tx.config) + tx.BillingGatheringInvoiceLine = NewBillingGatheringInvoiceLineClient(tx.config) tx.BillingInvoice = NewBillingInvoiceClient(tx.config) tx.BillingInvoiceFlatFeeLineConfig = NewBillingInvoiceFlatFeeLineConfigClient(tx.config) tx.BillingInvoiceLine = NewBillingInvoiceLineClient(tx.config) diff --git a/openmeter/ent/schema/billing.go b/openmeter/ent/schema/billing.go index a29b198b15..835a8fb2f0 100644 --- a/openmeter/ent/schema/billing.go +++ b/openmeter/ent/schema/billing.go @@ -304,6 +304,86 @@ func (InvoiceLineBaseMixin) Fields() []ent.Field { } } +// StandardInvoiceLineIntentMixin contains the line fields that survive gathering-line +// realization into a standard invoice line. Scheduling fields such as invoice_at belong +// to gathering lines and must not be added to this shared shape. +// +// This schema-local definition is temporary. Move it to openmeter/billing/models when +// gathering and standard lines share the line-intent domain model. +type StandardInvoiceLineIntentMixin struct { + mixin.Schema +} + +func (StandardInvoiceLineIntentMixin) Fields() []ent.Field { + return []ent.Field{ + field.String("currency"). + GoType(currencyx.Code("")). + NotEmpty(). + Immutable(). + SchemaType(map[string]string{ + dialect.Postgres: "varchar(3)", + }), + + field.Time("service_period_start"), + field.Time("service_period_end"), + + field.JSON("tax_config", billing.TaxConfig{}). + SchemaType(map[string]string{ + dialect.Postgres: "jsonb", + }). + Optional(), + + field.Enum("price_type"). + GoType(productcatalog.PriceType("")), + field.String("feature_key"). + Optional(). + Nillable(), + field.String("price"). + GoType(&productcatalog.Price{}). + ValueScanner(PriceValueScanner). + SchemaType(map[string]string{ + dialect.Postgres: "jsonb", + }), + field.String("unit_config"). + GoType(&productcatalog.UnitConfig{}). + ValueScanner(UnitConfigValueScanner). + SchemaType(map[string]string{ + dialect.Postgres: "jsonb", + }). + Optional(). + Nillable(), + + field.String("ratecard_discounts"). + GoType(&billing.Discounts{}). + ValueScanner(BillingDiscountsValueScanner). + SchemaType(map[string]string{ + dialect.Postgres: "jsonb", + }). + Optional(). + Nillable(), + + field.String("child_unique_reference_id"). + Optional(). + Nillable(), + + field.String("subscription_id"). + Optional(). + Nillable(), + field.String("subscription_phase_id"). + Optional(). + Nillable(), + field.String("subscription_item_id"). + Optional(). + Nillable(), + field.Time("subscription_billing_period_from"). + Optional(). + Nillable(), + field.Time("subscription_billing_period_to"). + Optional(). + Nillable(), + } +} + type BillingInvoiceLine struct { ent.Schema } @@ -503,6 +583,96 @@ func (BillingInvoiceLine) Edges() []ent.Edge { } } +type BillingGatheringInvoiceLine struct { + ent.Schema +} + +func (BillingGatheringInvoiceLine) Mixin() []ent.Mixin { + return []ent.Mixin{ + entutils.AnnotationsMixin{}, + entutils.ResourceMixin{}, + StandardInvoiceLineIntentMixin{}, + TaxMixin{}, + } +} + +func (BillingGatheringInvoiceLine) Fields() []ent.Field { + return []ent.Field{ + field.String("invoice_id"). + SchemaType(map[string]string{ + dialect.Postgres: "char(26)", + }), + field.Time("invoice_at"), + field.Enum("managed_by"). + GoType(billing.InvoiceLineManagedBy("")), + field.Enum("engine"). + GoType(billing.LineEngineType("")). + Default(string(billing.LineEngineTypeInvoice)), + field.String("split_line_group_id"). + SchemaType(map[string]string{ + dialect.Postgres: "char(26)", + }). + Optional(). + Nillable(), + field.String("charge_id"). + SchemaType(map[string]string{ + dialect.Postgres: "char(26)", + }). + Optional(). + Nillable(), + } +} + +func (BillingGatheringInvoiceLine) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("namespace", "invoice_id"), + index.Fields("namespace", "split_line_group_id"), + index.Fields("namespace", "charge_id"), + index.Fields("namespace", "invoice_id", "child_unique_reference_id"). + Annotations( + entsql.IndexWhere("child_unique_reference_id IS NOT NULL AND deleted_at IS NULL"), + ). + StorageKey("billinggatheringline_ns_invoice_child_id"). + Unique(), + index.Fields("namespace", "subscription_id", "subscription_phase_id", "subscription_item_id"). + StorageKey("billinggatheringline_ns_subscription_ref"), + } +} + +func (BillingGatheringInvoiceLine) Edges() []ent.Edge { + return []ent.Edge{ + edge.From("billing_invoice", BillingInvoice.Type). + Ref("billing_gathering_invoice_lines"). + Field("invoice_id"). + Unique(). + Required(), + edge.From("split_line_group", BillingInvoiceSplitLineGroup.Type). + Ref("billing_gathering_invoice_lines"). + Field("split_line_group_id"). + Unique(), + edge.From("subscription", Subscription.Type). + Ref("billing_gathering_invoice_lines"). + Field("subscription_id"). + Unique(), + edge.From("subscription_phase", SubscriptionPhase.Type). + Ref("billing_gathering_invoice_lines"). + Field("subscription_phase_id"). + Unique(), + edge.From("subscription_item", SubscriptionItem.Type). + Ref("billing_gathering_invoice_lines"). + Field("subscription_item_id"). + Unique(), + edge.From("charge", Charge.Type). + Ref("billing_gathering_invoice_lines"). + Field("charge_id"). + Unique(), + edge.From("tax_code", TaxCode.Type). + Ref("billing_gathering_invoice_lines"). + Field("tax_code_id"). + Unique(), + } +} + type BillingInvoiceFlatFeeLineConfig struct { ent.Schema } @@ -711,6 +881,8 @@ func (BillingInvoiceSplitLineGroup) Indexes() []ent.Index { func (BillingInvoiceSplitLineGroup) Edges() []ent.Edge { return []ent.Edge{ edge.To("billing_invoice_lines", BillingInvoiceLine.Type), + edge.To("billing_gathering_invoice_lines", BillingGatheringInvoiceLine.Type). + StorageKey(edge.Symbol("billing_gathering_line_split_group_fk")), edge.From("subscription", Subscription.Type). Ref("billing_split_line_groups"). Field("subscription_id"). @@ -1174,6 +1346,9 @@ func (BillingInvoice) Edges() []ent.Edge { Required(), edge.To("billing_invoice_lines", BillingInvoiceLine.Type). Annotations(entsql.OnDelete(entsql.Cascade)), + edge.To("billing_gathering_invoice_lines", BillingGatheringInvoiceLine.Type). + StorageKey(edge.Symbol("billing_gathering_line_invoice_fk")). + Annotations(entsql.OnDelete(entsql.Cascade)), edge.To("billing_invoice_detailed_lines", BillingStandardInvoiceDetailedLine.Type). Annotations(entsql.OnDelete(entsql.Cascade)), edge.To("billing_invoice_validation_issues", BillingInvoiceValidationIssue.Type). diff --git a/openmeter/ent/schema/charges.go b/openmeter/ent/schema/charges.go index d08b122317..0d5a9d81b3 100644 --- a/openmeter/ent/schema/charges.go +++ b/openmeter/ent/schema/charges.go @@ -166,6 +166,8 @@ func (Charge) Edges() []ent.Edge { Unique(), // Billing edge.To("billing_invoice_lines", BillingInvoiceLine.Type), + edge.To("billing_gathering_invoice_lines", BillingGatheringInvoiceLine.Type). + StorageKey(edge.Symbol("billing_gathering_line_charge_fk")), edge.To("billing_split_line_groups", BillingInvoiceSplitLineGroup.Type), edge.To("credit_realization_lineages", CreditRealizationLineage.Type), } diff --git a/openmeter/ent/schema/subscription.go b/openmeter/ent/schema/subscription.go index d40f178ac9..3393275852 100644 --- a/openmeter/ent/schema/subscription.go +++ b/openmeter/ent/schema/subscription.go @@ -76,6 +76,8 @@ func (Subscription) Edges() []ent.Edge { OnDelete: entsql.Cascade, }), edge.To("billing_lines", BillingInvoiceLine.Type), + edge.To("billing_gathering_invoice_lines", BillingGatheringInvoiceLine.Type). + StorageKey(edge.Symbol("billing_gathering_line_subscription_fk")), edge.To("billing_split_line_groups", BillingInvoiceSplitLineGroup.Type), edge.To("charges_usage_based", ChargeUsageBased.Type), edge.To("charges_credit_purchase", ChargeCreditPurchase.Type), @@ -131,6 +133,8 @@ func (SubscriptionPhase) Edges() []ent.Edge { OnDelete: entsql.Cascade, }), edge.To("billing_lines", BillingInvoiceLine.Type), + edge.To("billing_gathering_invoice_lines", BillingGatheringInvoiceLine.Type). + StorageKey(edge.Symbol("billing_gathering_line_subscription_phase_fk")), edge.To("billing_split_line_groups", BillingInvoiceSplitLineGroup.Type), edge.To("charges_usage_based", ChargeUsageBased.Type), edge.To("charges_credit_purchase", ChargeCreditPurchase.Type), @@ -239,6 +243,8 @@ func (SubscriptionItem) Edges() []ent.Edge { OnDelete: entsql.Cascade, }), edge.To("billing_lines", BillingInvoiceLine.Type), + edge.To("billing_gathering_invoice_lines", BillingGatheringInvoiceLine.Type). + StorageKey(edge.Symbol("billing_gathering_line_subscription_item_fk")), edge.To("billing_split_line_groups", BillingInvoiceSplitLineGroup.Type), edge.To("charges_usage_based", ChargeUsageBased.Type), edge.To("charges_credit_purchase", ChargeCreditPurchase.Type), diff --git a/openmeter/ent/schema/taxcode.go b/openmeter/ent/schema/taxcode.go index e9cf009782..166d6457fe 100644 --- a/openmeter/ent/schema/taxcode.go +++ b/openmeter/ent/schema/taxcode.go @@ -54,6 +54,8 @@ func (TaxCode) Edges() []ent.Edge { edge.To("billing_workflow_configs", BillingWorkflowConfig.Type), edge.To("billing_customer_overrides", BillingCustomerOverride.Type), edge.To("billing_invoice_lines", BillingInvoiceLine.Type), + edge.To("billing_gathering_invoice_lines", BillingGatheringInvoiceLine.Type). + StorageKey(edge.Symbol("billing_gathering_line_tax_code_fk")), edge.To("subscription_items", SubscriptionItem.Type), edge.To("plan_rate_cards", PlanRateCard.Type), edge.To("addon_rate_cards", AddonRateCard.Type), diff --git a/tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.down.sql b/tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.down.sql new file mode 100644 index 0000000000..80f59e45c4 --- /dev/null +++ b/tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.down.sql @@ -0,0 +1,22 @@ +-- reverse: create index "billinggatheringline_ns_subscription_ref" to table: "billing_gathering_invoice_lines" +DROP INDEX "billinggatheringline_ns_subscription_ref"; +-- reverse: create index "billinggatheringline_ns_invoice_child_id" to table: "billing_gathering_invoice_lines" +DROP INDEX "billinggatheringline_ns_invoice_child_id"; +-- reverse: create index "billinggatheringinvoiceline_tax_code_id" to table: "billing_gathering_invoice_lines" +DROP INDEX "billinggatheringinvoiceline_tax_code_id"; +-- reverse: create index "billinggatheringinvoiceline_namespace_split_line_group_id" to table: "billing_gathering_invoice_lines" +DROP INDEX "billinggatheringinvoiceline_namespace_split_line_group_id"; +-- reverse: create index "billinggatheringinvoiceline_namespace_invoice_id" to table: "billing_gathering_invoice_lines" +DROP INDEX "billinggatheringinvoiceline_namespace_invoice_id"; +-- reverse: create index "billinggatheringinvoiceline_namespace_id" to table: "billing_gathering_invoice_lines" +DROP INDEX "billinggatheringinvoiceline_namespace_id"; +-- reverse: create index "billinggatheringinvoiceline_namespace_charge_id" to table: "billing_gathering_invoice_lines" +DROP INDEX "billinggatheringinvoiceline_namespace_charge_id"; +-- reverse: create index "billinggatheringinvoiceline_namespace" to table: "billing_gathering_invoice_lines" +DROP INDEX "billinggatheringinvoiceline_namespace"; +-- reverse: create index "billinggatheringinvoiceline_id" to table: "billing_gathering_invoice_lines" +DROP INDEX "billinggatheringinvoiceline_id"; +-- reverse: create index "billinggatheringinvoiceline_annotations" to table: "billing_gathering_invoice_lines" +DROP INDEX "billinggatheringinvoiceline_annotations"; +-- reverse: create "billing_gathering_invoice_lines" table +DROP TABLE "billing_gathering_invoice_lines"; diff --git a/tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.up.sql b/tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.up.sql new file mode 100644 index 0000000000..23b3d5c1dd --- /dev/null +++ b/tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.up.sql @@ -0,0 +1,63 @@ +-- create "billing_gathering_invoice_lines" table +CREATE TABLE "billing_gathering_invoice_lines" ( + "id" character(26) NOT NULL, + "annotations" jsonb NULL, + "namespace" character varying NOT NULL, + "metadata" jsonb NULL, + "created_at" timestamptz NOT NULL, + "updated_at" timestamptz NOT NULL, + "deleted_at" timestamptz NULL, + "name" character varying NOT NULL, + "description" character varying NULL, + "currency" character varying(3) NOT NULL, + "service_period_start" timestamptz NOT NULL, + "service_period_end" timestamptz NOT NULL, + "tax_config" jsonb NULL, + "price_type" character varying NOT NULL, + "feature_key" character varying NULL, + "price" jsonb NOT NULL, + "unit_config" jsonb NULL, + "ratecard_discounts" jsonb NULL, + "child_unique_reference_id" character varying NULL, + "subscription_billing_period_from" timestamptz NULL, + "subscription_billing_period_to" timestamptz NULL, + "tax_behavior" character varying NULL, + "invoice_at" timestamptz NOT NULL, + "managed_by" character varying NOT NULL, + "engine" character varying NOT NULL DEFAULT 'invoicing', + "invoice_id" character(26) NOT NULL, + "split_line_group_id" character(26) NULL, + "charge_id" character(26) NULL, + "subscription_id" character(26) NULL, + "subscription_item_id" character(26) NULL, + "subscription_phase_id" character(26) NULL, + "tax_code_id" character(26) NULL, + PRIMARY KEY ("id"), + CONSTRAINT "billing_gathering_line_charge_fk" FOREIGN KEY ("charge_id") REFERENCES "charges" ("id") ON UPDATE NO ACTION ON DELETE SET NULL, + CONSTRAINT "billing_gathering_line_invoice_fk" FOREIGN KEY ("invoice_id") REFERENCES "billing_invoices" ("id") ON UPDATE NO ACTION ON DELETE CASCADE, + CONSTRAINT "billing_gathering_line_split_group_fk" FOREIGN KEY ("split_line_group_id") REFERENCES "billing_invoice_split_line_groups" ("id") ON UPDATE NO ACTION ON DELETE SET NULL, + CONSTRAINT "billing_gathering_line_subscription_fk" FOREIGN KEY ("subscription_id") REFERENCES "subscriptions" ("id") ON UPDATE NO ACTION ON DELETE SET NULL, + CONSTRAINT "billing_gathering_line_subscription_item_fk" FOREIGN KEY ("subscription_item_id") REFERENCES "subscription_items" ("id") ON UPDATE NO ACTION ON DELETE SET NULL, + CONSTRAINT "billing_gathering_line_subscription_phase_fk" FOREIGN KEY ("subscription_phase_id") REFERENCES "subscription_phases" ("id") ON UPDATE NO ACTION ON DELETE SET NULL, + CONSTRAINT "billing_gathering_line_tax_code_fk" FOREIGN KEY ("tax_code_id") REFERENCES "tax_codes" ("id") ON UPDATE NO ACTION ON DELETE SET NULL +); +-- create index "billinggatheringinvoiceline_annotations" to table: "billing_gathering_invoice_lines" +CREATE INDEX "billinggatheringinvoiceline_annotations" ON "billing_gathering_invoice_lines" USING gin ("annotations"); +-- create index "billinggatheringinvoiceline_id" to table: "billing_gathering_invoice_lines" +CREATE UNIQUE INDEX "billinggatheringinvoiceline_id" ON "billing_gathering_invoice_lines" ("id"); +-- create index "billinggatheringinvoiceline_namespace" to table: "billing_gathering_invoice_lines" +CREATE INDEX "billinggatheringinvoiceline_namespace" ON "billing_gathering_invoice_lines" ("namespace"); +-- create index "billinggatheringinvoiceline_namespace_charge_id" to table: "billing_gathering_invoice_lines" +CREATE INDEX "billinggatheringinvoiceline_namespace_charge_id" ON "billing_gathering_invoice_lines" ("namespace", "charge_id"); +-- create index "billinggatheringinvoiceline_namespace_id" to table: "billing_gathering_invoice_lines" +CREATE UNIQUE INDEX "billinggatheringinvoiceline_namespace_id" ON "billing_gathering_invoice_lines" ("namespace", "id"); +-- create index "billinggatheringinvoiceline_namespace_invoice_id" to table: "billing_gathering_invoice_lines" +CREATE INDEX "billinggatheringinvoiceline_namespace_invoice_id" ON "billing_gathering_invoice_lines" ("namespace", "invoice_id"); +-- create index "billinggatheringinvoiceline_namespace_split_line_group_id" to table: "billing_gathering_invoice_lines" +CREATE INDEX "billinggatheringinvoiceline_namespace_split_line_group_id" ON "billing_gathering_invoice_lines" ("namespace", "split_line_group_id"); +-- create index "billinggatheringinvoiceline_tax_code_id" to table: "billing_gathering_invoice_lines" +CREATE INDEX "billinggatheringinvoiceline_tax_code_id" ON "billing_gathering_invoice_lines" ("tax_code_id"); +-- create index "billinggatheringline_ns_invoice_child_id" to table: "billing_gathering_invoice_lines" +CREATE UNIQUE INDEX "billinggatheringline_ns_invoice_child_id" ON "billing_gathering_invoice_lines" ("namespace", "invoice_id", "child_unique_reference_id") WHERE ((child_unique_reference_id IS NOT NULL) AND (deleted_at IS NULL)); +-- create index "billinggatheringline_ns_subscription_ref" to table: "billing_gathering_invoice_lines" +CREATE INDEX "billinggatheringline_ns_subscription_ref" ON "billing_gathering_invoice_lines" ("namespace", "subscription_id", "subscription_phase_id", "subscription_item_id"); diff --git a/tools/migrate/migrations/atlas.sum b/tools/migrate/migrations/atlas.sum index 8e0b279e69..a32423edba 100644 --- a/tools/migrate/migrations/atlas.sum +++ b/tools/migrate/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:MP+4ibn/VPIA2p9vT3ekYsnlkSYx3rroWbiJ2xHl2xk= +h1:fGxsnkhiJB6V9H45GMrP04nNhDrnp6sIXmYpcva9w2g= 20240826120919_init.up.sql h1:tc1V91/smlmaeJGQ8h+MzTEeFjjnrrFDbDAjOYJK91o= 20240903155435_entitlement-expired-index.up.sql h1:Hp8u5uckmLXc1cRvWU0AtVnnK8ShlpzZNp8pbiJLhac= 20240917172257_billing-entities.up.sql h1:Q1dAMo0Vjiit76OybClNfYPGC5nmvov2/M2W1ioi4Kw= @@ -231,3 +231,4 @@ h1:MP+4ibn/VPIA2p9vT3ekYsnlkSYx3rroWbiJ2xHl2xk= 20260709134600_add_ledger_credit_void_records.up.sql h1:o5C0cNz9b50BMgQcn1lp3BtlBYx8ETeOs2m8Ck6OiXc= 20260714140423_set_billing_invoice_schema_level_2.up.sql h1:4SzI0XyP9hXBxwdeTNEf2r55KY6vDRUgkbaZAK8rwWA= 20260714144104_consolidate_usage_based_realization_statuses.up.sql h1:ihKrZw9u8mv3TxideKQB5ZeakiKVfjf6UeLidLGPRoU= +20260716050537_create_billing_gathering_invoice_lines.up.sql h1:xIrhDV2wX3GJSY8Numh6V0OcfBXp1QWW5ocpJ/H1KoE= From d2fc9daa3736e2963d92d2fc0f3dc9e7c10412c7 Mon Sep 17 00:00:00 2001 From: Peter Turi Date: Thu, 16 Jul 2026 11:21:50 +0200 Subject: [PATCH 2/4] fix: reject empty gathering line child references --- openmeter/ent/db/migrate/schema.go | 4 ++++ openmeter/ent/schema/billing.go | 9 +++++++++ ...2057_create_billing_gathering_invoice_lines.down.sql} | 0 ...092057_create_billing_gathering_invoice_lines.up.sql} | 3 ++- tools/migrate/migrations/atlas.sum | 4 ++-- 5 files changed, 17 insertions(+), 3 deletions(-) rename tools/migrate/migrations/{20260716050537_create_billing_gathering_invoice_lines.down.sql => 20260716092057_create_billing_gathering_invoice_lines.down.sql} (100%) rename tools/migrate/migrations/{20260716050537_create_billing_gathering_invoice_lines.up.sql => 20260716092057_create_billing_gathering_invoice_lines.up.sql} (97%) diff --git a/openmeter/ent/db/migrate/schema.go b/openmeter/ent/db/migrate/schema.go index 1ffabf6577..9f3777a6e3 100644 --- a/openmeter/ent/db/migrate/schema.go +++ b/openmeter/ent/db/migrate/schema.go @@ -5685,6 +5685,10 @@ func init() { BillingGatheringInvoiceLinesTable.ForeignKeys[4].RefTable = SubscriptionItemsTable BillingGatheringInvoiceLinesTable.ForeignKeys[5].RefTable = SubscriptionPhasesTable BillingGatheringInvoiceLinesTable.ForeignKeys[6].RefTable = TaxCodesTable + BillingGatheringInvoiceLinesTable.Annotation = &entsql.Annotation{} + BillingGatheringInvoiceLinesTable.Annotation.Checks = map[string]string{ + "child_unique_reference_id_not_empty": "child_unique_reference_id <> ''", + } BillingInvoicesTable.ForeignKeys[0].RefTable = AppsTable BillingInvoicesTable.ForeignKeys[1].RefTable = AppsTable BillingInvoicesTable.ForeignKeys[2].RefTable = AppsTable diff --git a/openmeter/ent/schema/billing.go b/openmeter/ent/schema/billing.go index 835a8fb2f0..6f4bb2d3c2 100644 --- a/openmeter/ent/schema/billing.go +++ b/openmeter/ent/schema/billing.go @@ -4,6 +4,7 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect" "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "entgo.io/ent/schema/index" @@ -314,6 +315,14 @@ type StandardInvoiceLineIntentMixin struct { mixin.Schema } +func (StandardInvoiceLineIntentMixin) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Checks(map[string]string{ + "child_unique_reference_id_not_empty": `child_unique_reference_id <> ''`, + }), + } +} + func (StandardInvoiceLineIntentMixin) Fields() []ent.Field { return []ent.Field{ field.String("currency"). diff --git a/tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.down.sql b/tools/migrate/migrations/20260716092057_create_billing_gathering_invoice_lines.down.sql similarity index 100% rename from tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.down.sql rename to tools/migrate/migrations/20260716092057_create_billing_gathering_invoice_lines.down.sql diff --git a/tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.up.sql b/tools/migrate/migrations/20260716092057_create_billing_gathering_invoice_lines.up.sql similarity index 97% rename from tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.up.sql rename to tools/migrate/migrations/20260716092057_create_billing_gathering_invoice_lines.up.sql index 23b3d5c1dd..e99cf6446f 100644 --- a/tools/migrate/migrations/20260716050537_create_billing_gathering_invoice_lines.up.sql +++ b/tools/migrate/migrations/20260716092057_create_billing_gathering_invoice_lines.up.sql @@ -39,7 +39,8 @@ CREATE TABLE "billing_gathering_invoice_lines" ( CONSTRAINT "billing_gathering_line_subscription_fk" FOREIGN KEY ("subscription_id") REFERENCES "subscriptions" ("id") ON UPDATE NO ACTION ON DELETE SET NULL, CONSTRAINT "billing_gathering_line_subscription_item_fk" FOREIGN KEY ("subscription_item_id") REFERENCES "subscription_items" ("id") ON UPDATE NO ACTION ON DELETE SET NULL, CONSTRAINT "billing_gathering_line_subscription_phase_fk" FOREIGN KEY ("subscription_phase_id") REFERENCES "subscription_phases" ("id") ON UPDATE NO ACTION ON DELETE SET NULL, - CONSTRAINT "billing_gathering_line_tax_code_fk" FOREIGN KEY ("tax_code_id") REFERENCES "tax_codes" ("id") ON UPDATE NO ACTION ON DELETE SET NULL + CONSTRAINT "billing_gathering_line_tax_code_fk" FOREIGN KEY ("tax_code_id") REFERENCES "tax_codes" ("id") ON UPDATE NO ACTION ON DELETE SET NULL, + CONSTRAINT "child_unique_reference_id_not_empty" CHECK ((child_unique_reference_id)::text <> ''::text) ); -- create index "billinggatheringinvoiceline_annotations" to table: "billing_gathering_invoice_lines" CREATE INDEX "billinggatheringinvoiceline_annotations" ON "billing_gathering_invoice_lines" USING gin ("annotations"); diff --git a/tools/migrate/migrations/atlas.sum b/tools/migrate/migrations/atlas.sum index a32423edba..ac8d44fa7d 100644 --- a/tools/migrate/migrations/atlas.sum +++ b/tools/migrate/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:fGxsnkhiJB6V9H45GMrP04nNhDrnp6sIXmYpcva9w2g= +h1:CYq4dkV2bEupp+k3M535u7SM8Gv3Bdh1aOzzelyBHBk= 20240826120919_init.up.sql h1:tc1V91/smlmaeJGQ8h+MzTEeFjjnrrFDbDAjOYJK91o= 20240903155435_entitlement-expired-index.up.sql h1:Hp8u5uckmLXc1cRvWU0AtVnnK8ShlpzZNp8pbiJLhac= 20240917172257_billing-entities.up.sql h1:Q1dAMo0Vjiit76OybClNfYPGC5nmvov2/M2W1ioi4Kw= @@ -231,4 +231,4 @@ h1:fGxsnkhiJB6V9H45GMrP04nNhDrnp6sIXmYpcva9w2g= 20260709134600_add_ledger_credit_void_records.up.sql h1:o5C0cNz9b50BMgQcn1lp3BtlBYx8ETeOs2m8Ck6OiXc= 20260714140423_set_billing_invoice_schema_level_2.up.sql h1:4SzI0XyP9hXBxwdeTNEf2r55KY6vDRUgkbaZAK8rwWA= 20260714144104_consolidate_usage_based_realization_statuses.up.sql h1:ihKrZw9u8mv3TxideKQB5ZeakiKVfjf6UeLidLGPRoU= -20260716050537_create_billing_gathering_invoice_lines.up.sql h1:xIrhDV2wX3GJSY8Numh6V0OcfBXp1QWW5ocpJ/H1KoE= +20260716092057_create_billing_gathering_invoice_lines.up.sql h1:mdYbF8T8Y/i9RX1R3CIHEk31QtRINRQZK1yYT7wi4/U= From 120fa011c97082b58fd02735c210a3f8741fe162 Mon Sep 17 00:00:00 2001 From: Peter Turi Date: Thu, 16 Jul 2026 10:53:57 +0200 Subject: [PATCH 3/4] feat: read gathering lines from dedicated table --- openmeter/billing/adapter.go | 3 +- openmeter/billing/adapter/gatheringinvoice.go | 24 +- openmeter/billing/adapter/gatheringlines.go | 276 ++++++++++++++++-- .../billing/adapter/gatheringlines_test.go | 128 ++++++++ .../billing/adapter/invoicelinesplitgroup.go | 72 ++++- openmeter/billing/adapter/stdinvoicelines.go | 66 ++--- openmeter/billing/gatheringinvoice.go | 46 ++- openmeter/billing/gatheringinvoice_test.go | 28 ++ openmeter/billing/invoiceline.go | 22 +- openmeter/billing/service.go | 28 +- openmeter/billing/service/gatheringinvoice.go | 12 + openmeter/billing/service/stdinvoiceline.go | 6 +- .../service/persistedstate/loader.go | 22 +- openmeter/server/server_test.go | 7 +- test/billing/adapter_test.go | 142 +++++++++ 15 files changed, 779 insertions(+), 103 deletions(-) create mode 100644 openmeter/billing/adapter/gatheringlines_test.go diff --git a/openmeter/billing/adapter.go b/openmeter/billing/adapter.go index 6b3c63a456..e9f11bb390 100644 --- a/openmeter/billing/adapter.go +++ b/openmeter/billing/adapter.go @@ -59,7 +59,6 @@ type CustomerSynchronizationAdapter interface { type InvoiceLineAdapter interface { UpsertInvoiceLines(ctx context.Context, input UpsertInvoiceLinesAdapterInput) ([]*StandardLine, error) ListInvoiceLines(ctx context.Context, input ListInvoiceLinesAdapterInput) ([]*StandardLine, error) - GetLinesForSubscription(ctx context.Context, input GetLinesForSubscriptionInput) ([]LineOrHierarchy, error) } type InvoiceAdapter interface { @@ -78,6 +77,7 @@ type StandardInvoiceAdapter interface { UpdateStandardInvoice(ctx context.Context, input UpdateStandardInvoiceAdapterInput) (StandardInvoice, error) ListStandardInvoicesPendingAdvancement(ctx context.Context, input ListStandardInvoicesPendingAdvancementInput) ([]StandardInvoice, error) CountStandardInvoicesPendingAdvancement(ctx context.Context, input CountStandardInvoicesPendingAdvancementInput) (int64, error) + GetStandardLinesForSubscription(ctx context.Context, input GetStandardLinesForSubscriptionInput) ([]LineOrHierarchy, error) } type GatheringInvoiceAdapter interface { @@ -86,6 +86,7 @@ type GatheringInvoiceAdapter interface { DeleteGatheringInvoice(ctx context.Context, input DeleteGatheringInvoiceAdapterInput) error GetGatheringInvoiceById(ctx context.Context, input GetGatheringInvoiceByIdInput) (GatheringInvoice, error) ListGatheringInvoices(ctx context.Context, input ListGatheringInvoicesInput) (pagination.Result[GatheringInvoice], error) + GetGatheringLinesForSubscription(ctx context.Context, input GetGatheringLinesForSubscriptionInput) (GatheringLines, error) HardDeleteGatheringInvoiceLines(ctx context.Context, invoiceID InvoiceID, lineIDs []string) error } diff --git a/openmeter/billing/adapter/gatheringinvoice.go b/openmeter/billing/adapter/gatheringinvoice.go index 5ed96ba0ff..118cef4948 100644 --- a/openmeter/billing/adapter/gatheringinvoice.go +++ b/openmeter/billing/adapter/gatheringinvoice.go @@ -11,6 +11,7 @@ import ( "github.com/openmeterio/openmeter/api" "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/ent/db" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/pkg/clock" @@ -19,6 +20,7 @@ import ( "github.com/openmeterio/openmeter/pkg/framework/entutils" "github.com/openmeterio/openmeter/pkg/models" "github.com/openmeterio/openmeter/pkg/pagination" + "github.com/openmeterio/openmeter/pkg/slicesx" "github.com/openmeterio/openmeter/pkg/sortx" "github.com/openmeterio/openmeter/pkg/timeutil" ) @@ -343,7 +345,7 @@ func (a *adapter) DeleteGatheringInvoice(ctx context.Context, input billing.Dele } func (a *adapter) expandGatheringInvoiceLines(q *db.BillingInvoiceQuery, expand billing.GatheringInvoiceExpands) *db.BillingInvoiceQuery { - return q.WithBillingInvoiceLines(func(q *db.BillingInvoiceLineQuery) { + q = q.WithBillingInvoiceLines(func(q *db.BillingInvoiceLineQuery) { if !expand.Has(billing.GatheringInvoiceExpandDeletedLines) { q = q.Where(billinginvoiceline.DeletedAtIsNil()) } @@ -354,6 +356,14 @@ func (a *adapter) expandGatheringInvoiceLines(q *db.BillingInvoiceQuery, expand WithUsageBasedLine(). WithTaxCode() }) + + return q.WithBillingGatheringInvoiceLines(func(q *db.BillingGatheringInvoiceLineQuery) { + if !expand.Has(billing.GatheringInvoiceExpandDeletedLines) { + q.Where(billinggatheringinvoiceline.DeletedAtIsNil()) + } + + q.WithTaxCode() + }) } func (a *adapter) GetGatheringInvoiceById(ctx context.Context, input billing.GetGatheringInvoiceByIdInput) (billing.GatheringInvoice, error) { @@ -428,7 +438,17 @@ func (a *adapter) mapGatheringInvoiceFromDB(ctx context.Context, invoice *db.Bil } if expand.Has(billing.GatheringInvoiceExpandLines) { - mappedLines, err := a.mapGatheringInvoiceLinesFromDB(invoice.SchemaLevel, invoice.Edges.BillingInvoiceLines) + legacyLines, err := slicesx.MapWithErr(invoice.Edges.BillingInvoiceLines, a.fromDBBillingInvoiceLine) + if err != nil { + return billing.GatheringInvoice{}, err + } + + gatheringLines, err := slicesx.MapWithErr(invoice.Edges.BillingGatheringInvoiceLines, a.fromDBBillingGatheringInvoiceLine) + if err != nil { + return billing.GatheringInvoice{}, err + } + + mappedLines, err := mergeGatheringLines(legacyLines, gatheringLines) if err != nil { return billing.GatheringInvoice{}, err } diff --git a/openmeter/billing/adapter/gatheringlines.go b/openmeter/billing/adapter/gatheringlines.go index f7bb4a6f55..3098aa837d 100644 --- a/openmeter/billing/adapter/gatheringlines.go +++ b/openmeter/billing/adapter/gatheringlines.go @@ -2,6 +2,7 @@ package billingadapter import ( "context" + "errors" "fmt" "time" @@ -12,10 +13,13 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/ent/db" + "github.com/openmeterio/openmeter/openmeter/ent/db/billinggatheringinvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoice" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceline" "github.com/openmeterio/openmeter/openmeter/ent/db/billinginvoiceusagebasedlineconfig" "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/openmeter/taxcode" + taxcodeadapter "github.com/openmeterio/openmeter/openmeter/taxcode/adapter" "github.com/openmeterio/openmeter/pkg/clock" "github.com/openmeterio/openmeter/pkg/convert" "github.com/openmeterio/openmeter/pkg/entitydiff" @@ -25,6 +29,113 @@ import ( "github.com/openmeterio/openmeter/pkg/timeutil" ) +func (a *adapter) GetGatheringLinesForSubscription(ctx context.Context, in billing.GetGatheringLinesForSubscriptionInput) (billing.GatheringLines, error) { + if err := in.Validate(); err != nil { + return nil, billing.ValidationError{ + Err: err, + } + } + + return entutils.TransactingRepo(ctx, a, func(ctx context.Context, tx *adapter) (billing.GatheringLines, error) { + legacyQuery := tx.db.BillingInvoiceLine.Query(). + Where(billinginvoiceline.Namespace(in.Namespace)). + Where(billinginvoiceline.SubscriptionID(in.SubscriptionID)). + Where(billinginvoiceline.HasBillingInvoiceWith( + billinginvoice.StatusEQ(billing.StandardInvoiceStatusGathering), + )). + Where(billinginvoiceline.ParentLineIDIsNil()). + Where( + billinginvoiceline.Or( + billinginvoiceline.DeletedAtIsNil(), + billinginvoiceline.And( + billinginvoiceline.DeletedAtNotNil(), + billinginvoiceline.ManagedByEQ(billing.ManuallyManagedLine), + ), + ), + ). + WithBillingInvoice() + + if !in.IncludeChargeManaged { + legacyQuery = legacyQuery.Where(billinginvoiceline.ChargeIDIsNil()) + } + + legacyQuery = tx.expandLineItems(legacyQuery) + + dbLegacyLines, err := legacyQuery.All(ctx) + if err != nil { + return nil, fmt.Errorf("fetching legacy gathering lines: %w", err) + } + + dedicatedQuery := tx.db.BillingGatheringInvoiceLine.Query(). + Where(billinggatheringinvoiceline.Namespace(in.Namespace)). + Where(billinggatheringinvoiceline.SubscriptionID(in.SubscriptionID)). + Where(billinggatheringinvoiceline.HasBillingInvoiceWith( + billinginvoice.StatusEQ(billing.StandardInvoiceStatusGathering), + )). + Where( + billinggatheringinvoiceline.Or( + billinggatheringinvoiceline.DeletedAtIsNil(), + billinggatheringinvoiceline.And( + billinggatheringinvoiceline.DeletedAtNotNil(), + billinggatheringinvoiceline.ManagedByEQ(billing.ManuallyManagedLine), + ), + ), + ). + WithBillingInvoice(). + WithTaxCode() + + if !in.IncludeChargeManaged { + dedicatedQuery = dedicatedQuery.Where(billinggatheringinvoiceline.ChargeIDIsNil()) + } + + dbDedicatedLines, err := dedicatedQuery.All(ctx) + if err != nil { + return nil, fmt.Errorf("fetching dedicated gathering lines: %w", err) + } + + if err := errors.Join( + lo.Map(dbLegacyLines, func(line *db.BillingInvoiceLine, _ int) error { + if line.Edges.BillingInvoice == nil { + return fmt.Errorf("billing invoice not found for legacy gathering line [id=%s]", line.ID) + } + + return nil + })..., + ); err != nil { + return nil, err + } + + if err := errors.Join( + lo.Map(dbDedicatedLines, func(line *db.BillingGatheringInvoiceLine, _ int) error { + if line.Edges.BillingInvoice == nil { + return fmt.Errorf("billing invoice not found for dedicated gathering line [id=%s]", line.ID) + } + + return nil + })..., + ); err != nil { + return nil, err + } + + legacyLines, err := slicesx.MapWithErr(dbLegacyLines, tx.fromDBBillingInvoiceLine) + if err != nil { + return nil, fmt.Errorf("mapping legacy gathering lines: %w", err) + } + + dedicatedLines, err := slicesx.MapWithErr(dbDedicatedLines, tx.fromDBBillingGatheringInvoiceLine) + if err != nil { + return nil, fmt.Errorf("mapping dedicated gathering lines: %w", err) + } + + lines, err := mergeGatheringLines(legacyLines, dedicatedLines) + if err != nil { + return nil, fmt.Errorf("merging gathering lines: %w", err) + } + + return lines, nil + }) +} + func (a *adapter) HardDeleteGatheringInvoiceLines(ctx context.Context, invoiceID billing.InvoiceID, lineIDs []string) error { if err := invoiceID.Validate(); err != nil { return fmt.Errorf("validating invoice ID: %w", err) @@ -109,7 +220,15 @@ func diffGatheringInvoiceLines(lines billing.GatheringLines) (gatheringLineDiff, dbState := []*billing.GatheringLine{} for _, line := range lines { if line.DBState != nil { - dbState = append(dbState, line.DBState) + if line.DBState.Source != billing.GatheringLineTableInvoiceLines { + return gatheringLineDiff{}, fmt.Errorf( + "writing gathering lines from table %s is not supported [line_id=%s]", + line.DBState.Source, + line.ID, + ) + } + + dbState = append(dbState, &line.DBState.Line) } } @@ -277,13 +396,7 @@ func (a *adapter) updateGatheringLines(ctx context.Context, lines billing.Gather return nil } -func (a *adapter) mapGatheringInvoiceLinesFromDB(schemaLevel int, dbLines []*db.BillingInvoiceLine) (billing.GatheringLines, error) { - return slicesx.MapWithErr(dbLines, func(dbLine *db.BillingInvoiceLine) (billing.GatheringLine, error) { - return a.mapGatheringInvoiceLineFromDB(schemaLevel, dbLine) - }) -} - -func (a *adapter) mapGatheringInvoiceLineFromDB(schemaLevel int, dbLine *db.BillingInvoiceLine) (billing.GatheringLine, error) { +func (a *adapter) fromDBBillingInvoiceLine(dbLine *db.BillingInvoiceLine) (billing.GatheringLine, error) { if dbLine.Type != billing.InvoiceLineAdapterTypeUsageBased { return billing.GatheringLine{}, fmt.Errorf("only usage based lines can be gathering invoice lines [line_id=%s]", dbLine.ID) } @@ -338,27 +451,144 @@ func (a *adapter) mapGatheringInvoiceLineFromDB(schemaLevel int, dbLine *db.Bill }, } - if dbLine.SubscriptionID != nil && dbLine.SubscriptionPhaseID != nil && dbLine.SubscriptionItemID != nil { - line.Subscription = &billing.SubscriptionReference{ - SubscriptionID: *dbLine.SubscriptionID, - PhaseID: *dbLine.SubscriptionPhaseID, - ItemID: *dbLine.SubscriptionItemID, + setGatheringLineSubscriptionReference( + &line, + dbLine.SubscriptionID, + dbLine.SubscriptionPhaseID, + dbLine.SubscriptionItemID, + dbLine.SubscriptionBillingPeriodFrom, + dbLine.SubscriptionBillingPeriodTo, + ) + + if err := line.SaveDBSnapshot(billing.GatheringLineTableInvoiceLines); err != nil { + return billing.GatheringLine{}, err + } + + return line, nil +} + +func (a *adapter) fromDBBillingGatheringInvoiceLine(dbLine *db.BillingGatheringInvoiceLine) (billing.GatheringLine, error) { + if dbLine.Price == nil { + return billing.GatheringLine{}, fmt.Errorf("price is missing [line_id=%s]", dbLine.ID) + } + + line := billing.GatheringLine{ + GatheringLineBase: billing.GatheringLineBase{ + ManagedResource: models.NewManagedResource(models.ManagedResourceInput{ + Namespace: dbLine.Namespace, + ID: dbLine.ID, + CreatedAt: dbLine.CreatedAt.In(time.UTC), + UpdatedAt: dbLine.UpdatedAt.In(time.UTC), + DeletedAt: convert.TimePtrIn(dbLine.DeletedAt, time.UTC), + Name: dbLine.Name, + Description: dbLine.Description, + }), + + Metadata: dbLine.Metadata, + Annotations: dbLine.Annotations, + InvoiceID: dbLine.InvoiceID, + ManagedBy: dbLine.ManagedBy, + Engine: dbLine.Engine, + + ServicePeriod: timeutil.ClosedPeriod{ + From: dbLine.ServicePeriodStart.In(time.UTC), + To: dbLine.ServicePeriodEnd.In(time.UTC), + }, + + SplitLineGroupID: dbLine.SplitLineGroupID, + ChargeID: dbLine.ChargeID, + ChildUniqueReferenceID: dbLine.ChildUniqueReferenceID, + + InvoiceAt: dbLine.InvoiceAt.In(time.UTC), + + Currency: dbLine.Currency, + + TaxConfig: productcatalog.BackfillTaxConfig( + lo.EmptyableToPtr(dbLine.TaxConfig).ToProductCatalog(), + dbLine.TaxBehavior, + taxCodeFromBillingGatheringInvoiceLineEdge(dbLine), + ), + RateCardDiscounts: lo.FromPtr(dbLine.RatecardDiscounts), + + FeatureKey: lo.FromPtr(dbLine.FeatureKey), + Price: lo.FromPtr(dbLine.Price), + UnitConfig: dbLine.UnitConfig, + }, + } + + setGatheringLineSubscriptionReference( + &line, + dbLine.SubscriptionID, + dbLine.SubscriptionPhaseID, + dbLine.SubscriptionItemID, + dbLine.SubscriptionBillingPeriodFrom, + dbLine.SubscriptionBillingPeriodTo, + ) + + if err := line.SaveDBSnapshot(billing.GatheringLineTableGatheringInvoiceLines); err != nil { + return billing.GatheringLine{}, err + } + + return line, nil +} + +func setGatheringLineSubscriptionReference( + line *billing.GatheringLine, + subscriptionID *string, + phaseID *string, + itemID *string, + billingPeriodFrom *time.Time, + billingPeriodTo *time.Time, +) { + if subscriptionID == nil || phaseID == nil || itemID == nil { + return + } + + line.Subscription = &billing.SubscriptionReference{ + SubscriptionID: *subscriptionID, + PhaseID: *phaseID, + ItemID: *itemID, + } + + if billingPeriodFrom != nil && billingPeriodTo != nil { + line.Subscription.BillingPeriod = timeutil.ClosedPeriod{ + From: billingPeriodFrom.In(time.UTC), + To: billingPeriodTo.In(time.UTC), } - if dbLine.SubscriptionBillingPeriodFrom != nil && - dbLine.SubscriptionBillingPeriodTo != nil { - line.Subscription.BillingPeriod = timeutil.ClosedPeriod{ - From: dbLine.SubscriptionBillingPeriodFrom.In(time.UTC), - To: dbLine.SubscriptionBillingPeriodTo.In(time.UTC), - } + } +} + +func mergeGatheringLines(lineGroups ...billing.GatheringLines) (billing.GatheringLines, error) { + merged := lo.Flatten(lineGroups) + linesByID := lo.GroupBy(merged, func(line billing.GatheringLine) string { + return line.ID + }) + + for lineID, lines := range linesByID { + if len(lines) > 1 { + return nil, fmt.Errorf("gathering line exists in multiple tables [line_id=%s]", lineID) } } - cloned, err := line.WithoutDBState() + for _, line := range merged { + if line.DBState == nil { + return nil, fmt.Errorf("gathering line DB state is missing [line_id=%s]", line.ID) + } + } + + return merged, nil +} + +func taxCodeFromBillingGatheringInvoiceLineEdge(dbLine *db.BillingGatheringInvoiceLine) *taxcode.TaxCode { + tc, err := dbLine.Edges.TaxCodeOrErr() if err != nil { - return billing.GatheringLine{}, fmt.Errorf("cloning line: %w", err) + return nil } - line.DBState = lo.ToPtr(cloned) + mapped, err := taxcodeadapter.MapTaxCodeFromEntity(tc) + if err != nil { + return nil + } - return line, nil + return &mapped } diff --git a/openmeter/billing/adapter/gatheringlines_test.go b/openmeter/billing/adapter/gatheringlines_test.go new file mode 100644 index 0000000000..01323bf932 --- /dev/null +++ b/openmeter/billing/adapter/gatheringlines_test.go @@ -0,0 +1,128 @@ +package billingadapter + +import ( + "testing" + "time" + + "github.com/alpacahq/alpacadecimal" + "github.com/stretchr/testify/require" + + "github.com/openmeterio/openmeter/openmeter/billing" + "github.com/openmeterio/openmeter/openmeter/ent/db" + "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/pkg/currencyx" + "github.com/openmeterio/openmeter/pkg/models" +) + +func TestGatheringLineMappings(t *testing.T) { + now := time.Date(2026, 7, 16, 6, 0, 0, 0, time.UTC) + periodEnd := now.Add(time.Hour) + featureKey := "feature" + price := productcatalog.NewPriceFrom(productcatalog.UnitPrice{ + Amount: alpacadecimal.NewFromInt(2), + }) + + legacyRow := &db.BillingInvoiceLine{ + ID: "line-id", + Namespace: "namespace", + CreatedAt: now, + UpdatedAt: now, + Name: "line", + Currency: currencyx.Code("USD"), + PeriodStart: now, + PeriodEnd: periodEnd, + InvoiceID: "invoice-id", + InvoiceAt: periodEnd, + ManagedBy: billing.SystemManagedLine, + Engine: billing.LineEngineTypeInvoice, + Type: billing.InvoiceLineAdapterTypeUsageBased, + Edges: db.BillingInvoiceLineEdges{ + UsageBasedLine: &db.BillingInvoiceUsageBasedLineConfig{ + ID: "usage-config-id", + FeatureKey: &featureKey, + Price: price, + }, + }, + } + + dedicatedRow := &db.BillingGatheringInvoiceLine{ + ID: legacyRow.ID, + Namespace: legacyRow.Namespace, + CreatedAt: legacyRow.CreatedAt, + UpdatedAt: legacyRow.UpdatedAt, + Name: legacyRow.Name, + Currency: legacyRow.Currency, + ServicePeriodStart: legacyRow.PeriodStart, + ServicePeriodEnd: legacyRow.PeriodEnd, + PriceType: price.Type(), + FeatureKey: &featureKey, + Price: price, + InvoiceID: legacyRow.InvoiceID, + InvoiceAt: legacyRow.InvoiceAt, + ManagedBy: legacyRow.ManagedBy, + Engine: legacyRow.Engine, + } + + a := &adapter{} + legacyLine, err := a.fromDBBillingInvoiceLine(legacyRow) + require.NoError(t, err) + require.Equal(t, billing.GatheringLineTableInvoiceLines, legacyLine.DBState.Source) + + dedicatedLine, err := a.fromDBBillingGatheringInvoiceLine(dedicatedRow) + require.NoError(t, err) + require.Equal(t, billing.GatheringLineTableGatheringInvoiceLines, dedicatedLine.DBState.Source) + + legacyLineWithoutDBState, err := legacyLine.WithoutDBState() + require.NoError(t, err) + legacyLineWithoutDBState.UBPConfigID = "" + + dedicatedLineWithoutDBState, err := dedicatedLine.WithoutDBState() + require.NoError(t, err) + + require.Equal(t, legacyLineWithoutDBState, dedicatedLineWithoutDBState) +} + +func TestMergeGatheringLines(t *testing.T) { + legacyLine := billing.GatheringLine{ + GatheringLineBase: billing.GatheringLineBase{ + ManagedResource: models.NewManagedResource(models.ManagedResourceInput{ID: "legacy-line"}), + }, + } + require.NoError(t, legacyLine.SaveDBSnapshot(billing.GatheringLineTableInvoiceLines)) + + dedicatedLine := billing.GatheringLine{ + GatheringLineBase: billing.GatheringLineBase{ + ManagedResource: models.NewManagedResource(models.ManagedResourceInput{ID: "dedicated-line"}), + }, + } + require.NoError(t, dedicatedLine.SaveDBSnapshot(billing.GatheringLineTableGatheringInvoiceLines)) + + merged, err := mergeGatheringLines( + billing.GatheringLines{legacyLine}, + billing.GatheringLines{dedicatedLine}, + ) + require.NoError(t, err) + require.Len(t, merged, 2) + + duplicate := dedicatedLine + duplicate.ID = legacyLine.ID + duplicate.DBState.Line.ID = legacyLine.ID + + _, err = mergeGatheringLines( + billing.GatheringLines{legacyLine}, + billing.GatheringLines{duplicate}, + ) + require.ErrorContains(t, err, "gathering line exists in multiple tables") +} + +func TestDiffGatheringInvoiceLinesRejectsDedicatedTableRows(t *testing.T) { + line := billing.GatheringLine{ + GatheringLineBase: billing.GatheringLineBase{ + ManagedResource: models.NewManagedResource(models.ManagedResourceInput{ID: "line-id"}), + }, + } + require.NoError(t, line.SaveDBSnapshot(billing.GatheringLineTableGatheringInvoiceLines)) + + _, err := diffGatheringInvoiceLines(billing.GatheringLines{line}) + require.ErrorContains(t, err, "writing gathering lines from table billing_gathering_invoice_lines is not supported") +} diff --git a/openmeter/billing/adapter/invoicelinesplitgroup.go b/openmeter/billing/adapter/invoicelinesplitgroup.go index e6ee34c5be..2c767b17d1 100644 --- a/openmeter/billing/adapter/invoicelinesplitgroup.go +++ b/openmeter/billing/adapter/invoicelinesplitgroup.go @@ -131,6 +131,12 @@ func (a *adapter) GetSplitLineGroup(ctx context.Context, input billing.GetSplitL q.WithBillingWorkflowConfig(workflowConfigWithTaxCode) }) }). + WithBillingGatheringInvoiceLines(func(q *db.BillingGatheringInvoiceLineQuery) { + q.WithTaxCode(). + WithBillingInvoice(func(q *db.BillingInvoiceQuery) { + q.WithBillingWorkflowConfig(workflowConfigWithTaxCode) + }) + }). First(ctx) if err != nil { if db.IsNotFound(err) { @@ -207,7 +213,11 @@ func (a *adapter) mapSplitLineHierarchyFromDB(ctx context.Context, dbSplitLineGr return empty, err } - mappedLines, err := a.mapSplitLineHierarchyLinesFromDB(ctx, dbSplitLineGroup.Edges.BillingInvoiceLines) + mappedLines, err := a.mapSplitLineHierarchyLinesFromDB( + ctx, + dbSplitLineGroup.Edges.BillingInvoiceLines, + dbSplitLineGroup.Edges.BillingGatheringInvoiceLines, + ) if err != nil { return empty, err } @@ -218,8 +228,12 @@ func (a *adapter) mapSplitLineHierarchyFromDB(ctx context.Context, dbSplitLineGr }, nil } -func (a *adapter) mapSplitLineHierarchyLinesFromDB(ctx context.Context, dbLines []*db.BillingInvoiceLine) ([]billing.LineWithInvoiceHeader, error) { - return slicesx.MapWithErr(dbLines, func(dbLine *db.BillingInvoiceLine) (billing.LineWithInvoiceHeader, error) { +func (a *adapter) mapSplitLineHierarchyLinesFromDB( + ctx context.Context, + dbStandardLines []*db.BillingInvoiceLine, + dbGatheringLines []*db.BillingGatheringInvoiceLine, +) ([]billing.LineWithInvoiceHeader, error) { + standardLines, err := slicesx.MapWithErr(dbStandardLines, func(dbLine *db.BillingInvoiceLine) (billing.LineWithInvoiceHeader, error) { if dbLine.Edges.BillingInvoice == nil { return billing.LineWithInvoiceHeader{}, fmt.Errorf("billing invoice must be expanded when mapping split line hierarchy lines [id=%s]", dbLine.ID) } @@ -231,6 +245,29 @@ func (a *adapter) mapSplitLineHierarchyLinesFromDB(ctx context.Context, dbLines return a.mapSplitLineHierarchyStandardLineFromDB(ctx, dbLine) } }) + if err != nil { + return nil, err + } + + dedicatedGatheringLines, err := slicesx.MapWithErr(dbGatheringLines, func(dbLine *db.BillingGatheringInvoiceLine) (billing.LineWithInvoiceHeader, error) { + return a.mapSplitLineHierarchyGatheringLineFromDedicatedTable(ctx, dbLine) + }) + if err != nil { + return nil, err + } + + lines := lo.Flatten([][]billing.LineWithInvoiceHeader{standardLines, dedicatedGatheringLines}) + linesByID := lo.GroupBy(lines, func(line billing.LineWithInvoiceHeader) string { + return line.Line.GetID() + }) + + for lineID, lines := range linesByID { + if len(lines) > 1 { + return nil, fmt.Errorf("split line hierarchy line exists in multiple tables [line_id=%s]", lineID) + } + } + + return lines, nil } func (a *adapter) mapSplitLineHierarchyStandardLineFromDB(ctx context.Context, dbLine *db.BillingInvoiceLine) (billing.LineWithInvoiceHeader, error) { @@ -251,7 +288,28 @@ func (a *adapter) mapSplitLineHierarchyStandardLineFromDB(ctx context.Context, d } func (a *adapter) mapSplitLineHierarchyGatheringLineFromDB(ctx context.Context, dbLine *db.BillingInvoiceLine) (billing.LineWithInvoiceHeader, error) { - line, err := a.mapGatheringInvoiceLineFromDB(dbLine.Edges.BillingInvoice.SchemaLevel, dbLine) + line, err := a.fromDBBillingInvoiceLine(dbLine) + if err != nil { + return billing.LineWithInvoiceHeader{}, err + } + + invoice, err := a.mapGatheringInvoiceFromDB(ctx, dbLine.Edges.BillingInvoice, billing.GatheringInvoiceExpands{}) + if err != nil { + return billing.LineWithInvoiceHeader{}, err + } + + return billing.NewLineWithInvoiceHeader(billing.GatheringLineWithInvoiceHeader{ + Line: line, + Invoice: invoice, + }), nil +} + +func (a *adapter) mapSplitLineHierarchyGatheringLineFromDedicatedTable(ctx context.Context, dbLine *db.BillingGatheringInvoiceLine) (billing.LineWithInvoiceHeader, error) { + if dbLine.Edges.BillingInvoice == nil { + return billing.LineWithInvoiceHeader{}, fmt.Errorf("billing invoice must be expanded when mapping split line hierarchy gathering line [id=%s]", dbLine.ID) + } + + line, err := a.fromDBBillingGatheringInvoiceLine(dbLine) if err != nil { return billing.LineWithInvoiceHeader{}, err } @@ -337,6 +395,12 @@ func (a *adapter) fetchAllSplitLineGroups(ctx context.Context, namespace string, q.WithBillingInvoice(func(q *db.BillingInvoiceQuery) { q.WithBillingWorkflowConfig(workflowConfigWithTaxCode) }) // TODO[later]: we can consider loading this in a separate query, might be more efficient + }). + WithBillingGatheringInvoiceLines(func(q *db.BillingGatheringInvoiceLineQuery) { + q.WithTaxCode(). + WithBillingInvoice(func(q *db.BillingInvoiceQuery) { + q.WithBillingWorkflowConfig(workflowConfigWithTaxCode) + }) }) dbSplitLineGroups, err := query.All(ctx) diff --git a/openmeter/billing/adapter/stdinvoicelines.go b/openmeter/billing/adapter/stdinvoicelines.go index f75072dfc1..a48aa1b60d 100644 --- a/openmeter/billing/adapter/stdinvoicelines.go +++ b/openmeter/billing/adapter/stdinvoicelines.go @@ -776,7 +776,8 @@ func (a *adapter) refetchInvoiceLines(ctx context.Context, in refetchInvoiceLine return lines, nil } -func (a *adapter) GetLinesForSubscription(ctx context.Context, in billing.GetLinesForSubscriptionInput) ([]billing.LineOrHierarchy, error) { +// TODO[later]: handle SplitLines in seperate adapter method (we should deprecate splitlinegroups in the future in favor of charges so, for now we can keep it here) +func (a *adapter) GetStandardLinesForSubscription(ctx context.Context, in billing.GetStandardLinesForSubscriptionInput) ([]billing.LineOrHierarchy, error) { if err := in.Validate(); err != nil { return nil, billing.ValidationError{ Err: err, @@ -787,6 +788,9 @@ func (a *adapter) GetLinesForSubscription(ctx context.Context, in billing.GetLin query := tx.db.BillingInvoiceLine.Query(). Where(billinginvoiceline.Namespace(in.Namespace)). Where(billinginvoiceline.SubscriptionID(in.SubscriptionID)). + Where(billinginvoiceline.HasBillingInvoiceWith( + billinginvoice.StatusNEQ(billing.StandardInvoiceStatusGathering), + )). Where(billinginvoiceline.ParentLineIDIsNil()). // This one is required so that we are not fetching split line's children directly, the mapper will handle that Where( billinginvoiceline.Or( @@ -831,40 +835,11 @@ func (a *adapter) GetLinesForSubscription(ctx context.Context, in billing.GetLin return nil, fmt.Errorf("getting schema level per invoice: %w", err) } - // map standard lines - dbStandardLines := lo.Filter(dbLines, func(line *db.BillingInvoiceLine, _ int) bool { - return line.Edges.BillingInvoice.Status != billing.StandardInvoiceStatusGathering - }) - - standardLines, err := tx.mapStandardInvoiceLinesFromDB(invoiceSchemaLevelByID, dbStandardLines) + standardLines, err := tx.mapStandardInvoiceLinesFromDB(invoiceSchemaLevelByID, dbLines) if err != nil { return nil, fmt.Errorf("mapping standard lines: %w", err) } - // map gathering lines - dbGatheringLines := lo.Filter(dbLines, func(line *db.BillingInvoiceLine, _ int) bool { - return line.Edges.BillingInvoice.Status == billing.StandardInvoiceStatusGathering - }) - - dbGatheringLinesByInvoiceID := lo.GroupBy(dbGatheringLines, func(line *db.BillingInvoiceLine) string { - return line.Edges.BillingInvoice.ID - }) - - gatheringLines := make([]billing.GatheringLine, 0, len(dbGatheringLines)) - for invoiceID, dbGatheringLinesForInvoice := range dbGatheringLinesByInvoiceID { - schemaLevel, found := invoiceSchemaLevelByID[invoiceID] - if !found { - return nil, fmt.Errorf("schema level not found for invoice [id=%s]", invoiceID) - } - - mappedLines, err := tx.mapGatheringInvoiceLinesFromDB(schemaLevel, dbGatheringLinesForInvoice) - if err != nil { - return nil, fmt.Errorf("mapping gathering lines: %w", err) - } - - gatheringLines = append(gatheringLines, mappedLines...) - } - dbGroups, err := tx.db.BillingInvoiceSplitLineGroup.Query(). Where(billinginvoicesplitlinegroup.Namespace(in.Namespace)). Where(billinginvoicesplitlinegroup.SubscriptionID(in.SubscriptionID)). @@ -874,6 +849,12 @@ func (a *adapter) GetLinesForSubscription(ctx context.Context, in billing.GetLin q.WithBillingWorkflowConfig(workflowConfigWithTaxCode) }) }). + WithBillingGatheringInvoiceLines(func(q *db.BillingGatheringInvoiceLineQuery) { + q.WithTaxCode(). + WithBillingInvoice(func(q *db.BillingInvoiceQuery) { + q.WithBillingWorkflowConfig(workflowConfigWithTaxCode) + }) + }). Where(billinginvoicesplitlinegroup.DeletedAtIsNil()). All(ctx) if err != nil { @@ -886,7 +867,11 @@ func (a *adapter) GetLinesForSubscription(ctx context.Context, in billing.GetLin return billing.SplitLineHierarchy{}, err } - lines, err := tx.mapSplitLineHierarchyLinesFromDB(ctx, dbGroup.Edges.BillingInvoiceLines) + lines, err := tx.mapSplitLineHierarchyLinesFromDB( + ctx, + dbGroup.Edges.BillingInvoiceLines, + dbGroup.Edges.BillingGatheringInvoiceLines, + ) if err != nil { return billing.SplitLineHierarchy{}, err } @@ -913,14 +898,9 @@ func (a *adapter) GetLinesForSubscription(ctx context.Context, in billing.GetLin }, ) - lineChildUniqueReferenceIDs := lo.Union( - lo.FilterMap(standardLines, func(line *billing.StandardLine, _ int) (string, bool) { - return lo.FromPtr(line.ChildUniqueReferenceID), line.ChildUniqueReferenceID != nil - }), - lo.FilterMap(gatheringLines, func(line billing.GatheringLine, _ int) (string, bool) { - return lo.FromPtr(line.ChildUniqueReferenceID), line.ChildUniqueReferenceID != nil - }), - ) + lineChildUniqueReferenceIDs := lo.FilterMap(standardLines, func(line *billing.StandardLine, _ int) (string, bool) { + return lo.FromPtr(line.ChildUniqueReferenceID), line.ChildUniqueReferenceID != nil + }) overlappingChildUniqueReferenceIDs := lo.Intersect(groupUniqueReferenceIDs, lineChildUniqueReferenceIDs) @@ -929,7 +909,7 @@ func (a *adapter) GetLinesForSubscription(ctx context.Context, in billing.GetLin } // Let's map to the union type - out := make([]billing.LineOrHierarchy, 0, len(groups)+len(standardLines)+len(gatheringLines)) + out := make([]billing.LineOrHierarchy, 0, len(groups)+len(standardLines)) out = append(out, lo.Map(groups, func(h billing.SplitLineHierarchy, _ int) billing.LineOrHierarchy { return billing.NewLineOrHierarchy(&h) @@ -939,10 +919,6 @@ func (a *adapter) GetLinesForSubscription(ctx context.Context, in billing.GetLin return billing.NewLineOrHierarchy(line) })...) - out = append(out, lo.Map(gatheringLines, func(line billing.GatheringLine, _ int) billing.LineOrHierarchy { - return billing.NewLineOrHierarchy(line) - })...) - return out, nil }) } diff --git a/openmeter/billing/gatheringinvoice.go b/openmeter/billing/gatheringinvoice.go index 33acdb00da..00cff706fa 100644 --- a/openmeter/billing/gatheringinvoice.go +++ b/openmeter/billing/gatheringinvoice.go @@ -727,8 +727,32 @@ func (i gatheringInvoiceLineGenericWrapper) AsGenericInvoiceLine() GenericInvoic type GatheringLine struct { GatheringLineBase `json:",inline"` - DBState *GatheringLine `json:"-"` - SplitLineHierarchy *SplitLineHierarchy `json:"splitLineHierarchy,omitempty"` + DBState *GatheringLineDBState `json:"-"` + SplitLineHierarchy *SplitLineHierarchy `json:"splitLineHierarchy,omitempty"` +} + +type GatheringLineTable string + +const ( + GatheringLineTableInvoiceLines GatheringLineTable = "billing_invoice_lines" + GatheringLineTableGatheringInvoiceLines GatheringLineTable = "billing_gathering_invoice_lines" +) + +func (t GatheringLineTable) Validate() error { + switch t { + case GatheringLineTableInvoiceLines, GatheringLineTableGatheringInvoiceLines: + return nil + default: + return fmt.Errorf("invalid gathering line table: %s", t) + } +} + +// GatheringLineDBState captures both the persisted line and the table that owns it. +// Source ownership is needed while gathering lines can be read from both the legacy +// invoice-line table and the dedicated gathering-line table. +type GatheringLineDBState struct { + Source GatheringLineTable + Line GatheringLine } func (g GatheringLine) Clone() (GatheringLine, error) { @@ -773,6 +797,24 @@ func (g GatheringLine) WithoutDBState() (GatheringLine, error) { return clone, nil } +func (g *GatheringLine) SaveDBSnapshot(source GatheringLineTable) error { + if err := source.Validate(); err != nil { + return err + } + + clone, err := g.WithoutDBState() + if err != nil { + return fmt.Errorf("cloning gathering line for DB snapshot: %w", err) + } + + g.DBState = &GatheringLineDBState{ + Source: source, + Line: clone, + } + + return nil +} + func (g GatheringLine) WithNormalizedValues() (GatheringLine, error) { clone, err := g.Clone() if err != nil { diff --git a/openmeter/billing/gatheringinvoice_test.go b/openmeter/billing/gatheringinvoice_test.go index 74b3213367..010038d6ef 100644 --- a/openmeter/billing/gatheringinvoice_test.go +++ b/openmeter/billing/gatheringinvoice_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/pkg/models" ) func TestGatheringInvoiceLineInvoiceAtAccessor(t *testing.T) { @@ -90,3 +91,30 @@ func TestGatheringLineUnitConfigSnapshotPropagation(t *testing.T) { require.True(t, unitConfig.Equal(base.UnitConfig), "clone must not share the pointer with the original") }) } + +func TestGatheringLineSaveDBSnapshot(t *testing.T) { + line := GatheringLine{ + GatheringLineBase: GatheringLineBase{ + ManagedResource: models.NewManagedResource(models.ManagedResourceInput{ + ID: "line-id", + Name: "original", + }), + }, + } + + err := line.SaveDBSnapshot(GatheringLineTableGatheringInvoiceLines) + require.NoError(t, err) + require.Equal(t, GatheringLineTableGatheringInvoiceLines, line.DBState.Source) + require.Nil(t, line.DBState.Line.DBState) + + line.Name = "updated" + require.Equal(t, "original", line.DBState.Line.Name) + + withoutDBState, err := line.WithoutDBState() + require.NoError(t, err) + require.Nil(t, withoutDBState.DBState) + require.NotNil(t, line.DBState) + + err = line.SaveDBSnapshot(GatheringLineTable("unknown")) + require.ErrorContains(t, err, "invalid gathering line table") +} diff --git a/openmeter/billing/invoiceline.go b/openmeter/billing/invoiceline.go index 95dc569164..9828168f95 100644 --- a/openmeter/billing/invoiceline.go +++ b/openmeter/billing/invoiceline.go @@ -41,14 +41,14 @@ func (InvoiceLineManagedBy) Values() []string { } } -type GetLinesForSubscriptionInput struct { +type GetStandardLinesForSubscriptionInput struct { Namespace string SubscriptionID string CustomerID string IncludeChargeManaged bool } -func (i GetLinesForSubscriptionInput) Validate() error { +func (i GetStandardLinesForSubscriptionInput) Validate() error { if i.Namespace == "" { return errors.New("namespace is required") } @@ -64,6 +64,24 @@ func (i GetLinesForSubscriptionInput) Validate() error { return nil } +type GetGatheringLinesForSubscriptionInput struct { + Namespace string + SubscriptionID string + IncludeChargeManaged bool +} + +func (i GetGatheringLinesForSubscriptionInput) Validate() error { + if i.Namespace == "" { + return errors.New("namespace is required") + } + + if i.SubscriptionID == "" { + return errors.New("subscription id is required") + } + + return nil +} + type GenericInvoiceLine interface { GenericInvoiceLineReader diff --git a/openmeter/billing/service.go b/openmeter/billing/service.go index f50bb5e88c..4ed197538c 100644 --- a/openmeter/billing/service.go +++ b/openmeter/billing/service.go @@ -11,7 +11,6 @@ import ( type Service interface { ProfileService CustomerOverrideService - InvoiceLineService LineEngineService SplitLineGroupService InvoiceService @@ -45,20 +44,6 @@ type CustomerOverrideService interface { ListCustomerOverrides(ctx context.Context, input ListCustomerOverridesInput) (ListCustomerOverridesResult, error) } -type InvoiceLineService interface { - // GetLinesForSubscription returns the lines or hierarchies required for subscription sync. - // - // It does not include any deleted lines or hierarchy unless the deleted line is manually edited. - // - // This logic prevents reusing old entities that might have dirty state, but the manually edited lines are - // included so that subscription sync can understand the user intent that they don't want to invoice - // that line. - GetLinesForSubscription(ctx context.Context, input GetLinesForSubscriptionInput) ([]LineOrHierarchy, error) - // SnapshotLineQuantity returns an updated line with the quantity snapshoted from meters - // the invoice is used as contextual information to the call. - SnapshotLineQuantity(ctx context.Context, input SnapshotLineQuantityInput) (*StandardLine, error) -} - type LineEngineService interface { RegisterLineEngine(engine LineEngine) error RegisterCreateLineRouter(router CreateLineRouter) error @@ -107,6 +92,17 @@ type InvoiceService interface { } type StandardInvoiceService interface { + // GetStandardLinesForSubscription returns the standard lines or hierarchies required for subscription sync. + // + // It does not include any deleted lines or hierarchy unless the deleted line is manually edited. + // + // This logic prevents reusing old entities that might have dirty state, but the manually edited lines are + // included so that subscription sync can understand the user intent that they don't want to invoice + // that line. + GetStandardLinesForSubscription(ctx context.Context, input GetStandardLinesForSubscriptionInput) ([]LineOrHierarchy, error) + // SnapshotLineQuantity returns an updated line with the quantity snapshoted from meters + // the invoice is used as contextual information to the call. + SnapshotLineQuantity(ctx context.Context, input SnapshotLineQuantityInput) (*StandardLine, error) // UpdateStandardInvoice updates a standard invoice as a whole UpdateStandardInvoice(ctx context.Context, input UpdateStandardInvoiceInput) (StandardInvoice, error) // GetStandardInvoiceById gets a standard invoice by its ID @@ -122,6 +118,8 @@ type StandardInvoiceService interface { } type GatheringInvoiceService interface { + // GetGatheringLinesForSubscription returns the gathering leaf lines required for subscription sync. + GetGatheringLinesForSubscription(ctx context.Context, input GetGatheringLinesForSubscriptionInput) (GatheringLines, error) // CreatePendingInvoiceLines creates pending invoice lines for a customer, if the lines are zero valued, the response is nil CreatePendingInvoiceLines(ctx context.Context, input CreatePendingInvoiceLinesInput) (*CreatePendingInvoiceLinesResult, error) diff --git a/openmeter/billing/service/gatheringinvoice.go b/openmeter/billing/service/gatheringinvoice.go index d0f49a4979..adda863a3c 100644 --- a/openmeter/billing/service/gatheringinvoice.go +++ b/openmeter/billing/service/gatheringinvoice.go @@ -18,6 +18,18 @@ import ( var _ billing.GatheringInvoiceService = (*Service)(nil) +func (s *Service) GetGatheringLinesForSubscription(ctx context.Context, input billing.GetGatheringLinesForSubscriptionInput) (billing.GatheringLines, error) { + if err := input.Validate(); err != nil { + return nil, billing.ValidationError{ + Err: err, + } + } + + return transaction.Run(ctx, s.adapter, func(ctx context.Context) (billing.GatheringLines, error) { + return s.adapter.GetGatheringLinesForSubscription(ctx, input) + }) +} + func (s *Service) ListGatheringInvoices(ctx context.Context, input billing.ListGatheringInvoicesInput) (pagination.Result[billing.GatheringInvoice], error) { if err := input.Validate(); err != nil { return pagination.Result[billing.GatheringInvoice]{}, err diff --git a/openmeter/billing/service/stdinvoiceline.go b/openmeter/billing/service/stdinvoiceline.go index 2c68cb5ca4..ed2f171f02 100644 --- a/openmeter/billing/service/stdinvoiceline.go +++ b/openmeter/billing/service/stdinvoiceline.go @@ -21,8 +21,6 @@ import ( "github.com/openmeterio/openmeter/pkg/sortx" ) -var _ billing.InvoiceLineService = (*Service)(nil) - // TODO[later]: Move this to gatheringinvoice.go func (s *Service) CreatePendingInvoiceLines(ctx context.Context, input billing.CreatePendingInvoiceLinesInput) (*billing.CreatePendingInvoiceLinesResult, error) { for i := range input.Lines { @@ -262,7 +260,7 @@ func (s *Service) upsertGatheringInvoiceForCurrency(ctx context.Context, currenc }, nil } -func (s *Service) GetLinesForSubscription(ctx context.Context, input billing.GetLinesForSubscriptionInput) ([]billing.LineOrHierarchy, error) { +func (s *Service) GetStandardLinesForSubscription(ctx context.Context, input billing.GetStandardLinesForSubscriptionInput) ([]billing.LineOrHierarchy, error) { if err := input.Validate(); err != nil { return nil, billing.ValidationError{ Err: err, @@ -270,6 +268,6 @@ func (s *Service) GetLinesForSubscription(ctx context.Context, input billing.Get } return transaction.Run(ctx, s.adapter, func(ctx context.Context) ([]billing.LineOrHierarchy, error) { - return s.adapter.GetLinesForSubscription(ctx, input) + return s.adapter.GetStandardLinesForSubscription(ctx, input) }) } diff --git a/openmeter/billing/worker/subscriptionsync/service/persistedstate/loader.go b/openmeter/billing/worker/subscriptionsync/service/persistedstate/loader.go index f6bbc27a29..ecf89e8c98 100644 --- a/openmeter/billing/worker/subscriptionsync/service/persistedstate/loader.go +++ b/openmeter/billing/worker/subscriptionsync/service/persistedstate/loader.go @@ -17,7 +17,8 @@ import ( ) type billingService interface { - GetLinesForSubscription(ctx context.Context, input billing.GetLinesForSubscriptionInput) ([]billing.LineOrHierarchy, error) + GetStandardLinesForSubscription(ctx context.Context, input billing.GetStandardLinesForSubscriptionInput) ([]billing.LineOrHierarchy, error) + GetGatheringLinesForSubscription(ctx context.Context, input billing.GetGatheringLinesForSubscriptionInput) (billing.GatheringLines, error) ListInvoices(ctx context.Context, input billing.ListInvoicesInput) (billing.ListInvoicesResponse, error) } @@ -38,7 +39,7 @@ func NewLoader(billingService billingService, chargeService chargeService) Loade } func (l Loader) LoadForSubscription(ctx context.Context, subs subscription.Subscription) (State, error) { - lines, err := l.billingService.GetLinesForSubscription(ctx, billing.GetLinesForSubscriptionInput{ + standardLines, err := l.billingService.GetStandardLinesForSubscription(ctx, billing.GetStandardLinesForSubscriptionInput{ Namespace: subs.Namespace, SubscriptionID: subs.ID, CustomerID: subs.CustomerId, @@ -47,9 +48,24 @@ func (l Loader) LoadForSubscription(ctx context.Context, subs subscription.Subsc IncludeChargeManaged: false, }) if err != nil { - return State{}, fmt.Errorf("getting existing lines: %w", err) + return State{}, fmt.Errorf("getting existing standard lines: %w", err) } + gatheringLines, err := l.billingService.GetGatheringLinesForSubscription(ctx, billing.GetGatheringLinesForSubscriptionInput{ + Namespace: subs.Namespace, + SubscriptionID: subs.ID, + // Charge-managed invoice lines are edited through charge patches, so subscription sync loads the + // charge entities instead of reconciling those lines directly. + IncludeChargeManaged: false, + }) + if err != nil { + return State{}, fmt.Errorf("getting existing gathering lines: %w", err) + } + + lines := append(standardLines, lo.Map(gatheringLines, func(line billing.GatheringLine, _ int) billing.LineOrHierarchy { + return billing.NewLineOrHierarchy(line) + })...) + lines, err = slicesx.MapWithErr(lines, normalizePersistedLineOrHierarchy) if err != nil { return State{}, fmt.Errorf("normalizing existing lines: %w", err) diff --git a/openmeter/server/server_test.go b/openmeter/server/server_test.go index 2438a81961..d11c0cd96b 100644 --- a/openmeter/server/server_test.go +++ b/openmeter/server/server_test.go @@ -1835,7 +1835,6 @@ func (n NoopBillingService) ListCustomerOverrides(ctx context.Context, input bil return billing.ListCustomerOverridesResult{}, nil } -// InvoiceLineService methods func (n NoopBillingService) CreatePendingInvoiceLines(ctx context.Context, input billing.CreatePendingInvoiceLinesInput) (*billing.CreatePendingInvoiceLinesResult, error) { return nil, nil } @@ -1860,10 +1859,14 @@ func (n NoopBillingService) OnUnsupportedCreditNote(ctx context.Context, input b return nil } -func (n NoopBillingService) GetLinesForSubscription(ctx context.Context, input billing.GetLinesForSubscriptionInput) ([]billing.LineOrHierarchy, error) { +func (n NoopBillingService) GetStandardLinesForSubscription(ctx context.Context, input billing.GetStandardLinesForSubscriptionInput) ([]billing.LineOrHierarchy, error) { return []billing.LineOrHierarchy{}, nil } +func (n NoopBillingService) GetGatheringLinesForSubscription(ctx context.Context, input billing.GetGatheringLinesForSubscriptionInput) (billing.GatheringLines, error) { + return billing.GatheringLines{}, nil +} + func (n NoopBillingService) SnapshotLineQuantity(ctx context.Context, input billing.SnapshotLineQuantityInput) (*billing.StandardLine, error) { return &billing.StandardLine{}, nil } diff --git a/test/billing/adapter_test.go b/test/billing/adapter_test.go index d2b3dbf5a6..2d93f7d925 100644 --- a/test/billing/adapter_test.go +++ b/test/billing/adapter_test.go @@ -1073,3 +1073,145 @@ func (s *BillingAdapterTestSuite) TestHardDeleteGatheringInvoiceLinesNegative() s.Error(err) }) } + +func (s *BillingAdapterTestSuite) TestDedicatedGatheringInvoiceLineReadCompatibility() { + ctx := s.T().Context() + namespace := s.GetUniqueNamespace("ns-adapter-dedicated-gathering-lines") + featureKey := "dedicated-gathering-line" + + // given: + // - a customer with a gathering invoice containing two legacy lines + sandboxApp := s.InstallSandboxApp(s.T(), namespace) + s.ProvisionBillingProfile(ctx, namespace, sandboxApp.GetID()) + customerEntity := s.CreateTestCustomer(namespace, "test-customer") + lo.Must(s.FeatureService.CreateFeature(ctx, feature.CreateFeatureInputs{ + Namespace: namespace, + Name: featureKey, + Key: featureKey, + })) + + periodStart := time.Now().Add(-time.Hour) + periodEnd := time.Now().Add(time.Hour) + created, err := s.BillingService.CreatePendingInvoiceLines(ctx, billing.CreatePendingInvoiceLinesInput{ + Customer: customerEntity.GetID(), + Currency: currencyx.Code(currency.USD), + Lines: []billing.GatheringLine{ + { + GatheringLineBase: billing.GatheringLineBase{ + ManagedResource: models.NewManagedResource(models.ManagedResourceInput{ + Namespace: namespace, + Name: "dedicated line", + }), + ServicePeriod: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, + InvoiceAt: periodEnd, + ManagedBy: billing.ManuallyManagedLine, + Currency: currencyx.Code(currency.USD), + FeatureKey: featureKey, + Price: lo.FromPtr(productcatalog.NewPriceFrom(productcatalog.UnitPrice{ + Amount: alpacadecimal.NewFromInt(1), + })), + }, + }, + { + GatheringLineBase: billing.GatheringLineBase{ + ManagedResource: models.NewManagedResource(models.ManagedResourceInput{ + Namespace: namespace, + Name: "legacy line", + }), + ServicePeriod: timeutil.ClosedPeriod{From: periodStart, To: periodEnd}, + InvoiceAt: periodEnd, + ManagedBy: billing.ManuallyManagedLine, + Currency: currencyx.Code(currency.USD), + FeatureKey: featureKey, + Price: lo.FromPtr(productcatalog.NewPriceFrom(productcatalog.UnitPrice{ + Amount: alpacadecimal.NewFromInt(1), + })), + }, + }, + }, + }) + s.Require().NoError(err) + + lines := created.Invoice.Lines.OrEmpty() + s.Require().Len(lines, 2) + dedicatedLine := lines[0] + legacyLine := lines[1] + + // when: + // - one line is moved to the dedicated table outside the application write path + err = s.BillingAdapter.HardDeleteGatheringInvoiceLines(ctx, created.Invoice.GetInvoiceID(), []string{dedicatedLine.ID}) + s.Require().NoError(err) + createDedicatedGatheringLine(s.T(), s.DBClient, dedicatedLine) + + // then: + // - the adapter returns both sources with their ownership recorded in DBState + reloaded, err := s.BillingAdapter.GetGatheringInvoiceById(ctx, billing.GetGatheringInvoiceByIdInput{ + Invoice: created.Invoice.GetInvoiceID(), + Expand: billing.GatheringInvoiceExpands{billing.GatheringInvoiceExpandLines}, + }) + s.Require().NoError(err) + s.Require().Len(reloaded.Lines.OrEmpty(), 2) + + reloadedByID := lo.SliceToMap(reloaded.Lines.OrEmpty(), func(line billing.GatheringLine) (string, billing.GatheringLine) { + return line.ID, line + }) + s.Equal(billing.GatheringLineTableGatheringInvoiceLines, reloadedByID[dedicatedLine.ID].DBState.Source) + s.Equal(billing.GatheringLineTableInvoiceLines, reloadedByID[legacyLine.ID].DBState.Source) + + // and: + // - writes remain disabled for invoices containing dedicated-table lines + _, err = s.BillingService.UpdateGatheringInvoice(ctx, billing.UpdateGatheringInvoiceInput{ + Invoice: created.Invoice.GetInvoiceID(), + ChangeSource: billing.ChangeSourceSystem, + EditFn: func(*billing.GatheringInvoice) error { return nil }, + }) + s.ErrorContains(err, "writing gathering lines from table billing_gathering_invoice_lines is not supported") + + // and: + // - duplicate IDs across the two tables fail instead of being resolved implicitly + createDedicatedGatheringLine(s.T(), s.DBClient, legacyLine) + _, err = s.BillingAdapter.GetGatheringInvoiceById(ctx, billing.GetGatheringInvoiceByIdInput{ + Invoice: created.Invoice.GetInvoiceID(), + Expand: billing.GatheringInvoiceExpands{billing.GatheringInvoiceExpandLines}, + }) + s.ErrorContains(err, "gathering line exists in multiple tables") +} + +func createDedicatedGatheringLine(t *testing.T, client *db.Client, line billing.GatheringLine) { + t.Helper() + + create := client.BillingGatheringInvoiceLine.Create(). + SetID(line.ID). + SetNamespace(line.Namespace). + SetName(line.Name). + SetNillableDescription(line.Description). + SetCurrency(line.Currency). + SetServicePeriodStart(line.ServicePeriod.From). + SetServicePeriodEnd(line.ServicePeriod.To). + SetPriceType(line.Price.Type()). + SetFeatureKey(line.FeatureKey). + SetPrice(lo.ToPtr(line.Price)). + SetInvoiceID(line.InvoiceID). + SetInvoiceAt(line.InvoiceAt). + SetManagedBy(line.ManagedBy). + SetEngine(line.Engine). + SetNillableSplitLineGroupID(line.SplitLineGroupID). + SetNillableChargeID(line.ChargeID). + SetNillableChildUniqueReferenceID(line.ChildUniqueReferenceID) + + if line.Subscription != nil { + create = create. + SetSubscriptionID(line.Subscription.SubscriptionID). + SetSubscriptionPhaseID(line.Subscription.PhaseID). + SetSubscriptionItemID(line.Subscription.ItemID). + SetSubscriptionBillingPeriodFrom(line.Subscription.BillingPeriod.From). + SetSubscriptionBillingPeriodTo(line.Subscription.BillingPeriod.To) + } + + if line.UnitConfig != nil { + create = create.SetUnitConfig(line.UnitConfig) + } + + _, err := create.Save(t.Context()) + require.NoError(t, err) +} From 0fdf6cacdbe9ea29945e5a18b77d5457a594fff6 Mon Sep 17 00:00:00 2001 From: Peter Turi Date: Thu, 16 Jul 2026 11:25:57 +0200 Subject: [PATCH 4/4] fix: exclude split gathering lines from leaf reads --- openmeter/billing/adapter/gatheringlines.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openmeter/billing/adapter/gatheringlines.go b/openmeter/billing/adapter/gatheringlines.go index 3098aa837d..b50ab0b4f1 100644 --- a/openmeter/billing/adapter/gatheringlines.go +++ b/openmeter/billing/adapter/gatheringlines.go @@ -44,6 +44,7 @@ func (a *adapter) GetGatheringLinesForSubscription(ctx context.Context, in billi billinginvoice.StatusEQ(billing.StandardInvoiceStatusGathering), )). Where(billinginvoiceline.ParentLineIDIsNil()). + Where(billinginvoiceline.SplitLineGroupIDIsNil()). Where( billinginvoiceline.Or( billinginvoiceline.DeletedAtIsNil(), @@ -72,6 +73,7 @@ func (a *adapter) GetGatheringLinesForSubscription(ctx context.Context, in billi Where(billinggatheringinvoiceline.HasBillingInvoiceWith( billinginvoice.StatusEQ(billing.StandardInvoiceStatusGathering), )). + Where(billinggatheringinvoiceline.SplitLineGroupIDIsNil()). Where( billinggatheringinvoiceline.Or( billinggatheringinvoiceline.DeletedAtIsNil(),