diff --git a/app/common/billing.go b/app/common/billing.go index 3ac66da9c6..18184cc6b0 100644 --- a/app/common/billing.go +++ b/app/common/billing.go @@ -173,6 +173,7 @@ func NewBillingRegistry( tracer trace.Tracer, taxCodeService taxcode.Service, currencyResolver currencies.CurrencyResolver, + currenciesService currencies.Service, locker *lockr.Locker, ledgerService ledger.Ledger, balanceQuerier ledger.BalanceQuerier, @@ -226,6 +227,7 @@ func NewBillingRegistry( breakageService, taxCodeService, currencyResolver, + currenciesService, fsConfig.NamespaceLockdown, creditsConfig, featureGate, diff --git a/app/common/charges.go b/app/common/charges.go index 05b2bfbdf5..06d58c9981 100644 --- a/app/common/charges.go +++ b/app/common/charges.go @@ -212,6 +212,7 @@ func NewChargesFlatFeeService( metaAdapter meta.Adapter, locker *lockr.Locker, ratingService rating.Service, + currenciesService currencies.Service, ) (flatfee.Service, error) { flatFeeSvc, err := flatfeeservice.New(flatfeeservice.Config{ Adapter: flatFeeAdapter, @@ -220,6 +221,7 @@ func NewChargesFlatFeeService( MetaAdapter: metaAdapter, Locker: locker, RatingService: ratingService, + Currencies: currenciesService, }) if err != nil { return nil, fmt.Errorf("failed to create charges flat fee service: %w", err) @@ -255,6 +257,7 @@ func NewChargesUsageBasedService( billingService billing.Service, featureService feature.FeatureConnector, ratingService rating.Service, + currenciesService currencies.Service, streamingConnector streaming.Connector, ) (usagebased.Service, error) { usageBasedSvc, err := usagebasedservice.New(usagebasedservice.Config{ @@ -267,6 +270,7 @@ func NewChargesUsageBasedService( CustomerOverrideService: billingService, FeatureService: featureService, RatingService: ratingService, + Currencies: currenciesService, StreamingConnector: streamingConnector, }) if err != nil { @@ -414,6 +418,7 @@ func newChargesRegistry( breakageService ledgerbreakage.Service, taxCodeService taxcode.Service, currencyResolver currencies.CurrencyResolver, + currenciesService currencies.Service, fsNamespaceLockdown []string, creditsConfig config.CreditsConfiguration, featureGate *featuregate.FeatureGateChecker, @@ -473,7 +478,7 @@ func newChargesRegistry( return nil, err } - flatFeeSvc, err := NewChargesFlatFeeService(flatFeeAdapter, flatFeeHandler, lineageService, metaAdapter, locker, ratingService) + flatFeeSvc, err := NewChargesFlatFeeService(flatFeeAdapter, flatFeeHandler, lineageService, metaAdapter, locker, ratingService, currenciesService) if err != nil { return nil, err } @@ -502,6 +507,7 @@ func newChargesRegistry( billingService, featureService, ratingService, + currenciesService, streamingConnector, ) if err != nil { diff --git a/cmd/billing-worker/wire_gen.go b/cmd/billing-worker/wire_gen.go index 6da9a87b2c..70644c6a33 100644 --- a/cmd/billing-worker/wire_gen.go +++ b/cmd/billing-worker/wire_gen.go @@ -387,7 +387,7 @@ func initializeApplication(ctx context.Context, conf config.Configuration) (Appl gate := featuregate.NewNoop() featureGateConfiguration := conf.FeatureGate featureGateChecker := common.NewFeatureGateChecker(gate, featureGateConfiguration, creditsConfiguration) - billingRegistry, err := common.NewBillingRegistry(logger, service, adapter, ratingService, customerService, featureConnector, meterService, meter, connector, eventbusPublisher, billingConfiguration, subscriptionServiceWithWorkflow, client, billingFeatureSwitchesConfiguration, creditsConfiguration, tracer, taxcodeService, currencyResolver, locker, ledger, balanceQuerier, accountResolver, accountService, breakageService, featureGateChecker) + billingRegistry, err := common.NewBillingRegistry(logger, service, adapter, ratingService, customerService, featureConnector, meterService, meter, connector, eventbusPublisher, billingConfiguration, subscriptionServiceWithWorkflow, client, billingFeatureSwitchesConfiguration, creditsConfiguration, tracer, taxcodeService, currencyResolver, currenciesService, locker, ledger, balanceQuerier, accountResolver, accountService, breakageService, featureGateChecker) if err != nil { cleanup7() cleanup6() diff --git a/cmd/jobs/internal/wire_gen.go b/cmd/jobs/internal/wire_gen.go index 51ab672d2b..227b9e5cd1 100644 --- a/cmd/jobs/internal/wire_gen.go +++ b/cmd/jobs/internal/wire_gen.go @@ -396,7 +396,7 @@ func initializeApplication(ctx context.Context, conf config.Configuration) (Appl gate := featuregate.NewNoop() featureGateConfiguration := conf.FeatureGate featureGateChecker := common.NewFeatureGateChecker(gate, featureGateConfiguration, creditsConfiguration) - billingRegistry, err := common.NewBillingRegistry(logger, service, adapter, ratingService, customerService, featureConnector, meterService, meter, connector, eventbusPublisher, billingConfiguration, subscriptionServiceWithWorkflow, client, billingFeatureSwitchesConfiguration, creditsConfiguration, tracer, taxcodeService, currencyResolver, locker, ledger, balanceQuerier, accountResolver, accountService, breakageService, featureGateChecker) + billingRegistry, err := common.NewBillingRegistry(logger, service, adapter, ratingService, customerService, featureConnector, meterService, meter, connector, eventbusPublisher, billingConfiguration, subscriptionServiceWithWorkflow, client, billingFeatureSwitchesConfiguration, creditsConfiguration, tracer, taxcodeService, currencyResolver, currenciesService, locker, ledger, balanceQuerier, accountResolver, accountService, breakageService, featureGateChecker) if err != nil { cleanup7() cleanup6() diff --git a/cmd/server/wire_gen.go b/cmd/server/wire_gen.go index 41c08a2671..902dc2367d 100644 --- a/cmd/server/wire_gen.go +++ b/cmd/server/wire_gen.go @@ -391,7 +391,7 @@ func initializeApplication(ctx context.Context, conf config.Configuration) (Appl gate := featuregate.NewNoop() featureGateConfiguration := conf.FeatureGate featureGateChecker := common.NewFeatureGateChecker(gate, featureGateConfiguration, creditsConfiguration) - billingRegistry, err := common.NewBillingRegistry(logger, appService, billingAdapter, ratingService, customerService, featureConnector, service, meter, connector, eventbusPublisher, billingConfiguration, subscriptionServiceWithWorkflow, client, billingFeatureSwitchesConfiguration, creditsConfiguration, tracer, taxcodeService, currencyResolver, locker, ledger, balanceQuerier, accountResolver, accountService, breakageService, featureGateChecker) + billingRegistry, err := common.NewBillingRegistry(logger, appService, billingAdapter, ratingService, customerService, featureConnector, service, meter, connector, eventbusPublisher, billingConfiguration, subscriptionServiceWithWorkflow, client, billingFeatureSwitchesConfiguration, creditsConfiguration, tracer, taxcodeService, currencyResolver, currenciesService, locker, ledger, balanceQuerier, accountResolver, accountService, breakageService, featureGateChecker) if err != nil { cleanup7() cleanup6() diff --git a/openmeter/billing/charges/flatfee/adapter.go b/openmeter/billing/charges/flatfee/adapter.go index 12f0c78531..6aa34e8594 100644 --- a/openmeter/billing/charges/flatfee/adapter.go +++ b/openmeter/billing/charges/flatfee/adapter.go @@ -9,6 +9,7 @@ import ( "github.com/alpacahq/alpacadecimal" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/creditrealization" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/invoicedusage" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/payment" @@ -24,10 +25,15 @@ type Adapter interface { ChargeRunAdapter ChargeInvoicedUsageAdapter ChargePaymentAdapter + ChargeCostBasisAdapter entutils.TxCreator } +type ChargeCostBasisAdapter interface { + SetResolvedCostBasis(ctx context.Context, input costbasis.SetResolvedCostBasisInput) (costbasis.CostBasis, error) +} + type ChargeAdapter interface { CreateCharges(ctx context.Context, charges CreateChargesInput) ([]Charge, error) @@ -141,6 +147,7 @@ type IntentWithInitialStatus struct { InitialAdvanceAfter *time.Time AmountAfterProration alpacadecimal.Decimal NoFiatTransactionRequired bool + ResolvedCostBasis *costbasis.State } func (i IntentWithInitialStatus) Validate() error { diff --git a/openmeter/billing/charges/flatfee/adapter/charge.go b/openmeter/billing/charges/flatfee/adapter/charge.go index b4a3ee5cfb..daf5fe0351 100644 --- a/openmeter/billing/charges/flatfee/adapter/charge.go +++ b/openmeter/billing/charges/flatfee/adapter/charge.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "github.com/oklog/ulid/v2" "github.com/samber/lo" "github.com/openmeterio/openmeter/openmeter/billing" @@ -12,6 +13,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" metaadapter "github.com/openmeterio/openmeter/openmeter/billing/charges/meta/adapter" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/chargemeta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/ent/db" dbchargeflatfee "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfee" dbchargeflatfeeoverride "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeoverride" @@ -86,6 +88,10 @@ func (a *adapter) UpdateCharge(ctx context.Context, charge flatfee.ChargeBase) ( return flatfee.ChargeBase{}, err } + if err := tx.loadCostBasisEdge(ctx, dbUpdatedChargeBase); err != nil { + return flatfee.ChargeBase{}, err + } + if overrideLayer := charge.Intent.GetOverrideLayerMutableFields(); overrideLayer != nil { intentOverride, err := tx.updateIntentOverride(ctx, charge.GetChargeID(), overrideLayer, intent.Currency) if err != nil { @@ -132,6 +138,9 @@ func (a *adapter) UpdateSubscriptionItemID(ctx context.Context, charge flatfee.C } updatedChargeBase.Edges.IntentOverride = override + if err := tx.loadCostBasisEdge(ctx, updatedChargeBase); err != nil { + return flatfee.Charge{}, err + } mappedChargeBase, err := fromDBBaseWithCurrency(updatedChargeBase, charge.Intent.GetBaseIntent().Currency) if err != nil { return flatfee.Charge{}, err @@ -208,19 +217,69 @@ func (a *adapter) CreateCharges(ctx context.Context, in flatfee.CreateChargesInp } return entutils.TransactingRepo(ctx, a, func(ctx context.Context, tx *adapter) ([]flatfee.Charge, error) { - creates, err := slicesx.MapWithErr(in.Intents, func(intent flatfee.IntentWithInitialStatus) (*db.ChargeFlatFeeCreate, error) { - return tx.buildCreateFlatFeeCharge(in.Namespace, intent) + type preparedCreate struct { + costBasis *db.ChargeFlatFeeCostBasisCreate + charge *db.ChargeFlatFeeCreate + } + + preparedCreates := make([]preparedCreate, 0, len(in.Intents)) + for _, intent := range in.Intents { + chargeCreate, err := tx.buildCreateFlatFeeCharge(in.Namespace, intent) + if err != nil { + return nil, err + } + + var costBasisCreate *db.ChargeFlatFeeCostBasisCreate + if intent.Intent.CostBasis != nil { + costBasisCreate, err = costbasis.Create(tx.db.ChargeFlatFeeCostBasis.Create(), costbasis.CreateInput{ + NamespacedID: models.NamespacedID{ + Namespace: in.Namespace, + ID: ulid.Make().String(), + }, + CurrencyID: intent.Intent.Currency.ID, + Intent: *intent.Intent.CostBasis, + State: intent.ResolvedCostBasis, + }) + if err != nil { + return nil, fmt.Errorf("building flat fee cost basis: %w", err) + } + } + + preparedCreates = append(preparedCreates, preparedCreate{ + costBasis: costBasisCreate, + charge: chargeCreate, + }) + } + + costBasisCreates := lo.Filter(preparedCreates, func(create preparedCreate, _ int) bool { + return create.costBasis != nil }) - if err != nil { - return nil, err + + var createdCostBases []*db.ChargeFlatFeeCostBasis + if len(costBasisCreates) > 0 { + var err error + createdCostBases, err = tx.db.ChargeFlatFeeCostBasis.CreateBulk( + lo.Map(costBasisCreates, func(create preparedCreate, _ int) *db.ChargeFlatFeeCostBasisCreate { + return create.costBasis + })..., + ).Save(ctx) + if err != nil { + return nil, fmt.Errorf("creating flat fee cost bases: %w", err) + } + + lo.ForEach(costBasisCreates, func(create preparedCreate, idx int) { + create.charge.SetCostBasisID(createdCostBases[idx].ID) + }) } - entities, err := tx.db.ChargeFlatFee.CreateBulk(creates...).Save(ctx) + chargeCreates := lo.Map(preparedCreates, func(create preparedCreate, _ int) *db.ChargeFlatFeeCreate { + return create.charge + }) + entities, err := tx.db.ChargeFlatFee.CreateBulk(chargeCreates...).Save(ctx) if err != nil { return nil, metaadapter.MapChargeConstraintError(err) } - // Let's reserve the charge IDs err = tx.metaAdapter.RegisterCharges(ctx, meta.RegisterChargesInput{ Namespace: in.Namespace, Type: meta.ChargeTypeFlatFee, @@ -235,7 +294,20 @@ func (a *adapter) CreateCharges(ctx context.Context, in flatfee.CreateChargesInp return nil, err } + costBasisByID := lo.SliceToMap(createdCostBases, func(entity *db.ChargeFlatFeeCostBasis) (string, *db.ChargeFlatFeeCostBasis) { + return entity.ID, entity + }) + return lo.MapErr(entities, func(entity *db.ChargeFlatFee, idx int) (flatfee.Charge, error) { + if entity.CostBasisID != nil { + createdCostBasis, ok := costBasisByID[*entity.CostBasisID] + if !ok { + return flatfee.Charge{}, fmt.Errorf("created flat fee cost basis %s not found", *entity.CostBasisID) + } + + entity.Edges.CostBasis = createdCostBasis + } + return FromDBWithCurrency(entity, in.Intents[idx].Intent.Currency, meta.ExpandNone) }) }) @@ -251,7 +323,8 @@ func (a *adapter) GetByIDs(ctx context.Context, input flatfee.GetByIDsInput) ([] Where(dbchargeflatfee.Namespace(input.Namespace)). Where(dbchargeflatfee.IDIn(input.IDs...)). WithIntentOverride(). - WithCustomCurrency() + WithCustomCurrency(). + WithCostBasis() if input.Expands.Has(meta.ExpandRealizations) { query = expandRealizations(query) @@ -294,7 +367,8 @@ func (a *adapter) GetByID(ctx context.Context, input flatfee.GetByIDInput) (flat Where(dbchargeflatfee.Namespace(input.ChargeID.Namespace)). Where(dbchargeflatfee.ID(input.ChargeID.ID)). WithIntentOverride(). - WithCustomCurrency() + WithCustomCurrency(). + WithCostBasis() if input.Expands.Has(meta.ExpandRealizations) { query = expandRealizations(query) diff --git a/openmeter/billing/charges/flatfee/adapter/costbasis.go b/openmeter/billing/charges/flatfee/adapter/costbasis.go new file mode 100644 index 0000000000..a40c29e775 --- /dev/null +++ b/openmeter/billing/charges/flatfee/adapter/costbasis.go @@ -0,0 +1,97 @@ +package adapter + +import ( + "context" + "fmt" + + "github.com/openmeterio/openmeter/openmeter/billing/charges/flatfee" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + entdb "github.com/openmeterio/openmeter/openmeter/ent/db" + dbchargeflatfeecostbasis "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeecostbasis" + "github.com/openmeterio/openmeter/pkg/framework/entutils" + "github.com/openmeterio/openmeter/pkg/models" +) + +var _ flatfee.ChargeCostBasisAdapter = (*adapter)(nil) + +func (a *adapter) loadCostBasisEdge(ctx context.Context, entity *entdb.ChargeFlatFee) error { + if entity.Edges.CostBasis != nil { + return fmt.Errorf("flat fee cost basis edge is already loaded [charge_id=%s,edge_id=%s]", entity.ID, entity.Edges.CostBasis.ID) + } + + if entity.CostBasisID == nil { + return nil + } + + costBasisEntity, err := a.db.ChargeFlatFeeCostBasis.Query(). + Where( + dbchargeflatfeecostbasis.ID(*entity.CostBasisID), + dbchargeflatfeecostbasis.Namespace(entity.Namespace), + ). + Only(ctx) + if err != nil { + return fmt.Errorf("load flat fee cost basis edge [charge_id=%s,cost_basis_id=%s]: %w", entity.ID, *entity.CostBasisID, err) + } + + entity.Edges.CostBasis = costBasisEntity + + return nil +} + +func (a *adapter) SetResolvedCostBasis(ctx context.Context, input costbasis.SetResolvedCostBasisInput) (costbasis.CostBasis, error) { + if err := input.Validate(); err != nil { + return costbasis.CostBasis{}, err + } + + return entutils.TransactingRepo(ctx, a, func(ctx context.Context, tx *adapter) (costbasis.CostBasis, error) { + update := tx.db.ChargeFlatFeeCostBasis.UpdateOneID(input.ID). + Where( + dbchargeflatfeecostbasis.Namespace(input.Namespace), + dbchargeflatfeecostbasis.ModeEQ(costbasis.ModeDynamic), + dbchargeflatfeecostbasis.ResolvedCostBasisIDIsNil(), + dbchargeflatfeecostbasis.ResolvedCostBasisIsNil(), + dbchargeflatfeecostbasis.ResolvedAtIsNil(), + ) + + update, err := costbasis.Set(update, input.State) + if err != nil { + return costbasis.CostBasis{}, err + } + + entity, err := update.Save(ctx) + if entdb.IsNotFound(err) { + existingEntity, getErr := tx.db.ChargeFlatFeeCostBasis.Query(). + Where( + dbchargeflatfeecostbasis.ID(input.ID), + dbchargeflatfeecostbasis.Namespace(input.Namespace), + ). + Only(ctx) + if entdb.IsNotFound(getErr) { + return costbasis.CostBasis{}, models.NewGenericNotFoundError( + fmt.Errorf("flat fee cost basis not found: %s", input.ID), + ) + } + if getErr != nil { + return costbasis.CostBasis{}, fmt.Errorf("get flat fee cost basis after conditional resolution: %w", getErr) + } + + existing, getErr := costbasis.Get(existingEntity) + if getErr != nil { + return costbasis.CostBasis{}, fmt.Errorf("map flat fee cost basis after conditional resolution: %w", getErr) + } + + if existing.Intent.Kind() == costbasis.ModeDynamic && existing.State != nil { + return existing, nil + } + + return costbasis.CostBasis{}, models.NewGenericValidationError( + fmt.Errorf("flat fee cost basis is not an unresolved dynamic cost basis: %s", input.ID), + ) + } + if err != nil { + return costbasis.CostBasis{}, fmt.Errorf("set resolved flat fee cost basis: %w", err) + } + + return costbasis.Get(entity) + }) +} diff --git a/openmeter/billing/charges/flatfee/adapter/intentoverride.go b/openmeter/billing/charges/flatfee/adapter/intentoverride.go index 239ebb89ee..7b20ab6902 100644 --- a/openmeter/billing/charges/flatfee/adapter/intentoverride.go +++ b/openmeter/billing/charges/flatfee/adapter/intentoverride.go @@ -83,6 +83,9 @@ func (a *adapter) CreateChargeOverride(ctx context.Context, charge flatfee.Charg } dbCharge.Edges.IntentOverride = dbIntentOverride + if err := tx.loadCostBasisEdge(ctx, dbCharge); err != nil { + return flatfee.ChargeBase{}, err + } return fromDBBaseWithCurrency(dbCharge, charge.Intent.GetBaseIntent().Currency) }) diff --git a/openmeter/billing/charges/flatfee/adapter/mapper.go b/openmeter/billing/charges/flatfee/adapter/mapper.go index 2a838f1672..1491991c03 100644 --- a/openmeter/billing/charges/flatfee/adapter/mapper.go +++ b/openmeter/billing/charges/flatfee/adapter/mapper.go @@ -11,6 +11,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing/charges/flatfee" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/chargemeta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/creditrealization" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/invoicedusage" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/payment" @@ -44,8 +45,13 @@ func FromDBWithCurrency(entity *entdb.ChargeFlatFee, currency currencies.Currenc } func fromDBWithMeta(entity *entdb.ChargeFlatFee, mappedMeta meta.Charge, expands meta.Expands) (flatfee.Charge, error) { + base, err := fromDBBase(entity, mappedMeta) + if err != nil { + return flatfee.Charge{}, fmt.Errorf("mapping flat fee charge base [id=%s]: %w", entity.ID, err) + } + charge := flatfee.Charge{ - ChargeBase: fromDBBase(entity, mappedMeta), + ChargeBase: base, } if expands.Has(meta.ExpandRealizations) { @@ -154,15 +160,39 @@ func fromDBBaseWithCurrency(entity *entdb.ChargeFlatFee, currency currencies.Cur return flatfee.ChargeBase{}, fmt.Errorf("mapping charge meta: %w", err) } - return fromDBBase(entity, mappedMeta), nil + return fromDBBase(entity, mappedMeta) } -func fromDBBase(entity *entdb.ChargeFlatFee, mappedMeta meta.Charge) flatfee.ChargeBase { +func fromDBBase(entity *entdb.ChargeFlatFee, mappedMeta meta.Charge) (flatfee.ChargeBase, error) { var percentageDiscounts *billing.PercentageDiscount if entity.Discounts != nil { percentageDiscounts = entity.Discounts.Percentage } + var costBasisIntent *costbasis.Intent + var resolvedCostBasis *costbasis.State + var costBasisID *string + if entity.CostBasisID != nil { + if entity.Edges.CostBasis == nil { + return flatfee.ChargeBase{}, fmt.Errorf("cost basis not loaded for flat fee charge [id=%s,cost_basis_id=%s]", entity.ID, *entity.CostBasisID) + } + + if entity.Edges.CostBasis.ID != *entity.CostBasisID { + return flatfee.ChargeBase{}, fmt.Errorf("cost basis ID mismatch for flat fee charge [id=%s,cost_basis_id=%s,edge_id=%s]", entity.ID, *entity.CostBasisID, entity.Edges.CostBasis.ID) + } + + mappedCostBasis, err := costbasis.Get(entity.Edges.CostBasis) + if err != nil { + return flatfee.ChargeBase{}, fmt.Errorf("mapping cost basis: %w", err) + } + + costBasisID = lo.ToPtr(*entity.CostBasisID) + costBasisIntent = &mappedCostBasis.Intent + resolvedCostBasis = mappedCostBasis.State + } else if entity.Edges.CostBasis != nil { + return flatfee.ChargeBase{}, fmt.Errorf("cost basis edge loaded without a reference for flat fee charge [id=%s,edge_id=%s]", entity.ID, entity.Edges.CostBasis.ID) + } + return flatfee.ChargeBase{ ManagedResource: mappedMeta.ManagedResource, Status: entity.StatusDetailed, @@ -170,11 +200,14 @@ func fromDBBase(entity *entdb.ChargeFlatFee, mappedMeta meta.Charge) flatfee.Cha AdvanceAfter: mappedMeta.AdvanceAfter, FeatureID: entity.FeatureID, AmountAfterProration: entity.AmountAfterProration, + CostBasisID: costBasisID, + ResolvedCostBasis: resolvedCostBasis, }, Intent: flatfee.NewOverridableIntent(flatfee.Intent{ Intent: mappedMeta.Intent, SettlementMode: entity.SettlementMode, FeatureKey: entity.FeatureKey, + CostBasis: costBasisIntent, IntentMutableFields: flatfee.IntentMutableFields{ IntentMutableFields: mappedMeta.IntentMutableFields, InvoiceAt: entity.InvoiceAt.UTC(), @@ -185,7 +218,7 @@ func fromDBBase(entity *entdb.ChargeFlatFee, mappedMeta meta.Charge) flatfee.Cha AmountBeforeProration: entity.AmountBeforeProration, }, }, fromDBOverride(entity.Edges.IntentOverride)), - } + }, nil } // fromDBProRatingConfig converts a DB ProRatingModeAdapterEnum to a ProRatingConfig. diff --git a/openmeter/billing/charges/flatfee/charge.go b/openmeter/billing/charges/flatfee/charge.go index be3785759b..63b0649191 100644 --- a/openmeter/billing/charges/flatfee/charge.go +++ b/openmeter/billing/charges/flatfee/charge.go @@ -11,6 +11,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/currencies" "github.com/openmeterio/openmeter/openmeter/customer" "github.com/openmeterio/openmeter/openmeter/productcatalog" @@ -46,6 +47,19 @@ func (c ChargeBase) Validate() error { errs = append(errs, fmt.Errorf("state: %w", err)) } + costBasisIntent := c.Intent.GetCostBasisIntent() + if costBasisIntent == nil { + if c.State.CostBasisID != nil { + errs = append(errs, errors.New("cost basis ID must not be set without a cost basis intent")) + } + + if c.State.ResolvedCostBasis != nil { + errs = append(errs, errors.New("resolved cost basis must not be set without a cost basis intent")) + } + } else if c.State.CostBasisID == nil { + errs = append(errs, errors.New("cost basis ID is required with a cost basis intent")) + } + return models.NewNillableGenericValidationError(errors.Join(errs...)) } @@ -120,6 +134,7 @@ type Intent struct { IntentMutableFields `json:"intentMutableFields"` SettlementMode productcatalog.SettlementMode `json:"settlementMode"` FeatureKey *string `json:"featureKey,omitempty"` + CostBasis *costbasis.Intent `json:"costBasis,omitempty"` } func (i Intent) Normalized() Intent { @@ -135,6 +150,7 @@ func (i Intent) AsOverridableIntent() OverridableIntent { baseLayer: i.IntentMutableFields, settlementMode: i.SettlementMode, featureKey: i.FeatureKey, + costBasis: i.CostBasis, } } @@ -153,9 +169,34 @@ func (i Intent) Validate() error { errs = append(errs, fmt.Errorf("settlement mode: %w", err)) } + if err := validateCostBasis(i.Currency, i.SettlementMode, i.CostBasis); err != nil { + errs = append(errs, err) + } + return models.NewNillableGenericValidationError(errors.Join(errs...)) } +func validateCostBasis(currency currencies.Currency, settlementMode productcatalog.SettlementMode, intent *costbasis.Intent) error { + isCostBasisRequired := currency.IsCustom() && settlementMode == productcatalog.CreditThenInvoiceSettlementMode + if !isCostBasisRequired { + if intent != nil { + return errors.New("cost basis must not be set unless currency is custom and settlement mode is credit then invoice") + } + + return nil + } + + if intent == nil { + return errors.New("cost basis is required for custom currency with credit then invoice settlement") + } + + if err := intent.Validate(); err != nil { + return fmt.Errorf("cost basis: %w", err) + } + + return nil +} + // CalculateAmountAfterProration computes the prorated amount from AmountBeforeProration, // ServicePeriod, and FullServicePeriod. Returns AmountBeforeProration when proration is // not applicable (disabled, unsupported mode, or zero-length periods). @@ -199,6 +240,7 @@ type OverridableIntent struct { settlementMode productcatalog.SettlementMode featureKey *string + costBasis *costbasis.Intent } func NewOverridableIntent(baseIntent Intent, overrideLayer *IntentMutableFields) OverridableIntent { @@ -208,6 +250,7 @@ func NewOverridableIntent(baseIntent Intent, overrideLayer *IntentMutableFields) overrideLayer: overrideLayer, settlementMode: baseIntent.SettlementMode, featureKey: baseIntent.FeatureKey, + costBasis: baseIntent.CostBasis, } } @@ -268,6 +311,10 @@ func (i OverridableIntent) Validate() error { errs = append(errs, fmt.Errorf("settlement mode: %w", err)) } + if err := validateCostBasis(i.intent.Currency, i.settlementMode, i.costBasis); err != nil { + errs = append(errs, err) + } + return models.NewNillableGenericValidationError(errors.Join(errs...)) } @@ -287,6 +334,7 @@ func (i OverridableIntent) GetEffectiveIntent() Intent { IntentMutableFields: i.baseLayer.Clone(), SettlementMode: i.settlementMode, FeatureKey: featureKey, + CostBasis: i.GetCostBasisIntent(), } if i.overrideLayer != nil { @@ -336,6 +384,16 @@ func (i OverridableIntent) GetFeatureKey() string { return *i.featureKey } +// GetCostBasisIntent returns the immutable cost-basis intent from the base intent. +// Override layers cannot change how the charge's custom-currency value is resolved. +func (i OverridableIntent) GetCostBasisIntent() *costbasis.Intent { + if i.costBasis == nil { + return nil + } + + return lo.ToPtr(i.costBasis.Clone()) +} + // GetTaxConfig returns the immutable tax config from the base intent. // Override layers cannot change tax attribution. func (i OverridableIntent) GetTaxConfig() productcatalog.TaxCodeConfig { @@ -368,6 +426,7 @@ func (i OverridableIntent) GetBaseIntent() Intent { IntentMutableFields: i.baseLayer.Clone(), SettlementMode: i.settlementMode, FeatureKey: featureKey, + CostBasis: i.GetCostBasisIntent(), } } @@ -381,6 +440,7 @@ func (i OverridableIntent) GetIntentForTarget(target meta.ChangeTarget) (Intent, Intent: i.intent.Clone(), SettlementMode: i.settlementMode, FeatureKey: featureKey, + CostBasis: i.GetCostBasisIntent(), } switch target { @@ -544,6 +604,8 @@ type State struct { AdvanceAfter *time.Time `json:"advanceAfter,omitempty"` FeatureID *string `json:"featureId,omitempty"` AmountAfterProration alpacadecimal.Decimal `json:"amountAfterProration"` + CostBasisID *string `json:"-"` + ResolvedCostBasis *costbasis.State `json:"resolvedCostBasis,omitempty"` } func (s State) Normalized() State { @@ -565,6 +627,16 @@ func (s State) Validate() error { errs = append(errs, fmt.Errorf("amount after proration cannot be negative")) } + if s.CostBasisID != nil && *s.CostBasisID == "" { + errs = append(errs, fmt.Errorf("cost basis ID is required")) + } + + if s.ResolvedCostBasis != nil { + if err := s.ResolvedCostBasis.Validate(); err != nil { + errs = append(errs, fmt.Errorf("resolved cost basis: %w", err)) + } + } + return models.NewNillableGenericValidationError(errors.Join(errs...)) } diff --git a/openmeter/billing/charges/flatfee/charge_test.go b/openmeter/billing/charges/flatfee/charge_test.go index e5e289b5ff..8f1abc2be4 100644 --- a/openmeter/billing/charges/flatfee/charge_test.go +++ b/openmeter/billing/charges/flatfee/charge_test.go @@ -9,13 +9,202 @@ import ( "github.com/stretchr/testify/require" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/currencies" currenciestestutils "github.com/openmeterio/openmeter/openmeter/currencies/testutils/currency" "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/pkg/currencyx" "github.com/openmeterio/openmeter/pkg/datetime" "github.com/openmeterio/openmeter/pkg/timeutil" ) +func TestIntentValidateCostBasis(t *testing.T) { + customCurrency := newCustomCurrency(t) + fiatCurrency := currenciestestutils.NewFiatCurrency(t, "USD") + validCostBasis := newManualCostBasisIntent(t) + invalidCostBasis := costbasis.Intent{} + + tests := []struct { + name string + currency currencies.Currency + settlementMode productcatalog.SettlementMode + costBasis *costbasis.Intent + wantErr string + }{ + { + name: "custom currency with credit then invoice requires cost basis", + currency: customCurrency, + settlementMode: productcatalog.CreditThenInvoiceSettlementMode, + wantErr: "cost basis is required", + }, + { + name: "custom currency with credit then invoice accepts valid cost basis", + currency: customCurrency, + settlementMode: productcatalog.CreditThenInvoiceSettlementMode, + costBasis: &validCostBasis, + }, + { + name: "custom currency with credit then invoice validates cost basis", + currency: customCurrency, + settlementMode: productcatalog.CreditThenInvoiceSettlementMode, + costBasis: &invalidCostBasis, + wantErr: "cost basis", + }, + { + name: "custom currency with credit only does not require cost basis", + currency: customCurrency, + settlementMode: productcatalog.CreditOnlySettlementMode, + }, + { + name: "custom currency with credit only rejects cost basis", + currency: customCurrency, + settlementMode: productcatalog.CreditOnlySettlementMode, + costBasis: &validCostBasis, + wantErr: "cost basis must not be set", + }, + { + name: "fiat currency with credit then invoice does not require cost basis", + currency: fiatCurrency, + settlementMode: productcatalog.CreditThenInvoiceSettlementMode, + }, + { + name: "fiat currency with credit then invoice rejects cost basis", + currency: fiatCurrency, + settlementMode: productcatalog.CreditThenInvoiceSettlementMode, + costBasis: &validCostBasis, + wantErr: "cost basis must not be set", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + intent := newValidIntent(t, tt.currency, tt.settlementMode) + intent.CostBasis = tt.costBasis + + validations := []struct { + name string + err error + }{ + {name: "intent", err: intent.Validate()}, + {name: "overridable intent", err: intent.AsOverridableIntent().Validate()}, + } + + for _, validation := range validations { + t.Run(validation.name, func(t *testing.T) { + if tt.wantErr == "" { + require.NoError(t, validation.err) + return + } + + require.ErrorContains(t, validation.err, tt.wantErr) + }) + } + }) + } +} + +func TestOverridableIntentPreservesCostBasis(t *testing.T) { + intent := newValidIntent(t, newCustomCurrency(t), productcatalog.CreditThenInvoiceSettlementMode) + costBasis := newManualCostBasisIntent(t) + intent.CostBasis = &costBasis + + overridable := intent.AsOverridableIntent() + requireManualCostBasisIntent(t, overridable.GetCostBasisIntent()) + requireManualCostBasisIntent(t, overridable.GetBaseIntent().CostBasis) + requireManualCostBasisIntent(t, overridable.GetEffectiveIntent().CostBasis) + + baseIntent, err := overridable.GetIntentForTarget(meta.ChangeTargetBase) + require.NoError(t, err) + requireManualCostBasisIntent(t, baseIntent.CostBasis) + + overrideLayer := intent.IntentMutableFields.Clone() + overrideLayer.Name = "override" + overridable = NewOverridableIntent(intent, &overrideLayer) + + overrideIntent, err := overridable.GetIntentForTarget(meta.ChangeTargetOverride) + require.NoError(t, err) + requireManualCostBasisIntent(t, overrideIntent.CostBasis) + + returnedCostBasis := overridable.GetCostBasisIntent() + *returnedCostBasis = costbasis.NewIntent(costbasis.DynamicIntent{ + FiatCurrency: newFiatCurrency(t, "EUR"), + }) + requireManualCostBasisIntent(t, overridable.GetCostBasisIntent()) +} + +func newCustomCurrency(t testing.TB) currencies.Currency { + t.Helper() + + currency, err := currencyx.NewCurrencyBuilder(currencyx.CurrencyTypeCustom). + WithCode(currencyx.Code("TOKENS")). + WithName("Tokens"). + Build() + require.NoError(t, err) + + return currencies.Currency{Currency: currency} +} + +func newValidIntent(t testing.TB, currency currencies.Currency, settlementMode productcatalog.SettlementMode) Intent { + t.Helper() + + period := timeutil.ClosedPeriod{ + From: time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC), + To: time.Date(2026, 2, 1, 0, 0, 0, 0, time.UTC), + } + + return Intent{ + Intent: meta.Intent{ + ManagedBy: "system", + CustomerID: "customer-1", + Currency: currency, + TaxConfig: productcatalog.TaxCodeConfig{ + TaxCodeID: "tax-code-1", + }, + }, + IntentMutableFields: IntentMutableFields{ + IntentMutableFields: meta.IntentMutableFields{ + Name: "flat fee", + ServicePeriod: period, + FullServicePeriod: period, + BillingPeriod: period, + }, + InvoiceAt: period.From, + PaymentTerm: productcatalog.InAdvancePaymentTerm, + AmountBeforeProration: alpacadecimal.NewFromInt(100), + }, + SettlementMode: settlementMode, + } +} + +func newManualCostBasisIntent(t testing.TB) costbasis.Intent { + t.Helper() + + return costbasis.NewIntent(costbasis.ManualIntent{ + FiatCurrency: newFiatCurrency(t, "USD"), + Rate: alpacadecimal.NewFromInt(2), + }) +} + +func newFiatCurrency(t testing.TB, code currencyx.Code) *currencyx.FiatCurrency { + t.Helper() + + fiatCurrency, err := currencyx.NewFiatCurrency(code) + require.NoError(t, err) + + return fiatCurrency +} + +func requireManualCostBasisIntent(t testing.TB, intent *costbasis.Intent) { + t.Helper() + require.NotNil(t, intent) + require.Equal(t, costbasis.ModeManual, intent.Kind()) + + manualIntent, err := intent.AsManual() + require.NoError(t, err) + require.Equal(t, float64(2), manualIntent.Rate.InexactFloat64()) + require.Equal(t, currencyx.Code("USD"), manualIntent.FiatCurrency.Details().Code) +} + func TestCalculateAmountAfterProration(t *testing.T) { // 2026-01-01 to 2026-02-01 (full month) fullMonthStart := datetime.MustParseTimeInLocation(t, "2026-01-01T00:00:00Z", time.UTC).AsTime() diff --git a/openmeter/billing/charges/flatfee/service/create.go b/openmeter/billing/charges/flatfee/service/create.go index 179296e7a1..37584dc0d1 100644 --- a/openmeter/billing/charges/flatfee/service/create.go +++ b/openmeter/billing/charges/flatfee/service/create.go @@ -10,7 +10,9 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/billing/charges/flatfee" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/pkg/clock" "github.com/openmeterio/openmeter/pkg/framework/transaction" "github.com/openmeterio/openmeter/pkg/models" "github.com/openmeterio/openmeter/pkg/slicesx" @@ -27,14 +29,31 @@ func (s *service) Create(ctx context.Context, input flatfee.CreateInput) ([]flat } return transaction.Run(ctx, s.adapter, func(ctx context.Context) ([]flatfee.ChargeWithGatheringLine, error) { + now := clock.Now().UTC() // Let's create all the flat fee charges in bulk intentsWithStatus, err := slicesx.MapWithErr(input.Intents, func(intent flatfee.Intent) (flatfee.IntentWithInitialStatus, error) { - if intent.Currency.IsCustom() && intent.SettlementMode != productcatalog.CreditOnlySettlementMode { + if intent.Currency.IsCustom() && + intent.SettlementMode == productcatalog.CreditThenInvoiceSettlementMode && + !s.enableCustomCurrency.Load() { return flatfee.IntentWithInitialStatus{}, fmt.Errorf("creating flat fee charge with custom currency %q: %w", intent.Currency.GetCode(), meta.ErrCustomCurrencyNotSupported) } chargeIntent := intent.Normalized() + var resolvedCostBasis *costbasis.State + if chargeIntent.CostBasis != nil { + var err error + + resolvedCostBasis, err = s.costbasisResolver.ResolveInitialState(ctx, costbasis.ResolveInitialStateInput{ + CurrencyID: chargeIntent.Currency.NamespacedID, + Intent: *chargeIntent.CostBasis, + ResolvedAt: now, + }) + if err != nil { + return flatfee.IntentWithInitialStatus{}, fmt.Errorf("resolving cost basis: %w", err) + } + } + amountAfterProration, err := chargeIntent.CalculateAmountAfterProration() if err != nil { return flatfee.IntentWithInitialStatus{}, fmt.Errorf("calculating amount after proration: %w", err) @@ -56,6 +75,7 @@ func (s *service) Create(ctx context.Context, input flatfee.CreateInput) ([]flat InitialAdvanceAfter: lo.ToPtr(meta.NormalizeTimestamp(chargeIntent.InvoiceAt)), AmountAfterProration: amountAfterProration, NoFiatTransactionRequired: chargeIntent.SettlementMode == productcatalog.CreditOnlySettlementMode || amountAfterProration.IsZero(), + ResolvedCostBasis: resolvedCostBasis, }, nil }) if err != nil { diff --git a/openmeter/billing/charges/flatfee/service/creditheninvoice.go b/openmeter/billing/charges/flatfee/service/creditheninvoice.go index f97e6d5108..8f90459a87 100644 --- a/openmeter/billing/charges/flatfee/service/creditheninvoice.go +++ b/openmeter/billing/charges/flatfee/service/creditheninvoice.go @@ -13,6 +13,7 @@ import ( flatfeerealizations "github.com/openmeterio/openmeter/openmeter/billing/charges/flatfee/service/realizations" "github.com/openmeterio/openmeter/openmeter/billing/charges/invoiceupdater" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/payment" "github.com/openmeterio/openmeter/openmeter/productcatalog" "github.com/openmeterio/openmeter/pkg/clock" @@ -99,7 +100,10 @@ func (s *CreditThenInvoiceStateMachine) configureStates() { InternalTransition(meta.TriggerExtend, statelessx.WithParameters(s.ExtendCharge)). InternalTransition(meta.TriggerShrink, statelessx.WithParameters(s.ShrinkCharge)). InternalTransition(meta.TriggerLineManualEdit, statelessx.WithParameters(s.LineManualEdit)). - OnActive(s.AdvanceAfterServicePeriodTo) + OnActive(statelessx.AllOf( + s.ResolveDynamicCostBasis, + s.AdvanceAfterServicePeriodTo, + )) s.Configure(flatfee.StatusActiveRealizationStarted). Permit(meta.TriggerNext, flatfee.StatusActiveRealizationWaitingForCollection). @@ -387,6 +391,54 @@ func (s *CreditThenInvoiceStateMachine) UnsupportedShrinkOperation(_ context.Con ) } +// ResolveDynamicCostBasis idempotently persists the dynamic cost basis +// effective at the charge's service-period start. Once resolved, the persisted +// value is authoritative and must never be overwritten by lifecycle retries. +func (s *CreditThenInvoiceStateMachine) ResolveDynamicCostBasis(ctx context.Context) error { + intent := s.Charge.Intent.GetCostBasisIntent() + if intent == nil || intent.Kind() != costbasis.ModeDynamic { + return nil + } + + if s.Charge.State.ResolvedCostBasis != nil { + return nil + } + + if s.Charge.State.CostBasisID == nil { + return models.NewGenericPreConditionFailedError( + fmt.Errorf("dynamic cost basis reference is missing for flat-fee charge %s", s.Charge.ID), + ) + } + + resolvedState, err := s.Service.costbasisResolver.ResolveDynamicState(ctx, costbasis.ResolveDynamicStateInput{ + CurrencyID: s.Charge.Intent.GetCurrency().NamespacedID, + Intent: *intent, + ServicePeriodFrom: s.Charge.Intent.GetEffectiveServicePeriod().From, + }) + if err != nil { + return fmt.Errorf("resolve dynamic cost basis for flat-fee charge %s: %w", s.Charge.ID, err) + } + + persisted, err := s.Adapter.SetResolvedCostBasis(ctx, costbasis.SetResolvedCostBasisInput{ + NamespacedID: models.NamespacedID{ + Namespace: s.Charge.Namespace, + ID: *s.Charge.State.CostBasisID, + }, + State: resolvedState, + }) + if err != nil { + return fmt.Errorf("persist dynamic cost basis for flat-fee charge %s: %w", s.Charge.ID, err) + } + + if persisted.State == nil { + return fmt.Errorf("persisted dynamic cost basis is unresolved for flat-fee charge %s", s.Charge.ID) + } + + s.Charge.State.ResolvedCostBasis = persisted.State + + return nil +} + // StartRealization creates the current run. The line engine maps the run back // onto the returned standard line before billing persists line updates. func (s *CreditThenInvoiceStateMachine) StartRealization(ctx context.Context, input billing.StandardLineWithInvoiceHeader) error { diff --git a/openmeter/billing/charges/flatfee/service/lineengine.go b/openmeter/billing/charges/flatfee/service/lineengine.go index d75f8a5460..a57a68c26f 100644 --- a/openmeter/billing/charges/flatfee/service/lineengine.go +++ b/openmeter/billing/charges/flatfee/service/lineengine.go @@ -539,6 +539,9 @@ func (e *LineEngine) attachManualStandardLine(ctx context.Context, invoice billi return nil, fmt.Errorf("new state machine for flat fee charge[%s]: %w", charge.ID, err) } + // TODO: reject cost-basis-backed charges in manual line attachment. This + // path bypasses StatusActive, which owns cost-basis resolution, so accepting + // it would create an invoice-backed charge without the required resolved value. if err := stateMachine.FireAndActivate(ctx, meta.TriggerAttachInvoiceLine, billing.StandardLineWithInvoiceHeader{ Line: &standardLine, Invoice: standardInvoice, diff --git a/openmeter/billing/charges/flatfee/service/service.go b/openmeter/billing/charges/flatfee/service/service.go index 1a515c2624..19c454c61d 100644 --- a/openmeter/billing/charges/flatfee/service/service.go +++ b/openmeter/billing/charges/flatfee/service/service.go @@ -11,7 +11,9 @@ import ( flatfeerealizations "github.com/openmeterio/openmeter/openmeter/billing/charges/flatfee/service/realizations" "github.com/openmeterio/openmeter/openmeter/billing/charges/lineage" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/rating" + "github.com/openmeterio/openmeter/openmeter/currencies" "github.com/openmeterio/openmeter/pkg/framework/lockr" ) @@ -22,6 +24,7 @@ type Config struct { MetaAdapter meta.Adapter Locker *lockr.Locker RatingService rating.Service + Currencies currencies.Service } func (c Config) Validate() error { @@ -51,6 +54,10 @@ func (c Config) Validate() error { errs = append(errs, errors.New("rating service cannot be null")) } + if c.Currencies == nil { + errs = append(errs, errors.New("currencies service cannot be null")) + } + return errors.Join(errs...) } @@ -69,12 +76,20 @@ func New(config Config) (flatfee.Service, error) { return nil, err } + costbasisResolver, err := costbasis.NewResolver(costbasis.ResolverConfig{ + Currencies: config.Currencies, + }) + if err != nil { + return nil, err + } + svc := &service{ - adapter: config.Adapter, - handler: config.Handler, - metaAdapter: config.MetaAdapter, - locker: config.Locker, - realizations: realizations, + adapter: config.Adapter, + handler: config.Handler, + metaAdapter: config.MetaAdapter, + locker: config.Locker, + realizations: realizations, + costbasisResolver: costbasisResolver, } svc.creditNotesSupported.Store(charges.CreditNotesSupportedByLineUpdater) @@ -88,6 +103,8 @@ type service struct { locker *lockr.Locker realizations *flatfeerealizations.Service creditNotesSupported atomic.Bool + enableCustomCurrency atomic.Bool + costbasisResolver costbasis.Resolver } func (s *service) GetLineEngine() billing.LineEngine { @@ -108,3 +125,13 @@ func (s *service) SetCreditNotesSupportedByLineUpdater(t *testing.T, supported b s.creditNotesSupported.Store(supported) return nil } + +func (s *service) SetEnableCustomCurrency(t *testing.T, enabled bool) error { + if t == nil { + return errors.New("testing is nil") + } + + t.Helper() + s.enableCustomCurrency.Store(enabled) + return nil +} diff --git a/openmeter/billing/charges/models/costbasis/costbasis.go b/openmeter/billing/charges/models/costbasis/costbasis.go new file mode 100644 index 0000000000..614319ccfa --- /dev/null +++ b/openmeter/billing/charges/models/costbasis/costbasis.go @@ -0,0 +1,13 @@ +package costbasis + +import "github.com/openmeterio/openmeter/pkg/models" + +type CostBasis struct { + models.NamespacedID + models.ManagedModel + + CurrencyID string `json:"currencyID"` + + Intent Intent `json:"intent"` + State *State `json:"state,omitempty"` +} diff --git a/openmeter/billing/charges/models/costbasis/intent.go b/openmeter/billing/charges/models/costbasis/intent.go new file mode 100644 index 0000000000..0bcd9100fb --- /dev/null +++ b/openmeter/billing/charges/models/costbasis/intent.go @@ -0,0 +1,183 @@ +package costbasis + +import ( + "errors" + "fmt" + "slices" + + "github.com/alpacahq/alpacadecimal" + + "github.com/openmeterio/openmeter/pkg/currencyx" + "github.com/openmeterio/openmeter/pkg/models" +) + +type Mode string + +const ( + ModeDynamic Mode = "dynamic" + ModePinned Mode = "pinned" + ModeManual Mode = "manual" +) + +func (Mode) Values() []string { + return []string{ + string(ModeDynamic), + string(ModePinned), + string(ModeManual), + } +} + +func (m Mode) Validate() error { + if !slices.Contains(m.Values(), string(m)) { + return models.NewGenericValidationError(fmt.Errorf("invalid cost basis mode: %s", m)) + } + + return nil +} + +type Intent struct { + kind Mode + + dynamic *DynamicIntent + pinned *PinnedIntent + manual *ManualIntent +} + +func NewIntent[T DynamicIntent | PinnedIntent | ManualIntent](in T) Intent { + switch v := any(in).(type) { + case DynamicIntent: + return Intent{kind: ModeDynamic, dynamic: &v} + case PinnedIntent: + return Intent{kind: ModePinned, pinned: &v} + case ManualIntent: + return Intent{kind: ModeManual, manual: &v} + } + + return Intent{} +} + +func (i Intent) Kind() Mode { + return i.kind +} + +func (i Intent) Clone() Intent { + out := i + + if i.dynamic != nil { + dynamic := *i.dynamic + out.dynamic = &dynamic + } + + if i.pinned != nil { + pinned := *i.pinned + out.pinned = &pinned + } + + if i.manual != nil { + manual := *i.manual + out.manual = &manual + } + + return out +} + +func (i Intent) Validate() error { + switch i.kind { + case ModeDynamic: + return i.dynamic.Validate() + case ModePinned: + return i.pinned.Validate() + case ModeManual: + return i.manual.Validate() + default: + return models.NewGenericValidationError(fmt.Errorf("invalid intent kind: %s", i.kind)) + } +} + +func (i Intent) AsPinned() (PinnedIntent, error) { + if i.kind != ModePinned { + return PinnedIntent{}, models.NewGenericValidationError(fmt.Errorf("intent is not a pinned intent")) + } + + if i.pinned == nil { + return PinnedIntent{}, models.NewGenericValidationError(fmt.Errorf("pinned intent is nil")) + } + + return *i.pinned, nil +} + +func (i Intent) AsManual() (ManualIntent, error) { + if i.kind != ModeManual { + return ManualIntent{}, models.NewGenericValidationError(fmt.Errorf("intent is not a manual intent")) + } + + if i.manual == nil { + return ManualIntent{}, models.NewGenericValidationError(fmt.Errorf("manual intent is nil")) + } + + return *i.manual, nil +} + +func (i Intent) AsDynamic() (DynamicIntent, error) { + if i.kind != ModeDynamic { + return DynamicIntent{}, models.NewGenericValidationError(fmt.Errorf("intent is not a dynamic intent")) + } + + if i.dynamic == nil { + return DynamicIntent{}, models.NewGenericValidationError(fmt.Errorf("dynamic intent is nil")) + } + + return *i.dynamic, nil +} + +type DynamicIntent struct { + FiatCurrency *currencyx.FiatCurrency +} + +func (i DynamicIntent) Validate() error { + var errs []error + + if err := i.FiatCurrency.Validate(); err != nil { + errs = append(errs, fmt.Errorf("fiat currency: %w", err)) + } + + return models.NewNillableGenericValidationError(errors.Join(errs...)) +} + +type PinnedIntent struct { + FiatCurrency *currencyx.FiatCurrency + CurrencyCostBasisID string +} + +func (i PinnedIntent) Validate() error { + var errs []error + + if err := i.FiatCurrency.Validate(); err != nil { + errs = append(errs, fmt.Errorf("fiat currency: %w", err)) + } + + if i.CurrencyCostBasisID == "" { + errs = append(errs, fmt.Errorf("currency cost basis id is required")) + } + + return models.NewNillableGenericValidationError(errors.Join(errs...)) +} + +type ManualIntent struct { + FiatCurrency *currencyx.FiatCurrency + Rate alpacadecimal.Decimal +} + +func (i ManualIntent) Validate() error { + var errs []error + + if err := i.FiatCurrency.Validate(); err != nil { + errs = append(errs, fmt.Errorf("fiat currency: %w", err)) + } + + if !i.Rate.IsPositive() { + errs = append(errs, fmt.Errorf("rate must be positive")) + } + + return models.NewNillableGenericValidationError(errors.Join(errs...)) +} diff --git a/openmeter/billing/charges/models/costbasis/intent_test.go b/openmeter/billing/charges/models/costbasis/intent_test.go new file mode 100644 index 0000000000..6687fdf286 --- /dev/null +++ b/openmeter/billing/charges/models/costbasis/intent_test.go @@ -0,0 +1,51 @@ +package costbasis + +import ( + "testing" + + "github.com/alpacahq/alpacadecimal" + "github.com/stretchr/testify/require" + + "github.com/openmeterio/openmeter/pkg/currencyx" +) + +func TestIntentClone(t *testing.T) { + usd, err := currencyx.NewFiatCurrency("USD") + require.NoError(t, err) + + eur, err := currencyx.NewFiatCurrency("EUR") + require.NoError(t, err) + + t.Run("dynamic", func(t *testing.T) { + original := NewIntent(DynamicIntent{FiatCurrency: usd}) + cloned := original.Clone() + + require.NotSame(t, original.dynamic, cloned.dynamic) + cloned.dynamic.FiatCurrency = eur + require.Same(t, usd, original.dynamic.FiatCurrency) + }) + + t.Run("pinned", func(t *testing.T) { + original := NewIntent(PinnedIntent{ + FiatCurrency: usd, + CurrencyCostBasisID: "cost-basis-1", + }) + cloned := original.Clone() + + require.NotSame(t, original.pinned, cloned.pinned) + cloned.pinned.CurrencyCostBasisID = "cost-basis-2" + require.Equal(t, "cost-basis-1", original.pinned.CurrencyCostBasisID) + }) + + t.Run("manual", func(t *testing.T) { + original := NewIntent(ManualIntent{ + FiatCurrency: usd, + Rate: alpacadecimal.NewFromInt(2), + }) + cloned := original.Clone() + + require.NotSame(t, original.manual, cloned.manual) + cloned.manual.Rate = alpacadecimal.NewFromInt(3) + require.Equal(t, float64(2), original.manual.Rate.InexactFloat64()) + }) +} diff --git a/openmeter/billing/charges/models/costbasis/model.go b/openmeter/billing/charges/models/costbasis/model.go new file mode 100644 index 0000000000..fae6c7056d --- /dev/null +++ b/openmeter/billing/charges/models/costbasis/model.go @@ -0,0 +1,299 @@ +package costbasis + +import ( + "errors" + "fmt" + "time" + + "github.com/alpacahq/alpacadecimal" + + "github.com/openmeterio/openmeter/pkg/clock" + "github.com/openmeterio/openmeter/pkg/currencyx" + "github.com/openmeterio/openmeter/pkg/framework/entutils" + "github.com/openmeterio/openmeter/pkg/models" +) + +type CreateInput struct { + models.NamespacedID + + CurrencyID string + Intent Intent + State *State +} + +func (i CreateInput) Validate() error { + var errs []error + + if err := i.NamespacedID.Validate(); err != nil { + errs = append(errs, err) + } + + if i.CurrencyID == "" { + errs = append(errs, errors.New("currency ID is required")) + } + + if err := i.Intent.Validate(); err != nil { + errs = append(errs, fmt.Errorf("intent: %w", err)) + } + + if i.State != nil { + if err := i.State.Validate(); err != nil { + errs = append(errs, fmt.Errorf("state: %w", err)) + } + } + + switch i.Intent.Kind() { + case ModeDynamic: + if i.State != nil && i.State.CostBasisID == nil { + errs = append(errs, errors.New("resolved dynamic cost basis must reference a currency cost basis")) + } + case ModePinned: + intent, err := i.Intent.AsPinned() + if err != nil { + errs = append(errs, err) + } else if i.State == nil { + errs = append(errs, errors.New("pinned cost basis state is required")) + } else if i.State.CostBasisID == nil || *i.State.CostBasisID != intent.CurrencyCostBasisID { + errs = append(errs, errors.New("pinned cost basis state must reference the intent cost basis")) + } + case ModeManual: + intent, err := i.Intent.AsManual() + if err != nil { + errs = append(errs, err) + } else if i.State != nil { + if i.State.CostBasisID != nil { + errs = append(errs, errors.New("manual cost basis state cannot reference a currency cost basis")) + } + + if !i.State.CostBasis.Equal(intent.Rate) { + errs = append(errs, errors.New("manual cost basis state must match the intent rate")) + } + } + } + + return models.NewNillableGenericValidationError(errors.Join(errs...)) +} + +type SetResolvedCostBasisInput struct { + models.NamespacedID + State State +} + +func (i SetResolvedCostBasisInput) Validate() error { + var errs []error + + if err := i.NamespacedID.Validate(); err != nil { + errs = append(errs, err) + } + + if err := i.State.Validate(); err != nil { + errs = append(errs, fmt.Errorf("state: %w", err)) + } + + if i.State.CostBasisID == nil { + errs = append(errs, errors.New("resolved currency cost basis ID is required")) + } + + return models.NewNillableGenericValidationError(errors.Join(errs...)) +} + +type Setter[T any] interface { + SetNillableResolvedCostBasisID(resolvedCostBasisID *string) T + SetResolvedCostBasis(resolvedCostBasis alpacadecimal.Decimal) T + SetResolvedAt(resolvedAt time.Time) T +} + +func Set[T Setter[T]](setter T, state State) (T, error) { + if err := state.Validate(); err != nil { + var empty T + return empty, err + } + + return setter. + SetNillableResolvedCostBasisID(state.CostBasisID). + SetResolvedCostBasis(state.CostBasis). + SetResolvedAt(state.ResolvedAt.UTC()), nil +} + +type Creator[T any] interface { + entutils.NamespaceMixinCreator[T] + entutils.IDMixinCreator[T] + Setter[T] + + SetMode(mode Mode) T + SetFiatCurrency(fiatCurrency currencyx.FiatCode) T + SetCurrencyCostBasisID(currencyCostBasisID string) T + SetCurrencyID(currencyID string) T + SetManualRate(manualRate alpacadecimal.Decimal) T +} + +func Create[T Creator[T]](creator T, input CreateInput) (T, error) { + if err := input.Validate(); err != nil { + var empty T + return empty, err + } + + creator = creator. + SetID(input.ID). + SetNamespace(input.Namespace). + SetMode(input.Intent.Kind()). + SetCurrencyID(input.CurrencyID) + state := input.State + + switch input.Intent.Kind() { + case ModeDynamic: + intent, err := input.Intent.AsDynamic() + if err != nil { + var empty T + return empty, err + } + + creator = creator.SetFiatCurrency(intent.FiatCurrency.GetFiatCode()) + case ModePinned: + intent, err := input.Intent.AsPinned() + if err != nil { + var empty T + return empty, err + } + + creator = creator. + SetFiatCurrency(intent.FiatCurrency.GetFiatCode()). + SetCurrencyCostBasisID(intent.CurrencyCostBasisID) + case ModeManual: + intent, err := input.Intent.AsManual() + if err != nil { + var empty T + return empty, err + } + + creator = creator. + SetFiatCurrency(intent.FiatCurrency.GetFiatCode()). + SetManualRate(intent.Rate) + + if state == nil { + state = &State{ + CostBasis: intent.Rate, + ResolvedAt: clock.Now().UTC(), + } + } + } + + if state != nil { + return Set(creator, *state) + } + + return creator, nil +} + +type Getter interface { + entutils.NamespaceMixinGetter + entutils.IDMixinGetter + entutils.TimeMixinGetter + + GetMode() Mode + GetFiatCurrency() currencyx.FiatCode + GetCurrencyCostBasisID() *string + GetResolvedCostBasisID() *string + GetCurrencyID() string + GetManualRate() *alpacadecimal.Decimal + GetResolvedCostBasis() *alpacadecimal.Decimal + GetResolvedAt() *time.Time +} + +func Get(dbEntity Getter) (CostBasis, error) { + intent, err := getIntent(dbEntity) + if err != nil { + return CostBasis{}, err + } + + state, err := getState(dbEntity) + if err != nil { + return CostBasis{}, err + } + + costBasis := CostBasis{ + NamespacedID: models.NamespacedID{ + Namespace: dbEntity.GetNamespace(), + ID: dbEntity.GetID(), + }, + ManagedModel: entutils.MapTimeMixinFromDB(dbEntity), + CurrencyID: dbEntity.GetCurrencyID(), + Intent: intent, + State: state, + } + + if err := (CreateInput{ + NamespacedID: costBasis.NamespacedID, + CurrencyID: costBasis.CurrencyID, + Intent: costBasis.Intent, + State: costBasis.State, + }).Validate(); err != nil { + return CostBasis{}, fmt.Errorf("validate persisted cost basis: %w", err) + } + + return costBasis, nil +} + +func getIntent(dbEntity Getter) (Intent, error) { + fiatCurrency, err := currencyx.NewFiatCurrency(dbEntity.GetFiatCurrency()) + if err != nil { + return Intent{}, fmt.Errorf("map fiat currency: %w", err) + } + + switch dbEntity.GetMode() { + case ModeDynamic: + return NewIntent(DynamicIntent{FiatCurrency: fiatCurrency}), nil + case ModePinned: + currencyCostBasisID := dbEntity.GetCurrencyCostBasisID() + if currencyCostBasisID == nil { + return Intent{}, errors.New("currency cost basis ID is required") + } + + return NewIntent(PinnedIntent{ + FiatCurrency: fiatCurrency, + CurrencyCostBasisID: *currencyCostBasisID, + }), nil + case ModeManual: + manualRate := dbEntity.GetManualRate() + if manualRate == nil { + return Intent{}, errors.New("manual rate is required") + } + + return NewIntent(ManualIntent{ + FiatCurrency: fiatCurrency, + Rate: *manualRate, + }), nil + default: + return Intent{}, fmt.Errorf("invalid cost basis mode: %s", dbEntity.GetMode()) + } +} + +func getState(dbEntity Getter) (*State, error) { + resolvedAt := dbEntity.GetResolvedAt() + resolvedCostBasis := dbEntity.GetResolvedCostBasis() + resolvedCostBasisID := dbEntity.GetResolvedCostBasisID() + + if resolvedAt == nil && resolvedCostBasis == nil && resolvedCostBasisID == nil { + return nil, nil + } + + if resolvedAt == nil { + return nil, errors.New("resolved at is required") + } + + if resolvedCostBasis == nil { + return nil, errors.New("resolved cost basis is required") + } + + state := State{ + CostBasis: *resolvedCostBasis, + CostBasisID: resolvedCostBasisID, + ResolvedAt: resolvedAt.UTC(), + } + + if err := state.Validate(); err != nil { + return nil, err + } + + return &state, nil +} diff --git a/openmeter/billing/charges/models/costbasis/resolver.go b/openmeter/billing/charges/models/costbasis/resolver.go new file mode 100644 index 0000000000..c6ec4725f8 --- /dev/null +++ b/openmeter/billing/charges/models/costbasis/resolver.go @@ -0,0 +1,176 @@ +package costbasis + +import ( + "context" + "errors" + "fmt" + "time" + + "github.com/samber/lo" + + "github.com/openmeterio/openmeter/openmeter/currencies" + "github.com/openmeterio/openmeter/pkg/models" +) + +type Resolver interface { + // ResolveInitialState resolves the initial state of the cost basis for a given intent, + // dynamic costbasis is resolved once we hit current service period's start so we are not + // doing the resolution during creation. + ResolveInitialState(ctx context.Context, input ResolveInitialStateInput) (*State, error) + + // ResolveDynamicState resolves the dynamic state of the cost basis for a given intent, + // dynamic costbasis is resolved once we hit current service period's start so we are not + // doing the resolution during creation. + ResolveDynamicState(ctx context.Context, input ResolveDynamicStateInput) (State, error) +} + +type ResolveInitialStateInput struct { + CurrencyID models.NamespacedID + Intent Intent + ResolvedAt time.Time +} + +func (i ResolveInitialStateInput) Validate() error { + var errs []error + + if err := i.CurrencyID.Validate(); err != nil { + errs = append(errs, fmt.Errorf("currency: %w", err)) + } + + if err := i.Intent.Validate(); err != nil { + errs = append(errs, fmt.Errorf("intent: %w", err)) + } + + if i.ResolvedAt.IsZero() { + errs = append(errs, errors.New("resolved at is required")) + } + + return models.NewNillableGenericValidationError(errors.Join(errs...)) +} + +type ResolveDynamicStateInput struct { + CurrencyID models.NamespacedID + Intent Intent + + ServicePeriodFrom time.Time +} + +func (i ResolveDynamicStateInput) Validate() error { + var errs []error + + if err := i.CurrencyID.Validate(); err != nil { + errs = append(errs, fmt.Errorf("currency: %w", err)) + } + + if err := i.Intent.Validate(); err != nil { + errs = append(errs, fmt.Errorf("intent: %w", err)) + } else if i.Intent.Kind() != ModeDynamic { + errs = append(errs, errors.New("intent is not a dynamic intent")) + } + + if i.ServicePeriodFrom.IsZero() { + errs = append(errs, errors.New("service period from is required")) + } + + return models.NewNillableGenericValidationError(errors.Join(errs...)) +} + +type resolver struct { + currencies currencies.Service +} + +var _ Resolver = (*resolver)(nil) + +type ResolverConfig struct { + Currencies currencies.Service +} + +func (c ResolverConfig) Validate() error { + if c.Currencies == nil { + return errors.New("currencies is required") + } + + return nil +} + +func NewResolver(config ResolverConfig) (Resolver, error) { + if err := config.Validate(); err != nil { + return nil, err + } + + return &resolver{ + currencies: config.Currencies, + }, nil +} + +func (r *resolver) ResolveInitialState(ctx context.Context, input ResolveInitialStateInput) (*State, error) { + if err := input.Validate(); err != nil { + return nil, err + } + + switch input.Intent.kind { + case ModeDynamic: + return nil, nil + case ModePinned: + return r.resolvePinnedState(ctx, input.CurrencyID, input.Intent, input.ResolvedAt) + case ModeManual: + return r.resolveManualState(ctx, input.Intent, input.ResolvedAt) + default: + return nil, errors.New("invalid intent kind") + } +} + +func (r *resolver) ResolveDynamicState(ctx context.Context, input ResolveDynamicStateInput) (State, error) { + if err := input.Validate(); err != nil { + return State{}, err + } + + effectiveCostBasis, err := r.currencies.GetCostBasisAt(ctx, currencies.GetCostBasisAtInput{ + Namespace: input.CurrencyID.Namespace, + CurrencyID: input.CurrencyID.ID, + FiatCode: input.Intent.dynamic.FiatCurrency.Details().Code, + At: input.ServicePeriodFrom, + }) + if err != nil { + return State{}, err + } + + return State{ + CostBasis: effectiveCostBasis.Rate, + CostBasisID: lo.ToPtr(effectiveCostBasis.ID), + ResolvedAt: input.ServicePeriodFrom.UTC(), + }, nil +} + +func (r *resolver) resolveManualState(_ context.Context, intent Intent, at time.Time) (*State, error) { + return &State{ + CostBasis: intent.manual.Rate, + ResolvedAt: at, + }, nil +} + +func (r *resolver) resolvePinnedState(ctx context.Context, currencyID models.NamespacedID, intent Intent, at time.Time) (*State, error) { + currencyCostBasis, err := r.currencies.GetCostBasis(ctx, currencies.GetCostBasisInput{ + NamespacedID: models.NamespacedID{ + Namespace: currencyID.Namespace, + ID: intent.pinned.CurrencyCostBasisID, + }, + }) + if err != nil { + return nil, err + } + + if currencyCostBasis.CurrencyID != currencyID.ID { + return nil, fmt.Errorf("currency cost basis currency mismatch: %s != %s", currencyCostBasis.CurrencyID, currencyID.ID) + } + + if currencyCostBasis.FiatCode != intent.pinned.FiatCurrency.Details().Code { + return nil, fmt.Errorf("currency cost basis fiat currency mismatch: %s != %s", currencyCostBasis.FiatCode, intent.pinned.FiatCurrency.Details().Code) + } + + return &State{ + CostBasis: currencyCostBasis.Rate, + CostBasisID: lo.ToPtr(currencyCostBasis.ID), + ResolvedAt: at, + }, nil +} diff --git a/openmeter/billing/charges/models/costbasis/state.go b/openmeter/billing/charges/models/costbasis/state.go new file mode 100644 index 0000000000..ecc61ad8b7 --- /dev/null +++ b/openmeter/billing/charges/models/costbasis/state.go @@ -0,0 +1,39 @@ +package costbasis + +import ( + "errors" + "fmt" + "time" + + "github.com/alpacahq/alpacadecimal" + + "github.com/openmeterio/openmeter/pkg/models" +) + +type State struct { + CostBasis alpacadecimal.Decimal + CostBasisID *string + ResolvedAt time.Time +} + +func (s State) String() string { + return fmt.Sprintf("cost_basis=%s cost_basis_id=%v resolved_at=%s", s.CostBasis, s.CostBasisID, s.ResolvedAt.UTC().Format(time.RFC3339)) +} + +func (s State) Validate() error { + var errs []error + + if !s.CostBasis.IsPositive() { + errs = append(errs, fmt.Errorf("cost basis must be positive")) + } + + if s.ResolvedAt.IsZero() { + errs = append(errs, fmt.Errorf("resolved at is required")) + } + + if s.CostBasisID != nil && *s.CostBasisID == "" { + errs = append(errs, fmt.Errorf("cost basis id is required")) + } + + return models.NewNillableGenericValidationError(errors.Join(errs...)) +} diff --git a/openmeter/billing/charges/service/base_test.go b/openmeter/billing/charges/service/base_test.go index 5855ee0e04..bccdefb9f5 100644 --- a/openmeter/billing/charges/service/base_test.go +++ b/openmeter/billing/charges/service/base_test.go @@ -85,6 +85,14 @@ func (s *BaseSuite) SetupSuite() { s.NoError(err) s.MetaAdapter = metaAdapter + currencyAdapter, err := currencyadapter.New(currencyadapter.Config{ + Client: s.DBClient, + }) + s.NoError(err) + currencyService, err := currencyservice.New(currencyAdapter) + s.NoError(err) + s.CurrencyService = currencyService + locker, err := lockr.NewLocker(&lockr.LockerConfig{ Logger: slog.Default(), }) @@ -117,6 +125,7 @@ func (s *BaseSuite) SetupSuite() { MetaAdapter: metaAdapter, Locker: locker, RatingService: billingratingservice.New(billingratingservice.Config{UnitConfigEnabled: s.UnitConfigEnabled}), + Currencies: currencyService, }) s.NoError(err) @@ -148,6 +157,7 @@ func (s *BaseSuite) SetupSuite() { CustomerOverrideService: s.BillingService, FeatureService: s.FeatureService, RatingService: billingratingservice.New(billingratingservice.Config{UnitConfigEnabled: s.UnitConfigEnabled}), + Currencies: currencyService, StreamingConnector: s.MockStreamingConnector, }) s.NoError(err) @@ -196,13 +206,6 @@ func (s *BaseSuite) SetupSuite() { }) s.NoError(err) - currencyAdapter, err := currencyadapter.New(currencyadapter.Config{ - Client: s.DBClient, - }) - s.NoError(err) - currencyService, err := currencyservice.New(currencyAdapter) - s.NoError(err) - s.CurrencyService = currencyService currencyResolver, err := currencyresolver.New(currencyService) s.NoError(err) diff --git a/openmeter/billing/charges/service/flatfee_costbasis_test.go b/openmeter/billing/charges/service/flatfee_costbasis_test.go new file mode 100644 index 0000000000..3e82186d4c --- /dev/null +++ b/openmeter/billing/charges/service/flatfee_costbasis_test.go @@ -0,0 +1,548 @@ +package service + +import ( + "testing" + "time" + + "github.com/alpacahq/alpacadecimal" + "github.com/samber/lo" + "github.com/stretchr/testify/suite" + + "github.com/openmeterio/openmeter/openmeter/billing" + "github.com/openmeterio/openmeter/openmeter/billing/charges/flatfee" + "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/currencies" + dbchargeflatfeecostbasis "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeecostbasis" + "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/openmeter/productcatalog/feature" + "github.com/openmeterio/openmeter/pkg/clock" + "github.com/openmeterio/openmeter/pkg/currencyx" + "github.com/openmeterio/openmeter/pkg/models" + "github.com/openmeterio/openmeter/pkg/timeutil" +) + +func TestFlatFeeCostBasisCreate(t *testing.T) { + suite.Run(t, new(FlatFeeCostBasisCreateSuite)) +} + +type FlatFeeCostBasisCreateSuite struct { + BaseSuite +} + +type customCurrencyEnabler interface { + SetEnableCustomCurrency(t *testing.T, enabled bool) error +} + +func (s *FlatFeeCostBasisCreateSuite) SetupSuite() { + s.BaseSuite.SetupSuite() +} + +func (s *FlatFeeCostBasisCreateSuite) TearDownTest() { + s.setCustomCurrencyEnabled(false) + s.BaseSuite.TearDownTest() +} + +func (s *FlatFeeCostBasisCreateSuite) TestCustomCurrencyCreditThenInvoiceIsDisabledByDefault() { + // given: + // - a valid manual cost-basis intent for a custom-currency flat fee + // - the test-only custom-currency switch left at its default value + // when: + // - the charge is created + // then: + // - creation is rejected before any charge cost basis is persisted + ctx := s.T().Context() + namespace := s.GetUniqueNamespace("flat-fee-cost-basis-disabled") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "flat-fee-cost-basis-disabled") + currency := s.createTestCustomCurrency(ctx, namespace) + fiatCurrency := s.newFiatCurrency("USD") + intent := costbasis.NewIntent(costbasis.ManualIntent{ + FiatCurrency: fiatCurrency, + Rate: alpacadecimal.NewFromInt(2), + }) + + _, err := s.Charges.flatFeeService.Create(ctx, flatfee.CreateInput{ + Namespace: namespace, + Intents: []flatfee.Intent{ + s.newFlatFeeIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "disabled", productcatalog.CreditThenInvoiceSettlementMode, &intent), + }, + FeatureMeters: feature.FeatureMeterCollection{}, + }) + s.Require().ErrorIs(err, meta.ErrCustomCurrencyNotSupported) + s.Require().Equal(0, s.countCostBases(namespace)) +} + +func (s *FlatFeeCostBasisCreateSuite) TestCreatePersistsManualPinnedAndDynamicCostBasesInInputOrder() { + // given: + // - manual, pinned, and dynamic cost-basis intents in one custom-currency batch + // when: + // - custom-currency creation is enabled, the flat fees are created, and each is reloaded through the charge service + // then: + // - each charge references its own persisted cost basis and its intent and resolved state survive the normal read path + ctx := s.T().Context() + now := time.Date(2026, time.January, 15, 12, 0, 0, 0, time.UTC) + clock.FreezeTime(now) + defer clock.UnFreeze() + + namespace := s.GetUniqueNamespace("flat-fee-cost-basis-modes") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "flat-fee-cost-basis-modes") + currency := s.createTestCustomCurrency(ctx, namespace) + fiatCurrency := s.newFiatCurrency("USD") + pinnedCostBasis, err := s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: currencyx.Code("USD"), + Rate: alpacadecimal.NewFromFloat(0.25), + }) + s.Require().NoError(err) + + manualIntent := costbasis.NewIntent(costbasis.ManualIntent{ + FiatCurrency: fiatCurrency, + Rate: alpacadecimal.NewFromFloat(0.5), + }) + pinnedIntent := costbasis.NewIntent(costbasis.PinnedIntent{ + FiatCurrency: fiatCurrency, + CurrencyCostBasisID: pinnedCostBasis.ID, + }) + dynamicIntent := costbasis.NewIntent(costbasis.DynamicIntent{ + FiatCurrency: fiatCurrency, + }) + + s.setCustomCurrencyEnabled(true) + created, err := s.Charges.flatFeeService.Create(ctx, flatfee.CreateInput{ + Namespace: namespace, + Intents: []flatfee.Intent{ + s.newFlatFeeIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "manual", productcatalog.CreditThenInvoiceSettlementMode, &manualIntent), + s.newFlatFeeIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "pinned", productcatalog.CreditThenInvoiceSettlementMode, &pinnedIntent), + s.newFlatFeeIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "dynamic", productcatalog.CreditThenInvoiceSettlementMode, &dynamicIntent), + }, + FeatureMeters: feature.FeatureMeterCollection{}, + }) + s.Require().NoError(err) + s.Require().Len(created, 3) + + s.Require().Equal(costbasis.ModeManual, created[0].Charge.Intent.GetCostBasisIntent().Kind()) + s.Require().NotNil(created[0].Charge.State.ResolvedCostBasis) + s.Require().Equal(float64(0.5), created[0].Charge.State.ResolvedCostBasis.CostBasis.InexactFloat64()) + s.Require().Nil(created[0].Charge.State.ResolvedCostBasis.CostBasisID) + s.Require().Equal(now, created[0].Charge.State.ResolvedCostBasis.ResolvedAt) + + s.Require().Equal(costbasis.ModePinned, created[1].Charge.Intent.GetCostBasisIntent().Kind()) + s.Require().NotNil(created[1].Charge.State.ResolvedCostBasis) + s.Require().Equal(float64(0.25), created[1].Charge.State.ResolvedCostBasis.CostBasis.InexactFloat64()) + s.Require().Equal(pinnedCostBasis.ID, *created[1].Charge.State.ResolvedCostBasis.CostBasisID) + s.Require().Equal(now, created[1].Charge.State.ResolvedCostBasis.ResolvedAt) + + s.Require().Equal(costbasis.ModeDynamic, created[2].Charge.Intent.GetCostBasisIntent().Kind()) + s.Require().Nil(created[2].Charge.State.ResolvedCostBasis) + + seenCostBasisIDs := map[string]struct{}{} + for idx, result := range created { + s.Require().NotNil(result.Charge.State.CostBasisID, "charge index %d", idx) + + reloaded, err := s.mustGetChargeByID(result.Charge.GetChargeID()).AsFlatFeeCharge() + s.Require().NoError(err) + s.Require().Equal(result.Charge.Intent.GetCostBasisIntent().Kind(), reloaded.Intent.GetCostBasisIntent().Kind(), "charge index %d", idx) + s.Require().Equal(result.Charge.State.CostBasisID, reloaded.State.CostBasisID, "charge index %d", idx) + s.Require().Equal(result.Charge.State.ResolvedCostBasis, reloaded.State.ResolvedCostBasis, "charge index %d", idx) + + chargeEntity, err := s.DBClient.ChargeFlatFee.Get(ctx, result.Charge.ID) + s.Require().NoError(err) + s.Require().NotNil(chargeEntity.CostBasisID) + s.Require().Equal(*result.Charge.State.CostBasisID, *chargeEntity.CostBasisID) + seenCostBasisIDs[*chargeEntity.CostBasisID] = struct{}{} + + costBasisEntity, err := s.DBClient.ChargeFlatFeeCostBasis.Get(ctx, *chargeEntity.CostBasisID) + s.Require().NoError(err) + persisted, err := costbasis.Get(costBasisEntity) + s.Require().NoError(err) + s.Require().Equal(result.Charge.Intent.GetCostBasisIntent().Kind(), persisted.Intent.Kind(), "charge index %d", idx) + s.Require().Equal(result.Charge.State.ResolvedCostBasis, persisted.State, "charge index %d", idx) + } + s.Require().Len(seenCostBasisIDs, 3) +} + +func (s *FlatFeeCostBasisCreateSuite) TestSetResolvedDynamicCostBasisIsRetrySafe() { + // given: + // - an unresolved dynamic cost basis attached to a flat-fee charge + // - a first persisted resolution + // when: + // - a stale retry attempts to persist a different resolution + // then: + // - the original persisted resolution is returned and remains unchanged + ctx := s.T().Context() + now := time.Date(2026, time.January, 15, 12, 0, 0, 0, time.UTC) + clock.FreezeTime(now) + defer clock.UnFreeze() + + namespace := s.GetUniqueNamespace("flat-fee-cost-basis-retry") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "flat-fee-cost-basis-retry") + currency := s.createTestCustomCurrency(ctx, namespace) + currencyCostBasis, err := s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: currencyx.Code("USD"), + Rate: alpacadecimal.NewFromFloat(0.25), + }) + s.Require().NoError(err) + + dynamicIntent := costbasis.NewIntent(costbasis.DynamicIntent{ + FiatCurrency: s.newFiatCurrency("USD"), + }) + s.setCustomCurrencyEnabled(true) + created, err := s.Charges.flatFeeService.Create(ctx, flatfee.CreateInput{ + Namespace: namespace, + Intents: []flatfee.Intent{ + s.newFlatFeeIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "dynamic-retry", productcatalog.CreditThenInvoiceSettlementMode, &dynamicIntent), + }, + FeatureMeters: feature.FeatureMeterCollection{}, + }) + s.Require().NoError(err) + s.Require().Len(created, 1) + s.Require().NotNil(created[0].Charge.State.CostBasisID) + + firstState := costbasis.State{ + CostBasis: currencyCostBasis.Rate, + CostBasisID: lo.ToPtr(currencyCostBasis.ID), + ResolvedAt: now, + } + first, err := s.FlatFeeAdapter.SetResolvedCostBasis(ctx, costbasis.SetResolvedCostBasisInput{ + NamespacedID: models.NamespacedID{ + Namespace: namespace, + ID: *created[0].Charge.State.CostBasisID, + }, + State: firstState, + }) + s.Require().NoError(err) + s.Require().Equal(&firstState, first.State) + + retryState := costbasis.State{ + CostBasis: alpacadecimal.NewFromInt(9), + CostBasisID: lo.ToPtr(currencyCostBasis.ID), + ResolvedAt: now.Add(time.Hour), + } + retried, err := s.FlatFeeAdapter.SetResolvedCostBasis(ctx, costbasis.SetResolvedCostBasisInput{ + NamespacedID: first.NamespacedID, + State: retryState, + }) + s.Require().NoError(err) + s.Require().Equal(&firstState, retried.State) + + reloaded, err := s.mustGetChargeByID(created[0].Charge.GetChargeID()).AsFlatFeeCharge() + s.Require().NoError(err) + s.Require().Equal(created[0].Charge.State.CostBasisID, reloaded.State.CostBasisID) + s.Require().Equal(&firstState, reloaded.State.ResolvedCostBasis) +} + +func (s *FlatFeeCostBasisCreateSuite) TestResolveDynamicCostBasisUsesServicePeriodFrom() { + // given: + // - two successive currency cost bases + // when: + // - dynamic resolution uses a service-period start in the first interval + // then: + // - the first value is selected and ResolvedAt equals the service-period start + ctx := s.T().Context() + firstEffectiveAt := time.Date(2026, time.January, 1, 0, 0, 0, 0, time.UTC) + secondEffectiveAt := firstEffectiveAt.Add(10 * 24 * time.Hour) + servicePeriodFrom := firstEffectiveAt.Add(5 * 24 * time.Hour) + clock.FreezeTime(firstEffectiveAt) + defer clock.UnFreeze() + + namespace := s.GetUniqueNamespace("flat-fee-cost-basis-resolution-times") + currency := s.createTestCustomCurrency(ctx, namespace) + first, err := s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: currencyx.Code("USD"), + Rate: alpacadecimal.NewFromFloat(0.25), + }) + s.Require().NoError(err) + _, err = s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: currencyx.Code("USD"), + Rate: alpacadecimal.NewFromFloat(0.5), + EffectiveFrom: lo.ToPtr(secondEffectiveAt), + }) + s.Require().NoError(err) + + resolver, err := costbasis.NewResolver(costbasis.ResolverConfig{Currencies: s.CurrencyService}) + s.Require().NoError(err) + resolved, err := resolver.ResolveDynamicState(ctx, costbasis.ResolveDynamicStateInput{ + CurrencyID: currency.NamespacedID, + Intent: costbasis.NewIntent(costbasis.DynamicIntent{ + FiatCurrency: s.newFiatCurrency("USD"), + }), + ServicePeriodFrom: servicePeriodFrom, + }) + s.Require().NoError(err) + s.Require().Equal(first.ID, *resolved.CostBasisID) + s.Require().Equal(first.Rate.InexactFloat64(), resolved.CostBasis.InexactFloat64()) + s.Require().Equal(servicePeriodFrom, resolved.ResolvedAt) +} + +func (s *FlatFeeCostBasisCreateSuite) TestDynamicCostBasisResolvesWhenChargeBecomesActive() { + // given: + // - an unresolved dynamic cost basis with two successive currency rates + // - activation delayed until after the second rate becomes effective + // when: + // - the charge advances from created to active + // then: + // - it persists the rate effective at service-period start and records that as ResolvedAt + ctx := s.T().Context() + servicePeriodFrom := time.Date(2026, time.January, 1, 0, 0, 0, 0, time.UTC) + secondEffectiveAt := servicePeriodFrom.Add(10 * 24 * time.Hour) + activationAt := secondEffectiveAt.Add(24 * time.Hour) + clock.FreezeTime(servicePeriodFrom) + defer clock.UnFreeze() + + namespace := s.GetUniqueNamespace("flat-fee-cost-basis-active") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "flat-fee-cost-basis-active") + currency := s.createTestCustomCurrency(ctx, namespace) + first, err := s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: currencyx.Code("USD"), + Rate: alpacadecimal.NewFromFloat(0.25), + }) + s.Require().NoError(err) + _, err = s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: currencyx.Code("USD"), + Rate: alpacadecimal.NewFromFloat(0.5), + EffectiveFrom: lo.ToPtr(secondEffectiveAt), + }) + s.Require().NoError(err) + + dynamicIntent := costbasis.NewIntent(costbasis.DynamicIntent{ + FiatCurrency: s.newFiatCurrency("USD"), + }) + s.setCustomCurrencyEnabled(true) + clock.FreezeTime(activationAt) + created, err := s.Charges.flatFeeService.Create(ctx, flatfee.CreateInput{ + Namespace: namespace, + Intents: []flatfee.Intent{ + s.newFlatFeeIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "dynamic-active", productcatalog.CreditThenInvoiceSettlementMode, &dynamicIntent), + }, + FeatureMeters: feature.FeatureMeterCollection{}, + }) + s.Require().NoError(err) + s.Require().Len(created, 1) + s.Require().Equal(flatfee.StatusCreated, created[0].Charge.Status) + s.Require().NotNil(created[0].Charge.State.CostBasisID) + s.Require().Nil(created[0].Charge.State.ResolvedCostBasis) + + advanced, err := s.Charges.flatFeeService.AdvanceCharge(ctx, flatfee.AdvanceChargeInput{ + ChargeID: created[0].Charge.GetChargeID(), + }) + s.Require().NoError(err) + s.Require().NotNil(advanced) + s.Require().Equal(flatfee.StatusActive, advanced.Status) + s.Require().Equal(created[0].Charge.State.CostBasisID, advanced.State.CostBasisID) + s.Require().NotNil(advanced.State.ResolvedCostBasis) + s.Require().Equal(first.ID, *advanced.State.ResolvedCostBasis.CostBasisID) + s.Require().Equal(first.Rate.InexactFloat64(), advanced.State.ResolvedCostBasis.CostBasis.InexactFloat64()) + s.Require().Equal(servicePeriodFrom, advanced.State.ResolvedCostBasis.ResolvedAt) + + reloaded, err := s.mustGetChargeByID(created[0].Charge.GetChargeID()).AsFlatFeeCharge() + s.Require().NoError(err) + s.Require().Equal(advanced.State.CostBasisID, reloaded.State.CostBasisID) + s.Require().Equal(advanced.State.ResolvedCostBasis, reloaded.State.ResolvedCostBasis) +} + +func (s *FlatFeeCostBasisCreateSuite) TestPinnedCostBasisMustMatchCurrencyAndFiatCurrency() { + ctx := s.T().Context() + namespace := s.GetUniqueNamespace("flat-fee-cost-basis-pinned-mismatch") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "flat-fee-cost-basis-pinned-mismatch") + currency := s.createTestCustomCurrency(ctx, namespace) + otherCurrency, err := s.CurrencyService.CreateCurrency(ctx, currencies.CreateCurrencyInput{ + Namespace: namespace, + CurrencyDetails: currencyx.CurrencyDetails{ + Code: "OTHER", + Name: "Other", + Symbol: "O", + Precision: 3, + DecimalMark: ".", + ThousandsSeparator: ",", + }, + }) + s.Require().NoError(err) + + otherCurrencyCostBasis, err := s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: otherCurrency.ID, + FiatCode: currencyx.Code("USD"), + Rate: alpacadecimal.NewFromInt(1), + }) + s.Require().NoError(err) + eurCostBasis, err := s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: currencyx.Code("EUR"), + Rate: alpacadecimal.NewFromInt(1), + }) + s.Require().NoError(err) + + tests := []struct { + name string + costBasisID string + errorText string + }{ + {name: "currency", costBasisID: otherCurrencyCostBasis.ID, errorText: "currency cost basis currency mismatch"}, + {name: "fiat currency", costBasisID: eurCostBasis.ID, errorText: "currency cost basis fiat currency mismatch"}, + } + + s.setCustomCurrencyEnabled(true) + for _, test := range tests { + s.Run(test.name, func() { + // given: + // - a pinned cost basis that disagrees with the charge currency or requested fiat currency + // when: + // - the flat fee is created + // then: + // - resolution rejects the mismatch before charge cost-basis persistence + intent := costbasis.NewIntent(costbasis.PinnedIntent{ + FiatCurrency: s.newFiatCurrency("USD"), + CurrencyCostBasisID: test.costBasisID, + }) + + _, err := s.Charges.flatFeeService.Create(ctx, flatfee.CreateInput{ + Namespace: namespace, + Intents: []flatfee.Intent{ + s.newFlatFeeIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "mismatch-"+test.name, productcatalog.CreditThenInvoiceSettlementMode, &intent), + }, + FeatureMeters: feature.FeatureMeterCollection{}, + }) + s.Require().ErrorContains(err, test.errorText) + }) + } + s.Require().Equal(0, s.countCostBases(namespace)) +} + +func (s *FlatFeeCostBasisCreateSuite) TestCreateRollsBackCostBasesWhenChargeCreationFails() { + // given: + // - two cost-basis-backed intents with the same charge unique reference + // when: + // - the charge constraint rejects the bulk create after cost bases were inserted + // then: + // - the surrounding transaction removes all newly inserted charge cost bases + ctx := s.T().Context() + namespace := s.GetUniqueNamespace("flat-fee-cost-basis-rollback") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "flat-fee-cost-basis-rollback") + currency := s.createTestCustomCurrency(ctx, namespace) + intent := costbasis.NewIntent(costbasis.ManualIntent{ + FiatCurrency: s.newFiatCurrency("USD"), + Rate: alpacadecimal.NewFromInt(2), + }) + + s.setCustomCurrencyEnabled(true) + _, err := s.Charges.flatFeeService.Create(ctx, flatfee.CreateInput{ + Namespace: namespace, + Intents: []flatfee.Intent{ + s.newFlatFeeIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "duplicate", productcatalog.CreditThenInvoiceSettlementMode, &intent), + s.newFlatFeeIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "duplicate", productcatalog.CreditThenInvoiceSettlementMode, &intent), + }, + FeatureMeters: feature.FeatureMeterCollection{}, + }) + s.Require().Error(err) + s.Require().Equal(0, s.countCostBases(namespace)) +} + +func (s *FlatFeeCostBasisCreateSuite) TestCreateWithoutCostBasisLeavesChargeReferenceEmpty() { + ctx := s.T().Context() + namespace := s.GetUniqueNamespace("flat-fee-without-cost-basis") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "flat-fee-without-cost-basis") + currency := s.createTestCustomCurrency(ctx, namespace) + + created, err := s.Charges.flatFeeService.Create(ctx, flatfee.CreateInput{ + Namespace: namespace, + Intents: []flatfee.Intent{ + s.newFlatFeeIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "credit-only", productcatalog.CreditOnlySettlementMode, nil), + }, + FeatureMeters: feature.FeatureMeterCollection{}, + }) + s.Require().NoError(err) + s.Require().Len(created, 1) + s.Require().Nil(created[0].Charge.Intent.GetCostBasisIntent()) + s.Require().Nil(created[0].Charge.State.CostBasisID) + s.Require().Nil(created[0].Charge.State.ResolvedCostBasis) + + chargeEntity, err := s.DBClient.ChargeFlatFee.Get(ctx, created[0].Charge.ID) + s.Require().NoError(err) + s.Require().Nil(chargeEntity.CostBasisID) + s.Require().Equal(0, s.countCostBases(namespace)) +} + +func (s *FlatFeeCostBasisCreateSuite) setCustomCurrencyEnabled(enabled bool) { + s.T().Helper() + enabler, ok := s.Charges.flatFeeService.(customCurrencyEnabler) + s.Require().True(ok) + s.Require().NoError(enabler.SetEnableCustomCurrency(s.T(), enabled)) +} + +func (s *FlatFeeCostBasisCreateSuite) countCostBases(namespace string) int { + s.T().Helper() + + count, err := s.DBClient.ChargeFlatFeeCostBasis.Query(). + Where(dbchargeflatfeecostbasis.Namespace(namespace)). + Count(s.T().Context()) + s.Require().NoError(err) + + return count +} + +func (s *FlatFeeCostBasisCreateSuite) newFiatCurrency(code currencyx.Code) *currencyx.FiatCurrency { + s.T().Helper() + + fiatCurrency, err := currencyx.NewFiatCurrency(code) + s.Require().NoError(err) + + return fiatCurrency +} + +func (s *FlatFeeCostBasisCreateSuite) newFlatFeeIntent( + customerID string, + currency currencies.Currency, + taxCodeID string, + uniqueReferenceID string, + settlementMode productcatalog.SettlementMode, + costBasis *costbasis.Intent, +) flatfee.Intent { + s.T().Helper() + + period := timeutil.ClosedPeriod{ + From: time.Date(2026, time.January, 1, 0, 0, 0, 0, time.UTC), + To: time.Date(2026, time.February, 1, 0, 0, 0, 0, time.UTC), + } + + return flatfee.Intent{ + Intent: meta.Intent{ + ManagedBy: billing.ManuallyManagedLine, + CustomerID: customerID, + Currency: currency, + TaxConfig: productcatalog.TaxCodeConfig{TaxCodeID: taxCodeID}, + UniqueReferenceID: lo.ToPtr(uniqueReferenceID), + }, + IntentMutableFields: flatfee.IntentMutableFields{ + IntentMutableFields: meta.IntentMutableFields{ + Name: uniqueReferenceID, + ServicePeriod: period, + FullServicePeriod: period, + BillingPeriod: period, + }, + InvoiceAt: period.From, + PaymentTerm: productcatalog.InAdvancePaymentTerm, + AmountBeforeProration: alpacadecimal.NewFromInt(10), + }, + SettlementMode: settlementMode, + CostBasis: costBasis, + } +} diff --git a/openmeter/billing/charges/service/invoicable_test.go b/openmeter/billing/charges/service/invoicable_test.go index 1560e330a9..dffeb4c9bd 100644 --- a/openmeter/billing/charges/service/invoicable_test.go +++ b/openmeter/billing/charges/service/invoicable_test.go @@ -3008,6 +3008,7 @@ func (s *InvoicableChargesTestSuite) TestFlatFeeCreditOnlyWithCustomCurrency() { MetaAdapter: s.MetaAdapter, Locker: s.Locker, RatingService: billingratingservice.New(billingratingservice.Config{UnitConfigEnabled: s.UnitConfigEnabled}), + Currencies: s.CurrencyService, }) s.Require().NoError(err) originalFlatFeeService := s.Charges.flatFeeService @@ -3165,6 +3166,7 @@ func (s *InvoicableChargesTestSuite) TestUsageBasedCreditOnlyWithCustomCurrency( CustomerOverrideService: s.BillingService, FeatureService: s.FeatureService, RatingService: billingratingservice.New(billingratingservice.Config{UnitConfigEnabled: s.UnitConfigEnabled}), + Currencies: s.CurrencyService, StreamingConnector: s.MockStreamingConnector, }) s.Require().NoError(err) diff --git a/openmeter/billing/charges/service/usagebased_costbasis_test.go b/openmeter/billing/charges/service/usagebased_costbasis_test.go new file mode 100644 index 0000000000..748e0d2893 --- /dev/null +++ b/openmeter/billing/charges/service/usagebased_costbasis_test.go @@ -0,0 +1,535 @@ +package service + +import ( + "context" + "testing" + "time" + + "github.com/alpacahq/alpacadecimal" + "github.com/samber/lo" + "github.com/stretchr/testify/suite" + + "github.com/openmeterio/openmeter/openmeter/billing" + "github.com/openmeterio/openmeter/openmeter/billing/charges" + "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased" + "github.com/openmeterio/openmeter/openmeter/currencies" + dbchargeusagebasedcostbasis "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedcostbasis" + "github.com/openmeterio/openmeter/openmeter/meter" + "github.com/openmeterio/openmeter/openmeter/productcatalog" + featurepkg "github.com/openmeterio/openmeter/openmeter/productcatalog/feature" + "github.com/openmeterio/openmeter/pkg/clock" + "github.com/openmeterio/openmeter/pkg/currencyx" + "github.com/openmeterio/openmeter/pkg/models" + "github.com/openmeterio/openmeter/pkg/timeutil" +) + +func TestUsageBasedCostBasisCreate(t *testing.T) { + suite.Run(t, new(UsageBasedCostBasisCreateSuite)) +} + +type UsageBasedCostBasisCreateSuite struct { + BaseSuite +} + +func (s *UsageBasedCostBasisCreateSuite) SetupSuite() { + s.BaseSuite.SetupSuite() +} + +func (s *UsageBasedCostBasisCreateSuite) TearDownTest() { + s.setCustomCurrencyEnabled(false) + s.BaseSuite.TearDownTest() +} + +func (s *UsageBasedCostBasisCreateSuite) TestCustomCurrencyCreditThenInvoiceIsDisabledByDefault() { + // given: + // - a valid manual cost-basis intent for a custom-currency usage-based charge + // - the test-only custom-currency switch left at its default value + // when: + // - the charge is created + // then: + // - creation is rejected before any charge cost basis is persisted + ctx := s.T().Context() + namespace := s.GetUniqueNamespace("usage-based-cost-basis-disabled") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "usage-based-cost-basis-disabled") + currency := s.createTestCustomCurrency(ctx, namespace) + featureMeters := s.createFeatureMeters(ctx, namespace, "disabled-feature") + intent := costbasis.NewIntent(costbasis.ManualIntent{ + FiatCurrency: s.newFiatCurrency("USD"), + Rate: alpacadecimal.NewFromInt(2), + }) + + _, err := s.Charges.usageBasedService.Create(ctx, usagebased.CreateInput{ + Namespace: namespace, + Intents: []usagebased.Intent{ + s.newUsageBasedIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "disabled", "disabled-feature", productcatalog.CreditThenInvoiceSettlementMode, &intent), + }, + FeatureMeters: featureMeters, + }) + s.Require().ErrorIs(err, meta.ErrCustomCurrencyNotSupported) + s.Require().Equal(0, s.countCostBases(namespace)) +} + +func (s *UsageBasedCostBasisCreateSuite) TestCreatePersistsManualPinnedAndDynamicCostBasesInInputOrder() { + // given: + // - manual, pinned, and dynamic cost-basis intents in one custom-currency batch + // when: + // - custom-currency creation is enabled, the charges are created, and each is reloaded through the charge service + // then: + // - each charge references its own persisted cost basis and its intent and resolved state survive the normal read path + ctx := s.T().Context() + now := time.Date(2026, time.January, 15, 12, 0, 0, 0, time.UTC) + clock.FreezeTime(now) + defer clock.UnFreeze() + + namespace := s.GetUniqueNamespace("usage-based-cost-basis-modes") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "usage-based-cost-basis-modes") + currency := s.createTestCustomCurrency(ctx, namespace) + featureMeters := s.createFeatureMeters(ctx, namespace, "modes-feature") + fiatCurrency := s.newFiatCurrency("USD") + pinnedCostBasis, err := s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: currencyx.Code("USD"), + Rate: alpacadecimal.NewFromFloat(0.25), + }) + s.Require().NoError(err) + + manualIntent := costbasis.NewIntent(costbasis.ManualIntent{ + FiatCurrency: fiatCurrency, + Rate: alpacadecimal.NewFromFloat(0.5), + }) + pinnedIntent := costbasis.NewIntent(costbasis.PinnedIntent{ + FiatCurrency: fiatCurrency, + CurrencyCostBasisID: pinnedCostBasis.ID, + }) + dynamicIntent := costbasis.NewIntent(costbasis.DynamicIntent{ + FiatCurrency: fiatCurrency, + }) + + s.setCustomCurrencyEnabled(true) + created, err := s.Charges.usageBasedService.Create(ctx, usagebased.CreateInput{ + Namespace: namespace, + Intents: []usagebased.Intent{ + s.newUsageBasedIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "manual", "modes-feature", productcatalog.CreditThenInvoiceSettlementMode, &manualIntent), + s.newUsageBasedIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "pinned", "modes-feature", productcatalog.CreditThenInvoiceSettlementMode, &pinnedIntent), + s.newUsageBasedIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "dynamic", "modes-feature", productcatalog.CreditThenInvoiceSettlementMode, &dynamicIntent), + }, + FeatureMeters: featureMeters, + }) + s.Require().NoError(err) + s.Require().Len(created, 3) + + s.Require().Equal(costbasis.ModeManual, created[0].Charge.Intent.GetCostBasisIntent().Kind()) + s.Require().NotNil(created[0].Charge.State.ResolvedCostBasis) + s.Require().Equal(float64(0.5), created[0].Charge.State.ResolvedCostBasis.CostBasis.InexactFloat64()) + s.Require().Nil(created[0].Charge.State.ResolvedCostBasis.CostBasisID) + s.Require().Equal(now, created[0].Charge.State.ResolvedCostBasis.ResolvedAt) + + s.Require().Equal(costbasis.ModePinned, created[1].Charge.Intent.GetCostBasisIntent().Kind()) + s.Require().NotNil(created[1].Charge.State.ResolvedCostBasis) + s.Require().Equal(float64(0.25), created[1].Charge.State.ResolvedCostBasis.CostBasis.InexactFloat64()) + s.Require().Equal(pinnedCostBasis.ID, *created[1].Charge.State.ResolvedCostBasis.CostBasisID) + s.Require().Equal(now, created[1].Charge.State.ResolvedCostBasis.ResolvedAt) + + s.Require().Equal(costbasis.ModeDynamic, created[2].Charge.Intent.GetCostBasisIntent().Kind()) + s.Require().Nil(created[2].Charge.State.ResolvedCostBasis) + + seenCostBasisIDs := map[string]struct{}{} + for idx, result := range created { + s.Require().NotNil(result.Charge.State.CostBasisID, "charge index %d", idx) + + reloaded, err := s.mustGetChargeByID(result.Charge.GetChargeID()).AsUsageBasedCharge() + s.Require().NoError(err) + s.Require().Equal(result.Charge.Intent.GetCostBasisIntent().Kind(), reloaded.Intent.GetCostBasisIntent().Kind(), "charge index %d", idx) + s.Require().Equal(result.Charge.State.CostBasisID, reloaded.State.CostBasisID, "charge index %d", idx) + s.Require().Equal(result.Charge.State.ResolvedCostBasis, reloaded.State.ResolvedCostBasis, "charge index %d", idx) + + chargeEntity, err := s.DBClient.ChargeUsageBased.Get(ctx, result.Charge.ID) + s.Require().NoError(err) + s.Require().NotNil(chargeEntity.CostBasisID) + s.Require().Equal(*result.Charge.State.CostBasisID, *chargeEntity.CostBasisID) + seenCostBasisIDs[*chargeEntity.CostBasisID] = struct{}{} + + costBasisEntity, err := s.DBClient.ChargeUsageBasedCostBasis.Get(ctx, *chargeEntity.CostBasisID) + s.Require().NoError(err) + persisted, err := costbasis.Get(costBasisEntity) + s.Require().NoError(err) + s.Require().Equal(result.Charge.Intent.GetCostBasisIntent().Kind(), persisted.Intent.Kind(), "charge index %d", idx) + s.Require().Equal(result.Charge.State.ResolvedCostBasis, persisted.State, "charge index %d", idx) + } + s.Require().Len(seenCostBasisIDs, 3) +} + +func (s *UsageBasedCostBasisCreateSuite) TestSetResolvedDynamicCostBasisIsRetrySafe() { + // given: + // - an unresolved dynamic cost basis attached to a usage-based charge + // - a first persisted resolution + // when: + // - a stale retry attempts to persist a different resolution + // then: + // - the original persisted resolution is returned and remains unchanged + ctx := s.T().Context() + now := time.Date(2026, time.January, 15, 12, 0, 0, 0, time.UTC) + clock.FreezeTime(now) + defer clock.UnFreeze() + + namespace := s.GetUniqueNamespace("usage-based-cost-basis-retry") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "usage-based-cost-basis-retry") + currency := s.createTestCustomCurrency(ctx, namespace) + featureMeters := s.createFeatureMeters(ctx, namespace, "retry-feature") + currencyCostBasis, err := s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: currencyx.Code("USD"), + Rate: alpacadecimal.NewFromFloat(0.25), + }) + s.Require().NoError(err) + + dynamicIntent := costbasis.NewIntent(costbasis.DynamicIntent{ + FiatCurrency: s.newFiatCurrency("USD"), + }) + s.setCustomCurrencyEnabled(true) + created, err := s.Charges.usageBasedService.Create(ctx, usagebased.CreateInput{ + Namespace: namespace, + Intents: []usagebased.Intent{ + s.newUsageBasedIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "dynamic-retry", "retry-feature", productcatalog.CreditThenInvoiceSettlementMode, &dynamicIntent), + }, + FeatureMeters: featureMeters, + }) + s.Require().NoError(err) + s.Require().Len(created, 1) + s.Require().NotNil(created[0].Charge.State.CostBasisID) + + firstState := costbasis.State{ + CostBasis: currencyCostBasis.Rate, + CostBasisID: lo.ToPtr(currencyCostBasis.ID), + ResolvedAt: now, + } + first, err := s.UsageBasedAdapter.SetResolvedCostBasis(ctx, costbasis.SetResolvedCostBasisInput{ + NamespacedID: models.NamespacedID{ + Namespace: namespace, + ID: *created[0].Charge.State.CostBasisID, + }, + State: firstState, + }) + s.Require().NoError(err) + s.Require().Equal(&firstState, first.State) + + retryState := costbasis.State{ + CostBasis: alpacadecimal.NewFromInt(9), + CostBasisID: lo.ToPtr(currencyCostBasis.ID), + ResolvedAt: now.Add(time.Hour), + } + retried, err := s.UsageBasedAdapter.SetResolvedCostBasis(ctx, costbasis.SetResolvedCostBasisInput{ + NamespacedID: first.NamespacedID, + State: retryState, + }) + s.Require().NoError(err) + s.Require().Equal(&firstState, retried.State) + + reloaded, err := s.mustGetChargeByID(created[0].Charge.GetChargeID()).AsUsageBasedCharge() + s.Require().NoError(err) + s.Require().Equal(created[0].Charge.State.CostBasisID, reloaded.State.CostBasisID) + s.Require().Equal(&firstState, reloaded.State.ResolvedCostBasis) +} + +func (s *UsageBasedCostBasisCreateSuite) TestDynamicCostBasisResolvesWhenChargeBecomesActive() { + // given: + // - an unresolved dynamic cost basis with two successive currency rates + // - activation delayed until after the second rate becomes effective + // when: + // - the charge advances from created to active + // then: + // - it idempotently persists the rate effective at service-period start and records that as ResolvedAt + ctx := s.T().Context() + servicePeriodFrom := time.Date(2026, time.January, 1, 0, 0, 0, 0, time.UTC) + secondEffectiveAt := servicePeriodFrom.Add(10 * 24 * time.Hour) + activationAt := secondEffectiveAt.Add(24 * time.Hour) + clock.FreezeTime(servicePeriodFrom) + defer clock.UnFreeze() + + namespace := s.GetUniqueNamespace("usage-based-cost-basis-active") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "usage-based-cost-basis-active") + sandboxApp := s.InstallSandboxApp(s.T(), namespace) + _ = s.ProvisionBillingProfile(ctx, namespace, sandboxApp.GetID()) + currency := s.createTestCustomCurrency(ctx, namespace) + featureMeters := s.createFeatureMeters(ctx, namespace, "active-feature") + first, err := s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: currencyx.Code("USD"), + Rate: alpacadecimal.NewFromFloat(0.25), + }) + s.Require().NoError(err) + _, err = s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: currencyx.Code("USD"), + Rate: alpacadecimal.NewFromFloat(0.5), + EffectiveFrom: lo.ToPtr(secondEffectiveAt), + }) + s.Require().NoError(err) + + dynamicIntent := costbasis.NewIntent(costbasis.DynamicIntent{ + FiatCurrency: s.newFiatCurrency("USD"), + }) + s.setCustomCurrencyEnabled(true) + clock.FreezeTime(activationAt) + defer clock.UnFreeze() + created, err := s.Charges.usageBasedService.Create(ctx, usagebased.CreateInput{ + Namespace: namespace, + Intents: []usagebased.Intent{ + s.newUsageBasedIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "dynamic-active", "active-feature", productcatalog.CreditThenInvoiceSettlementMode, &dynamicIntent), + }, + FeatureMeters: featureMeters, + }) + s.Require().NoError(err) + s.Require().Len(created, 1) + s.Require().Equal(usagebased.StatusCreated, created[0].Charge.Status) + s.Require().NotNil(created[0].Charge.State.CostBasisID) + s.Require().Nil(created[0].Charge.State.ResolvedCostBasis) + + advanced, err := s.Charges.AdvanceCharges(ctx, charges.AdvanceChargesInput{ + Customer: customer.GetID(), + }) + s.Require().NoError(err) + s.Require().Len(advanced, 1) + + reloaded, err := s.mustGetChargeByID(created[0].Charge.GetChargeID()).AsUsageBasedCharge() + s.Require().NoError(err) + s.Require().Equal(usagebased.StatusActive, reloaded.Status) + s.Require().Equal(created[0].Charge.State.CostBasisID, reloaded.State.CostBasisID) + s.Require().NotNil(reloaded.State.ResolvedCostBasis) + s.Require().Equal(first.ID, *reloaded.State.ResolvedCostBasis.CostBasisID) + s.Require().Equal(first.Rate.InexactFloat64(), reloaded.State.ResolvedCostBasis.CostBasis.InexactFloat64()) + s.Require().Equal(servicePeriodFrom, reloaded.State.ResolvedCostBasis.ResolvedAt) +} + +func (s *UsageBasedCostBasisCreateSuite) TestPinnedCostBasisMustMatchCurrencyAndFiatCurrency() { + ctx := s.T().Context() + namespace := s.GetUniqueNamespace("usage-based-cost-basis-pinned-mismatch") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "usage-based-cost-basis-pinned-mismatch") + currency := s.createTestCustomCurrency(ctx, namespace) + featureMeters := s.createFeatureMeters(ctx, namespace, "mismatch-feature") + otherCurrency, err := s.CurrencyService.CreateCurrency(ctx, currencies.CreateCurrencyInput{ + Namespace: namespace, + CurrencyDetails: currencyx.CurrencyDetails{ + Code: "OTHER", + Name: "Other", + Symbol: "O", + Precision: 3, + DecimalMark: ".", + ThousandsSeparator: ",", + }, + }) + s.Require().NoError(err) + + otherCurrencyCostBasis, err := s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: otherCurrency.ID, + FiatCode: currencyx.Code("USD"), + Rate: alpacadecimal.NewFromInt(1), + }) + s.Require().NoError(err) + eurCostBasis, err := s.CurrencyService.CreateCostBasis(ctx, currencies.CreateCostBasisInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: currencyx.Code("EUR"), + Rate: alpacadecimal.NewFromInt(1), + }) + s.Require().NoError(err) + + tests := []struct { + name string + costBasisID string + errorText string + }{ + {name: "currency", costBasisID: otherCurrencyCostBasis.ID, errorText: "currency cost basis currency mismatch"}, + {name: "fiat currency", costBasisID: eurCostBasis.ID, errorText: "currency cost basis fiat currency mismatch"}, + } + + s.setCustomCurrencyEnabled(true) + for _, test := range tests { + s.Run(test.name, func() { + // given: + // - a pinned cost basis that disagrees with the charge currency or requested fiat currency + // when: + // - the usage-based charge is created + // then: + // - resolution rejects the mismatch before charge cost-basis persistence + intent := costbasis.NewIntent(costbasis.PinnedIntent{ + FiatCurrency: s.newFiatCurrency("USD"), + CurrencyCostBasisID: test.costBasisID, + }) + + _, err := s.Charges.usageBasedService.Create(ctx, usagebased.CreateInput{ + Namespace: namespace, + Intents: []usagebased.Intent{ + s.newUsageBasedIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "mismatch-"+test.name, "mismatch-feature", productcatalog.CreditThenInvoiceSettlementMode, &intent), + }, + FeatureMeters: featureMeters, + }) + s.Require().ErrorContains(err, test.errorText) + }) + } + s.Require().Equal(0, s.countCostBases(namespace)) +} + +func (s *UsageBasedCostBasisCreateSuite) TestCreateRollsBackCostBasesWhenChargeCreationFails() { + // given: + // - two cost-basis-backed intents with the same charge unique reference + // when: + // - the charge constraint rejects the bulk create after cost bases were inserted + // then: + // - the surrounding transaction removes all newly inserted charge cost bases + ctx := s.T().Context() + namespace := s.GetUniqueNamespace("usage-based-cost-basis-rollback") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "usage-based-cost-basis-rollback") + currency := s.createTestCustomCurrency(ctx, namespace) + featureMeters := s.createFeatureMeters(ctx, namespace, "rollback-feature") + intent := costbasis.NewIntent(costbasis.ManualIntent{ + FiatCurrency: s.newFiatCurrency("USD"), + Rate: alpacadecimal.NewFromInt(2), + }) + + s.setCustomCurrencyEnabled(true) + _, err := s.Charges.usageBasedService.Create(ctx, usagebased.CreateInput{ + Namespace: namespace, + Intents: []usagebased.Intent{ + s.newUsageBasedIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "duplicate", "rollback-feature", productcatalog.CreditThenInvoiceSettlementMode, &intent), + s.newUsageBasedIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "duplicate", "rollback-feature", productcatalog.CreditThenInvoiceSettlementMode, &intent), + }, + FeatureMeters: featureMeters, + }) + s.Require().Error(err) + s.Require().Equal(0, s.countCostBases(namespace)) +} + +func (s *UsageBasedCostBasisCreateSuite) TestCreateWithoutCostBasisLeavesChargeReferenceEmpty() { + ctx := s.T().Context() + namespace := s.GetUniqueNamespace("usage-based-without-cost-basis") + defaults := s.ProvisionDefaultTaxCodes(ctx, namespace) + customer := s.CreateTestCustomer(namespace, "usage-based-without-cost-basis") + currency := s.createTestCustomCurrency(ctx, namespace) + featureMeters := s.createFeatureMeters(ctx, namespace, "credit-only-feature") + + created, err := s.Charges.usageBasedService.Create(ctx, usagebased.CreateInput{ + Namespace: namespace, + Intents: []usagebased.Intent{ + s.newUsageBasedIntent(customer.ID, currency, defaults.InvoicingTaxCodeID, "credit-only", "credit-only-feature", productcatalog.CreditOnlySettlementMode, nil), + }, + FeatureMeters: featureMeters, + }) + s.Require().NoError(err) + s.Require().Len(created, 1) + s.Require().Nil(created[0].Charge.Intent.GetCostBasisIntent()) + s.Require().Nil(created[0].Charge.State.CostBasisID) + s.Require().Nil(created[0].Charge.State.ResolvedCostBasis) + + chargeEntity, err := s.DBClient.ChargeUsageBased.Get(ctx, created[0].Charge.ID) + s.Require().NoError(err) + s.Require().Nil(chargeEntity.CostBasisID) + s.Require().Equal(0, s.countCostBases(namespace)) +} + +func (s *UsageBasedCostBasisCreateSuite) setCustomCurrencyEnabled(enabled bool) { + s.T().Helper() + enabler, ok := s.Charges.usageBasedService.(customCurrencyEnabler) + s.Require().True(ok) + s.Require().NoError(enabler.SetEnableCustomCurrency(s.T(), enabled)) +} + +func (s *UsageBasedCostBasisCreateSuite) countCostBases(namespace string) int { + s.T().Helper() + + count, err := s.DBClient.ChargeUsageBasedCostBasis.Query(). + Where(dbchargeusagebasedcostbasis.Namespace(namespace)). + Count(s.T().Context()) + s.Require().NoError(err) + + return count +} + +func (s *UsageBasedCostBasisCreateSuite) createFeatureMeters(ctx context.Context, namespace, key string) featurepkg.FeatureMeterCollection { + s.T().Helper() + + testMeter := newTestMeter(namespace, key+"-meter") + s.Require().NoError(s.MeterAdapter.ReplaceMeters(ctx, []meter.Meter{testMeter})) + + feature, err := s.FeatureService.CreateFeature(ctx, featurepkg.CreateFeatureInputs{ + Namespace: namespace, + Name: key, + Key: key, + MeterID: lo.ToPtr(testMeter.ID), + }) + s.Require().NoError(err) + + featureMeter := featurepkg.FeatureMeter{ + Feature: feature, + Meter: &testMeter, + } + + return featurepkg.FeatureMeterCollection{ + ByKey: map[string]featurepkg.FeatureMeter{feature.Key: featureMeter}, + ByID: map[string]featurepkg.FeatureMeter{feature.ID: featureMeter}, + } +} + +func (s *UsageBasedCostBasisCreateSuite) newFiatCurrency(code currencyx.Code) *currencyx.FiatCurrency { + s.T().Helper() + + fiatCurrency, err := currencyx.NewFiatCurrency(code) + s.Require().NoError(err) + + return fiatCurrency +} + +func (s *UsageBasedCostBasisCreateSuite) newUsageBasedIntent( + customerID string, + currency currencies.Currency, + taxCodeID string, + uniqueReferenceID string, + featureKey string, + settlementMode productcatalog.SettlementMode, + costBasis *costbasis.Intent, +) usagebased.Intent { + s.T().Helper() + + period := timeutil.ClosedPeriod{ + From: time.Date(2026, time.January, 1, 0, 0, 0, 0, time.UTC), + To: time.Date(2026, time.February, 1, 0, 0, 0, 0, time.UTC), + } + + return usagebased.Intent{ + Intent: meta.Intent{ + ManagedBy: billing.ManuallyManagedLine, + CustomerID: customerID, + Currency: currency, + TaxConfig: productcatalog.TaxCodeConfig{TaxCodeID: taxCodeID}, + UniqueReferenceID: lo.ToPtr(uniqueReferenceID), + }, + IntentMutableFields: usagebased.IntentMutableFields{ + IntentMutableFields: meta.IntentMutableFields{ + Name: uniqueReferenceID, + ServicePeriod: period, + FullServicePeriod: period, + BillingPeriod: period, + }, + InvoiceAt: period.To, + Price: *productcatalog.NewPriceFrom(productcatalog.UnitPrice{ + Amount: alpacadecimal.NewFromInt(1), + }), + }, + SettlementMode: settlementMode, + FeatureKey: featureKey, + CostBasis: costBasis, + } +} diff --git a/openmeter/billing/charges/testutils/service.go b/openmeter/billing/charges/testutils/service.go index 0889bb44d2..5b84413d3b 100644 --- a/openmeter/billing/charges/testutils/service.go +++ b/openmeter/billing/charges/testutils/service.go @@ -25,6 +25,7 @@ import ( usagebasedadapter "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased/adapter" usagebasedservice "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased/service" billingratingservice "github.com/openmeterio/openmeter/openmeter/billing/rating/service" + "github.com/openmeterio/openmeter/openmeter/currencies" currencyadapter "github.com/openmeterio/openmeter/openmeter/currencies/adapter" "github.com/openmeterio/openmeter/openmeter/currencies/currencyresolver" currencyservice "github.com/openmeterio/openmeter/openmeter/currencies/service" @@ -94,6 +95,7 @@ type Services struct { UsageBasedService usagebased.Service FlatFeeService flatfee.Service CreditPurchaseService creditpurchase.Service + CurrencyService currencies.Service } // NewServices constructs the charges stack from external dependencies and handlers. @@ -121,6 +123,18 @@ func NewServices(t testing.TB, config Config) (*Services, error) { return nil, fmt.Errorf("creating meta adapter: %w", err) } + currencyAdapter, err := currencyadapter.New(currencyadapter.Config{ + Client: config.Client, + }) + if err != nil { + return nil, fmt.Errorf("creating currency adapter: %w", err) + } + + currencyService, err := currencyservice.New(currencyAdapter) + if err != nil { + return nil, fmt.Errorf("creating currency service: %w", err) + } + locker, err := lockr.NewLocker(&lockr.LockerConfig{ Logger: logger, }) @@ -158,6 +172,7 @@ func NewServices(t testing.TB, config Config) (*Services, error) { MetaAdapter: metaAdapter, Locker: locker, RatingService: billingratingservice.New(billingratingservice.Config{UnitConfigEnabled: true}), + Currencies: currencyService, }) if err != nil { return nil, fmt.Errorf("creating flat fee service: %w", err) @@ -194,6 +209,7 @@ func NewServices(t testing.TB, config Config) (*Services, error) { CustomerOverrideService: config.BillingService, FeatureService: config.FeatureService, RatingService: billingratingservice.New(billingratingservice.Config{UnitConfigEnabled: true}), + Currencies: currencyService, StreamingConnector: config.StreamingConnector, }) if err != nil { @@ -245,18 +261,6 @@ func NewServices(t testing.TB, config Config) (*Services, error) { return nil, fmt.Errorf("creating charges adapter: %w", err) } - currencyAdapter, err := currencyadapter.New(currencyadapter.Config{ - Client: config.Client, - }) - if err != nil { - return nil, fmt.Errorf("creating currency adapter: %w", err) - } - - currencyService, err := currencyservice.New(currencyAdapter) - if err != nil { - return nil, fmt.Errorf("creating currency service: %w", err) - } - currencyResolver, err := currencyresolver.New(currencyService) if err != nil { return nil, fmt.Errorf("creating currency resolver: %w", err) @@ -284,5 +288,6 @@ func NewServices(t testing.TB, config Config) (*Services, error) { UsageBasedService: usageBasedService, FlatFeeService: flatFeeService, CreditPurchaseService: creditPurchaseService, + CurrencyService: currencyService, }, nil } diff --git a/openmeter/billing/charges/usagebased/adapter.go b/openmeter/billing/charges/usagebased/adapter.go index 3b746e485c..5cf32295ef 100644 --- a/openmeter/billing/charges/usagebased/adapter.go +++ b/openmeter/billing/charges/usagebased/adapter.go @@ -4,6 +4,7 @@ import ( "context" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/creditrealization" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/invoicedusage" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/payment" @@ -16,10 +17,15 @@ type Adapter interface { RealizationRunInvoiceUsageAdapter RealizationRunPaymentAdapter ChargeAdapter + ChargeCostBasisAdapter entutils.TxCreator } +type ChargeCostBasisAdapter interface { + SetResolvedCostBasis(ctx context.Context, input costbasis.SetResolvedCostBasisInput) (costbasis.CostBasis, error) +} + type ChargeAdapter interface { CreateCharges(ctx context.Context, charges CreateChargesInput) ([]Charge, error) UpdateCharge(ctx context.Context, charge ChargeBase) (ChargeBase, error) diff --git a/openmeter/billing/charges/usagebased/adapter/charge.go b/openmeter/billing/charges/usagebased/adapter/charge.go index 1b2f4621f5..46df435f0c 100644 --- a/openmeter/billing/charges/usagebased/adapter/charge.go +++ b/openmeter/billing/charges/usagebased/adapter/charge.go @@ -5,11 +5,13 @@ import ( "fmt" "time" + "github.com/oklog/ulid/v2" "github.com/samber/lo" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" metaadapter "github.com/openmeterio/openmeter/openmeter/billing/charges/meta/adapter" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/chargemeta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased" "github.com/openmeterio/openmeter/openmeter/ent/db" dbchargeusagebased "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebased" @@ -72,6 +74,10 @@ func (a *adapter) UpdateCharge(ctx context.Context, charge usagebased.ChargeBase return usagebased.ChargeBase{}, err } + if err := tx.loadCostBasisEdge(ctx, dbUpdatedChargeBase); err != nil { + return usagebased.ChargeBase{}, err + } + if overrideLayer := charge.Intent.GetOverrideLayerMutableFields(); overrideLayer != nil { intentOverride, err := tx.updateIntentOverride(ctx, charge.GetChargeID(), overrideLayer) if err != nil { @@ -109,6 +115,10 @@ func (a *adapter) UpdateSubscriptionItemID(ctx context.Context, charge usagebase return usagebased.Charge{}, err } + if err := tx.loadCostBasisEdge(ctx, updatedChargeBase); err != nil { + return usagebased.Charge{}, err + } + overrideLayer := charge.Intent.GetOverrideLayerMutableFields() mappedChargeBase, err := fromDBBaseWithCurrency(updatedChargeBase, charge.Intent.GetBaseIntent().Currency) if err != nil { @@ -188,19 +198,98 @@ func (a *adapter) CreateCharges(ctx context.Context, in usagebased.CreateCharges } return entutils.TransactingRepo(ctx, a, func(ctx context.Context, tx *adapter) ([]usagebased.Charge, error) { - creates, err := slicesx.MapWithErr(in.Intents, func(intent usagebased.CreateIntent) (*db.ChargeUsageBasedCreate, error) { - return tx.buildCreateUsageBasedCharge(ctx, in.Namespace, intent) + type preparedCreate struct { + costBasis *db.ChargeUsageBasedCostBasisCreate + charge *db.ChargeUsageBasedCreate + } + + preparedCreates := make([]preparedCreate, 0, len(in.Intents)) + for _, intent := range in.Intents { + chargeCreate, err := tx.buildCreateUsageBasedCharge(ctx, in.Namespace, intent) + if err != nil { + return nil, err + } + + var costBasisCreate *db.ChargeUsageBasedCostBasisCreate + baseIntent := intent.Intent.GetBaseIntent() + if baseIntent.CostBasis != nil { + costBasisCreate, err = costbasis.Create(tx.db.ChargeUsageBasedCostBasis.Create(), costbasis.CreateInput{ + NamespacedID: models.NamespacedID{ + Namespace: in.Namespace, + ID: ulid.Make().String(), + }, + CurrencyID: baseIntent.Currency.ID, + Intent: *baseIntent.CostBasis, + State: intent.ResolvedCostBasis, + }) + if err != nil { + return nil, fmt.Errorf("building usage based cost basis: %w", err) + } + } + + preparedCreates = append(preparedCreates, preparedCreate{ + costBasis: costBasisCreate, + charge: chargeCreate, + }) + } + + costBasisCreates := lo.Filter(preparedCreates, func(create preparedCreate, _ int) bool { + return create.costBasis != nil }) - if err != nil { - return nil, err + + var createdCostBases []*db.ChargeUsageBasedCostBasis + if len(costBasisCreates) > 0 { + var err error + createdCostBases, err = tx.db.ChargeUsageBasedCostBasis.CreateBulk( + lo.Map(costBasisCreates, func(create preparedCreate, _ int) *db.ChargeUsageBasedCostBasisCreate { + return create.costBasis + })..., + ).Save(ctx) + if err != nil { + return nil, fmt.Errorf("creating usage based cost bases: %w", err) + } + + lo.ForEach(costBasisCreates, func(create preparedCreate, idx int) { + create.charge.SetCostBasisID(createdCostBases[idx].ID) + }) } - entities, err := tx.db.ChargeUsageBased.CreateBulk(creates...).Save(ctx) + chargeCreates := lo.Map(preparedCreates, func(create preparedCreate, _ int) *db.ChargeUsageBasedCreate { + return create.charge + }) + entities, err := tx.db.ChargeUsageBased.CreateBulk(chargeCreates...).Save(ctx) if err != nil { return nil, metaadapter.MapChargeConstraintError(err) } + err = tx.metaAdapter.RegisterCharges(ctx, meta.RegisterChargesInput{ + Namespace: in.Namespace, + Type: meta.ChargeTypeUsageBased, + Charges: lo.Map(entities, func(entity *db.ChargeUsageBased, _ int) meta.IDWithUniqueReferenceID { + return meta.IDWithUniqueReferenceID{ + ID: entity.ID, + UniqueReferenceID: entity.UniqueReferenceID, + } + }), + }) + if err != nil { + return nil, err + } + + costBasisByID := lo.SliceToMap(createdCostBases, func(entity *db.ChargeUsageBasedCostBasis) (string, *db.ChargeUsageBasedCostBasis) { + return entity.ID, entity + }) + return lo.MapErr(entities, func(entity *db.ChargeUsageBased, idx int) (usagebased.Charge, error) { + if entity.CostBasisID != nil { + createdCostBasis, ok := costBasisByID[*entity.CostBasisID] + if !ok { + return usagebased.Charge{}, fmt.Errorf("created usage based cost basis %s not found", *entity.CostBasisID) + } + + entity.Edges.CostBasis = createdCostBasis + } + return FromDBWithCurrency(entity, in.Intents[idx].Intent.GetBaseIntent().Currency, meta.ExpandNone) }) }) @@ -217,7 +306,8 @@ func (a *adapter) GetByIDs(ctx context.Context, input usagebased.GetByIDsInput) Where(dbchargeusagebased.Namespace(input.Namespace)). Where(dbchargeusagebased.IDIn(input.IDs...)). WithIntentOverride(). - WithCustomCurrency() + WithCustomCurrency(). + WithCostBasis() if input.Expands.Has(meta.ExpandRealizations) { query = expandRealizations(query, input.Expands) @@ -263,7 +353,8 @@ func (a *adapter) GetByID(ctx context.Context, input usagebased.GetByIDInput) (u Where(dbchargeusagebased.Namespace(input.ChargeID.Namespace)). Where(dbchargeusagebased.ID(input.ChargeID.ID)). WithIntentOverride(). - WithCustomCurrency() + WithCustomCurrency(). + WithCostBasis() if input.Expands.Has(meta.ExpandRealizations) { query = expandRealizations(query, input.Expands) diff --git a/openmeter/billing/charges/usagebased/adapter/costbasis.go b/openmeter/billing/charges/usagebased/adapter/costbasis.go new file mode 100644 index 0000000000..1d6e99c08a --- /dev/null +++ b/openmeter/billing/charges/usagebased/adapter/costbasis.go @@ -0,0 +1,97 @@ +package adapter + +import ( + "context" + "fmt" + + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased" + entdb "github.com/openmeterio/openmeter/openmeter/ent/db" + dbchargeusagebasedcostbasis "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedcostbasis" + "github.com/openmeterio/openmeter/pkg/framework/entutils" + "github.com/openmeterio/openmeter/pkg/models" +) + +var _ usagebased.ChargeCostBasisAdapter = (*adapter)(nil) + +func (a *adapter) loadCostBasisEdge(ctx context.Context, entity *entdb.ChargeUsageBased) error { + if entity.Edges.CostBasis != nil { + return fmt.Errorf("usage based cost basis edge is already loaded [charge_id=%s,edge_id=%s]", entity.ID, entity.Edges.CostBasis.ID) + } + + if entity.CostBasisID == nil { + return nil + } + + costBasisEntity, err := a.db.ChargeUsageBasedCostBasis.Query(). + Where( + dbchargeusagebasedcostbasis.ID(*entity.CostBasisID), + dbchargeusagebasedcostbasis.Namespace(entity.Namespace), + ). + Only(ctx) + if err != nil { + return fmt.Errorf("load usage based cost basis edge [charge_id=%s,cost_basis_id=%s]: %w", entity.ID, *entity.CostBasisID, err) + } + + entity.Edges.CostBasis = costBasisEntity + + return nil +} + +func (a *adapter) SetResolvedCostBasis(ctx context.Context, input costbasis.SetResolvedCostBasisInput) (costbasis.CostBasis, error) { + if err := input.Validate(); err != nil { + return costbasis.CostBasis{}, err + } + + return entutils.TransactingRepo(ctx, a, func(ctx context.Context, tx *adapter) (costbasis.CostBasis, error) { + update := tx.db.ChargeUsageBasedCostBasis.UpdateOneID(input.ID). + Where( + dbchargeusagebasedcostbasis.Namespace(input.Namespace), + dbchargeusagebasedcostbasis.ModeEQ(costbasis.ModeDynamic), + dbchargeusagebasedcostbasis.ResolvedCostBasisIDIsNil(), + dbchargeusagebasedcostbasis.ResolvedCostBasisIsNil(), + dbchargeusagebasedcostbasis.ResolvedAtIsNil(), + ) + + update, err := costbasis.Set(update, input.State) + if err != nil { + return costbasis.CostBasis{}, err + } + + entity, err := update.Save(ctx) + if entdb.IsNotFound(err) { + existingEntity, getErr := tx.db.ChargeUsageBasedCostBasis.Query(). + Where( + dbchargeusagebasedcostbasis.ID(input.ID), + dbchargeusagebasedcostbasis.Namespace(input.Namespace), + ). + Only(ctx) + if entdb.IsNotFound(getErr) { + return costbasis.CostBasis{}, models.NewGenericNotFoundError( + fmt.Errorf("usage based cost basis not found: %s", input.ID), + ) + } + if getErr != nil { + return costbasis.CostBasis{}, fmt.Errorf("get usage based cost basis after conditional resolution: %w", getErr) + } + + existing, getErr := costbasis.Get(existingEntity) + if getErr != nil { + return costbasis.CostBasis{}, fmt.Errorf("map usage based cost basis after conditional resolution: %w", getErr) + } + + if existing.Intent.Kind() == costbasis.ModeDynamic && existing.State != nil { + return existing, nil + } + + return costbasis.CostBasis{}, models.NewGenericValidationError( + fmt.Errorf("usage based cost basis is not an unresolved dynamic cost basis: %s", input.ID), + ) + } + if err != nil { + return costbasis.CostBasis{}, fmt.Errorf("set resolved usage based cost basis: %w", err) + } + + return costbasis.Get(entity) + }) +} diff --git a/openmeter/billing/charges/usagebased/adapter/intentoverride.go b/openmeter/billing/charges/usagebased/adapter/intentoverride.go index d6120d8cff..bfa5216dca 100644 --- a/openmeter/billing/charges/usagebased/adapter/intentoverride.go +++ b/openmeter/billing/charges/usagebased/adapter/intentoverride.go @@ -73,6 +73,9 @@ func (a *adapter) CreateChargeOverride(ctx context.Context, charge usagebased.Ch } dbCharge.Edges.IntentOverride = dbIntentOverride + if err := tx.loadCostBasisEdge(ctx, dbCharge); err != nil { + return usagebased.ChargeBase{}, err + } return fromDBBaseWithCurrency(dbCharge, charge.Intent.GetBaseIntent().Currency) }) diff --git a/openmeter/billing/charges/usagebased/adapter/intentoverride_test.go b/openmeter/billing/charges/usagebased/adapter/intentoverride_test.go index 21866b0e3b..1e0909338d 100644 --- a/openmeter/billing/charges/usagebased/adapter/intentoverride_test.go +++ b/openmeter/billing/charges/usagebased/adapter/intentoverride_test.go @@ -419,16 +419,6 @@ func (s *UsageBasedIntentOverrideAdapterSuite) createCharge(namespace string) us }) s.Require().NoError(err) s.Require().Len(createdCharges, 1) - s.Require().NoError(s.meta.RegisterCharges(s.T().Context(), chargesmeta.RegisterChargesInput{ - Namespace: namespace, - Type: chargesmeta.ChargeTypeUsageBased, - Charges: []chargesmeta.IDWithUniqueReferenceID{ - { - ID: createdCharges[0].ID, - UniqueReferenceID: createdCharges[0].Intent.GetUniqueReferenceID(), - }, - }, - })) s.Nil(createdCharges[0].Intent.GetOverrideLayerMutableFields()) return createdCharges[0] diff --git a/openmeter/billing/charges/usagebased/adapter/mapper.go b/openmeter/billing/charges/usagebased/adapter/mapper.go index a347d5efe3..45a2caf861 100644 --- a/openmeter/billing/charges/usagebased/adapter/mapper.go +++ b/openmeter/billing/charges/usagebased/adapter/mapper.go @@ -10,6 +10,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/chargemeta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/creditrealization" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/invoicedusage" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/payment" @@ -41,6 +42,11 @@ func FromDBWithCurrency(entity *entdb.ChargeUsageBased, currency currencies.Curr } func fromDBWithMeta(entity *entdb.ChargeUsageBased, chargeMeta meta.Charge, expands meta.Expands) (usagebased.Charge, error) { + base, err := fromDBBase(entity, chargeMeta) + if err != nil { + return usagebased.Charge{}, fmt.Errorf("mapping usage based charge base [id=%s]: %w", entity.ID, err) + } + var realizations usagebased.RealizationRuns if expands.Has(meta.ExpandRealizations) { var err error @@ -51,7 +57,7 @@ func fromDBWithMeta(entity *entdb.ChargeUsageBased, chargeMeta meta.Charge, expa } return usagebased.Charge{ - ChargeBase: fromDBBase(entity, chargeMeta), + ChargeBase: base, Realizations: realizations, }, nil } @@ -62,13 +68,38 @@ func fromDBBaseWithCurrency(entity *entdb.ChargeUsageBased, currency currencies. return usagebased.ChargeBase{}, fmt.Errorf("mapping charge meta: %w", err) } - return fromDBBase(entity, chargeMeta), nil + return fromDBBase(entity, chargeMeta) } -func fromDBBase(entity *entdb.ChargeUsageBased, chargeMeta meta.Charge) usagebased.ChargeBase { +func fromDBBase(entity *entdb.ChargeUsageBased, chargeMeta meta.Charge) (usagebased.ChargeBase, error) { + var costBasisIntent *costbasis.Intent + var resolvedCostBasis *costbasis.State + var costBasisID *string + if entity.CostBasisID != nil { + if entity.Edges.CostBasis == nil { + return usagebased.ChargeBase{}, fmt.Errorf("cost basis not loaded for usage based charge [id=%s,cost_basis_id=%s]", entity.ID, *entity.CostBasisID) + } + + if entity.Edges.CostBasis.ID != *entity.CostBasisID { + return usagebased.ChargeBase{}, fmt.Errorf("cost basis ID mismatch for usage based charge [id=%s,cost_basis_id=%s,edge_id=%s]", entity.ID, *entity.CostBasisID, entity.Edges.CostBasis.ID) + } + + mappedCostBasis, err := costbasis.Get(entity.Edges.CostBasis) + if err != nil { + return usagebased.ChargeBase{}, fmt.Errorf("mapping cost basis: %w", err) + } + + costBasisID = lo.ToPtr(*entity.CostBasisID) + costBasisIntent = &mappedCostBasis.Intent + resolvedCostBasis = mappedCostBasis.State + } else if entity.Edges.CostBasis != nil { + return usagebased.ChargeBase{}, fmt.Errorf("cost basis edge loaded without a reference for usage based charge [id=%s,edge_id=%s]", entity.ID, entity.Edges.CostBasis.ID) + } + intent := usagebased.Intent{ Intent: chargeMeta.Intent, FeatureKey: entity.FeatureKey, + CostBasis: costBasisIntent, IntentMutableFields: usagebased.IntentMutableFields{ IntentMutableFields: chargeMeta.IntentMutableFields, InvoiceAt: entity.InvoiceAt.UTC(), @@ -89,8 +120,10 @@ func fromDBBase(entity *entdb.ChargeUsageBased, chargeMeta meta.Charge) usagebas AdvanceAfter: entity.AdvanceAfter, FeatureID: entity.FeatureID, RatingEngine: entity.RatingEngine, + CostBasisID: costBasisID, + ResolvedCostBasis: resolvedCostBasis, }, - } + }, nil } func fromDBRuns(entity *entdb.ChargeUsageBased) (usagebased.RealizationRuns, error) { diff --git a/openmeter/billing/charges/usagebased/charge.go b/openmeter/billing/charges/usagebased/charge.go index fdf9b04b01..ca886df010 100644 --- a/openmeter/billing/charges/usagebased/charge.go +++ b/openmeter/billing/charges/usagebased/charge.go @@ -9,6 +9,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/models/totals" "github.com/openmeterio/openmeter/openmeter/currencies" "github.com/openmeterio/openmeter/openmeter/customer" @@ -49,6 +50,19 @@ func (c ChargeBase) Validate() error { errs = append(errs, fmt.Errorf("state: %w", err)) } + costBasisIntent := c.Intent.GetCostBasisIntent() + if costBasisIntent == nil { + if c.State.CostBasisID != nil { + errs = append(errs, errors.New("cost basis ID must not be set without a cost basis intent")) + } + + if c.State.ResolvedCostBasis != nil { + errs = append(errs, errors.New("resolved cost basis must not be set without a cost basis intent")) + } + } else if c.State.CostBasisID == nil { + errs = append(errs, errors.New("cost basis ID is required with a cost basis intent")) + } + return models.NewNillableGenericValidationError(errors.Join(errs...)) } @@ -197,6 +211,7 @@ type Intent struct { IntentMutableFields `json:"intentMutableFields"` SettlementMode productcatalog.SettlementMode `json:"settlementMode"` FeatureKey string `json:"featureKey"` + CostBasis *costbasis.Intent `json:"costBasis,omitempty"` } // AsOverridableIntent maps the intent's mutable fields as the base layer. @@ -206,6 +221,7 @@ func (i Intent) AsOverridableIntent() OverridableIntent { baseLayer: i.IntentMutableFields, settlementMode: i.SettlementMode, featureKey: i.FeatureKey, + costBasis: i.CostBasis, } } @@ -234,9 +250,34 @@ func (i Intent) Validate() error { errs = append(errs, fmt.Errorf("feature key is required")) } + if err := validateCostBasis(i.Currency, i.SettlementMode, i.CostBasis); err != nil { + errs = append(errs, err) + } + return models.NewNillableGenericValidationError(errors.Join(errs...)) } +func validateCostBasis(currency currencies.Currency, settlementMode productcatalog.SettlementMode, intent *costbasis.Intent) error { + isCostBasisRequired := currency.IsCustom() && settlementMode == productcatalog.CreditThenInvoiceSettlementMode + if !isCostBasisRequired { + if intent != nil { + return errors.New("cost basis must not be set unless currency is custom and settlement mode is credit then invoice") + } + + return nil + } + + if intent == nil { + return errors.New("cost basis is required for custom currency with credit then invoice settlement") + } + + if err := intent.Validate(); err != nil { + return fmt.Errorf("cost basis: %w", err) + } + + return nil +} + // OverridableIntent stores the immutable intent plus the base and optional // override mutable layers. Direct layer access is error-prone because callers // must manually decide which layer is active; this API centralizes that choice @@ -249,6 +290,7 @@ type OverridableIntent struct { settlementMode productcatalog.SettlementMode featureKey string + costBasis *costbasis.Intent } func NewOverridableIntent(baseIntent Intent, overrideLayer *IntentMutableFields) OverridableIntent { @@ -258,6 +300,7 @@ func NewOverridableIntent(baseIntent Intent, overrideLayer *IntentMutableFields) overrideLayer: overrideLayer, settlementMode: baseIntent.SettlementMode, featureKey: baseIntent.FeatureKey, + costBasis: baseIntent.CostBasis, } } @@ -318,6 +361,10 @@ func (i OverridableIntent) Validate() error { errs = append(errs, fmt.Errorf("settlement mode: %w", err)) } + if err := validateCostBasis(i.intent.Currency, i.settlementMode, i.costBasis); err != nil { + errs = append(errs, err) + } + return models.NewNillableGenericValidationError(errors.Join(errs...)) } @@ -332,6 +379,7 @@ func (i OverridableIntent) GetEffectiveIntent() Intent { IntentMutableFields: i.baseLayer.Clone(), SettlementMode: i.settlementMode, FeatureKey: i.featureKey, + CostBasis: i.GetCostBasisIntent(), } if i.overrideLayer != nil { @@ -367,6 +415,16 @@ func (i OverridableIntent) GetFeatureKey() string { return i.featureKey } +// GetCostBasisIntent returns the immutable cost-basis intent from the base intent. +// Override layers cannot change how the charge's custom-currency value is resolved. +func (i OverridableIntent) GetCostBasisIntent() *costbasis.Intent { + if i.costBasis == nil { + return nil + } + + return lo.ToPtr(i.costBasis.Clone()) +} + // GetEffectivePrice returns a cloned price from the active mutable layer, // preferring the override layer when it is present. func (i OverridableIntent) GetEffectivePrice() productcatalog.Price { @@ -433,6 +491,7 @@ func (i OverridableIntent) GetBaseIntent() Intent { IntentMutableFields: i.baseLayer.Clone(), SettlementMode: i.settlementMode, FeatureKey: i.featureKey, + CostBasis: i.GetCostBasisIntent(), } } @@ -441,6 +500,7 @@ func (i OverridableIntent) GetIntentForTarget(target meta.ChangeTarget) (Intent, Intent: i.intent.Clone(), SettlementMode: i.settlementMode, FeatureKey: i.featureKey, + CostBasis: i.GetCostBasisIntent(), } switch target { @@ -598,10 +658,12 @@ func (f IntentMutableFields) Validate() error { } type State struct { - CurrentRealizationRunID *string `json:"currentRealizationRunId"` - AdvanceAfter *time.Time `json:"advanceAfter"` - FeatureID string `json:"featureId"` - RatingEngine RatingEngine `json:"ratingEngine"` + CurrentRealizationRunID *string `json:"currentRealizationRunId"` + AdvanceAfter *time.Time `json:"advanceAfter"` + FeatureID string `json:"featureId"` + RatingEngine RatingEngine `json:"ratingEngine"` + CostBasisID *string `json:"-"` + ResolvedCostBasis *costbasis.State `json:"resolvedCostBasis,omitempty"` } func (s State) Normalized() State { @@ -625,6 +687,16 @@ func (s State) Validate() error { errs = append(errs, fmt.Errorf("rating engine: %w", err)) } + if s.CostBasisID != nil && *s.CostBasisID == "" { + errs = append(errs, fmt.Errorf("cost basis ID is required")) + } + + if s.ResolvedCostBasis != nil { + if err := s.ResolvedCostBasis.Validate(); err != nil { + errs = append(errs, fmt.Errorf("resolved cost basis: %w", err)) + } + } + return models.NewNillableGenericValidationError(errors.Join(errs...)) } diff --git a/openmeter/billing/charges/usagebased/charge_test.go b/openmeter/billing/charges/usagebased/charge_test.go index e4f68c276c..44e0958884 100644 --- a/openmeter/billing/charges/usagebased/charge_test.go +++ b/openmeter/billing/charges/usagebased/charge_test.go @@ -2,13 +2,210 @@ package usagebased import ( "testing" + "time" "github.com/alpacahq/alpacadecimal" "github.com/stretchr/testify/require" + "github.com/openmeterio/openmeter/openmeter/billing" + "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/currencies" + currenciestestutils "github.com/openmeterio/openmeter/openmeter/currencies/testutils/currency" "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/pkg/currencyx" + "github.com/openmeterio/openmeter/pkg/timeutil" ) +func TestIntentValidateCostBasis(t *testing.T) { + customCurrency := newCustomCurrency(t) + fiatCurrency := currenciestestutils.NewFiatCurrency(t, "USD") + validCostBasis := newManualCostBasisIntent(t) + invalidCostBasis := costbasis.Intent{} + + tests := []struct { + name string + currency currencies.Currency + settlementMode productcatalog.SettlementMode + costBasis *costbasis.Intent + wantErr string + }{ + { + name: "custom currency with credit then invoice requires cost basis", + currency: customCurrency, + settlementMode: productcatalog.CreditThenInvoiceSettlementMode, + wantErr: "cost basis is required", + }, + { + name: "custom currency with credit then invoice accepts valid cost basis", + currency: customCurrency, + settlementMode: productcatalog.CreditThenInvoiceSettlementMode, + costBasis: &validCostBasis, + }, + { + name: "custom currency with credit then invoice validates cost basis", + currency: customCurrency, + settlementMode: productcatalog.CreditThenInvoiceSettlementMode, + costBasis: &invalidCostBasis, + wantErr: "cost basis", + }, + { + name: "custom currency with credit only does not require cost basis", + currency: customCurrency, + settlementMode: productcatalog.CreditOnlySettlementMode, + }, + { + name: "custom currency with credit only rejects cost basis", + currency: customCurrency, + settlementMode: productcatalog.CreditOnlySettlementMode, + costBasis: &validCostBasis, + wantErr: "cost basis must not be set", + }, + { + name: "fiat currency with credit then invoice does not require cost basis", + currency: fiatCurrency, + settlementMode: productcatalog.CreditThenInvoiceSettlementMode, + }, + { + name: "fiat currency with credit then invoice rejects cost basis", + currency: fiatCurrency, + settlementMode: productcatalog.CreditThenInvoiceSettlementMode, + costBasis: &validCostBasis, + wantErr: "cost basis must not be set", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + intent := newValidIntent(t, tt.currency, tt.settlementMode) + intent.CostBasis = tt.costBasis + + validations := []struct { + name string + err error + }{ + {name: "intent", err: intent.Validate()}, + {name: "overridable intent", err: intent.AsOverridableIntent().Validate()}, + } + + for _, validation := range validations { + t.Run(validation.name, func(t *testing.T) { + if tt.wantErr == "" { + require.NoError(t, validation.err) + return + } + + require.ErrorContains(t, validation.err, tt.wantErr) + }) + } + }) + } +} + +func TestOverridableIntentPreservesCostBasis(t *testing.T) { + intent := newValidIntent(t, newCustomCurrency(t), productcatalog.CreditThenInvoiceSettlementMode) + costBasis := newManualCostBasisIntent(t) + intent.CostBasis = &costBasis + + overridable := intent.AsOverridableIntent() + requireManualCostBasisIntent(t, overridable.GetCostBasisIntent()) + requireManualCostBasisIntent(t, overridable.GetBaseIntent().CostBasis) + requireManualCostBasisIntent(t, overridable.GetEffectiveIntent().CostBasis) + + baseIntent, err := overridable.GetIntentForTarget(meta.ChangeTargetBase) + require.NoError(t, err) + requireManualCostBasisIntent(t, baseIntent.CostBasis) + + overrideLayer := intent.IntentMutableFields.Clone() + overrideLayer.Name = "override" + overridable = NewOverridableIntent(intent, &overrideLayer) + + overrideIntent, err := overridable.GetIntentForTarget(meta.ChangeTargetOverride) + require.NoError(t, err) + requireManualCostBasisIntent(t, overrideIntent.CostBasis) + + returnedCostBasis := overridable.GetCostBasisIntent() + *returnedCostBasis = costbasis.NewIntent(costbasis.DynamicIntent{ + FiatCurrency: newFiatCurrency(t, "EUR"), + }) + requireManualCostBasisIntent(t, overridable.GetCostBasisIntent()) +} + +func newCustomCurrency(t testing.TB) currencies.Currency { + t.Helper() + + currency, err := currencyx.NewCurrencyBuilder(currencyx.CurrencyTypeCustom). + WithCode(currencyx.Code("TOKENS")). + WithName("Tokens"). + Build() + require.NoError(t, err) + + return currencies.Currency{Currency: currency} +} + +func newValidIntent(t testing.TB, currency currencies.Currency, settlementMode productcatalog.SettlementMode) Intent { + t.Helper() + + period := timeutil.ClosedPeriod{ + From: time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC), + To: time.Date(2026, 2, 1, 0, 0, 0, 0, time.UTC), + } + + return Intent{ + Intent: meta.Intent{ + ManagedBy: billing.ManuallyManagedLine, + CustomerID: "customer-1", + Currency: currency, + TaxConfig: productcatalog.TaxCodeConfig{ + TaxCodeID: "tax-code-1", + }, + }, + IntentMutableFields: IntentMutableFields{ + IntentMutableFields: meta.IntentMutableFields{ + Name: "usage based", + ServicePeriod: period, + FullServicePeriod: period, + BillingPeriod: period, + }, + InvoiceAt: period.To, + Price: *productcatalog.NewPriceFrom(productcatalog.UnitPrice{ + Amount: alpacadecimal.NewFromInt(1), + }), + }, + SettlementMode: settlementMode, + FeatureKey: "feature-key", + } +} + +func newManualCostBasisIntent(t testing.TB) costbasis.Intent { + t.Helper() + + return costbasis.NewIntent(costbasis.ManualIntent{ + FiatCurrency: newFiatCurrency(t, "USD"), + Rate: alpacadecimal.NewFromInt(2), + }) +} + +func newFiatCurrency(t testing.TB, code currencyx.Code) *currencyx.FiatCurrency { + t.Helper() + + fiatCurrency, err := currencyx.NewFiatCurrency(code) + require.NoError(t, err) + + return fiatCurrency +} + +func requireManualCostBasisIntent(t testing.TB, intent *costbasis.Intent) { + t.Helper() + require.NotNil(t, intent) + require.Equal(t, costbasis.ModeManual, intent.Kind()) + + manualIntent, err := intent.AsManual() + require.NoError(t, err) + require.Equal(t, float64(2), manualIntent.Rate.InexactFloat64()) + require.Equal(t, currencyx.Code("USD"), manualIntent.FiatCurrency.Details().Code) +} + // TestOverridableIntentGetEffectiveUnitConfig locks in that the override layer is a // full snapshot of the effective mutable fields: an override created from the effective // intent inherits the base unit_config, so an unrelated edit does not drop the diff --git a/openmeter/billing/charges/usagebased/service.go b/openmeter/billing/charges/usagebased/service.go index e3727dd756..229d5b31c5 100644 --- a/openmeter/billing/charges/usagebased/service.go +++ b/openmeter/billing/charges/usagebased/service.go @@ -7,6 +7,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/models/totals" "github.com/openmeterio/openmeter/openmeter/productcatalog/feature" "github.com/openmeterio/openmeter/pkg/models" @@ -73,8 +74,9 @@ type CreateIntent struct { Intent OverridableIntent Annotations models.Annotations `json:"annotations"` - FeatureID string - RatingEngine RatingEngine + FeatureID string + RatingEngine RatingEngine + ResolvedCostBasis *costbasis.State } func (i CreateIntent) Validate() error { diff --git a/openmeter/billing/charges/usagebased/service/create.go b/openmeter/billing/charges/usagebased/service/create.go index 698707e78c..f9426e9ba2 100644 --- a/openmeter/billing/charges/usagebased/service/create.go +++ b/openmeter/billing/charges/usagebased/service/create.go @@ -9,8 +9,10 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased" "github.com/openmeterio/openmeter/openmeter/productcatalog" + "github.com/openmeterio/openmeter/pkg/clock" "github.com/openmeterio/openmeter/pkg/framework/transaction" "github.com/openmeterio/openmeter/pkg/models" "github.com/openmeterio/openmeter/pkg/slicesx" @@ -27,23 +29,41 @@ func (s *service) Create(ctx context.Context, input usagebased.CreateInput) ([]u } return transaction.Run(ctx, s.adapter, func(ctx context.Context) ([]usagebased.ChargeWithGatheringLine, error) { + now := clock.Now().UTC() createIntents, err := slicesx.MapWithErr(input.Intents, func(intent usagebased.Intent) (usagebased.CreateIntent, error) { - if intent.Currency.IsCustom() && intent.SettlementMode != productcatalog.CreditOnlySettlementMode { + if intent.Currency.IsCustom() && + intent.SettlementMode == productcatalog.CreditThenInvoiceSettlementMode && + !s.enableCustomCurrency.Load() { return usagebased.CreateIntent{}, fmt.Errorf("creating usage based charge with custom currency %q: %w", intent.Currency.GetCode(), meta.ErrCustomCurrencyNotSupported) } chargeIntent := intent.Normalized() + var resolvedCostBasis *costbasis.State + if chargeIntent.CostBasis != nil { + var err error + + resolvedCostBasis, err = s.costbasisResolver.ResolveInitialState(ctx, costbasis.ResolveInitialStateInput{ + CurrencyID: chargeIntent.Currency.NamespacedID, + Intent: *chargeIntent.CostBasis, + ResolvedAt: now, + }) + if err != nil { + return usagebased.CreateIntent{}, fmt.Errorf("resolving cost basis: %w", err) + } + } + featureMeter, err := input.FeatureMeters.Get(chargeIntent.FeatureKey, false) if err != nil { return usagebased.CreateIntent{}, fmt.Errorf("resolve usage based feature for key %s: %w", chargeIntent.FeatureKey, err) } return usagebased.CreateIntent{ - Intent: chargeIntent.AsOverridableIntent(), - Annotations: chargeIntent.Annotations, - FeatureID: featureMeter.Feature.ID, - RatingEngine: s.rater.GetPreferredRatingEngineFor(chargeIntent), + Intent: chargeIntent.AsOverridableIntent(), + Annotations: chargeIntent.Annotations, + FeatureID: featureMeter.Feature.ID, + RatingEngine: s.rater.GetPreferredRatingEngineFor(chargeIntent), + ResolvedCostBasis: resolvedCostBasis, }, nil }) if err != nil { @@ -59,20 +79,6 @@ func (s *service) Create(ctx context.Context, input usagebased.CreateInput) ([]u return nil, err } - err = s.metaAdapter.RegisterCharges(ctx, meta.RegisterChargesInput{ - Namespace: input.Namespace, - Type: meta.ChargeTypeUsageBased, - Charges: lo.Map(charges, func(charge usagebased.Charge, idx int) meta.IDWithUniqueReferenceID { - return meta.IDWithUniqueReferenceID{ - ID: charge.ID, - UniqueReferenceID: charge.Intent.GetUniqueReferenceID(), - } - }), - }) - if err != nil { - return nil, err - } - return slicesx.MapWithErr(charges, func(charge usagebased.Charge) (usagebased.ChargeWithGatheringLine, error) { // For credit only flat fees we are not relying on the invoicing stack at all, so we can return early. if charge.Intent.GetSettlementMode() == productcatalog.CreditOnlySettlementMode { diff --git a/openmeter/billing/charges/usagebased/service/creditheninvoice.go b/openmeter/billing/charges/usagebased/service/creditheninvoice.go index ddeb64dd25..b25147890a 100644 --- a/openmeter/billing/charges/usagebased/service/creditheninvoice.go +++ b/openmeter/billing/charges/usagebased/service/creditheninvoice.go @@ -12,6 +12,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/billing/charges/invoiceupdater" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased" usagebasedrating "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased/service/rating" usagebasedrun "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased/service/run" @@ -98,6 +99,7 @@ func (s *CreditThenInvoiceStateMachine) configureStates() { InternalTransition(meta.TriggerShrinkToRealizedPeriod, statelessx.WithParameters(s.ShrinkToRealizedPeriod)). OnActive( statelessx.AllOf( + s.ResolveDynamicCostBasis, s.SyncFeatureIDFromFeatureMeter, s.AdvanceAfterServicePeriodTo, ), @@ -488,6 +490,54 @@ func (s *CreditThenInvoiceStateMachine) UnsupportedShrinkToRealizedPeriodOperati ) } +// ResolveDynamicCostBasis idempotently persists the dynamic cost basis +// effective at the charge's service-period start. Once resolved, the persisted +// value is authoritative and must never be overwritten by lifecycle retries. +func (s *CreditThenInvoiceStateMachine) ResolveDynamicCostBasis(ctx context.Context) error { + intent := s.Charge.Intent.GetCostBasisIntent() + if intent == nil || intent.Kind() != costbasis.ModeDynamic { + return nil + } + + if s.Charge.State.ResolvedCostBasis != nil { + return nil + } + + if s.Charge.State.CostBasisID == nil { + return models.NewGenericPreConditionFailedError( + fmt.Errorf("dynamic cost basis reference is missing for usage based charge %s", s.Charge.ID), + ) + } + + resolvedState, err := s.CostBasisResolver.ResolveDynamicState(ctx, costbasis.ResolveDynamicStateInput{ + CurrencyID: s.Charge.Intent.GetCurrency().NamespacedID, + Intent: *intent, + ServicePeriodFrom: s.Charge.Intent.GetEffectiveServicePeriod().From, + }) + if err != nil { + return fmt.Errorf("resolve dynamic cost basis for usage based charge %s: %w", s.Charge.ID, err) + } + + persisted, err := s.Adapter.SetResolvedCostBasis(ctx, costbasis.SetResolvedCostBasisInput{ + NamespacedID: models.NamespacedID{ + Namespace: s.Charge.Namespace, + ID: *s.Charge.State.CostBasisID, + }, + State: resolvedState, + }) + if err != nil { + return fmt.Errorf("persist dynamic cost basis for usage based charge %s: %w", s.Charge.ID, err) + } + + if persisted.State == nil { + return fmt.Errorf("persisted dynamic cost basis is unresolved for usage based charge %s", s.Charge.ID) + } + + s.Charge.State.ResolvedCostBasis = persisted.State + + return nil +} + func (s *CreditThenInvoiceStateMachine) handleRunsOnShrink() error { servicePeriod := s.Charge.Intent.GetEffectiveServicePeriod() newServicePeriodTo := meta.NormalizeTimestamp(servicePeriod.To) diff --git a/openmeter/billing/charges/usagebased/service/service.go b/openmeter/billing/charges/usagebased/service/service.go index a18e15c6dd..b12621f046 100644 --- a/openmeter/billing/charges/usagebased/service/service.go +++ b/openmeter/billing/charges/usagebased/service/service.go @@ -2,15 +2,19 @@ package service import ( "errors" + "sync/atomic" + "testing" "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/billing/charges/invoiceupdater" "github.com/openmeterio/openmeter/openmeter/billing/charges/lineage" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased" usagebasedrating "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased/service/rating" usagebasedrun "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased/service/run" "github.com/openmeterio/openmeter/openmeter/billing/rating" + "github.com/openmeterio/openmeter/openmeter/currencies" "github.com/openmeterio/openmeter/openmeter/productcatalog/feature" "github.com/openmeterio/openmeter/openmeter/streaming" "github.com/openmeterio/openmeter/pkg/framework/lockr" @@ -26,6 +30,7 @@ type Config struct { CustomerOverrideService billing.CustomerOverrideService FeatureService feature.FeatureConnector RatingService rating.Service + Currencies currencies.Service StreamingConnector streaming.Connector } @@ -69,6 +74,10 @@ func (c Config) Validate() error { errs = append(errs, errors.New("rating service cannot be null")) } + if c.Currencies == nil { + errs = append(errs, errors.New("currencies service cannot be null")) + } + if c.StreamingConnector == nil { errs = append(errs, errors.New("streaming connector cannot be null")) } @@ -100,6 +109,13 @@ func New(config Config) (usagebased.Service, error) { return nil, err } + costbasisResolver, err := costbasis.NewResolver(costbasis.ResolverConfig{ + Currencies: config.Currencies, + }) + if err != nil { + return nil, err + } + return &service{ adapter: config.Adapter, locker: config.Locker, @@ -110,6 +126,7 @@ func New(config Config) (usagebased.Service, error) { ratingService: config.RatingService, rater: rater, runs: runs, + costbasisResolver: costbasisResolver, }, nil } @@ -124,6 +141,9 @@ type service struct { rater usagebasedrating.Service runs *usagebasedrun.Service + + enableCustomCurrency atomic.Bool + costbasisResolver costbasis.Resolver } func (s *service) GetLineEngine() billing.LineEngine { @@ -131,3 +151,13 @@ func (s *service) GetLineEngine() billing.LineEngine { service: s, } } + +func (s *service) SetEnableCustomCurrency(t *testing.T, enabled bool) error { + if t == nil { + return errors.New("testing is nil") + } + + t.Helper() + s.enableCustomCurrency.Store(enabled) + return nil +} diff --git a/openmeter/billing/charges/usagebased/service/statemachine.go b/openmeter/billing/charges/usagebased/service/statemachine.go index 4d04d27cec..9b235eb5b6 100644 --- a/openmeter/billing/charges/usagebased/service/statemachine.go +++ b/openmeter/billing/charges/usagebased/service/statemachine.go @@ -11,6 +11,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" chargestatemachine "github.com/openmeterio/openmeter/openmeter/billing/charges/statemachine" "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased" usagebasedrating "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased/service/rating" @@ -33,6 +34,7 @@ type stateMachine struct { CustomerOverride billing.CustomerOverrideWithDetails FeatureMeter feature.FeatureMeter CurrencyCalculator currencyx.Currency + CostBasisResolver costbasis.Resolver } type StateMachine = chargestatemachine.StateMachine[usagebased.Charge] @@ -46,6 +48,7 @@ type StateMachineConfig struct { CustomerOverride billing.CustomerOverrideWithDetails FeatureMeter feature.FeatureMeter CurrencyCalculator currencyx.Currency + CostBasisResolver costbasis.Resolver } func (c StateMachineConfig) Validate() error { @@ -89,6 +92,10 @@ func (c StateMachineConfig) Validate() error { } } + if c.CostBasisResolver == nil { + errs = append(errs, errors.New("cost basis resolver is required")) + } + return errors.Join(errs...) } @@ -105,6 +112,7 @@ func newStateMachineBase(config StateMachineConfig) (*stateMachine, error) { CustomerOverride: config.CustomerOverride, FeatureMeter: config.FeatureMeter, CurrencyCalculator: config.CurrencyCalculator, + CostBasisResolver: config.CostBasisResolver, } machine, err := chargestatemachine.New(chargestatemachine.Config[usagebased.Charge, usagebased.ChargeBase, usagebased.Status]{ diff --git a/openmeter/billing/charges/usagebased/service/triggers.go b/openmeter/billing/charges/usagebased/service/triggers.go index 651fb99609..5246847422 100644 --- a/openmeter/billing/charges/usagebased/service/triggers.go +++ b/openmeter/billing/charges/usagebased/service/triggers.go @@ -34,6 +34,7 @@ func (s *service) AdvanceCharge(ctx context.Context, input usagebased.AdvanceCha CustomerOverride: input.CustomerOverride, FeatureMeter: featureMeter, CurrencyCalculator: charge.Intent.GetCurrency(), + CostBasisResolver: s.costbasisResolver, }) if err != nil { return nil, fmt.Errorf("new state machine: %w", err) @@ -230,6 +231,7 @@ func (s *service) getStateMachineConfigForCharge(ctx context.Context, charge usa CustomerOverride: customerOverride, FeatureMeter: featureMeter, CurrencyCalculator: currency, + CostBasisResolver: s.costbasisResolver, }, nil } diff --git a/openmeter/currencies/adapter/currencies.go b/openmeter/currencies/adapter/currencies.go index 1d3255e9ca..48b91c8c50 100644 --- a/openmeter/currencies/adapter/currencies.go +++ b/openmeter/currencies/adapter/currencies.go @@ -80,7 +80,7 @@ func FromDBCustomCurrency(c *entdb.CustomCurrency) (currencies.Currency, error) for _, cb := range c.Edges.CostBasisHistory { if cb != nil { - costBasisList = append(costBasisList, mapCostBasisFromDB(cb)) + costBasisList = append(costBasisList, FromDBCurrencyCostBasis(cb)) } } @@ -105,7 +105,7 @@ func FromDBCustomCurrency(c *entdb.CustomCurrency) (currencies.Currency, error) }, nil } -func mapCostBasisFromDB(c *entdb.CurrencyCostBasis) currencies.CostBasis { +func FromDBCurrencyCostBasis(c *entdb.CurrencyCostBasis) currencies.CostBasis { var effectiveTo *time.Time if c.EffectiveTo != nil { @@ -267,7 +267,7 @@ func (a *adapter) CreateCostBasis(ctx context.Context, params currencies.CreateC return currencies.CostBasis{}, fmt.Errorf("failed to create cost basis: %w", err) } - return mapCostBasisFromDB(costBasis), nil + return FromDBCurrencyCostBasis(costBasis), nil }) } @@ -292,7 +292,7 @@ func (a *adapter) GetCostBasis(ctx context.Context, params currencies.GetCostBas return currencies.CostBasis{}, fmt.Errorf("failed to get cost basis: %w", err) } - result := mapCostBasisFromDB(costBasis) + result := FromDBCurrencyCostBasis(costBasis) if params.CustomCurrency { customCurrency, err := FromDBCustomCurrency(costBasis.Edges.Currency) @@ -325,7 +325,7 @@ func (a *adapter) ListCostBases(ctx context.Context, params currencies.ListCostB return pagination.Result[currencies.CostBasis]{}, fmt.Errorf("failed to list cost bases: %w", err) } - return pagination.MapResult(paged, mapCostBasisFromDB), nil + return pagination.MapResult(paged, FromDBCurrencyCostBasis), nil }) } @@ -402,3 +402,35 @@ func WithCostBasis(q *entdb.CustomCurrencyQuery, at time.Time) *entdb.CustomCurr }) }) } + +func (a *adapter) GetCostBasisAt(ctx context.Context, params currencies.GetCostBasisAtInput) (currencies.CostBasis, error) { + return entutils.TransactingRepo(ctx, a, func(ctx context.Context, tx *adapter) (currencies.CostBasis, error) { + costBasis, err := tx.db.CurrencyCostBasis.Query(). + Where( + currencycostbasis.Namespace(params.Namespace), + currencycostbasis.CurrencyID(params.CurrencyID), + currencycostbasis.FiatCode(params.FiatCode), + currencycostbasis.EffectiveFromLTE(params.At), + currencycostbasis.Or( + currencycostbasis.EffectiveToIsNil(), + currencycostbasis.EffectiveToGT(params.At), + ), + currencycostbasis.DeletedAtIsNil(), + ). + Order(currencycostbasis.ByEffectiveFrom(sql.OrderDesc())). + First(ctx) + if entdb.IsNotFound(err) { + return currencies.CostBasis{}, models.NewGenericNotFoundError(fmt.Errorf( + "cost basis not found [currency.id=%s fiat=%s at=%s]", + params.CurrencyID, + params.FiatCode, + params.At.UTC().Format(time.RFC3339), + )) + } + if err != nil { + return currencies.CostBasis{}, fmt.Errorf("querying cost basis: %w", err) + } + + return FromDBCurrencyCostBasis(costBasis), nil + }) +} diff --git a/openmeter/currencies/adapter/currencies_test.go b/openmeter/currencies/adapter/currencies_test.go index 4eaaffda61..0644367c4c 100644 --- a/openmeter/currencies/adapter/currencies_test.go +++ b/openmeter/currencies/adapter/currencies_test.go @@ -2,7 +2,9 @@ package adapter_test import ( "testing" + "time" + "github.com/alpacahq/alpacadecimal" "github.com/samber/lo" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -10,6 +12,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/currencies" currenciestestutils "github.com/openmeterio/openmeter/openmeter/currencies/testutils" "github.com/openmeterio/openmeter/pkg/currencyx" + "github.com/openmeterio/openmeter/pkg/models" "github.com/openmeterio/openmeter/pkg/pagination" ) @@ -73,3 +76,121 @@ func TestListCustomCurrenciesFiltersCurrencyType(t *testing.T) { }) } } + +func TestGetCostBasisAt(t *testing.T) { + env := currenciestestutils.NewTestEnv(t) + t.Cleanup(func() { + env.Close(t) + }) + + namespace := currenciestestutils.NewTestNamespace(t) + currency, err := env.Service.CreateCurrency(t.Context(), currencies.CreateCurrencyInput{ + Namespace: namespace, + CurrencyDetails: currencyx.CurrencyDetails{ + Code: "TOKENS", + Name: "Tokens", + Symbol: "T", + Precision: 2, + DecimalMark: ".", + ThousandsSeparator: ",", + }, + }) + require.NoError(t, err) + + firstEffectiveFrom := time.Date(2026, time.July, 1, 0, 0, 0, 0, time.UTC) + secondEffectiveFrom := firstEffectiveFrom.Add(24 * time.Hour) + + // given: + // - consecutive USD cost bases and a EUR cost basis ending at the same boundary + firstUSD, err := env.Client.CurrencyCostBasis.Create(). + SetNamespace(namespace). + SetCurrencyID(currency.ID). + SetFiatCode("USD"). + SetRate(alpacadecimal.RequireFromString("0.01")). + SetEffectiveFrom(firstEffectiveFrom). + SetEffectiveTo(secondEffectiveFrom). + Save(t.Context()) + require.NoError(t, err) + + secondUSD, err := env.Client.CurrencyCostBasis.Create(). + SetNamespace(namespace). + SetCurrencyID(currency.ID). + SetFiatCode("USD"). + SetRate(alpacadecimal.RequireFromString("0.02")). + SetEffectiveFrom(secondEffectiveFrom). + Save(t.Context()) + require.NoError(t, err) + + _, err = env.Client.CurrencyCostBasis.Create(). + SetNamespace(namespace). + SetCurrencyID(currency.ID). + SetFiatCode("EUR"). + SetRate(alpacadecimal.RequireFromString("0.009")). + SetEffectiveFrom(firstEffectiveFrom). + SetEffectiveTo(secondEffectiveFrom). + Save(t.Context()) + require.NoError(t, err) + + testCases := []struct { + name string + fiatCode currencyx.Code + at time.Time + expectedID string + notFound bool + }{ + { + name: "effective from is inclusive", + fiatCode: "USD", + at: firstEffectiveFrom, + expectedID: firstUSD.ID, + }, + { + name: "newer cost basis wins at its effective start", + fiatCode: "USD", + at: secondEffectiveFrom, + expectedID: secondUSD.ID, + }, + { + name: "open interval remains effective", + fiatCode: "USD", + at: secondEffectiveFrom.Add(30 * 24 * time.Hour), + expectedID: secondUSD.ID, + }, + { + name: "before first interval", + fiatCode: "USD", + at: firstEffectiveFrom.Add(-time.Nanosecond), + notFound: true, + }, + { + name: "effective to is exclusive", + fiatCode: "EUR", + at: secondEffectiveFrom, + notFound: true, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + // when: + // - the cost basis effective at the requested instant is queried + result, err := env.Repository.GetCostBasisAt(t.Context(), currencies.GetCostBasisAtInput{ + Namespace: namespace, + CurrencyID: currency.ID, + FiatCode: testCase.fiatCode, + At: testCase.at, + }) + + // then: + // - interval boundaries select the matching row or return a typed not-found error + if testCase.notFound { + require.Error(t, err) + assert.True(t, models.IsGenericNotFoundError(err)) + return + } + + require.NoError(t, err) + assert.Equal(t, testCase.expectedID, result.ID) + }) + } +} diff --git a/openmeter/currencies/repository.go b/openmeter/currencies/repository.go index d08f574844..05bcea081c 100644 --- a/openmeter/currencies/repository.go +++ b/openmeter/currencies/repository.go @@ -23,5 +23,6 @@ type CurrencyRepository interface { type CostBasisRepository interface { CreateCostBasis(ctx context.Context, params CreateCostBasisInput) (CostBasis, error) GetCostBasis(ctx context.Context, params GetCostBasisInput) (CostBasis, error) + GetCostBasisAt(ctx context.Context, params GetCostBasisAtInput) (CostBasis, error) ListCostBases(ctx context.Context, params ListCostBasesInput) (pagination.Result[CostBasis], error) } diff --git a/openmeter/currencies/service.go b/openmeter/currencies/service.go index 90be039b16..60675d6d06 100644 --- a/openmeter/currencies/service.go +++ b/openmeter/currencies/service.go @@ -29,6 +29,7 @@ type CurrencyService interface { type CostBasisService interface { CreateCostBasis(ctx context.Context, params CreateCostBasisInput) (CostBasis, error) GetCostBasis(ctx context.Context, params GetCostBasisInput) (CostBasis, error) + GetCostBasisAt(ctx context.Context, params GetCostBasisAtInput) (CostBasis, error) ListCostBases(ctx context.Context, params ListCostBasesInput) (pagination.Result[CostBasis], error) } @@ -239,3 +240,36 @@ func (i GetCurrencyInput) Validate() error { return models.NewNillableGenericValidationError(errors.Join(errs...)) } + +var _ models.Validator = (*GetCostBasisAtInput)(nil) + +type GetCostBasisAtInput struct { + Namespace string `json:"namespace"` + CurrencyID string `json:"currency_id"` + FiatCode currencyx.Code `json:"fiat_code"` + At time.Time `json:"at"` +} + +func (i GetCostBasisAtInput) Validate() error { + var errs []error + + if i.Namespace == "" { + errs = append(errs, errors.New("namespace is required")) + } + + if i.CurrencyID == "" { + errs = append(errs, errors.New("currency_id is required")) + } + + if err := i.FiatCode.Validate(); err != nil { + errs = append(errs, fmt.Errorf("fiat_code: %w", err)) + } else if !i.FiatCode.IsFiat() { + errs = append(errs, fmt.Errorf("fiat_code %q must be fiat", i.FiatCode)) + } + + if i.At.IsZero() { + errs = append(errs, errors.New("at is required")) + } + + return models.NewNillableGenericValidationError(errors.Join(errs...)) +} diff --git a/openmeter/currencies/service/service.go b/openmeter/currencies/service/service.go index 8679fd4dd6..5ce87c8de2 100644 --- a/openmeter/currencies/service/service.go +++ b/openmeter/currencies/service/service.go @@ -240,3 +240,13 @@ func (s *service) GetCurrency(ctx context.Context, params currencies.GetCurrency return s.adapter.GetCurrency(ctx, params) }) } + +func (s *service) GetCostBasisAt(ctx context.Context, params currencies.GetCostBasisAtInput) (currencies.CostBasis, error) { + if err := params.Validate(); err != nil { + return currencies.CostBasis{}, models.NewGenericValidationError(fmt.Errorf("invalid input parameters: %w", err)) + } + + return transaction.Run(ctx, s.adapter, func(ctx context.Context) (currencies.CostBasis, error) { + return s.adapter.GetCostBasisAt(ctx, params) + }) +} diff --git a/openmeter/ent/db/chargecreditpurchase.go b/openmeter/ent/db/chargecreditpurchase.go index 65d59964bd..d1ed58e091 100644 --- a/openmeter/ent/db/chargecreditpurchase.go +++ b/openmeter/ent/db/chargecreditpurchase.go @@ -17,6 +17,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecreditgrant" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseexternalpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseinvoicedpayment" @@ -106,6 +107,8 @@ type ChargeCreditPurchase struct { Key *string `json:"key,omitempty"` // VoidedAt holds the value of the "voided_at" field. VoidedAt *time.Time `json:"voided_at,omitempty"` + // CostBasisID holds the value of the "cost_basis_id" field. + CostBasisID *string `json:"cost_basis_id,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the ChargeCreditPurchaseQuery when eager-loading is set. Edges ChargeCreditPurchaseEdges `json:"edges"` @@ -120,6 +123,8 @@ type ChargeCreditPurchaseEdges struct { InvoicedPayment *ChargeCreditPurchaseInvoicedPayment `json:"invoiced_payment,omitempty"` // CreditGrant holds the value of the credit_grant edge. CreditGrant *ChargeCreditPurchaseCreditGrant `json:"credit_grant,omitempty"` + // CostBasis holds the value of the cost_basis edge. + CostBasis *ChargeCreditPurchaseCostBasis `json:"cost_basis,omitempty"` // Charge holds the value of the charge edge. Charge *Charge `json:"charge,omitempty"` // Subscription holds the value of the subscription edge. @@ -136,7 +141,7 @@ type ChargeCreditPurchaseEdges struct { CustomCurrency *CustomCurrency `json:"custom_currency,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 } // ExternalPaymentOrErr returns the ExternalPayment value or an error if the edge @@ -172,12 +177,23 @@ func (e ChargeCreditPurchaseEdges) CreditGrantOrErr() (*ChargeCreditPurchaseCred return nil, &NotLoadedError{edge: "credit_grant"} } +// CostBasisOrErr returns the CostBasis value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChargeCreditPurchaseEdges) CostBasisOrErr() (*ChargeCreditPurchaseCostBasis, error) { + if e.CostBasis != nil { + return e.CostBasis, nil + } else if e.loadedTypes[3] { + return nil, &NotFoundError{label: chargecreditpurchasecostbasis.Label} + } + return nil, &NotLoadedError{edge: "cost_basis"} +} + // 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 ChargeCreditPurchaseEdges) ChargeOrErr() (*Charge, error) { if e.Charge != nil { return e.Charge, nil - } else if e.loadedTypes[3] { + } else if e.loadedTypes[4] { return nil, &NotFoundError{label: charge.Label} } return nil, &NotLoadedError{edge: "charge"} @@ -188,7 +204,7 @@ func (e ChargeCreditPurchaseEdges) ChargeOrErr() (*Charge, error) { func (e ChargeCreditPurchaseEdges) SubscriptionOrErr() (*Subscription, error) { if e.Subscription != nil { return e.Subscription, nil - } else if e.loadedTypes[4] { + } else if e.loadedTypes[5] { return nil, &NotFoundError{label: subscription.Label} } return nil, &NotLoadedError{edge: "subscription"} @@ -199,7 +215,7 @@ func (e ChargeCreditPurchaseEdges) SubscriptionOrErr() (*Subscription, error) { func (e ChargeCreditPurchaseEdges) SubscriptionPhaseOrErr() (*SubscriptionPhase, error) { if e.SubscriptionPhase != nil { return e.SubscriptionPhase, nil - } else if e.loadedTypes[5] { + } else if e.loadedTypes[6] { return nil, &NotFoundError{label: subscriptionphase.Label} } return nil, &NotLoadedError{edge: "subscription_phase"} @@ -210,7 +226,7 @@ func (e ChargeCreditPurchaseEdges) SubscriptionPhaseOrErr() (*SubscriptionPhase, func (e ChargeCreditPurchaseEdges) SubscriptionItemOrErr() (*SubscriptionItem, error) { if e.SubscriptionItem != nil { return e.SubscriptionItem, nil - } else if e.loadedTypes[6] { + } else if e.loadedTypes[7] { return nil, &NotFoundError{label: subscriptionitem.Label} } return nil, &NotLoadedError{edge: "subscription_item"} @@ -221,7 +237,7 @@ func (e ChargeCreditPurchaseEdges) SubscriptionItemOrErr() (*SubscriptionItem, e func (e ChargeCreditPurchaseEdges) CustomerOrErr() (*Customer, error) { if e.Customer != nil { return e.Customer, nil - } else if e.loadedTypes[7] { + } else if e.loadedTypes[8] { return nil, &NotFoundError{label: customer.Label} } return nil, &NotLoadedError{edge: "customer"} @@ -232,7 +248,7 @@ func (e ChargeCreditPurchaseEdges) CustomerOrErr() (*Customer, error) { func (e ChargeCreditPurchaseEdges) TaxCodeOrErr() (*TaxCode, error) { if e.TaxCode != nil { return e.TaxCode, nil - } else if e.loadedTypes[8] { + } else if e.loadedTypes[9] { return nil, &NotFoundError{label: dbtaxcode.Label} } return nil, &NotLoadedError{edge: "tax_code"} @@ -243,7 +259,7 @@ func (e ChargeCreditPurchaseEdges) TaxCodeOrErr() (*TaxCode, error) { func (e ChargeCreditPurchaseEdges) CustomCurrencyOrErr() (*CustomCurrency, error) { if e.CustomCurrency != nil { return e.CustomCurrency, nil - } else if e.loadedTypes[9] { + } else if e.loadedTypes[10] { return nil, &NotFoundError{label: customcurrency.Label} } return nil, &NotLoadedError{edge: "custom_currency"} @@ -262,7 +278,7 @@ func (*ChargeCreditPurchase) scanValues(columns []string) ([]any, error) { values[i] = new(pq.StringArray) case chargecreditpurchase.FieldPriority: values[i] = new(sql.NullInt64) - case chargecreditpurchase.FieldID, chargecreditpurchase.FieldCustomerID, chargecreditpurchase.FieldStatus, chargecreditpurchase.FieldUniqueReferenceID, chargecreditpurchase.FieldFiatCurrencyCode, chargecreditpurchase.FieldCustomCurrencyID, chargecreditpurchase.FieldManagedBy, chargecreditpurchase.FieldSubscriptionID, chargecreditpurchase.FieldSubscriptionPhaseID, chargecreditpurchase.FieldSubscriptionItemID, chargecreditpurchase.FieldTaxCodeID, chargecreditpurchase.FieldTaxBehavior, chargecreditpurchase.FieldNamespace, chargecreditpurchase.FieldName, chargecreditpurchase.FieldDescription, chargecreditpurchase.FieldStatusDetailed, chargecreditpurchase.FieldKey: + case chargecreditpurchase.FieldID, chargecreditpurchase.FieldCustomerID, chargecreditpurchase.FieldStatus, chargecreditpurchase.FieldUniqueReferenceID, chargecreditpurchase.FieldFiatCurrencyCode, chargecreditpurchase.FieldCustomCurrencyID, chargecreditpurchase.FieldManagedBy, chargecreditpurchase.FieldSubscriptionID, chargecreditpurchase.FieldSubscriptionPhaseID, chargecreditpurchase.FieldSubscriptionItemID, chargecreditpurchase.FieldTaxCodeID, chargecreditpurchase.FieldTaxBehavior, chargecreditpurchase.FieldNamespace, chargecreditpurchase.FieldName, chargecreditpurchase.FieldDescription, chargecreditpurchase.FieldStatusDetailed, chargecreditpurchase.FieldKey, chargecreditpurchase.FieldCostBasisID: values[i] = new(sql.NullString) case chargecreditpurchase.FieldServicePeriodFrom, chargecreditpurchase.FieldServicePeriodTo, chargecreditpurchase.FieldBillingPeriodFrom, chargecreditpurchase.FieldBillingPeriodTo, chargecreditpurchase.FieldFullServicePeriodFrom, chargecreditpurchase.FieldFullServicePeriodTo, chargecreditpurchase.FieldAdvanceAfter, chargecreditpurchase.FieldCreatedAt, chargecreditpurchase.FieldUpdatedAt, chargecreditpurchase.FieldDeletedAt, chargecreditpurchase.FieldEffectiveAt, chargecreditpurchase.FieldExpiresAt, chargecreditpurchase.FieldVoidedAt: values[i] = new(sql.NullTime) @@ -518,6 +534,13 @@ func (_m *ChargeCreditPurchase) assignValues(columns []string, values []any) err _m.VoidedAt = new(time.Time) *_m.VoidedAt = value.Time } + case chargecreditpurchase.FieldCostBasisID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field cost_basis_id", values[i]) + } else if value.Valid { + _m.CostBasisID = new(string) + *_m.CostBasisID = value.String + } default: _m.selectValues.Set(columns[i], values[i]) } @@ -546,6 +569,11 @@ func (_m *ChargeCreditPurchase) QueryCreditGrant() *ChargeCreditPurchaseCreditGr return NewChargeCreditPurchaseClient(_m.config).QueryCreditGrant(_m) } +// QueryCostBasis queries the "cost_basis" edge of the ChargeCreditPurchase entity. +func (_m *ChargeCreditPurchase) QueryCostBasis() *ChargeCreditPurchaseCostBasisQuery { + return NewChargeCreditPurchaseClient(_m.config).QueryCostBasis(_m) +} + // QueryCharge queries the "charge" edge of the ChargeCreditPurchase entity. func (_m *ChargeCreditPurchase) QueryCharge() *ChargeQuery { return NewChargeCreditPurchaseClient(_m.config).QueryCharge(_m) @@ -738,6 +766,11 @@ func (_m *ChargeCreditPurchase) String() string { builder.WriteString("voided_at=") builder.WriteString(v.Format(time.ANSIC)) } + builder.WriteString(", ") + if v := _m.CostBasisID; v != nil { + builder.WriteString("cost_basis_id=") + builder.WriteString(*v) + } builder.WriteByte(')') return builder.String() } diff --git a/openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.go b/openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.go index 3e57eb0230..4edf3b0ad3 100644 --- a/openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.go +++ b/openmeter/ent/db/chargecreditpurchase/chargecreditpurchase.go @@ -90,12 +90,16 @@ const ( FieldKey = "key" // FieldVoidedAt holds the string denoting the voided_at field in the database. FieldVoidedAt = "voided_at" + // FieldCostBasisID holds the string denoting the cost_basis_id field in the database. + FieldCostBasisID = "cost_basis_id" // EdgeExternalPayment holds the string denoting the external_payment edge name in mutations. EdgeExternalPayment = "external_payment" // EdgeInvoicedPayment holds the string denoting the invoiced_payment edge name in mutations. EdgeInvoicedPayment = "invoiced_payment" // EdgeCreditGrant holds the string denoting the credit_grant edge name in mutations. EdgeCreditGrant = "credit_grant" + // EdgeCostBasis holds the string denoting the cost_basis edge name in mutations. + EdgeCostBasis = "cost_basis" // EdgeCharge holds the string denoting the charge edge name in mutations. EdgeCharge = "charge" // EdgeSubscription holds the string denoting the subscription edge name in mutations. @@ -133,6 +137,13 @@ const ( CreditGrantInverseTable = "charge_credit_purchase_credit_grants" // CreditGrantColumn is the table column denoting the credit_grant relation/edge. CreditGrantColumn = "charge_id" + // CostBasisTable is the table that holds the cost_basis relation/edge. + CostBasisTable = "charge_credit_purchases" + // CostBasisInverseTable is the table name for the ChargeCreditPurchaseCostBasis entity. + // It exists in this package in order to avoid circular dependency with the "chargecreditpurchasecostbasis" package. + CostBasisInverseTable = "charge_credit_purchase_cost_bases" + // CostBasisColumn is the table column denoting the cost_basis relation/edge. + CostBasisColumn = "cost_basis_id" // ChargeTable is the table that holds the charge relation/edge. ChargeTable = "charges" // ChargeInverseTable is the table name for the Charge entity. @@ -222,6 +233,7 @@ var Columns = []string{ FieldStatusDetailed, FieldKey, FieldVoidedAt, + FieldCostBasisID, } // ValidColumn reports if the column name is valid (part of the table columns). @@ -472,6 +484,11 @@ func ByVoidedAt(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldVoidedAt, opts...).ToFunc() } +// ByCostBasisID orders the results by the cost_basis_id field. +func ByCostBasisID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCostBasisID, opts...).ToFunc() +} + // ByExternalPaymentField orders the results by external_payment field. func ByExternalPaymentField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -493,6 +510,13 @@ func ByCreditGrantField(field string, opts ...sql.OrderTermOption) OrderOption { } } +// ByCostBasisField orders the results by cost_basis field. +func ByCostBasisField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCostBasisStep(), sql.OrderByField(field, opts...)) + } +} + // ByChargeField orders the results by charge field. func ByChargeField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -562,6 +586,13 @@ func newCreditGrantStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2O, false, CreditGrantTable, CreditGrantColumn), ) } +func newCostBasisStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CostBasisInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CostBasisTable, CostBasisColumn), + ) +} func newChargeStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/openmeter/ent/db/chargecreditpurchase/where.go b/openmeter/ent/db/chargecreditpurchase/where.go index 35e17ef797..32af733f1c 100644 --- a/openmeter/ent/db/chargecreditpurchase/where.go +++ b/openmeter/ent/db/chargecreditpurchase/where.go @@ -213,6 +213,11 @@ func VoidedAt(v time.Time) predicate.ChargeCreditPurchase { return predicate.ChargeCreditPurchase(sql.FieldEQ(FieldVoidedAt, v)) } +// CostBasisID applies equality check predicate on the "cost_basis_id" field. It's identical to CostBasisIDEQ. +func CostBasisID(v string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldEQ(FieldCostBasisID, v)) +} + // CustomerIDEQ applies the EQ predicate on the "customer_id" field. func CustomerIDEQ(v string) predicate.ChargeCreditPurchase { return predicate.ChargeCreditPurchase(sql.FieldEQ(FieldCustomerID, v)) @@ -1952,6 +1957,81 @@ func VoidedAtNotNil() predicate.ChargeCreditPurchase { return predicate.ChargeCreditPurchase(sql.FieldNotNull(FieldVoidedAt)) } +// CostBasisIDEQ applies the EQ predicate on the "cost_basis_id" field. +func CostBasisIDEQ(v string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldEQ(FieldCostBasisID, v)) +} + +// CostBasisIDNEQ applies the NEQ predicate on the "cost_basis_id" field. +func CostBasisIDNEQ(v string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldNEQ(FieldCostBasisID, v)) +} + +// CostBasisIDIn applies the In predicate on the "cost_basis_id" field. +func CostBasisIDIn(vs ...string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldIn(FieldCostBasisID, vs...)) +} + +// CostBasisIDNotIn applies the NotIn predicate on the "cost_basis_id" field. +func CostBasisIDNotIn(vs ...string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldNotIn(FieldCostBasisID, vs...)) +} + +// CostBasisIDGT applies the GT predicate on the "cost_basis_id" field. +func CostBasisIDGT(v string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldGT(FieldCostBasisID, v)) +} + +// CostBasisIDGTE applies the GTE predicate on the "cost_basis_id" field. +func CostBasisIDGTE(v string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldGTE(FieldCostBasisID, v)) +} + +// CostBasisIDLT applies the LT predicate on the "cost_basis_id" field. +func CostBasisIDLT(v string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldLT(FieldCostBasisID, v)) +} + +// CostBasisIDLTE applies the LTE predicate on the "cost_basis_id" field. +func CostBasisIDLTE(v string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldLTE(FieldCostBasisID, v)) +} + +// CostBasisIDContains applies the Contains predicate on the "cost_basis_id" field. +func CostBasisIDContains(v string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldContains(FieldCostBasisID, v)) +} + +// CostBasisIDHasPrefix applies the HasPrefix predicate on the "cost_basis_id" field. +func CostBasisIDHasPrefix(v string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldHasPrefix(FieldCostBasisID, v)) +} + +// CostBasisIDHasSuffix applies the HasSuffix predicate on the "cost_basis_id" field. +func CostBasisIDHasSuffix(v string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldHasSuffix(FieldCostBasisID, v)) +} + +// CostBasisIDIsNil applies the IsNil predicate on the "cost_basis_id" field. +func CostBasisIDIsNil() predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldIsNull(FieldCostBasisID)) +} + +// CostBasisIDNotNil applies the NotNil predicate on the "cost_basis_id" field. +func CostBasisIDNotNil() predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldNotNull(FieldCostBasisID)) +} + +// CostBasisIDEqualFold applies the EqualFold predicate on the "cost_basis_id" field. +func CostBasisIDEqualFold(v string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldEqualFold(FieldCostBasisID, v)) +} + +// CostBasisIDContainsFold applies the ContainsFold predicate on the "cost_basis_id" field. +func CostBasisIDContainsFold(v string) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(sql.FieldContainsFold(FieldCostBasisID, v)) +} + // HasExternalPayment applies the HasEdge predicate on the "external_payment" edge. func HasExternalPayment() predicate.ChargeCreditPurchase { return predicate.ChargeCreditPurchase(func(s *sql.Selector) { @@ -2021,6 +2101,29 @@ func HasCreditGrantWith(preds ...predicate.ChargeCreditPurchaseCreditGrant) pred }) } +// HasCostBasis applies the HasEdge predicate on the "cost_basis" edge. +func HasCostBasis() predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CostBasisTable, CostBasisColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasCostBasisWith applies the HasEdge predicate on the "cost_basis" edge with a given conditions (other predicates). +func HasCostBasisWith(preds ...predicate.ChargeCreditPurchaseCostBasis) predicate.ChargeCreditPurchase { + return predicate.ChargeCreditPurchase(func(s *sql.Selector) { + step := newCostBasisStep() + 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.ChargeCreditPurchase { return predicate.ChargeCreditPurchase(func(s *sql.Selector) { diff --git a/openmeter/ent/db/chargecreditpurchase_create.go b/openmeter/ent/db/chargecreditpurchase_create.go index e85c2cefdd..2934b9e908 100644 --- a/openmeter/ent/db/chargecreditpurchase_create.go +++ b/openmeter/ent/db/chargecreditpurchase_create.go @@ -19,6 +19,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecreditgrant" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseexternalpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseinvoicedpayment" @@ -387,6 +388,20 @@ func (_c *ChargeCreditPurchaseCreate) SetNillableVoidedAt(v *time.Time) *ChargeC return _c } +// SetCostBasisID sets the "cost_basis_id" field. +func (_c *ChargeCreditPurchaseCreate) SetCostBasisID(v string) *ChargeCreditPurchaseCreate { + _c.mutation.SetCostBasisID(v) + return _c +} + +// SetNillableCostBasisID sets the "cost_basis_id" field if the given value is not nil. +func (_c *ChargeCreditPurchaseCreate) SetNillableCostBasisID(v *string) *ChargeCreditPurchaseCreate { + if v != nil { + _c.SetCostBasisID(*v) + } + return _c +} + // SetID sets the "id" field. func (_c *ChargeCreditPurchaseCreate) SetID(v string) *ChargeCreditPurchaseCreate { _c.mutation.SetID(v) @@ -458,6 +473,11 @@ func (_c *ChargeCreditPurchaseCreate) SetCreditGrant(v *ChargeCreditPurchaseCred return _c.SetCreditGrantID(v.ID) } +// SetCostBasis sets the "cost_basis" edge to the ChargeCreditPurchaseCostBasis entity. +func (_c *ChargeCreditPurchaseCreate) SetCostBasis(v *ChargeCreditPurchaseCostBasis) *ChargeCreditPurchaseCreate { + return _c.SetCostBasisID(v.ID) +} + // SetChargeID sets the "charge" edge to the Charge entity by ID. func (_c *ChargeCreditPurchaseCreate) SetChargeID(id string) *ChargeCreditPurchaseCreate { _c.mutation.SetChargeID(id) @@ -872,6 +892,23 @@ func (_c *ChargeCreditPurchaseCreate) createSpec() (*ChargeCreditPurchase, *sqlg } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.CostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargecreditpurchase.CostBasisTable, + Columns: []string{chargecreditpurchase.CostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(chargecreditpurchasecostbasis.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.CostBasisID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.ChargeIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2O, @@ -1377,6 +1414,9 @@ func (u *ChargeCreditPurchaseUpsertOne) UpdateNewValues() *ChargeCreditPurchaseU if _, exists := u.create.mutation.Key(); exists { s.SetIgnore(chargecreditpurchase.FieldKey) } + if _, exists := u.create.mutation.CostBasisID(); exists { + s.SetIgnore(chargecreditpurchase.FieldCostBasisID) + } })) return u } @@ -1957,6 +1997,9 @@ func (u *ChargeCreditPurchaseUpsertBulk) UpdateNewValues() *ChargeCreditPurchase if _, exists := b.mutation.Key(); exists { s.SetIgnore(chargecreditpurchase.FieldKey) } + if _, exists := b.mutation.CostBasisID(); exists { + s.SetIgnore(chargecreditpurchase.FieldCostBasisID) + } } })) return u diff --git a/openmeter/ent/db/chargecreditpurchase_query.go b/openmeter/ent/db/chargecreditpurchase_query.go index d233a66413..1fd5166df3 100644 --- a/openmeter/ent/db/chargecreditpurchase_query.go +++ b/openmeter/ent/db/chargecreditpurchase_query.go @@ -15,6 +15,7 @@ import ( "entgo.io/ent/schema/field" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecreditgrant" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseexternalpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseinvoicedpayment" @@ -37,6 +38,7 @@ type ChargeCreditPurchaseQuery struct { withExternalPayment *ChargeCreditPurchaseExternalPaymentQuery withInvoicedPayment *ChargeCreditPurchaseInvoicedPaymentQuery withCreditGrant *ChargeCreditPurchaseCreditGrantQuery + withCostBasis *ChargeCreditPurchaseCostBasisQuery withCharge *ChargeQuery withSubscription *SubscriptionQuery withSubscriptionPhase *SubscriptionPhaseQuery @@ -147,6 +149,28 @@ func (_q *ChargeCreditPurchaseQuery) QueryCreditGrant() *ChargeCreditPurchaseCre return query } +// QueryCostBasis chains the current query on the "cost_basis" edge. +func (_q *ChargeCreditPurchaseQuery) QueryCostBasis() *ChargeCreditPurchaseCostBasisQuery { + query := (&ChargeCreditPurchaseCostBasisClient{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(chargecreditpurchase.Table, chargecreditpurchase.FieldID, selector), + sqlgraph.To(chargecreditpurchasecostbasis.Table, chargecreditpurchasecostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargecreditpurchase.CostBasisTable, chargecreditpurchase.CostBasisColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryCharge chains the current query on the "charge" edge. func (_q *ChargeCreditPurchaseQuery) QueryCharge() *ChargeQuery { query := (&ChargeClient{config: _q.config}).Query() @@ -496,6 +520,7 @@ func (_q *ChargeCreditPurchaseQuery) Clone() *ChargeCreditPurchaseQuery { withExternalPayment: _q.withExternalPayment.Clone(), withInvoicedPayment: _q.withInvoicedPayment.Clone(), withCreditGrant: _q.withCreditGrant.Clone(), + withCostBasis: _q.withCostBasis.Clone(), withCharge: _q.withCharge.Clone(), withSubscription: _q.withSubscription.Clone(), withSubscriptionPhase: _q.withSubscriptionPhase.Clone(), @@ -542,6 +567,17 @@ func (_q *ChargeCreditPurchaseQuery) WithCreditGrant(opts ...func(*ChargeCreditP return _q } +// WithCostBasis tells the query-builder to eager-load the nodes that are connected to +// the "cost_basis" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeCreditPurchaseQuery) WithCostBasis(opts ...func(*ChargeCreditPurchaseCostBasisQuery)) *ChargeCreditPurchaseQuery { + query := (&ChargeCreditPurchaseCostBasisClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withCostBasis = 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 *ChargeCreditPurchaseQuery) WithCharge(opts ...func(*ChargeQuery)) *ChargeCreditPurchaseQuery { @@ -697,10 +733,11 @@ func (_q *ChargeCreditPurchaseQuery) sqlAll(ctx context.Context, hooks ...queryH var ( nodes = []*ChargeCreditPurchase{} _spec = _q.querySpec() - loadedTypes = [10]bool{ + loadedTypes = [11]bool{ _q.withExternalPayment != nil, _q.withInvoicedPayment != nil, _q.withCreditGrant != nil, + _q.withCostBasis != nil, _q.withCharge != nil, _q.withSubscription != nil, _q.withSubscriptionPhase != nil, @@ -749,6 +786,12 @@ func (_q *ChargeCreditPurchaseQuery) sqlAll(ctx context.Context, hooks ...queryH return nil, err } } + if query := _q.withCostBasis; query != nil { + if err := _q.loadCostBasis(ctx, query, nodes, nil, + func(n *ChargeCreditPurchase, e *ChargeCreditPurchaseCostBasis) { n.Edges.CostBasis = e }); err != nil { + return nil, err + } + } if query := _q.withCharge; query != nil { if err := _q.loadCharge(ctx, query, nodes, nil, func(n *ChargeCreditPurchase, e *Charge) { n.Edges.Charge = e }); err != nil { @@ -875,6 +918,38 @@ func (_q *ChargeCreditPurchaseQuery) loadCreditGrant(ctx context.Context, query } return nil } +func (_q *ChargeCreditPurchaseQuery) loadCostBasis(ctx context.Context, query *ChargeCreditPurchaseCostBasisQuery, nodes []*ChargeCreditPurchase, init func(*ChargeCreditPurchase), assign func(*ChargeCreditPurchase, *ChargeCreditPurchaseCostBasis)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*ChargeCreditPurchase) + for i := range nodes { + if nodes[i].CostBasisID == nil { + continue + } + fk := *nodes[i].CostBasisID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(chargecreditpurchasecostbasis.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 "cost_basis_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} func (_q *ChargeCreditPurchaseQuery) loadCharge(ctx context.Context, query *ChargeQuery, nodes []*ChargeCreditPurchase, init func(*ChargeCreditPurchase), assign func(*ChargeCreditPurchase, *Charge)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[string]*ChargeCreditPurchase) @@ -1120,6 +1195,9 @@ func (_q *ChargeCreditPurchaseQuery) querySpec() *sqlgraph.QuerySpec { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } + if _q.withCostBasis != nil { + _spec.Node.AddColumnOnce(chargecreditpurchase.FieldCostBasisID) + } if _q.withSubscription != nil { _spec.Node.AddColumnOnce(chargecreditpurchase.FieldSubscriptionID) } diff --git a/openmeter/ent/db/chargecreditpurchasecostbasis.go b/openmeter/ent/db/chargecreditpurchasecostbasis.go new file mode 100644 index 0000000000..2009cc477e --- /dev/null +++ b/openmeter/ent/db/chargecreditpurchasecostbasis.go @@ -0,0 +1,314 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/alpacahq/alpacadecimal" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/currencycostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" + "github.com/openmeterio/openmeter/pkg/currencyx" +) + +// ChargeCreditPurchaseCostBasis is the model entity for the ChargeCreditPurchaseCostBasis schema. +type ChargeCreditPurchaseCostBasis struct { + config `json:"-"` + // ID of the ent. + ID string `json:"id,omitempty"` + // Mode holds the value of the "mode" field. + Mode costbasis.Mode `json:"mode,omitempty"` + // FiatCurrency holds the value of the "fiat_currency" field. + FiatCurrency currencyx.FiatCode `json:"fiat_currency,omitempty"` + // CurrencyCostBasisID holds the value of the "currency_cost_basis_id" field. + CurrencyCostBasisID *string `json:"currency_cost_basis_id,omitempty"` + // ResolvedCostBasisID holds the value of the "resolved_cost_basis_id" field. + ResolvedCostBasisID *string `json:"resolved_cost_basis_id,omitempty"` + // CurrencyID holds the value of the "currency_id" field. + CurrencyID string `json:"currency_id,omitempty"` + // ManualRate holds the value of the "manual_rate" field. + ManualRate *alpacadecimal.Decimal `json:"manual_rate,omitempty"` + // ResolvedCostBasis holds the value of the "resolved_cost_basis" field. + ResolvedCostBasis *alpacadecimal.Decimal `json:"resolved_cost_basis,omitempty"` + // ResolvedAt holds the value of the "resolved_at" field. + ResolvedAt *time.Time `json:"resolved_at,omitempty"` + // Namespace holds the value of the "namespace" field. + Namespace string `json:"namespace,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"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the ChargeCreditPurchaseCostBasisQuery when eager-loading is set. + Edges ChargeCreditPurchaseCostBasisEdges `json:"edges"` + selectValues sql.SelectValues +} + +// ChargeCreditPurchaseCostBasisEdges holds the relations/edges for other nodes in the graph. +type ChargeCreditPurchaseCostBasisEdges struct { + // CurrencyCostBasis holds the value of the currency_cost_basis edge. + CurrencyCostBasis *CurrencyCostBasis `json:"currency_cost_basis,omitempty"` + // ResolvedCurrencyCostBasis holds the value of the resolved_currency_cost_basis edge. + ResolvedCurrencyCostBasis *CurrencyCostBasis `json:"resolved_currency_cost_basis,omitempty"` + // CustomCurrency holds the value of the custom_currency edge. + CustomCurrency *CustomCurrency `json:"custom_currency,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [3]bool +} + +// CurrencyCostBasisOrErr returns the CurrencyCostBasis value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChargeCreditPurchaseCostBasisEdges) CurrencyCostBasisOrErr() (*CurrencyCostBasis, error) { + if e.CurrencyCostBasis != nil { + return e.CurrencyCostBasis, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: currencycostbasis.Label} + } + return nil, &NotLoadedError{edge: "currency_cost_basis"} +} + +// ResolvedCurrencyCostBasisOrErr returns the ResolvedCurrencyCostBasis value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChargeCreditPurchaseCostBasisEdges) ResolvedCurrencyCostBasisOrErr() (*CurrencyCostBasis, error) { + if e.ResolvedCurrencyCostBasis != nil { + return e.ResolvedCurrencyCostBasis, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: currencycostbasis.Label} + } + return nil, &NotLoadedError{edge: "resolved_currency_cost_basis"} +} + +// CustomCurrencyOrErr returns the CustomCurrency value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChargeCreditPurchaseCostBasisEdges) CustomCurrencyOrErr() (*CustomCurrency, error) { + if e.CustomCurrency != nil { + return e.CustomCurrency, nil + } else if e.loadedTypes[2] { + return nil, &NotFoundError{label: customcurrency.Label} + } + return nil, &NotLoadedError{edge: "custom_currency"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*ChargeCreditPurchaseCostBasis) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case chargecreditpurchasecostbasis.FieldManualRate, chargecreditpurchasecostbasis.FieldResolvedCostBasis: + values[i] = &sql.NullScanner{S: new(alpacadecimal.Decimal)} + case chargecreditpurchasecostbasis.FieldID, chargecreditpurchasecostbasis.FieldMode, chargecreditpurchasecostbasis.FieldFiatCurrency, chargecreditpurchasecostbasis.FieldCurrencyCostBasisID, chargecreditpurchasecostbasis.FieldResolvedCostBasisID, chargecreditpurchasecostbasis.FieldCurrencyID, chargecreditpurchasecostbasis.FieldNamespace: + values[i] = new(sql.NullString) + case chargecreditpurchasecostbasis.FieldResolvedAt, chargecreditpurchasecostbasis.FieldCreatedAt, chargecreditpurchasecostbasis.FieldUpdatedAt, chargecreditpurchasecostbasis.FieldDeletedAt: + values[i] = new(sql.NullTime) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the ChargeCreditPurchaseCostBasis fields. +func (_m *ChargeCreditPurchaseCostBasis) 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 chargecreditpurchasecostbasis.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 chargecreditpurchasecostbasis.FieldMode: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field mode", values[i]) + } else if value.Valid { + _m.Mode = costbasis.Mode(value.String) + } + case chargecreditpurchasecostbasis.FieldFiatCurrency: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field fiat_currency", values[i]) + } else if value.Valid { + _m.FiatCurrency = currencyx.FiatCode(value.String) + } + case chargecreditpurchasecostbasis.FieldCurrencyCostBasisID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field currency_cost_basis_id", values[i]) + } else if value.Valid { + _m.CurrencyCostBasisID = new(string) + *_m.CurrencyCostBasisID = value.String + } + case chargecreditpurchasecostbasis.FieldResolvedCostBasisID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field resolved_cost_basis_id", values[i]) + } else if value.Valid { + _m.ResolvedCostBasisID = new(string) + *_m.ResolvedCostBasisID = value.String + } + case chargecreditpurchasecostbasis.FieldCurrencyID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field currency_id", values[i]) + } else if value.Valid { + _m.CurrencyID = value.String + } + case chargecreditpurchasecostbasis.FieldManualRate: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field manual_rate", values[i]) + } else if value.Valid { + _m.ManualRate = new(alpacadecimal.Decimal) + *_m.ManualRate = *value.S.(*alpacadecimal.Decimal) + } + case chargecreditpurchasecostbasis.FieldResolvedCostBasis: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field resolved_cost_basis", values[i]) + } else if value.Valid { + _m.ResolvedCostBasis = new(alpacadecimal.Decimal) + *_m.ResolvedCostBasis = *value.S.(*alpacadecimal.Decimal) + } + case chargecreditpurchasecostbasis.FieldResolvedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field resolved_at", values[i]) + } else if value.Valid { + _m.ResolvedAt = new(time.Time) + *_m.ResolvedAt = value.Time + } + case chargecreditpurchasecostbasis.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 chargecreditpurchasecostbasis.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 chargecreditpurchasecostbasis.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 chargecreditpurchasecostbasis.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 + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the ChargeCreditPurchaseCostBasis. +// This includes values selected through modifiers, order, etc. +func (_m *ChargeCreditPurchaseCostBasis) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryCurrencyCostBasis queries the "currency_cost_basis" edge of the ChargeCreditPurchaseCostBasis entity. +func (_m *ChargeCreditPurchaseCostBasis) QueryCurrencyCostBasis() *CurrencyCostBasisQuery { + return NewChargeCreditPurchaseCostBasisClient(_m.config).QueryCurrencyCostBasis(_m) +} + +// QueryResolvedCurrencyCostBasis queries the "resolved_currency_cost_basis" edge of the ChargeCreditPurchaseCostBasis entity. +func (_m *ChargeCreditPurchaseCostBasis) QueryResolvedCurrencyCostBasis() *CurrencyCostBasisQuery { + return NewChargeCreditPurchaseCostBasisClient(_m.config).QueryResolvedCurrencyCostBasis(_m) +} + +// QueryCustomCurrency queries the "custom_currency" edge of the ChargeCreditPurchaseCostBasis entity. +func (_m *ChargeCreditPurchaseCostBasis) QueryCustomCurrency() *CustomCurrencyQuery { + return NewChargeCreditPurchaseCostBasisClient(_m.config).QueryCustomCurrency(_m) +} + +// Update returns a builder for updating this ChargeCreditPurchaseCostBasis. +// Note that you need to call ChargeCreditPurchaseCostBasis.Unwrap() before calling this method if this ChargeCreditPurchaseCostBasis +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *ChargeCreditPurchaseCostBasis) Update() *ChargeCreditPurchaseCostBasisUpdateOne { + return NewChargeCreditPurchaseCostBasisClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCostBasis) Unwrap() *ChargeCreditPurchaseCostBasis { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("db: ChargeCreditPurchaseCostBasis is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *ChargeCreditPurchaseCostBasis) String() string { + var builder strings.Builder + builder.WriteString("ChargeCreditPurchaseCostBasis(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("mode=") + builder.WriteString(fmt.Sprintf("%v", _m.Mode)) + builder.WriteString(", ") + builder.WriteString("fiat_currency=") + builder.WriteString(fmt.Sprintf("%v", _m.FiatCurrency)) + builder.WriteString(", ") + if v := _m.CurrencyCostBasisID; v != nil { + builder.WriteString("currency_cost_basis_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.ResolvedCostBasisID; v != nil { + builder.WriteString("resolved_cost_basis_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") + builder.WriteString("currency_id=") + builder.WriteString(_m.CurrencyID) + builder.WriteString(", ") + if v := _m.ManualRate; v != nil { + builder.WriteString("manual_rate=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + if v := _m.ResolvedCostBasis; v != nil { + builder.WriteString("resolved_cost_basis=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + if v := _m.ResolvedAt; v != nil { + builder.WriteString("resolved_at=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteString(", ") + builder.WriteString("namespace=") + builder.WriteString(_m.Namespace) + 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.WriteByte(')') + return builder.String() +} + +// ChargeCreditPurchaseCostBases is a parsable slice of ChargeCreditPurchaseCostBasis. +type ChargeCreditPurchaseCostBases []*ChargeCreditPurchaseCostBasis diff --git a/openmeter/ent/db/chargecreditpurchasecostbasis/chargecreditpurchasecostbasis.go b/openmeter/ent/db/chargecreditpurchasecostbasis/chargecreditpurchasecostbasis.go new file mode 100644 index 0000000000..17c633e13f --- /dev/null +++ b/openmeter/ent/db/chargecreditpurchasecostbasis/chargecreditpurchasecostbasis.go @@ -0,0 +1,236 @@ +// Code generated by ent, DO NOT EDIT. + +package chargecreditpurchasecostbasis + +import ( + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" +) + +const ( + // Label holds the string label denoting the chargecreditpurchasecostbasis type in the database. + Label = "charge_credit_purchase_cost_basis" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldMode holds the string denoting the mode field in the database. + FieldMode = "mode" + // FieldFiatCurrency holds the string denoting the fiat_currency field in the database. + FieldFiatCurrency = "fiat_currency" + // FieldCurrencyCostBasisID holds the string denoting the currency_cost_basis_id field in the database. + FieldCurrencyCostBasisID = "currency_cost_basis_id" + // FieldResolvedCostBasisID holds the string denoting the resolved_cost_basis_id field in the database. + FieldResolvedCostBasisID = "resolved_cost_basis_id" + // FieldCurrencyID holds the string denoting the currency_id field in the database. + FieldCurrencyID = "currency_id" + // FieldManualRate holds the string denoting the manual_rate field in the database. + FieldManualRate = "manual_rate" + // FieldResolvedCostBasis holds the string denoting the resolved_cost_basis field in the database. + FieldResolvedCostBasis = "resolved_cost_basis" + // FieldResolvedAt holds the string denoting the resolved_at field in the database. + FieldResolvedAt = "resolved_at" + // FieldNamespace holds the string denoting the namespace field in the database. + FieldNamespace = "namespace" + // 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" + // EdgeCurrencyCostBasis holds the string denoting the currency_cost_basis edge name in mutations. + EdgeCurrencyCostBasis = "currency_cost_basis" + // EdgeResolvedCurrencyCostBasis holds the string denoting the resolved_currency_cost_basis edge name in mutations. + EdgeResolvedCurrencyCostBasis = "resolved_currency_cost_basis" + // EdgeCustomCurrency holds the string denoting the custom_currency edge name in mutations. + EdgeCustomCurrency = "custom_currency" + // Table holds the table name of the chargecreditpurchasecostbasis in the database. + Table = "charge_credit_purchase_cost_bases" + // CurrencyCostBasisTable is the table that holds the currency_cost_basis relation/edge. + CurrencyCostBasisTable = "charge_credit_purchase_cost_bases" + // CurrencyCostBasisInverseTable is the table name for the CurrencyCostBasis entity. + // It exists in this package in order to avoid circular dependency with the "currencycostbasis" package. + CurrencyCostBasisInverseTable = "currency_cost_bases" + // CurrencyCostBasisColumn is the table column denoting the currency_cost_basis relation/edge. + CurrencyCostBasisColumn = "currency_cost_basis_id" + // ResolvedCurrencyCostBasisTable is the table that holds the resolved_currency_cost_basis relation/edge. + ResolvedCurrencyCostBasisTable = "charge_credit_purchase_cost_bases" + // ResolvedCurrencyCostBasisInverseTable is the table name for the CurrencyCostBasis entity. + // It exists in this package in order to avoid circular dependency with the "currencycostbasis" package. + ResolvedCurrencyCostBasisInverseTable = "currency_cost_bases" + // ResolvedCurrencyCostBasisColumn is the table column denoting the resolved_currency_cost_basis relation/edge. + ResolvedCurrencyCostBasisColumn = "resolved_cost_basis_id" + // CustomCurrencyTable is the table that holds the custom_currency relation/edge. + CustomCurrencyTable = "charge_credit_purchase_cost_bases" + // CustomCurrencyInverseTable is the table name for the CustomCurrency entity. + // It exists in this package in order to avoid circular dependency with the "customcurrency" package. + CustomCurrencyInverseTable = "custom_currencies" + // CustomCurrencyColumn is the table column denoting the custom_currency relation/edge. + CustomCurrencyColumn = "currency_id" +) + +// Columns holds all SQL columns for chargecreditpurchasecostbasis fields. +var Columns = []string{ + FieldID, + FieldMode, + FieldFiatCurrency, + FieldCurrencyCostBasisID, + FieldResolvedCostBasisID, + FieldCurrencyID, + FieldManualRate, + FieldResolvedCostBasis, + FieldResolvedAt, + FieldNamespace, + FieldCreatedAt, + FieldUpdatedAt, + FieldDeletedAt, +} + +// 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 ( + // FiatCurrencyValidator is a validator for the "fiat_currency" field. It is called by the builders before save. + FiatCurrencyValidator func(string) error + // CurrencyIDValidator is a validator for the "currency_id" field. It is called by the builders before save. + CurrencyIDValidator func(string) error + // 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 + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() string +) + +// ModeValidator is a validator for the "mode" field enum values. It is called by the builders before save. +func ModeValidator(m costbasis.Mode) error { + switch m { + case "dynamic", "pinned", "manual": + return nil + default: + return fmt.Errorf("chargecreditpurchasecostbasis: invalid enum value for mode field: %q", m) + } +} + +// OrderOption defines the ordering options for the ChargeCreditPurchaseCostBasis 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() +} + +// ByMode orders the results by the mode field. +func ByMode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMode, opts...).ToFunc() +} + +// ByFiatCurrency orders the results by the fiat_currency field. +func ByFiatCurrency(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldFiatCurrency, opts...).ToFunc() +} + +// ByCurrencyCostBasisID orders the results by the currency_cost_basis_id field. +func ByCurrencyCostBasisID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCurrencyCostBasisID, opts...).ToFunc() +} + +// ByResolvedCostBasisID orders the results by the resolved_cost_basis_id field. +func ByResolvedCostBasisID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldResolvedCostBasisID, opts...).ToFunc() +} + +// ByCurrencyID orders the results by the currency_id field. +func ByCurrencyID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCurrencyID, opts...).ToFunc() +} + +// ByManualRate orders the results by the manual_rate field. +func ByManualRate(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldManualRate, opts...).ToFunc() +} + +// ByResolvedCostBasis orders the results by the resolved_cost_basis field. +func ByResolvedCostBasis(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldResolvedCostBasis, opts...).ToFunc() +} + +// ByResolvedAt orders the results by the resolved_at field. +func ByResolvedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldResolvedAt, 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() +} + +// ByCurrencyCostBasisField orders the results by currency_cost_basis field. +func ByCurrencyCostBasisField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCurrencyCostBasisStep(), sql.OrderByField(field, opts...)) + } +} + +// ByResolvedCurrencyCostBasisField orders the results by resolved_currency_cost_basis field. +func ByResolvedCurrencyCostBasisField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newResolvedCurrencyCostBasisStep(), sql.OrderByField(field, opts...)) + } +} + +// ByCustomCurrencyField orders the results by custom_currency field. +func ByCustomCurrencyField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCustomCurrencyStep(), sql.OrderByField(field, opts...)) + } +} +func newCurrencyCostBasisStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CurrencyCostBasisInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CurrencyCostBasisTable, CurrencyCostBasisColumn), + ) +} +func newResolvedCurrencyCostBasisStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(ResolvedCurrencyCostBasisInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, ResolvedCurrencyCostBasisTable, ResolvedCurrencyCostBasisColumn), + ) +} +func newCustomCurrencyStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CustomCurrencyInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CustomCurrencyTable, CustomCurrencyColumn), + ) +} diff --git a/openmeter/ent/db/chargecreditpurchasecostbasis/where.go b/openmeter/ent/db/chargecreditpurchasecostbasis/where.go new file mode 100644 index 0000000000..37d08dc8d9 --- /dev/null +++ b/openmeter/ent/db/chargecreditpurchasecostbasis/where.go @@ -0,0 +1,883 @@ +// Code generated by ent, DO NOT EDIT. + +package chargecreditpurchasecostbasis + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/alpacahq/alpacadecimal" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" + "github.com/openmeterio/openmeter/pkg/currencyx" +) + +// ID filters vertices based on their ID field. +func ID(id string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLTE(FieldID, id)) +} + +// IDEqualFold applies the EqualFold predicate on the ID field. +func IDEqualFold(id string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEqualFold(FieldID, id)) +} + +// IDContainsFold applies the ContainsFold predicate on the ID field. +func IDContainsFold(id string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldContainsFold(FieldID, id)) +} + +// FiatCurrency applies equality check predicate on the "fiat_currency" field. It's identical to FiatCurrencyEQ. +func FiatCurrency(v currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + vc := string(v) + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldFiatCurrency, vc)) +} + +// CurrencyCostBasisID applies equality check predicate on the "currency_cost_basis_id" field. It's identical to CurrencyCostBasisIDEQ. +func CurrencyCostBasisID(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldCurrencyCostBasisID, v)) +} + +// ResolvedCostBasisID applies equality check predicate on the "resolved_cost_basis_id" field. It's identical to ResolvedCostBasisIDEQ. +func ResolvedCostBasisID(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldResolvedCostBasisID, v)) +} + +// CurrencyID applies equality check predicate on the "currency_id" field. It's identical to CurrencyIDEQ. +func CurrencyID(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldCurrencyID, v)) +} + +// ManualRate applies equality check predicate on the "manual_rate" field. It's identical to ManualRateEQ. +func ManualRate(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldManualRate, v)) +} + +// ResolvedCostBasis applies equality check predicate on the "resolved_cost_basis" field. It's identical to ResolvedCostBasisEQ. +func ResolvedCostBasis(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldResolvedCostBasis, v)) +} + +// ResolvedAt applies equality check predicate on the "resolved_at" field. It's identical to ResolvedAtEQ. +func ResolvedAt(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldResolvedAt, v)) +} + +// Namespace applies equality check predicate on the "namespace" field. It's identical to NamespaceEQ. +func Namespace(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(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.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(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.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(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.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldDeletedAt, v)) +} + +// ModeEQ applies the EQ predicate on the "mode" field. +func ModeEQ(v costbasis.Mode) predicate.ChargeCreditPurchaseCostBasis { + vc := v + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldMode, vc)) +} + +// ModeNEQ applies the NEQ predicate on the "mode" field. +func ModeNEQ(v costbasis.Mode) predicate.ChargeCreditPurchaseCostBasis { + vc := v + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldMode, vc)) +} + +// ModeIn applies the In predicate on the "mode" field. +func ModeIn(vs ...costbasis.Mode) predicate.ChargeCreditPurchaseCostBasis { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldMode, v...)) +} + +// ModeNotIn applies the NotIn predicate on the "mode" field. +func ModeNotIn(vs ...costbasis.Mode) predicate.ChargeCreditPurchaseCostBasis { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldMode, v...)) +} + +// FiatCurrencyEQ applies the EQ predicate on the "fiat_currency" field. +func FiatCurrencyEQ(v currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + vc := string(v) + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldFiatCurrency, vc)) +} + +// FiatCurrencyNEQ applies the NEQ predicate on the "fiat_currency" field. +func FiatCurrencyNEQ(v currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + vc := string(v) + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldFiatCurrency, vc)) +} + +// FiatCurrencyIn applies the In predicate on the "fiat_currency" field. +func FiatCurrencyIn(vs ...currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + v := make([]any, len(vs)) + for i := range v { + v[i] = string(vs[i]) + } + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldFiatCurrency, v...)) +} + +// FiatCurrencyNotIn applies the NotIn predicate on the "fiat_currency" field. +func FiatCurrencyNotIn(vs ...currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + v := make([]any, len(vs)) + for i := range v { + v[i] = string(vs[i]) + } + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldFiatCurrency, v...)) +} + +// FiatCurrencyGT applies the GT predicate on the "fiat_currency" field. +func FiatCurrencyGT(v currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + vc := string(v) + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGT(FieldFiatCurrency, vc)) +} + +// FiatCurrencyGTE applies the GTE predicate on the "fiat_currency" field. +func FiatCurrencyGTE(v currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + vc := string(v) + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGTE(FieldFiatCurrency, vc)) +} + +// FiatCurrencyLT applies the LT predicate on the "fiat_currency" field. +func FiatCurrencyLT(v currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + vc := string(v) + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLT(FieldFiatCurrency, vc)) +} + +// FiatCurrencyLTE applies the LTE predicate on the "fiat_currency" field. +func FiatCurrencyLTE(v currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + vc := string(v) + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLTE(FieldFiatCurrency, vc)) +} + +// FiatCurrencyContains applies the Contains predicate on the "fiat_currency" field. +func FiatCurrencyContains(v currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + vc := string(v) + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldContains(FieldFiatCurrency, vc)) +} + +// FiatCurrencyHasPrefix applies the HasPrefix predicate on the "fiat_currency" field. +func FiatCurrencyHasPrefix(v currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + vc := string(v) + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldHasPrefix(FieldFiatCurrency, vc)) +} + +// FiatCurrencyHasSuffix applies the HasSuffix predicate on the "fiat_currency" field. +func FiatCurrencyHasSuffix(v currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + vc := string(v) + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldHasSuffix(FieldFiatCurrency, vc)) +} + +// FiatCurrencyEqualFold applies the EqualFold predicate on the "fiat_currency" field. +func FiatCurrencyEqualFold(v currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + vc := string(v) + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEqualFold(FieldFiatCurrency, vc)) +} + +// FiatCurrencyContainsFold applies the ContainsFold predicate on the "fiat_currency" field. +func FiatCurrencyContainsFold(v currencyx.FiatCode) predicate.ChargeCreditPurchaseCostBasis { + vc := string(v) + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldContainsFold(FieldFiatCurrency, vc)) +} + +// CurrencyCostBasisIDEQ applies the EQ predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDEQ(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDNEQ applies the NEQ predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDNEQ(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDIn applies the In predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDIn(vs ...string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldCurrencyCostBasisID, vs...)) +} + +// CurrencyCostBasisIDNotIn applies the NotIn predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDNotIn(vs ...string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldCurrencyCostBasisID, vs...)) +} + +// CurrencyCostBasisIDGT applies the GT predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDGT(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGT(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDGTE applies the GTE predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDGTE(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGTE(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDLT applies the LT predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDLT(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLT(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDLTE applies the LTE predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDLTE(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLTE(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDContains applies the Contains predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDContains(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldContains(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDHasPrefix applies the HasPrefix predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDHasPrefix(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldHasPrefix(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDHasSuffix applies the HasSuffix predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDHasSuffix(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldHasSuffix(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDIsNil applies the IsNil predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDIsNil() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIsNull(FieldCurrencyCostBasisID)) +} + +// CurrencyCostBasisIDNotNil applies the NotNil predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDNotNil() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotNull(FieldCurrencyCostBasisID)) +} + +// CurrencyCostBasisIDEqualFold applies the EqualFold predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDEqualFold(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEqualFold(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDContainsFold applies the ContainsFold predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDContainsFold(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldContainsFold(FieldCurrencyCostBasisID, v)) +} + +// ResolvedCostBasisIDEQ applies the EQ predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDEQ(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDNEQ applies the NEQ predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDNEQ(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDIn applies the In predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDIn(vs ...string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldResolvedCostBasisID, vs...)) +} + +// ResolvedCostBasisIDNotIn applies the NotIn predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDNotIn(vs ...string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldResolvedCostBasisID, vs...)) +} + +// ResolvedCostBasisIDGT applies the GT predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDGT(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGT(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDGTE applies the GTE predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDGTE(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGTE(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDLT applies the LT predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDLT(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLT(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDLTE applies the LTE predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDLTE(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLTE(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDContains applies the Contains predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDContains(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldContains(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDHasPrefix applies the HasPrefix predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDHasPrefix(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldHasPrefix(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDHasSuffix applies the HasSuffix predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDHasSuffix(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldHasSuffix(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDIsNil applies the IsNil predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDIsNil() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIsNull(FieldResolvedCostBasisID)) +} + +// ResolvedCostBasisIDNotNil applies the NotNil predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDNotNil() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotNull(FieldResolvedCostBasisID)) +} + +// ResolvedCostBasisIDEqualFold applies the EqualFold predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDEqualFold(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEqualFold(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDContainsFold applies the ContainsFold predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDContainsFold(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldContainsFold(FieldResolvedCostBasisID, v)) +} + +// CurrencyIDEQ applies the EQ predicate on the "currency_id" field. +func CurrencyIDEQ(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldCurrencyID, v)) +} + +// CurrencyIDNEQ applies the NEQ predicate on the "currency_id" field. +func CurrencyIDNEQ(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldCurrencyID, v)) +} + +// CurrencyIDIn applies the In predicate on the "currency_id" field. +func CurrencyIDIn(vs ...string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldCurrencyID, vs...)) +} + +// CurrencyIDNotIn applies the NotIn predicate on the "currency_id" field. +func CurrencyIDNotIn(vs ...string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldCurrencyID, vs...)) +} + +// CurrencyIDGT applies the GT predicate on the "currency_id" field. +func CurrencyIDGT(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGT(FieldCurrencyID, v)) +} + +// CurrencyIDGTE applies the GTE predicate on the "currency_id" field. +func CurrencyIDGTE(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGTE(FieldCurrencyID, v)) +} + +// CurrencyIDLT applies the LT predicate on the "currency_id" field. +func CurrencyIDLT(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLT(FieldCurrencyID, v)) +} + +// CurrencyIDLTE applies the LTE predicate on the "currency_id" field. +func CurrencyIDLTE(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLTE(FieldCurrencyID, v)) +} + +// CurrencyIDContains applies the Contains predicate on the "currency_id" field. +func CurrencyIDContains(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldContains(FieldCurrencyID, v)) +} + +// CurrencyIDHasPrefix applies the HasPrefix predicate on the "currency_id" field. +func CurrencyIDHasPrefix(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldHasPrefix(FieldCurrencyID, v)) +} + +// CurrencyIDHasSuffix applies the HasSuffix predicate on the "currency_id" field. +func CurrencyIDHasSuffix(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldHasSuffix(FieldCurrencyID, v)) +} + +// CurrencyIDEqualFold applies the EqualFold predicate on the "currency_id" field. +func CurrencyIDEqualFold(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEqualFold(FieldCurrencyID, v)) +} + +// CurrencyIDContainsFold applies the ContainsFold predicate on the "currency_id" field. +func CurrencyIDContainsFold(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldContainsFold(FieldCurrencyID, v)) +} + +// ManualRateEQ applies the EQ predicate on the "manual_rate" field. +func ManualRateEQ(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldManualRate, v)) +} + +// ManualRateNEQ applies the NEQ predicate on the "manual_rate" field. +func ManualRateNEQ(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldManualRate, v)) +} + +// ManualRateIn applies the In predicate on the "manual_rate" field. +func ManualRateIn(vs ...alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldManualRate, vs...)) +} + +// ManualRateNotIn applies the NotIn predicate on the "manual_rate" field. +func ManualRateNotIn(vs ...alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldManualRate, vs...)) +} + +// ManualRateGT applies the GT predicate on the "manual_rate" field. +func ManualRateGT(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGT(FieldManualRate, v)) +} + +// ManualRateGTE applies the GTE predicate on the "manual_rate" field. +func ManualRateGTE(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGTE(FieldManualRate, v)) +} + +// ManualRateLT applies the LT predicate on the "manual_rate" field. +func ManualRateLT(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLT(FieldManualRate, v)) +} + +// ManualRateLTE applies the LTE predicate on the "manual_rate" field. +func ManualRateLTE(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLTE(FieldManualRate, v)) +} + +// ManualRateIsNil applies the IsNil predicate on the "manual_rate" field. +func ManualRateIsNil() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIsNull(FieldManualRate)) +} + +// ManualRateNotNil applies the NotNil predicate on the "manual_rate" field. +func ManualRateNotNil() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotNull(FieldManualRate)) +} + +// ResolvedCostBasisEQ applies the EQ predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisEQ(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisNEQ applies the NEQ predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisNEQ(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisIn applies the In predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisIn(vs ...alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldResolvedCostBasis, vs...)) +} + +// ResolvedCostBasisNotIn applies the NotIn predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisNotIn(vs ...alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldResolvedCostBasis, vs...)) +} + +// ResolvedCostBasisGT applies the GT predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisGT(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGT(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisGTE applies the GTE predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisGTE(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGTE(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisLT applies the LT predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisLT(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLT(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisLTE applies the LTE predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisLTE(v alpacadecimal.Decimal) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLTE(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisIsNil applies the IsNil predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisIsNil() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIsNull(FieldResolvedCostBasis)) +} + +// ResolvedCostBasisNotNil applies the NotNil predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisNotNil() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotNull(FieldResolvedCostBasis)) +} + +// ResolvedAtEQ applies the EQ predicate on the "resolved_at" field. +func ResolvedAtEQ(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldResolvedAt, v)) +} + +// ResolvedAtNEQ applies the NEQ predicate on the "resolved_at" field. +func ResolvedAtNEQ(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldResolvedAt, v)) +} + +// ResolvedAtIn applies the In predicate on the "resolved_at" field. +func ResolvedAtIn(vs ...time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldResolvedAt, vs...)) +} + +// ResolvedAtNotIn applies the NotIn predicate on the "resolved_at" field. +func ResolvedAtNotIn(vs ...time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldResolvedAt, vs...)) +} + +// ResolvedAtGT applies the GT predicate on the "resolved_at" field. +func ResolvedAtGT(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGT(FieldResolvedAt, v)) +} + +// ResolvedAtGTE applies the GTE predicate on the "resolved_at" field. +func ResolvedAtGTE(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGTE(FieldResolvedAt, v)) +} + +// ResolvedAtLT applies the LT predicate on the "resolved_at" field. +func ResolvedAtLT(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLT(FieldResolvedAt, v)) +} + +// ResolvedAtLTE applies the LTE predicate on the "resolved_at" field. +func ResolvedAtLTE(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLTE(FieldResolvedAt, v)) +} + +// ResolvedAtIsNil applies the IsNil predicate on the "resolved_at" field. +func ResolvedAtIsNil() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIsNull(FieldResolvedAt)) +} + +// ResolvedAtNotNil applies the NotNil predicate on the "resolved_at" field. +func ResolvedAtNotNil() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotNull(FieldResolvedAt)) +} + +// NamespaceEQ applies the EQ predicate on the "namespace" field. +func NamespaceEQ(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldNamespace, v)) +} + +// NamespaceNEQ applies the NEQ predicate on the "namespace" field. +func NamespaceNEQ(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldNamespace, v)) +} + +// NamespaceIn applies the In predicate on the "namespace" field. +func NamespaceIn(vs ...string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldNamespace, vs...)) +} + +// NamespaceNotIn applies the NotIn predicate on the "namespace" field. +func NamespaceNotIn(vs ...string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldNamespace, vs...)) +} + +// NamespaceGT applies the GT predicate on the "namespace" field. +func NamespaceGT(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGT(FieldNamespace, v)) +} + +// NamespaceGTE applies the GTE predicate on the "namespace" field. +func NamespaceGTE(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGTE(FieldNamespace, v)) +} + +// NamespaceLT applies the LT predicate on the "namespace" field. +func NamespaceLT(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLT(FieldNamespace, v)) +} + +// NamespaceLTE applies the LTE predicate on the "namespace" field. +func NamespaceLTE(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLTE(FieldNamespace, v)) +} + +// NamespaceContains applies the Contains predicate on the "namespace" field. +func NamespaceContains(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldContains(FieldNamespace, v)) +} + +// NamespaceHasPrefix applies the HasPrefix predicate on the "namespace" field. +func NamespaceHasPrefix(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldHasPrefix(FieldNamespace, v)) +} + +// NamespaceHasSuffix applies the HasSuffix predicate on the "namespace" field. +func NamespaceHasSuffix(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldHasSuffix(FieldNamespace, v)) +} + +// NamespaceEqualFold applies the EqualFold predicate on the "namespace" field. +func NamespaceEqualFold(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEqualFold(FieldNamespace, v)) +} + +// NamespaceContainsFold applies the ContainsFold predicate on the "namespace" field. +func NamespaceContainsFold(v string) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldContainsFold(FieldNamespace, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// DeletedAtEQ applies the EQ predicate on the "deleted_at" field. +func DeletedAtEQ(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldEQ(FieldDeletedAt, v)) +} + +// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field. +func DeletedAtNEQ(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNEQ(FieldDeletedAt, v)) +} + +// DeletedAtIn applies the In predicate on the "deleted_at" field. +func DeletedAtIn(vs ...time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIn(FieldDeletedAt, vs...)) +} + +// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field. +func DeletedAtNotIn(vs ...time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotIn(FieldDeletedAt, vs...)) +} + +// DeletedAtGT applies the GT predicate on the "deleted_at" field. +func DeletedAtGT(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGT(FieldDeletedAt, v)) +} + +// DeletedAtGTE applies the GTE predicate on the "deleted_at" field. +func DeletedAtGTE(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldGTE(FieldDeletedAt, v)) +} + +// DeletedAtLT applies the LT predicate on the "deleted_at" field. +func DeletedAtLT(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLT(FieldDeletedAt, v)) +} + +// DeletedAtLTE applies the LTE predicate on the "deleted_at" field. +func DeletedAtLTE(v time.Time) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldLTE(FieldDeletedAt, v)) +} + +// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field. +func DeletedAtIsNil() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldIsNull(FieldDeletedAt)) +} + +// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field. +func DeletedAtNotNil() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.FieldNotNull(FieldDeletedAt)) +} + +// HasCurrencyCostBasis applies the HasEdge predicate on the "currency_cost_basis" edge. +func HasCurrencyCostBasis() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CurrencyCostBasisTable, CurrencyCostBasisColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasCurrencyCostBasisWith applies the HasEdge predicate on the "currency_cost_basis" edge with a given conditions (other predicates). +func HasCurrencyCostBasisWith(preds ...predicate.CurrencyCostBasis) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(func(s *sql.Selector) { + step := newCurrencyCostBasisStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasResolvedCurrencyCostBasis applies the HasEdge predicate on the "resolved_currency_cost_basis" edge. +func HasResolvedCurrencyCostBasis() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, ResolvedCurrencyCostBasisTable, ResolvedCurrencyCostBasisColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasResolvedCurrencyCostBasisWith applies the HasEdge predicate on the "resolved_currency_cost_basis" edge with a given conditions (other predicates). +func HasResolvedCurrencyCostBasisWith(preds ...predicate.CurrencyCostBasis) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(func(s *sql.Selector) { + step := newResolvedCurrencyCostBasisStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasCustomCurrency applies the HasEdge predicate on the "custom_currency" edge. +func HasCustomCurrency() predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CustomCurrencyTable, CustomCurrencyColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasCustomCurrencyWith applies the HasEdge predicate on the "custom_currency" edge with a given conditions (other predicates). +func HasCustomCurrencyWith(preds ...predicate.CustomCurrency) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(func(s *sql.Selector) { + step := newCustomCurrencyStep() + 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.ChargeCreditPurchaseCostBasis) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.ChargeCreditPurchaseCostBasis) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.ChargeCreditPurchaseCostBasis) predicate.ChargeCreditPurchaseCostBasis { + return predicate.ChargeCreditPurchaseCostBasis(sql.NotPredicates(p)) +} diff --git a/openmeter/ent/db/chargecreditpurchasecostbasis_create.go b/openmeter/ent/db/chargecreditpurchasecostbasis_create.go new file mode 100644 index 0000000000..c75de94eed --- /dev/null +++ b/openmeter/ent/db/chargecreditpurchasecostbasis_create.go @@ -0,0 +1,1143 @@ +// 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/alpacahq/alpacadecimal" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/currencycostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" + "github.com/openmeterio/openmeter/pkg/currencyx" +) + +// ChargeCreditPurchaseCostBasisCreate is the builder for creating a ChargeCreditPurchaseCostBasis entity. +type ChargeCreditPurchaseCostBasisCreate struct { + config + mutation *ChargeCreditPurchaseCostBasisMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetMode sets the "mode" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetMode(v costbasis.Mode) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetMode(v) + return _c +} + +// SetFiatCurrency sets the "fiat_currency" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetFiatCurrency(v currencyx.FiatCode) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetFiatCurrency(v) + return _c +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetCurrencyCostBasisID(v string) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetCurrencyCostBasisID(v) + return _c +} + +// SetNillableCurrencyCostBasisID sets the "currency_cost_basis_id" field if the given value is not nil. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetNillableCurrencyCostBasisID(v *string) *ChargeCreditPurchaseCostBasisCreate { + if v != nil { + _c.SetCurrencyCostBasisID(*v) + } + return _c +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetResolvedCostBasisID(v string) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetResolvedCostBasisID(v) + return _c +} + +// SetNillableResolvedCostBasisID sets the "resolved_cost_basis_id" field if the given value is not nil. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetNillableResolvedCostBasisID(v *string) *ChargeCreditPurchaseCostBasisCreate { + if v != nil { + _c.SetResolvedCostBasisID(*v) + } + return _c +} + +// SetCurrencyID sets the "currency_id" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetCurrencyID(v string) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetCurrencyID(v) + return _c +} + +// SetManualRate sets the "manual_rate" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetManualRate(v alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetManualRate(v) + return _c +} + +// SetNillableManualRate sets the "manual_rate" field if the given value is not nil. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetNillableManualRate(v *alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisCreate { + if v != nil { + _c.SetManualRate(*v) + } + return _c +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetResolvedCostBasis(v) + return _c +} + +// SetNillableResolvedCostBasis sets the "resolved_cost_basis" field if the given value is not nil. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetNillableResolvedCostBasis(v *alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisCreate { + if v != nil { + _c.SetResolvedCostBasis(*v) + } + return _c +} + +// SetResolvedAt sets the "resolved_at" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetResolvedAt(v time.Time) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetResolvedAt(v) + return _c +} + +// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetNillableResolvedAt(v *time.Time) *ChargeCreditPurchaseCostBasisCreate { + if v != nil { + _c.SetResolvedAt(*v) + } + return _c +} + +// SetNamespace sets the "namespace" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetNamespace(v string) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetNamespace(v) + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetCreatedAt(v time.Time) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetNillableCreatedAt(v *time.Time) *ChargeCreditPurchaseCostBasisCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetUpdatedAt(v time.Time) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetNillableUpdatedAt(v *time.Time) *ChargeCreditPurchaseCostBasisCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetDeletedAt sets the "deleted_at" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetDeletedAt(v time.Time) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetDeletedAt(v) + return _c +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetNillableDeletedAt(v *time.Time) *ChargeCreditPurchaseCostBasisCreate { + if v != nil { + _c.SetDeletedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetID(v string) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetNillableID(v *string) *ChargeCreditPurchaseCostBasisCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// SetCurrencyCostBasis sets the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetCurrencyCostBasis(v *CurrencyCostBasis) *ChargeCreditPurchaseCostBasisCreate { + return _c.SetCurrencyCostBasisID(v.ID) +} + +// SetResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetResolvedCurrencyCostBasisID(id string) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetResolvedCurrencyCostBasisID(id) + return _c +} + +// SetNillableResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID if the given value is not nil. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetNillableResolvedCurrencyCostBasisID(id *string) *ChargeCreditPurchaseCostBasisCreate { + if id != nil { + _c = _c.SetResolvedCurrencyCostBasisID(*id) + } + return _c +} + +// SetResolvedCurrencyCostBasis sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetResolvedCurrencyCostBasis(v *CurrencyCostBasis) *ChargeCreditPurchaseCostBasisCreate { + return _c.SetResolvedCurrencyCostBasisID(v.ID) +} + +// SetCustomCurrencyID sets the "custom_currency" edge to the CustomCurrency entity by ID. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetCustomCurrencyID(id string) *ChargeCreditPurchaseCostBasisCreate { + _c.mutation.SetCustomCurrencyID(id) + return _c +} + +// SetCustomCurrency sets the "custom_currency" edge to the CustomCurrency entity. +func (_c *ChargeCreditPurchaseCostBasisCreate) SetCustomCurrency(v *CustomCurrency) *ChargeCreditPurchaseCostBasisCreate { + return _c.SetCustomCurrencyID(v.ID) +} + +// Mutation returns the ChargeCreditPurchaseCostBasisMutation object of the builder. +func (_c *ChargeCreditPurchaseCostBasisCreate) Mutation() *ChargeCreditPurchaseCostBasisMutation { + return _c.mutation +} + +// Save creates the ChargeCreditPurchaseCostBasis in the database. +func (_c *ChargeCreditPurchaseCostBasisCreate) Save(ctx context.Context) (*ChargeCreditPurchaseCostBasis, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *ChargeCreditPurchaseCostBasisCreate) SaveX(ctx context.Context) *ChargeCreditPurchaseCostBasis { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ChargeCreditPurchaseCostBasisCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ChargeCreditPurchaseCostBasisCreate) 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 *ChargeCreditPurchaseCostBasisCreate) defaults() { + if _, ok := _c.mutation.CreatedAt(); !ok { + v := chargecreditpurchasecostbasis.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := chargecreditpurchasecostbasis.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := chargecreditpurchasecostbasis.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *ChargeCreditPurchaseCostBasisCreate) check() error { + if _, ok := _c.mutation.Mode(); !ok { + return &ValidationError{Name: "mode", err: errors.New(`db: missing required field "ChargeCreditPurchaseCostBasis.mode"`)} + } + if v, ok := _c.mutation.Mode(); ok { + if err := chargecreditpurchasecostbasis.ModeValidator(v); err != nil { + return &ValidationError{Name: "mode", err: fmt.Errorf(`db: validator failed for field "ChargeCreditPurchaseCostBasis.mode": %w`, err)} + } + } + if _, ok := _c.mutation.FiatCurrency(); !ok { + return &ValidationError{Name: "fiat_currency", err: errors.New(`db: missing required field "ChargeCreditPurchaseCostBasis.fiat_currency"`)} + } + if v, ok := _c.mutation.FiatCurrency(); ok { + if err := chargecreditpurchasecostbasis.FiatCurrencyValidator(string(v)); err != nil { + return &ValidationError{Name: "fiat_currency", err: fmt.Errorf(`db: validator failed for field "ChargeCreditPurchaseCostBasis.fiat_currency": %w`, err)} + } + } + if _, ok := _c.mutation.CurrencyID(); !ok { + return &ValidationError{Name: "currency_id", err: errors.New(`db: missing required field "ChargeCreditPurchaseCostBasis.currency_id"`)} + } + if v, ok := _c.mutation.CurrencyID(); ok { + if err := chargecreditpurchasecostbasis.CurrencyIDValidator(v); err != nil { + return &ValidationError{Name: "currency_id", err: fmt.Errorf(`db: validator failed for field "ChargeCreditPurchaseCostBasis.currency_id": %w`, err)} + } + } + if _, ok := _c.mutation.Namespace(); !ok { + return &ValidationError{Name: "namespace", err: errors.New(`db: missing required field "ChargeCreditPurchaseCostBasis.namespace"`)} + } + if v, ok := _c.mutation.Namespace(); ok { + if err := chargecreditpurchasecostbasis.NamespaceValidator(v); err != nil { + return &ValidationError{Name: "namespace", err: fmt.Errorf(`db: validator failed for field "ChargeCreditPurchaseCostBasis.namespace": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "ChargeCreditPurchaseCostBasis.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "ChargeCreditPurchaseCostBasis.updated_at"`)} + } + if len(_c.mutation.CustomCurrencyIDs()) == 0 { + return &ValidationError{Name: "custom_currency", err: errors.New(`db: missing required edge "ChargeCreditPurchaseCostBasis.custom_currency"`)} + } + return nil +} + +func (_c *ChargeCreditPurchaseCostBasisCreate) sqlSave(ctx context.Context) (*ChargeCreditPurchaseCostBasis, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + 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 ChargeCreditPurchaseCostBasis.ID type: %T", _spec.ID.Value) + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *ChargeCreditPurchaseCostBasisCreate) createSpec() (*ChargeCreditPurchaseCostBasis, *sqlgraph.CreateSpec) { + var ( + _node = &ChargeCreditPurchaseCostBasis{config: _c.config} + _spec = sqlgraph.NewCreateSpec(chargecreditpurchasecostbasis.Table, sqlgraph.NewFieldSpec(chargecreditpurchasecostbasis.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.Mode(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldMode, field.TypeEnum, value) + _node.Mode = value + } + if value, ok := _c.mutation.FiatCurrency(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldFiatCurrency, field.TypeString, value) + _node.FiatCurrency = value + } + if value, ok := _c.mutation.ManualRate(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldManualRate, field.TypeOther, value) + _node.ManualRate = &value + } + if value, ok := _c.mutation.ResolvedCostBasis(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldResolvedCostBasis, field.TypeOther, value) + _node.ResolvedCostBasis = &value + } + if value, ok := _c.mutation.ResolvedAt(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldResolvedAt, field.TypeTime, value) + _node.ResolvedAt = &value + } + if value, ok := _c.mutation.Namespace(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldNamespace, field.TypeString, value) + _node.Namespace = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := _c.mutation.DeletedAt(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldDeletedAt, field.TypeTime, value) + _node.DeletedAt = &value + } + if nodes := _c.mutation.CurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargecreditpurchasecostbasis.CurrencyCostBasisTable, + Columns: []string{chargecreditpurchasecostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.CurrencyCostBasisID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.ResolvedCurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.ResolvedCostBasisID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.CustomCurrencyIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargecreditpurchasecostbasis.CustomCurrencyTable, + Columns: []string{chargecreditpurchasecostbasis.CustomCurrencyColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(customcurrency.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.CurrencyID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.ChargeCreditPurchaseCostBasis.Create(). +// SetMode(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.ChargeCreditPurchaseCostBasisUpsert) { +// SetMode(v+v). +// }). +// Exec(ctx) +func (_c *ChargeCreditPurchaseCostBasisCreate) OnConflict(opts ...sql.ConflictOption) *ChargeCreditPurchaseCostBasisUpsertOne { + _c.conflict = opts + return &ChargeCreditPurchaseCostBasisUpsertOne{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.ChargeCreditPurchaseCostBasis.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *ChargeCreditPurchaseCostBasisCreate) OnConflictColumns(columns ...string) *ChargeCreditPurchaseCostBasisUpsertOne { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &ChargeCreditPurchaseCostBasisUpsertOne{ + create: _c, + } +} + +type ( + // ChargeCreditPurchaseCostBasisUpsertOne is the builder for "upsert"-ing + // one ChargeCreditPurchaseCostBasis node. + ChargeCreditPurchaseCostBasisUpsertOne struct { + create *ChargeCreditPurchaseCostBasisCreate + } + + // ChargeCreditPurchaseCostBasisUpsert is the "OnConflict" setter. + ChargeCreditPurchaseCostBasisUpsert struct { + *sql.UpdateSet + } +) + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (u *ChargeCreditPurchaseCostBasisUpsert) SetCurrencyCostBasisID(v string) *ChargeCreditPurchaseCostBasisUpsert { + u.Set(chargecreditpurchasecostbasis.FieldCurrencyCostBasisID, v) + return u +} + +// UpdateCurrencyCostBasisID sets the "currency_cost_basis_id" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsert) UpdateCurrencyCostBasisID() *ChargeCreditPurchaseCostBasisUpsert { + u.SetExcluded(chargecreditpurchasecostbasis.FieldCurrencyCostBasisID) + return u +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (u *ChargeCreditPurchaseCostBasisUpsert) ClearCurrencyCostBasisID() *ChargeCreditPurchaseCostBasisUpsert { + u.SetNull(chargecreditpurchasecostbasis.FieldCurrencyCostBasisID) + return u +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (u *ChargeCreditPurchaseCostBasisUpsert) SetResolvedCostBasisID(v string) *ChargeCreditPurchaseCostBasisUpsert { + u.Set(chargecreditpurchasecostbasis.FieldResolvedCostBasisID, v) + return u +} + +// UpdateResolvedCostBasisID sets the "resolved_cost_basis_id" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsert) UpdateResolvedCostBasisID() *ChargeCreditPurchaseCostBasisUpsert { + u.SetExcluded(chargecreditpurchasecostbasis.FieldResolvedCostBasisID) + return u +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (u *ChargeCreditPurchaseCostBasisUpsert) ClearResolvedCostBasisID() *ChargeCreditPurchaseCostBasisUpsert { + u.SetNull(chargecreditpurchasecostbasis.FieldResolvedCostBasisID) + return u +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (u *ChargeCreditPurchaseCostBasisUpsert) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisUpsert { + u.Set(chargecreditpurchasecostbasis.FieldResolvedCostBasis, v) + return u +} + +// UpdateResolvedCostBasis sets the "resolved_cost_basis" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsert) UpdateResolvedCostBasis() *ChargeCreditPurchaseCostBasisUpsert { + u.SetExcluded(chargecreditpurchasecostbasis.FieldResolvedCostBasis) + return u +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (u *ChargeCreditPurchaseCostBasisUpsert) ClearResolvedCostBasis() *ChargeCreditPurchaseCostBasisUpsert { + u.SetNull(chargecreditpurchasecostbasis.FieldResolvedCostBasis) + return u +} + +// SetResolvedAt sets the "resolved_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsert) SetResolvedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpsert { + u.Set(chargecreditpurchasecostbasis.FieldResolvedAt, v) + return u +} + +// UpdateResolvedAt sets the "resolved_at" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsert) UpdateResolvedAt() *ChargeCreditPurchaseCostBasisUpsert { + u.SetExcluded(chargecreditpurchasecostbasis.FieldResolvedAt) + return u +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsert) ClearResolvedAt() *ChargeCreditPurchaseCostBasisUpsert { + u.SetNull(chargecreditpurchasecostbasis.FieldResolvedAt) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsert) SetUpdatedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpsert { + u.Set(chargecreditpurchasecostbasis.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsert) UpdateUpdatedAt() *ChargeCreditPurchaseCostBasisUpsert { + u.SetExcluded(chargecreditpurchasecostbasis.FieldUpdatedAt) + return u +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsert) SetDeletedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpsert { + u.Set(chargecreditpurchasecostbasis.FieldDeletedAt, v) + return u +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsert) UpdateDeletedAt() *ChargeCreditPurchaseCostBasisUpsert { + u.SetExcluded(chargecreditpurchasecostbasis.FieldDeletedAt) + return u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsert) ClearDeletedAt() *ChargeCreditPurchaseCostBasisUpsert { + u.SetNull(chargecreditpurchasecostbasis.FieldDeletedAt) + 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.ChargeCreditPurchaseCostBasis.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(chargecreditpurchasecostbasis.FieldID) +// }), +// ). +// Exec(ctx) +func (u *ChargeCreditPurchaseCostBasisUpsertOne) UpdateNewValues() *ChargeCreditPurchaseCostBasisUpsertOne { + 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(chargecreditpurchasecostbasis.FieldID) + } + if _, exists := u.create.mutation.Mode(); exists { + s.SetIgnore(chargecreditpurchasecostbasis.FieldMode) + } + if _, exists := u.create.mutation.FiatCurrency(); exists { + s.SetIgnore(chargecreditpurchasecostbasis.FieldFiatCurrency) + } + if _, exists := u.create.mutation.CurrencyID(); exists { + s.SetIgnore(chargecreditpurchasecostbasis.FieldCurrencyID) + } + if _, exists := u.create.mutation.ManualRate(); exists { + s.SetIgnore(chargecreditpurchasecostbasis.FieldManualRate) + } + if _, exists := u.create.mutation.Namespace(); exists { + s.SetIgnore(chargecreditpurchasecostbasis.FieldNamespace) + } + if _, exists := u.create.mutation.CreatedAt(); exists { + s.SetIgnore(chargecreditpurchasecostbasis.FieldCreatedAt) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.ChargeCreditPurchaseCostBasis.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *ChargeCreditPurchaseCostBasisUpsertOne) Ignore() *ChargeCreditPurchaseCostBasisUpsertOne { + 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 *ChargeCreditPurchaseCostBasisUpsertOne) DoNothing() *ChargeCreditPurchaseCostBasisUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the ChargeCreditPurchaseCostBasisCreate.OnConflict +// documentation for more info. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) Update(set func(*ChargeCreditPurchaseCostBasisUpsert)) *ChargeCreditPurchaseCostBasisUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&ChargeCreditPurchaseCostBasisUpsert{UpdateSet: update}) + })) + return u +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) SetCurrencyCostBasisID(v string) *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.SetCurrencyCostBasisID(v) + }) +} + +// UpdateCurrencyCostBasisID sets the "currency_cost_basis_id" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) UpdateCurrencyCostBasisID() *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.UpdateCurrencyCostBasisID() + }) +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) ClearCurrencyCostBasisID() *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.ClearCurrencyCostBasisID() + }) +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) SetResolvedCostBasisID(v string) *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.SetResolvedCostBasisID(v) + }) +} + +// UpdateResolvedCostBasisID sets the "resolved_cost_basis_id" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) UpdateResolvedCostBasisID() *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.UpdateResolvedCostBasisID() + }) +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) ClearResolvedCostBasisID() *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.ClearResolvedCostBasisID() + }) +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.SetResolvedCostBasis(v) + }) +} + +// UpdateResolvedCostBasis sets the "resolved_cost_basis" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) UpdateResolvedCostBasis() *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.UpdateResolvedCostBasis() + }) +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) ClearResolvedCostBasis() *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.ClearResolvedCostBasis() + }) +} + +// SetResolvedAt sets the "resolved_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) SetResolvedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.SetResolvedAt(v) + }) +} + +// UpdateResolvedAt sets the "resolved_at" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) UpdateResolvedAt() *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.UpdateResolvedAt() + }) +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) ClearResolvedAt() *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.ClearResolvedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) SetUpdatedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) UpdateUpdatedAt() *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) SetDeletedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.SetDeletedAt(v) + }) +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) UpdateDeletedAt() *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.UpdateDeletedAt() + }) +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) ClearDeletedAt() *ChargeCreditPurchaseCostBasisUpsertOne { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.ClearDeletedAt() + }) +} + +// Exec executes the query. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for ChargeCreditPurchaseCostBasisCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *ChargeCreditPurchaseCostBasisUpsertOne) 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 *ChargeCreditPurchaseCostBasisUpsertOne) 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: ChargeCreditPurchaseCostBasisUpsertOne.ID is not supported by MySQL driver. Use ChargeCreditPurchaseCostBasisUpsertOne.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 *ChargeCreditPurchaseCostBasisUpsertOne) IDX(ctx context.Context) string { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// ChargeCreditPurchaseCostBasisCreateBulk is the builder for creating many ChargeCreditPurchaseCostBasis entities in bulk. +type ChargeCreditPurchaseCostBasisCreateBulk struct { + config + err error + builders []*ChargeCreditPurchaseCostBasisCreate + conflict []sql.ConflictOption +} + +// Save creates the ChargeCreditPurchaseCostBasis entities in the database. +func (_c *ChargeCreditPurchaseCostBasisCreateBulk) Save(ctx context.Context) ([]*ChargeCreditPurchaseCostBasis, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*ChargeCreditPurchaseCostBasis, 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.(*ChargeCreditPurchaseCostBasisMutation) + 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] = builder.createSpec() + 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 *ChargeCreditPurchaseCostBasisCreateBulk) SaveX(ctx context.Context) []*ChargeCreditPurchaseCostBasis { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ChargeCreditPurchaseCostBasisCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ChargeCreditPurchaseCostBasisCreateBulk) 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.ChargeCreditPurchaseCostBasis.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.ChargeCreditPurchaseCostBasisUpsert) { +// SetMode(v+v). +// }). +// Exec(ctx) +func (_c *ChargeCreditPurchaseCostBasisCreateBulk) OnConflict(opts ...sql.ConflictOption) *ChargeCreditPurchaseCostBasisUpsertBulk { + _c.conflict = opts + return &ChargeCreditPurchaseCostBasisUpsertBulk{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.ChargeCreditPurchaseCostBasis.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *ChargeCreditPurchaseCostBasisCreateBulk) OnConflictColumns(columns ...string) *ChargeCreditPurchaseCostBasisUpsertBulk { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &ChargeCreditPurchaseCostBasisUpsertBulk{ + create: _c, + } +} + +// ChargeCreditPurchaseCostBasisUpsertBulk is the builder for "upsert"-ing +// a bulk of ChargeCreditPurchaseCostBasis nodes. +type ChargeCreditPurchaseCostBasisUpsertBulk struct { + create *ChargeCreditPurchaseCostBasisCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.ChargeCreditPurchaseCostBasis.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(chargecreditpurchasecostbasis.FieldID) +// }), +// ). +// Exec(ctx) +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) UpdateNewValues() *ChargeCreditPurchaseCostBasisUpsertBulk { + 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(chargecreditpurchasecostbasis.FieldID) + } + if _, exists := b.mutation.Mode(); exists { + s.SetIgnore(chargecreditpurchasecostbasis.FieldMode) + } + if _, exists := b.mutation.FiatCurrency(); exists { + s.SetIgnore(chargecreditpurchasecostbasis.FieldFiatCurrency) + } + if _, exists := b.mutation.CurrencyID(); exists { + s.SetIgnore(chargecreditpurchasecostbasis.FieldCurrencyID) + } + if _, exists := b.mutation.ManualRate(); exists { + s.SetIgnore(chargecreditpurchasecostbasis.FieldManualRate) + } + if _, exists := b.mutation.Namespace(); exists { + s.SetIgnore(chargecreditpurchasecostbasis.FieldNamespace) + } + if _, exists := b.mutation.CreatedAt(); exists { + s.SetIgnore(chargecreditpurchasecostbasis.FieldCreatedAt) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.ChargeCreditPurchaseCostBasis.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) Ignore() *ChargeCreditPurchaseCostBasisUpsertBulk { + 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 *ChargeCreditPurchaseCostBasisUpsertBulk) DoNothing() *ChargeCreditPurchaseCostBasisUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the ChargeCreditPurchaseCostBasisCreateBulk.OnConflict +// documentation for more info. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) Update(set func(*ChargeCreditPurchaseCostBasisUpsert)) *ChargeCreditPurchaseCostBasisUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&ChargeCreditPurchaseCostBasisUpsert{UpdateSet: update}) + })) + return u +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) SetCurrencyCostBasisID(v string) *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.SetCurrencyCostBasisID(v) + }) +} + +// UpdateCurrencyCostBasisID sets the "currency_cost_basis_id" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) UpdateCurrencyCostBasisID() *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.UpdateCurrencyCostBasisID() + }) +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) ClearCurrencyCostBasisID() *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.ClearCurrencyCostBasisID() + }) +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) SetResolvedCostBasisID(v string) *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.SetResolvedCostBasisID(v) + }) +} + +// UpdateResolvedCostBasisID sets the "resolved_cost_basis_id" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) UpdateResolvedCostBasisID() *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.UpdateResolvedCostBasisID() + }) +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) ClearResolvedCostBasisID() *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.ClearResolvedCostBasisID() + }) +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.SetResolvedCostBasis(v) + }) +} + +// UpdateResolvedCostBasis sets the "resolved_cost_basis" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) UpdateResolvedCostBasis() *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.UpdateResolvedCostBasis() + }) +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) ClearResolvedCostBasis() *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.ClearResolvedCostBasis() + }) +} + +// SetResolvedAt sets the "resolved_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) SetResolvedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.SetResolvedAt(v) + }) +} + +// UpdateResolvedAt sets the "resolved_at" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) UpdateResolvedAt() *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.UpdateResolvedAt() + }) +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) ClearResolvedAt() *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.ClearResolvedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) SetUpdatedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) UpdateUpdatedAt() *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) SetDeletedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.SetDeletedAt(v) + }) +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) UpdateDeletedAt() *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.UpdateDeletedAt() + }) +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) ClearDeletedAt() *ChargeCreditPurchaseCostBasisUpsertBulk { + return u.Update(func(s *ChargeCreditPurchaseCostBasisUpsert) { + s.ClearDeletedAt() + }) +} + +// Exec executes the query. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) 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 ChargeCreditPurchaseCostBasisCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for ChargeCreditPurchaseCostBasisCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *ChargeCreditPurchaseCostBasisUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/openmeter/ent/db/chargecreditpurchasecostbasis_delete.go b/openmeter/ent/db/chargecreditpurchasecostbasis_delete.go new file mode 100644 index 0000000000..c344047c9d --- /dev/null +++ b/openmeter/ent/db/chargecreditpurchasecostbasis_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/chargecreditpurchasecostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" +) + +// ChargeCreditPurchaseCostBasisDelete is the builder for deleting a ChargeCreditPurchaseCostBasis entity. +type ChargeCreditPurchaseCostBasisDelete struct { + config + hooks []Hook + mutation *ChargeCreditPurchaseCostBasisMutation +} + +// Where appends a list predicates to the ChargeCreditPurchaseCostBasisDelete builder. +func (_d *ChargeCreditPurchaseCostBasisDelete) Where(ps ...predicate.ChargeCreditPurchaseCostBasis) *ChargeCreditPurchaseCostBasisDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *ChargeCreditPurchaseCostBasisDelete) 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 *ChargeCreditPurchaseCostBasisDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *ChargeCreditPurchaseCostBasisDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(chargecreditpurchasecostbasis.Table, sqlgraph.NewFieldSpec(chargecreditpurchasecostbasis.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 +} + +// ChargeCreditPurchaseCostBasisDeleteOne is the builder for deleting a single ChargeCreditPurchaseCostBasis entity. +type ChargeCreditPurchaseCostBasisDeleteOne struct { + _d *ChargeCreditPurchaseCostBasisDelete +} + +// Where appends a list predicates to the ChargeCreditPurchaseCostBasisDelete builder. +func (_d *ChargeCreditPurchaseCostBasisDeleteOne) Where(ps ...predicate.ChargeCreditPurchaseCostBasis) *ChargeCreditPurchaseCostBasisDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *ChargeCreditPurchaseCostBasisDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{chargecreditpurchasecostbasis.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ChargeCreditPurchaseCostBasisDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/openmeter/ent/db/chargecreditpurchasecostbasis_query.go b/openmeter/ent/db/chargecreditpurchasecostbasis_query.go new file mode 100644 index 0000000000..8ec6588e5e --- /dev/null +++ b/openmeter/ent/db/chargecreditpurchasecostbasis_query.go @@ -0,0 +1,798 @@ +// 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/chargecreditpurchasecostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/currencycostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" +) + +// ChargeCreditPurchaseCostBasisQuery is the builder for querying ChargeCreditPurchaseCostBasis entities. +type ChargeCreditPurchaseCostBasisQuery struct { + config + ctx *QueryContext + order []chargecreditpurchasecostbasis.OrderOption + inters []Interceptor + predicates []predicate.ChargeCreditPurchaseCostBasis + withCurrencyCostBasis *CurrencyCostBasisQuery + withResolvedCurrencyCostBasis *CurrencyCostBasisQuery + withCustomCurrency *CustomCurrencyQuery + 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 ChargeCreditPurchaseCostBasisQuery builder. +func (_q *ChargeCreditPurchaseCostBasisQuery) Where(ps ...predicate.ChargeCreditPurchaseCostBasis) *ChargeCreditPurchaseCostBasisQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *ChargeCreditPurchaseCostBasisQuery) Limit(limit int) *ChargeCreditPurchaseCostBasisQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *ChargeCreditPurchaseCostBasisQuery) Offset(offset int) *ChargeCreditPurchaseCostBasisQuery { + _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 *ChargeCreditPurchaseCostBasisQuery) Unique(unique bool) *ChargeCreditPurchaseCostBasisQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *ChargeCreditPurchaseCostBasisQuery) Order(o ...chargecreditpurchasecostbasis.OrderOption) *ChargeCreditPurchaseCostBasisQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryCurrencyCostBasis chains the current query on the "currency_cost_basis" edge. +func (_q *ChargeCreditPurchaseCostBasisQuery) QueryCurrencyCostBasis() *CurrencyCostBasisQuery { + query := (&CurrencyCostBasisClient{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(chargecreditpurchasecostbasis.Table, chargecreditpurchasecostbasis.FieldID, selector), + sqlgraph.To(currencycostbasis.Table, currencycostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargecreditpurchasecostbasis.CurrencyCostBasisTable, chargecreditpurchasecostbasis.CurrencyCostBasisColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryResolvedCurrencyCostBasis chains the current query on the "resolved_currency_cost_basis" edge. +func (_q *ChargeCreditPurchaseCostBasisQuery) QueryResolvedCurrencyCostBasis() *CurrencyCostBasisQuery { + query := (&CurrencyCostBasisClient{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(chargecreditpurchasecostbasis.Table, chargecreditpurchasecostbasis.FieldID, selector), + sqlgraph.To(currencycostbasis.Table, currencycostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisTable, chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryCustomCurrency chains the current query on the "custom_currency" edge. +func (_q *ChargeCreditPurchaseCostBasisQuery) QueryCustomCurrency() *CustomCurrencyQuery { + query := (&CustomCurrencyClient{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(chargecreditpurchasecostbasis.Table, chargecreditpurchasecostbasis.FieldID, selector), + sqlgraph.To(customcurrency.Table, customcurrency.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargecreditpurchasecostbasis.CustomCurrencyTable, chargecreditpurchasecostbasis.CustomCurrencyColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first ChargeCreditPurchaseCostBasis entity from the query. +// Returns a *NotFoundError when no ChargeCreditPurchaseCostBasis was found. +func (_q *ChargeCreditPurchaseCostBasisQuery) First(ctx context.Context) (*ChargeCreditPurchaseCostBasis, 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{chargecreditpurchasecostbasis.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *ChargeCreditPurchaseCostBasisQuery) FirstX(ctx context.Context) *ChargeCreditPurchaseCostBasis { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first ChargeCreditPurchaseCostBasis ID from the query. +// Returns a *NotFoundError when no ChargeCreditPurchaseCostBasis ID was found. +func (_q *ChargeCreditPurchaseCostBasisQuery) 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{chargecreditpurchasecostbasis.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *ChargeCreditPurchaseCostBasisQuery) FirstIDX(ctx context.Context) string { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single ChargeCreditPurchaseCostBasis entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one ChargeCreditPurchaseCostBasis entity is found. +// Returns a *NotFoundError when no ChargeCreditPurchaseCostBasis entities are found. +func (_q *ChargeCreditPurchaseCostBasisQuery) Only(ctx context.Context) (*ChargeCreditPurchaseCostBasis, 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{chargecreditpurchasecostbasis.Label} + default: + return nil, &NotSingularError{chargecreditpurchasecostbasis.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *ChargeCreditPurchaseCostBasisQuery) OnlyX(ctx context.Context) *ChargeCreditPurchaseCostBasis { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only ChargeCreditPurchaseCostBasis ID in the query. +// Returns a *NotSingularError when more than one ChargeCreditPurchaseCostBasis ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *ChargeCreditPurchaseCostBasisQuery) 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{chargecreditpurchasecostbasis.Label} + default: + err = &NotSingularError{chargecreditpurchasecostbasis.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *ChargeCreditPurchaseCostBasisQuery) 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 ChargeCreditPurchaseCostBases. +func (_q *ChargeCreditPurchaseCostBasisQuery) All(ctx context.Context) ([]*ChargeCreditPurchaseCostBasis, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*ChargeCreditPurchaseCostBasis, *ChargeCreditPurchaseCostBasisQuery]() + return withInterceptors[[]*ChargeCreditPurchaseCostBasis](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *ChargeCreditPurchaseCostBasisQuery) AllX(ctx context.Context) []*ChargeCreditPurchaseCostBasis { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of ChargeCreditPurchaseCostBasis IDs. +func (_q *ChargeCreditPurchaseCostBasisQuery) 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(chargecreditpurchasecostbasis.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *ChargeCreditPurchaseCostBasisQuery) 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 *ChargeCreditPurchaseCostBasisQuery) 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[*ChargeCreditPurchaseCostBasisQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *ChargeCreditPurchaseCostBasisQuery) 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 *ChargeCreditPurchaseCostBasisQuery) 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 *ChargeCreditPurchaseCostBasisQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the ChargeCreditPurchaseCostBasisQuery 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 *ChargeCreditPurchaseCostBasisQuery) Clone() *ChargeCreditPurchaseCostBasisQuery { + if _q == nil { + return nil + } + return &ChargeCreditPurchaseCostBasisQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]chargecreditpurchasecostbasis.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.ChargeCreditPurchaseCostBasis{}, _q.predicates...), + withCurrencyCostBasis: _q.withCurrencyCostBasis.Clone(), + withResolvedCurrencyCostBasis: _q.withResolvedCurrencyCostBasis.Clone(), + withCustomCurrency: _q.withCustomCurrency.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithCurrencyCostBasis tells the query-builder to eager-load the nodes that are connected to +// the "currency_cost_basis" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeCreditPurchaseCostBasisQuery) WithCurrencyCostBasis(opts ...func(*CurrencyCostBasisQuery)) *ChargeCreditPurchaseCostBasisQuery { + query := (&CurrencyCostBasisClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withCurrencyCostBasis = query + return _q +} + +// WithResolvedCurrencyCostBasis tells the query-builder to eager-load the nodes that are connected to +// the "resolved_currency_cost_basis" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeCreditPurchaseCostBasisQuery) WithResolvedCurrencyCostBasis(opts ...func(*CurrencyCostBasisQuery)) *ChargeCreditPurchaseCostBasisQuery { + query := (&CurrencyCostBasisClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withResolvedCurrencyCostBasis = query + return _q +} + +// WithCustomCurrency tells the query-builder to eager-load the nodes that are connected to +// the "custom_currency" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeCreditPurchaseCostBasisQuery) WithCustomCurrency(opts ...func(*CustomCurrencyQuery)) *ChargeCreditPurchaseCostBasisQuery { + query := (&CustomCurrencyClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withCustomCurrency = 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 { +// Mode costbasis.Mode `json:"mode,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.ChargeCreditPurchaseCostBasis.Query(). +// GroupBy(chargecreditpurchasecostbasis.FieldMode). +// Aggregate(db.Count()). +// Scan(ctx, &v) +func (_q *ChargeCreditPurchaseCostBasisQuery) GroupBy(field string, fields ...string) *ChargeCreditPurchaseCostBasisGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &ChargeCreditPurchaseCostBasisGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = chargecreditpurchasecostbasis.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 { +// Mode costbasis.Mode `json:"mode,omitempty"` +// } +// +// client.ChargeCreditPurchaseCostBasis.Query(). +// Select(chargecreditpurchasecostbasis.FieldMode). +// Scan(ctx, &v) +func (_q *ChargeCreditPurchaseCostBasisQuery) Select(fields ...string) *ChargeCreditPurchaseCostBasisSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &ChargeCreditPurchaseCostBasisSelect{ChargeCreditPurchaseCostBasisQuery: _q} + sbuild.label = chargecreditpurchasecostbasis.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a ChargeCreditPurchaseCostBasisSelect configured with the given aggregations. +func (_q *ChargeCreditPurchaseCostBasisQuery) Aggregate(fns ...AggregateFunc) *ChargeCreditPurchaseCostBasisSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *ChargeCreditPurchaseCostBasisQuery) 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 !chargecreditpurchasecostbasis.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 *ChargeCreditPurchaseCostBasisQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ChargeCreditPurchaseCostBasis, error) { + var ( + nodes = []*ChargeCreditPurchaseCostBasis{} + _spec = _q.querySpec() + loadedTypes = [3]bool{ + _q.withCurrencyCostBasis != nil, + _q.withResolvedCurrencyCostBasis != nil, + _q.withCustomCurrency != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*ChargeCreditPurchaseCostBasis).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &ChargeCreditPurchaseCostBasis{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.withCurrencyCostBasis; query != nil { + if err := _q.loadCurrencyCostBasis(ctx, query, nodes, nil, + func(n *ChargeCreditPurchaseCostBasis, e *CurrencyCostBasis) { n.Edges.CurrencyCostBasis = e }); err != nil { + return nil, err + } + } + if query := _q.withResolvedCurrencyCostBasis; query != nil { + if err := _q.loadResolvedCurrencyCostBasis(ctx, query, nodes, nil, + func(n *ChargeCreditPurchaseCostBasis, e *CurrencyCostBasis) { n.Edges.ResolvedCurrencyCostBasis = e }); err != nil { + return nil, err + } + } + if query := _q.withCustomCurrency; query != nil { + if err := _q.loadCustomCurrency(ctx, query, nodes, nil, + func(n *ChargeCreditPurchaseCostBasis, e *CustomCurrency) { n.Edges.CustomCurrency = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *ChargeCreditPurchaseCostBasisQuery) loadCurrencyCostBasis(ctx context.Context, query *CurrencyCostBasisQuery, nodes []*ChargeCreditPurchaseCostBasis, init func(*ChargeCreditPurchaseCostBasis), assign func(*ChargeCreditPurchaseCostBasis, *CurrencyCostBasis)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*ChargeCreditPurchaseCostBasis) + for i := range nodes { + if nodes[i].CurrencyCostBasisID == nil { + continue + } + fk := *nodes[i].CurrencyCostBasisID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(currencycostbasis.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 "currency_cost_basis_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *ChargeCreditPurchaseCostBasisQuery) loadResolvedCurrencyCostBasis(ctx context.Context, query *CurrencyCostBasisQuery, nodes []*ChargeCreditPurchaseCostBasis, init func(*ChargeCreditPurchaseCostBasis), assign func(*ChargeCreditPurchaseCostBasis, *CurrencyCostBasis)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*ChargeCreditPurchaseCostBasis) + for i := range nodes { + if nodes[i].ResolvedCostBasisID == nil { + continue + } + fk := *nodes[i].ResolvedCostBasisID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(currencycostbasis.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 "resolved_cost_basis_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *ChargeCreditPurchaseCostBasisQuery) loadCustomCurrency(ctx context.Context, query *CustomCurrencyQuery, nodes []*ChargeCreditPurchaseCostBasis, init func(*ChargeCreditPurchaseCostBasis), assign func(*ChargeCreditPurchaseCostBasis, *CustomCurrency)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*ChargeCreditPurchaseCostBasis) + for i := range nodes { + fk := nodes[i].CurrencyID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(customcurrency.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 "currency_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (_q *ChargeCreditPurchaseCostBasisQuery) 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 *ChargeCreditPurchaseCostBasisQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(chargecreditpurchasecostbasis.Table, chargecreditpurchasecostbasis.Columns, sqlgraph.NewFieldSpec(chargecreditpurchasecostbasis.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, chargecreditpurchasecostbasis.FieldID) + for i := range fields { + if fields[i] != chargecreditpurchasecostbasis.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withCurrencyCostBasis != nil { + _spec.Node.AddColumnOnce(chargecreditpurchasecostbasis.FieldCurrencyCostBasisID) + } + if _q.withResolvedCurrencyCostBasis != nil { + _spec.Node.AddColumnOnce(chargecreditpurchasecostbasis.FieldResolvedCostBasisID) + } + if _q.withCustomCurrency != nil { + _spec.Node.AddColumnOnce(chargecreditpurchasecostbasis.FieldCurrencyID) + } + } + 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 *ChargeCreditPurchaseCostBasisQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(chargecreditpurchasecostbasis.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = chargecreditpurchasecostbasis.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 *ChargeCreditPurchaseCostBasisQuery) ForUpdate(opts ...sql.LockOption) *ChargeCreditPurchaseCostBasisQuery { + 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 *ChargeCreditPurchaseCostBasisQuery) ForShare(opts ...sql.LockOption) *ChargeCreditPurchaseCostBasisQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForShare(opts...) + }) + return _q +} + +// ChargeCreditPurchaseCostBasisGroupBy is the group-by builder for ChargeCreditPurchaseCostBasis entities. +type ChargeCreditPurchaseCostBasisGroupBy struct { + selector + build *ChargeCreditPurchaseCostBasisQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *ChargeCreditPurchaseCostBasisGroupBy) Aggregate(fns ...AggregateFunc) *ChargeCreditPurchaseCostBasisGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *ChargeCreditPurchaseCostBasisGroupBy) 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[*ChargeCreditPurchaseCostBasisQuery, *ChargeCreditPurchaseCostBasisGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *ChargeCreditPurchaseCostBasisGroupBy) sqlScan(ctx context.Context, root *ChargeCreditPurchaseCostBasisQuery, 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) +} + +// ChargeCreditPurchaseCostBasisSelect is the builder for selecting fields of ChargeCreditPurchaseCostBasis entities. +type ChargeCreditPurchaseCostBasisSelect struct { + *ChargeCreditPurchaseCostBasisQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *ChargeCreditPurchaseCostBasisSelect) Aggregate(fns ...AggregateFunc) *ChargeCreditPurchaseCostBasisSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *ChargeCreditPurchaseCostBasisSelect) 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[*ChargeCreditPurchaseCostBasisQuery, *ChargeCreditPurchaseCostBasisSelect](ctx, _s.ChargeCreditPurchaseCostBasisQuery, _s, _s.inters, v) +} + +func (_s *ChargeCreditPurchaseCostBasisSelect) sqlScan(ctx context.Context, root *ChargeCreditPurchaseCostBasisQuery, 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/chargecreditpurchasecostbasis_update.go b/openmeter/ent/db/chargecreditpurchasecostbasis_update.go new file mode 100644 index 0000000000..0d0051371f --- /dev/null +++ b/openmeter/ent/db/chargecreditpurchasecostbasis_update.go @@ -0,0 +1,666 @@ +// 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/alpacahq/alpacadecimal" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/currencycostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" +) + +// ChargeCreditPurchaseCostBasisUpdate is the builder for updating ChargeCreditPurchaseCostBasis entities. +type ChargeCreditPurchaseCostBasisUpdate struct { + config + hooks []Hook + mutation *ChargeCreditPurchaseCostBasisMutation +} + +// Where appends a list predicates to the ChargeCreditPurchaseCostBasisUpdate builder. +func (_u *ChargeCreditPurchaseCostBasisUpdate) Where(ps ...predicate.ChargeCreditPurchaseCostBasis) *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetCurrencyCostBasisID(v string) *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.SetCurrencyCostBasisID(v) + return _u +} + +// SetNillableCurrencyCostBasisID sets the "currency_cost_basis_id" field if the given value is not nil. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetNillableCurrencyCostBasisID(v *string) *ChargeCreditPurchaseCostBasisUpdate { + if v != nil { + _u.SetCurrencyCostBasisID(*v) + } + return _u +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (_u *ChargeCreditPurchaseCostBasisUpdate) ClearCurrencyCostBasisID() *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.ClearCurrencyCostBasisID() + return _u +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetResolvedCostBasisID(v string) *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.SetResolvedCostBasisID(v) + return _u +} + +// SetNillableResolvedCostBasisID sets the "resolved_cost_basis_id" field if the given value is not nil. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetNillableResolvedCostBasisID(v *string) *ChargeCreditPurchaseCostBasisUpdate { + if v != nil { + _u.SetResolvedCostBasisID(*v) + } + return _u +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (_u *ChargeCreditPurchaseCostBasisUpdate) ClearResolvedCostBasisID() *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.ClearResolvedCostBasisID() + return _u +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.SetResolvedCostBasis(v) + return _u +} + +// SetNillableResolvedCostBasis sets the "resolved_cost_basis" field if the given value is not nil. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetNillableResolvedCostBasis(v *alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisUpdate { + if v != nil { + _u.SetResolvedCostBasis(*v) + } + return _u +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (_u *ChargeCreditPurchaseCostBasisUpdate) ClearResolvedCostBasis() *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.ClearResolvedCostBasis() + return _u +} + +// SetResolvedAt sets the "resolved_at" field. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetResolvedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.SetResolvedAt(v) + return _u +} + +// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetNillableResolvedAt(v *time.Time) *ChargeCreditPurchaseCostBasisUpdate { + if v != nil { + _u.SetResolvedAt(*v) + } + return _u +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (_u *ChargeCreditPurchaseCostBasisUpdate) ClearResolvedAt() *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.ClearResolvedAt() + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetUpdatedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetDeletedAt sets the "deleted_at" field. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetDeletedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.SetDeletedAt(v) + return _u +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetNillableDeletedAt(v *time.Time) *ChargeCreditPurchaseCostBasisUpdate { + if v != nil { + _u.SetDeletedAt(*v) + } + return _u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (_u *ChargeCreditPurchaseCostBasisUpdate) ClearDeletedAt() *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.ClearDeletedAt() + return _u +} + +// SetCurrencyCostBasis sets the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetCurrencyCostBasis(v *CurrencyCostBasis) *ChargeCreditPurchaseCostBasisUpdate { + return _u.SetCurrencyCostBasisID(v.ID) +} + +// SetResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetResolvedCurrencyCostBasisID(id string) *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.SetResolvedCurrencyCostBasisID(id) + return _u +} + +// SetNillableResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID if the given value is not nil. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetNillableResolvedCurrencyCostBasisID(id *string) *ChargeCreditPurchaseCostBasisUpdate { + if id != nil { + _u = _u.SetResolvedCurrencyCostBasisID(*id) + } + return _u +} + +// SetResolvedCurrencyCostBasis sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeCreditPurchaseCostBasisUpdate) SetResolvedCurrencyCostBasis(v *CurrencyCostBasis) *ChargeCreditPurchaseCostBasisUpdate { + return _u.SetResolvedCurrencyCostBasisID(v.ID) +} + +// Mutation returns the ChargeCreditPurchaseCostBasisMutation object of the builder. +func (_u *ChargeCreditPurchaseCostBasisUpdate) Mutation() *ChargeCreditPurchaseCostBasisMutation { + return _u.mutation +} + +// ClearCurrencyCostBasis clears the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeCreditPurchaseCostBasisUpdate) ClearCurrencyCostBasis() *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.ClearCurrencyCostBasis() + return _u +} + +// ClearResolvedCurrencyCostBasis clears the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeCreditPurchaseCostBasisUpdate) ClearResolvedCurrencyCostBasis() *ChargeCreditPurchaseCostBasisUpdate { + _u.mutation.ClearResolvedCurrencyCostBasis() + return _u +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *ChargeCreditPurchaseCostBasisUpdate) 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 *ChargeCreditPurchaseCostBasisUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *ChargeCreditPurchaseCostBasisUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ChargeCreditPurchaseCostBasisUpdate) 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 *ChargeCreditPurchaseCostBasisUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := chargecreditpurchasecostbasis.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ChargeCreditPurchaseCostBasisUpdate) check() error { + if _u.mutation.CustomCurrencyCleared() && len(_u.mutation.CustomCurrencyIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "ChargeCreditPurchaseCostBasis.custom_currency"`) + } + return nil +} + +func (_u *ChargeCreditPurchaseCostBasisUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(chargecreditpurchasecostbasis.Table, chargecreditpurchasecostbasis.Columns, sqlgraph.NewFieldSpec(chargecreditpurchasecostbasis.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 _u.mutation.ManualRateCleared() { + _spec.ClearField(chargecreditpurchasecostbasis.FieldManualRate, field.TypeOther) + } + if value, ok := _u.mutation.ResolvedCostBasis(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldResolvedCostBasis, field.TypeOther, value) + } + if _u.mutation.ResolvedCostBasisCleared() { + _spec.ClearField(chargecreditpurchasecostbasis.FieldResolvedCostBasis, field.TypeOther) + } + if value, ok := _u.mutation.ResolvedAt(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldResolvedAt, field.TypeTime, value) + } + if _u.mutation.ResolvedAtCleared() { + _spec.ClearField(chargecreditpurchasecostbasis.FieldResolvedAt, field.TypeTime) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.DeletedAt(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldDeletedAt, field.TypeTime, value) + } + if _u.mutation.DeletedAtCleared() { + _spec.ClearField(chargecreditpurchasecostbasis.FieldDeletedAt, field.TypeTime) + } + if _u.mutation.CurrencyCostBasisCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargecreditpurchasecostbasis.CurrencyCostBasisTable, + Columns: []string{chargecreditpurchasecostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.CurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargecreditpurchasecostbasis.CurrencyCostBasisTable, + Columns: []string{chargecreditpurchasecostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.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.ResolvedCurrencyCostBasisCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ResolvedCurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.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{chargecreditpurchasecostbasis.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// ChargeCreditPurchaseCostBasisUpdateOne is the builder for updating a single ChargeCreditPurchaseCostBasis entity. +type ChargeCreditPurchaseCostBasisUpdateOne struct { + config + fields []string + hooks []Hook + mutation *ChargeCreditPurchaseCostBasisMutation +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetCurrencyCostBasisID(v string) *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.SetCurrencyCostBasisID(v) + return _u +} + +// SetNillableCurrencyCostBasisID sets the "currency_cost_basis_id" field if the given value is not nil. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetNillableCurrencyCostBasisID(v *string) *ChargeCreditPurchaseCostBasisUpdateOne { + if v != nil { + _u.SetCurrencyCostBasisID(*v) + } + return _u +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) ClearCurrencyCostBasisID() *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.ClearCurrencyCostBasisID() + return _u +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetResolvedCostBasisID(v string) *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.SetResolvedCostBasisID(v) + return _u +} + +// SetNillableResolvedCostBasisID sets the "resolved_cost_basis_id" field if the given value is not nil. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetNillableResolvedCostBasisID(v *string) *ChargeCreditPurchaseCostBasisUpdateOne { + if v != nil { + _u.SetResolvedCostBasisID(*v) + } + return _u +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) ClearResolvedCostBasisID() *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.ClearResolvedCostBasisID() + return _u +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.SetResolvedCostBasis(v) + return _u +} + +// SetNillableResolvedCostBasis sets the "resolved_cost_basis" field if the given value is not nil. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetNillableResolvedCostBasis(v *alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisUpdateOne { + if v != nil { + _u.SetResolvedCostBasis(*v) + } + return _u +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) ClearResolvedCostBasis() *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.ClearResolvedCostBasis() + return _u +} + +// SetResolvedAt sets the "resolved_at" field. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetResolvedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.SetResolvedAt(v) + return _u +} + +// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetNillableResolvedAt(v *time.Time) *ChargeCreditPurchaseCostBasisUpdateOne { + if v != nil { + _u.SetResolvedAt(*v) + } + return _u +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) ClearResolvedAt() *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.ClearResolvedAt() + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetUpdatedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetDeletedAt sets the "deleted_at" field. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetDeletedAt(v time.Time) *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.SetDeletedAt(v) + return _u +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetNillableDeletedAt(v *time.Time) *ChargeCreditPurchaseCostBasisUpdateOne { + if v != nil { + _u.SetDeletedAt(*v) + } + return _u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) ClearDeletedAt() *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.ClearDeletedAt() + return _u +} + +// SetCurrencyCostBasis sets the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetCurrencyCostBasis(v *CurrencyCostBasis) *ChargeCreditPurchaseCostBasisUpdateOne { + return _u.SetCurrencyCostBasisID(v.ID) +} + +// SetResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetResolvedCurrencyCostBasisID(id string) *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.SetResolvedCurrencyCostBasisID(id) + return _u +} + +// SetNillableResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID if the given value is not nil. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetNillableResolvedCurrencyCostBasisID(id *string) *ChargeCreditPurchaseCostBasisUpdateOne { + if id != nil { + _u = _u.SetResolvedCurrencyCostBasisID(*id) + } + return _u +} + +// SetResolvedCurrencyCostBasis sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SetResolvedCurrencyCostBasis(v *CurrencyCostBasis) *ChargeCreditPurchaseCostBasisUpdateOne { + return _u.SetResolvedCurrencyCostBasisID(v.ID) +} + +// Mutation returns the ChargeCreditPurchaseCostBasisMutation object of the builder. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) Mutation() *ChargeCreditPurchaseCostBasisMutation { + return _u.mutation +} + +// ClearCurrencyCostBasis clears the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) ClearCurrencyCostBasis() *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.ClearCurrencyCostBasis() + return _u +} + +// ClearResolvedCurrencyCostBasis clears the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) ClearResolvedCurrencyCostBasis() *ChargeCreditPurchaseCostBasisUpdateOne { + _u.mutation.ClearResolvedCurrencyCostBasis() + return _u +} + +// Where appends a list predicates to the ChargeCreditPurchaseCostBasisUpdate builder. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) Where(ps ...predicate.ChargeCreditPurchaseCostBasis) *ChargeCreditPurchaseCostBasisUpdateOne { + _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 *ChargeCreditPurchaseCostBasisUpdateOne) Select(field string, fields ...string) *ChargeCreditPurchaseCostBasisUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated ChargeCreditPurchaseCostBasis entity. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) Save(ctx context.Context) (*ChargeCreditPurchaseCostBasis, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) SaveX(ctx context.Context) *ChargeCreditPurchaseCostBasis { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) 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 *ChargeCreditPurchaseCostBasisUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := chargecreditpurchasecostbasis.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) check() error { + if _u.mutation.CustomCurrencyCleared() && len(_u.mutation.CustomCurrencyIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "ChargeCreditPurchaseCostBasis.custom_currency"`) + } + return nil +} + +func (_u *ChargeCreditPurchaseCostBasisUpdateOne) sqlSave(ctx context.Context) (_node *ChargeCreditPurchaseCostBasis, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(chargecreditpurchasecostbasis.Table, chargecreditpurchasecostbasis.Columns, sqlgraph.NewFieldSpec(chargecreditpurchasecostbasis.FieldID, field.TypeString)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "ChargeCreditPurchaseCostBasis.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, chargecreditpurchasecostbasis.FieldID) + for _, f := range fields { + if !chargecreditpurchasecostbasis.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + if f != chargecreditpurchasecostbasis.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 _u.mutation.ManualRateCleared() { + _spec.ClearField(chargecreditpurchasecostbasis.FieldManualRate, field.TypeOther) + } + if value, ok := _u.mutation.ResolvedCostBasis(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldResolvedCostBasis, field.TypeOther, value) + } + if _u.mutation.ResolvedCostBasisCleared() { + _spec.ClearField(chargecreditpurchasecostbasis.FieldResolvedCostBasis, field.TypeOther) + } + if value, ok := _u.mutation.ResolvedAt(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldResolvedAt, field.TypeTime, value) + } + if _u.mutation.ResolvedAtCleared() { + _spec.ClearField(chargecreditpurchasecostbasis.FieldResolvedAt, field.TypeTime) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.DeletedAt(); ok { + _spec.SetField(chargecreditpurchasecostbasis.FieldDeletedAt, field.TypeTime, value) + } + if _u.mutation.DeletedAtCleared() { + _spec.ClearField(chargecreditpurchasecostbasis.FieldDeletedAt, field.TypeTime) + } + if _u.mutation.CurrencyCostBasisCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargecreditpurchasecostbasis.CurrencyCostBasisTable, + Columns: []string{chargecreditpurchasecostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.CurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargecreditpurchasecostbasis.CurrencyCostBasisTable, + Columns: []string{chargecreditpurchasecostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.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.ResolvedCurrencyCostBasisCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ResolvedCurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &ChargeCreditPurchaseCostBasis{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{chargecreditpurchasecostbasis.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/chargeflatfee.go b/openmeter/ent/db/chargeflatfee.go index 0ef67d48c7..ad43311e6b 100644 --- a/openmeter/ent/db/chargeflatfee.go +++ b/openmeter/ent/db/chargeflatfee.go @@ -16,6 +16,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfee" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeerun" "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" @@ -109,6 +110,8 @@ type ChargeFlatFee struct { AmountAfterProration alpacadecimal.Decimal `json:"amount_after_proration,omitempty"` // CurrentRealizationRunID holds the value of the "current_realization_run_id" field. CurrentRealizationRunID *string `json:"current_realization_run_id,omitempty"` + // CostBasisID holds the value of the "cost_basis_id" field. + CostBasisID *string `json:"cost_basis_id,omitempty"` // StatusDetailed holds the value of the "status_detailed" field. StatusDetailed flatfee.Status `json:"status_detailed,omitempty"` // Edges holds the relations/edges for other nodes in the graph. @@ -123,6 +126,8 @@ type ChargeFlatFeeEdges struct { Runs []*ChargeFlatFeeRun `json:"runs,omitempty"` // CurrentRun holds the value of the current_run edge. CurrentRun *ChargeFlatFeeRun `json:"current_run,omitempty"` + // CostBasis holds the value of the cost_basis edge. + CostBasis *ChargeFlatFeeCostBasis `json:"cost_basis,omitempty"` // Charge holds the value of the charge edge. Charge *Charge `json:"charge,omitempty"` // IntentOverride holds the value of the intent_override edge. @@ -143,7 +148,7 @@ type ChargeFlatFeeEdges struct { CustomCurrency *CustomCurrency `json:"custom_currency,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 } // RunsOrErr returns the Runs value or an error if the edge @@ -166,12 +171,23 @@ func (e ChargeFlatFeeEdges) CurrentRunOrErr() (*ChargeFlatFeeRun, error) { return nil, &NotLoadedError{edge: "current_run"} } +// CostBasisOrErr returns the CostBasis value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChargeFlatFeeEdges) CostBasisOrErr() (*ChargeFlatFeeCostBasis, error) { + if e.CostBasis != nil { + return e.CostBasis, nil + } else if e.loadedTypes[2] { + return nil, &NotFoundError{label: chargeflatfeecostbasis.Label} + } + return nil, &NotLoadedError{edge: "cost_basis"} +} + // 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 ChargeFlatFeeEdges) ChargeOrErr() (*Charge, error) { if e.Charge != nil { return e.Charge, nil - } else if e.loadedTypes[2] { + } else if e.loadedTypes[3] { return nil, &NotFoundError{label: charge.Label} } return nil, &NotLoadedError{edge: "charge"} @@ -182,7 +198,7 @@ func (e ChargeFlatFeeEdges) ChargeOrErr() (*Charge, error) { func (e ChargeFlatFeeEdges) IntentOverrideOrErr() (*ChargeFlatFeeOverride, error) { if e.IntentOverride != nil { return e.IntentOverride, nil - } else if e.loadedTypes[3] { + } else if e.loadedTypes[4] { return nil, &NotFoundError{label: chargeflatfeeoverride.Label} } return nil, &NotLoadedError{edge: "intent_override"} @@ -193,7 +209,7 @@ func (e ChargeFlatFeeEdges) IntentOverrideOrErr() (*ChargeFlatFeeOverride, error func (e ChargeFlatFeeEdges) SubscriptionOrErr() (*Subscription, error) { if e.Subscription != nil { return e.Subscription, nil - } else if e.loadedTypes[4] { + } else if e.loadedTypes[5] { return nil, &NotFoundError{label: subscription.Label} } return nil, &NotLoadedError{edge: "subscription"} @@ -204,7 +220,7 @@ func (e ChargeFlatFeeEdges) SubscriptionOrErr() (*Subscription, error) { func (e ChargeFlatFeeEdges) SubscriptionPhaseOrErr() (*SubscriptionPhase, error) { if e.SubscriptionPhase != nil { return e.SubscriptionPhase, nil - } else if e.loadedTypes[5] { + } else if e.loadedTypes[6] { return nil, &NotFoundError{label: subscriptionphase.Label} } return nil, &NotLoadedError{edge: "subscription_phase"} @@ -215,7 +231,7 @@ func (e ChargeFlatFeeEdges) SubscriptionPhaseOrErr() (*SubscriptionPhase, error) func (e ChargeFlatFeeEdges) SubscriptionItemOrErr() (*SubscriptionItem, error) { if e.SubscriptionItem != nil { return e.SubscriptionItem, nil - } else if e.loadedTypes[6] { + } else if e.loadedTypes[7] { return nil, &NotFoundError{label: subscriptionitem.Label} } return nil, &NotLoadedError{edge: "subscription_item"} @@ -226,7 +242,7 @@ func (e ChargeFlatFeeEdges) SubscriptionItemOrErr() (*SubscriptionItem, error) { func (e ChargeFlatFeeEdges) CustomerOrErr() (*Customer, error) { if e.Customer != nil { return e.Customer, nil - } else if e.loadedTypes[7] { + } else if e.loadedTypes[8] { return nil, &NotFoundError{label: customer.Label} } return nil, &NotLoadedError{edge: "customer"} @@ -237,7 +253,7 @@ func (e ChargeFlatFeeEdges) CustomerOrErr() (*Customer, error) { func (e ChargeFlatFeeEdges) FeatureOrErr() (*Feature, error) { if e.Feature != nil { return e.Feature, nil - } else if e.loadedTypes[8] { + } else if e.loadedTypes[9] { return nil, &NotFoundError{label: dbfeature.Label} } return nil, &NotLoadedError{edge: "feature"} @@ -248,7 +264,7 @@ func (e ChargeFlatFeeEdges) FeatureOrErr() (*Feature, error) { func (e ChargeFlatFeeEdges) TaxCodeOrErr() (*TaxCode, error) { if e.TaxCode != nil { return e.TaxCode, nil - } else if e.loadedTypes[9] { + } else if e.loadedTypes[10] { return nil, &NotFoundError{label: dbtaxcode.Label} } return nil, &NotLoadedError{edge: "tax_code"} @@ -259,7 +275,7 @@ func (e ChargeFlatFeeEdges) TaxCodeOrErr() (*TaxCode, error) { func (e ChargeFlatFeeEdges) CustomCurrencyOrErr() (*CustomCurrency, error) { if e.CustomCurrency != nil { return e.CustomCurrency, nil - } else if e.loadedTypes[10] { + } else if e.loadedTypes[11] { return nil, &NotFoundError{label: customcurrency.Label} } return nil, &NotLoadedError{edge: "custom_currency"} @@ -274,7 +290,7 @@ func (*ChargeFlatFee) scanValues(columns []string) ([]any, error) { values[i] = new([]byte) case chargeflatfee.FieldAmountBeforeProration, chargeflatfee.FieldAmountAfterProration: values[i] = new(alpacadecimal.Decimal) - case chargeflatfee.FieldID, chargeflatfee.FieldCustomerID, chargeflatfee.FieldStatus, chargeflatfee.FieldUniqueReferenceID, chargeflatfee.FieldFiatCurrencyCode, chargeflatfee.FieldCustomCurrencyID, chargeflatfee.FieldManagedBy, chargeflatfee.FieldSubscriptionID, chargeflatfee.FieldSubscriptionPhaseID, chargeflatfee.FieldSubscriptionItemID, chargeflatfee.FieldTaxCodeID, chargeflatfee.FieldTaxBehavior, chargeflatfee.FieldNamespace, chargeflatfee.FieldName, chargeflatfee.FieldDescription, chargeflatfee.FieldPaymentTerm, chargeflatfee.FieldSettlementMode, chargeflatfee.FieldProRating, chargeflatfee.FieldFeatureKey, chargeflatfee.FieldFeatureID, chargeflatfee.FieldCurrentRealizationRunID, chargeflatfee.FieldStatusDetailed: + case chargeflatfee.FieldID, chargeflatfee.FieldCustomerID, chargeflatfee.FieldStatus, chargeflatfee.FieldUniqueReferenceID, chargeflatfee.FieldFiatCurrencyCode, chargeflatfee.FieldCustomCurrencyID, chargeflatfee.FieldManagedBy, chargeflatfee.FieldSubscriptionID, chargeflatfee.FieldSubscriptionPhaseID, chargeflatfee.FieldSubscriptionItemID, chargeflatfee.FieldTaxCodeID, chargeflatfee.FieldTaxBehavior, chargeflatfee.FieldNamespace, chargeflatfee.FieldName, chargeflatfee.FieldDescription, chargeflatfee.FieldPaymentTerm, chargeflatfee.FieldSettlementMode, chargeflatfee.FieldProRating, chargeflatfee.FieldFeatureKey, chargeflatfee.FieldFeatureID, chargeflatfee.FieldCurrentRealizationRunID, chargeflatfee.FieldCostBasisID, chargeflatfee.FieldStatusDetailed: values[i] = new(sql.NullString) case chargeflatfee.FieldServicePeriodFrom, chargeflatfee.FieldServicePeriodTo, chargeflatfee.FieldBillingPeriodFrom, chargeflatfee.FieldBillingPeriodTo, chargeflatfee.FieldFullServicePeriodFrom, chargeflatfee.FieldFullServicePeriodTo, chargeflatfee.FieldAdvanceAfter, chargeflatfee.FieldCreatedAt, chargeflatfee.FieldUpdatedAt, chargeflatfee.FieldDeletedAt, chargeflatfee.FieldInvoiceAt, chargeflatfee.FieldIntentDeletedAt: values[i] = new(sql.NullTime) @@ -541,6 +557,13 @@ func (_m *ChargeFlatFee) assignValues(columns []string, values []any) error { _m.CurrentRealizationRunID = new(string) *_m.CurrentRealizationRunID = value.String } + case chargeflatfee.FieldCostBasisID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field cost_basis_id", values[i]) + } else if value.Valid { + _m.CostBasisID = new(string) + *_m.CostBasisID = value.String + } case chargeflatfee.FieldStatusDetailed: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field status_detailed", values[i]) @@ -570,6 +593,11 @@ func (_m *ChargeFlatFee) QueryCurrentRun() *ChargeFlatFeeRunQuery { return NewChargeFlatFeeClient(_m.config).QueryCurrentRun(_m) } +// QueryCostBasis queries the "cost_basis" edge of the ChargeFlatFee entity. +func (_m *ChargeFlatFee) QueryCostBasis() *ChargeFlatFeeCostBasisQuery { + return NewChargeFlatFeeClient(_m.config).QueryCostBasis(_m) +} + // QueryCharge queries the "charge" edge of the ChargeFlatFee entity. func (_m *ChargeFlatFee) QueryCharge() *ChargeQuery { return NewChargeFlatFeeClient(_m.config).QueryCharge(_m) @@ -779,6 +807,11 @@ func (_m *ChargeFlatFee) String() string { builder.WriteString(*v) } builder.WriteString(", ") + if v := _m.CostBasisID; v != nil { + builder.WriteString("cost_basis_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") builder.WriteString("status_detailed=") builder.WriteString(fmt.Sprintf("%v", _m.StatusDetailed)) builder.WriteByte(')') diff --git a/openmeter/ent/db/chargeflatfee/chargeflatfee.go b/openmeter/ent/db/chargeflatfee/chargeflatfee.go index 0674a4f276..0e4681027d 100644 --- a/openmeter/ent/db/chargeflatfee/chargeflatfee.go +++ b/openmeter/ent/db/chargeflatfee/chargeflatfee.go @@ -94,12 +94,16 @@ const ( FieldAmountAfterProration = "amount_after_proration" // FieldCurrentRealizationRunID holds the string denoting the current_realization_run_id field in the database. FieldCurrentRealizationRunID = "current_realization_run_id" + // FieldCostBasisID holds the string denoting the cost_basis_id field in the database. + FieldCostBasisID = "cost_basis_id" // FieldStatusDetailed holds the string denoting the status_detailed field in the database. FieldStatusDetailed = "status_detailed" // EdgeRuns holds the string denoting the runs edge name in mutations. EdgeRuns = "runs" // EdgeCurrentRun holds the string denoting the current_run edge name in mutations. EdgeCurrentRun = "current_run" + // EdgeCostBasis holds the string denoting the cost_basis edge name in mutations. + EdgeCostBasis = "cost_basis" // EdgeCharge holds the string denoting the charge edge name in mutations. EdgeCharge = "charge" // EdgeIntentOverride holds the string denoting the intent_override edge name in mutations. @@ -134,6 +138,13 @@ const ( CurrentRunInverseTable = "charge_flat_fee_runs" // CurrentRunColumn is the table column denoting the current_run relation/edge. CurrentRunColumn = "current_realization_run_id" + // CostBasisTable is the table that holds the cost_basis relation/edge. + CostBasisTable = "charge_flat_fees" + // CostBasisInverseTable is the table name for the ChargeFlatFeeCostBasis entity. + // It exists in this package in order to avoid circular dependency with the "chargeflatfeecostbasis" package. + CostBasisInverseTable = "charge_flat_fee_cost_bases" + // CostBasisColumn is the table column denoting the cost_basis relation/edge. + CostBasisColumn = "cost_basis_id" // ChargeTable is the table that holds the charge relation/edge. ChargeTable = "charges" // ChargeInverseTable is the table name for the Charge entity. @@ -239,6 +250,7 @@ var Columns = []string{ FieldAmountBeforeProration, FieldAmountAfterProration, FieldCurrentRealizationRunID, + FieldCostBasisID, FieldStatusDetailed, } @@ -524,6 +536,11 @@ func ByCurrentRealizationRunID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCurrentRealizationRunID, opts...).ToFunc() } +// ByCostBasisID orders the results by the cost_basis_id field. +func ByCostBasisID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCostBasisID, opts...).ToFunc() +} + // ByStatusDetailed orders the results by the status_detailed field. func ByStatusDetailed(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldStatusDetailed, opts...).ToFunc() @@ -550,6 +567,13 @@ func ByCurrentRunField(field string, opts ...sql.OrderTermOption) OrderOption { } } +// ByCostBasisField orders the results by cost_basis field. +func ByCostBasisField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCostBasisStep(), sql.OrderByField(field, opts...)) + } +} + // ByChargeField orders the results by charge field. func ByChargeField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -626,6 +650,13 @@ func newCurrentRunStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.M2O, false, CurrentRunTable, CurrentRunColumn), ) } +func newCostBasisStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CostBasisInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CostBasisTable, CostBasisColumn), + ) +} func newChargeStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/openmeter/ent/db/chargeflatfee/where.go b/openmeter/ent/db/chargeflatfee/where.go index e1357522e1..3bfdc1f4e5 100644 --- a/openmeter/ent/db/chargeflatfee/where.go +++ b/openmeter/ent/db/chargeflatfee/where.go @@ -218,6 +218,11 @@ func CurrentRealizationRunID(v string) predicate.ChargeFlatFee { return predicate.ChargeFlatFee(sql.FieldEQ(FieldCurrentRealizationRunID, v)) } +// CostBasisID applies equality check predicate on the "cost_basis_id" field. It's identical to CostBasisIDEQ. +func CostBasisID(v string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldEQ(FieldCostBasisID, v)) +} + // CustomerIDEQ applies the EQ predicate on the "customer_id" field. func CustomerIDEQ(v string) predicate.ChargeFlatFee { return predicate.ChargeFlatFee(sql.FieldEQ(FieldCustomerID, v)) @@ -2111,6 +2116,81 @@ func CurrentRealizationRunIDContainsFold(v string) predicate.ChargeFlatFee { return predicate.ChargeFlatFee(sql.FieldContainsFold(FieldCurrentRealizationRunID, v)) } +// CostBasisIDEQ applies the EQ predicate on the "cost_basis_id" field. +func CostBasisIDEQ(v string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldEQ(FieldCostBasisID, v)) +} + +// CostBasisIDNEQ applies the NEQ predicate on the "cost_basis_id" field. +func CostBasisIDNEQ(v string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldNEQ(FieldCostBasisID, v)) +} + +// CostBasisIDIn applies the In predicate on the "cost_basis_id" field. +func CostBasisIDIn(vs ...string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldIn(FieldCostBasisID, vs...)) +} + +// CostBasisIDNotIn applies the NotIn predicate on the "cost_basis_id" field. +func CostBasisIDNotIn(vs ...string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldNotIn(FieldCostBasisID, vs...)) +} + +// CostBasisIDGT applies the GT predicate on the "cost_basis_id" field. +func CostBasisIDGT(v string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldGT(FieldCostBasisID, v)) +} + +// CostBasisIDGTE applies the GTE predicate on the "cost_basis_id" field. +func CostBasisIDGTE(v string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldGTE(FieldCostBasisID, v)) +} + +// CostBasisIDLT applies the LT predicate on the "cost_basis_id" field. +func CostBasisIDLT(v string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldLT(FieldCostBasisID, v)) +} + +// CostBasisIDLTE applies the LTE predicate on the "cost_basis_id" field. +func CostBasisIDLTE(v string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldLTE(FieldCostBasisID, v)) +} + +// CostBasisIDContains applies the Contains predicate on the "cost_basis_id" field. +func CostBasisIDContains(v string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldContains(FieldCostBasisID, v)) +} + +// CostBasisIDHasPrefix applies the HasPrefix predicate on the "cost_basis_id" field. +func CostBasisIDHasPrefix(v string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldHasPrefix(FieldCostBasisID, v)) +} + +// CostBasisIDHasSuffix applies the HasSuffix predicate on the "cost_basis_id" field. +func CostBasisIDHasSuffix(v string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldHasSuffix(FieldCostBasisID, v)) +} + +// CostBasisIDIsNil applies the IsNil predicate on the "cost_basis_id" field. +func CostBasisIDIsNil() predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldIsNull(FieldCostBasisID)) +} + +// CostBasisIDNotNil applies the NotNil predicate on the "cost_basis_id" field. +func CostBasisIDNotNil() predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldNotNull(FieldCostBasisID)) +} + +// CostBasisIDEqualFold applies the EqualFold predicate on the "cost_basis_id" field. +func CostBasisIDEqualFold(v string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldEqualFold(FieldCostBasisID, v)) +} + +// CostBasisIDContainsFold applies the ContainsFold predicate on the "cost_basis_id" field. +func CostBasisIDContainsFold(v string) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(sql.FieldContainsFold(FieldCostBasisID, v)) +} + // StatusDetailedEQ applies the EQ predicate on the "status_detailed" field. func StatusDetailedEQ(v flatfee.Status) predicate.ChargeFlatFee { vc := v @@ -2187,6 +2267,29 @@ func HasCurrentRunWith(preds ...predicate.ChargeFlatFeeRun) predicate.ChargeFlat }) } +// HasCostBasis applies the HasEdge predicate on the "cost_basis" edge. +func HasCostBasis() predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CostBasisTable, CostBasisColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasCostBasisWith applies the HasEdge predicate on the "cost_basis" edge with a given conditions (other predicates). +func HasCostBasisWith(preds ...predicate.ChargeFlatFeeCostBasis) predicate.ChargeFlatFee { + return predicate.ChargeFlatFee(func(s *sql.Selector) { + step := newCostBasisStep() + 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.ChargeFlatFee { return predicate.ChargeFlatFee(func(s *sql.Selector) { diff --git a/openmeter/ent/db/chargeflatfee_create.go b/openmeter/ent/db/chargeflatfee_create.go index 5e12522eef..b5484b8dd3 100644 --- a/openmeter/ent/db/chargeflatfee_create.go +++ b/openmeter/ent/db/chargeflatfee_create.go @@ -18,6 +18,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfee" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeerun" "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" @@ -390,6 +391,20 @@ func (_c *ChargeFlatFeeCreate) SetNillableCurrentRealizationRunID(v *string) *Ch return _c } +// SetCostBasisID sets the "cost_basis_id" field. +func (_c *ChargeFlatFeeCreate) SetCostBasisID(v string) *ChargeFlatFeeCreate { + _c.mutation.SetCostBasisID(v) + return _c +} + +// SetNillableCostBasisID sets the "cost_basis_id" field if the given value is not nil. +func (_c *ChargeFlatFeeCreate) SetNillableCostBasisID(v *string) *ChargeFlatFeeCreate { + if v != nil { + _c.SetCostBasisID(*v) + } + return _c +} + // SetStatusDetailed sets the "status_detailed" field. func (_c *ChargeFlatFeeCreate) SetStatusDetailed(v flatfee.Status) *ChargeFlatFeeCreate { _c.mutation.SetStatusDetailed(v) @@ -444,6 +459,11 @@ func (_c *ChargeFlatFeeCreate) SetCurrentRun(v *ChargeFlatFeeRun) *ChargeFlatFee return _c.SetCurrentRunID(v.ID) } +// SetCostBasis sets the "cost_basis" edge to the ChargeFlatFeeCostBasis entity. +func (_c *ChargeFlatFeeCreate) SetCostBasis(v *ChargeFlatFeeCostBasis) *ChargeFlatFeeCreate { + return _c.SetCostBasisID(v.ID) +} + // SetChargeID sets the "charge" edge to the Charge entity by ID. func (_c *ChargeFlatFeeCreate) SetChargeID(id string) *ChargeFlatFeeCreate { _c.mutation.SetChargeID(id) @@ -903,6 +923,23 @@ func (_c *ChargeFlatFeeCreate) createSpec() (*ChargeFlatFee, *sqlgraph.CreateSpe _node.CurrentRealizationRunID = &nodes[0] _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.CostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeflatfee.CostBasisTable, + Columns: []string{chargeflatfee.CostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(chargeflatfeecostbasis.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.CostBasisID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.ChargeIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2O, @@ -1522,6 +1559,9 @@ func (u *ChargeFlatFeeUpsertOne) UpdateNewValues() *ChargeFlatFeeUpsertOne { if _, exists := u.create.mutation.FeatureKey(); exists { s.SetIgnore(chargeflatfee.FieldFeatureKey) } + if _, exists := u.create.mutation.CostBasisID(); exists { + s.SetIgnore(chargeflatfee.FieldCostBasisID) + } })) return u } @@ -2198,6 +2238,9 @@ func (u *ChargeFlatFeeUpsertBulk) UpdateNewValues() *ChargeFlatFeeUpsertBulk { if _, exists := b.mutation.FeatureKey(); exists { s.SetIgnore(chargeflatfee.FieldFeatureKey) } + if _, exists := b.mutation.CostBasisID(); exists { + s.SetIgnore(chargeflatfee.FieldCostBasisID) + } } })) return u diff --git a/openmeter/ent/db/chargeflatfee_query.go b/openmeter/ent/db/chargeflatfee_query.go index 04c16417c8..fe586e8ebb 100644 --- a/openmeter/ent/db/chargeflatfee_query.go +++ b/openmeter/ent/db/chargeflatfee_query.go @@ -15,6 +15,7 @@ import ( "entgo.io/ent/schema/field" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfee" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeerun" "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" @@ -36,6 +37,7 @@ type ChargeFlatFeeQuery struct { predicates []predicate.ChargeFlatFee withRuns *ChargeFlatFeeRunQuery withCurrentRun *ChargeFlatFeeRunQuery + withCostBasis *ChargeFlatFeeCostBasisQuery withCharge *ChargeQuery withIntentOverride *ChargeFlatFeeOverrideQuery withSubscription *SubscriptionQuery @@ -126,6 +128,28 @@ func (_q *ChargeFlatFeeQuery) QueryCurrentRun() *ChargeFlatFeeRunQuery { return query } +// QueryCostBasis chains the current query on the "cost_basis" edge. +func (_q *ChargeFlatFeeQuery) QueryCostBasis() *ChargeFlatFeeCostBasisQuery { + query := (&ChargeFlatFeeCostBasisClient{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(chargeflatfee.Table, chargeflatfee.FieldID, selector), + sqlgraph.To(chargeflatfeecostbasis.Table, chargeflatfeecostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeflatfee.CostBasisTable, chargeflatfee.CostBasisColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryCharge chains the current query on the "charge" edge. func (_q *ChargeFlatFeeQuery) QueryCharge() *ChargeQuery { query := (&ChargeClient{config: _q.config}).Query() @@ -518,6 +542,7 @@ func (_q *ChargeFlatFeeQuery) Clone() *ChargeFlatFeeQuery { predicates: append([]predicate.ChargeFlatFee{}, _q.predicates...), withRuns: _q.withRuns.Clone(), withCurrentRun: _q.withCurrentRun.Clone(), + withCostBasis: _q.withCostBasis.Clone(), withCharge: _q.withCharge.Clone(), withIntentOverride: _q.withIntentOverride.Clone(), withSubscription: _q.withSubscription.Clone(), @@ -555,6 +580,17 @@ func (_q *ChargeFlatFeeQuery) WithCurrentRun(opts ...func(*ChargeFlatFeeRunQuery return _q } +// WithCostBasis tells the query-builder to eager-load the nodes that are connected to +// the "cost_basis" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeFlatFeeQuery) WithCostBasis(opts ...func(*ChargeFlatFeeCostBasisQuery)) *ChargeFlatFeeQuery { + query := (&ChargeFlatFeeCostBasisClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withCostBasis = 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 *ChargeFlatFeeQuery) WithCharge(opts ...func(*ChargeQuery)) *ChargeFlatFeeQuery { @@ -732,9 +768,10 @@ func (_q *ChargeFlatFeeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([ var ( nodes = []*ChargeFlatFee{} _spec = _q.querySpec() - loadedTypes = [11]bool{ + loadedTypes = [12]bool{ _q.withRuns != nil, _q.withCurrentRun != nil, + _q.withCostBasis != nil, _q.withCharge != nil, _q.withIntentOverride != nil, _q.withSubscription != nil, @@ -780,6 +817,12 @@ func (_q *ChargeFlatFeeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([ return nil, err } } + if query := _q.withCostBasis; query != nil { + if err := _q.loadCostBasis(ctx, query, nodes, nil, + func(n *ChargeFlatFee, e *ChargeFlatFeeCostBasis) { n.Edges.CostBasis = e }); err != nil { + return nil, err + } + } if query := _q.withCharge; query != nil { if err := _q.loadCharge(ctx, query, nodes, nil, func(n *ChargeFlatFee, e *Charge) { n.Edges.Charge = e }); err != nil { @@ -899,6 +942,38 @@ func (_q *ChargeFlatFeeQuery) loadCurrentRun(ctx context.Context, query *ChargeF } return nil } +func (_q *ChargeFlatFeeQuery) loadCostBasis(ctx context.Context, query *ChargeFlatFeeCostBasisQuery, nodes []*ChargeFlatFee, init func(*ChargeFlatFee), assign func(*ChargeFlatFee, *ChargeFlatFeeCostBasis)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*ChargeFlatFee) + for i := range nodes { + if nodes[i].CostBasisID == nil { + continue + } + fk := *nodes[i].CostBasisID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(chargeflatfeecostbasis.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 "cost_basis_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} func (_q *ChargeFlatFeeQuery) loadCharge(ctx context.Context, query *ChargeQuery, nodes []*ChargeFlatFee, init func(*ChargeFlatFee), assign func(*ChargeFlatFee, *Charge)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[string]*ChargeFlatFee) @@ -1206,6 +1281,9 @@ func (_q *ChargeFlatFeeQuery) querySpec() *sqlgraph.QuerySpec { if _q.withCurrentRun != nil { _spec.Node.AddColumnOnce(chargeflatfee.FieldCurrentRealizationRunID) } + if _q.withCostBasis != nil { + _spec.Node.AddColumnOnce(chargeflatfee.FieldCostBasisID) + } if _q.withSubscription != nil { _spec.Node.AddColumnOnce(chargeflatfee.FieldSubscriptionID) } diff --git a/openmeter/ent/db/chargeflatfeecostbasis.go b/openmeter/ent/db/chargeflatfeecostbasis.go new file mode 100644 index 0000000000..f9ed916b1c --- /dev/null +++ b/openmeter/ent/db/chargeflatfeecostbasis.go @@ -0,0 +1,314 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/alpacahq/alpacadecimal" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeecostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/currencycostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" + "github.com/openmeterio/openmeter/pkg/currencyx" +) + +// ChargeFlatFeeCostBasis is the model entity for the ChargeFlatFeeCostBasis schema. +type ChargeFlatFeeCostBasis struct { + config `json:"-"` + // ID of the ent. + ID string `json:"id,omitempty"` + // Mode holds the value of the "mode" field. + Mode costbasis.Mode `json:"mode,omitempty"` + // FiatCurrency holds the value of the "fiat_currency" field. + FiatCurrency currencyx.FiatCode `json:"fiat_currency,omitempty"` + // CurrencyCostBasisID holds the value of the "currency_cost_basis_id" field. + CurrencyCostBasisID *string `json:"currency_cost_basis_id,omitempty"` + // ResolvedCostBasisID holds the value of the "resolved_cost_basis_id" field. + ResolvedCostBasisID *string `json:"resolved_cost_basis_id,omitempty"` + // CurrencyID holds the value of the "currency_id" field. + CurrencyID string `json:"currency_id,omitempty"` + // ManualRate holds the value of the "manual_rate" field. + ManualRate *alpacadecimal.Decimal `json:"manual_rate,omitempty"` + // ResolvedCostBasis holds the value of the "resolved_cost_basis" field. + ResolvedCostBasis *alpacadecimal.Decimal `json:"resolved_cost_basis,omitempty"` + // ResolvedAt holds the value of the "resolved_at" field. + ResolvedAt *time.Time `json:"resolved_at,omitempty"` + // Namespace holds the value of the "namespace" field. + Namespace string `json:"namespace,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"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the ChargeFlatFeeCostBasisQuery when eager-loading is set. + Edges ChargeFlatFeeCostBasisEdges `json:"edges"` + selectValues sql.SelectValues +} + +// ChargeFlatFeeCostBasisEdges holds the relations/edges for other nodes in the graph. +type ChargeFlatFeeCostBasisEdges struct { + // CurrencyCostBasis holds the value of the currency_cost_basis edge. + CurrencyCostBasis *CurrencyCostBasis `json:"currency_cost_basis,omitempty"` + // ResolvedCurrencyCostBasis holds the value of the resolved_currency_cost_basis edge. + ResolvedCurrencyCostBasis *CurrencyCostBasis `json:"resolved_currency_cost_basis,omitempty"` + // CustomCurrency holds the value of the custom_currency edge. + CustomCurrency *CustomCurrency `json:"custom_currency,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [3]bool +} + +// CurrencyCostBasisOrErr returns the CurrencyCostBasis value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChargeFlatFeeCostBasisEdges) CurrencyCostBasisOrErr() (*CurrencyCostBasis, error) { + if e.CurrencyCostBasis != nil { + return e.CurrencyCostBasis, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: currencycostbasis.Label} + } + return nil, &NotLoadedError{edge: "currency_cost_basis"} +} + +// ResolvedCurrencyCostBasisOrErr returns the ResolvedCurrencyCostBasis value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChargeFlatFeeCostBasisEdges) ResolvedCurrencyCostBasisOrErr() (*CurrencyCostBasis, error) { + if e.ResolvedCurrencyCostBasis != nil { + return e.ResolvedCurrencyCostBasis, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: currencycostbasis.Label} + } + return nil, &NotLoadedError{edge: "resolved_currency_cost_basis"} +} + +// CustomCurrencyOrErr returns the CustomCurrency value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChargeFlatFeeCostBasisEdges) CustomCurrencyOrErr() (*CustomCurrency, error) { + if e.CustomCurrency != nil { + return e.CustomCurrency, nil + } else if e.loadedTypes[2] { + return nil, &NotFoundError{label: customcurrency.Label} + } + return nil, &NotLoadedError{edge: "custom_currency"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*ChargeFlatFeeCostBasis) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case chargeflatfeecostbasis.FieldManualRate, chargeflatfeecostbasis.FieldResolvedCostBasis: + values[i] = &sql.NullScanner{S: new(alpacadecimal.Decimal)} + case chargeflatfeecostbasis.FieldID, chargeflatfeecostbasis.FieldMode, chargeflatfeecostbasis.FieldFiatCurrency, chargeflatfeecostbasis.FieldCurrencyCostBasisID, chargeflatfeecostbasis.FieldResolvedCostBasisID, chargeflatfeecostbasis.FieldCurrencyID, chargeflatfeecostbasis.FieldNamespace: + values[i] = new(sql.NullString) + case chargeflatfeecostbasis.FieldResolvedAt, chargeflatfeecostbasis.FieldCreatedAt, chargeflatfeecostbasis.FieldUpdatedAt, chargeflatfeecostbasis.FieldDeletedAt: + values[i] = new(sql.NullTime) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the ChargeFlatFeeCostBasis fields. +func (_m *ChargeFlatFeeCostBasis) 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 chargeflatfeecostbasis.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 chargeflatfeecostbasis.FieldMode: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field mode", values[i]) + } else if value.Valid { + _m.Mode = costbasis.Mode(value.String) + } + case chargeflatfeecostbasis.FieldFiatCurrency: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field fiat_currency", values[i]) + } else if value.Valid { + _m.FiatCurrency = currencyx.FiatCode(value.String) + } + case chargeflatfeecostbasis.FieldCurrencyCostBasisID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field currency_cost_basis_id", values[i]) + } else if value.Valid { + _m.CurrencyCostBasisID = new(string) + *_m.CurrencyCostBasisID = value.String + } + case chargeflatfeecostbasis.FieldResolvedCostBasisID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field resolved_cost_basis_id", values[i]) + } else if value.Valid { + _m.ResolvedCostBasisID = new(string) + *_m.ResolvedCostBasisID = value.String + } + case chargeflatfeecostbasis.FieldCurrencyID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field currency_id", values[i]) + } else if value.Valid { + _m.CurrencyID = value.String + } + case chargeflatfeecostbasis.FieldManualRate: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field manual_rate", values[i]) + } else if value.Valid { + _m.ManualRate = new(alpacadecimal.Decimal) + *_m.ManualRate = *value.S.(*alpacadecimal.Decimal) + } + case chargeflatfeecostbasis.FieldResolvedCostBasis: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field resolved_cost_basis", values[i]) + } else if value.Valid { + _m.ResolvedCostBasis = new(alpacadecimal.Decimal) + *_m.ResolvedCostBasis = *value.S.(*alpacadecimal.Decimal) + } + case chargeflatfeecostbasis.FieldResolvedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field resolved_at", values[i]) + } else if value.Valid { + _m.ResolvedAt = new(time.Time) + *_m.ResolvedAt = value.Time + } + case chargeflatfeecostbasis.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 chargeflatfeecostbasis.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 chargeflatfeecostbasis.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 chargeflatfeecostbasis.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 + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the ChargeFlatFeeCostBasis. +// This includes values selected through modifiers, order, etc. +func (_m *ChargeFlatFeeCostBasis) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryCurrencyCostBasis queries the "currency_cost_basis" edge of the ChargeFlatFeeCostBasis entity. +func (_m *ChargeFlatFeeCostBasis) QueryCurrencyCostBasis() *CurrencyCostBasisQuery { + return NewChargeFlatFeeCostBasisClient(_m.config).QueryCurrencyCostBasis(_m) +} + +// QueryResolvedCurrencyCostBasis queries the "resolved_currency_cost_basis" edge of the ChargeFlatFeeCostBasis entity. +func (_m *ChargeFlatFeeCostBasis) QueryResolvedCurrencyCostBasis() *CurrencyCostBasisQuery { + return NewChargeFlatFeeCostBasisClient(_m.config).QueryResolvedCurrencyCostBasis(_m) +} + +// QueryCustomCurrency queries the "custom_currency" edge of the ChargeFlatFeeCostBasis entity. +func (_m *ChargeFlatFeeCostBasis) QueryCustomCurrency() *CustomCurrencyQuery { + return NewChargeFlatFeeCostBasisClient(_m.config).QueryCustomCurrency(_m) +} + +// Update returns a builder for updating this ChargeFlatFeeCostBasis. +// Note that you need to call ChargeFlatFeeCostBasis.Unwrap() before calling this method if this ChargeFlatFeeCostBasis +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *ChargeFlatFeeCostBasis) Update() *ChargeFlatFeeCostBasisUpdateOne { + return NewChargeFlatFeeCostBasisClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeCostBasis) Unwrap() *ChargeFlatFeeCostBasis { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("db: ChargeFlatFeeCostBasis is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *ChargeFlatFeeCostBasis) String() string { + var builder strings.Builder + builder.WriteString("ChargeFlatFeeCostBasis(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("mode=") + builder.WriteString(fmt.Sprintf("%v", _m.Mode)) + builder.WriteString(", ") + builder.WriteString("fiat_currency=") + builder.WriteString(fmt.Sprintf("%v", _m.FiatCurrency)) + builder.WriteString(", ") + if v := _m.CurrencyCostBasisID; v != nil { + builder.WriteString("currency_cost_basis_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.ResolvedCostBasisID; v != nil { + builder.WriteString("resolved_cost_basis_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") + builder.WriteString("currency_id=") + builder.WriteString(_m.CurrencyID) + builder.WriteString(", ") + if v := _m.ManualRate; v != nil { + builder.WriteString("manual_rate=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + if v := _m.ResolvedCostBasis; v != nil { + builder.WriteString("resolved_cost_basis=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + if v := _m.ResolvedAt; v != nil { + builder.WriteString("resolved_at=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteString(", ") + builder.WriteString("namespace=") + builder.WriteString(_m.Namespace) + 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.WriteByte(')') + return builder.String() +} + +// ChargeFlatFeeCostBases is a parsable slice of ChargeFlatFeeCostBasis. +type ChargeFlatFeeCostBases []*ChargeFlatFeeCostBasis diff --git a/openmeter/ent/db/chargeflatfeecostbasis/chargeflatfeecostbasis.go b/openmeter/ent/db/chargeflatfeecostbasis/chargeflatfeecostbasis.go new file mode 100644 index 0000000000..41800441c8 --- /dev/null +++ b/openmeter/ent/db/chargeflatfeecostbasis/chargeflatfeecostbasis.go @@ -0,0 +1,236 @@ +// Code generated by ent, DO NOT EDIT. + +package chargeflatfeecostbasis + +import ( + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" +) + +const ( + // Label holds the string label denoting the chargeflatfeecostbasis type in the database. + Label = "charge_flat_fee_cost_basis" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldMode holds the string denoting the mode field in the database. + FieldMode = "mode" + // FieldFiatCurrency holds the string denoting the fiat_currency field in the database. + FieldFiatCurrency = "fiat_currency" + // FieldCurrencyCostBasisID holds the string denoting the currency_cost_basis_id field in the database. + FieldCurrencyCostBasisID = "currency_cost_basis_id" + // FieldResolvedCostBasisID holds the string denoting the resolved_cost_basis_id field in the database. + FieldResolvedCostBasisID = "resolved_cost_basis_id" + // FieldCurrencyID holds the string denoting the currency_id field in the database. + FieldCurrencyID = "currency_id" + // FieldManualRate holds the string denoting the manual_rate field in the database. + FieldManualRate = "manual_rate" + // FieldResolvedCostBasis holds the string denoting the resolved_cost_basis field in the database. + FieldResolvedCostBasis = "resolved_cost_basis" + // FieldResolvedAt holds the string denoting the resolved_at field in the database. + FieldResolvedAt = "resolved_at" + // FieldNamespace holds the string denoting the namespace field in the database. + FieldNamespace = "namespace" + // 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" + // EdgeCurrencyCostBasis holds the string denoting the currency_cost_basis edge name in mutations. + EdgeCurrencyCostBasis = "currency_cost_basis" + // EdgeResolvedCurrencyCostBasis holds the string denoting the resolved_currency_cost_basis edge name in mutations. + EdgeResolvedCurrencyCostBasis = "resolved_currency_cost_basis" + // EdgeCustomCurrency holds the string denoting the custom_currency edge name in mutations. + EdgeCustomCurrency = "custom_currency" + // Table holds the table name of the chargeflatfeecostbasis in the database. + Table = "charge_flat_fee_cost_bases" + // CurrencyCostBasisTable is the table that holds the currency_cost_basis relation/edge. + CurrencyCostBasisTable = "charge_flat_fee_cost_bases" + // CurrencyCostBasisInverseTable is the table name for the CurrencyCostBasis entity. + // It exists in this package in order to avoid circular dependency with the "currencycostbasis" package. + CurrencyCostBasisInverseTable = "currency_cost_bases" + // CurrencyCostBasisColumn is the table column denoting the currency_cost_basis relation/edge. + CurrencyCostBasisColumn = "currency_cost_basis_id" + // ResolvedCurrencyCostBasisTable is the table that holds the resolved_currency_cost_basis relation/edge. + ResolvedCurrencyCostBasisTable = "charge_flat_fee_cost_bases" + // ResolvedCurrencyCostBasisInverseTable is the table name for the CurrencyCostBasis entity. + // It exists in this package in order to avoid circular dependency with the "currencycostbasis" package. + ResolvedCurrencyCostBasisInverseTable = "currency_cost_bases" + // ResolvedCurrencyCostBasisColumn is the table column denoting the resolved_currency_cost_basis relation/edge. + ResolvedCurrencyCostBasisColumn = "resolved_cost_basis_id" + // CustomCurrencyTable is the table that holds the custom_currency relation/edge. + CustomCurrencyTable = "charge_flat_fee_cost_bases" + // CustomCurrencyInverseTable is the table name for the CustomCurrency entity. + // It exists in this package in order to avoid circular dependency with the "customcurrency" package. + CustomCurrencyInverseTable = "custom_currencies" + // CustomCurrencyColumn is the table column denoting the custom_currency relation/edge. + CustomCurrencyColumn = "currency_id" +) + +// Columns holds all SQL columns for chargeflatfeecostbasis fields. +var Columns = []string{ + FieldID, + FieldMode, + FieldFiatCurrency, + FieldCurrencyCostBasisID, + FieldResolvedCostBasisID, + FieldCurrencyID, + FieldManualRate, + FieldResolvedCostBasis, + FieldResolvedAt, + FieldNamespace, + FieldCreatedAt, + FieldUpdatedAt, + FieldDeletedAt, +} + +// 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 ( + // FiatCurrencyValidator is a validator for the "fiat_currency" field. It is called by the builders before save. + FiatCurrencyValidator func(string) error + // CurrencyIDValidator is a validator for the "currency_id" field. It is called by the builders before save. + CurrencyIDValidator func(string) error + // 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 + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() string +) + +// ModeValidator is a validator for the "mode" field enum values. It is called by the builders before save. +func ModeValidator(m costbasis.Mode) error { + switch m { + case "dynamic", "pinned", "manual": + return nil + default: + return fmt.Errorf("chargeflatfeecostbasis: invalid enum value for mode field: %q", m) + } +} + +// OrderOption defines the ordering options for the ChargeFlatFeeCostBasis 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() +} + +// ByMode orders the results by the mode field. +func ByMode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMode, opts...).ToFunc() +} + +// ByFiatCurrency orders the results by the fiat_currency field. +func ByFiatCurrency(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldFiatCurrency, opts...).ToFunc() +} + +// ByCurrencyCostBasisID orders the results by the currency_cost_basis_id field. +func ByCurrencyCostBasisID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCurrencyCostBasisID, opts...).ToFunc() +} + +// ByResolvedCostBasisID orders the results by the resolved_cost_basis_id field. +func ByResolvedCostBasisID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldResolvedCostBasisID, opts...).ToFunc() +} + +// ByCurrencyID orders the results by the currency_id field. +func ByCurrencyID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCurrencyID, opts...).ToFunc() +} + +// ByManualRate orders the results by the manual_rate field. +func ByManualRate(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldManualRate, opts...).ToFunc() +} + +// ByResolvedCostBasis orders the results by the resolved_cost_basis field. +func ByResolvedCostBasis(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldResolvedCostBasis, opts...).ToFunc() +} + +// ByResolvedAt orders the results by the resolved_at field. +func ByResolvedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldResolvedAt, 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() +} + +// ByCurrencyCostBasisField orders the results by currency_cost_basis field. +func ByCurrencyCostBasisField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCurrencyCostBasisStep(), sql.OrderByField(field, opts...)) + } +} + +// ByResolvedCurrencyCostBasisField orders the results by resolved_currency_cost_basis field. +func ByResolvedCurrencyCostBasisField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newResolvedCurrencyCostBasisStep(), sql.OrderByField(field, opts...)) + } +} + +// ByCustomCurrencyField orders the results by custom_currency field. +func ByCustomCurrencyField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCustomCurrencyStep(), sql.OrderByField(field, opts...)) + } +} +func newCurrencyCostBasisStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CurrencyCostBasisInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CurrencyCostBasisTable, CurrencyCostBasisColumn), + ) +} +func newResolvedCurrencyCostBasisStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(ResolvedCurrencyCostBasisInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, ResolvedCurrencyCostBasisTable, ResolvedCurrencyCostBasisColumn), + ) +} +func newCustomCurrencyStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CustomCurrencyInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CustomCurrencyTable, CustomCurrencyColumn), + ) +} diff --git a/openmeter/ent/db/chargeflatfeecostbasis/where.go b/openmeter/ent/db/chargeflatfeecostbasis/where.go new file mode 100644 index 0000000000..4983d42750 --- /dev/null +++ b/openmeter/ent/db/chargeflatfeecostbasis/where.go @@ -0,0 +1,883 @@ +// Code generated by ent, DO NOT EDIT. + +package chargeflatfeecostbasis + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/alpacahq/alpacadecimal" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" + "github.com/openmeterio/openmeter/pkg/currencyx" +) + +// ID filters vertices based on their ID field. +func ID(id string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLTE(FieldID, id)) +} + +// IDEqualFold applies the EqualFold predicate on the ID field. +func IDEqualFold(id string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEqualFold(FieldID, id)) +} + +// IDContainsFold applies the ContainsFold predicate on the ID field. +func IDContainsFold(id string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldContainsFold(FieldID, id)) +} + +// FiatCurrency applies equality check predicate on the "fiat_currency" field. It's identical to FiatCurrencyEQ. +func FiatCurrency(v currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + vc := string(v) + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldFiatCurrency, vc)) +} + +// CurrencyCostBasisID applies equality check predicate on the "currency_cost_basis_id" field. It's identical to CurrencyCostBasisIDEQ. +func CurrencyCostBasisID(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldCurrencyCostBasisID, v)) +} + +// ResolvedCostBasisID applies equality check predicate on the "resolved_cost_basis_id" field. It's identical to ResolvedCostBasisIDEQ. +func ResolvedCostBasisID(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldResolvedCostBasisID, v)) +} + +// CurrencyID applies equality check predicate on the "currency_id" field. It's identical to CurrencyIDEQ. +func CurrencyID(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldCurrencyID, v)) +} + +// ManualRate applies equality check predicate on the "manual_rate" field. It's identical to ManualRateEQ. +func ManualRate(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldManualRate, v)) +} + +// ResolvedCostBasis applies equality check predicate on the "resolved_cost_basis" field. It's identical to ResolvedCostBasisEQ. +func ResolvedCostBasis(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldResolvedCostBasis, v)) +} + +// ResolvedAt applies equality check predicate on the "resolved_at" field. It's identical to ResolvedAtEQ. +func ResolvedAt(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldResolvedAt, v)) +} + +// Namespace applies equality check predicate on the "namespace" field. It's identical to NamespaceEQ. +func Namespace(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(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.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(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.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(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.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldDeletedAt, v)) +} + +// ModeEQ applies the EQ predicate on the "mode" field. +func ModeEQ(v costbasis.Mode) predicate.ChargeFlatFeeCostBasis { + vc := v + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldMode, vc)) +} + +// ModeNEQ applies the NEQ predicate on the "mode" field. +func ModeNEQ(v costbasis.Mode) predicate.ChargeFlatFeeCostBasis { + vc := v + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldMode, vc)) +} + +// ModeIn applies the In predicate on the "mode" field. +func ModeIn(vs ...costbasis.Mode) predicate.ChargeFlatFeeCostBasis { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldMode, v...)) +} + +// ModeNotIn applies the NotIn predicate on the "mode" field. +func ModeNotIn(vs ...costbasis.Mode) predicate.ChargeFlatFeeCostBasis { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldMode, v...)) +} + +// FiatCurrencyEQ applies the EQ predicate on the "fiat_currency" field. +func FiatCurrencyEQ(v currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + vc := string(v) + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldFiatCurrency, vc)) +} + +// FiatCurrencyNEQ applies the NEQ predicate on the "fiat_currency" field. +func FiatCurrencyNEQ(v currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + vc := string(v) + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldFiatCurrency, vc)) +} + +// FiatCurrencyIn applies the In predicate on the "fiat_currency" field. +func FiatCurrencyIn(vs ...currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + v := make([]any, len(vs)) + for i := range v { + v[i] = string(vs[i]) + } + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldFiatCurrency, v...)) +} + +// FiatCurrencyNotIn applies the NotIn predicate on the "fiat_currency" field. +func FiatCurrencyNotIn(vs ...currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + v := make([]any, len(vs)) + for i := range v { + v[i] = string(vs[i]) + } + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldFiatCurrency, v...)) +} + +// FiatCurrencyGT applies the GT predicate on the "fiat_currency" field. +func FiatCurrencyGT(v currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + vc := string(v) + return predicate.ChargeFlatFeeCostBasis(sql.FieldGT(FieldFiatCurrency, vc)) +} + +// FiatCurrencyGTE applies the GTE predicate on the "fiat_currency" field. +func FiatCurrencyGTE(v currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + vc := string(v) + return predicate.ChargeFlatFeeCostBasis(sql.FieldGTE(FieldFiatCurrency, vc)) +} + +// FiatCurrencyLT applies the LT predicate on the "fiat_currency" field. +func FiatCurrencyLT(v currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + vc := string(v) + return predicate.ChargeFlatFeeCostBasis(sql.FieldLT(FieldFiatCurrency, vc)) +} + +// FiatCurrencyLTE applies the LTE predicate on the "fiat_currency" field. +func FiatCurrencyLTE(v currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + vc := string(v) + return predicate.ChargeFlatFeeCostBasis(sql.FieldLTE(FieldFiatCurrency, vc)) +} + +// FiatCurrencyContains applies the Contains predicate on the "fiat_currency" field. +func FiatCurrencyContains(v currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + vc := string(v) + return predicate.ChargeFlatFeeCostBasis(sql.FieldContains(FieldFiatCurrency, vc)) +} + +// FiatCurrencyHasPrefix applies the HasPrefix predicate on the "fiat_currency" field. +func FiatCurrencyHasPrefix(v currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + vc := string(v) + return predicate.ChargeFlatFeeCostBasis(sql.FieldHasPrefix(FieldFiatCurrency, vc)) +} + +// FiatCurrencyHasSuffix applies the HasSuffix predicate on the "fiat_currency" field. +func FiatCurrencyHasSuffix(v currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + vc := string(v) + return predicate.ChargeFlatFeeCostBasis(sql.FieldHasSuffix(FieldFiatCurrency, vc)) +} + +// FiatCurrencyEqualFold applies the EqualFold predicate on the "fiat_currency" field. +func FiatCurrencyEqualFold(v currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + vc := string(v) + return predicate.ChargeFlatFeeCostBasis(sql.FieldEqualFold(FieldFiatCurrency, vc)) +} + +// FiatCurrencyContainsFold applies the ContainsFold predicate on the "fiat_currency" field. +func FiatCurrencyContainsFold(v currencyx.FiatCode) predicate.ChargeFlatFeeCostBasis { + vc := string(v) + return predicate.ChargeFlatFeeCostBasis(sql.FieldContainsFold(FieldFiatCurrency, vc)) +} + +// CurrencyCostBasisIDEQ applies the EQ predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDEQ(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDNEQ applies the NEQ predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDNEQ(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDIn applies the In predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDIn(vs ...string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldCurrencyCostBasisID, vs...)) +} + +// CurrencyCostBasisIDNotIn applies the NotIn predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDNotIn(vs ...string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldCurrencyCostBasisID, vs...)) +} + +// CurrencyCostBasisIDGT applies the GT predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDGT(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGT(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDGTE applies the GTE predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDGTE(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGTE(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDLT applies the LT predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDLT(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLT(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDLTE applies the LTE predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDLTE(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLTE(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDContains applies the Contains predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDContains(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldContains(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDHasPrefix applies the HasPrefix predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDHasPrefix(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldHasPrefix(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDHasSuffix applies the HasSuffix predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDHasSuffix(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldHasSuffix(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDIsNil applies the IsNil predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDIsNil() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIsNull(FieldCurrencyCostBasisID)) +} + +// CurrencyCostBasisIDNotNil applies the NotNil predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDNotNil() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotNull(FieldCurrencyCostBasisID)) +} + +// CurrencyCostBasisIDEqualFold applies the EqualFold predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDEqualFold(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEqualFold(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDContainsFold applies the ContainsFold predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDContainsFold(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldContainsFold(FieldCurrencyCostBasisID, v)) +} + +// ResolvedCostBasisIDEQ applies the EQ predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDEQ(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDNEQ applies the NEQ predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDNEQ(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDIn applies the In predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDIn(vs ...string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldResolvedCostBasisID, vs...)) +} + +// ResolvedCostBasisIDNotIn applies the NotIn predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDNotIn(vs ...string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldResolvedCostBasisID, vs...)) +} + +// ResolvedCostBasisIDGT applies the GT predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDGT(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGT(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDGTE applies the GTE predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDGTE(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGTE(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDLT applies the LT predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDLT(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLT(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDLTE applies the LTE predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDLTE(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLTE(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDContains applies the Contains predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDContains(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldContains(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDHasPrefix applies the HasPrefix predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDHasPrefix(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldHasPrefix(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDHasSuffix applies the HasSuffix predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDHasSuffix(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldHasSuffix(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDIsNil applies the IsNil predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDIsNil() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIsNull(FieldResolvedCostBasisID)) +} + +// ResolvedCostBasisIDNotNil applies the NotNil predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDNotNil() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotNull(FieldResolvedCostBasisID)) +} + +// ResolvedCostBasisIDEqualFold applies the EqualFold predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDEqualFold(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEqualFold(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDContainsFold applies the ContainsFold predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDContainsFold(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldContainsFold(FieldResolvedCostBasisID, v)) +} + +// CurrencyIDEQ applies the EQ predicate on the "currency_id" field. +func CurrencyIDEQ(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldCurrencyID, v)) +} + +// CurrencyIDNEQ applies the NEQ predicate on the "currency_id" field. +func CurrencyIDNEQ(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldCurrencyID, v)) +} + +// CurrencyIDIn applies the In predicate on the "currency_id" field. +func CurrencyIDIn(vs ...string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldCurrencyID, vs...)) +} + +// CurrencyIDNotIn applies the NotIn predicate on the "currency_id" field. +func CurrencyIDNotIn(vs ...string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldCurrencyID, vs...)) +} + +// CurrencyIDGT applies the GT predicate on the "currency_id" field. +func CurrencyIDGT(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGT(FieldCurrencyID, v)) +} + +// CurrencyIDGTE applies the GTE predicate on the "currency_id" field. +func CurrencyIDGTE(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGTE(FieldCurrencyID, v)) +} + +// CurrencyIDLT applies the LT predicate on the "currency_id" field. +func CurrencyIDLT(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLT(FieldCurrencyID, v)) +} + +// CurrencyIDLTE applies the LTE predicate on the "currency_id" field. +func CurrencyIDLTE(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLTE(FieldCurrencyID, v)) +} + +// CurrencyIDContains applies the Contains predicate on the "currency_id" field. +func CurrencyIDContains(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldContains(FieldCurrencyID, v)) +} + +// CurrencyIDHasPrefix applies the HasPrefix predicate on the "currency_id" field. +func CurrencyIDHasPrefix(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldHasPrefix(FieldCurrencyID, v)) +} + +// CurrencyIDHasSuffix applies the HasSuffix predicate on the "currency_id" field. +func CurrencyIDHasSuffix(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldHasSuffix(FieldCurrencyID, v)) +} + +// CurrencyIDEqualFold applies the EqualFold predicate on the "currency_id" field. +func CurrencyIDEqualFold(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEqualFold(FieldCurrencyID, v)) +} + +// CurrencyIDContainsFold applies the ContainsFold predicate on the "currency_id" field. +func CurrencyIDContainsFold(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldContainsFold(FieldCurrencyID, v)) +} + +// ManualRateEQ applies the EQ predicate on the "manual_rate" field. +func ManualRateEQ(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldManualRate, v)) +} + +// ManualRateNEQ applies the NEQ predicate on the "manual_rate" field. +func ManualRateNEQ(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldManualRate, v)) +} + +// ManualRateIn applies the In predicate on the "manual_rate" field. +func ManualRateIn(vs ...alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldManualRate, vs...)) +} + +// ManualRateNotIn applies the NotIn predicate on the "manual_rate" field. +func ManualRateNotIn(vs ...alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldManualRate, vs...)) +} + +// ManualRateGT applies the GT predicate on the "manual_rate" field. +func ManualRateGT(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGT(FieldManualRate, v)) +} + +// ManualRateGTE applies the GTE predicate on the "manual_rate" field. +func ManualRateGTE(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGTE(FieldManualRate, v)) +} + +// ManualRateLT applies the LT predicate on the "manual_rate" field. +func ManualRateLT(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLT(FieldManualRate, v)) +} + +// ManualRateLTE applies the LTE predicate on the "manual_rate" field. +func ManualRateLTE(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLTE(FieldManualRate, v)) +} + +// ManualRateIsNil applies the IsNil predicate on the "manual_rate" field. +func ManualRateIsNil() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIsNull(FieldManualRate)) +} + +// ManualRateNotNil applies the NotNil predicate on the "manual_rate" field. +func ManualRateNotNil() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotNull(FieldManualRate)) +} + +// ResolvedCostBasisEQ applies the EQ predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisEQ(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisNEQ applies the NEQ predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisNEQ(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisIn applies the In predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisIn(vs ...alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldResolvedCostBasis, vs...)) +} + +// ResolvedCostBasisNotIn applies the NotIn predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisNotIn(vs ...alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldResolvedCostBasis, vs...)) +} + +// ResolvedCostBasisGT applies the GT predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisGT(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGT(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisGTE applies the GTE predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisGTE(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGTE(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisLT applies the LT predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisLT(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLT(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisLTE applies the LTE predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisLTE(v alpacadecimal.Decimal) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLTE(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisIsNil applies the IsNil predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisIsNil() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIsNull(FieldResolvedCostBasis)) +} + +// ResolvedCostBasisNotNil applies the NotNil predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisNotNil() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotNull(FieldResolvedCostBasis)) +} + +// ResolvedAtEQ applies the EQ predicate on the "resolved_at" field. +func ResolvedAtEQ(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldResolvedAt, v)) +} + +// ResolvedAtNEQ applies the NEQ predicate on the "resolved_at" field. +func ResolvedAtNEQ(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldResolvedAt, v)) +} + +// ResolvedAtIn applies the In predicate on the "resolved_at" field. +func ResolvedAtIn(vs ...time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldResolvedAt, vs...)) +} + +// ResolvedAtNotIn applies the NotIn predicate on the "resolved_at" field. +func ResolvedAtNotIn(vs ...time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldResolvedAt, vs...)) +} + +// ResolvedAtGT applies the GT predicate on the "resolved_at" field. +func ResolvedAtGT(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGT(FieldResolvedAt, v)) +} + +// ResolvedAtGTE applies the GTE predicate on the "resolved_at" field. +func ResolvedAtGTE(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGTE(FieldResolvedAt, v)) +} + +// ResolvedAtLT applies the LT predicate on the "resolved_at" field. +func ResolvedAtLT(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLT(FieldResolvedAt, v)) +} + +// ResolvedAtLTE applies the LTE predicate on the "resolved_at" field. +func ResolvedAtLTE(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLTE(FieldResolvedAt, v)) +} + +// ResolvedAtIsNil applies the IsNil predicate on the "resolved_at" field. +func ResolvedAtIsNil() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIsNull(FieldResolvedAt)) +} + +// ResolvedAtNotNil applies the NotNil predicate on the "resolved_at" field. +func ResolvedAtNotNil() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotNull(FieldResolvedAt)) +} + +// NamespaceEQ applies the EQ predicate on the "namespace" field. +func NamespaceEQ(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldNamespace, v)) +} + +// NamespaceNEQ applies the NEQ predicate on the "namespace" field. +func NamespaceNEQ(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldNamespace, v)) +} + +// NamespaceIn applies the In predicate on the "namespace" field. +func NamespaceIn(vs ...string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldNamespace, vs...)) +} + +// NamespaceNotIn applies the NotIn predicate on the "namespace" field. +func NamespaceNotIn(vs ...string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldNamespace, vs...)) +} + +// NamespaceGT applies the GT predicate on the "namespace" field. +func NamespaceGT(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGT(FieldNamespace, v)) +} + +// NamespaceGTE applies the GTE predicate on the "namespace" field. +func NamespaceGTE(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGTE(FieldNamespace, v)) +} + +// NamespaceLT applies the LT predicate on the "namespace" field. +func NamespaceLT(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLT(FieldNamespace, v)) +} + +// NamespaceLTE applies the LTE predicate on the "namespace" field. +func NamespaceLTE(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLTE(FieldNamespace, v)) +} + +// NamespaceContains applies the Contains predicate on the "namespace" field. +func NamespaceContains(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldContains(FieldNamespace, v)) +} + +// NamespaceHasPrefix applies the HasPrefix predicate on the "namespace" field. +func NamespaceHasPrefix(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldHasPrefix(FieldNamespace, v)) +} + +// NamespaceHasSuffix applies the HasSuffix predicate on the "namespace" field. +func NamespaceHasSuffix(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldHasSuffix(FieldNamespace, v)) +} + +// NamespaceEqualFold applies the EqualFold predicate on the "namespace" field. +func NamespaceEqualFold(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEqualFold(FieldNamespace, v)) +} + +// NamespaceContainsFold applies the ContainsFold predicate on the "namespace" field. +func NamespaceContainsFold(v string) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldContainsFold(FieldNamespace, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// DeletedAtEQ applies the EQ predicate on the "deleted_at" field. +func DeletedAtEQ(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldEQ(FieldDeletedAt, v)) +} + +// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field. +func DeletedAtNEQ(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNEQ(FieldDeletedAt, v)) +} + +// DeletedAtIn applies the In predicate on the "deleted_at" field. +func DeletedAtIn(vs ...time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIn(FieldDeletedAt, vs...)) +} + +// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field. +func DeletedAtNotIn(vs ...time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotIn(FieldDeletedAt, vs...)) +} + +// DeletedAtGT applies the GT predicate on the "deleted_at" field. +func DeletedAtGT(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGT(FieldDeletedAt, v)) +} + +// DeletedAtGTE applies the GTE predicate on the "deleted_at" field. +func DeletedAtGTE(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldGTE(FieldDeletedAt, v)) +} + +// DeletedAtLT applies the LT predicate on the "deleted_at" field. +func DeletedAtLT(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLT(FieldDeletedAt, v)) +} + +// DeletedAtLTE applies the LTE predicate on the "deleted_at" field. +func DeletedAtLTE(v time.Time) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldLTE(FieldDeletedAt, v)) +} + +// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field. +func DeletedAtIsNil() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldIsNull(FieldDeletedAt)) +} + +// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field. +func DeletedAtNotNil() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.FieldNotNull(FieldDeletedAt)) +} + +// HasCurrencyCostBasis applies the HasEdge predicate on the "currency_cost_basis" edge. +func HasCurrencyCostBasis() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CurrencyCostBasisTable, CurrencyCostBasisColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasCurrencyCostBasisWith applies the HasEdge predicate on the "currency_cost_basis" edge with a given conditions (other predicates). +func HasCurrencyCostBasisWith(preds ...predicate.CurrencyCostBasis) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(func(s *sql.Selector) { + step := newCurrencyCostBasisStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasResolvedCurrencyCostBasis applies the HasEdge predicate on the "resolved_currency_cost_basis" edge. +func HasResolvedCurrencyCostBasis() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, ResolvedCurrencyCostBasisTable, ResolvedCurrencyCostBasisColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasResolvedCurrencyCostBasisWith applies the HasEdge predicate on the "resolved_currency_cost_basis" edge with a given conditions (other predicates). +func HasResolvedCurrencyCostBasisWith(preds ...predicate.CurrencyCostBasis) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(func(s *sql.Selector) { + step := newResolvedCurrencyCostBasisStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasCustomCurrency applies the HasEdge predicate on the "custom_currency" edge. +func HasCustomCurrency() predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CustomCurrencyTable, CustomCurrencyColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasCustomCurrencyWith applies the HasEdge predicate on the "custom_currency" edge with a given conditions (other predicates). +func HasCustomCurrencyWith(preds ...predicate.CustomCurrency) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(func(s *sql.Selector) { + step := newCustomCurrencyStep() + 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.ChargeFlatFeeCostBasis) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.ChargeFlatFeeCostBasis) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.ChargeFlatFeeCostBasis) predicate.ChargeFlatFeeCostBasis { + return predicate.ChargeFlatFeeCostBasis(sql.NotPredicates(p)) +} diff --git a/openmeter/ent/db/chargeflatfeecostbasis_create.go b/openmeter/ent/db/chargeflatfeecostbasis_create.go new file mode 100644 index 0000000000..e39dbea3c5 --- /dev/null +++ b/openmeter/ent/db/chargeflatfeecostbasis_create.go @@ -0,0 +1,1143 @@ +// 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/alpacahq/alpacadecimal" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeecostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/currencycostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" + "github.com/openmeterio/openmeter/pkg/currencyx" +) + +// ChargeFlatFeeCostBasisCreate is the builder for creating a ChargeFlatFeeCostBasis entity. +type ChargeFlatFeeCostBasisCreate struct { + config + mutation *ChargeFlatFeeCostBasisMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetMode sets the "mode" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetMode(v costbasis.Mode) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetMode(v) + return _c +} + +// SetFiatCurrency sets the "fiat_currency" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetFiatCurrency(v currencyx.FiatCode) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetFiatCurrency(v) + return _c +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetCurrencyCostBasisID(v string) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetCurrencyCostBasisID(v) + return _c +} + +// SetNillableCurrencyCostBasisID sets the "currency_cost_basis_id" field if the given value is not nil. +func (_c *ChargeFlatFeeCostBasisCreate) SetNillableCurrencyCostBasisID(v *string) *ChargeFlatFeeCostBasisCreate { + if v != nil { + _c.SetCurrencyCostBasisID(*v) + } + return _c +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetResolvedCostBasisID(v string) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetResolvedCostBasisID(v) + return _c +} + +// SetNillableResolvedCostBasisID sets the "resolved_cost_basis_id" field if the given value is not nil. +func (_c *ChargeFlatFeeCostBasisCreate) SetNillableResolvedCostBasisID(v *string) *ChargeFlatFeeCostBasisCreate { + if v != nil { + _c.SetResolvedCostBasisID(*v) + } + return _c +} + +// SetCurrencyID sets the "currency_id" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetCurrencyID(v string) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetCurrencyID(v) + return _c +} + +// SetManualRate sets the "manual_rate" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetManualRate(v alpacadecimal.Decimal) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetManualRate(v) + return _c +} + +// SetNillableManualRate sets the "manual_rate" field if the given value is not nil. +func (_c *ChargeFlatFeeCostBasisCreate) SetNillableManualRate(v *alpacadecimal.Decimal) *ChargeFlatFeeCostBasisCreate { + if v != nil { + _c.SetManualRate(*v) + } + return _c +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetResolvedCostBasis(v) + return _c +} + +// SetNillableResolvedCostBasis sets the "resolved_cost_basis" field if the given value is not nil. +func (_c *ChargeFlatFeeCostBasisCreate) SetNillableResolvedCostBasis(v *alpacadecimal.Decimal) *ChargeFlatFeeCostBasisCreate { + if v != nil { + _c.SetResolvedCostBasis(*v) + } + return _c +} + +// SetResolvedAt sets the "resolved_at" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetResolvedAt(v time.Time) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetResolvedAt(v) + return _c +} + +// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil. +func (_c *ChargeFlatFeeCostBasisCreate) SetNillableResolvedAt(v *time.Time) *ChargeFlatFeeCostBasisCreate { + if v != nil { + _c.SetResolvedAt(*v) + } + return _c +} + +// SetNamespace sets the "namespace" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetNamespace(v string) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetNamespace(v) + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetCreatedAt(v time.Time) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *ChargeFlatFeeCostBasisCreate) SetNillableCreatedAt(v *time.Time) *ChargeFlatFeeCostBasisCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetUpdatedAt(v time.Time) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *ChargeFlatFeeCostBasisCreate) SetNillableUpdatedAt(v *time.Time) *ChargeFlatFeeCostBasisCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetDeletedAt sets the "deleted_at" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetDeletedAt(v time.Time) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetDeletedAt(v) + return _c +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_c *ChargeFlatFeeCostBasisCreate) SetNillableDeletedAt(v *time.Time) *ChargeFlatFeeCostBasisCreate { + if v != nil { + _c.SetDeletedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *ChargeFlatFeeCostBasisCreate) SetID(v string) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *ChargeFlatFeeCostBasisCreate) SetNillableID(v *string) *ChargeFlatFeeCostBasisCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// SetCurrencyCostBasis sets the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_c *ChargeFlatFeeCostBasisCreate) SetCurrencyCostBasis(v *CurrencyCostBasis) *ChargeFlatFeeCostBasisCreate { + return _c.SetCurrencyCostBasisID(v.ID) +} + +// SetResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID. +func (_c *ChargeFlatFeeCostBasisCreate) SetResolvedCurrencyCostBasisID(id string) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetResolvedCurrencyCostBasisID(id) + return _c +} + +// SetNillableResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID if the given value is not nil. +func (_c *ChargeFlatFeeCostBasisCreate) SetNillableResolvedCurrencyCostBasisID(id *string) *ChargeFlatFeeCostBasisCreate { + if id != nil { + _c = _c.SetResolvedCurrencyCostBasisID(*id) + } + return _c +} + +// SetResolvedCurrencyCostBasis sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_c *ChargeFlatFeeCostBasisCreate) SetResolvedCurrencyCostBasis(v *CurrencyCostBasis) *ChargeFlatFeeCostBasisCreate { + return _c.SetResolvedCurrencyCostBasisID(v.ID) +} + +// SetCustomCurrencyID sets the "custom_currency" edge to the CustomCurrency entity by ID. +func (_c *ChargeFlatFeeCostBasisCreate) SetCustomCurrencyID(id string) *ChargeFlatFeeCostBasisCreate { + _c.mutation.SetCustomCurrencyID(id) + return _c +} + +// SetCustomCurrency sets the "custom_currency" edge to the CustomCurrency entity. +func (_c *ChargeFlatFeeCostBasisCreate) SetCustomCurrency(v *CustomCurrency) *ChargeFlatFeeCostBasisCreate { + return _c.SetCustomCurrencyID(v.ID) +} + +// Mutation returns the ChargeFlatFeeCostBasisMutation object of the builder. +func (_c *ChargeFlatFeeCostBasisCreate) Mutation() *ChargeFlatFeeCostBasisMutation { + return _c.mutation +} + +// Save creates the ChargeFlatFeeCostBasis in the database. +func (_c *ChargeFlatFeeCostBasisCreate) Save(ctx context.Context) (*ChargeFlatFeeCostBasis, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *ChargeFlatFeeCostBasisCreate) SaveX(ctx context.Context) *ChargeFlatFeeCostBasis { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ChargeFlatFeeCostBasisCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ChargeFlatFeeCostBasisCreate) 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 *ChargeFlatFeeCostBasisCreate) defaults() { + if _, ok := _c.mutation.CreatedAt(); !ok { + v := chargeflatfeecostbasis.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := chargeflatfeecostbasis.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := chargeflatfeecostbasis.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *ChargeFlatFeeCostBasisCreate) check() error { + if _, ok := _c.mutation.Mode(); !ok { + return &ValidationError{Name: "mode", err: errors.New(`db: missing required field "ChargeFlatFeeCostBasis.mode"`)} + } + if v, ok := _c.mutation.Mode(); ok { + if err := chargeflatfeecostbasis.ModeValidator(v); err != nil { + return &ValidationError{Name: "mode", err: fmt.Errorf(`db: validator failed for field "ChargeFlatFeeCostBasis.mode": %w`, err)} + } + } + if _, ok := _c.mutation.FiatCurrency(); !ok { + return &ValidationError{Name: "fiat_currency", err: errors.New(`db: missing required field "ChargeFlatFeeCostBasis.fiat_currency"`)} + } + if v, ok := _c.mutation.FiatCurrency(); ok { + if err := chargeflatfeecostbasis.FiatCurrencyValidator(string(v)); err != nil { + return &ValidationError{Name: "fiat_currency", err: fmt.Errorf(`db: validator failed for field "ChargeFlatFeeCostBasis.fiat_currency": %w`, err)} + } + } + if _, ok := _c.mutation.CurrencyID(); !ok { + return &ValidationError{Name: "currency_id", err: errors.New(`db: missing required field "ChargeFlatFeeCostBasis.currency_id"`)} + } + if v, ok := _c.mutation.CurrencyID(); ok { + if err := chargeflatfeecostbasis.CurrencyIDValidator(v); err != nil { + return &ValidationError{Name: "currency_id", err: fmt.Errorf(`db: validator failed for field "ChargeFlatFeeCostBasis.currency_id": %w`, err)} + } + } + if _, ok := _c.mutation.Namespace(); !ok { + return &ValidationError{Name: "namespace", err: errors.New(`db: missing required field "ChargeFlatFeeCostBasis.namespace"`)} + } + if v, ok := _c.mutation.Namespace(); ok { + if err := chargeflatfeecostbasis.NamespaceValidator(v); err != nil { + return &ValidationError{Name: "namespace", err: fmt.Errorf(`db: validator failed for field "ChargeFlatFeeCostBasis.namespace": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "ChargeFlatFeeCostBasis.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "ChargeFlatFeeCostBasis.updated_at"`)} + } + if len(_c.mutation.CustomCurrencyIDs()) == 0 { + return &ValidationError{Name: "custom_currency", err: errors.New(`db: missing required edge "ChargeFlatFeeCostBasis.custom_currency"`)} + } + return nil +} + +func (_c *ChargeFlatFeeCostBasisCreate) sqlSave(ctx context.Context) (*ChargeFlatFeeCostBasis, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + 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 ChargeFlatFeeCostBasis.ID type: %T", _spec.ID.Value) + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *ChargeFlatFeeCostBasisCreate) createSpec() (*ChargeFlatFeeCostBasis, *sqlgraph.CreateSpec) { + var ( + _node = &ChargeFlatFeeCostBasis{config: _c.config} + _spec = sqlgraph.NewCreateSpec(chargeflatfeecostbasis.Table, sqlgraph.NewFieldSpec(chargeflatfeecostbasis.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.Mode(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldMode, field.TypeEnum, value) + _node.Mode = value + } + if value, ok := _c.mutation.FiatCurrency(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldFiatCurrency, field.TypeString, value) + _node.FiatCurrency = value + } + if value, ok := _c.mutation.ManualRate(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldManualRate, field.TypeOther, value) + _node.ManualRate = &value + } + if value, ok := _c.mutation.ResolvedCostBasis(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldResolvedCostBasis, field.TypeOther, value) + _node.ResolvedCostBasis = &value + } + if value, ok := _c.mutation.ResolvedAt(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldResolvedAt, field.TypeTime, value) + _node.ResolvedAt = &value + } + if value, ok := _c.mutation.Namespace(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldNamespace, field.TypeString, value) + _node.Namespace = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := _c.mutation.DeletedAt(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldDeletedAt, field.TypeTime, value) + _node.DeletedAt = &value + } + if nodes := _c.mutation.CurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeflatfeecostbasis.CurrencyCostBasisTable, + Columns: []string{chargeflatfeecostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.CurrencyCostBasisID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.ResolvedCurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeflatfeecostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargeflatfeecostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.ResolvedCostBasisID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.CustomCurrencyIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeflatfeecostbasis.CustomCurrencyTable, + Columns: []string{chargeflatfeecostbasis.CustomCurrencyColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(customcurrency.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.CurrencyID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.ChargeFlatFeeCostBasis.Create(). +// SetMode(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.ChargeFlatFeeCostBasisUpsert) { +// SetMode(v+v). +// }). +// Exec(ctx) +func (_c *ChargeFlatFeeCostBasisCreate) OnConflict(opts ...sql.ConflictOption) *ChargeFlatFeeCostBasisUpsertOne { + _c.conflict = opts + return &ChargeFlatFeeCostBasisUpsertOne{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.ChargeFlatFeeCostBasis.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *ChargeFlatFeeCostBasisCreate) OnConflictColumns(columns ...string) *ChargeFlatFeeCostBasisUpsertOne { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &ChargeFlatFeeCostBasisUpsertOne{ + create: _c, + } +} + +type ( + // ChargeFlatFeeCostBasisUpsertOne is the builder for "upsert"-ing + // one ChargeFlatFeeCostBasis node. + ChargeFlatFeeCostBasisUpsertOne struct { + create *ChargeFlatFeeCostBasisCreate + } + + // ChargeFlatFeeCostBasisUpsert is the "OnConflict" setter. + ChargeFlatFeeCostBasisUpsert struct { + *sql.UpdateSet + } +) + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (u *ChargeFlatFeeCostBasisUpsert) SetCurrencyCostBasisID(v string) *ChargeFlatFeeCostBasisUpsert { + u.Set(chargeflatfeecostbasis.FieldCurrencyCostBasisID, v) + return u +} + +// UpdateCurrencyCostBasisID sets the "currency_cost_basis_id" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsert) UpdateCurrencyCostBasisID() *ChargeFlatFeeCostBasisUpsert { + u.SetExcluded(chargeflatfeecostbasis.FieldCurrencyCostBasisID) + return u +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (u *ChargeFlatFeeCostBasisUpsert) ClearCurrencyCostBasisID() *ChargeFlatFeeCostBasisUpsert { + u.SetNull(chargeflatfeecostbasis.FieldCurrencyCostBasisID) + return u +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (u *ChargeFlatFeeCostBasisUpsert) SetResolvedCostBasisID(v string) *ChargeFlatFeeCostBasisUpsert { + u.Set(chargeflatfeecostbasis.FieldResolvedCostBasisID, v) + return u +} + +// UpdateResolvedCostBasisID sets the "resolved_cost_basis_id" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsert) UpdateResolvedCostBasisID() *ChargeFlatFeeCostBasisUpsert { + u.SetExcluded(chargeflatfeecostbasis.FieldResolvedCostBasisID) + return u +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (u *ChargeFlatFeeCostBasisUpsert) ClearResolvedCostBasisID() *ChargeFlatFeeCostBasisUpsert { + u.SetNull(chargeflatfeecostbasis.FieldResolvedCostBasisID) + return u +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (u *ChargeFlatFeeCostBasisUpsert) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeFlatFeeCostBasisUpsert { + u.Set(chargeflatfeecostbasis.FieldResolvedCostBasis, v) + return u +} + +// UpdateResolvedCostBasis sets the "resolved_cost_basis" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsert) UpdateResolvedCostBasis() *ChargeFlatFeeCostBasisUpsert { + u.SetExcluded(chargeflatfeecostbasis.FieldResolvedCostBasis) + return u +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (u *ChargeFlatFeeCostBasisUpsert) ClearResolvedCostBasis() *ChargeFlatFeeCostBasisUpsert { + u.SetNull(chargeflatfeecostbasis.FieldResolvedCostBasis) + return u +} + +// SetResolvedAt sets the "resolved_at" field. +func (u *ChargeFlatFeeCostBasisUpsert) SetResolvedAt(v time.Time) *ChargeFlatFeeCostBasisUpsert { + u.Set(chargeflatfeecostbasis.FieldResolvedAt, v) + return u +} + +// UpdateResolvedAt sets the "resolved_at" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsert) UpdateResolvedAt() *ChargeFlatFeeCostBasisUpsert { + u.SetExcluded(chargeflatfeecostbasis.FieldResolvedAt) + return u +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (u *ChargeFlatFeeCostBasisUpsert) ClearResolvedAt() *ChargeFlatFeeCostBasisUpsert { + u.SetNull(chargeflatfeecostbasis.FieldResolvedAt) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *ChargeFlatFeeCostBasisUpsert) SetUpdatedAt(v time.Time) *ChargeFlatFeeCostBasisUpsert { + u.Set(chargeflatfeecostbasis.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsert) UpdateUpdatedAt() *ChargeFlatFeeCostBasisUpsert { + u.SetExcluded(chargeflatfeecostbasis.FieldUpdatedAt) + return u +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *ChargeFlatFeeCostBasisUpsert) SetDeletedAt(v time.Time) *ChargeFlatFeeCostBasisUpsert { + u.Set(chargeflatfeecostbasis.FieldDeletedAt, v) + return u +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsert) UpdateDeletedAt() *ChargeFlatFeeCostBasisUpsert { + u.SetExcluded(chargeflatfeecostbasis.FieldDeletedAt) + return u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *ChargeFlatFeeCostBasisUpsert) ClearDeletedAt() *ChargeFlatFeeCostBasisUpsert { + u.SetNull(chargeflatfeecostbasis.FieldDeletedAt) + 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.ChargeFlatFeeCostBasis.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(chargeflatfeecostbasis.FieldID) +// }), +// ). +// Exec(ctx) +func (u *ChargeFlatFeeCostBasisUpsertOne) UpdateNewValues() *ChargeFlatFeeCostBasisUpsertOne { + 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(chargeflatfeecostbasis.FieldID) + } + if _, exists := u.create.mutation.Mode(); exists { + s.SetIgnore(chargeflatfeecostbasis.FieldMode) + } + if _, exists := u.create.mutation.FiatCurrency(); exists { + s.SetIgnore(chargeflatfeecostbasis.FieldFiatCurrency) + } + if _, exists := u.create.mutation.CurrencyID(); exists { + s.SetIgnore(chargeflatfeecostbasis.FieldCurrencyID) + } + if _, exists := u.create.mutation.ManualRate(); exists { + s.SetIgnore(chargeflatfeecostbasis.FieldManualRate) + } + if _, exists := u.create.mutation.Namespace(); exists { + s.SetIgnore(chargeflatfeecostbasis.FieldNamespace) + } + if _, exists := u.create.mutation.CreatedAt(); exists { + s.SetIgnore(chargeflatfeecostbasis.FieldCreatedAt) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.ChargeFlatFeeCostBasis.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *ChargeFlatFeeCostBasisUpsertOne) Ignore() *ChargeFlatFeeCostBasisUpsertOne { + 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 *ChargeFlatFeeCostBasisUpsertOne) DoNothing() *ChargeFlatFeeCostBasisUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the ChargeFlatFeeCostBasisCreate.OnConflict +// documentation for more info. +func (u *ChargeFlatFeeCostBasisUpsertOne) Update(set func(*ChargeFlatFeeCostBasisUpsert)) *ChargeFlatFeeCostBasisUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&ChargeFlatFeeCostBasisUpsert{UpdateSet: update}) + })) + return u +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (u *ChargeFlatFeeCostBasisUpsertOne) SetCurrencyCostBasisID(v string) *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.SetCurrencyCostBasisID(v) + }) +} + +// UpdateCurrencyCostBasisID sets the "currency_cost_basis_id" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsertOne) UpdateCurrencyCostBasisID() *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.UpdateCurrencyCostBasisID() + }) +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (u *ChargeFlatFeeCostBasisUpsertOne) ClearCurrencyCostBasisID() *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.ClearCurrencyCostBasisID() + }) +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (u *ChargeFlatFeeCostBasisUpsertOne) SetResolvedCostBasisID(v string) *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.SetResolvedCostBasisID(v) + }) +} + +// UpdateResolvedCostBasisID sets the "resolved_cost_basis_id" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsertOne) UpdateResolvedCostBasisID() *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.UpdateResolvedCostBasisID() + }) +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (u *ChargeFlatFeeCostBasisUpsertOne) ClearResolvedCostBasisID() *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.ClearResolvedCostBasisID() + }) +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (u *ChargeFlatFeeCostBasisUpsertOne) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.SetResolvedCostBasis(v) + }) +} + +// UpdateResolvedCostBasis sets the "resolved_cost_basis" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsertOne) UpdateResolvedCostBasis() *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.UpdateResolvedCostBasis() + }) +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (u *ChargeFlatFeeCostBasisUpsertOne) ClearResolvedCostBasis() *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.ClearResolvedCostBasis() + }) +} + +// SetResolvedAt sets the "resolved_at" field. +func (u *ChargeFlatFeeCostBasisUpsertOne) SetResolvedAt(v time.Time) *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.SetResolvedAt(v) + }) +} + +// UpdateResolvedAt sets the "resolved_at" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsertOne) UpdateResolvedAt() *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.UpdateResolvedAt() + }) +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (u *ChargeFlatFeeCostBasisUpsertOne) ClearResolvedAt() *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.ClearResolvedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *ChargeFlatFeeCostBasisUpsertOne) SetUpdatedAt(v time.Time) *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsertOne) UpdateUpdatedAt() *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *ChargeFlatFeeCostBasisUpsertOne) SetDeletedAt(v time.Time) *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.SetDeletedAt(v) + }) +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsertOne) UpdateDeletedAt() *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.UpdateDeletedAt() + }) +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *ChargeFlatFeeCostBasisUpsertOne) ClearDeletedAt() *ChargeFlatFeeCostBasisUpsertOne { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.ClearDeletedAt() + }) +} + +// Exec executes the query. +func (u *ChargeFlatFeeCostBasisUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for ChargeFlatFeeCostBasisCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *ChargeFlatFeeCostBasisUpsertOne) 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 *ChargeFlatFeeCostBasisUpsertOne) 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: ChargeFlatFeeCostBasisUpsertOne.ID is not supported by MySQL driver. Use ChargeFlatFeeCostBasisUpsertOne.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 *ChargeFlatFeeCostBasisUpsertOne) IDX(ctx context.Context) string { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// ChargeFlatFeeCostBasisCreateBulk is the builder for creating many ChargeFlatFeeCostBasis entities in bulk. +type ChargeFlatFeeCostBasisCreateBulk struct { + config + err error + builders []*ChargeFlatFeeCostBasisCreate + conflict []sql.ConflictOption +} + +// Save creates the ChargeFlatFeeCostBasis entities in the database. +func (_c *ChargeFlatFeeCostBasisCreateBulk) Save(ctx context.Context) ([]*ChargeFlatFeeCostBasis, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*ChargeFlatFeeCostBasis, 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.(*ChargeFlatFeeCostBasisMutation) + 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] = builder.createSpec() + 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 *ChargeFlatFeeCostBasisCreateBulk) SaveX(ctx context.Context) []*ChargeFlatFeeCostBasis { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ChargeFlatFeeCostBasisCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ChargeFlatFeeCostBasisCreateBulk) 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.ChargeFlatFeeCostBasis.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.ChargeFlatFeeCostBasisUpsert) { +// SetMode(v+v). +// }). +// Exec(ctx) +func (_c *ChargeFlatFeeCostBasisCreateBulk) OnConflict(opts ...sql.ConflictOption) *ChargeFlatFeeCostBasisUpsertBulk { + _c.conflict = opts + return &ChargeFlatFeeCostBasisUpsertBulk{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.ChargeFlatFeeCostBasis.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *ChargeFlatFeeCostBasisCreateBulk) OnConflictColumns(columns ...string) *ChargeFlatFeeCostBasisUpsertBulk { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &ChargeFlatFeeCostBasisUpsertBulk{ + create: _c, + } +} + +// ChargeFlatFeeCostBasisUpsertBulk is the builder for "upsert"-ing +// a bulk of ChargeFlatFeeCostBasis nodes. +type ChargeFlatFeeCostBasisUpsertBulk struct { + create *ChargeFlatFeeCostBasisCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.ChargeFlatFeeCostBasis.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(chargeflatfeecostbasis.FieldID) +// }), +// ). +// Exec(ctx) +func (u *ChargeFlatFeeCostBasisUpsertBulk) UpdateNewValues() *ChargeFlatFeeCostBasisUpsertBulk { + 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(chargeflatfeecostbasis.FieldID) + } + if _, exists := b.mutation.Mode(); exists { + s.SetIgnore(chargeflatfeecostbasis.FieldMode) + } + if _, exists := b.mutation.FiatCurrency(); exists { + s.SetIgnore(chargeflatfeecostbasis.FieldFiatCurrency) + } + if _, exists := b.mutation.CurrencyID(); exists { + s.SetIgnore(chargeflatfeecostbasis.FieldCurrencyID) + } + if _, exists := b.mutation.ManualRate(); exists { + s.SetIgnore(chargeflatfeecostbasis.FieldManualRate) + } + if _, exists := b.mutation.Namespace(); exists { + s.SetIgnore(chargeflatfeecostbasis.FieldNamespace) + } + if _, exists := b.mutation.CreatedAt(); exists { + s.SetIgnore(chargeflatfeecostbasis.FieldCreatedAt) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.ChargeFlatFeeCostBasis.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *ChargeFlatFeeCostBasisUpsertBulk) Ignore() *ChargeFlatFeeCostBasisUpsertBulk { + 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 *ChargeFlatFeeCostBasisUpsertBulk) DoNothing() *ChargeFlatFeeCostBasisUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the ChargeFlatFeeCostBasisCreateBulk.OnConflict +// documentation for more info. +func (u *ChargeFlatFeeCostBasisUpsertBulk) Update(set func(*ChargeFlatFeeCostBasisUpsert)) *ChargeFlatFeeCostBasisUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&ChargeFlatFeeCostBasisUpsert{UpdateSet: update}) + })) + return u +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (u *ChargeFlatFeeCostBasisUpsertBulk) SetCurrencyCostBasisID(v string) *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.SetCurrencyCostBasisID(v) + }) +} + +// UpdateCurrencyCostBasisID sets the "currency_cost_basis_id" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsertBulk) UpdateCurrencyCostBasisID() *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.UpdateCurrencyCostBasisID() + }) +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (u *ChargeFlatFeeCostBasisUpsertBulk) ClearCurrencyCostBasisID() *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.ClearCurrencyCostBasisID() + }) +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (u *ChargeFlatFeeCostBasisUpsertBulk) SetResolvedCostBasisID(v string) *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.SetResolvedCostBasisID(v) + }) +} + +// UpdateResolvedCostBasisID sets the "resolved_cost_basis_id" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsertBulk) UpdateResolvedCostBasisID() *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.UpdateResolvedCostBasisID() + }) +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (u *ChargeFlatFeeCostBasisUpsertBulk) ClearResolvedCostBasisID() *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.ClearResolvedCostBasisID() + }) +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (u *ChargeFlatFeeCostBasisUpsertBulk) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.SetResolvedCostBasis(v) + }) +} + +// UpdateResolvedCostBasis sets the "resolved_cost_basis" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsertBulk) UpdateResolvedCostBasis() *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.UpdateResolvedCostBasis() + }) +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (u *ChargeFlatFeeCostBasisUpsertBulk) ClearResolvedCostBasis() *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.ClearResolvedCostBasis() + }) +} + +// SetResolvedAt sets the "resolved_at" field. +func (u *ChargeFlatFeeCostBasisUpsertBulk) SetResolvedAt(v time.Time) *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.SetResolvedAt(v) + }) +} + +// UpdateResolvedAt sets the "resolved_at" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsertBulk) UpdateResolvedAt() *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.UpdateResolvedAt() + }) +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (u *ChargeFlatFeeCostBasisUpsertBulk) ClearResolvedAt() *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.ClearResolvedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *ChargeFlatFeeCostBasisUpsertBulk) SetUpdatedAt(v time.Time) *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsertBulk) UpdateUpdatedAt() *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *ChargeFlatFeeCostBasisUpsertBulk) SetDeletedAt(v time.Time) *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.SetDeletedAt(v) + }) +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *ChargeFlatFeeCostBasisUpsertBulk) UpdateDeletedAt() *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.UpdateDeletedAt() + }) +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *ChargeFlatFeeCostBasisUpsertBulk) ClearDeletedAt() *ChargeFlatFeeCostBasisUpsertBulk { + return u.Update(func(s *ChargeFlatFeeCostBasisUpsert) { + s.ClearDeletedAt() + }) +} + +// Exec executes the query. +func (u *ChargeFlatFeeCostBasisUpsertBulk) 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 ChargeFlatFeeCostBasisCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for ChargeFlatFeeCostBasisCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *ChargeFlatFeeCostBasisUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/openmeter/ent/db/chargeflatfeecostbasis_delete.go b/openmeter/ent/db/chargeflatfeecostbasis_delete.go new file mode 100644 index 0000000000..f98400c869 --- /dev/null +++ b/openmeter/ent/db/chargeflatfeecostbasis_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/chargeflatfeecostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" +) + +// ChargeFlatFeeCostBasisDelete is the builder for deleting a ChargeFlatFeeCostBasis entity. +type ChargeFlatFeeCostBasisDelete struct { + config + hooks []Hook + mutation *ChargeFlatFeeCostBasisMutation +} + +// Where appends a list predicates to the ChargeFlatFeeCostBasisDelete builder. +func (_d *ChargeFlatFeeCostBasisDelete) Where(ps ...predicate.ChargeFlatFeeCostBasis) *ChargeFlatFeeCostBasisDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *ChargeFlatFeeCostBasisDelete) 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 *ChargeFlatFeeCostBasisDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *ChargeFlatFeeCostBasisDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(chargeflatfeecostbasis.Table, sqlgraph.NewFieldSpec(chargeflatfeecostbasis.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 +} + +// ChargeFlatFeeCostBasisDeleteOne is the builder for deleting a single ChargeFlatFeeCostBasis entity. +type ChargeFlatFeeCostBasisDeleteOne struct { + _d *ChargeFlatFeeCostBasisDelete +} + +// Where appends a list predicates to the ChargeFlatFeeCostBasisDelete builder. +func (_d *ChargeFlatFeeCostBasisDeleteOne) Where(ps ...predicate.ChargeFlatFeeCostBasis) *ChargeFlatFeeCostBasisDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *ChargeFlatFeeCostBasisDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{chargeflatfeecostbasis.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ChargeFlatFeeCostBasisDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/openmeter/ent/db/chargeflatfeecostbasis_query.go b/openmeter/ent/db/chargeflatfeecostbasis_query.go new file mode 100644 index 0000000000..88316f62c2 --- /dev/null +++ b/openmeter/ent/db/chargeflatfeecostbasis_query.go @@ -0,0 +1,798 @@ +// 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/chargeflatfeecostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/currencycostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" +) + +// ChargeFlatFeeCostBasisQuery is the builder for querying ChargeFlatFeeCostBasis entities. +type ChargeFlatFeeCostBasisQuery struct { + config + ctx *QueryContext + order []chargeflatfeecostbasis.OrderOption + inters []Interceptor + predicates []predicate.ChargeFlatFeeCostBasis + withCurrencyCostBasis *CurrencyCostBasisQuery + withResolvedCurrencyCostBasis *CurrencyCostBasisQuery + withCustomCurrency *CustomCurrencyQuery + 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 ChargeFlatFeeCostBasisQuery builder. +func (_q *ChargeFlatFeeCostBasisQuery) Where(ps ...predicate.ChargeFlatFeeCostBasis) *ChargeFlatFeeCostBasisQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *ChargeFlatFeeCostBasisQuery) Limit(limit int) *ChargeFlatFeeCostBasisQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *ChargeFlatFeeCostBasisQuery) Offset(offset int) *ChargeFlatFeeCostBasisQuery { + _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 *ChargeFlatFeeCostBasisQuery) Unique(unique bool) *ChargeFlatFeeCostBasisQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *ChargeFlatFeeCostBasisQuery) Order(o ...chargeflatfeecostbasis.OrderOption) *ChargeFlatFeeCostBasisQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryCurrencyCostBasis chains the current query on the "currency_cost_basis" edge. +func (_q *ChargeFlatFeeCostBasisQuery) QueryCurrencyCostBasis() *CurrencyCostBasisQuery { + query := (&CurrencyCostBasisClient{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(chargeflatfeecostbasis.Table, chargeflatfeecostbasis.FieldID, selector), + sqlgraph.To(currencycostbasis.Table, currencycostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeflatfeecostbasis.CurrencyCostBasisTable, chargeflatfeecostbasis.CurrencyCostBasisColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryResolvedCurrencyCostBasis chains the current query on the "resolved_currency_cost_basis" edge. +func (_q *ChargeFlatFeeCostBasisQuery) QueryResolvedCurrencyCostBasis() *CurrencyCostBasisQuery { + query := (&CurrencyCostBasisClient{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(chargeflatfeecostbasis.Table, chargeflatfeecostbasis.FieldID, selector), + sqlgraph.To(currencycostbasis.Table, currencycostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeflatfeecostbasis.ResolvedCurrencyCostBasisTable, chargeflatfeecostbasis.ResolvedCurrencyCostBasisColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryCustomCurrency chains the current query on the "custom_currency" edge. +func (_q *ChargeFlatFeeCostBasisQuery) QueryCustomCurrency() *CustomCurrencyQuery { + query := (&CustomCurrencyClient{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(chargeflatfeecostbasis.Table, chargeflatfeecostbasis.FieldID, selector), + sqlgraph.To(customcurrency.Table, customcurrency.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeflatfeecostbasis.CustomCurrencyTable, chargeflatfeecostbasis.CustomCurrencyColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first ChargeFlatFeeCostBasis entity from the query. +// Returns a *NotFoundError when no ChargeFlatFeeCostBasis was found. +func (_q *ChargeFlatFeeCostBasisQuery) First(ctx context.Context) (*ChargeFlatFeeCostBasis, 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{chargeflatfeecostbasis.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *ChargeFlatFeeCostBasisQuery) FirstX(ctx context.Context) *ChargeFlatFeeCostBasis { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first ChargeFlatFeeCostBasis ID from the query. +// Returns a *NotFoundError when no ChargeFlatFeeCostBasis ID was found. +func (_q *ChargeFlatFeeCostBasisQuery) 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{chargeflatfeecostbasis.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *ChargeFlatFeeCostBasisQuery) FirstIDX(ctx context.Context) string { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single ChargeFlatFeeCostBasis entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one ChargeFlatFeeCostBasis entity is found. +// Returns a *NotFoundError when no ChargeFlatFeeCostBasis entities are found. +func (_q *ChargeFlatFeeCostBasisQuery) Only(ctx context.Context) (*ChargeFlatFeeCostBasis, 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{chargeflatfeecostbasis.Label} + default: + return nil, &NotSingularError{chargeflatfeecostbasis.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *ChargeFlatFeeCostBasisQuery) OnlyX(ctx context.Context) *ChargeFlatFeeCostBasis { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only ChargeFlatFeeCostBasis ID in the query. +// Returns a *NotSingularError when more than one ChargeFlatFeeCostBasis ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *ChargeFlatFeeCostBasisQuery) 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{chargeflatfeecostbasis.Label} + default: + err = &NotSingularError{chargeflatfeecostbasis.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *ChargeFlatFeeCostBasisQuery) 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 ChargeFlatFeeCostBases. +func (_q *ChargeFlatFeeCostBasisQuery) All(ctx context.Context) ([]*ChargeFlatFeeCostBasis, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*ChargeFlatFeeCostBasis, *ChargeFlatFeeCostBasisQuery]() + return withInterceptors[[]*ChargeFlatFeeCostBasis](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *ChargeFlatFeeCostBasisQuery) AllX(ctx context.Context) []*ChargeFlatFeeCostBasis { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of ChargeFlatFeeCostBasis IDs. +func (_q *ChargeFlatFeeCostBasisQuery) 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(chargeflatfeecostbasis.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *ChargeFlatFeeCostBasisQuery) 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 *ChargeFlatFeeCostBasisQuery) 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[*ChargeFlatFeeCostBasisQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *ChargeFlatFeeCostBasisQuery) 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 *ChargeFlatFeeCostBasisQuery) 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 *ChargeFlatFeeCostBasisQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the ChargeFlatFeeCostBasisQuery 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 *ChargeFlatFeeCostBasisQuery) Clone() *ChargeFlatFeeCostBasisQuery { + if _q == nil { + return nil + } + return &ChargeFlatFeeCostBasisQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]chargeflatfeecostbasis.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.ChargeFlatFeeCostBasis{}, _q.predicates...), + withCurrencyCostBasis: _q.withCurrencyCostBasis.Clone(), + withResolvedCurrencyCostBasis: _q.withResolvedCurrencyCostBasis.Clone(), + withCustomCurrency: _q.withCustomCurrency.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithCurrencyCostBasis tells the query-builder to eager-load the nodes that are connected to +// the "currency_cost_basis" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeFlatFeeCostBasisQuery) WithCurrencyCostBasis(opts ...func(*CurrencyCostBasisQuery)) *ChargeFlatFeeCostBasisQuery { + query := (&CurrencyCostBasisClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withCurrencyCostBasis = query + return _q +} + +// WithResolvedCurrencyCostBasis tells the query-builder to eager-load the nodes that are connected to +// the "resolved_currency_cost_basis" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeFlatFeeCostBasisQuery) WithResolvedCurrencyCostBasis(opts ...func(*CurrencyCostBasisQuery)) *ChargeFlatFeeCostBasisQuery { + query := (&CurrencyCostBasisClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withResolvedCurrencyCostBasis = query + return _q +} + +// WithCustomCurrency tells the query-builder to eager-load the nodes that are connected to +// the "custom_currency" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeFlatFeeCostBasisQuery) WithCustomCurrency(opts ...func(*CustomCurrencyQuery)) *ChargeFlatFeeCostBasisQuery { + query := (&CustomCurrencyClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withCustomCurrency = 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 { +// Mode costbasis.Mode `json:"mode,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.ChargeFlatFeeCostBasis.Query(). +// GroupBy(chargeflatfeecostbasis.FieldMode). +// Aggregate(db.Count()). +// Scan(ctx, &v) +func (_q *ChargeFlatFeeCostBasisQuery) GroupBy(field string, fields ...string) *ChargeFlatFeeCostBasisGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &ChargeFlatFeeCostBasisGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = chargeflatfeecostbasis.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 { +// Mode costbasis.Mode `json:"mode,omitempty"` +// } +// +// client.ChargeFlatFeeCostBasis.Query(). +// Select(chargeflatfeecostbasis.FieldMode). +// Scan(ctx, &v) +func (_q *ChargeFlatFeeCostBasisQuery) Select(fields ...string) *ChargeFlatFeeCostBasisSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &ChargeFlatFeeCostBasisSelect{ChargeFlatFeeCostBasisQuery: _q} + sbuild.label = chargeflatfeecostbasis.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a ChargeFlatFeeCostBasisSelect configured with the given aggregations. +func (_q *ChargeFlatFeeCostBasisQuery) Aggregate(fns ...AggregateFunc) *ChargeFlatFeeCostBasisSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *ChargeFlatFeeCostBasisQuery) 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 !chargeflatfeecostbasis.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 *ChargeFlatFeeCostBasisQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ChargeFlatFeeCostBasis, error) { + var ( + nodes = []*ChargeFlatFeeCostBasis{} + _spec = _q.querySpec() + loadedTypes = [3]bool{ + _q.withCurrencyCostBasis != nil, + _q.withResolvedCurrencyCostBasis != nil, + _q.withCustomCurrency != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*ChargeFlatFeeCostBasis).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &ChargeFlatFeeCostBasis{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.withCurrencyCostBasis; query != nil { + if err := _q.loadCurrencyCostBasis(ctx, query, nodes, nil, + func(n *ChargeFlatFeeCostBasis, e *CurrencyCostBasis) { n.Edges.CurrencyCostBasis = e }); err != nil { + return nil, err + } + } + if query := _q.withResolvedCurrencyCostBasis; query != nil { + if err := _q.loadResolvedCurrencyCostBasis(ctx, query, nodes, nil, + func(n *ChargeFlatFeeCostBasis, e *CurrencyCostBasis) { n.Edges.ResolvedCurrencyCostBasis = e }); err != nil { + return nil, err + } + } + if query := _q.withCustomCurrency; query != nil { + if err := _q.loadCustomCurrency(ctx, query, nodes, nil, + func(n *ChargeFlatFeeCostBasis, e *CustomCurrency) { n.Edges.CustomCurrency = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *ChargeFlatFeeCostBasisQuery) loadCurrencyCostBasis(ctx context.Context, query *CurrencyCostBasisQuery, nodes []*ChargeFlatFeeCostBasis, init func(*ChargeFlatFeeCostBasis), assign func(*ChargeFlatFeeCostBasis, *CurrencyCostBasis)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*ChargeFlatFeeCostBasis) + for i := range nodes { + if nodes[i].CurrencyCostBasisID == nil { + continue + } + fk := *nodes[i].CurrencyCostBasisID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(currencycostbasis.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 "currency_cost_basis_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *ChargeFlatFeeCostBasisQuery) loadResolvedCurrencyCostBasis(ctx context.Context, query *CurrencyCostBasisQuery, nodes []*ChargeFlatFeeCostBasis, init func(*ChargeFlatFeeCostBasis), assign func(*ChargeFlatFeeCostBasis, *CurrencyCostBasis)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*ChargeFlatFeeCostBasis) + for i := range nodes { + if nodes[i].ResolvedCostBasisID == nil { + continue + } + fk := *nodes[i].ResolvedCostBasisID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(currencycostbasis.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 "resolved_cost_basis_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *ChargeFlatFeeCostBasisQuery) loadCustomCurrency(ctx context.Context, query *CustomCurrencyQuery, nodes []*ChargeFlatFeeCostBasis, init func(*ChargeFlatFeeCostBasis), assign func(*ChargeFlatFeeCostBasis, *CustomCurrency)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*ChargeFlatFeeCostBasis) + for i := range nodes { + fk := nodes[i].CurrencyID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(customcurrency.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 "currency_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (_q *ChargeFlatFeeCostBasisQuery) 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 *ChargeFlatFeeCostBasisQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(chargeflatfeecostbasis.Table, chargeflatfeecostbasis.Columns, sqlgraph.NewFieldSpec(chargeflatfeecostbasis.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, chargeflatfeecostbasis.FieldID) + for i := range fields { + if fields[i] != chargeflatfeecostbasis.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withCurrencyCostBasis != nil { + _spec.Node.AddColumnOnce(chargeflatfeecostbasis.FieldCurrencyCostBasisID) + } + if _q.withResolvedCurrencyCostBasis != nil { + _spec.Node.AddColumnOnce(chargeflatfeecostbasis.FieldResolvedCostBasisID) + } + if _q.withCustomCurrency != nil { + _spec.Node.AddColumnOnce(chargeflatfeecostbasis.FieldCurrencyID) + } + } + 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 *ChargeFlatFeeCostBasisQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(chargeflatfeecostbasis.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = chargeflatfeecostbasis.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 *ChargeFlatFeeCostBasisQuery) ForUpdate(opts ...sql.LockOption) *ChargeFlatFeeCostBasisQuery { + 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 *ChargeFlatFeeCostBasisQuery) ForShare(opts ...sql.LockOption) *ChargeFlatFeeCostBasisQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForShare(opts...) + }) + return _q +} + +// ChargeFlatFeeCostBasisGroupBy is the group-by builder for ChargeFlatFeeCostBasis entities. +type ChargeFlatFeeCostBasisGroupBy struct { + selector + build *ChargeFlatFeeCostBasisQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *ChargeFlatFeeCostBasisGroupBy) Aggregate(fns ...AggregateFunc) *ChargeFlatFeeCostBasisGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *ChargeFlatFeeCostBasisGroupBy) 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[*ChargeFlatFeeCostBasisQuery, *ChargeFlatFeeCostBasisGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *ChargeFlatFeeCostBasisGroupBy) sqlScan(ctx context.Context, root *ChargeFlatFeeCostBasisQuery, 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) +} + +// ChargeFlatFeeCostBasisSelect is the builder for selecting fields of ChargeFlatFeeCostBasis entities. +type ChargeFlatFeeCostBasisSelect struct { + *ChargeFlatFeeCostBasisQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *ChargeFlatFeeCostBasisSelect) Aggregate(fns ...AggregateFunc) *ChargeFlatFeeCostBasisSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *ChargeFlatFeeCostBasisSelect) 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[*ChargeFlatFeeCostBasisQuery, *ChargeFlatFeeCostBasisSelect](ctx, _s.ChargeFlatFeeCostBasisQuery, _s, _s.inters, v) +} + +func (_s *ChargeFlatFeeCostBasisSelect) sqlScan(ctx context.Context, root *ChargeFlatFeeCostBasisQuery, 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/chargeflatfeecostbasis_update.go b/openmeter/ent/db/chargeflatfeecostbasis_update.go new file mode 100644 index 0000000000..28572c61a2 --- /dev/null +++ b/openmeter/ent/db/chargeflatfeecostbasis_update.go @@ -0,0 +1,666 @@ +// 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/alpacahq/alpacadecimal" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeecostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/currencycostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" +) + +// ChargeFlatFeeCostBasisUpdate is the builder for updating ChargeFlatFeeCostBasis entities. +type ChargeFlatFeeCostBasisUpdate struct { + config + hooks []Hook + mutation *ChargeFlatFeeCostBasisMutation +} + +// Where appends a list predicates to the ChargeFlatFeeCostBasisUpdate builder. +func (_u *ChargeFlatFeeCostBasisUpdate) Where(ps ...predicate.ChargeFlatFeeCostBasis) *ChargeFlatFeeCostBasisUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (_u *ChargeFlatFeeCostBasisUpdate) SetCurrencyCostBasisID(v string) *ChargeFlatFeeCostBasisUpdate { + _u.mutation.SetCurrencyCostBasisID(v) + return _u +} + +// SetNillableCurrencyCostBasisID sets the "currency_cost_basis_id" field if the given value is not nil. +func (_u *ChargeFlatFeeCostBasisUpdate) SetNillableCurrencyCostBasisID(v *string) *ChargeFlatFeeCostBasisUpdate { + if v != nil { + _u.SetCurrencyCostBasisID(*v) + } + return _u +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (_u *ChargeFlatFeeCostBasisUpdate) ClearCurrencyCostBasisID() *ChargeFlatFeeCostBasisUpdate { + _u.mutation.ClearCurrencyCostBasisID() + return _u +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (_u *ChargeFlatFeeCostBasisUpdate) SetResolvedCostBasisID(v string) *ChargeFlatFeeCostBasisUpdate { + _u.mutation.SetResolvedCostBasisID(v) + return _u +} + +// SetNillableResolvedCostBasisID sets the "resolved_cost_basis_id" field if the given value is not nil. +func (_u *ChargeFlatFeeCostBasisUpdate) SetNillableResolvedCostBasisID(v *string) *ChargeFlatFeeCostBasisUpdate { + if v != nil { + _u.SetResolvedCostBasisID(*v) + } + return _u +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (_u *ChargeFlatFeeCostBasisUpdate) ClearResolvedCostBasisID() *ChargeFlatFeeCostBasisUpdate { + _u.mutation.ClearResolvedCostBasisID() + return _u +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (_u *ChargeFlatFeeCostBasisUpdate) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeFlatFeeCostBasisUpdate { + _u.mutation.SetResolvedCostBasis(v) + return _u +} + +// SetNillableResolvedCostBasis sets the "resolved_cost_basis" field if the given value is not nil. +func (_u *ChargeFlatFeeCostBasisUpdate) SetNillableResolvedCostBasis(v *alpacadecimal.Decimal) *ChargeFlatFeeCostBasisUpdate { + if v != nil { + _u.SetResolvedCostBasis(*v) + } + return _u +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (_u *ChargeFlatFeeCostBasisUpdate) ClearResolvedCostBasis() *ChargeFlatFeeCostBasisUpdate { + _u.mutation.ClearResolvedCostBasis() + return _u +} + +// SetResolvedAt sets the "resolved_at" field. +func (_u *ChargeFlatFeeCostBasisUpdate) SetResolvedAt(v time.Time) *ChargeFlatFeeCostBasisUpdate { + _u.mutation.SetResolvedAt(v) + return _u +} + +// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil. +func (_u *ChargeFlatFeeCostBasisUpdate) SetNillableResolvedAt(v *time.Time) *ChargeFlatFeeCostBasisUpdate { + if v != nil { + _u.SetResolvedAt(*v) + } + return _u +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (_u *ChargeFlatFeeCostBasisUpdate) ClearResolvedAt() *ChargeFlatFeeCostBasisUpdate { + _u.mutation.ClearResolvedAt() + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ChargeFlatFeeCostBasisUpdate) SetUpdatedAt(v time.Time) *ChargeFlatFeeCostBasisUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetDeletedAt sets the "deleted_at" field. +func (_u *ChargeFlatFeeCostBasisUpdate) SetDeletedAt(v time.Time) *ChargeFlatFeeCostBasisUpdate { + _u.mutation.SetDeletedAt(v) + return _u +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_u *ChargeFlatFeeCostBasisUpdate) SetNillableDeletedAt(v *time.Time) *ChargeFlatFeeCostBasisUpdate { + if v != nil { + _u.SetDeletedAt(*v) + } + return _u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (_u *ChargeFlatFeeCostBasisUpdate) ClearDeletedAt() *ChargeFlatFeeCostBasisUpdate { + _u.mutation.ClearDeletedAt() + return _u +} + +// SetCurrencyCostBasis sets the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeFlatFeeCostBasisUpdate) SetCurrencyCostBasis(v *CurrencyCostBasis) *ChargeFlatFeeCostBasisUpdate { + return _u.SetCurrencyCostBasisID(v.ID) +} + +// SetResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID. +func (_u *ChargeFlatFeeCostBasisUpdate) SetResolvedCurrencyCostBasisID(id string) *ChargeFlatFeeCostBasisUpdate { + _u.mutation.SetResolvedCurrencyCostBasisID(id) + return _u +} + +// SetNillableResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID if the given value is not nil. +func (_u *ChargeFlatFeeCostBasisUpdate) SetNillableResolvedCurrencyCostBasisID(id *string) *ChargeFlatFeeCostBasisUpdate { + if id != nil { + _u = _u.SetResolvedCurrencyCostBasisID(*id) + } + return _u +} + +// SetResolvedCurrencyCostBasis sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeFlatFeeCostBasisUpdate) SetResolvedCurrencyCostBasis(v *CurrencyCostBasis) *ChargeFlatFeeCostBasisUpdate { + return _u.SetResolvedCurrencyCostBasisID(v.ID) +} + +// Mutation returns the ChargeFlatFeeCostBasisMutation object of the builder. +func (_u *ChargeFlatFeeCostBasisUpdate) Mutation() *ChargeFlatFeeCostBasisMutation { + return _u.mutation +} + +// ClearCurrencyCostBasis clears the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeFlatFeeCostBasisUpdate) ClearCurrencyCostBasis() *ChargeFlatFeeCostBasisUpdate { + _u.mutation.ClearCurrencyCostBasis() + return _u +} + +// ClearResolvedCurrencyCostBasis clears the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeFlatFeeCostBasisUpdate) ClearResolvedCurrencyCostBasis() *ChargeFlatFeeCostBasisUpdate { + _u.mutation.ClearResolvedCurrencyCostBasis() + return _u +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *ChargeFlatFeeCostBasisUpdate) 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 *ChargeFlatFeeCostBasisUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *ChargeFlatFeeCostBasisUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ChargeFlatFeeCostBasisUpdate) 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 *ChargeFlatFeeCostBasisUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := chargeflatfeecostbasis.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ChargeFlatFeeCostBasisUpdate) check() error { + if _u.mutation.CustomCurrencyCleared() && len(_u.mutation.CustomCurrencyIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "ChargeFlatFeeCostBasis.custom_currency"`) + } + return nil +} + +func (_u *ChargeFlatFeeCostBasisUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(chargeflatfeecostbasis.Table, chargeflatfeecostbasis.Columns, sqlgraph.NewFieldSpec(chargeflatfeecostbasis.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 _u.mutation.ManualRateCleared() { + _spec.ClearField(chargeflatfeecostbasis.FieldManualRate, field.TypeOther) + } + if value, ok := _u.mutation.ResolvedCostBasis(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldResolvedCostBasis, field.TypeOther, value) + } + if _u.mutation.ResolvedCostBasisCleared() { + _spec.ClearField(chargeflatfeecostbasis.FieldResolvedCostBasis, field.TypeOther) + } + if value, ok := _u.mutation.ResolvedAt(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldResolvedAt, field.TypeTime, value) + } + if _u.mutation.ResolvedAtCleared() { + _spec.ClearField(chargeflatfeecostbasis.FieldResolvedAt, field.TypeTime) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.DeletedAt(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldDeletedAt, field.TypeTime, value) + } + if _u.mutation.DeletedAtCleared() { + _spec.ClearField(chargeflatfeecostbasis.FieldDeletedAt, field.TypeTime) + } + if _u.mutation.CurrencyCostBasisCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeflatfeecostbasis.CurrencyCostBasisTable, + Columns: []string{chargeflatfeecostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.CurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeflatfeecostbasis.CurrencyCostBasisTable, + Columns: []string{chargeflatfeecostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.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.ResolvedCurrencyCostBasisCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeflatfeecostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargeflatfeecostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ResolvedCurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeflatfeecostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargeflatfeecostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.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{chargeflatfeecostbasis.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// ChargeFlatFeeCostBasisUpdateOne is the builder for updating a single ChargeFlatFeeCostBasis entity. +type ChargeFlatFeeCostBasisUpdateOne struct { + config + fields []string + hooks []Hook + mutation *ChargeFlatFeeCostBasisMutation +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetCurrencyCostBasisID(v string) *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.SetCurrencyCostBasisID(v) + return _u +} + +// SetNillableCurrencyCostBasisID sets the "currency_cost_basis_id" field if the given value is not nil. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetNillableCurrencyCostBasisID(v *string) *ChargeFlatFeeCostBasisUpdateOne { + if v != nil { + _u.SetCurrencyCostBasisID(*v) + } + return _u +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (_u *ChargeFlatFeeCostBasisUpdateOne) ClearCurrencyCostBasisID() *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.ClearCurrencyCostBasisID() + return _u +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetResolvedCostBasisID(v string) *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.SetResolvedCostBasisID(v) + return _u +} + +// SetNillableResolvedCostBasisID sets the "resolved_cost_basis_id" field if the given value is not nil. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetNillableResolvedCostBasisID(v *string) *ChargeFlatFeeCostBasisUpdateOne { + if v != nil { + _u.SetResolvedCostBasisID(*v) + } + return _u +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (_u *ChargeFlatFeeCostBasisUpdateOne) ClearResolvedCostBasisID() *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.ClearResolvedCostBasisID() + return _u +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.SetResolvedCostBasis(v) + return _u +} + +// SetNillableResolvedCostBasis sets the "resolved_cost_basis" field if the given value is not nil. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetNillableResolvedCostBasis(v *alpacadecimal.Decimal) *ChargeFlatFeeCostBasisUpdateOne { + if v != nil { + _u.SetResolvedCostBasis(*v) + } + return _u +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (_u *ChargeFlatFeeCostBasisUpdateOne) ClearResolvedCostBasis() *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.ClearResolvedCostBasis() + return _u +} + +// SetResolvedAt sets the "resolved_at" field. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetResolvedAt(v time.Time) *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.SetResolvedAt(v) + return _u +} + +// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetNillableResolvedAt(v *time.Time) *ChargeFlatFeeCostBasisUpdateOne { + if v != nil { + _u.SetResolvedAt(*v) + } + return _u +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (_u *ChargeFlatFeeCostBasisUpdateOne) ClearResolvedAt() *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.ClearResolvedAt() + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetUpdatedAt(v time.Time) *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetDeletedAt sets the "deleted_at" field. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetDeletedAt(v time.Time) *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.SetDeletedAt(v) + return _u +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetNillableDeletedAt(v *time.Time) *ChargeFlatFeeCostBasisUpdateOne { + if v != nil { + _u.SetDeletedAt(*v) + } + return _u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (_u *ChargeFlatFeeCostBasisUpdateOne) ClearDeletedAt() *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.ClearDeletedAt() + return _u +} + +// SetCurrencyCostBasis sets the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetCurrencyCostBasis(v *CurrencyCostBasis) *ChargeFlatFeeCostBasisUpdateOne { + return _u.SetCurrencyCostBasisID(v.ID) +} + +// SetResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetResolvedCurrencyCostBasisID(id string) *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.SetResolvedCurrencyCostBasisID(id) + return _u +} + +// SetNillableResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID if the given value is not nil. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetNillableResolvedCurrencyCostBasisID(id *string) *ChargeFlatFeeCostBasisUpdateOne { + if id != nil { + _u = _u.SetResolvedCurrencyCostBasisID(*id) + } + return _u +} + +// SetResolvedCurrencyCostBasis sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SetResolvedCurrencyCostBasis(v *CurrencyCostBasis) *ChargeFlatFeeCostBasisUpdateOne { + return _u.SetResolvedCurrencyCostBasisID(v.ID) +} + +// Mutation returns the ChargeFlatFeeCostBasisMutation object of the builder. +func (_u *ChargeFlatFeeCostBasisUpdateOne) Mutation() *ChargeFlatFeeCostBasisMutation { + return _u.mutation +} + +// ClearCurrencyCostBasis clears the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeFlatFeeCostBasisUpdateOne) ClearCurrencyCostBasis() *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.ClearCurrencyCostBasis() + return _u +} + +// ClearResolvedCurrencyCostBasis clears the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeFlatFeeCostBasisUpdateOne) ClearResolvedCurrencyCostBasis() *ChargeFlatFeeCostBasisUpdateOne { + _u.mutation.ClearResolvedCurrencyCostBasis() + return _u +} + +// Where appends a list predicates to the ChargeFlatFeeCostBasisUpdate builder. +func (_u *ChargeFlatFeeCostBasisUpdateOne) Where(ps ...predicate.ChargeFlatFeeCostBasis) *ChargeFlatFeeCostBasisUpdateOne { + _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 *ChargeFlatFeeCostBasisUpdateOne) Select(field string, fields ...string) *ChargeFlatFeeCostBasisUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated ChargeFlatFeeCostBasis entity. +func (_u *ChargeFlatFeeCostBasisUpdateOne) Save(ctx context.Context) (*ChargeFlatFeeCostBasis, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ChargeFlatFeeCostBasisUpdateOne) SaveX(ctx context.Context) *ChargeFlatFeeCostBasis { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *ChargeFlatFeeCostBasisUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ChargeFlatFeeCostBasisUpdateOne) 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 *ChargeFlatFeeCostBasisUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := chargeflatfeecostbasis.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ChargeFlatFeeCostBasisUpdateOne) check() error { + if _u.mutation.CustomCurrencyCleared() && len(_u.mutation.CustomCurrencyIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "ChargeFlatFeeCostBasis.custom_currency"`) + } + return nil +} + +func (_u *ChargeFlatFeeCostBasisUpdateOne) sqlSave(ctx context.Context) (_node *ChargeFlatFeeCostBasis, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(chargeflatfeecostbasis.Table, chargeflatfeecostbasis.Columns, sqlgraph.NewFieldSpec(chargeflatfeecostbasis.FieldID, field.TypeString)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "ChargeFlatFeeCostBasis.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, chargeflatfeecostbasis.FieldID) + for _, f := range fields { + if !chargeflatfeecostbasis.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + if f != chargeflatfeecostbasis.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 _u.mutation.ManualRateCleared() { + _spec.ClearField(chargeflatfeecostbasis.FieldManualRate, field.TypeOther) + } + if value, ok := _u.mutation.ResolvedCostBasis(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldResolvedCostBasis, field.TypeOther, value) + } + if _u.mutation.ResolvedCostBasisCleared() { + _spec.ClearField(chargeflatfeecostbasis.FieldResolvedCostBasis, field.TypeOther) + } + if value, ok := _u.mutation.ResolvedAt(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldResolvedAt, field.TypeTime, value) + } + if _u.mutation.ResolvedAtCleared() { + _spec.ClearField(chargeflatfeecostbasis.FieldResolvedAt, field.TypeTime) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.DeletedAt(); ok { + _spec.SetField(chargeflatfeecostbasis.FieldDeletedAt, field.TypeTime, value) + } + if _u.mutation.DeletedAtCleared() { + _spec.ClearField(chargeflatfeecostbasis.FieldDeletedAt, field.TypeTime) + } + if _u.mutation.CurrencyCostBasisCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeflatfeecostbasis.CurrencyCostBasisTable, + Columns: []string{chargeflatfeecostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.CurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeflatfeecostbasis.CurrencyCostBasisTable, + Columns: []string{chargeflatfeecostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.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.ResolvedCurrencyCostBasisCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeflatfeecostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargeflatfeecostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ResolvedCurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeflatfeecostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargeflatfeecostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &ChargeFlatFeeCostBasis{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{chargeflatfeecostbasis.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/chargeusagebased.go b/openmeter/ent/db/chargeusagebased.go index a1268aa5ac..99312cbe41 100644 --- a/openmeter/ent/db/chargeusagebased.go +++ b/openmeter/ent/db/chargeusagebased.go @@ -15,6 +15,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebased" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedcostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedruns" "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" @@ -106,6 +107,8 @@ type ChargeUsageBased struct { UnitConfig *productcatalog.UnitConfig `json:"unit_config,omitempty"` // CurrentRealizationRunID holds the value of the "current_realization_run_id" field. CurrentRealizationRunID *string `json:"current_realization_run_id,omitempty"` + // CostBasisID holds the value of the "cost_basis_id" field. + CostBasisID *string `json:"cost_basis_id,omitempty"` // StatusDetailed holds the value of the "status_detailed" field. StatusDetailed usagebased.Status `json:"status_detailed,omitempty"` // Edges holds the relations/edges for other nodes in the graph. @@ -122,6 +125,8 @@ type ChargeUsageBasedEdges struct { DetailedLines []*ChargeUsageBasedRunDetailedLine `json:"detailed_lines,omitempty"` // CurrentRun holds the value of the current_run edge. CurrentRun *ChargeUsageBasedRuns `json:"current_run,omitempty"` + // CostBasis holds the value of the cost_basis edge. + CostBasis *ChargeUsageBasedCostBasis `json:"cost_basis,omitempty"` // Charge holds the value of the charge edge. Charge *Charge `json:"charge,omitempty"` // IntentOverride holds the value of the intent_override edge. @@ -142,7 +147,7 @@ type ChargeUsageBasedEdges struct { CustomCurrency *CustomCurrency `json:"custom_currency,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [12]bool + loadedTypes [13]bool } // RunsOrErr returns the Runs value or an error if the edge @@ -174,12 +179,23 @@ func (e ChargeUsageBasedEdges) CurrentRunOrErr() (*ChargeUsageBasedRuns, error) return nil, &NotLoadedError{edge: "current_run"} } +// CostBasisOrErr returns the CostBasis value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChargeUsageBasedEdges) CostBasisOrErr() (*ChargeUsageBasedCostBasis, error) { + if e.CostBasis != nil { + return e.CostBasis, nil + } else if e.loadedTypes[3] { + return nil, &NotFoundError{label: chargeusagebasedcostbasis.Label} + } + return nil, &NotLoadedError{edge: "cost_basis"} +} + // 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 ChargeUsageBasedEdges) ChargeOrErr() (*Charge, error) { if e.Charge != nil { return e.Charge, nil - } else if e.loadedTypes[3] { + } else if e.loadedTypes[4] { return nil, &NotFoundError{label: charge.Label} } return nil, &NotLoadedError{edge: "charge"} @@ -190,7 +206,7 @@ func (e ChargeUsageBasedEdges) ChargeOrErr() (*Charge, error) { func (e ChargeUsageBasedEdges) IntentOverrideOrErr() (*ChargeUsageBasedOverride, error) { if e.IntentOverride != nil { return e.IntentOverride, nil - } else if e.loadedTypes[4] { + } else if e.loadedTypes[5] { return nil, &NotFoundError{label: chargeusagebasedoverride.Label} } return nil, &NotLoadedError{edge: "intent_override"} @@ -201,7 +217,7 @@ func (e ChargeUsageBasedEdges) IntentOverrideOrErr() (*ChargeUsageBasedOverride, func (e ChargeUsageBasedEdges) SubscriptionOrErr() (*Subscription, error) { if e.Subscription != nil { return e.Subscription, nil - } else if e.loadedTypes[5] { + } else if e.loadedTypes[6] { return nil, &NotFoundError{label: subscription.Label} } return nil, &NotLoadedError{edge: "subscription"} @@ -212,7 +228,7 @@ func (e ChargeUsageBasedEdges) SubscriptionOrErr() (*Subscription, error) { func (e ChargeUsageBasedEdges) SubscriptionPhaseOrErr() (*SubscriptionPhase, error) { if e.SubscriptionPhase != nil { return e.SubscriptionPhase, nil - } else if e.loadedTypes[6] { + } else if e.loadedTypes[7] { return nil, &NotFoundError{label: subscriptionphase.Label} } return nil, &NotLoadedError{edge: "subscription_phase"} @@ -223,7 +239,7 @@ func (e ChargeUsageBasedEdges) SubscriptionPhaseOrErr() (*SubscriptionPhase, err func (e ChargeUsageBasedEdges) SubscriptionItemOrErr() (*SubscriptionItem, error) { if e.SubscriptionItem != nil { return e.SubscriptionItem, nil - } else if e.loadedTypes[7] { + } else if e.loadedTypes[8] { return nil, &NotFoundError{label: subscriptionitem.Label} } return nil, &NotLoadedError{edge: "subscription_item"} @@ -234,7 +250,7 @@ func (e ChargeUsageBasedEdges) SubscriptionItemOrErr() (*SubscriptionItem, error func (e ChargeUsageBasedEdges) CustomerOrErr() (*Customer, error) { if e.Customer != nil { return e.Customer, nil - } else if e.loadedTypes[8] { + } else if e.loadedTypes[9] { return nil, &NotFoundError{label: customer.Label} } return nil, &NotLoadedError{edge: "customer"} @@ -245,7 +261,7 @@ func (e ChargeUsageBasedEdges) CustomerOrErr() (*Customer, error) { func (e ChargeUsageBasedEdges) FeatureOrErr() (*Feature, error) { if e.Feature != nil { return e.Feature, nil - } else if e.loadedTypes[9] { + } else if e.loadedTypes[10] { return nil, &NotFoundError{label: dbfeature.Label} } return nil, &NotLoadedError{edge: "feature"} @@ -256,7 +272,7 @@ func (e ChargeUsageBasedEdges) FeatureOrErr() (*Feature, error) { func (e ChargeUsageBasedEdges) TaxCodeOrErr() (*TaxCode, error) { if e.TaxCode != nil { return e.TaxCode, nil - } else if e.loadedTypes[10] { + } else if e.loadedTypes[11] { return nil, &NotFoundError{label: dbtaxcode.Label} } return nil, &NotLoadedError{edge: "tax_code"} @@ -267,7 +283,7 @@ func (e ChargeUsageBasedEdges) TaxCodeOrErr() (*TaxCode, error) { func (e ChargeUsageBasedEdges) CustomCurrencyOrErr() (*CustomCurrency, error) { if e.CustomCurrency != nil { return e.CustomCurrency, nil - } else if e.loadedTypes[11] { + } else if e.loadedTypes[12] { return nil, &NotFoundError{label: customcurrency.Label} } return nil, &NotLoadedError{edge: "custom_currency"} @@ -280,7 +296,7 @@ func (*ChargeUsageBased) scanValues(columns []string) ([]any, error) { switch columns[i] { case chargeusagebased.FieldAnnotations, chargeusagebased.FieldMetadata: values[i] = new([]byte) - case chargeusagebased.FieldID, chargeusagebased.FieldCustomerID, chargeusagebased.FieldStatus, chargeusagebased.FieldUniqueReferenceID, chargeusagebased.FieldFiatCurrencyCode, chargeusagebased.FieldCustomCurrencyID, chargeusagebased.FieldManagedBy, chargeusagebased.FieldSubscriptionID, chargeusagebased.FieldSubscriptionPhaseID, chargeusagebased.FieldSubscriptionItemID, chargeusagebased.FieldTaxCodeID, chargeusagebased.FieldTaxBehavior, chargeusagebased.FieldNamespace, chargeusagebased.FieldName, chargeusagebased.FieldDescription, chargeusagebased.FieldSettlementMode, chargeusagebased.FieldFeatureKey, chargeusagebased.FieldFeatureID, chargeusagebased.FieldRatingEngine, chargeusagebased.FieldCurrentRealizationRunID, chargeusagebased.FieldStatusDetailed: + case chargeusagebased.FieldID, chargeusagebased.FieldCustomerID, chargeusagebased.FieldStatus, chargeusagebased.FieldUniqueReferenceID, chargeusagebased.FieldFiatCurrencyCode, chargeusagebased.FieldCustomCurrencyID, chargeusagebased.FieldManagedBy, chargeusagebased.FieldSubscriptionID, chargeusagebased.FieldSubscriptionPhaseID, chargeusagebased.FieldSubscriptionItemID, chargeusagebased.FieldTaxCodeID, chargeusagebased.FieldTaxBehavior, chargeusagebased.FieldNamespace, chargeusagebased.FieldName, chargeusagebased.FieldDescription, chargeusagebased.FieldSettlementMode, chargeusagebased.FieldFeatureKey, chargeusagebased.FieldFeatureID, chargeusagebased.FieldRatingEngine, chargeusagebased.FieldCurrentRealizationRunID, chargeusagebased.FieldCostBasisID, chargeusagebased.FieldStatusDetailed: values[i] = new(sql.NullString) case chargeusagebased.FieldServicePeriodFrom, chargeusagebased.FieldServicePeriodTo, chargeusagebased.FieldBillingPeriodFrom, chargeusagebased.FieldBillingPeriodTo, chargeusagebased.FieldFullServicePeriodFrom, chargeusagebased.FieldFullServicePeriodTo, chargeusagebased.FieldAdvanceAfter, chargeusagebased.FieldCreatedAt, chargeusagebased.FieldUpdatedAt, chargeusagebased.FieldDeletedAt, chargeusagebased.FieldInvoiceAt, chargeusagebased.FieldIntentDeletedAt: values[i] = new(sql.NullTime) @@ -543,6 +559,13 @@ func (_m *ChargeUsageBased) assignValues(columns []string, values []any) error { _m.CurrentRealizationRunID = new(string) *_m.CurrentRealizationRunID = value.String } + case chargeusagebased.FieldCostBasisID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field cost_basis_id", values[i]) + } else if value.Valid { + _m.CostBasisID = new(string) + *_m.CostBasisID = value.String + } case chargeusagebased.FieldStatusDetailed: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field status_detailed", values[i]) @@ -577,6 +600,11 @@ func (_m *ChargeUsageBased) QueryCurrentRun() *ChargeUsageBasedRunsQuery { return NewChargeUsageBasedClient(_m.config).QueryCurrentRun(_m) } +// QueryCostBasis queries the "cost_basis" edge of the ChargeUsageBased entity. +func (_m *ChargeUsageBased) QueryCostBasis() *ChargeUsageBasedCostBasisQuery { + return NewChargeUsageBasedClient(_m.config).QueryCostBasis(_m) +} + // QueryCharge queries the "charge" edge of the ChargeUsageBased entity. func (_m *ChargeUsageBased) QueryCharge() *ChargeQuery { return NewChargeUsageBasedClient(_m.config).QueryCharge(_m) @@ -781,6 +809,11 @@ func (_m *ChargeUsageBased) String() string { builder.WriteString(*v) } builder.WriteString(", ") + if v := _m.CostBasisID; v != nil { + builder.WriteString("cost_basis_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") builder.WriteString("status_detailed=") builder.WriteString(fmt.Sprintf("%v", _m.StatusDetailed)) builder.WriteByte(')') diff --git a/openmeter/ent/db/chargeusagebased/chargeusagebased.go b/openmeter/ent/db/chargeusagebased/chargeusagebased.go index 5b47f2ee5e..683b99cfac 100644 --- a/openmeter/ent/db/chargeusagebased/chargeusagebased.go +++ b/openmeter/ent/db/chargeusagebased/chargeusagebased.go @@ -92,6 +92,8 @@ const ( FieldUnitConfig = "unit_config" // FieldCurrentRealizationRunID holds the string denoting the current_realization_run_id field in the database. FieldCurrentRealizationRunID = "current_realization_run_id" + // FieldCostBasisID holds the string denoting the cost_basis_id field in the database. + FieldCostBasisID = "cost_basis_id" // FieldStatusDetailed holds the string denoting the status_detailed field in the database. FieldStatusDetailed = "status_detailed" // EdgeRuns holds the string denoting the runs edge name in mutations. @@ -100,6 +102,8 @@ const ( EdgeDetailedLines = "detailed_lines" // EdgeCurrentRun holds the string denoting the current_run edge name in mutations. EdgeCurrentRun = "current_run" + // EdgeCostBasis holds the string denoting the cost_basis edge name in mutations. + EdgeCostBasis = "cost_basis" // EdgeCharge holds the string denoting the charge edge name in mutations. EdgeCharge = "charge" // EdgeIntentOverride holds the string denoting the intent_override edge name in mutations. @@ -141,6 +145,13 @@ const ( CurrentRunInverseTable = "charge_usage_based_runs" // CurrentRunColumn is the table column denoting the current_run relation/edge. CurrentRunColumn = "current_realization_run_id" + // CostBasisTable is the table that holds the cost_basis relation/edge. + CostBasisTable = "charge_usage_based" + // CostBasisInverseTable is the table name for the ChargeUsageBasedCostBasis entity. + // It exists in this package in order to avoid circular dependency with the "chargeusagebasedcostbasis" package. + CostBasisInverseTable = "charge_usage_based_cost_bases" + // CostBasisColumn is the table column denoting the cost_basis relation/edge. + CostBasisColumn = "cost_basis_id" // ChargeTable is the table that holds the charge relation/edge. ChargeTable = "charges" // ChargeInverseTable is the table name for the Charge entity. @@ -245,6 +256,7 @@ var Columns = []string{ FieldPrice, FieldUnitConfig, FieldCurrentRealizationRunID, + FieldCostBasisID, FieldStatusDetailed, } @@ -527,6 +539,11 @@ func ByCurrentRealizationRunID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCurrentRealizationRunID, opts...).ToFunc() } +// ByCostBasisID orders the results by the cost_basis_id field. +func ByCostBasisID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCostBasisID, opts...).ToFunc() +} + // ByStatusDetailed orders the results by the status_detailed field. func ByStatusDetailed(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldStatusDetailed, opts...).ToFunc() @@ -567,6 +584,13 @@ func ByCurrentRunField(field string, opts ...sql.OrderTermOption) OrderOption { } } +// ByCostBasisField orders the results by cost_basis field. +func ByCostBasisField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCostBasisStep(), sql.OrderByField(field, opts...)) + } +} + // ByChargeField orders the results by charge field. func ByChargeField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -650,6 +674,13 @@ func newCurrentRunStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.M2O, false, CurrentRunTable, CurrentRunColumn), ) } +func newCostBasisStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CostBasisInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CostBasisTable, CostBasisColumn), + ) +} func newChargeStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/openmeter/ent/db/chargeusagebased/where.go b/openmeter/ent/db/chargeusagebased/where.go index 14b42835b9..1d14144029 100644 --- a/openmeter/ent/db/chargeusagebased/where.go +++ b/openmeter/ent/db/chargeusagebased/where.go @@ -201,6 +201,11 @@ func CurrentRealizationRunID(v string) predicate.ChargeUsageBased { return predicate.ChargeUsageBased(sql.FieldEQ(FieldCurrentRealizationRunID, v)) } +// CostBasisID applies equality check predicate on the "cost_basis_id" field. It's identical to CostBasisIDEQ. +func CostBasisID(v string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldEQ(FieldCostBasisID, v)) +} + // CustomerIDEQ applies the EQ predicate on the "customer_id" field. func CustomerIDEQ(v string) predicate.ChargeUsageBased { return predicate.ChargeUsageBased(sql.FieldEQ(FieldCustomerID, v)) @@ -1920,6 +1925,81 @@ func CurrentRealizationRunIDContainsFold(v string) predicate.ChargeUsageBased { return predicate.ChargeUsageBased(sql.FieldContainsFold(FieldCurrentRealizationRunID, v)) } +// CostBasisIDEQ applies the EQ predicate on the "cost_basis_id" field. +func CostBasisIDEQ(v string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldEQ(FieldCostBasisID, v)) +} + +// CostBasisIDNEQ applies the NEQ predicate on the "cost_basis_id" field. +func CostBasisIDNEQ(v string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldNEQ(FieldCostBasisID, v)) +} + +// CostBasisIDIn applies the In predicate on the "cost_basis_id" field. +func CostBasisIDIn(vs ...string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldIn(FieldCostBasisID, vs...)) +} + +// CostBasisIDNotIn applies the NotIn predicate on the "cost_basis_id" field. +func CostBasisIDNotIn(vs ...string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldNotIn(FieldCostBasisID, vs...)) +} + +// CostBasisIDGT applies the GT predicate on the "cost_basis_id" field. +func CostBasisIDGT(v string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldGT(FieldCostBasisID, v)) +} + +// CostBasisIDGTE applies the GTE predicate on the "cost_basis_id" field. +func CostBasisIDGTE(v string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldGTE(FieldCostBasisID, v)) +} + +// CostBasisIDLT applies the LT predicate on the "cost_basis_id" field. +func CostBasisIDLT(v string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldLT(FieldCostBasisID, v)) +} + +// CostBasisIDLTE applies the LTE predicate on the "cost_basis_id" field. +func CostBasisIDLTE(v string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldLTE(FieldCostBasisID, v)) +} + +// CostBasisIDContains applies the Contains predicate on the "cost_basis_id" field. +func CostBasisIDContains(v string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldContains(FieldCostBasisID, v)) +} + +// CostBasisIDHasPrefix applies the HasPrefix predicate on the "cost_basis_id" field. +func CostBasisIDHasPrefix(v string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldHasPrefix(FieldCostBasisID, v)) +} + +// CostBasisIDHasSuffix applies the HasSuffix predicate on the "cost_basis_id" field. +func CostBasisIDHasSuffix(v string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldHasSuffix(FieldCostBasisID, v)) +} + +// CostBasisIDIsNil applies the IsNil predicate on the "cost_basis_id" field. +func CostBasisIDIsNil() predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldIsNull(FieldCostBasisID)) +} + +// CostBasisIDNotNil applies the NotNil predicate on the "cost_basis_id" field. +func CostBasisIDNotNil() predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldNotNull(FieldCostBasisID)) +} + +// CostBasisIDEqualFold applies the EqualFold predicate on the "cost_basis_id" field. +func CostBasisIDEqualFold(v string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldEqualFold(FieldCostBasisID, v)) +} + +// CostBasisIDContainsFold applies the ContainsFold predicate on the "cost_basis_id" field. +func CostBasisIDContainsFold(v string) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(sql.FieldContainsFold(FieldCostBasisID, v)) +} + // StatusDetailedEQ applies the EQ predicate on the "status_detailed" field. func StatusDetailedEQ(v usagebased.Status) predicate.ChargeUsageBased { vc := v @@ -2019,6 +2099,29 @@ func HasCurrentRunWith(preds ...predicate.ChargeUsageBasedRuns) predicate.Charge }) } +// HasCostBasis applies the HasEdge predicate on the "cost_basis" edge. +func HasCostBasis() predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CostBasisTable, CostBasisColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasCostBasisWith applies the HasEdge predicate on the "cost_basis" edge with a given conditions (other predicates). +func HasCostBasisWith(preds ...predicate.ChargeUsageBasedCostBasis) predicate.ChargeUsageBased { + return predicate.ChargeUsageBased(func(s *sql.Selector) { + step := newCostBasisStep() + 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.ChargeUsageBased { return predicate.ChargeUsageBased(func(s *sql.Selector) { diff --git a/openmeter/ent/db/chargeusagebased_create.go b/openmeter/ent/db/chargeusagebased_create.go index f9f1c9837f..7977abcf16 100644 --- a/openmeter/ent/db/chargeusagebased_create.go +++ b/openmeter/ent/db/chargeusagebased_create.go @@ -17,6 +17,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebased" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedcostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedrundetailedline" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedruns" @@ -368,6 +369,20 @@ func (_c *ChargeUsageBasedCreate) SetNillableCurrentRealizationRunID(v *string) return _c } +// SetCostBasisID sets the "cost_basis_id" field. +func (_c *ChargeUsageBasedCreate) SetCostBasisID(v string) *ChargeUsageBasedCreate { + _c.mutation.SetCostBasisID(v) + return _c +} + +// SetNillableCostBasisID sets the "cost_basis_id" field if the given value is not nil. +func (_c *ChargeUsageBasedCreate) SetNillableCostBasisID(v *string) *ChargeUsageBasedCreate { + if v != nil { + _c.SetCostBasisID(*v) + } + return _c +} + // SetStatusDetailed sets the "status_detailed" field. func (_c *ChargeUsageBasedCreate) SetStatusDetailed(v usagebased.Status) *ChargeUsageBasedCreate { _c.mutation.SetStatusDetailed(v) @@ -437,6 +452,11 @@ func (_c *ChargeUsageBasedCreate) SetCurrentRun(v *ChargeUsageBasedRuns) *Charge return _c.SetCurrentRunID(v.ID) } +// SetCostBasis sets the "cost_basis" edge to the ChargeUsageBasedCostBasis entity. +func (_c *ChargeUsageBasedCreate) SetCostBasis(v *ChargeUsageBasedCostBasis) *ChargeUsageBasedCreate { + return _c.SetCostBasisID(v.ID) +} + // SetChargeID sets the "charge" edge to the Charge entity by ID. func (_c *ChargeUsageBasedCreate) SetChargeID(id string) *ChargeUsageBasedCreate { _c.mutation.SetChargeID(id) @@ -929,6 +949,23 @@ func (_c *ChargeUsageBasedCreate) createSpec() (*ChargeUsageBased, *sqlgraph.Cre _node.CurrentRealizationRunID = &nodes[0] _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.CostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeusagebased.CostBasisTable, + Columns: []string{chargeusagebased.CostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(chargeusagebasedcostbasis.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.CostBasisID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.ChargeIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2O, @@ -1536,6 +1573,9 @@ func (u *ChargeUsageBasedUpsertOne) UpdateNewValues() *ChargeUsageBasedUpsertOne if _, exists := u.create.mutation.FeatureKey(); exists { s.SetIgnore(chargeusagebased.FieldFeatureKey) } + if _, exists := u.create.mutation.CostBasisID(); exists { + s.SetIgnore(chargeusagebased.FieldCostBasisID) + } })) return u } @@ -2198,6 +2238,9 @@ func (u *ChargeUsageBasedUpsertBulk) UpdateNewValues() *ChargeUsageBasedUpsertBu if _, exists := b.mutation.FeatureKey(); exists { s.SetIgnore(chargeusagebased.FieldFeatureKey) } + if _, exists := b.mutation.CostBasisID(); exists { + s.SetIgnore(chargeusagebased.FieldCostBasisID) + } } })) return u diff --git a/openmeter/ent/db/chargeusagebased_query.go b/openmeter/ent/db/chargeusagebased_query.go index b8001f28e3..5fd5ae4197 100644 --- a/openmeter/ent/db/chargeusagebased_query.go +++ b/openmeter/ent/db/chargeusagebased_query.go @@ -15,6 +15,7 @@ import ( "entgo.io/ent/schema/field" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebased" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedcostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedrundetailedline" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedruns" @@ -38,6 +39,7 @@ type ChargeUsageBasedQuery struct { withRuns *ChargeUsageBasedRunsQuery withDetailedLines *ChargeUsageBasedRunDetailedLineQuery withCurrentRun *ChargeUsageBasedRunsQuery + withCostBasis *ChargeUsageBasedCostBasisQuery withCharge *ChargeQuery withIntentOverride *ChargeUsageBasedOverrideQuery withSubscription *SubscriptionQuery @@ -150,6 +152,28 @@ func (_q *ChargeUsageBasedQuery) QueryCurrentRun() *ChargeUsageBasedRunsQuery { return query } +// QueryCostBasis chains the current query on the "cost_basis" edge. +func (_q *ChargeUsageBasedQuery) QueryCostBasis() *ChargeUsageBasedCostBasisQuery { + query := (&ChargeUsageBasedCostBasisClient{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(chargeusagebased.Table, chargeusagebased.FieldID, selector), + sqlgraph.To(chargeusagebasedcostbasis.Table, chargeusagebasedcostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeusagebased.CostBasisTable, chargeusagebased.CostBasisColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryCharge chains the current query on the "charge" edge. func (_q *ChargeUsageBasedQuery) QueryCharge() *ChargeQuery { query := (&ChargeClient{config: _q.config}).Query() @@ -543,6 +567,7 @@ func (_q *ChargeUsageBasedQuery) Clone() *ChargeUsageBasedQuery { withRuns: _q.withRuns.Clone(), withDetailedLines: _q.withDetailedLines.Clone(), withCurrentRun: _q.withCurrentRun.Clone(), + withCostBasis: _q.withCostBasis.Clone(), withCharge: _q.withCharge.Clone(), withIntentOverride: _q.withIntentOverride.Clone(), withSubscription: _q.withSubscription.Clone(), @@ -591,6 +616,17 @@ func (_q *ChargeUsageBasedQuery) WithCurrentRun(opts ...func(*ChargeUsageBasedRu return _q } +// WithCostBasis tells the query-builder to eager-load the nodes that are connected to +// the "cost_basis" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeUsageBasedQuery) WithCostBasis(opts ...func(*ChargeUsageBasedCostBasisQuery)) *ChargeUsageBasedQuery { + query := (&ChargeUsageBasedCostBasisClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withCostBasis = 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 *ChargeUsageBasedQuery) WithCharge(opts ...func(*ChargeQuery)) *ChargeUsageBasedQuery { @@ -768,10 +804,11 @@ func (_q *ChargeUsageBasedQuery) sqlAll(ctx context.Context, hooks ...queryHook) var ( nodes = []*ChargeUsageBased{} _spec = _q.querySpec() - loadedTypes = [12]bool{ + loadedTypes = [13]bool{ _q.withRuns != nil, _q.withDetailedLines != nil, _q.withCurrentRun != nil, + _q.withCostBasis != nil, _q.withCharge != nil, _q.withIntentOverride != nil, _q.withSubscription != nil, @@ -826,6 +863,12 @@ func (_q *ChargeUsageBasedQuery) sqlAll(ctx context.Context, hooks ...queryHook) return nil, err } } + if query := _q.withCostBasis; query != nil { + if err := _q.loadCostBasis(ctx, query, nodes, nil, + func(n *ChargeUsageBased, e *ChargeUsageBasedCostBasis) { n.Edges.CostBasis = e }); err != nil { + return nil, err + } + } if query := _q.withCharge; query != nil { if err := _q.loadCharge(ctx, query, nodes, nil, func(n *ChargeUsageBased, e *Charge) { n.Edges.Charge = e }); err != nil { @@ -975,6 +1018,38 @@ func (_q *ChargeUsageBasedQuery) loadCurrentRun(ctx context.Context, query *Char } return nil } +func (_q *ChargeUsageBasedQuery) loadCostBasis(ctx context.Context, query *ChargeUsageBasedCostBasisQuery, nodes []*ChargeUsageBased, init func(*ChargeUsageBased), assign func(*ChargeUsageBased, *ChargeUsageBasedCostBasis)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*ChargeUsageBased) + for i := range nodes { + if nodes[i].CostBasisID == nil { + continue + } + fk := *nodes[i].CostBasisID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(chargeusagebasedcostbasis.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 "cost_basis_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} func (_q *ChargeUsageBasedQuery) loadCharge(ctx context.Context, query *ChargeQuery, nodes []*ChargeUsageBased, init func(*ChargeUsageBased), assign func(*ChargeUsageBased, *Charge)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[string]*ChargeUsageBased) @@ -1279,6 +1354,9 @@ func (_q *ChargeUsageBasedQuery) querySpec() *sqlgraph.QuerySpec { if _q.withCurrentRun != nil { _spec.Node.AddColumnOnce(chargeusagebased.FieldCurrentRealizationRunID) } + if _q.withCostBasis != nil { + _spec.Node.AddColumnOnce(chargeusagebased.FieldCostBasisID) + } if _q.withSubscription != nil { _spec.Node.AddColumnOnce(chargeusagebased.FieldSubscriptionID) } diff --git a/openmeter/ent/db/chargeusagebasedcostbasis.go b/openmeter/ent/db/chargeusagebasedcostbasis.go new file mode 100644 index 0000000000..4e9180d965 --- /dev/null +++ b/openmeter/ent/db/chargeusagebasedcostbasis.go @@ -0,0 +1,314 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/alpacahq/alpacadecimal" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedcostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/currencycostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" + "github.com/openmeterio/openmeter/pkg/currencyx" +) + +// ChargeUsageBasedCostBasis is the model entity for the ChargeUsageBasedCostBasis schema. +type ChargeUsageBasedCostBasis struct { + config `json:"-"` + // ID of the ent. + ID string `json:"id,omitempty"` + // Mode holds the value of the "mode" field. + Mode costbasis.Mode `json:"mode,omitempty"` + // FiatCurrency holds the value of the "fiat_currency" field. + FiatCurrency currencyx.FiatCode `json:"fiat_currency,omitempty"` + // CurrencyCostBasisID holds the value of the "currency_cost_basis_id" field. + CurrencyCostBasisID *string `json:"currency_cost_basis_id,omitempty"` + // ResolvedCostBasisID holds the value of the "resolved_cost_basis_id" field. + ResolvedCostBasisID *string `json:"resolved_cost_basis_id,omitempty"` + // CurrencyID holds the value of the "currency_id" field. + CurrencyID string `json:"currency_id,omitempty"` + // ManualRate holds the value of the "manual_rate" field. + ManualRate *alpacadecimal.Decimal `json:"manual_rate,omitempty"` + // ResolvedCostBasis holds the value of the "resolved_cost_basis" field. + ResolvedCostBasis *alpacadecimal.Decimal `json:"resolved_cost_basis,omitempty"` + // ResolvedAt holds the value of the "resolved_at" field. + ResolvedAt *time.Time `json:"resolved_at,omitempty"` + // Namespace holds the value of the "namespace" field. + Namespace string `json:"namespace,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"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the ChargeUsageBasedCostBasisQuery when eager-loading is set. + Edges ChargeUsageBasedCostBasisEdges `json:"edges"` + selectValues sql.SelectValues +} + +// ChargeUsageBasedCostBasisEdges holds the relations/edges for other nodes in the graph. +type ChargeUsageBasedCostBasisEdges struct { + // CurrencyCostBasis holds the value of the currency_cost_basis edge. + CurrencyCostBasis *CurrencyCostBasis `json:"currency_cost_basis,omitempty"` + // ResolvedCurrencyCostBasis holds the value of the resolved_currency_cost_basis edge. + ResolvedCurrencyCostBasis *CurrencyCostBasis `json:"resolved_currency_cost_basis,omitempty"` + // CustomCurrency holds the value of the custom_currency edge. + CustomCurrency *CustomCurrency `json:"custom_currency,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [3]bool +} + +// CurrencyCostBasisOrErr returns the CurrencyCostBasis value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChargeUsageBasedCostBasisEdges) CurrencyCostBasisOrErr() (*CurrencyCostBasis, error) { + if e.CurrencyCostBasis != nil { + return e.CurrencyCostBasis, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: currencycostbasis.Label} + } + return nil, &NotLoadedError{edge: "currency_cost_basis"} +} + +// ResolvedCurrencyCostBasisOrErr returns the ResolvedCurrencyCostBasis value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChargeUsageBasedCostBasisEdges) ResolvedCurrencyCostBasisOrErr() (*CurrencyCostBasis, error) { + if e.ResolvedCurrencyCostBasis != nil { + return e.ResolvedCurrencyCostBasis, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: currencycostbasis.Label} + } + return nil, &NotLoadedError{edge: "resolved_currency_cost_basis"} +} + +// CustomCurrencyOrErr returns the CustomCurrency value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e ChargeUsageBasedCostBasisEdges) CustomCurrencyOrErr() (*CustomCurrency, error) { + if e.CustomCurrency != nil { + return e.CustomCurrency, nil + } else if e.loadedTypes[2] { + return nil, &NotFoundError{label: customcurrency.Label} + } + return nil, &NotLoadedError{edge: "custom_currency"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*ChargeUsageBasedCostBasis) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case chargeusagebasedcostbasis.FieldManualRate, chargeusagebasedcostbasis.FieldResolvedCostBasis: + values[i] = &sql.NullScanner{S: new(alpacadecimal.Decimal)} + case chargeusagebasedcostbasis.FieldID, chargeusagebasedcostbasis.FieldMode, chargeusagebasedcostbasis.FieldFiatCurrency, chargeusagebasedcostbasis.FieldCurrencyCostBasisID, chargeusagebasedcostbasis.FieldResolvedCostBasisID, chargeusagebasedcostbasis.FieldCurrencyID, chargeusagebasedcostbasis.FieldNamespace: + values[i] = new(sql.NullString) + case chargeusagebasedcostbasis.FieldResolvedAt, chargeusagebasedcostbasis.FieldCreatedAt, chargeusagebasedcostbasis.FieldUpdatedAt, chargeusagebasedcostbasis.FieldDeletedAt: + values[i] = new(sql.NullTime) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the ChargeUsageBasedCostBasis fields. +func (_m *ChargeUsageBasedCostBasis) 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 chargeusagebasedcostbasis.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 chargeusagebasedcostbasis.FieldMode: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field mode", values[i]) + } else if value.Valid { + _m.Mode = costbasis.Mode(value.String) + } + case chargeusagebasedcostbasis.FieldFiatCurrency: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field fiat_currency", values[i]) + } else if value.Valid { + _m.FiatCurrency = currencyx.FiatCode(value.String) + } + case chargeusagebasedcostbasis.FieldCurrencyCostBasisID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field currency_cost_basis_id", values[i]) + } else if value.Valid { + _m.CurrencyCostBasisID = new(string) + *_m.CurrencyCostBasisID = value.String + } + case chargeusagebasedcostbasis.FieldResolvedCostBasisID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field resolved_cost_basis_id", values[i]) + } else if value.Valid { + _m.ResolvedCostBasisID = new(string) + *_m.ResolvedCostBasisID = value.String + } + case chargeusagebasedcostbasis.FieldCurrencyID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field currency_id", values[i]) + } else if value.Valid { + _m.CurrencyID = value.String + } + case chargeusagebasedcostbasis.FieldManualRate: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field manual_rate", values[i]) + } else if value.Valid { + _m.ManualRate = new(alpacadecimal.Decimal) + *_m.ManualRate = *value.S.(*alpacadecimal.Decimal) + } + case chargeusagebasedcostbasis.FieldResolvedCostBasis: + if value, ok := values[i].(*sql.NullScanner); !ok { + return fmt.Errorf("unexpected type %T for field resolved_cost_basis", values[i]) + } else if value.Valid { + _m.ResolvedCostBasis = new(alpacadecimal.Decimal) + *_m.ResolvedCostBasis = *value.S.(*alpacadecimal.Decimal) + } + case chargeusagebasedcostbasis.FieldResolvedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field resolved_at", values[i]) + } else if value.Valid { + _m.ResolvedAt = new(time.Time) + *_m.ResolvedAt = value.Time + } + case chargeusagebasedcostbasis.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 chargeusagebasedcostbasis.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 chargeusagebasedcostbasis.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 chargeusagebasedcostbasis.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 + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the ChargeUsageBasedCostBasis. +// This includes values selected through modifiers, order, etc. +func (_m *ChargeUsageBasedCostBasis) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryCurrencyCostBasis queries the "currency_cost_basis" edge of the ChargeUsageBasedCostBasis entity. +func (_m *ChargeUsageBasedCostBasis) QueryCurrencyCostBasis() *CurrencyCostBasisQuery { + return NewChargeUsageBasedCostBasisClient(_m.config).QueryCurrencyCostBasis(_m) +} + +// QueryResolvedCurrencyCostBasis queries the "resolved_currency_cost_basis" edge of the ChargeUsageBasedCostBasis entity. +func (_m *ChargeUsageBasedCostBasis) QueryResolvedCurrencyCostBasis() *CurrencyCostBasisQuery { + return NewChargeUsageBasedCostBasisClient(_m.config).QueryResolvedCurrencyCostBasis(_m) +} + +// QueryCustomCurrency queries the "custom_currency" edge of the ChargeUsageBasedCostBasis entity. +func (_m *ChargeUsageBasedCostBasis) QueryCustomCurrency() *CustomCurrencyQuery { + return NewChargeUsageBasedCostBasisClient(_m.config).QueryCustomCurrency(_m) +} + +// Update returns a builder for updating this ChargeUsageBasedCostBasis. +// Note that you need to call ChargeUsageBasedCostBasis.Unwrap() before calling this method if this ChargeUsageBasedCostBasis +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *ChargeUsageBasedCostBasis) Update() *ChargeUsageBasedCostBasisUpdateOne { + return NewChargeUsageBasedCostBasisClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedCostBasis) Unwrap() *ChargeUsageBasedCostBasis { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("db: ChargeUsageBasedCostBasis is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *ChargeUsageBasedCostBasis) String() string { + var builder strings.Builder + builder.WriteString("ChargeUsageBasedCostBasis(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("mode=") + builder.WriteString(fmt.Sprintf("%v", _m.Mode)) + builder.WriteString(", ") + builder.WriteString("fiat_currency=") + builder.WriteString(fmt.Sprintf("%v", _m.FiatCurrency)) + builder.WriteString(", ") + if v := _m.CurrencyCostBasisID; v != nil { + builder.WriteString("currency_cost_basis_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") + if v := _m.ResolvedCostBasisID; v != nil { + builder.WriteString("resolved_cost_basis_id=") + builder.WriteString(*v) + } + builder.WriteString(", ") + builder.WriteString("currency_id=") + builder.WriteString(_m.CurrencyID) + builder.WriteString(", ") + if v := _m.ManualRate; v != nil { + builder.WriteString("manual_rate=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + if v := _m.ResolvedCostBasis; v != nil { + builder.WriteString("resolved_cost_basis=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + if v := _m.ResolvedAt; v != nil { + builder.WriteString("resolved_at=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteString(", ") + builder.WriteString("namespace=") + builder.WriteString(_m.Namespace) + 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.WriteByte(')') + return builder.String() +} + +// ChargeUsageBasedCostBases is a parsable slice of ChargeUsageBasedCostBasis. +type ChargeUsageBasedCostBases []*ChargeUsageBasedCostBasis diff --git a/openmeter/ent/db/chargeusagebasedcostbasis/chargeusagebasedcostbasis.go b/openmeter/ent/db/chargeusagebasedcostbasis/chargeusagebasedcostbasis.go new file mode 100644 index 0000000000..0310f32b76 --- /dev/null +++ b/openmeter/ent/db/chargeusagebasedcostbasis/chargeusagebasedcostbasis.go @@ -0,0 +1,236 @@ +// Code generated by ent, DO NOT EDIT. + +package chargeusagebasedcostbasis + +import ( + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" +) + +const ( + // Label holds the string label denoting the chargeusagebasedcostbasis type in the database. + Label = "charge_usage_based_cost_basis" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldMode holds the string denoting the mode field in the database. + FieldMode = "mode" + // FieldFiatCurrency holds the string denoting the fiat_currency field in the database. + FieldFiatCurrency = "fiat_currency" + // FieldCurrencyCostBasisID holds the string denoting the currency_cost_basis_id field in the database. + FieldCurrencyCostBasisID = "currency_cost_basis_id" + // FieldResolvedCostBasisID holds the string denoting the resolved_cost_basis_id field in the database. + FieldResolvedCostBasisID = "resolved_cost_basis_id" + // FieldCurrencyID holds the string denoting the currency_id field in the database. + FieldCurrencyID = "currency_id" + // FieldManualRate holds the string denoting the manual_rate field in the database. + FieldManualRate = "manual_rate" + // FieldResolvedCostBasis holds the string denoting the resolved_cost_basis field in the database. + FieldResolvedCostBasis = "resolved_cost_basis" + // FieldResolvedAt holds the string denoting the resolved_at field in the database. + FieldResolvedAt = "resolved_at" + // FieldNamespace holds the string denoting the namespace field in the database. + FieldNamespace = "namespace" + // 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" + // EdgeCurrencyCostBasis holds the string denoting the currency_cost_basis edge name in mutations. + EdgeCurrencyCostBasis = "currency_cost_basis" + // EdgeResolvedCurrencyCostBasis holds the string denoting the resolved_currency_cost_basis edge name in mutations. + EdgeResolvedCurrencyCostBasis = "resolved_currency_cost_basis" + // EdgeCustomCurrency holds the string denoting the custom_currency edge name in mutations. + EdgeCustomCurrency = "custom_currency" + // Table holds the table name of the chargeusagebasedcostbasis in the database. + Table = "charge_usage_based_cost_bases" + // CurrencyCostBasisTable is the table that holds the currency_cost_basis relation/edge. + CurrencyCostBasisTable = "charge_usage_based_cost_bases" + // CurrencyCostBasisInverseTable is the table name for the CurrencyCostBasis entity. + // It exists in this package in order to avoid circular dependency with the "currencycostbasis" package. + CurrencyCostBasisInverseTable = "currency_cost_bases" + // CurrencyCostBasisColumn is the table column denoting the currency_cost_basis relation/edge. + CurrencyCostBasisColumn = "currency_cost_basis_id" + // ResolvedCurrencyCostBasisTable is the table that holds the resolved_currency_cost_basis relation/edge. + ResolvedCurrencyCostBasisTable = "charge_usage_based_cost_bases" + // ResolvedCurrencyCostBasisInverseTable is the table name for the CurrencyCostBasis entity. + // It exists in this package in order to avoid circular dependency with the "currencycostbasis" package. + ResolvedCurrencyCostBasisInverseTable = "currency_cost_bases" + // ResolvedCurrencyCostBasisColumn is the table column denoting the resolved_currency_cost_basis relation/edge. + ResolvedCurrencyCostBasisColumn = "resolved_cost_basis_id" + // CustomCurrencyTable is the table that holds the custom_currency relation/edge. + CustomCurrencyTable = "charge_usage_based_cost_bases" + // CustomCurrencyInverseTable is the table name for the CustomCurrency entity. + // It exists in this package in order to avoid circular dependency with the "customcurrency" package. + CustomCurrencyInverseTable = "custom_currencies" + // CustomCurrencyColumn is the table column denoting the custom_currency relation/edge. + CustomCurrencyColumn = "currency_id" +) + +// Columns holds all SQL columns for chargeusagebasedcostbasis fields. +var Columns = []string{ + FieldID, + FieldMode, + FieldFiatCurrency, + FieldCurrencyCostBasisID, + FieldResolvedCostBasisID, + FieldCurrencyID, + FieldManualRate, + FieldResolvedCostBasis, + FieldResolvedAt, + FieldNamespace, + FieldCreatedAt, + FieldUpdatedAt, + FieldDeletedAt, +} + +// 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 ( + // FiatCurrencyValidator is a validator for the "fiat_currency" field. It is called by the builders before save. + FiatCurrencyValidator func(string) error + // CurrencyIDValidator is a validator for the "currency_id" field. It is called by the builders before save. + CurrencyIDValidator func(string) error + // 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 + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() string +) + +// ModeValidator is a validator for the "mode" field enum values. It is called by the builders before save. +func ModeValidator(m costbasis.Mode) error { + switch m { + case "dynamic", "pinned", "manual": + return nil + default: + return fmt.Errorf("chargeusagebasedcostbasis: invalid enum value for mode field: %q", m) + } +} + +// OrderOption defines the ordering options for the ChargeUsageBasedCostBasis 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() +} + +// ByMode orders the results by the mode field. +func ByMode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMode, opts...).ToFunc() +} + +// ByFiatCurrency orders the results by the fiat_currency field. +func ByFiatCurrency(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldFiatCurrency, opts...).ToFunc() +} + +// ByCurrencyCostBasisID orders the results by the currency_cost_basis_id field. +func ByCurrencyCostBasisID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCurrencyCostBasisID, opts...).ToFunc() +} + +// ByResolvedCostBasisID orders the results by the resolved_cost_basis_id field. +func ByResolvedCostBasisID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldResolvedCostBasisID, opts...).ToFunc() +} + +// ByCurrencyID orders the results by the currency_id field. +func ByCurrencyID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCurrencyID, opts...).ToFunc() +} + +// ByManualRate orders the results by the manual_rate field. +func ByManualRate(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldManualRate, opts...).ToFunc() +} + +// ByResolvedCostBasis orders the results by the resolved_cost_basis field. +func ByResolvedCostBasis(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldResolvedCostBasis, opts...).ToFunc() +} + +// ByResolvedAt orders the results by the resolved_at field. +func ByResolvedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldResolvedAt, 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() +} + +// ByCurrencyCostBasisField orders the results by currency_cost_basis field. +func ByCurrencyCostBasisField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCurrencyCostBasisStep(), sql.OrderByField(field, opts...)) + } +} + +// ByResolvedCurrencyCostBasisField orders the results by resolved_currency_cost_basis field. +func ByResolvedCurrencyCostBasisField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newResolvedCurrencyCostBasisStep(), sql.OrderByField(field, opts...)) + } +} + +// ByCustomCurrencyField orders the results by custom_currency field. +func ByCustomCurrencyField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCustomCurrencyStep(), sql.OrderByField(field, opts...)) + } +} +func newCurrencyCostBasisStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CurrencyCostBasisInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CurrencyCostBasisTable, CurrencyCostBasisColumn), + ) +} +func newResolvedCurrencyCostBasisStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(ResolvedCurrencyCostBasisInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, ResolvedCurrencyCostBasisTable, ResolvedCurrencyCostBasisColumn), + ) +} +func newCustomCurrencyStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CustomCurrencyInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CustomCurrencyTable, CustomCurrencyColumn), + ) +} diff --git a/openmeter/ent/db/chargeusagebasedcostbasis/where.go b/openmeter/ent/db/chargeusagebasedcostbasis/where.go new file mode 100644 index 0000000000..51d85e7e18 --- /dev/null +++ b/openmeter/ent/db/chargeusagebasedcostbasis/where.go @@ -0,0 +1,883 @@ +// Code generated by ent, DO NOT EDIT. + +package chargeusagebasedcostbasis + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/alpacahq/alpacadecimal" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" + "github.com/openmeterio/openmeter/pkg/currencyx" +) + +// ID filters vertices based on their ID field. +func ID(id string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLTE(FieldID, id)) +} + +// IDEqualFold applies the EqualFold predicate on the ID field. +func IDEqualFold(id string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEqualFold(FieldID, id)) +} + +// IDContainsFold applies the ContainsFold predicate on the ID field. +func IDContainsFold(id string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldContainsFold(FieldID, id)) +} + +// FiatCurrency applies equality check predicate on the "fiat_currency" field. It's identical to FiatCurrencyEQ. +func FiatCurrency(v currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + vc := string(v) + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldFiatCurrency, vc)) +} + +// CurrencyCostBasisID applies equality check predicate on the "currency_cost_basis_id" field. It's identical to CurrencyCostBasisIDEQ. +func CurrencyCostBasisID(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldCurrencyCostBasisID, v)) +} + +// ResolvedCostBasisID applies equality check predicate on the "resolved_cost_basis_id" field. It's identical to ResolvedCostBasisIDEQ. +func ResolvedCostBasisID(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldResolvedCostBasisID, v)) +} + +// CurrencyID applies equality check predicate on the "currency_id" field. It's identical to CurrencyIDEQ. +func CurrencyID(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldCurrencyID, v)) +} + +// ManualRate applies equality check predicate on the "manual_rate" field. It's identical to ManualRateEQ. +func ManualRate(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldManualRate, v)) +} + +// ResolvedCostBasis applies equality check predicate on the "resolved_cost_basis" field. It's identical to ResolvedCostBasisEQ. +func ResolvedCostBasis(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldResolvedCostBasis, v)) +} + +// ResolvedAt applies equality check predicate on the "resolved_at" field. It's identical to ResolvedAtEQ. +func ResolvedAt(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldResolvedAt, v)) +} + +// Namespace applies equality check predicate on the "namespace" field. It's identical to NamespaceEQ. +func Namespace(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(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.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(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.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(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.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldDeletedAt, v)) +} + +// ModeEQ applies the EQ predicate on the "mode" field. +func ModeEQ(v costbasis.Mode) predicate.ChargeUsageBasedCostBasis { + vc := v + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldMode, vc)) +} + +// ModeNEQ applies the NEQ predicate on the "mode" field. +func ModeNEQ(v costbasis.Mode) predicate.ChargeUsageBasedCostBasis { + vc := v + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldMode, vc)) +} + +// ModeIn applies the In predicate on the "mode" field. +func ModeIn(vs ...costbasis.Mode) predicate.ChargeUsageBasedCostBasis { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldMode, v...)) +} + +// ModeNotIn applies the NotIn predicate on the "mode" field. +func ModeNotIn(vs ...costbasis.Mode) predicate.ChargeUsageBasedCostBasis { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldMode, v...)) +} + +// FiatCurrencyEQ applies the EQ predicate on the "fiat_currency" field. +func FiatCurrencyEQ(v currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + vc := string(v) + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldFiatCurrency, vc)) +} + +// FiatCurrencyNEQ applies the NEQ predicate on the "fiat_currency" field. +func FiatCurrencyNEQ(v currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + vc := string(v) + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldFiatCurrency, vc)) +} + +// FiatCurrencyIn applies the In predicate on the "fiat_currency" field. +func FiatCurrencyIn(vs ...currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + v := make([]any, len(vs)) + for i := range v { + v[i] = string(vs[i]) + } + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldFiatCurrency, v...)) +} + +// FiatCurrencyNotIn applies the NotIn predicate on the "fiat_currency" field. +func FiatCurrencyNotIn(vs ...currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + v := make([]any, len(vs)) + for i := range v { + v[i] = string(vs[i]) + } + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldFiatCurrency, v...)) +} + +// FiatCurrencyGT applies the GT predicate on the "fiat_currency" field. +func FiatCurrencyGT(v currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + vc := string(v) + return predicate.ChargeUsageBasedCostBasis(sql.FieldGT(FieldFiatCurrency, vc)) +} + +// FiatCurrencyGTE applies the GTE predicate on the "fiat_currency" field. +func FiatCurrencyGTE(v currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + vc := string(v) + return predicate.ChargeUsageBasedCostBasis(sql.FieldGTE(FieldFiatCurrency, vc)) +} + +// FiatCurrencyLT applies the LT predicate on the "fiat_currency" field. +func FiatCurrencyLT(v currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + vc := string(v) + return predicate.ChargeUsageBasedCostBasis(sql.FieldLT(FieldFiatCurrency, vc)) +} + +// FiatCurrencyLTE applies the LTE predicate on the "fiat_currency" field. +func FiatCurrencyLTE(v currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + vc := string(v) + return predicate.ChargeUsageBasedCostBasis(sql.FieldLTE(FieldFiatCurrency, vc)) +} + +// FiatCurrencyContains applies the Contains predicate on the "fiat_currency" field. +func FiatCurrencyContains(v currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + vc := string(v) + return predicate.ChargeUsageBasedCostBasis(sql.FieldContains(FieldFiatCurrency, vc)) +} + +// FiatCurrencyHasPrefix applies the HasPrefix predicate on the "fiat_currency" field. +func FiatCurrencyHasPrefix(v currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + vc := string(v) + return predicate.ChargeUsageBasedCostBasis(sql.FieldHasPrefix(FieldFiatCurrency, vc)) +} + +// FiatCurrencyHasSuffix applies the HasSuffix predicate on the "fiat_currency" field. +func FiatCurrencyHasSuffix(v currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + vc := string(v) + return predicate.ChargeUsageBasedCostBasis(sql.FieldHasSuffix(FieldFiatCurrency, vc)) +} + +// FiatCurrencyEqualFold applies the EqualFold predicate on the "fiat_currency" field. +func FiatCurrencyEqualFold(v currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + vc := string(v) + return predicate.ChargeUsageBasedCostBasis(sql.FieldEqualFold(FieldFiatCurrency, vc)) +} + +// FiatCurrencyContainsFold applies the ContainsFold predicate on the "fiat_currency" field. +func FiatCurrencyContainsFold(v currencyx.FiatCode) predicate.ChargeUsageBasedCostBasis { + vc := string(v) + return predicate.ChargeUsageBasedCostBasis(sql.FieldContainsFold(FieldFiatCurrency, vc)) +} + +// CurrencyCostBasisIDEQ applies the EQ predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDEQ(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDNEQ applies the NEQ predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDNEQ(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDIn applies the In predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDIn(vs ...string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldCurrencyCostBasisID, vs...)) +} + +// CurrencyCostBasisIDNotIn applies the NotIn predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDNotIn(vs ...string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldCurrencyCostBasisID, vs...)) +} + +// CurrencyCostBasisIDGT applies the GT predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDGT(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGT(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDGTE applies the GTE predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDGTE(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGTE(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDLT applies the LT predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDLT(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLT(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDLTE applies the LTE predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDLTE(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLTE(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDContains applies the Contains predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDContains(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldContains(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDHasPrefix applies the HasPrefix predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDHasPrefix(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldHasPrefix(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDHasSuffix applies the HasSuffix predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDHasSuffix(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldHasSuffix(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDIsNil applies the IsNil predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDIsNil() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIsNull(FieldCurrencyCostBasisID)) +} + +// CurrencyCostBasisIDNotNil applies the NotNil predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDNotNil() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotNull(FieldCurrencyCostBasisID)) +} + +// CurrencyCostBasisIDEqualFold applies the EqualFold predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDEqualFold(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEqualFold(FieldCurrencyCostBasisID, v)) +} + +// CurrencyCostBasisIDContainsFold applies the ContainsFold predicate on the "currency_cost_basis_id" field. +func CurrencyCostBasisIDContainsFold(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldContainsFold(FieldCurrencyCostBasisID, v)) +} + +// ResolvedCostBasisIDEQ applies the EQ predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDEQ(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDNEQ applies the NEQ predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDNEQ(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDIn applies the In predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDIn(vs ...string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldResolvedCostBasisID, vs...)) +} + +// ResolvedCostBasisIDNotIn applies the NotIn predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDNotIn(vs ...string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldResolvedCostBasisID, vs...)) +} + +// ResolvedCostBasisIDGT applies the GT predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDGT(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGT(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDGTE applies the GTE predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDGTE(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGTE(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDLT applies the LT predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDLT(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLT(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDLTE applies the LTE predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDLTE(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLTE(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDContains applies the Contains predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDContains(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldContains(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDHasPrefix applies the HasPrefix predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDHasPrefix(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldHasPrefix(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDHasSuffix applies the HasSuffix predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDHasSuffix(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldHasSuffix(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDIsNil applies the IsNil predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDIsNil() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIsNull(FieldResolvedCostBasisID)) +} + +// ResolvedCostBasisIDNotNil applies the NotNil predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDNotNil() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotNull(FieldResolvedCostBasisID)) +} + +// ResolvedCostBasisIDEqualFold applies the EqualFold predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDEqualFold(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEqualFold(FieldResolvedCostBasisID, v)) +} + +// ResolvedCostBasisIDContainsFold applies the ContainsFold predicate on the "resolved_cost_basis_id" field. +func ResolvedCostBasisIDContainsFold(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldContainsFold(FieldResolvedCostBasisID, v)) +} + +// CurrencyIDEQ applies the EQ predicate on the "currency_id" field. +func CurrencyIDEQ(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldCurrencyID, v)) +} + +// CurrencyIDNEQ applies the NEQ predicate on the "currency_id" field. +func CurrencyIDNEQ(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldCurrencyID, v)) +} + +// CurrencyIDIn applies the In predicate on the "currency_id" field. +func CurrencyIDIn(vs ...string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldCurrencyID, vs...)) +} + +// CurrencyIDNotIn applies the NotIn predicate on the "currency_id" field. +func CurrencyIDNotIn(vs ...string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldCurrencyID, vs...)) +} + +// CurrencyIDGT applies the GT predicate on the "currency_id" field. +func CurrencyIDGT(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGT(FieldCurrencyID, v)) +} + +// CurrencyIDGTE applies the GTE predicate on the "currency_id" field. +func CurrencyIDGTE(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGTE(FieldCurrencyID, v)) +} + +// CurrencyIDLT applies the LT predicate on the "currency_id" field. +func CurrencyIDLT(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLT(FieldCurrencyID, v)) +} + +// CurrencyIDLTE applies the LTE predicate on the "currency_id" field. +func CurrencyIDLTE(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLTE(FieldCurrencyID, v)) +} + +// CurrencyIDContains applies the Contains predicate on the "currency_id" field. +func CurrencyIDContains(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldContains(FieldCurrencyID, v)) +} + +// CurrencyIDHasPrefix applies the HasPrefix predicate on the "currency_id" field. +func CurrencyIDHasPrefix(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldHasPrefix(FieldCurrencyID, v)) +} + +// CurrencyIDHasSuffix applies the HasSuffix predicate on the "currency_id" field. +func CurrencyIDHasSuffix(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldHasSuffix(FieldCurrencyID, v)) +} + +// CurrencyIDEqualFold applies the EqualFold predicate on the "currency_id" field. +func CurrencyIDEqualFold(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEqualFold(FieldCurrencyID, v)) +} + +// CurrencyIDContainsFold applies the ContainsFold predicate on the "currency_id" field. +func CurrencyIDContainsFold(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldContainsFold(FieldCurrencyID, v)) +} + +// ManualRateEQ applies the EQ predicate on the "manual_rate" field. +func ManualRateEQ(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldManualRate, v)) +} + +// ManualRateNEQ applies the NEQ predicate on the "manual_rate" field. +func ManualRateNEQ(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldManualRate, v)) +} + +// ManualRateIn applies the In predicate on the "manual_rate" field. +func ManualRateIn(vs ...alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldManualRate, vs...)) +} + +// ManualRateNotIn applies the NotIn predicate on the "manual_rate" field. +func ManualRateNotIn(vs ...alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldManualRate, vs...)) +} + +// ManualRateGT applies the GT predicate on the "manual_rate" field. +func ManualRateGT(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGT(FieldManualRate, v)) +} + +// ManualRateGTE applies the GTE predicate on the "manual_rate" field. +func ManualRateGTE(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGTE(FieldManualRate, v)) +} + +// ManualRateLT applies the LT predicate on the "manual_rate" field. +func ManualRateLT(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLT(FieldManualRate, v)) +} + +// ManualRateLTE applies the LTE predicate on the "manual_rate" field. +func ManualRateLTE(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLTE(FieldManualRate, v)) +} + +// ManualRateIsNil applies the IsNil predicate on the "manual_rate" field. +func ManualRateIsNil() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIsNull(FieldManualRate)) +} + +// ManualRateNotNil applies the NotNil predicate on the "manual_rate" field. +func ManualRateNotNil() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotNull(FieldManualRate)) +} + +// ResolvedCostBasisEQ applies the EQ predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisEQ(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisNEQ applies the NEQ predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisNEQ(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisIn applies the In predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisIn(vs ...alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldResolvedCostBasis, vs...)) +} + +// ResolvedCostBasisNotIn applies the NotIn predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisNotIn(vs ...alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldResolvedCostBasis, vs...)) +} + +// ResolvedCostBasisGT applies the GT predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisGT(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGT(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisGTE applies the GTE predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisGTE(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGTE(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisLT applies the LT predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisLT(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLT(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisLTE applies the LTE predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisLTE(v alpacadecimal.Decimal) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLTE(FieldResolvedCostBasis, v)) +} + +// ResolvedCostBasisIsNil applies the IsNil predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisIsNil() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIsNull(FieldResolvedCostBasis)) +} + +// ResolvedCostBasisNotNil applies the NotNil predicate on the "resolved_cost_basis" field. +func ResolvedCostBasisNotNil() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotNull(FieldResolvedCostBasis)) +} + +// ResolvedAtEQ applies the EQ predicate on the "resolved_at" field. +func ResolvedAtEQ(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldResolvedAt, v)) +} + +// ResolvedAtNEQ applies the NEQ predicate on the "resolved_at" field. +func ResolvedAtNEQ(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldResolvedAt, v)) +} + +// ResolvedAtIn applies the In predicate on the "resolved_at" field. +func ResolvedAtIn(vs ...time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldResolvedAt, vs...)) +} + +// ResolvedAtNotIn applies the NotIn predicate on the "resolved_at" field. +func ResolvedAtNotIn(vs ...time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldResolvedAt, vs...)) +} + +// ResolvedAtGT applies the GT predicate on the "resolved_at" field. +func ResolvedAtGT(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGT(FieldResolvedAt, v)) +} + +// ResolvedAtGTE applies the GTE predicate on the "resolved_at" field. +func ResolvedAtGTE(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGTE(FieldResolvedAt, v)) +} + +// ResolvedAtLT applies the LT predicate on the "resolved_at" field. +func ResolvedAtLT(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLT(FieldResolvedAt, v)) +} + +// ResolvedAtLTE applies the LTE predicate on the "resolved_at" field. +func ResolvedAtLTE(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLTE(FieldResolvedAt, v)) +} + +// ResolvedAtIsNil applies the IsNil predicate on the "resolved_at" field. +func ResolvedAtIsNil() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIsNull(FieldResolvedAt)) +} + +// ResolvedAtNotNil applies the NotNil predicate on the "resolved_at" field. +func ResolvedAtNotNil() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotNull(FieldResolvedAt)) +} + +// NamespaceEQ applies the EQ predicate on the "namespace" field. +func NamespaceEQ(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldNamespace, v)) +} + +// NamespaceNEQ applies the NEQ predicate on the "namespace" field. +func NamespaceNEQ(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldNamespace, v)) +} + +// NamespaceIn applies the In predicate on the "namespace" field. +func NamespaceIn(vs ...string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldNamespace, vs...)) +} + +// NamespaceNotIn applies the NotIn predicate on the "namespace" field. +func NamespaceNotIn(vs ...string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldNamespace, vs...)) +} + +// NamespaceGT applies the GT predicate on the "namespace" field. +func NamespaceGT(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGT(FieldNamespace, v)) +} + +// NamespaceGTE applies the GTE predicate on the "namespace" field. +func NamespaceGTE(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGTE(FieldNamespace, v)) +} + +// NamespaceLT applies the LT predicate on the "namespace" field. +func NamespaceLT(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLT(FieldNamespace, v)) +} + +// NamespaceLTE applies the LTE predicate on the "namespace" field. +func NamespaceLTE(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLTE(FieldNamespace, v)) +} + +// NamespaceContains applies the Contains predicate on the "namespace" field. +func NamespaceContains(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldContains(FieldNamespace, v)) +} + +// NamespaceHasPrefix applies the HasPrefix predicate on the "namespace" field. +func NamespaceHasPrefix(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldHasPrefix(FieldNamespace, v)) +} + +// NamespaceHasSuffix applies the HasSuffix predicate on the "namespace" field. +func NamespaceHasSuffix(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldHasSuffix(FieldNamespace, v)) +} + +// NamespaceEqualFold applies the EqualFold predicate on the "namespace" field. +func NamespaceEqualFold(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEqualFold(FieldNamespace, v)) +} + +// NamespaceContainsFold applies the ContainsFold predicate on the "namespace" field. +func NamespaceContainsFold(v string) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldContainsFold(FieldNamespace, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// DeletedAtEQ applies the EQ predicate on the "deleted_at" field. +func DeletedAtEQ(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldEQ(FieldDeletedAt, v)) +} + +// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field. +func DeletedAtNEQ(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNEQ(FieldDeletedAt, v)) +} + +// DeletedAtIn applies the In predicate on the "deleted_at" field. +func DeletedAtIn(vs ...time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIn(FieldDeletedAt, vs...)) +} + +// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field. +func DeletedAtNotIn(vs ...time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotIn(FieldDeletedAt, vs...)) +} + +// DeletedAtGT applies the GT predicate on the "deleted_at" field. +func DeletedAtGT(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGT(FieldDeletedAt, v)) +} + +// DeletedAtGTE applies the GTE predicate on the "deleted_at" field. +func DeletedAtGTE(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldGTE(FieldDeletedAt, v)) +} + +// DeletedAtLT applies the LT predicate on the "deleted_at" field. +func DeletedAtLT(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLT(FieldDeletedAt, v)) +} + +// DeletedAtLTE applies the LTE predicate on the "deleted_at" field. +func DeletedAtLTE(v time.Time) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldLTE(FieldDeletedAt, v)) +} + +// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field. +func DeletedAtIsNil() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldIsNull(FieldDeletedAt)) +} + +// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field. +func DeletedAtNotNil() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.FieldNotNull(FieldDeletedAt)) +} + +// HasCurrencyCostBasis applies the HasEdge predicate on the "currency_cost_basis" edge. +func HasCurrencyCostBasis() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CurrencyCostBasisTable, CurrencyCostBasisColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasCurrencyCostBasisWith applies the HasEdge predicate on the "currency_cost_basis" edge with a given conditions (other predicates). +func HasCurrencyCostBasisWith(preds ...predicate.CurrencyCostBasis) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(func(s *sql.Selector) { + step := newCurrencyCostBasisStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasResolvedCurrencyCostBasis applies the HasEdge predicate on the "resolved_currency_cost_basis" edge. +func HasResolvedCurrencyCostBasis() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, ResolvedCurrencyCostBasisTable, ResolvedCurrencyCostBasisColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasResolvedCurrencyCostBasisWith applies the HasEdge predicate on the "resolved_currency_cost_basis" edge with a given conditions (other predicates). +func HasResolvedCurrencyCostBasisWith(preds ...predicate.CurrencyCostBasis) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(func(s *sql.Selector) { + step := newResolvedCurrencyCostBasisStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasCustomCurrency applies the HasEdge predicate on the "custom_currency" edge. +func HasCustomCurrency() predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, CustomCurrencyTable, CustomCurrencyColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasCustomCurrencyWith applies the HasEdge predicate on the "custom_currency" edge with a given conditions (other predicates). +func HasCustomCurrencyWith(preds ...predicate.CustomCurrency) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(func(s *sql.Selector) { + step := newCustomCurrencyStep() + 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.ChargeUsageBasedCostBasis) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.ChargeUsageBasedCostBasis) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.ChargeUsageBasedCostBasis) predicate.ChargeUsageBasedCostBasis { + return predicate.ChargeUsageBasedCostBasis(sql.NotPredicates(p)) +} diff --git a/openmeter/ent/db/chargeusagebasedcostbasis_create.go b/openmeter/ent/db/chargeusagebasedcostbasis_create.go new file mode 100644 index 0000000000..7fc17a0b81 --- /dev/null +++ b/openmeter/ent/db/chargeusagebasedcostbasis_create.go @@ -0,0 +1,1143 @@ +// 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/alpacahq/alpacadecimal" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedcostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/currencycostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" + "github.com/openmeterio/openmeter/pkg/currencyx" +) + +// ChargeUsageBasedCostBasisCreate is the builder for creating a ChargeUsageBasedCostBasis entity. +type ChargeUsageBasedCostBasisCreate struct { + config + mutation *ChargeUsageBasedCostBasisMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetMode sets the "mode" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetMode(v costbasis.Mode) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetMode(v) + return _c +} + +// SetFiatCurrency sets the "fiat_currency" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetFiatCurrency(v currencyx.FiatCode) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetFiatCurrency(v) + return _c +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetCurrencyCostBasisID(v string) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetCurrencyCostBasisID(v) + return _c +} + +// SetNillableCurrencyCostBasisID sets the "currency_cost_basis_id" field if the given value is not nil. +func (_c *ChargeUsageBasedCostBasisCreate) SetNillableCurrencyCostBasisID(v *string) *ChargeUsageBasedCostBasisCreate { + if v != nil { + _c.SetCurrencyCostBasisID(*v) + } + return _c +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetResolvedCostBasisID(v string) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetResolvedCostBasisID(v) + return _c +} + +// SetNillableResolvedCostBasisID sets the "resolved_cost_basis_id" field if the given value is not nil. +func (_c *ChargeUsageBasedCostBasisCreate) SetNillableResolvedCostBasisID(v *string) *ChargeUsageBasedCostBasisCreate { + if v != nil { + _c.SetResolvedCostBasisID(*v) + } + return _c +} + +// SetCurrencyID sets the "currency_id" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetCurrencyID(v string) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetCurrencyID(v) + return _c +} + +// SetManualRate sets the "manual_rate" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetManualRate(v alpacadecimal.Decimal) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetManualRate(v) + return _c +} + +// SetNillableManualRate sets the "manual_rate" field if the given value is not nil. +func (_c *ChargeUsageBasedCostBasisCreate) SetNillableManualRate(v *alpacadecimal.Decimal) *ChargeUsageBasedCostBasisCreate { + if v != nil { + _c.SetManualRate(*v) + } + return _c +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetResolvedCostBasis(v) + return _c +} + +// SetNillableResolvedCostBasis sets the "resolved_cost_basis" field if the given value is not nil. +func (_c *ChargeUsageBasedCostBasisCreate) SetNillableResolvedCostBasis(v *alpacadecimal.Decimal) *ChargeUsageBasedCostBasisCreate { + if v != nil { + _c.SetResolvedCostBasis(*v) + } + return _c +} + +// SetResolvedAt sets the "resolved_at" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetResolvedAt(v time.Time) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetResolvedAt(v) + return _c +} + +// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil. +func (_c *ChargeUsageBasedCostBasisCreate) SetNillableResolvedAt(v *time.Time) *ChargeUsageBasedCostBasisCreate { + if v != nil { + _c.SetResolvedAt(*v) + } + return _c +} + +// SetNamespace sets the "namespace" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetNamespace(v string) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetNamespace(v) + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetCreatedAt(v time.Time) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *ChargeUsageBasedCostBasisCreate) SetNillableCreatedAt(v *time.Time) *ChargeUsageBasedCostBasisCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetUpdatedAt(v time.Time) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *ChargeUsageBasedCostBasisCreate) SetNillableUpdatedAt(v *time.Time) *ChargeUsageBasedCostBasisCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetDeletedAt sets the "deleted_at" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetDeletedAt(v time.Time) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetDeletedAt(v) + return _c +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_c *ChargeUsageBasedCostBasisCreate) SetNillableDeletedAt(v *time.Time) *ChargeUsageBasedCostBasisCreate { + if v != nil { + _c.SetDeletedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *ChargeUsageBasedCostBasisCreate) SetID(v string) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetID(v) + return _c +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (_c *ChargeUsageBasedCostBasisCreate) SetNillableID(v *string) *ChargeUsageBasedCostBasisCreate { + if v != nil { + _c.SetID(*v) + } + return _c +} + +// SetCurrencyCostBasis sets the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_c *ChargeUsageBasedCostBasisCreate) SetCurrencyCostBasis(v *CurrencyCostBasis) *ChargeUsageBasedCostBasisCreate { + return _c.SetCurrencyCostBasisID(v.ID) +} + +// SetResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID. +func (_c *ChargeUsageBasedCostBasisCreate) SetResolvedCurrencyCostBasisID(id string) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetResolvedCurrencyCostBasisID(id) + return _c +} + +// SetNillableResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID if the given value is not nil. +func (_c *ChargeUsageBasedCostBasisCreate) SetNillableResolvedCurrencyCostBasisID(id *string) *ChargeUsageBasedCostBasisCreate { + if id != nil { + _c = _c.SetResolvedCurrencyCostBasisID(*id) + } + return _c +} + +// SetResolvedCurrencyCostBasis sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_c *ChargeUsageBasedCostBasisCreate) SetResolvedCurrencyCostBasis(v *CurrencyCostBasis) *ChargeUsageBasedCostBasisCreate { + return _c.SetResolvedCurrencyCostBasisID(v.ID) +} + +// SetCustomCurrencyID sets the "custom_currency" edge to the CustomCurrency entity by ID. +func (_c *ChargeUsageBasedCostBasisCreate) SetCustomCurrencyID(id string) *ChargeUsageBasedCostBasisCreate { + _c.mutation.SetCustomCurrencyID(id) + return _c +} + +// SetCustomCurrency sets the "custom_currency" edge to the CustomCurrency entity. +func (_c *ChargeUsageBasedCostBasisCreate) SetCustomCurrency(v *CustomCurrency) *ChargeUsageBasedCostBasisCreate { + return _c.SetCustomCurrencyID(v.ID) +} + +// Mutation returns the ChargeUsageBasedCostBasisMutation object of the builder. +func (_c *ChargeUsageBasedCostBasisCreate) Mutation() *ChargeUsageBasedCostBasisMutation { + return _c.mutation +} + +// Save creates the ChargeUsageBasedCostBasis in the database. +func (_c *ChargeUsageBasedCostBasisCreate) Save(ctx context.Context) (*ChargeUsageBasedCostBasis, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *ChargeUsageBasedCostBasisCreate) SaveX(ctx context.Context) *ChargeUsageBasedCostBasis { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ChargeUsageBasedCostBasisCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ChargeUsageBasedCostBasisCreate) 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 *ChargeUsageBasedCostBasisCreate) defaults() { + if _, ok := _c.mutation.CreatedAt(); !ok { + v := chargeusagebasedcostbasis.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := chargeusagebasedcostbasis.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } + if _, ok := _c.mutation.ID(); !ok { + v := chargeusagebasedcostbasis.DefaultID() + _c.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *ChargeUsageBasedCostBasisCreate) check() error { + if _, ok := _c.mutation.Mode(); !ok { + return &ValidationError{Name: "mode", err: errors.New(`db: missing required field "ChargeUsageBasedCostBasis.mode"`)} + } + if v, ok := _c.mutation.Mode(); ok { + if err := chargeusagebasedcostbasis.ModeValidator(v); err != nil { + return &ValidationError{Name: "mode", err: fmt.Errorf(`db: validator failed for field "ChargeUsageBasedCostBasis.mode": %w`, err)} + } + } + if _, ok := _c.mutation.FiatCurrency(); !ok { + return &ValidationError{Name: "fiat_currency", err: errors.New(`db: missing required field "ChargeUsageBasedCostBasis.fiat_currency"`)} + } + if v, ok := _c.mutation.FiatCurrency(); ok { + if err := chargeusagebasedcostbasis.FiatCurrencyValidator(string(v)); err != nil { + return &ValidationError{Name: "fiat_currency", err: fmt.Errorf(`db: validator failed for field "ChargeUsageBasedCostBasis.fiat_currency": %w`, err)} + } + } + if _, ok := _c.mutation.CurrencyID(); !ok { + return &ValidationError{Name: "currency_id", err: errors.New(`db: missing required field "ChargeUsageBasedCostBasis.currency_id"`)} + } + if v, ok := _c.mutation.CurrencyID(); ok { + if err := chargeusagebasedcostbasis.CurrencyIDValidator(v); err != nil { + return &ValidationError{Name: "currency_id", err: fmt.Errorf(`db: validator failed for field "ChargeUsageBasedCostBasis.currency_id": %w`, err)} + } + } + if _, ok := _c.mutation.Namespace(); !ok { + return &ValidationError{Name: "namespace", err: errors.New(`db: missing required field "ChargeUsageBasedCostBasis.namespace"`)} + } + if v, ok := _c.mutation.Namespace(); ok { + if err := chargeusagebasedcostbasis.NamespaceValidator(v); err != nil { + return &ValidationError{Name: "namespace", err: fmt.Errorf(`db: validator failed for field "ChargeUsageBasedCostBasis.namespace": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "ChargeUsageBasedCostBasis.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "ChargeUsageBasedCostBasis.updated_at"`)} + } + if len(_c.mutation.CustomCurrencyIDs()) == 0 { + return &ValidationError{Name: "custom_currency", err: errors.New(`db: missing required edge "ChargeUsageBasedCostBasis.custom_currency"`)} + } + return nil +} + +func (_c *ChargeUsageBasedCostBasisCreate) sqlSave(ctx context.Context) (*ChargeUsageBasedCostBasis, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + 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 ChargeUsageBasedCostBasis.ID type: %T", _spec.ID.Value) + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *ChargeUsageBasedCostBasisCreate) createSpec() (*ChargeUsageBasedCostBasis, *sqlgraph.CreateSpec) { + var ( + _node = &ChargeUsageBasedCostBasis{config: _c.config} + _spec = sqlgraph.NewCreateSpec(chargeusagebasedcostbasis.Table, sqlgraph.NewFieldSpec(chargeusagebasedcostbasis.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.Mode(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldMode, field.TypeEnum, value) + _node.Mode = value + } + if value, ok := _c.mutation.FiatCurrency(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldFiatCurrency, field.TypeString, value) + _node.FiatCurrency = value + } + if value, ok := _c.mutation.ManualRate(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldManualRate, field.TypeOther, value) + _node.ManualRate = &value + } + if value, ok := _c.mutation.ResolvedCostBasis(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldResolvedCostBasis, field.TypeOther, value) + _node.ResolvedCostBasis = &value + } + if value, ok := _c.mutation.ResolvedAt(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldResolvedAt, field.TypeTime, value) + _node.ResolvedAt = &value + } + if value, ok := _c.mutation.Namespace(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldNamespace, field.TypeString, value) + _node.Namespace = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := _c.mutation.DeletedAt(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldDeletedAt, field.TypeTime, value) + _node.DeletedAt = &value + } + if nodes := _c.mutation.CurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeusagebasedcostbasis.CurrencyCostBasisTable, + Columns: []string{chargeusagebasedcostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.CurrencyCostBasisID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.ResolvedCurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeusagebasedcostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargeusagebasedcostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.ResolvedCostBasisID = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := _c.mutation.CustomCurrencyIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeusagebasedcostbasis.CustomCurrencyTable, + Columns: []string{chargeusagebasedcostbasis.CustomCurrencyColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(customcurrency.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.CurrencyID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.ChargeUsageBasedCostBasis.Create(). +// SetMode(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.ChargeUsageBasedCostBasisUpsert) { +// SetMode(v+v). +// }). +// Exec(ctx) +func (_c *ChargeUsageBasedCostBasisCreate) OnConflict(opts ...sql.ConflictOption) *ChargeUsageBasedCostBasisUpsertOne { + _c.conflict = opts + return &ChargeUsageBasedCostBasisUpsertOne{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.ChargeUsageBasedCostBasis.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *ChargeUsageBasedCostBasisCreate) OnConflictColumns(columns ...string) *ChargeUsageBasedCostBasisUpsertOne { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &ChargeUsageBasedCostBasisUpsertOne{ + create: _c, + } +} + +type ( + // ChargeUsageBasedCostBasisUpsertOne is the builder for "upsert"-ing + // one ChargeUsageBasedCostBasis node. + ChargeUsageBasedCostBasisUpsertOne struct { + create *ChargeUsageBasedCostBasisCreate + } + + // ChargeUsageBasedCostBasisUpsert is the "OnConflict" setter. + ChargeUsageBasedCostBasisUpsert struct { + *sql.UpdateSet + } +) + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (u *ChargeUsageBasedCostBasisUpsert) SetCurrencyCostBasisID(v string) *ChargeUsageBasedCostBasisUpsert { + u.Set(chargeusagebasedcostbasis.FieldCurrencyCostBasisID, v) + return u +} + +// UpdateCurrencyCostBasisID sets the "currency_cost_basis_id" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsert) UpdateCurrencyCostBasisID() *ChargeUsageBasedCostBasisUpsert { + u.SetExcluded(chargeusagebasedcostbasis.FieldCurrencyCostBasisID) + return u +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (u *ChargeUsageBasedCostBasisUpsert) ClearCurrencyCostBasisID() *ChargeUsageBasedCostBasisUpsert { + u.SetNull(chargeusagebasedcostbasis.FieldCurrencyCostBasisID) + return u +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (u *ChargeUsageBasedCostBasisUpsert) SetResolvedCostBasisID(v string) *ChargeUsageBasedCostBasisUpsert { + u.Set(chargeusagebasedcostbasis.FieldResolvedCostBasisID, v) + return u +} + +// UpdateResolvedCostBasisID sets the "resolved_cost_basis_id" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsert) UpdateResolvedCostBasisID() *ChargeUsageBasedCostBasisUpsert { + u.SetExcluded(chargeusagebasedcostbasis.FieldResolvedCostBasisID) + return u +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (u *ChargeUsageBasedCostBasisUpsert) ClearResolvedCostBasisID() *ChargeUsageBasedCostBasisUpsert { + u.SetNull(chargeusagebasedcostbasis.FieldResolvedCostBasisID) + return u +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (u *ChargeUsageBasedCostBasisUpsert) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeUsageBasedCostBasisUpsert { + u.Set(chargeusagebasedcostbasis.FieldResolvedCostBasis, v) + return u +} + +// UpdateResolvedCostBasis sets the "resolved_cost_basis" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsert) UpdateResolvedCostBasis() *ChargeUsageBasedCostBasisUpsert { + u.SetExcluded(chargeusagebasedcostbasis.FieldResolvedCostBasis) + return u +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (u *ChargeUsageBasedCostBasisUpsert) ClearResolvedCostBasis() *ChargeUsageBasedCostBasisUpsert { + u.SetNull(chargeusagebasedcostbasis.FieldResolvedCostBasis) + return u +} + +// SetResolvedAt sets the "resolved_at" field. +func (u *ChargeUsageBasedCostBasisUpsert) SetResolvedAt(v time.Time) *ChargeUsageBasedCostBasisUpsert { + u.Set(chargeusagebasedcostbasis.FieldResolvedAt, v) + return u +} + +// UpdateResolvedAt sets the "resolved_at" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsert) UpdateResolvedAt() *ChargeUsageBasedCostBasisUpsert { + u.SetExcluded(chargeusagebasedcostbasis.FieldResolvedAt) + return u +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (u *ChargeUsageBasedCostBasisUpsert) ClearResolvedAt() *ChargeUsageBasedCostBasisUpsert { + u.SetNull(chargeusagebasedcostbasis.FieldResolvedAt) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *ChargeUsageBasedCostBasisUpsert) SetUpdatedAt(v time.Time) *ChargeUsageBasedCostBasisUpsert { + u.Set(chargeusagebasedcostbasis.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsert) UpdateUpdatedAt() *ChargeUsageBasedCostBasisUpsert { + u.SetExcluded(chargeusagebasedcostbasis.FieldUpdatedAt) + return u +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *ChargeUsageBasedCostBasisUpsert) SetDeletedAt(v time.Time) *ChargeUsageBasedCostBasisUpsert { + u.Set(chargeusagebasedcostbasis.FieldDeletedAt, v) + return u +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsert) UpdateDeletedAt() *ChargeUsageBasedCostBasisUpsert { + u.SetExcluded(chargeusagebasedcostbasis.FieldDeletedAt) + return u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *ChargeUsageBasedCostBasisUpsert) ClearDeletedAt() *ChargeUsageBasedCostBasisUpsert { + u.SetNull(chargeusagebasedcostbasis.FieldDeletedAt) + 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.ChargeUsageBasedCostBasis.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(chargeusagebasedcostbasis.FieldID) +// }), +// ). +// Exec(ctx) +func (u *ChargeUsageBasedCostBasisUpsertOne) UpdateNewValues() *ChargeUsageBasedCostBasisUpsertOne { + 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(chargeusagebasedcostbasis.FieldID) + } + if _, exists := u.create.mutation.Mode(); exists { + s.SetIgnore(chargeusagebasedcostbasis.FieldMode) + } + if _, exists := u.create.mutation.FiatCurrency(); exists { + s.SetIgnore(chargeusagebasedcostbasis.FieldFiatCurrency) + } + if _, exists := u.create.mutation.CurrencyID(); exists { + s.SetIgnore(chargeusagebasedcostbasis.FieldCurrencyID) + } + if _, exists := u.create.mutation.ManualRate(); exists { + s.SetIgnore(chargeusagebasedcostbasis.FieldManualRate) + } + if _, exists := u.create.mutation.Namespace(); exists { + s.SetIgnore(chargeusagebasedcostbasis.FieldNamespace) + } + if _, exists := u.create.mutation.CreatedAt(); exists { + s.SetIgnore(chargeusagebasedcostbasis.FieldCreatedAt) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.ChargeUsageBasedCostBasis.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *ChargeUsageBasedCostBasisUpsertOne) Ignore() *ChargeUsageBasedCostBasisUpsertOne { + 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 *ChargeUsageBasedCostBasisUpsertOne) DoNothing() *ChargeUsageBasedCostBasisUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the ChargeUsageBasedCostBasisCreate.OnConflict +// documentation for more info. +func (u *ChargeUsageBasedCostBasisUpsertOne) Update(set func(*ChargeUsageBasedCostBasisUpsert)) *ChargeUsageBasedCostBasisUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&ChargeUsageBasedCostBasisUpsert{UpdateSet: update}) + })) + return u +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (u *ChargeUsageBasedCostBasisUpsertOne) SetCurrencyCostBasisID(v string) *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.SetCurrencyCostBasisID(v) + }) +} + +// UpdateCurrencyCostBasisID sets the "currency_cost_basis_id" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsertOne) UpdateCurrencyCostBasisID() *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.UpdateCurrencyCostBasisID() + }) +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (u *ChargeUsageBasedCostBasisUpsertOne) ClearCurrencyCostBasisID() *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.ClearCurrencyCostBasisID() + }) +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (u *ChargeUsageBasedCostBasisUpsertOne) SetResolvedCostBasisID(v string) *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.SetResolvedCostBasisID(v) + }) +} + +// UpdateResolvedCostBasisID sets the "resolved_cost_basis_id" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsertOne) UpdateResolvedCostBasisID() *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.UpdateResolvedCostBasisID() + }) +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (u *ChargeUsageBasedCostBasisUpsertOne) ClearResolvedCostBasisID() *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.ClearResolvedCostBasisID() + }) +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (u *ChargeUsageBasedCostBasisUpsertOne) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.SetResolvedCostBasis(v) + }) +} + +// UpdateResolvedCostBasis sets the "resolved_cost_basis" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsertOne) UpdateResolvedCostBasis() *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.UpdateResolvedCostBasis() + }) +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (u *ChargeUsageBasedCostBasisUpsertOne) ClearResolvedCostBasis() *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.ClearResolvedCostBasis() + }) +} + +// SetResolvedAt sets the "resolved_at" field. +func (u *ChargeUsageBasedCostBasisUpsertOne) SetResolvedAt(v time.Time) *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.SetResolvedAt(v) + }) +} + +// UpdateResolvedAt sets the "resolved_at" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsertOne) UpdateResolvedAt() *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.UpdateResolvedAt() + }) +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (u *ChargeUsageBasedCostBasisUpsertOne) ClearResolvedAt() *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.ClearResolvedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *ChargeUsageBasedCostBasisUpsertOne) SetUpdatedAt(v time.Time) *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsertOne) UpdateUpdatedAt() *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *ChargeUsageBasedCostBasisUpsertOne) SetDeletedAt(v time.Time) *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.SetDeletedAt(v) + }) +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsertOne) UpdateDeletedAt() *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.UpdateDeletedAt() + }) +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *ChargeUsageBasedCostBasisUpsertOne) ClearDeletedAt() *ChargeUsageBasedCostBasisUpsertOne { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.ClearDeletedAt() + }) +} + +// Exec executes the query. +func (u *ChargeUsageBasedCostBasisUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for ChargeUsageBasedCostBasisCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *ChargeUsageBasedCostBasisUpsertOne) 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 *ChargeUsageBasedCostBasisUpsertOne) 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: ChargeUsageBasedCostBasisUpsertOne.ID is not supported by MySQL driver. Use ChargeUsageBasedCostBasisUpsertOne.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 *ChargeUsageBasedCostBasisUpsertOne) IDX(ctx context.Context) string { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// ChargeUsageBasedCostBasisCreateBulk is the builder for creating many ChargeUsageBasedCostBasis entities in bulk. +type ChargeUsageBasedCostBasisCreateBulk struct { + config + err error + builders []*ChargeUsageBasedCostBasisCreate + conflict []sql.ConflictOption +} + +// Save creates the ChargeUsageBasedCostBasis entities in the database. +func (_c *ChargeUsageBasedCostBasisCreateBulk) Save(ctx context.Context) ([]*ChargeUsageBasedCostBasis, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*ChargeUsageBasedCostBasis, 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.(*ChargeUsageBasedCostBasisMutation) + 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] = builder.createSpec() + 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 *ChargeUsageBasedCostBasisCreateBulk) SaveX(ctx context.Context) []*ChargeUsageBasedCostBasis { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ChargeUsageBasedCostBasisCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ChargeUsageBasedCostBasisCreateBulk) 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.ChargeUsageBasedCostBasis.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.ChargeUsageBasedCostBasisUpsert) { +// SetMode(v+v). +// }). +// Exec(ctx) +func (_c *ChargeUsageBasedCostBasisCreateBulk) OnConflict(opts ...sql.ConflictOption) *ChargeUsageBasedCostBasisUpsertBulk { + _c.conflict = opts + return &ChargeUsageBasedCostBasisUpsertBulk{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.ChargeUsageBasedCostBasis.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *ChargeUsageBasedCostBasisCreateBulk) OnConflictColumns(columns ...string) *ChargeUsageBasedCostBasisUpsertBulk { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &ChargeUsageBasedCostBasisUpsertBulk{ + create: _c, + } +} + +// ChargeUsageBasedCostBasisUpsertBulk is the builder for "upsert"-ing +// a bulk of ChargeUsageBasedCostBasis nodes. +type ChargeUsageBasedCostBasisUpsertBulk struct { + create *ChargeUsageBasedCostBasisCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.ChargeUsageBasedCostBasis.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(chargeusagebasedcostbasis.FieldID) +// }), +// ). +// Exec(ctx) +func (u *ChargeUsageBasedCostBasisUpsertBulk) UpdateNewValues() *ChargeUsageBasedCostBasisUpsertBulk { + 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(chargeusagebasedcostbasis.FieldID) + } + if _, exists := b.mutation.Mode(); exists { + s.SetIgnore(chargeusagebasedcostbasis.FieldMode) + } + if _, exists := b.mutation.FiatCurrency(); exists { + s.SetIgnore(chargeusagebasedcostbasis.FieldFiatCurrency) + } + if _, exists := b.mutation.CurrencyID(); exists { + s.SetIgnore(chargeusagebasedcostbasis.FieldCurrencyID) + } + if _, exists := b.mutation.ManualRate(); exists { + s.SetIgnore(chargeusagebasedcostbasis.FieldManualRate) + } + if _, exists := b.mutation.Namespace(); exists { + s.SetIgnore(chargeusagebasedcostbasis.FieldNamespace) + } + if _, exists := b.mutation.CreatedAt(); exists { + s.SetIgnore(chargeusagebasedcostbasis.FieldCreatedAt) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.ChargeUsageBasedCostBasis.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *ChargeUsageBasedCostBasisUpsertBulk) Ignore() *ChargeUsageBasedCostBasisUpsertBulk { + 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 *ChargeUsageBasedCostBasisUpsertBulk) DoNothing() *ChargeUsageBasedCostBasisUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the ChargeUsageBasedCostBasisCreateBulk.OnConflict +// documentation for more info. +func (u *ChargeUsageBasedCostBasisUpsertBulk) Update(set func(*ChargeUsageBasedCostBasisUpsert)) *ChargeUsageBasedCostBasisUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&ChargeUsageBasedCostBasisUpsert{UpdateSet: update}) + })) + return u +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (u *ChargeUsageBasedCostBasisUpsertBulk) SetCurrencyCostBasisID(v string) *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.SetCurrencyCostBasisID(v) + }) +} + +// UpdateCurrencyCostBasisID sets the "currency_cost_basis_id" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsertBulk) UpdateCurrencyCostBasisID() *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.UpdateCurrencyCostBasisID() + }) +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (u *ChargeUsageBasedCostBasisUpsertBulk) ClearCurrencyCostBasisID() *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.ClearCurrencyCostBasisID() + }) +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (u *ChargeUsageBasedCostBasisUpsertBulk) SetResolvedCostBasisID(v string) *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.SetResolvedCostBasisID(v) + }) +} + +// UpdateResolvedCostBasisID sets the "resolved_cost_basis_id" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsertBulk) UpdateResolvedCostBasisID() *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.UpdateResolvedCostBasisID() + }) +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (u *ChargeUsageBasedCostBasisUpsertBulk) ClearResolvedCostBasisID() *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.ClearResolvedCostBasisID() + }) +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (u *ChargeUsageBasedCostBasisUpsertBulk) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.SetResolvedCostBasis(v) + }) +} + +// UpdateResolvedCostBasis sets the "resolved_cost_basis" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsertBulk) UpdateResolvedCostBasis() *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.UpdateResolvedCostBasis() + }) +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (u *ChargeUsageBasedCostBasisUpsertBulk) ClearResolvedCostBasis() *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.ClearResolvedCostBasis() + }) +} + +// SetResolvedAt sets the "resolved_at" field. +func (u *ChargeUsageBasedCostBasisUpsertBulk) SetResolvedAt(v time.Time) *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.SetResolvedAt(v) + }) +} + +// UpdateResolvedAt sets the "resolved_at" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsertBulk) UpdateResolvedAt() *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.UpdateResolvedAt() + }) +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (u *ChargeUsageBasedCostBasisUpsertBulk) ClearResolvedAt() *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.ClearResolvedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *ChargeUsageBasedCostBasisUpsertBulk) SetUpdatedAt(v time.Time) *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsertBulk) UpdateUpdatedAt() *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetDeletedAt sets the "deleted_at" field. +func (u *ChargeUsageBasedCostBasisUpsertBulk) SetDeletedAt(v time.Time) *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.SetDeletedAt(v) + }) +} + +// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create. +func (u *ChargeUsageBasedCostBasisUpsertBulk) UpdateDeletedAt() *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.UpdateDeletedAt() + }) +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (u *ChargeUsageBasedCostBasisUpsertBulk) ClearDeletedAt() *ChargeUsageBasedCostBasisUpsertBulk { + return u.Update(func(s *ChargeUsageBasedCostBasisUpsert) { + s.ClearDeletedAt() + }) +} + +// Exec executes the query. +func (u *ChargeUsageBasedCostBasisUpsertBulk) 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 ChargeUsageBasedCostBasisCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for ChargeUsageBasedCostBasisCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *ChargeUsageBasedCostBasisUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/openmeter/ent/db/chargeusagebasedcostbasis_delete.go b/openmeter/ent/db/chargeusagebasedcostbasis_delete.go new file mode 100644 index 0000000000..010d3a8d57 --- /dev/null +++ b/openmeter/ent/db/chargeusagebasedcostbasis_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/chargeusagebasedcostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" +) + +// ChargeUsageBasedCostBasisDelete is the builder for deleting a ChargeUsageBasedCostBasis entity. +type ChargeUsageBasedCostBasisDelete struct { + config + hooks []Hook + mutation *ChargeUsageBasedCostBasisMutation +} + +// Where appends a list predicates to the ChargeUsageBasedCostBasisDelete builder. +func (_d *ChargeUsageBasedCostBasisDelete) Where(ps ...predicate.ChargeUsageBasedCostBasis) *ChargeUsageBasedCostBasisDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *ChargeUsageBasedCostBasisDelete) 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 *ChargeUsageBasedCostBasisDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *ChargeUsageBasedCostBasisDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(chargeusagebasedcostbasis.Table, sqlgraph.NewFieldSpec(chargeusagebasedcostbasis.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 +} + +// ChargeUsageBasedCostBasisDeleteOne is the builder for deleting a single ChargeUsageBasedCostBasis entity. +type ChargeUsageBasedCostBasisDeleteOne struct { + _d *ChargeUsageBasedCostBasisDelete +} + +// Where appends a list predicates to the ChargeUsageBasedCostBasisDelete builder. +func (_d *ChargeUsageBasedCostBasisDeleteOne) Where(ps ...predicate.ChargeUsageBasedCostBasis) *ChargeUsageBasedCostBasisDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *ChargeUsageBasedCostBasisDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{chargeusagebasedcostbasis.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ChargeUsageBasedCostBasisDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/openmeter/ent/db/chargeusagebasedcostbasis_query.go b/openmeter/ent/db/chargeusagebasedcostbasis_query.go new file mode 100644 index 0000000000..6d85d6d3c2 --- /dev/null +++ b/openmeter/ent/db/chargeusagebasedcostbasis_query.go @@ -0,0 +1,798 @@ +// 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/chargeusagebasedcostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/currencycostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/customcurrency" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" +) + +// ChargeUsageBasedCostBasisQuery is the builder for querying ChargeUsageBasedCostBasis entities. +type ChargeUsageBasedCostBasisQuery struct { + config + ctx *QueryContext + order []chargeusagebasedcostbasis.OrderOption + inters []Interceptor + predicates []predicate.ChargeUsageBasedCostBasis + withCurrencyCostBasis *CurrencyCostBasisQuery + withResolvedCurrencyCostBasis *CurrencyCostBasisQuery + withCustomCurrency *CustomCurrencyQuery + 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 ChargeUsageBasedCostBasisQuery builder. +func (_q *ChargeUsageBasedCostBasisQuery) Where(ps ...predicate.ChargeUsageBasedCostBasis) *ChargeUsageBasedCostBasisQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *ChargeUsageBasedCostBasisQuery) Limit(limit int) *ChargeUsageBasedCostBasisQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *ChargeUsageBasedCostBasisQuery) Offset(offset int) *ChargeUsageBasedCostBasisQuery { + _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 *ChargeUsageBasedCostBasisQuery) Unique(unique bool) *ChargeUsageBasedCostBasisQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *ChargeUsageBasedCostBasisQuery) Order(o ...chargeusagebasedcostbasis.OrderOption) *ChargeUsageBasedCostBasisQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryCurrencyCostBasis chains the current query on the "currency_cost_basis" edge. +func (_q *ChargeUsageBasedCostBasisQuery) QueryCurrencyCostBasis() *CurrencyCostBasisQuery { + query := (&CurrencyCostBasisClient{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(chargeusagebasedcostbasis.Table, chargeusagebasedcostbasis.FieldID, selector), + sqlgraph.To(currencycostbasis.Table, currencycostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeusagebasedcostbasis.CurrencyCostBasisTable, chargeusagebasedcostbasis.CurrencyCostBasisColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryResolvedCurrencyCostBasis chains the current query on the "resolved_currency_cost_basis" edge. +func (_q *ChargeUsageBasedCostBasisQuery) QueryResolvedCurrencyCostBasis() *CurrencyCostBasisQuery { + query := (&CurrencyCostBasisClient{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(chargeusagebasedcostbasis.Table, chargeusagebasedcostbasis.FieldID, selector), + sqlgraph.To(currencycostbasis.Table, currencycostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeusagebasedcostbasis.ResolvedCurrencyCostBasisTable, chargeusagebasedcostbasis.ResolvedCurrencyCostBasisColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryCustomCurrency chains the current query on the "custom_currency" edge. +func (_q *ChargeUsageBasedCostBasisQuery) QueryCustomCurrency() *CustomCurrencyQuery { + query := (&CustomCurrencyClient{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(chargeusagebasedcostbasis.Table, chargeusagebasedcostbasis.FieldID, selector), + sqlgraph.To(customcurrency.Table, customcurrency.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeusagebasedcostbasis.CustomCurrencyTable, chargeusagebasedcostbasis.CustomCurrencyColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first ChargeUsageBasedCostBasis entity from the query. +// Returns a *NotFoundError when no ChargeUsageBasedCostBasis was found. +func (_q *ChargeUsageBasedCostBasisQuery) First(ctx context.Context) (*ChargeUsageBasedCostBasis, 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{chargeusagebasedcostbasis.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *ChargeUsageBasedCostBasisQuery) FirstX(ctx context.Context) *ChargeUsageBasedCostBasis { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first ChargeUsageBasedCostBasis ID from the query. +// Returns a *NotFoundError when no ChargeUsageBasedCostBasis ID was found. +func (_q *ChargeUsageBasedCostBasisQuery) 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{chargeusagebasedcostbasis.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *ChargeUsageBasedCostBasisQuery) FirstIDX(ctx context.Context) string { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single ChargeUsageBasedCostBasis entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one ChargeUsageBasedCostBasis entity is found. +// Returns a *NotFoundError when no ChargeUsageBasedCostBasis entities are found. +func (_q *ChargeUsageBasedCostBasisQuery) Only(ctx context.Context) (*ChargeUsageBasedCostBasis, 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{chargeusagebasedcostbasis.Label} + default: + return nil, &NotSingularError{chargeusagebasedcostbasis.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *ChargeUsageBasedCostBasisQuery) OnlyX(ctx context.Context) *ChargeUsageBasedCostBasis { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only ChargeUsageBasedCostBasis ID in the query. +// Returns a *NotSingularError when more than one ChargeUsageBasedCostBasis ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *ChargeUsageBasedCostBasisQuery) 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{chargeusagebasedcostbasis.Label} + default: + err = &NotSingularError{chargeusagebasedcostbasis.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *ChargeUsageBasedCostBasisQuery) 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 ChargeUsageBasedCostBases. +func (_q *ChargeUsageBasedCostBasisQuery) All(ctx context.Context) ([]*ChargeUsageBasedCostBasis, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*ChargeUsageBasedCostBasis, *ChargeUsageBasedCostBasisQuery]() + return withInterceptors[[]*ChargeUsageBasedCostBasis](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *ChargeUsageBasedCostBasisQuery) AllX(ctx context.Context) []*ChargeUsageBasedCostBasis { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of ChargeUsageBasedCostBasis IDs. +func (_q *ChargeUsageBasedCostBasisQuery) 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(chargeusagebasedcostbasis.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *ChargeUsageBasedCostBasisQuery) 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 *ChargeUsageBasedCostBasisQuery) 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[*ChargeUsageBasedCostBasisQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *ChargeUsageBasedCostBasisQuery) 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 *ChargeUsageBasedCostBasisQuery) 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 *ChargeUsageBasedCostBasisQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the ChargeUsageBasedCostBasisQuery 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 *ChargeUsageBasedCostBasisQuery) Clone() *ChargeUsageBasedCostBasisQuery { + if _q == nil { + return nil + } + return &ChargeUsageBasedCostBasisQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]chargeusagebasedcostbasis.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.ChargeUsageBasedCostBasis{}, _q.predicates...), + withCurrencyCostBasis: _q.withCurrencyCostBasis.Clone(), + withResolvedCurrencyCostBasis: _q.withResolvedCurrencyCostBasis.Clone(), + withCustomCurrency: _q.withCustomCurrency.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// WithCurrencyCostBasis tells the query-builder to eager-load the nodes that are connected to +// the "currency_cost_basis" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeUsageBasedCostBasisQuery) WithCurrencyCostBasis(opts ...func(*CurrencyCostBasisQuery)) *ChargeUsageBasedCostBasisQuery { + query := (&CurrencyCostBasisClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withCurrencyCostBasis = query + return _q +} + +// WithResolvedCurrencyCostBasis tells the query-builder to eager-load the nodes that are connected to +// the "resolved_currency_cost_basis" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeUsageBasedCostBasisQuery) WithResolvedCurrencyCostBasis(opts ...func(*CurrencyCostBasisQuery)) *ChargeUsageBasedCostBasisQuery { + query := (&CurrencyCostBasisClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withResolvedCurrencyCostBasis = query + return _q +} + +// WithCustomCurrency tells the query-builder to eager-load the nodes that are connected to +// the "custom_currency" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ChargeUsageBasedCostBasisQuery) WithCustomCurrency(opts ...func(*CustomCurrencyQuery)) *ChargeUsageBasedCostBasisQuery { + query := (&CustomCurrencyClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withCustomCurrency = 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 { +// Mode costbasis.Mode `json:"mode,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.ChargeUsageBasedCostBasis.Query(). +// GroupBy(chargeusagebasedcostbasis.FieldMode). +// Aggregate(db.Count()). +// Scan(ctx, &v) +func (_q *ChargeUsageBasedCostBasisQuery) GroupBy(field string, fields ...string) *ChargeUsageBasedCostBasisGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &ChargeUsageBasedCostBasisGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = chargeusagebasedcostbasis.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 { +// Mode costbasis.Mode `json:"mode,omitempty"` +// } +// +// client.ChargeUsageBasedCostBasis.Query(). +// Select(chargeusagebasedcostbasis.FieldMode). +// Scan(ctx, &v) +func (_q *ChargeUsageBasedCostBasisQuery) Select(fields ...string) *ChargeUsageBasedCostBasisSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &ChargeUsageBasedCostBasisSelect{ChargeUsageBasedCostBasisQuery: _q} + sbuild.label = chargeusagebasedcostbasis.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a ChargeUsageBasedCostBasisSelect configured with the given aggregations. +func (_q *ChargeUsageBasedCostBasisQuery) Aggregate(fns ...AggregateFunc) *ChargeUsageBasedCostBasisSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *ChargeUsageBasedCostBasisQuery) 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 !chargeusagebasedcostbasis.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 *ChargeUsageBasedCostBasisQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ChargeUsageBasedCostBasis, error) { + var ( + nodes = []*ChargeUsageBasedCostBasis{} + _spec = _q.querySpec() + loadedTypes = [3]bool{ + _q.withCurrencyCostBasis != nil, + _q.withResolvedCurrencyCostBasis != nil, + _q.withCustomCurrency != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*ChargeUsageBasedCostBasis).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &ChargeUsageBasedCostBasis{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.withCurrencyCostBasis; query != nil { + if err := _q.loadCurrencyCostBasis(ctx, query, nodes, nil, + func(n *ChargeUsageBasedCostBasis, e *CurrencyCostBasis) { n.Edges.CurrencyCostBasis = e }); err != nil { + return nil, err + } + } + if query := _q.withResolvedCurrencyCostBasis; query != nil { + if err := _q.loadResolvedCurrencyCostBasis(ctx, query, nodes, nil, + func(n *ChargeUsageBasedCostBasis, e *CurrencyCostBasis) { n.Edges.ResolvedCurrencyCostBasis = e }); err != nil { + return nil, err + } + } + if query := _q.withCustomCurrency; query != nil { + if err := _q.loadCustomCurrency(ctx, query, nodes, nil, + func(n *ChargeUsageBasedCostBasis, e *CustomCurrency) { n.Edges.CustomCurrency = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *ChargeUsageBasedCostBasisQuery) loadCurrencyCostBasis(ctx context.Context, query *CurrencyCostBasisQuery, nodes []*ChargeUsageBasedCostBasis, init func(*ChargeUsageBasedCostBasis), assign func(*ChargeUsageBasedCostBasis, *CurrencyCostBasis)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*ChargeUsageBasedCostBasis) + for i := range nodes { + if nodes[i].CurrencyCostBasisID == nil { + continue + } + fk := *nodes[i].CurrencyCostBasisID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(currencycostbasis.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 "currency_cost_basis_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *ChargeUsageBasedCostBasisQuery) loadResolvedCurrencyCostBasis(ctx context.Context, query *CurrencyCostBasisQuery, nodes []*ChargeUsageBasedCostBasis, init func(*ChargeUsageBasedCostBasis), assign func(*ChargeUsageBasedCostBasis, *CurrencyCostBasis)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*ChargeUsageBasedCostBasis) + for i := range nodes { + if nodes[i].ResolvedCostBasisID == nil { + continue + } + fk := *nodes[i].ResolvedCostBasisID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(currencycostbasis.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 "resolved_cost_basis_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (_q *ChargeUsageBasedCostBasisQuery) loadCustomCurrency(ctx context.Context, query *CustomCurrencyQuery, nodes []*ChargeUsageBasedCostBasis, init func(*ChargeUsageBasedCostBasis), assign func(*ChargeUsageBasedCostBasis, *CustomCurrency)) error { + ids := make([]string, 0, len(nodes)) + nodeids := make(map[string][]*ChargeUsageBasedCostBasis) + for i := range nodes { + fk := nodes[i].CurrencyID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(customcurrency.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 "currency_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (_q *ChargeUsageBasedCostBasisQuery) 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 *ChargeUsageBasedCostBasisQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(chargeusagebasedcostbasis.Table, chargeusagebasedcostbasis.Columns, sqlgraph.NewFieldSpec(chargeusagebasedcostbasis.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, chargeusagebasedcostbasis.FieldID) + for i := range fields { + if fields[i] != chargeusagebasedcostbasis.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withCurrencyCostBasis != nil { + _spec.Node.AddColumnOnce(chargeusagebasedcostbasis.FieldCurrencyCostBasisID) + } + if _q.withResolvedCurrencyCostBasis != nil { + _spec.Node.AddColumnOnce(chargeusagebasedcostbasis.FieldResolvedCostBasisID) + } + if _q.withCustomCurrency != nil { + _spec.Node.AddColumnOnce(chargeusagebasedcostbasis.FieldCurrencyID) + } + } + 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 *ChargeUsageBasedCostBasisQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(chargeusagebasedcostbasis.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = chargeusagebasedcostbasis.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 *ChargeUsageBasedCostBasisQuery) ForUpdate(opts ...sql.LockOption) *ChargeUsageBasedCostBasisQuery { + 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 *ChargeUsageBasedCostBasisQuery) ForShare(opts ...sql.LockOption) *ChargeUsageBasedCostBasisQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForShare(opts...) + }) + return _q +} + +// ChargeUsageBasedCostBasisGroupBy is the group-by builder for ChargeUsageBasedCostBasis entities. +type ChargeUsageBasedCostBasisGroupBy struct { + selector + build *ChargeUsageBasedCostBasisQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *ChargeUsageBasedCostBasisGroupBy) Aggregate(fns ...AggregateFunc) *ChargeUsageBasedCostBasisGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *ChargeUsageBasedCostBasisGroupBy) 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[*ChargeUsageBasedCostBasisQuery, *ChargeUsageBasedCostBasisGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *ChargeUsageBasedCostBasisGroupBy) sqlScan(ctx context.Context, root *ChargeUsageBasedCostBasisQuery, 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) +} + +// ChargeUsageBasedCostBasisSelect is the builder for selecting fields of ChargeUsageBasedCostBasis entities. +type ChargeUsageBasedCostBasisSelect struct { + *ChargeUsageBasedCostBasisQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *ChargeUsageBasedCostBasisSelect) Aggregate(fns ...AggregateFunc) *ChargeUsageBasedCostBasisSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *ChargeUsageBasedCostBasisSelect) 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[*ChargeUsageBasedCostBasisQuery, *ChargeUsageBasedCostBasisSelect](ctx, _s.ChargeUsageBasedCostBasisQuery, _s, _s.inters, v) +} + +func (_s *ChargeUsageBasedCostBasisSelect) sqlScan(ctx context.Context, root *ChargeUsageBasedCostBasisQuery, 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/chargeusagebasedcostbasis_update.go b/openmeter/ent/db/chargeusagebasedcostbasis_update.go new file mode 100644 index 0000000000..400ef2c3ad --- /dev/null +++ b/openmeter/ent/db/chargeusagebasedcostbasis_update.go @@ -0,0 +1,666 @@ +// 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/alpacahq/alpacadecimal" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedcostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/currencycostbasis" + "github.com/openmeterio/openmeter/openmeter/ent/db/predicate" +) + +// ChargeUsageBasedCostBasisUpdate is the builder for updating ChargeUsageBasedCostBasis entities. +type ChargeUsageBasedCostBasisUpdate struct { + config + hooks []Hook + mutation *ChargeUsageBasedCostBasisMutation +} + +// Where appends a list predicates to the ChargeUsageBasedCostBasisUpdate builder. +func (_u *ChargeUsageBasedCostBasisUpdate) Where(ps ...predicate.ChargeUsageBasedCostBasis) *ChargeUsageBasedCostBasisUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (_u *ChargeUsageBasedCostBasisUpdate) SetCurrencyCostBasisID(v string) *ChargeUsageBasedCostBasisUpdate { + _u.mutation.SetCurrencyCostBasisID(v) + return _u +} + +// SetNillableCurrencyCostBasisID sets the "currency_cost_basis_id" field if the given value is not nil. +func (_u *ChargeUsageBasedCostBasisUpdate) SetNillableCurrencyCostBasisID(v *string) *ChargeUsageBasedCostBasisUpdate { + if v != nil { + _u.SetCurrencyCostBasisID(*v) + } + return _u +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (_u *ChargeUsageBasedCostBasisUpdate) ClearCurrencyCostBasisID() *ChargeUsageBasedCostBasisUpdate { + _u.mutation.ClearCurrencyCostBasisID() + return _u +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (_u *ChargeUsageBasedCostBasisUpdate) SetResolvedCostBasisID(v string) *ChargeUsageBasedCostBasisUpdate { + _u.mutation.SetResolvedCostBasisID(v) + return _u +} + +// SetNillableResolvedCostBasisID sets the "resolved_cost_basis_id" field if the given value is not nil. +func (_u *ChargeUsageBasedCostBasisUpdate) SetNillableResolvedCostBasisID(v *string) *ChargeUsageBasedCostBasisUpdate { + if v != nil { + _u.SetResolvedCostBasisID(*v) + } + return _u +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (_u *ChargeUsageBasedCostBasisUpdate) ClearResolvedCostBasisID() *ChargeUsageBasedCostBasisUpdate { + _u.mutation.ClearResolvedCostBasisID() + return _u +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (_u *ChargeUsageBasedCostBasisUpdate) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeUsageBasedCostBasisUpdate { + _u.mutation.SetResolvedCostBasis(v) + return _u +} + +// SetNillableResolvedCostBasis sets the "resolved_cost_basis" field if the given value is not nil. +func (_u *ChargeUsageBasedCostBasisUpdate) SetNillableResolvedCostBasis(v *alpacadecimal.Decimal) *ChargeUsageBasedCostBasisUpdate { + if v != nil { + _u.SetResolvedCostBasis(*v) + } + return _u +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (_u *ChargeUsageBasedCostBasisUpdate) ClearResolvedCostBasis() *ChargeUsageBasedCostBasisUpdate { + _u.mutation.ClearResolvedCostBasis() + return _u +} + +// SetResolvedAt sets the "resolved_at" field. +func (_u *ChargeUsageBasedCostBasisUpdate) SetResolvedAt(v time.Time) *ChargeUsageBasedCostBasisUpdate { + _u.mutation.SetResolvedAt(v) + return _u +} + +// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil. +func (_u *ChargeUsageBasedCostBasisUpdate) SetNillableResolvedAt(v *time.Time) *ChargeUsageBasedCostBasisUpdate { + if v != nil { + _u.SetResolvedAt(*v) + } + return _u +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (_u *ChargeUsageBasedCostBasisUpdate) ClearResolvedAt() *ChargeUsageBasedCostBasisUpdate { + _u.mutation.ClearResolvedAt() + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ChargeUsageBasedCostBasisUpdate) SetUpdatedAt(v time.Time) *ChargeUsageBasedCostBasisUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetDeletedAt sets the "deleted_at" field. +func (_u *ChargeUsageBasedCostBasisUpdate) SetDeletedAt(v time.Time) *ChargeUsageBasedCostBasisUpdate { + _u.mutation.SetDeletedAt(v) + return _u +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_u *ChargeUsageBasedCostBasisUpdate) SetNillableDeletedAt(v *time.Time) *ChargeUsageBasedCostBasisUpdate { + if v != nil { + _u.SetDeletedAt(*v) + } + return _u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (_u *ChargeUsageBasedCostBasisUpdate) ClearDeletedAt() *ChargeUsageBasedCostBasisUpdate { + _u.mutation.ClearDeletedAt() + return _u +} + +// SetCurrencyCostBasis sets the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeUsageBasedCostBasisUpdate) SetCurrencyCostBasis(v *CurrencyCostBasis) *ChargeUsageBasedCostBasisUpdate { + return _u.SetCurrencyCostBasisID(v.ID) +} + +// SetResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID. +func (_u *ChargeUsageBasedCostBasisUpdate) SetResolvedCurrencyCostBasisID(id string) *ChargeUsageBasedCostBasisUpdate { + _u.mutation.SetResolvedCurrencyCostBasisID(id) + return _u +} + +// SetNillableResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID if the given value is not nil. +func (_u *ChargeUsageBasedCostBasisUpdate) SetNillableResolvedCurrencyCostBasisID(id *string) *ChargeUsageBasedCostBasisUpdate { + if id != nil { + _u = _u.SetResolvedCurrencyCostBasisID(*id) + } + return _u +} + +// SetResolvedCurrencyCostBasis sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeUsageBasedCostBasisUpdate) SetResolvedCurrencyCostBasis(v *CurrencyCostBasis) *ChargeUsageBasedCostBasisUpdate { + return _u.SetResolvedCurrencyCostBasisID(v.ID) +} + +// Mutation returns the ChargeUsageBasedCostBasisMutation object of the builder. +func (_u *ChargeUsageBasedCostBasisUpdate) Mutation() *ChargeUsageBasedCostBasisMutation { + return _u.mutation +} + +// ClearCurrencyCostBasis clears the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeUsageBasedCostBasisUpdate) ClearCurrencyCostBasis() *ChargeUsageBasedCostBasisUpdate { + _u.mutation.ClearCurrencyCostBasis() + return _u +} + +// ClearResolvedCurrencyCostBasis clears the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeUsageBasedCostBasisUpdate) ClearResolvedCurrencyCostBasis() *ChargeUsageBasedCostBasisUpdate { + _u.mutation.ClearResolvedCurrencyCostBasis() + return _u +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *ChargeUsageBasedCostBasisUpdate) 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 *ChargeUsageBasedCostBasisUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *ChargeUsageBasedCostBasisUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ChargeUsageBasedCostBasisUpdate) 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 *ChargeUsageBasedCostBasisUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := chargeusagebasedcostbasis.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ChargeUsageBasedCostBasisUpdate) check() error { + if _u.mutation.CustomCurrencyCleared() && len(_u.mutation.CustomCurrencyIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "ChargeUsageBasedCostBasis.custom_currency"`) + } + return nil +} + +func (_u *ChargeUsageBasedCostBasisUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(chargeusagebasedcostbasis.Table, chargeusagebasedcostbasis.Columns, sqlgraph.NewFieldSpec(chargeusagebasedcostbasis.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 _u.mutation.ManualRateCleared() { + _spec.ClearField(chargeusagebasedcostbasis.FieldManualRate, field.TypeOther) + } + if value, ok := _u.mutation.ResolvedCostBasis(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldResolvedCostBasis, field.TypeOther, value) + } + if _u.mutation.ResolvedCostBasisCleared() { + _spec.ClearField(chargeusagebasedcostbasis.FieldResolvedCostBasis, field.TypeOther) + } + if value, ok := _u.mutation.ResolvedAt(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldResolvedAt, field.TypeTime, value) + } + if _u.mutation.ResolvedAtCleared() { + _spec.ClearField(chargeusagebasedcostbasis.FieldResolvedAt, field.TypeTime) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.DeletedAt(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldDeletedAt, field.TypeTime, value) + } + if _u.mutation.DeletedAtCleared() { + _spec.ClearField(chargeusagebasedcostbasis.FieldDeletedAt, field.TypeTime) + } + if _u.mutation.CurrencyCostBasisCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeusagebasedcostbasis.CurrencyCostBasisTable, + Columns: []string{chargeusagebasedcostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.CurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeusagebasedcostbasis.CurrencyCostBasisTable, + Columns: []string{chargeusagebasedcostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.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.ResolvedCurrencyCostBasisCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeusagebasedcostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargeusagebasedcostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ResolvedCurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeusagebasedcostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargeusagebasedcostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.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{chargeusagebasedcostbasis.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// ChargeUsageBasedCostBasisUpdateOne is the builder for updating a single ChargeUsageBasedCostBasis entity. +type ChargeUsageBasedCostBasisUpdateOne struct { + config + fields []string + hooks []Hook + mutation *ChargeUsageBasedCostBasisMutation +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetCurrencyCostBasisID(v string) *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.SetCurrencyCostBasisID(v) + return _u +} + +// SetNillableCurrencyCostBasisID sets the "currency_cost_basis_id" field if the given value is not nil. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetNillableCurrencyCostBasisID(v *string) *ChargeUsageBasedCostBasisUpdateOne { + if v != nil { + _u.SetCurrencyCostBasisID(*v) + } + return _u +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (_u *ChargeUsageBasedCostBasisUpdateOne) ClearCurrencyCostBasisID() *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.ClearCurrencyCostBasisID() + return _u +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetResolvedCostBasisID(v string) *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.SetResolvedCostBasisID(v) + return _u +} + +// SetNillableResolvedCostBasisID sets the "resolved_cost_basis_id" field if the given value is not nil. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetNillableResolvedCostBasisID(v *string) *ChargeUsageBasedCostBasisUpdateOne { + if v != nil { + _u.SetResolvedCostBasisID(*v) + } + return _u +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (_u *ChargeUsageBasedCostBasisUpdateOne) ClearResolvedCostBasisID() *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.ClearResolvedCostBasisID() + return _u +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetResolvedCostBasis(v alpacadecimal.Decimal) *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.SetResolvedCostBasis(v) + return _u +} + +// SetNillableResolvedCostBasis sets the "resolved_cost_basis" field if the given value is not nil. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetNillableResolvedCostBasis(v *alpacadecimal.Decimal) *ChargeUsageBasedCostBasisUpdateOne { + if v != nil { + _u.SetResolvedCostBasis(*v) + } + return _u +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (_u *ChargeUsageBasedCostBasisUpdateOne) ClearResolvedCostBasis() *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.ClearResolvedCostBasis() + return _u +} + +// SetResolvedAt sets the "resolved_at" field. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetResolvedAt(v time.Time) *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.SetResolvedAt(v) + return _u +} + +// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetNillableResolvedAt(v *time.Time) *ChargeUsageBasedCostBasisUpdateOne { + if v != nil { + _u.SetResolvedAt(*v) + } + return _u +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (_u *ChargeUsageBasedCostBasisUpdateOne) ClearResolvedAt() *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.ClearResolvedAt() + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetUpdatedAt(v time.Time) *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetDeletedAt sets the "deleted_at" field. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetDeletedAt(v time.Time) *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.SetDeletedAt(v) + return _u +} + +// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetNillableDeletedAt(v *time.Time) *ChargeUsageBasedCostBasisUpdateOne { + if v != nil { + _u.SetDeletedAt(*v) + } + return _u +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (_u *ChargeUsageBasedCostBasisUpdateOne) ClearDeletedAt() *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.ClearDeletedAt() + return _u +} + +// SetCurrencyCostBasis sets the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetCurrencyCostBasis(v *CurrencyCostBasis) *ChargeUsageBasedCostBasisUpdateOne { + return _u.SetCurrencyCostBasisID(v.ID) +} + +// SetResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetResolvedCurrencyCostBasisID(id string) *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.SetResolvedCurrencyCostBasisID(id) + return _u +} + +// SetNillableResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by ID if the given value is not nil. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetNillableResolvedCurrencyCostBasisID(id *string) *ChargeUsageBasedCostBasisUpdateOne { + if id != nil { + _u = _u.SetResolvedCurrencyCostBasisID(*id) + } + return _u +} + +// SetResolvedCurrencyCostBasis sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SetResolvedCurrencyCostBasis(v *CurrencyCostBasis) *ChargeUsageBasedCostBasisUpdateOne { + return _u.SetResolvedCurrencyCostBasisID(v.ID) +} + +// Mutation returns the ChargeUsageBasedCostBasisMutation object of the builder. +func (_u *ChargeUsageBasedCostBasisUpdateOne) Mutation() *ChargeUsageBasedCostBasisMutation { + return _u.mutation +} + +// ClearCurrencyCostBasis clears the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeUsageBasedCostBasisUpdateOne) ClearCurrencyCostBasis() *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.ClearCurrencyCostBasis() + return _u +} + +// ClearResolvedCurrencyCostBasis clears the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (_u *ChargeUsageBasedCostBasisUpdateOne) ClearResolvedCurrencyCostBasis() *ChargeUsageBasedCostBasisUpdateOne { + _u.mutation.ClearResolvedCurrencyCostBasis() + return _u +} + +// Where appends a list predicates to the ChargeUsageBasedCostBasisUpdate builder. +func (_u *ChargeUsageBasedCostBasisUpdateOne) Where(ps ...predicate.ChargeUsageBasedCostBasis) *ChargeUsageBasedCostBasisUpdateOne { + _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 *ChargeUsageBasedCostBasisUpdateOne) Select(field string, fields ...string) *ChargeUsageBasedCostBasisUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated ChargeUsageBasedCostBasis entity. +func (_u *ChargeUsageBasedCostBasisUpdateOne) Save(ctx context.Context) (*ChargeUsageBasedCostBasis, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ChargeUsageBasedCostBasisUpdateOne) SaveX(ctx context.Context) *ChargeUsageBasedCostBasis { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *ChargeUsageBasedCostBasisUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ChargeUsageBasedCostBasisUpdateOne) 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 *ChargeUsageBasedCostBasisUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok { + v := chargeusagebasedcostbasis.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ChargeUsageBasedCostBasisUpdateOne) check() error { + if _u.mutation.CustomCurrencyCleared() && len(_u.mutation.CustomCurrencyIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "ChargeUsageBasedCostBasis.custom_currency"`) + } + return nil +} + +func (_u *ChargeUsageBasedCostBasisUpdateOne) sqlSave(ctx context.Context) (_node *ChargeUsageBasedCostBasis, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(chargeusagebasedcostbasis.Table, chargeusagebasedcostbasis.Columns, sqlgraph.NewFieldSpec(chargeusagebasedcostbasis.FieldID, field.TypeString)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "ChargeUsageBasedCostBasis.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, chargeusagebasedcostbasis.FieldID) + for _, f := range fields { + if !chargeusagebasedcostbasis.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + if f != chargeusagebasedcostbasis.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 _u.mutation.ManualRateCleared() { + _spec.ClearField(chargeusagebasedcostbasis.FieldManualRate, field.TypeOther) + } + if value, ok := _u.mutation.ResolvedCostBasis(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldResolvedCostBasis, field.TypeOther, value) + } + if _u.mutation.ResolvedCostBasisCleared() { + _spec.ClearField(chargeusagebasedcostbasis.FieldResolvedCostBasis, field.TypeOther) + } + if value, ok := _u.mutation.ResolvedAt(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldResolvedAt, field.TypeTime, value) + } + if _u.mutation.ResolvedAtCleared() { + _spec.ClearField(chargeusagebasedcostbasis.FieldResolvedAt, field.TypeTime) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.DeletedAt(); ok { + _spec.SetField(chargeusagebasedcostbasis.FieldDeletedAt, field.TypeTime, value) + } + if _u.mutation.DeletedAtCleared() { + _spec.ClearField(chargeusagebasedcostbasis.FieldDeletedAt, field.TypeTime) + } + if _u.mutation.CurrencyCostBasisCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeusagebasedcostbasis.CurrencyCostBasisTable, + Columns: []string{chargeusagebasedcostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.CurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeusagebasedcostbasis.CurrencyCostBasisTable, + Columns: []string{chargeusagebasedcostbasis.CurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.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.ResolvedCurrencyCostBasisCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeusagebasedcostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargeusagebasedcostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.ResolvedCurrencyCostBasisIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: chargeusagebasedcostbasis.ResolvedCurrencyCostBasisTable, + Columns: []string{chargeusagebasedcostbasis.ResolvedCurrencyCostBasisColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(currencycostbasis.FieldID, field.TypeString), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &ChargeUsageBasedCostBasis{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{chargeusagebasedcostbasis.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/client.go b/openmeter/ent/db/client.go index 1de894aa6b..8dfe7f1cd0 100644 --- a/openmeter/ent/db/client.go +++ b/openmeter/ent/db/client.go @@ -43,10 +43,12 @@ import ( "github.com/openmeterio/openmeter/openmeter/ent/db/billingworkflowconfig" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecreditgrant" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseexternalpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseinvoicedpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfee" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeerun" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeruncreditallocations" @@ -54,6 +56,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeruninvoicedusage" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeerunpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebased" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedcostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedruncreditallocations" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedrundetailedline" @@ -163,6 +166,8 @@ type Client struct { Charge *ChargeClient // ChargeCreditPurchase is the client for interacting with the ChargeCreditPurchase builders. ChargeCreditPurchase *ChargeCreditPurchaseClient + // ChargeCreditPurchaseCostBasis is the client for interacting with the ChargeCreditPurchaseCostBasis builders. + ChargeCreditPurchaseCostBasis *ChargeCreditPurchaseCostBasisClient // ChargeCreditPurchaseCreditGrant is the client for interacting with the ChargeCreditPurchaseCreditGrant builders. ChargeCreditPurchaseCreditGrant *ChargeCreditPurchaseCreditGrantClient // ChargeCreditPurchaseExternalPayment is the client for interacting with the ChargeCreditPurchaseExternalPayment builders. @@ -171,6 +176,8 @@ type Client struct { ChargeCreditPurchaseInvoicedPayment *ChargeCreditPurchaseInvoicedPaymentClient // ChargeFlatFee is the client for interacting with the ChargeFlatFee builders. ChargeFlatFee *ChargeFlatFeeClient + // ChargeFlatFeeCostBasis is the client for interacting with the ChargeFlatFeeCostBasis builders. + ChargeFlatFeeCostBasis *ChargeFlatFeeCostBasisClient // ChargeFlatFeeOverride is the client for interacting with the ChargeFlatFeeOverride builders. ChargeFlatFeeOverride *ChargeFlatFeeOverrideClient // ChargeFlatFeeRun is the client for interacting with the ChargeFlatFeeRun builders. @@ -185,6 +192,8 @@ type Client struct { ChargeFlatFeeRunPayment *ChargeFlatFeeRunPaymentClient // ChargeUsageBased is the client for interacting with the ChargeUsageBased builders. ChargeUsageBased *ChargeUsageBasedClient + // ChargeUsageBasedCostBasis is the client for interacting with the ChargeUsageBasedCostBasis builders. + ChargeUsageBasedCostBasis *ChargeUsageBasedCostBasisClient // ChargeUsageBasedOverride is the client for interacting with the ChargeUsageBasedOverride builders. ChargeUsageBasedOverride *ChargeUsageBasedOverrideClient // ChargeUsageBasedRunCreditAllocations is the client for interacting with the ChargeUsageBasedRunCreditAllocations builders. @@ -314,10 +323,12 @@ func (c *Client) init() { c.BillingWorkflowConfig = NewBillingWorkflowConfigClient(c.config) c.Charge = NewChargeClient(c.config) c.ChargeCreditPurchase = NewChargeCreditPurchaseClient(c.config) + c.ChargeCreditPurchaseCostBasis = NewChargeCreditPurchaseCostBasisClient(c.config) c.ChargeCreditPurchaseCreditGrant = NewChargeCreditPurchaseCreditGrantClient(c.config) c.ChargeCreditPurchaseExternalPayment = NewChargeCreditPurchaseExternalPaymentClient(c.config) c.ChargeCreditPurchaseInvoicedPayment = NewChargeCreditPurchaseInvoicedPaymentClient(c.config) c.ChargeFlatFee = NewChargeFlatFeeClient(c.config) + c.ChargeFlatFeeCostBasis = NewChargeFlatFeeCostBasisClient(c.config) c.ChargeFlatFeeOverride = NewChargeFlatFeeOverrideClient(c.config) c.ChargeFlatFeeRun = NewChargeFlatFeeRunClient(c.config) c.ChargeFlatFeeRunCreditAllocations = NewChargeFlatFeeRunCreditAllocationsClient(c.config) @@ -325,6 +336,7 @@ func (c *Client) init() { c.ChargeFlatFeeRunInvoicedUsage = NewChargeFlatFeeRunInvoicedUsageClient(c.config) c.ChargeFlatFeeRunPayment = NewChargeFlatFeeRunPaymentClient(c.config) c.ChargeUsageBased = NewChargeUsageBasedClient(c.config) + c.ChargeUsageBasedCostBasis = NewChargeUsageBasedCostBasisClient(c.config) c.ChargeUsageBasedOverride = NewChargeUsageBasedOverrideClient(c.config) c.ChargeUsageBasedRunCreditAllocations = NewChargeUsageBasedRunCreditAllocationsClient(c.config) c.ChargeUsageBasedRunDetailedLine = NewChargeUsageBasedRunDetailedLineClient(c.config) @@ -490,10 +502,12 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { BillingWorkflowConfig: NewBillingWorkflowConfigClient(cfg), Charge: NewChargeClient(cfg), ChargeCreditPurchase: NewChargeCreditPurchaseClient(cfg), + ChargeCreditPurchaseCostBasis: NewChargeCreditPurchaseCostBasisClient(cfg), ChargeCreditPurchaseCreditGrant: NewChargeCreditPurchaseCreditGrantClient(cfg), ChargeCreditPurchaseExternalPayment: NewChargeCreditPurchaseExternalPaymentClient(cfg), ChargeCreditPurchaseInvoicedPayment: NewChargeCreditPurchaseInvoicedPaymentClient(cfg), ChargeFlatFee: NewChargeFlatFeeClient(cfg), + ChargeFlatFeeCostBasis: NewChargeFlatFeeCostBasisClient(cfg), ChargeFlatFeeOverride: NewChargeFlatFeeOverrideClient(cfg), ChargeFlatFeeRun: NewChargeFlatFeeRunClient(cfg), ChargeFlatFeeRunCreditAllocations: NewChargeFlatFeeRunCreditAllocationsClient(cfg), @@ -501,6 +515,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { ChargeFlatFeeRunInvoicedUsage: NewChargeFlatFeeRunInvoicedUsageClient(cfg), ChargeFlatFeeRunPayment: NewChargeFlatFeeRunPaymentClient(cfg), ChargeUsageBased: NewChargeUsageBasedClient(cfg), + ChargeUsageBasedCostBasis: NewChargeUsageBasedCostBasisClient(cfg), ChargeUsageBasedOverride: NewChargeUsageBasedOverrideClient(cfg), ChargeUsageBasedRunCreditAllocations: NewChargeUsageBasedRunCreditAllocationsClient(cfg), ChargeUsageBasedRunDetailedLine: NewChargeUsageBasedRunDetailedLineClient(cfg), @@ -593,10 +608,12 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) BillingWorkflowConfig: NewBillingWorkflowConfigClient(cfg), Charge: NewChargeClient(cfg), ChargeCreditPurchase: NewChargeCreditPurchaseClient(cfg), + ChargeCreditPurchaseCostBasis: NewChargeCreditPurchaseCostBasisClient(cfg), ChargeCreditPurchaseCreditGrant: NewChargeCreditPurchaseCreditGrantClient(cfg), ChargeCreditPurchaseExternalPayment: NewChargeCreditPurchaseExternalPaymentClient(cfg), ChargeCreditPurchaseInvoicedPayment: NewChargeCreditPurchaseInvoicedPaymentClient(cfg), ChargeFlatFee: NewChargeFlatFeeClient(cfg), + ChargeFlatFeeCostBasis: NewChargeFlatFeeCostBasisClient(cfg), ChargeFlatFeeOverride: NewChargeFlatFeeOverrideClient(cfg), ChargeFlatFeeRun: NewChargeFlatFeeRunClient(cfg), ChargeFlatFeeRunCreditAllocations: NewChargeFlatFeeRunCreditAllocationsClient(cfg), @@ -604,6 +621,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) ChargeFlatFeeRunInvoicedUsage: NewChargeFlatFeeRunInvoicedUsageClient(cfg), ChargeFlatFeeRunPayment: NewChargeFlatFeeRunPaymentClient(cfg), ChargeUsageBased: NewChargeUsageBasedClient(cfg), + ChargeUsageBasedCostBasis: NewChargeUsageBasedCostBasisClient(cfg), ChargeUsageBasedOverride: NewChargeUsageBasedOverrideClient(cfg), ChargeUsageBasedRunCreditAllocations: NewChargeUsageBasedRunCreditAllocationsClient(cfg), ChargeUsageBasedRunDetailedLine: NewChargeUsageBasedRunDetailedLineClient(cfg), @@ -689,21 +707,23 @@ func (c *Client) Use(hooks ...Hook) { c.BillingProfile, c.BillingSequenceNumbers, c.BillingStandardInvoiceDetailedLine, c.BillingStandardInvoiceDetailedLineAmountDiscount, c.BillingWorkflowConfig, - c.Charge, c.ChargeCreditPurchase, c.ChargeCreditPurchaseCreditGrant, - c.ChargeCreditPurchaseExternalPayment, c.ChargeCreditPurchaseInvoicedPayment, - c.ChargeFlatFee, c.ChargeFlatFeeOverride, c.ChargeFlatFeeRun, + c.Charge, c.ChargeCreditPurchase, c.ChargeCreditPurchaseCostBasis, + c.ChargeCreditPurchaseCreditGrant, c.ChargeCreditPurchaseExternalPayment, + c.ChargeCreditPurchaseInvoicedPayment, c.ChargeFlatFee, + c.ChargeFlatFeeCostBasis, c.ChargeFlatFeeOverride, c.ChargeFlatFeeRun, c.ChargeFlatFeeRunCreditAllocations, c.ChargeFlatFeeRunDetailedLine, c.ChargeFlatFeeRunInvoicedUsage, c.ChargeFlatFeeRunPayment, c.ChargeUsageBased, - c.ChargeUsageBasedOverride, c.ChargeUsageBasedRunCreditAllocations, - c.ChargeUsageBasedRunDetailedLine, c.ChargeUsageBasedRunInvoicedUsage, - c.ChargeUsageBasedRunPayment, c.ChargeUsageBasedRuns, - c.CreditRealizationLineage, c.CreditRealizationLineageSegment, - c.CurrencyCostBasis, c.CustomCurrency, c.Customer, c.CustomerSubjects, - c.Entitlement, c.Feature, c.Grant, c.LLMCostPrice, c.LedgerAccount, - c.LedgerBreakageRecord, c.LedgerCreditVoidRecord, c.LedgerCustomerAccount, - c.LedgerEntry, c.LedgerSubAccount, c.LedgerSubAccountRoute, - c.LedgerTransaction, c.LedgerTransactionGroup, c.Meter, c.NotificationChannel, - c.NotificationEvent, c.NotificationEventDeliveryStatus, c.NotificationRule, + c.ChargeUsageBasedCostBasis, c.ChargeUsageBasedOverride, + c.ChargeUsageBasedRunCreditAllocations, c.ChargeUsageBasedRunDetailedLine, + c.ChargeUsageBasedRunInvoicedUsage, c.ChargeUsageBasedRunPayment, + c.ChargeUsageBasedRuns, c.CreditRealizationLineage, + c.CreditRealizationLineageSegment, c.CurrencyCostBasis, c.CustomCurrency, + c.Customer, c.CustomerSubjects, c.Entitlement, c.Feature, c.Grant, + c.LLMCostPrice, c.LedgerAccount, c.LedgerBreakageRecord, + c.LedgerCreditVoidRecord, c.LedgerCustomerAccount, c.LedgerEntry, + c.LedgerSubAccount, c.LedgerSubAccountRoute, c.LedgerTransaction, + c.LedgerTransactionGroup, c.Meter, c.NotificationChannel, c.NotificationEvent, + c.NotificationEventDeliveryStatus, c.NotificationRule, c.OrganizationDefaultTaxCodes, c.Plan, c.PlanAddon, c.PlanPhase, c.PlanRateCard, c.Subject, c.Subscription, c.SubscriptionAddon, c.SubscriptionAddonQuantity, c.SubscriptionBillingSyncState, @@ -728,21 +748,23 @@ func (c *Client) Intercept(interceptors ...Interceptor) { c.BillingProfile, c.BillingSequenceNumbers, c.BillingStandardInvoiceDetailedLine, c.BillingStandardInvoiceDetailedLineAmountDiscount, c.BillingWorkflowConfig, - c.Charge, c.ChargeCreditPurchase, c.ChargeCreditPurchaseCreditGrant, - c.ChargeCreditPurchaseExternalPayment, c.ChargeCreditPurchaseInvoicedPayment, - c.ChargeFlatFee, c.ChargeFlatFeeOverride, c.ChargeFlatFeeRun, + c.Charge, c.ChargeCreditPurchase, c.ChargeCreditPurchaseCostBasis, + c.ChargeCreditPurchaseCreditGrant, c.ChargeCreditPurchaseExternalPayment, + c.ChargeCreditPurchaseInvoicedPayment, c.ChargeFlatFee, + c.ChargeFlatFeeCostBasis, c.ChargeFlatFeeOverride, c.ChargeFlatFeeRun, c.ChargeFlatFeeRunCreditAllocations, c.ChargeFlatFeeRunDetailedLine, c.ChargeFlatFeeRunInvoicedUsage, c.ChargeFlatFeeRunPayment, c.ChargeUsageBased, - c.ChargeUsageBasedOverride, c.ChargeUsageBasedRunCreditAllocations, - c.ChargeUsageBasedRunDetailedLine, c.ChargeUsageBasedRunInvoicedUsage, - c.ChargeUsageBasedRunPayment, c.ChargeUsageBasedRuns, c.ChargesSearchV1, - c.CreditRealizationLineage, c.CreditRealizationLineageSegment, - c.CurrencyCostBasis, c.CustomCurrency, c.Customer, c.CustomerSubjects, - c.Entitlement, c.Feature, c.Grant, c.LLMCostPrice, c.LedgerAccount, - c.LedgerBreakageRecord, c.LedgerCreditVoidRecord, c.LedgerCustomerAccount, - c.LedgerEntry, c.LedgerSubAccount, c.LedgerSubAccountRoute, - c.LedgerTransaction, c.LedgerTransactionGroup, c.Meter, c.NotificationChannel, - c.NotificationEvent, c.NotificationEventDeliveryStatus, c.NotificationRule, + c.ChargeUsageBasedCostBasis, c.ChargeUsageBasedOverride, + c.ChargeUsageBasedRunCreditAllocations, c.ChargeUsageBasedRunDetailedLine, + c.ChargeUsageBasedRunInvoicedUsage, c.ChargeUsageBasedRunPayment, + c.ChargeUsageBasedRuns, c.ChargesSearchV1, c.CreditRealizationLineage, + c.CreditRealizationLineageSegment, c.CurrencyCostBasis, c.CustomCurrency, + c.Customer, c.CustomerSubjects, c.Entitlement, c.Feature, c.Grant, + c.LLMCostPrice, c.LedgerAccount, c.LedgerBreakageRecord, + c.LedgerCreditVoidRecord, c.LedgerCustomerAccount, c.LedgerEntry, + c.LedgerSubAccount, c.LedgerSubAccountRoute, c.LedgerTransaction, + c.LedgerTransactionGroup, c.Meter, c.NotificationChannel, c.NotificationEvent, + c.NotificationEventDeliveryStatus, c.NotificationRule, c.OrganizationDefaultTaxCodes, c.Plan, c.PlanAddon, c.PlanPhase, c.PlanRateCard, c.Subject, c.Subscription, c.SubscriptionAddon, c.SubscriptionAddonQuantity, c.SubscriptionBillingSyncState, @@ -811,6 +833,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.Charge.mutate(ctx, m) case *ChargeCreditPurchaseMutation: return c.ChargeCreditPurchase.mutate(ctx, m) + case *ChargeCreditPurchaseCostBasisMutation: + return c.ChargeCreditPurchaseCostBasis.mutate(ctx, m) case *ChargeCreditPurchaseCreditGrantMutation: return c.ChargeCreditPurchaseCreditGrant.mutate(ctx, m) case *ChargeCreditPurchaseExternalPaymentMutation: @@ -819,6 +843,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.ChargeCreditPurchaseInvoicedPayment.mutate(ctx, m) case *ChargeFlatFeeMutation: return c.ChargeFlatFee.mutate(ctx, m) + case *ChargeFlatFeeCostBasisMutation: + return c.ChargeFlatFeeCostBasis.mutate(ctx, m) case *ChargeFlatFeeOverrideMutation: return c.ChargeFlatFeeOverride.mutate(ctx, m) case *ChargeFlatFeeRunMutation: @@ -833,6 +859,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.ChargeFlatFeeRunPayment.mutate(ctx, m) case *ChargeUsageBasedMutation: return c.ChargeUsageBased.mutate(ctx, m) + case *ChargeUsageBasedCostBasisMutation: + return c.ChargeUsageBasedCostBasis.mutate(ctx, m) case *ChargeUsageBasedOverrideMutation: return c.ChargeUsageBasedOverride.mutate(ctx, m) case *ChargeUsageBasedRunCreditAllocationsMutation: @@ -6177,6 +6205,22 @@ func (c *ChargeCreditPurchaseClient) QueryCreditGrant(_m *ChargeCreditPurchase) return query } +// QueryCostBasis queries the cost_basis edge of a ChargeCreditPurchase. +func (c *ChargeCreditPurchaseClient) QueryCostBasis(_m *ChargeCreditPurchase) *ChargeCreditPurchaseCostBasisQuery { + query := (&ChargeCreditPurchaseCostBasisClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(chargecreditpurchase.Table, chargecreditpurchase.FieldID, id), + sqlgraph.To(chargecreditpurchasecostbasis.Table, chargecreditpurchasecostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargecreditpurchase.CostBasisTable, chargecreditpurchase.CostBasisColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryCharge queries the charge edge of a ChargeCreditPurchase. func (c *ChargeCreditPurchaseClient) QueryCharge(_m *ChargeCreditPurchase) *ChargeQuery { query := (&ChargeClient{config: c.config}).Query() @@ -6314,6 +6358,187 @@ func (c *ChargeCreditPurchaseClient) mutate(ctx context.Context, m *ChargeCredit } } +// ChargeCreditPurchaseCostBasisClient is a client for the ChargeCreditPurchaseCostBasis schema. +type ChargeCreditPurchaseCostBasisClient struct { + config +} + +// NewChargeCreditPurchaseCostBasisClient returns a client for the ChargeCreditPurchaseCostBasis from the given config. +func NewChargeCreditPurchaseCostBasisClient(c config) *ChargeCreditPurchaseCostBasisClient { + return &ChargeCreditPurchaseCostBasisClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `chargecreditpurchasecostbasis.Hooks(f(g(h())))`. +func (c *ChargeCreditPurchaseCostBasisClient) Use(hooks ...Hook) { + c.hooks.ChargeCreditPurchaseCostBasis = append(c.hooks.ChargeCreditPurchaseCostBasis, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `chargecreditpurchasecostbasis.Intercept(f(g(h())))`. +func (c *ChargeCreditPurchaseCostBasisClient) Intercept(interceptors ...Interceptor) { + c.inters.ChargeCreditPurchaseCostBasis = append(c.inters.ChargeCreditPurchaseCostBasis, interceptors...) +} + +// Create returns a builder for creating a ChargeCreditPurchaseCostBasis entity. +func (c *ChargeCreditPurchaseCostBasisClient) Create() *ChargeCreditPurchaseCostBasisCreate { + mutation := newChargeCreditPurchaseCostBasisMutation(c.config, OpCreate) + return &ChargeCreditPurchaseCostBasisCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of ChargeCreditPurchaseCostBasis entities. +func (c *ChargeCreditPurchaseCostBasisClient) CreateBulk(builders ...*ChargeCreditPurchaseCostBasisCreate) *ChargeCreditPurchaseCostBasisCreateBulk { + return &ChargeCreditPurchaseCostBasisCreateBulk{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 *ChargeCreditPurchaseCostBasisClient) MapCreateBulk(slice any, setFunc func(*ChargeCreditPurchaseCostBasisCreate, int)) *ChargeCreditPurchaseCostBasisCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ChargeCreditPurchaseCostBasisCreateBulk{err: fmt.Errorf("calling to ChargeCreditPurchaseCostBasisClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ChargeCreditPurchaseCostBasisCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ChargeCreditPurchaseCostBasisCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for ChargeCreditPurchaseCostBasis. +func (c *ChargeCreditPurchaseCostBasisClient) Update() *ChargeCreditPurchaseCostBasisUpdate { + mutation := newChargeCreditPurchaseCostBasisMutation(c.config, OpUpdate) + return &ChargeCreditPurchaseCostBasisUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ChargeCreditPurchaseCostBasisClient) UpdateOne(_m *ChargeCreditPurchaseCostBasis) *ChargeCreditPurchaseCostBasisUpdateOne { + mutation := newChargeCreditPurchaseCostBasisMutation(c.config, OpUpdateOne, withChargeCreditPurchaseCostBasis(_m)) + return &ChargeCreditPurchaseCostBasisUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ChargeCreditPurchaseCostBasisClient) UpdateOneID(id string) *ChargeCreditPurchaseCostBasisUpdateOne { + mutation := newChargeCreditPurchaseCostBasisMutation(c.config, OpUpdateOne, withChargeCreditPurchaseCostBasisID(id)) + return &ChargeCreditPurchaseCostBasisUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for ChargeCreditPurchaseCostBasis. +func (c *ChargeCreditPurchaseCostBasisClient) Delete() *ChargeCreditPurchaseCostBasisDelete { + mutation := newChargeCreditPurchaseCostBasisMutation(c.config, OpDelete) + return &ChargeCreditPurchaseCostBasisDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *ChargeCreditPurchaseCostBasisClient) DeleteOne(_m *ChargeCreditPurchaseCostBasis) *ChargeCreditPurchaseCostBasisDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *ChargeCreditPurchaseCostBasisClient) DeleteOneID(id string) *ChargeCreditPurchaseCostBasisDeleteOne { + builder := c.Delete().Where(chargecreditpurchasecostbasis.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ChargeCreditPurchaseCostBasisDeleteOne{builder} +} + +// Query returns a query builder for ChargeCreditPurchaseCostBasis. +func (c *ChargeCreditPurchaseCostBasisClient) Query() *ChargeCreditPurchaseCostBasisQuery { + return &ChargeCreditPurchaseCostBasisQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeChargeCreditPurchaseCostBasis}, + inters: c.Interceptors(), + } +} + +// Get returns a ChargeCreditPurchaseCostBasis entity by its id. +func (c *ChargeCreditPurchaseCostBasisClient) Get(ctx context.Context, id string) (*ChargeCreditPurchaseCostBasis, error) { + return c.Query().Where(chargecreditpurchasecostbasis.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ChargeCreditPurchaseCostBasisClient) GetX(ctx context.Context, id string) *ChargeCreditPurchaseCostBasis { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryCurrencyCostBasis queries the currency_cost_basis edge of a ChargeCreditPurchaseCostBasis. +func (c *ChargeCreditPurchaseCostBasisClient) QueryCurrencyCostBasis(_m *ChargeCreditPurchaseCostBasis) *CurrencyCostBasisQuery { + query := (&CurrencyCostBasisClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(chargecreditpurchasecostbasis.Table, chargecreditpurchasecostbasis.FieldID, id), + sqlgraph.To(currencycostbasis.Table, currencycostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargecreditpurchasecostbasis.CurrencyCostBasisTable, chargecreditpurchasecostbasis.CurrencyCostBasisColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryResolvedCurrencyCostBasis queries the resolved_currency_cost_basis edge of a ChargeCreditPurchaseCostBasis. +func (c *ChargeCreditPurchaseCostBasisClient) QueryResolvedCurrencyCostBasis(_m *ChargeCreditPurchaseCostBasis) *CurrencyCostBasisQuery { + query := (&CurrencyCostBasisClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(chargecreditpurchasecostbasis.Table, chargecreditpurchasecostbasis.FieldID, id), + sqlgraph.To(currencycostbasis.Table, currencycostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisTable, chargecreditpurchasecostbasis.ResolvedCurrencyCostBasisColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryCustomCurrency queries the custom_currency edge of a ChargeCreditPurchaseCostBasis. +func (c *ChargeCreditPurchaseCostBasisClient) QueryCustomCurrency(_m *ChargeCreditPurchaseCostBasis) *CustomCurrencyQuery { + query := (&CustomCurrencyClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(chargecreditpurchasecostbasis.Table, chargecreditpurchasecostbasis.FieldID, id), + sqlgraph.To(customcurrency.Table, customcurrency.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargecreditpurchasecostbasis.CustomCurrencyTable, chargecreditpurchasecostbasis.CustomCurrencyColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *ChargeCreditPurchaseCostBasisClient) Hooks() []Hook { + return c.hooks.ChargeCreditPurchaseCostBasis +} + +// Interceptors returns the client interceptors. +func (c *ChargeCreditPurchaseCostBasisClient) Interceptors() []Interceptor { + return c.inters.ChargeCreditPurchaseCostBasis +} + +func (c *ChargeCreditPurchaseCostBasisClient) mutate(ctx context.Context, m *ChargeCreditPurchaseCostBasisMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ChargeCreditPurchaseCostBasisCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ChargeCreditPurchaseCostBasisUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ChargeCreditPurchaseCostBasisUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ChargeCreditPurchaseCostBasisDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown ChargeCreditPurchaseCostBasis mutation op: %q", m.Op()) + } +} + // ChargeCreditPurchaseCreditGrantClient is a client for the ChargeCreditPurchaseCreditGrant schema. type ChargeCreditPurchaseCreditGrantClient struct { config @@ -6917,6 +7142,22 @@ func (c *ChargeFlatFeeClient) QueryCurrentRun(_m *ChargeFlatFee) *ChargeFlatFeeR return query } +// QueryCostBasis queries the cost_basis edge of a ChargeFlatFee. +func (c *ChargeFlatFeeClient) QueryCostBasis(_m *ChargeFlatFee) *ChargeFlatFeeCostBasisQuery { + query := (&ChargeFlatFeeCostBasisClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(chargeflatfee.Table, chargeflatfee.FieldID, id), + sqlgraph.To(chargeflatfeecostbasis.Table, chargeflatfeecostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeflatfee.CostBasisTable, chargeflatfee.CostBasisColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryCharge queries the charge edge of a ChargeFlatFee. func (c *ChargeFlatFeeClient) QueryCharge(_m *ChargeFlatFee) *ChargeQuery { query := (&ChargeClient{config: c.config}).Query() @@ -7086,6 +7327,187 @@ func (c *ChargeFlatFeeClient) mutate(ctx context.Context, m *ChargeFlatFeeMutati } } +// ChargeFlatFeeCostBasisClient is a client for the ChargeFlatFeeCostBasis schema. +type ChargeFlatFeeCostBasisClient struct { + config +} + +// NewChargeFlatFeeCostBasisClient returns a client for the ChargeFlatFeeCostBasis from the given config. +func NewChargeFlatFeeCostBasisClient(c config) *ChargeFlatFeeCostBasisClient { + return &ChargeFlatFeeCostBasisClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `chargeflatfeecostbasis.Hooks(f(g(h())))`. +func (c *ChargeFlatFeeCostBasisClient) Use(hooks ...Hook) { + c.hooks.ChargeFlatFeeCostBasis = append(c.hooks.ChargeFlatFeeCostBasis, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `chargeflatfeecostbasis.Intercept(f(g(h())))`. +func (c *ChargeFlatFeeCostBasisClient) Intercept(interceptors ...Interceptor) { + c.inters.ChargeFlatFeeCostBasis = append(c.inters.ChargeFlatFeeCostBasis, interceptors...) +} + +// Create returns a builder for creating a ChargeFlatFeeCostBasis entity. +func (c *ChargeFlatFeeCostBasisClient) Create() *ChargeFlatFeeCostBasisCreate { + mutation := newChargeFlatFeeCostBasisMutation(c.config, OpCreate) + return &ChargeFlatFeeCostBasisCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of ChargeFlatFeeCostBasis entities. +func (c *ChargeFlatFeeCostBasisClient) CreateBulk(builders ...*ChargeFlatFeeCostBasisCreate) *ChargeFlatFeeCostBasisCreateBulk { + return &ChargeFlatFeeCostBasisCreateBulk{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 *ChargeFlatFeeCostBasisClient) MapCreateBulk(slice any, setFunc func(*ChargeFlatFeeCostBasisCreate, int)) *ChargeFlatFeeCostBasisCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ChargeFlatFeeCostBasisCreateBulk{err: fmt.Errorf("calling to ChargeFlatFeeCostBasisClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ChargeFlatFeeCostBasisCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ChargeFlatFeeCostBasisCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for ChargeFlatFeeCostBasis. +func (c *ChargeFlatFeeCostBasisClient) Update() *ChargeFlatFeeCostBasisUpdate { + mutation := newChargeFlatFeeCostBasisMutation(c.config, OpUpdate) + return &ChargeFlatFeeCostBasisUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ChargeFlatFeeCostBasisClient) UpdateOne(_m *ChargeFlatFeeCostBasis) *ChargeFlatFeeCostBasisUpdateOne { + mutation := newChargeFlatFeeCostBasisMutation(c.config, OpUpdateOne, withChargeFlatFeeCostBasis(_m)) + return &ChargeFlatFeeCostBasisUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ChargeFlatFeeCostBasisClient) UpdateOneID(id string) *ChargeFlatFeeCostBasisUpdateOne { + mutation := newChargeFlatFeeCostBasisMutation(c.config, OpUpdateOne, withChargeFlatFeeCostBasisID(id)) + return &ChargeFlatFeeCostBasisUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for ChargeFlatFeeCostBasis. +func (c *ChargeFlatFeeCostBasisClient) Delete() *ChargeFlatFeeCostBasisDelete { + mutation := newChargeFlatFeeCostBasisMutation(c.config, OpDelete) + return &ChargeFlatFeeCostBasisDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *ChargeFlatFeeCostBasisClient) DeleteOne(_m *ChargeFlatFeeCostBasis) *ChargeFlatFeeCostBasisDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *ChargeFlatFeeCostBasisClient) DeleteOneID(id string) *ChargeFlatFeeCostBasisDeleteOne { + builder := c.Delete().Where(chargeflatfeecostbasis.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ChargeFlatFeeCostBasisDeleteOne{builder} +} + +// Query returns a query builder for ChargeFlatFeeCostBasis. +func (c *ChargeFlatFeeCostBasisClient) Query() *ChargeFlatFeeCostBasisQuery { + return &ChargeFlatFeeCostBasisQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeChargeFlatFeeCostBasis}, + inters: c.Interceptors(), + } +} + +// Get returns a ChargeFlatFeeCostBasis entity by its id. +func (c *ChargeFlatFeeCostBasisClient) Get(ctx context.Context, id string) (*ChargeFlatFeeCostBasis, error) { + return c.Query().Where(chargeflatfeecostbasis.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ChargeFlatFeeCostBasisClient) GetX(ctx context.Context, id string) *ChargeFlatFeeCostBasis { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryCurrencyCostBasis queries the currency_cost_basis edge of a ChargeFlatFeeCostBasis. +func (c *ChargeFlatFeeCostBasisClient) QueryCurrencyCostBasis(_m *ChargeFlatFeeCostBasis) *CurrencyCostBasisQuery { + query := (&CurrencyCostBasisClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(chargeflatfeecostbasis.Table, chargeflatfeecostbasis.FieldID, id), + sqlgraph.To(currencycostbasis.Table, currencycostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeflatfeecostbasis.CurrencyCostBasisTable, chargeflatfeecostbasis.CurrencyCostBasisColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryResolvedCurrencyCostBasis queries the resolved_currency_cost_basis edge of a ChargeFlatFeeCostBasis. +func (c *ChargeFlatFeeCostBasisClient) QueryResolvedCurrencyCostBasis(_m *ChargeFlatFeeCostBasis) *CurrencyCostBasisQuery { + query := (&CurrencyCostBasisClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(chargeflatfeecostbasis.Table, chargeflatfeecostbasis.FieldID, id), + sqlgraph.To(currencycostbasis.Table, currencycostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeflatfeecostbasis.ResolvedCurrencyCostBasisTable, chargeflatfeecostbasis.ResolvedCurrencyCostBasisColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryCustomCurrency queries the custom_currency edge of a ChargeFlatFeeCostBasis. +func (c *ChargeFlatFeeCostBasisClient) QueryCustomCurrency(_m *ChargeFlatFeeCostBasis) *CustomCurrencyQuery { + query := (&CustomCurrencyClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(chargeflatfeecostbasis.Table, chargeflatfeecostbasis.FieldID, id), + sqlgraph.To(customcurrency.Table, customcurrency.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeflatfeecostbasis.CustomCurrencyTable, chargeflatfeecostbasis.CustomCurrencyColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *ChargeFlatFeeCostBasisClient) Hooks() []Hook { + return c.hooks.ChargeFlatFeeCostBasis +} + +// Interceptors returns the client interceptors. +func (c *ChargeFlatFeeCostBasisClient) Interceptors() []Interceptor { + return c.inters.ChargeFlatFeeCostBasis +} + +func (c *ChargeFlatFeeCostBasisClient) mutate(ctx context.Context, m *ChargeFlatFeeCostBasisMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ChargeFlatFeeCostBasisCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ChargeFlatFeeCostBasisUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ChargeFlatFeeCostBasisUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ChargeFlatFeeCostBasisDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown ChargeFlatFeeCostBasis mutation op: %q", m.Op()) + } +} + // ChargeFlatFeeOverrideClient is a client for the ChargeFlatFeeOverride schema. type ChargeFlatFeeOverrideClient struct { config @@ -8312,6 +8734,22 @@ func (c *ChargeUsageBasedClient) QueryCurrentRun(_m *ChargeUsageBased) *ChargeUs return query } +// QueryCostBasis queries the cost_basis edge of a ChargeUsageBased. +func (c *ChargeUsageBasedClient) QueryCostBasis(_m *ChargeUsageBased) *ChargeUsageBasedCostBasisQuery { + query := (&ChargeUsageBasedCostBasisClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(chargeusagebased.Table, chargeusagebased.FieldID, id), + sqlgraph.To(chargeusagebasedcostbasis.Table, chargeusagebasedcostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeusagebased.CostBasisTable, chargeusagebased.CostBasisColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryCharge queries the charge edge of a ChargeUsageBased. func (c *ChargeUsageBasedClient) QueryCharge(_m *ChargeUsageBased) *ChargeQuery { query := (&ChargeClient{config: c.config}).Query() @@ -8481,6 +8919,187 @@ func (c *ChargeUsageBasedClient) mutate(ctx context.Context, m *ChargeUsageBased } } +// ChargeUsageBasedCostBasisClient is a client for the ChargeUsageBasedCostBasis schema. +type ChargeUsageBasedCostBasisClient struct { + config +} + +// NewChargeUsageBasedCostBasisClient returns a client for the ChargeUsageBasedCostBasis from the given config. +func NewChargeUsageBasedCostBasisClient(c config) *ChargeUsageBasedCostBasisClient { + return &ChargeUsageBasedCostBasisClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `chargeusagebasedcostbasis.Hooks(f(g(h())))`. +func (c *ChargeUsageBasedCostBasisClient) Use(hooks ...Hook) { + c.hooks.ChargeUsageBasedCostBasis = append(c.hooks.ChargeUsageBasedCostBasis, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `chargeusagebasedcostbasis.Intercept(f(g(h())))`. +func (c *ChargeUsageBasedCostBasisClient) Intercept(interceptors ...Interceptor) { + c.inters.ChargeUsageBasedCostBasis = append(c.inters.ChargeUsageBasedCostBasis, interceptors...) +} + +// Create returns a builder for creating a ChargeUsageBasedCostBasis entity. +func (c *ChargeUsageBasedCostBasisClient) Create() *ChargeUsageBasedCostBasisCreate { + mutation := newChargeUsageBasedCostBasisMutation(c.config, OpCreate) + return &ChargeUsageBasedCostBasisCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of ChargeUsageBasedCostBasis entities. +func (c *ChargeUsageBasedCostBasisClient) CreateBulk(builders ...*ChargeUsageBasedCostBasisCreate) *ChargeUsageBasedCostBasisCreateBulk { + return &ChargeUsageBasedCostBasisCreateBulk{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 *ChargeUsageBasedCostBasisClient) MapCreateBulk(slice any, setFunc func(*ChargeUsageBasedCostBasisCreate, int)) *ChargeUsageBasedCostBasisCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ChargeUsageBasedCostBasisCreateBulk{err: fmt.Errorf("calling to ChargeUsageBasedCostBasisClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ChargeUsageBasedCostBasisCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ChargeUsageBasedCostBasisCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for ChargeUsageBasedCostBasis. +func (c *ChargeUsageBasedCostBasisClient) Update() *ChargeUsageBasedCostBasisUpdate { + mutation := newChargeUsageBasedCostBasisMutation(c.config, OpUpdate) + return &ChargeUsageBasedCostBasisUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ChargeUsageBasedCostBasisClient) UpdateOne(_m *ChargeUsageBasedCostBasis) *ChargeUsageBasedCostBasisUpdateOne { + mutation := newChargeUsageBasedCostBasisMutation(c.config, OpUpdateOne, withChargeUsageBasedCostBasis(_m)) + return &ChargeUsageBasedCostBasisUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ChargeUsageBasedCostBasisClient) UpdateOneID(id string) *ChargeUsageBasedCostBasisUpdateOne { + mutation := newChargeUsageBasedCostBasisMutation(c.config, OpUpdateOne, withChargeUsageBasedCostBasisID(id)) + return &ChargeUsageBasedCostBasisUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for ChargeUsageBasedCostBasis. +func (c *ChargeUsageBasedCostBasisClient) Delete() *ChargeUsageBasedCostBasisDelete { + mutation := newChargeUsageBasedCostBasisMutation(c.config, OpDelete) + return &ChargeUsageBasedCostBasisDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *ChargeUsageBasedCostBasisClient) DeleteOne(_m *ChargeUsageBasedCostBasis) *ChargeUsageBasedCostBasisDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *ChargeUsageBasedCostBasisClient) DeleteOneID(id string) *ChargeUsageBasedCostBasisDeleteOne { + builder := c.Delete().Where(chargeusagebasedcostbasis.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ChargeUsageBasedCostBasisDeleteOne{builder} +} + +// Query returns a query builder for ChargeUsageBasedCostBasis. +func (c *ChargeUsageBasedCostBasisClient) Query() *ChargeUsageBasedCostBasisQuery { + return &ChargeUsageBasedCostBasisQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeChargeUsageBasedCostBasis}, + inters: c.Interceptors(), + } +} + +// Get returns a ChargeUsageBasedCostBasis entity by its id. +func (c *ChargeUsageBasedCostBasisClient) Get(ctx context.Context, id string) (*ChargeUsageBasedCostBasis, error) { + return c.Query().Where(chargeusagebasedcostbasis.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ChargeUsageBasedCostBasisClient) GetX(ctx context.Context, id string) *ChargeUsageBasedCostBasis { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryCurrencyCostBasis queries the currency_cost_basis edge of a ChargeUsageBasedCostBasis. +func (c *ChargeUsageBasedCostBasisClient) QueryCurrencyCostBasis(_m *ChargeUsageBasedCostBasis) *CurrencyCostBasisQuery { + query := (&CurrencyCostBasisClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(chargeusagebasedcostbasis.Table, chargeusagebasedcostbasis.FieldID, id), + sqlgraph.To(currencycostbasis.Table, currencycostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeusagebasedcostbasis.CurrencyCostBasisTable, chargeusagebasedcostbasis.CurrencyCostBasisColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryResolvedCurrencyCostBasis queries the resolved_currency_cost_basis edge of a ChargeUsageBasedCostBasis. +func (c *ChargeUsageBasedCostBasisClient) QueryResolvedCurrencyCostBasis(_m *ChargeUsageBasedCostBasis) *CurrencyCostBasisQuery { + query := (&CurrencyCostBasisClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(chargeusagebasedcostbasis.Table, chargeusagebasedcostbasis.FieldID, id), + sqlgraph.To(currencycostbasis.Table, currencycostbasis.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeusagebasedcostbasis.ResolvedCurrencyCostBasisTable, chargeusagebasedcostbasis.ResolvedCurrencyCostBasisColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryCustomCurrency queries the custom_currency edge of a ChargeUsageBasedCostBasis. +func (c *ChargeUsageBasedCostBasisClient) QueryCustomCurrency(_m *ChargeUsageBasedCostBasis) *CustomCurrencyQuery { + query := (&CustomCurrencyClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(chargeusagebasedcostbasis.Table, chargeusagebasedcostbasis.FieldID, id), + sqlgraph.To(customcurrency.Table, customcurrency.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, chargeusagebasedcostbasis.CustomCurrencyTable, chargeusagebasedcostbasis.CustomCurrencyColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *ChargeUsageBasedCostBasisClient) Hooks() []Hook { + return c.hooks.ChargeUsageBasedCostBasis +} + +// Interceptors returns the client interceptors. +func (c *ChargeUsageBasedCostBasisClient) Interceptors() []Interceptor { + return c.inters.ChargeUsageBasedCostBasis +} + +func (c *ChargeUsageBasedCostBasisClient) mutate(ctx context.Context, m *ChargeUsageBasedCostBasisMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ChargeUsageBasedCostBasisCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ChargeUsageBasedCostBasisUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ChargeUsageBasedCostBasisUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ChargeUsageBasedCostBasisDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown ChargeUsageBasedCostBasis mutation op: %q", m.Op()) + } +} + // ChargeUsageBasedOverrideClient is a client for the ChargeUsageBasedOverride schema. type ChargeUsageBasedOverrideClient struct { config @@ -16775,11 +17394,12 @@ type ( BillingInvoiceValidationIssue, BillingInvoiceWriteSchemaLevel, BillingProfile, BillingSequenceNumbers, BillingStandardInvoiceDetailedLine, BillingStandardInvoiceDetailedLineAmountDiscount, BillingWorkflowConfig, - Charge, ChargeCreditPurchase, ChargeCreditPurchaseCreditGrant, - ChargeCreditPurchaseExternalPayment, ChargeCreditPurchaseInvoicedPayment, - ChargeFlatFee, ChargeFlatFeeOverride, ChargeFlatFeeRun, - ChargeFlatFeeRunCreditAllocations, ChargeFlatFeeRunDetailedLine, - ChargeFlatFeeRunInvoicedUsage, ChargeFlatFeeRunPayment, ChargeUsageBased, + Charge, ChargeCreditPurchase, ChargeCreditPurchaseCostBasis, + ChargeCreditPurchaseCreditGrant, ChargeCreditPurchaseExternalPayment, + ChargeCreditPurchaseInvoicedPayment, ChargeFlatFee, ChargeFlatFeeCostBasis, + ChargeFlatFeeOverride, ChargeFlatFeeRun, ChargeFlatFeeRunCreditAllocations, + ChargeFlatFeeRunDetailedLine, ChargeFlatFeeRunInvoicedUsage, + ChargeFlatFeeRunPayment, ChargeUsageBased, ChargeUsageBasedCostBasis, ChargeUsageBasedOverride, ChargeUsageBasedRunCreditAllocations, ChargeUsageBasedRunDetailedLine, ChargeUsageBasedRunInvoicedUsage, ChargeUsageBasedRunPayment, ChargeUsageBasedRuns, CreditRealizationLineage, @@ -16803,11 +17423,12 @@ type ( BillingInvoiceValidationIssue, BillingInvoiceWriteSchemaLevel, BillingProfile, BillingSequenceNumbers, BillingStandardInvoiceDetailedLine, BillingStandardInvoiceDetailedLineAmountDiscount, BillingWorkflowConfig, - Charge, ChargeCreditPurchase, ChargeCreditPurchaseCreditGrant, - ChargeCreditPurchaseExternalPayment, ChargeCreditPurchaseInvoicedPayment, - ChargeFlatFee, ChargeFlatFeeOverride, ChargeFlatFeeRun, - ChargeFlatFeeRunCreditAllocations, ChargeFlatFeeRunDetailedLine, - ChargeFlatFeeRunInvoicedUsage, ChargeFlatFeeRunPayment, ChargeUsageBased, + Charge, ChargeCreditPurchase, ChargeCreditPurchaseCostBasis, + ChargeCreditPurchaseCreditGrant, ChargeCreditPurchaseExternalPayment, + ChargeCreditPurchaseInvoicedPayment, ChargeFlatFee, ChargeFlatFeeCostBasis, + ChargeFlatFeeOverride, ChargeFlatFeeRun, ChargeFlatFeeRunCreditAllocations, + ChargeFlatFeeRunDetailedLine, ChargeFlatFeeRunInvoicedUsage, + ChargeFlatFeeRunPayment, ChargeUsageBased, ChargeUsageBasedCostBasis, ChargeUsageBasedOverride, ChargeUsageBasedRunCreditAllocations, ChargeUsageBasedRunDetailedLine, ChargeUsageBasedRunInvoicedUsage, ChargeUsageBasedRunPayment, ChargeUsageBasedRuns, ChargesSearchV1, diff --git a/openmeter/ent/db/cursor.go b/openmeter/ent/db/cursor.go index a4e7145586..72b2f38a20 100644 --- a/openmeter/ent/db/cursor.go +++ b/openmeter/ent/db/cursor.go @@ -1184,6 +1184,57 @@ func (_m *ChargeCreditPurchaseQuery) Cursor(ctx context.Context, cursor *paginat return result, nil } +// Cursor runs the query and returns a cursor-paginated response. +// Ordering is always by created_at asc, id asc. +func (_m *ChargeCreditPurchaseCostBasisQuery) Cursor(ctx context.Context, cursor *pagination.Cursor) (pagination.Result[*ChargeCreditPurchaseCostBasis], error) { + if cursor != nil { + if err := cursor.Validate(); err != nil { + return pagination.Result[*ChargeCreditPurchaseCostBasis]{}, 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[*ChargeCreditPurchaseCostBasis]{}, err + } + + if items == nil { + items = make([]*ChargeCreditPurchaseCostBasis, 0) + } + + result := pagination.Result[*ChargeCreditPurchaseCostBasis]{ + 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 *ChargeCreditPurchaseCreditGrantQuery) Cursor(ctx context.Context, cursor *pagination.Cursor) (pagination.Result[*ChargeCreditPurchaseCreditGrant], error) { @@ -1388,6 +1439,57 @@ func (_m *ChargeFlatFeeQuery) Cursor(ctx context.Context, cursor *pagination.Cur return result, nil } +// Cursor runs the query and returns a cursor-paginated response. +// Ordering is always by created_at asc, id asc. +func (_m *ChargeFlatFeeCostBasisQuery) Cursor(ctx context.Context, cursor *pagination.Cursor) (pagination.Result[*ChargeFlatFeeCostBasis], error) { + if cursor != nil { + if err := cursor.Validate(); err != nil { + return pagination.Result[*ChargeFlatFeeCostBasis]{}, 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[*ChargeFlatFeeCostBasis]{}, err + } + + if items == nil { + items = make([]*ChargeFlatFeeCostBasis, 0) + } + + result := pagination.Result[*ChargeFlatFeeCostBasis]{ + 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 *ChargeFlatFeeRunQuery) Cursor(ctx context.Context, cursor *pagination.Cursor) (pagination.Result[*ChargeFlatFeeRun], error) { @@ -1694,6 +1796,57 @@ func (_m *ChargeUsageBasedQuery) Cursor(ctx context.Context, cursor *pagination. return result, nil } +// Cursor runs the query and returns a cursor-paginated response. +// Ordering is always by created_at asc, id asc. +func (_m *ChargeUsageBasedCostBasisQuery) Cursor(ctx context.Context, cursor *pagination.Cursor) (pagination.Result[*ChargeUsageBasedCostBasis], error) { + if cursor != nil { + if err := cursor.Validate(); err != nil { + return pagination.Result[*ChargeUsageBasedCostBasis]{}, 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[*ChargeUsageBasedCostBasis]{}, err + } + + if items == nil { + items = make([]*ChargeUsageBasedCostBasis, 0) + } + + result := pagination.Result[*ChargeUsageBasedCostBasis]{ + 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 *ChargeUsageBasedRunCreditAllocationsQuery) Cursor(ctx context.Context, cursor *pagination.Cursor) (pagination.Result[*ChargeUsageBasedRunCreditAllocations], error) { diff --git a/openmeter/ent/db/ent.go b/openmeter/ent/db/ent.go index 72c7b11c54..58d5ee0341 100644 --- a/openmeter/ent/db/ent.go +++ b/openmeter/ent/db/ent.go @@ -41,10 +41,12 @@ import ( "github.com/openmeterio/openmeter/openmeter/ent/db/billingworkflowconfig" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecreditgrant" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseexternalpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseinvoicedpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfee" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeerun" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeruncreditallocations" @@ -53,6 +55,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeerunpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargessearchv1" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebased" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedcostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedruncreditallocations" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedrundetailedline" @@ -189,10 +192,12 @@ func checkColumn(t, c string) error { billingworkflowconfig.Table: billingworkflowconfig.ValidColumn, charge.Table: charge.ValidColumn, chargecreditpurchase.Table: chargecreditpurchase.ValidColumn, + chargecreditpurchasecostbasis.Table: chargecreditpurchasecostbasis.ValidColumn, chargecreditpurchasecreditgrant.Table: chargecreditpurchasecreditgrant.ValidColumn, chargecreditpurchaseexternalpayment.Table: chargecreditpurchaseexternalpayment.ValidColumn, chargecreditpurchaseinvoicedpayment.Table: chargecreditpurchaseinvoicedpayment.ValidColumn, chargeflatfee.Table: chargeflatfee.ValidColumn, + chargeflatfeecostbasis.Table: chargeflatfeecostbasis.ValidColumn, chargeflatfeeoverride.Table: chargeflatfeeoverride.ValidColumn, chargeflatfeerun.Table: chargeflatfeerun.ValidColumn, chargeflatfeeruncreditallocations.Table: chargeflatfeeruncreditallocations.ValidColumn, @@ -200,6 +205,7 @@ func checkColumn(t, c string) error { chargeflatfeeruninvoicedusage.Table: chargeflatfeeruninvoicedusage.ValidColumn, chargeflatfeerunpayment.Table: chargeflatfeerunpayment.ValidColumn, chargeusagebased.Table: chargeusagebased.ValidColumn, + chargeusagebasedcostbasis.Table: chargeusagebasedcostbasis.ValidColumn, chargeusagebasedoverride.Table: chargeusagebasedoverride.ValidColumn, chargeusagebasedruncreditallocations.Table: chargeusagebasedruncreditallocations.ValidColumn, chargeusagebasedrundetailedline.Table: chargeusagebasedrundetailedline.ValidColumn, diff --git a/openmeter/ent/db/entmixinaccessor.go b/openmeter/ent/db/entmixinaccessor.go index 022343dfb9..98635780eb 100644 --- a/openmeter/ent/db/entmixinaccessor.go +++ b/openmeter/ent/db/entmixinaccessor.go @@ -8,6 +8,7 @@ import ( "github.com/alpacahq/alpacadecimal" "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/creditrealization" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/payment" "github.com/openmeterio/openmeter/openmeter/billing/models/creditsapplied" @@ -1097,6 +1098,58 @@ func (e *ChargeCreditPurchase) GetDescription() *string { return e.Description } +func (e *ChargeCreditPurchaseCostBasis) GetID() string { + return e.ID +} + +func (e *ChargeCreditPurchaseCostBasis) GetMode() costbasis.Mode { + return e.Mode +} + +func (e *ChargeCreditPurchaseCostBasis) GetFiatCurrency() currencyx.FiatCode { + return e.FiatCurrency +} + +func (e *ChargeCreditPurchaseCostBasis) GetCurrencyCostBasisID() *string { + return e.CurrencyCostBasisID +} + +func (e *ChargeCreditPurchaseCostBasis) GetResolvedCostBasisID() *string { + return e.ResolvedCostBasisID +} + +func (e *ChargeCreditPurchaseCostBasis) GetCurrencyID() string { + return e.CurrencyID +} + +func (e *ChargeCreditPurchaseCostBasis) GetManualRate() *alpacadecimal.Decimal { + return e.ManualRate +} + +func (e *ChargeCreditPurchaseCostBasis) GetResolvedCostBasis() *alpacadecimal.Decimal { + return e.ResolvedCostBasis +} + +func (e *ChargeCreditPurchaseCostBasis) GetResolvedAt() *time.Time { + return e.ResolvedAt +} + +func (e *ChargeCreditPurchaseCostBasis) GetNamespace() string { + return e.Namespace +} + +func (e *ChargeCreditPurchaseCostBasis) GetCreatedAt() time.Time { + return e.CreatedAt +} + +func (e *ChargeCreditPurchaseCostBasis) GetUpdatedAt() time.Time { + return e.UpdatedAt +} + +func (e *ChargeCreditPurchaseCostBasis) GetDeletedAt() *time.Time { + return e.DeletedAt +} + func (e *ChargeCreditPurchaseCreditGrant) GetID() string { return e.ID } @@ -1345,6 +1398,58 @@ func (e *ChargeFlatFee) GetDescription() *string { return e.Description } +func (e *ChargeFlatFeeCostBasis) GetID() string { + return e.ID +} + +func (e *ChargeFlatFeeCostBasis) GetMode() costbasis.Mode { + return e.Mode +} + +func (e *ChargeFlatFeeCostBasis) GetFiatCurrency() currencyx.FiatCode { + return e.FiatCurrency +} + +func (e *ChargeFlatFeeCostBasis) GetCurrencyCostBasisID() *string { + return e.CurrencyCostBasisID +} + +func (e *ChargeFlatFeeCostBasis) GetResolvedCostBasisID() *string { + return e.ResolvedCostBasisID +} + +func (e *ChargeFlatFeeCostBasis) GetCurrencyID() string { + return e.CurrencyID +} + +func (e *ChargeFlatFeeCostBasis) GetManualRate() *alpacadecimal.Decimal { + return e.ManualRate +} + +func (e *ChargeFlatFeeCostBasis) GetResolvedCostBasis() *alpacadecimal.Decimal { + return e.ResolvedCostBasis +} + +func (e *ChargeFlatFeeCostBasis) GetResolvedAt() *time.Time { + return e.ResolvedAt +} + +func (e *ChargeFlatFeeCostBasis) GetNamespace() string { + return e.Namespace +} + +func (e *ChargeFlatFeeCostBasis) GetCreatedAt() time.Time { + return e.CreatedAt +} + +func (e *ChargeFlatFeeCostBasis) GetUpdatedAt() time.Time { + return e.UpdatedAt +} + +func (e *ChargeFlatFeeCostBasis) GetDeletedAt() *time.Time { + return e.DeletedAt +} + func (e *ChargeFlatFeeOverride) GetID() string { return e.ID } @@ -1813,6 +1918,58 @@ func (e *ChargeUsageBased) GetDescription() *string { return e.Description } +func (e *ChargeUsageBasedCostBasis) GetID() string { + return e.ID +} + +func (e *ChargeUsageBasedCostBasis) GetMode() costbasis.Mode { + return e.Mode +} + +func (e *ChargeUsageBasedCostBasis) GetFiatCurrency() currencyx.FiatCode { + return e.FiatCurrency +} + +func (e *ChargeUsageBasedCostBasis) GetCurrencyCostBasisID() *string { + return e.CurrencyCostBasisID +} + +func (e *ChargeUsageBasedCostBasis) GetResolvedCostBasisID() *string { + return e.ResolvedCostBasisID +} + +func (e *ChargeUsageBasedCostBasis) GetCurrencyID() string { + return e.CurrencyID +} + +func (e *ChargeUsageBasedCostBasis) GetManualRate() *alpacadecimal.Decimal { + return e.ManualRate +} + +func (e *ChargeUsageBasedCostBasis) GetResolvedCostBasis() *alpacadecimal.Decimal { + return e.ResolvedCostBasis +} + +func (e *ChargeUsageBasedCostBasis) GetResolvedAt() *time.Time { + return e.ResolvedAt +} + +func (e *ChargeUsageBasedCostBasis) GetNamespace() string { + return e.Namespace +} + +func (e *ChargeUsageBasedCostBasis) GetCreatedAt() time.Time { + return e.CreatedAt +} + +func (e *ChargeUsageBasedCostBasis) GetUpdatedAt() time.Time { + return e.UpdatedAt +} + +func (e *ChargeUsageBasedCostBasis) GetDeletedAt() *time.Time { + return e.DeletedAt +} + func (e *ChargeUsageBasedOverride) GetID() string { return e.ID } diff --git a/openmeter/ent/db/expose.go b/openmeter/ent/db/expose.go index 08ca187a4b..fdd1c4e099 100644 --- a/openmeter/ent/db/expose.go +++ b/openmeter/ent/db/expose.go @@ -145,6 +145,8 @@ func NewTxClientFromRawConfig(ctx context.Context, cfg entutils.RawEntConfig) *T ChargeCreditPurchase: NewChargeCreditPurchaseClient(config), + ChargeCreditPurchaseCostBasis: NewChargeCreditPurchaseCostBasisClient(config), + ChargeCreditPurchaseCreditGrant: NewChargeCreditPurchaseCreditGrantClient(config), ChargeCreditPurchaseExternalPayment: NewChargeCreditPurchaseExternalPaymentClient(config), @@ -153,6 +155,8 @@ func NewTxClientFromRawConfig(ctx context.Context, cfg entutils.RawEntConfig) *T ChargeFlatFee: NewChargeFlatFeeClient(config), + ChargeFlatFeeCostBasis: NewChargeFlatFeeCostBasisClient(config), + ChargeFlatFeeOverride: NewChargeFlatFeeOverrideClient(config), ChargeFlatFeeRun: NewChargeFlatFeeRunClient(config), @@ -167,6 +171,8 @@ func NewTxClientFromRawConfig(ctx context.Context, cfg entutils.RawEntConfig) *T ChargeUsageBased: NewChargeUsageBasedClient(config), + ChargeUsageBasedCostBasis: NewChargeUsageBasedCostBasisClient(config), + ChargeUsageBasedOverride: NewChargeUsageBasedOverrideClient(config), ChargeUsageBasedRunCreditAllocations: NewChargeUsageBasedRunCreditAllocationsClient(config), diff --git a/openmeter/ent/db/hook/hook.go b/openmeter/ent/db/hook/hook.go index 77aa9eaafc..0095fc33af 100644 --- a/openmeter/ent/db/hook/hook.go +++ b/openmeter/ent/db/hook/hook.go @@ -345,6 +345,18 @@ func (f ChargeCreditPurchaseFunc) Mutate(ctx context.Context, m db.Mutation) (db return nil, fmt.Errorf("unexpected mutation type %T. expect *db.ChargeCreditPurchaseMutation", m) } +// The ChargeCreditPurchaseCostBasisFunc type is an adapter to allow the use of ordinary +// function as ChargeCreditPurchaseCostBasis mutator. +type ChargeCreditPurchaseCostBasisFunc func(context.Context, *db.ChargeCreditPurchaseCostBasisMutation) (db.Value, error) + +// Mutate calls f(ctx, m). +func (f ChargeCreditPurchaseCostBasisFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { + if mv, ok := m.(*db.ChargeCreditPurchaseCostBasisMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.ChargeCreditPurchaseCostBasisMutation", m) +} + // The ChargeCreditPurchaseCreditGrantFunc type is an adapter to allow the use of ordinary // function as ChargeCreditPurchaseCreditGrant mutator. type ChargeCreditPurchaseCreditGrantFunc func(context.Context, *db.ChargeCreditPurchaseCreditGrantMutation) (db.Value, error) @@ -393,6 +405,18 @@ func (f ChargeFlatFeeFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, return nil, fmt.Errorf("unexpected mutation type %T. expect *db.ChargeFlatFeeMutation", m) } +// The ChargeFlatFeeCostBasisFunc type is an adapter to allow the use of ordinary +// function as ChargeFlatFeeCostBasis mutator. +type ChargeFlatFeeCostBasisFunc func(context.Context, *db.ChargeFlatFeeCostBasisMutation) (db.Value, error) + +// Mutate calls f(ctx, m). +func (f ChargeFlatFeeCostBasisFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { + if mv, ok := m.(*db.ChargeFlatFeeCostBasisMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.ChargeFlatFeeCostBasisMutation", m) +} + // The ChargeFlatFeeOverrideFunc type is an adapter to allow the use of ordinary // function as ChargeFlatFeeOverride mutator. type ChargeFlatFeeOverrideFunc func(context.Context, *db.ChargeFlatFeeOverrideMutation) (db.Value, error) @@ -477,6 +501,18 @@ func (f ChargeUsageBasedFunc) Mutate(ctx context.Context, m db.Mutation) (db.Val return nil, fmt.Errorf("unexpected mutation type %T. expect *db.ChargeUsageBasedMutation", m) } +// The ChargeUsageBasedCostBasisFunc type is an adapter to allow the use of ordinary +// function as ChargeUsageBasedCostBasis mutator. +type ChargeUsageBasedCostBasisFunc func(context.Context, *db.ChargeUsageBasedCostBasisMutation) (db.Value, error) + +// Mutate calls f(ctx, m). +func (f ChargeUsageBasedCostBasisFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { + if mv, ok := m.(*db.ChargeUsageBasedCostBasisMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.ChargeUsageBasedCostBasisMutation", m) +} + // The ChargeUsageBasedOverrideFunc type is an adapter to allow the use of ordinary // function as ChargeUsageBasedOverride mutator. type ChargeUsageBasedOverrideFunc func(context.Context, *db.ChargeUsageBasedOverrideMutation) (db.Value, error) diff --git a/openmeter/ent/db/migrate/schema.go b/openmeter/ent/db/migrate/schema.go index 48c30189be..a2a15bd68c 100644 --- a/openmeter/ent/db/migrate/schema.go +++ b/openmeter/ent/db/migrate/schema.go @@ -1796,6 +1796,7 @@ var ( {Name: "status_detailed", Type: field.TypeEnum, Enums: []string{"created", "active", "active.initial_credit_grant", "active.payment.pending", "active.payment.authorized", "active.payment.paid_and_authorized", "active.payment.settled", "final", "deleted"}}, {Name: "key", Type: field.TypeString, Nullable: true}, {Name: "voided_at", Type: field.TypeTime, Nullable: true}, + {Name: "cost_basis_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "custom_currency_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "customer_id", Type: field.TypeString, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "subscription_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, @@ -1810,38 +1811,44 @@ var ( PrimaryKey: []*schema.Column{ChargeCreditPurchasesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { - Symbol: "charge_credit_purchases_custom_currencies_charges_credit_purchase", + Symbol: "charge_credit_purchase_cost_basis_charge_fk", Columns: []*schema.Column{ChargeCreditPurchasesColumns[30]}, + RefColumns: []*schema.Column{ChargeCreditPurchaseCostBasesColumns[0]}, + OnDelete: schema.Cascade, + }, + { + Symbol: "charge_credit_purchases_custom_currencies_charges_credit_purchase", + Columns: []*schema.Column{ChargeCreditPurchasesColumns[31]}, RefColumns: []*schema.Column{CustomCurrenciesColumns[0]}, OnDelete: schema.Restrict, }, { Symbol: "charge_credit_purchases_customers_charges_credit_purchase", - Columns: []*schema.Column{ChargeCreditPurchasesColumns[31]}, + Columns: []*schema.Column{ChargeCreditPurchasesColumns[32]}, RefColumns: []*schema.Column{CustomersColumns[0]}, OnDelete: schema.NoAction, }, { Symbol: "charge_credit_purchases_subscriptions_charges_credit_purchase", - Columns: []*schema.Column{ChargeCreditPurchasesColumns[32]}, + Columns: []*schema.Column{ChargeCreditPurchasesColumns[33]}, RefColumns: []*schema.Column{SubscriptionsColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "charge_credit_purchases_subscription_items_charges_credit_purchase", - Columns: []*schema.Column{ChargeCreditPurchasesColumns[33]}, + Columns: []*schema.Column{ChargeCreditPurchasesColumns[34]}, RefColumns: []*schema.Column{SubscriptionItemsColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "charge_credit_purchases_subscription_phases_charges_credit_purchase", - Columns: []*schema.Column{ChargeCreditPurchasesColumns[34]}, + Columns: []*schema.Column{ChargeCreditPurchasesColumns[35]}, RefColumns: []*schema.Column{SubscriptionPhasesColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "charge_credit_purchases_tax_codes_charge_credit_purchases", - Columns: []*schema.Column{ChargeCreditPurchasesColumns[35]}, + Columns: []*schema.Column{ChargeCreditPurchasesColumns[36]}, RefColumns: []*schema.Column{TaxCodesColumns[0]}, OnDelete: schema.NoAction, }, @@ -1850,7 +1857,7 @@ var ( { Name: "chargecreditpurchase_namespace_customer_id_unique_reference_id", Unique: true, - Columns: []*schema.Column{ChargeCreditPurchasesColumns[14], ChargeCreditPurchasesColumns[31], ChargeCreditPurchasesColumns[8]}, + Columns: []*schema.Column{ChargeCreditPurchasesColumns[14], ChargeCreditPurchasesColumns[32], ChargeCreditPurchasesColumns[8]}, Annotation: &entsql.IndexAnnotation{ Where: "unique_reference_id IS NOT NULL AND deleted_at IS NULL", }, @@ -1883,18 +1890,87 @@ var ( { Name: "chargecreditpurchases_tax_code_id", Unique: false, - Columns: []*schema.Column{ChargeCreditPurchasesColumns[35]}, + Columns: []*schema.Column{ChargeCreditPurchasesColumns[36]}, }, { Name: "chargecreditpurchase_namespace_customer_id_key", Unique: true, - Columns: []*schema.Column{ChargeCreditPurchasesColumns[14], ChargeCreditPurchasesColumns[31], ChargeCreditPurchasesColumns[28]}, + Columns: []*schema.Column{ChargeCreditPurchasesColumns[14], ChargeCreditPurchasesColumns[32], ChargeCreditPurchasesColumns[28]}, Annotation: &entsql.IndexAnnotation{ Where: "key IS NOT NULL AND deleted_at IS NULL", }, }, }, } + // ChargeCreditPurchaseCostBasesColumns holds the columns for the "charge_credit_purchase_cost_bases" table. + ChargeCreditPurchaseCostBasesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeString, Unique: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "mode", Type: field.TypeEnum, Enums: []string{"dynamic", "pinned", "manual"}}, + {Name: "fiat_currency", Type: field.TypeString, SchemaType: map[string]string{"postgres": "varchar(3)"}}, + {Name: "manual_rate", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "numeric"}}, + {Name: "resolved_cost_basis", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "numeric"}}, + {Name: "resolved_at", Type: field.TypeTime, Nullable: true}, + {Name: "namespace", Type: field.TypeString}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "deleted_at", Type: field.TypeTime, Nullable: true}, + {Name: "currency_cost_basis_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "resolved_cost_basis_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "currency_id", Type: field.TypeString, SchemaType: map[string]string{"postgres": "char(26)"}}, + } + // ChargeCreditPurchaseCostBasesTable holds the schema information for the "charge_credit_purchase_cost_bases" table. + ChargeCreditPurchaseCostBasesTable = &schema.Table{ + Name: "charge_credit_purchase_cost_bases", + Columns: ChargeCreditPurchaseCostBasesColumns, + PrimaryKey: []*schema.Column{ChargeCreditPurchaseCostBasesColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "charge_credit_purchase_cost_basis_currency_cost_basis_fk", + Columns: []*schema.Column{ChargeCreditPurchaseCostBasesColumns[10]}, + RefColumns: []*schema.Column{CurrencyCostBasesColumns[0]}, + OnDelete: schema.Restrict, + }, + { + Symbol: "charge_credit_purchase_cost_basis_resolved_cost_basis_fk", + Columns: []*schema.Column{ChargeCreditPurchaseCostBasesColumns[11]}, + RefColumns: []*schema.Column{CurrencyCostBasesColumns[0]}, + OnDelete: schema.Restrict, + }, + { + Symbol: "charge_credit_purchase_cost_basis_currency_fk", + Columns: []*schema.Column{ChargeCreditPurchaseCostBasesColumns[12]}, + RefColumns: []*schema.Column{CustomCurrenciesColumns[0]}, + OnDelete: schema.Restrict, + }, + }, + Indexes: []*schema.Index{ + { + Name: "chargecreditpurchasecostbasis_currency_cost_basis_id", + Unique: false, + Columns: []*schema.Column{ChargeCreditPurchaseCostBasesColumns[10]}, + }, + { + Name: "chargecreditpurchasecostbasis_resolved_cost_basis_id", + Unique: false, + Columns: []*schema.Column{ChargeCreditPurchaseCostBasesColumns[11]}, + }, + { + Name: "chargecreditpurchasecostbasis_currency_id", + Unique: false, + Columns: []*schema.Column{ChargeCreditPurchaseCostBasesColumns[12]}, + }, + { + Name: "chargecreditpurchasecostbasis_namespace", + Unique: false, + Columns: []*schema.Column{ChargeCreditPurchaseCostBasesColumns[6]}, + }, + { + Name: "chargecreditpurchasecostbasis_id", + Unique: true, + Columns: []*schema.Column{ChargeCreditPurchaseCostBasesColumns[0]}, + }, + }, + } // ChargeCreditPurchaseCreditGrantsColumns holds the columns for the "charge_credit_purchase_credit_grants" table. ChargeCreditPurchaseCreditGrantsColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true, SchemaType: map[string]string{"postgres": "char(26)"}}, @@ -2092,6 +2168,7 @@ var ( {Name: "amount_after_proration", Type: field.TypeOther, SchemaType: map[string]string{"postgres": "numeric"}}, {Name: "status_detailed", Type: field.TypeEnum, Enums: []string{"created", "active", "active.realization.started", "active.realization.waiting_for_collection", "active.realization.processing", "active.realization.issuing", "active.realization.completed", "active.awaiting_payment_settlement", "final", "deleted"}}, {Name: "current_realization_run_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "cost_basis_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "custom_currency_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "customer_id", Type: field.TypeString, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "feature_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, @@ -2113,44 +2190,50 @@ var ( OnDelete: schema.SetNull, }, { - Symbol: "charge_flat_fees_custom_currencies_charges_flat_fee", + Symbol: "charge_flat_fee_cost_basis_charge_fk", Columns: []*schema.Column{ChargeFlatFeesColumns[32]}, + RefColumns: []*schema.Column{ChargeFlatFeeCostBasesColumns[0]}, + OnDelete: schema.Cascade, + }, + { + Symbol: "charge_flat_fees_custom_currencies_charges_flat_fee", + Columns: []*schema.Column{ChargeFlatFeesColumns[33]}, RefColumns: []*schema.Column{CustomCurrenciesColumns[0]}, OnDelete: schema.Restrict, }, { Symbol: "charge_flat_fees_customers_charges_flat_fee", - Columns: []*schema.Column{ChargeFlatFeesColumns[33]}, + Columns: []*schema.Column{ChargeFlatFeesColumns[34]}, RefColumns: []*schema.Column{CustomersColumns[0]}, OnDelete: schema.NoAction, }, { Symbol: "charge_flat_fees_features_flat_fee_charges", - Columns: []*schema.Column{ChargeFlatFeesColumns[34]}, + Columns: []*schema.Column{ChargeFlatFeesColumns[35]}, RefColumns: []*schema.Column{FeaturesColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "charge_flat_fees_subscriptions_charges_flat_fee", - Columns: []*schema.Column{ChargeFlatFeesColumns[35]}, + Columns: []*schema.Column{ChargeFlatFeesColumns[36]}, RefColumns: []*schema.Column{SubscriptionsColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "charge_flat_fees_subscription_items_charges_flat_fee", - Columns: []*schema.Column{ChargeFlatFeesColumns[36]}, + Columns: []*schema.Column{ChargeFlatFeesColumns[37]}, RefColumns: []*schema.Column{SubscriptionItemsColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "charge_flat_fees_subscription_phases_charges_flat_fee", - Columns: []*schema.Column{ChargeFlatFeesColumns[37]}, + Columns: []*schema.Column{ChargeFlatFeesColumns[38]}, RefColumns: []*schema.Column{SubscriptionPhasesColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "charge_flat_fees_tax_codes_charge_flat_fees", - Columns: []*schema.Column{ChargeFlatFeesColumns[38]}, + Columns: []*schema.Column{ChargeFlatFeesColumns[39]}, RefColumns: []*schema.Column{TaxCodesColumns[0]}, OnDelete: schema.NoAction, }, @@ -2159,7 +2242,7 @@ var ( { Name: "chargeflatfee_namespace_customer_id_unique_reference_id", Unique: true, - Columns: []*schema.Column{ChargeFlatFeesColumns[14], ChargeFlatFeesColumns[33], ChargeFlatFeesColumns[8]}, + Columns: []*schema.Column{ChargeFlatFeesColumns[14], ChargeFlatFeesColumns[34], ChargeFlatFeesColumns[8]}, Annotation: &entsql.IndexAnnotation{ Where: "unique_reference_id IS NOT NULL AND deleted_at IS NULL", }, @@ -2192,7 +2275,76 @@ var ( { Name: "chargeflatfees_tax_code_id", Unique: false, - Columns: []*schema.Column{ChargeFlatFeesColumns[38]}, + Columns: []*schema.Column{ChargeFlatFeesColumns[39]}, + }, + }, + } + // ChargeFlatFeeCostBasesColumns holds the columns for the "charge_flat_fee_cost_bases" table. + ChargeFlatFeeCostBasesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeString, Unique: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "mode", Type: field.TypeEnum, Enums: []string{"dynamic", "pinned", "manual"}}, + {Name: "fiat_currency", Type: field.TypeString, SchemaType: map[string]string{"postgres": "varchar(3)"}}, + {Name: "manual_rate", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "numeric"}}, + {Name: "resolved_cost_basis", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "numeric"}}, + {Name: "resolved_at", Type: field.TypeTime, Nullable: true}, + {Name: "namespace", Type: field.TypeString}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "deleted_at", Type: field.TypeTime, Nullable: true}, + {Name: "currency_cost_basis_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "resolved_cost_basis_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "currency_id", Type: field.TypeString, SchemaType: map[string]string{"postgres": "char(26)"}}, + } + // ChargeFlatFeeCostBasesTable holds the schema information for the "charge_flat_fee_cost_bases" table. + ChargeFlatFeeCostBasesTable = &schema.Table{ + Name: "charge_flat_fee_cost_bases", + Columns: ChargeFlatFeeCostBasesColumns, + PrimaryKey: []*schema.Column{ChargeFlatFeeCostBasesColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "charge_flat_fee_cost_basis_currency_cost_basis_fk", + Columns: []*schema.Column{ChargeFlatFeeCostBasesColumns[10]}, + RefColumns: []*schema.Column{CurrencyCostBasesColumns[0]}, + OnDelete: schema.Restrict, + }, + { + Symbol: "charge_flat_fee_cost_basis_resolved_cost_basis_fk", + Columns: []*schema.Column{ChargeFlatFeeCostBasesColumns[11]}, + RefColumns: []*schema.Column{CurrencyCostBasesColumns[0]}, + OnDelete: schema.Restrict, + }, + { + Symbol: "charge_flat_fee_cost_basis_currency_fk", + Columns: []*schema.Column{ChargeFlatFeeCostBasesColumns[12]}, + RefColumns: []*schema.Column{CustomCurrenciesColumns[0]}, + OnDelete: schema.Restrict, + }, + }, + Indexes: []*schema.Index{ + { + Name: "chargeflatfeecostbasis_currency_cost_basis_id", + Unique: false, + Columns: []*schema.Column{ChargeFlatFeeCostBasesColumns[10]}, + }, + { + Name: "chargeflatfeecostbasis_resolved_cost_basis_id", + Unique: false, + Columns: []*schema.Column{ChargeFlatFeeCostBasesColumns[11]}, + }, + { + Name: "chargeflatfeecostbasis_currency_id", + Unique: false, + Columns: []*schema.Column{ChargeFlatFeeCostBasesColumns[12]}, + }, + { + Name: "chargeflatfeecostbasis_namespace", + Unique: false, + Columns: []*schema.Column{ChargeFlatFeeCostBasesColumns[6]}, + }, + { + Name: "chargeflatfeecostbasis_id", + Unique: true, + Columns: []*schema.Column{ChargeFlatFeeCostBasesColumns[0]}, }, }, } @@ -2642,6 +2794,7 @@ var ( {Name: "unit_config", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "jsonb"}}, {Name: "status_detailed", Type: field.TypeEnum, Enums: []string{"created", "active", "active.realization.started", "active.realization.waiting_for_collection", "active.realization.processing", "active.realization.issuing", "active.realization.completed", "active.awaiting_payment_settlement", "final", "deleted"}}, {Name: "current_realization_run_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "cost_basis_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "custom_currency_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "customer_id", Type: field.TypeString, SchemaType: map[string]string{"postgres": "char(26)"}}, {Name: "feature_id", Type: field.TypeString, SchemaType: map[string]string{"postgres": "char(26)"}}, @@ -2663,44 +2816,50 @@ var ( OnDelete: schema.SetNull, }, { - Symbol: "charge_usage_based_custom_currencies_charges_usage_based", + Symbol: "charge_usage_based_cost_basis_charge_fk", Columns: []*schema.Column{ChargeUsageBasedColumns[31]}, + RefColumns: []*schema.Column{ChargeUsageBasedCostBasesColumns[0]}, + OnDelete: schema.Cascade, + }, + { + Symbol: "charge_usage_based_custom_currencies_charges_usage_based", + Columns: []*schema.Column{ChargeUsageBasedColumns[32]}, RefColumns: []*schema.Column{CustomCurrenciesColumns[0]}, OnDelete: schema.Restrict, }, { Symbol: "charge_usage_based_customers_charges_usage_based", - Columns: []*schema.Column{ChargeUsageBasedColumns[32]}, + Columns: []*schema.Column{ChargeUsageBasedColumns[33]}, RefColumns: []*schema.Column{CustomersColumns[0]}, OnDelete: schema.NoAction, }, { Symbol: "charge_usage_based_features_usage_based_charges", - Columns: []*schema.Column{ChargeUsageBasedColumns[33]}, + Columns: []*schema.Column{ChargeUsageBasedColumns[34]}, RefColumns: []*schema.Column{FeaturesColumns[0]}, OnDelete: schema.NoAction, }, { Symbol: "charge_usage_based_subscriptions_charges_usage_based", - Columns: []*schema.Column{ChargeUsageBasedColumns[34]}, + Columns: []*schema.Column{ChargeUsageBasedColumns[35]}, RefColumns: []*schema.Column{SubscriptionsColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "charge_usage_based_subscription_items_charges_usage_based", - Columns: []*schema.Column{ChargeUsageBasedColumns[35]}, + Columns: []*schema.Column{ChargeUsageBasedColumns[36]}, RefColumns: []*schema.Column{SubscriptionItemsColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "charge_usage_based_subscription_phases_charges_usage_based", - Columns: []*schema.Column{ChargeUsageBasedColumns[36]}, + Columns: []*schema.Column{ChargeUsageBasedColumns[37]}, RefColumns: []*schema.Column{SubscriptionPhasesColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "charge_usage_based_tax_codes_charge_usage_based", - Columns: []*schema.Column{ChargeUsageBasedColumns[37]}, + Columns: []*schema.Column{ChargeUsageBasedColumns[38]}, RefColumns: []*schema.Column{TaxCodesColumns[0]}, OnDelete: schema.NoAction, }, @@ -2709,7 +2868,7 @@ var ( { Name: "chargeusagebased_namespace_customer_id_unique_reference_id", Unique: true, - Columns: []*schema.Column{ChargeUsageBasedColumns[14], ChargeUsageBasedColumns[32], ChargeUsageBasedColumns[8]}, + Columns: []*schema.Column{ChargeUsageBasedColumns[14], ChargeUsageBasedColumns[33], ChargeUsageBasedColumns[8]}, Annotation: &entsql.IndexAnnotation{ Where: "unique_reference_id IS NOT NULL AND deleted_at IS NULL", }, @@ -2742,7 +2901,76 @@ var ( { Name: "chargeusagebased_tax_code_id", Unique: false, - Columns: []*schema.Column{ChargeUsageBasedColumns[37]}, + Columns: []*schema.Column{ChargeUsageBasedColumns[38]}, + }, + }, + } + // ChargeUsageBasedCostBasesColumns holds the columns for the "charge_usage_based_cost_bases" table. + ChargeUsageBasedCostBasesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeString, Unique: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "mode", Type: field.TypeEnum, Enums: []string{"dynamic", "pinned", "manual"}}, + {Name: "fiat_currency", Type: field.TypeString, SchemaType: map[string]string{"postgres": "varchar(3)"}}, + {Name: "manual_rate", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "numeric"}}, + {Name: "resolved_cost_basis", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "numeric"}}, + {Name: "resolved_at", Type: field.TypeTime, Nullable: true}, + {Name: "namespace", Type: field.TypeString}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "deleted_at", Type: field.TypeTime, Nullable: true}, + {Name: "currency_cost_basis_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "resolved_cost_basis_id", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "char(26)"}}, + {Name: "currency_id", Type: field.TypeString, SchemaType: map[string]string{"postgres": "char(26)"}}, + } + // ChargeUsageBasedCostBasesTable holds the schema information for the "charge_usage_based_cost_bases" table. + ChargeUsageBasedCostBasesTable = &schema.Table{ + Name: "charge_usage_based_cost_bases", + Columns: ChargeUsageBasedCostBasesColumns, + PrimaryKey: []*schema.Column{ChargeUsageBasedCostBasesColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "charge_usage_based_cost_basis_currency_cost_basis_fk", + Columns: []*schema.Column{ChargeUsageBasedCostBasesColumns[10]}, + RefColumns: []*schema.Column{CurrencyCostBasesColumns[0]}, + OnDelete: schema.Restrict, + }, + { + Symbol: "charge_usage_based_cost_basis_resolved_cost_basis_fk", + Columns: []*schema.Column{ChargeUsageBasedCostBasesColumns[11]}, + RefColumns: []*schema.Column{CurrencyCostBasesColumns[0]}, + OnDelete: schema.Restrict, + }, + { + Symbol: "charge_usage_based_cost_basis_currency_fk", + Columns: []*schema.Column{ChargeUsageBasedCostBasesColumns[12]}, + RefColumns: []*schema.Column{CustomCurrenciesColumns[0]}, + OnDelete: schema.Restrict, + }, + }, + Indexes: []*schema.Index{ + { + Name: "chargeusagebasedcostbasis_currency_cost_basis_id", + Unique: false, + Columns: []*schema.Column{ChargeUsageBasedCostBasesColumns[10]}, + }, + { + Name: "chargeusagebasedcostbasis_resolved_cost_basis_id", + Unique: false, + Columns: []*schema.Column{ChargeUsageBasedCostBasesColumns[11]}, + }, + { + Name: "chargeusagebasedcostbasis_currency_id", + Unique: false, + Columns: []*schema.Column{ChargeUsageBasedCostBasesColumns[12]}, + }, + { + Name: "chargeusagebasedcostbasis_namespace", + Unique: false, + Columns: []*schema.Column{ChargeUsageBasedCostBasesColumns[6]}, + }, + { + Name: "chargeusagebasedcostbasis_id", + Unique: true, + Columns: []*schema.Column{ChargeUsageBasedCostBasesColumns[0]}, }, }, } @@ -5626,10 +5854,12 @@ var ( BillingWorkflowConfigsTable, ChargesTable, ChargeCreditPurchasesTable, + ChargeCreditPurchaseCostBasesTable, ChargeCreditPurchaseCreditGrantsTable, ChargeCreditPurchaseExternalPaymentsTable, ChargeCreditPurchaseInvoicedPaymentsTable, ChargeFlatFeesTable, + ChargeFlatFeeCostBasesTable, ChargeFlatFeeOverridesTable, ChargeFlatFeeRunsTable, ChargeFlatFeeRunCreditAllocationsTable, @@ -5637,6 +5867,7 @@ var ( ChargeFlatFeeRunInvoicedUsagesTable, ChargeFlatFeeRunPaymentsTable, ChargeUsageBasedTable, + ChargeUsageBasedCostBasesTable, ChargeUsageBasedOverridesTable, ChargeUsageBasedRunCreditAllocationsTable, ChargeUsageBasedRunDetailedLineTable, @@ -5751,34 +5982,58 @@ func init() { ChargesTable.ForeignKeys[0].RefTable = ChargeCreditPurchasesTable ChargesTable.ForeignKeys[1].RefTable = ChargeFlatFeesTable ChargesTable.ForeignKeys[2].RefTable = ChargeUsageBasedTable - ChargeCreditPurchasesTable.ForeignKeys[0].RefTable = CustomCurrenciesTable - ChargeCreditPurchasesTable.ForeignKeys[1].RefTable = CustomersTable - ChargeCreditPurchasesTable.ForeignKeys[2].RefTable = SubscriptionsTable - ChargeCreditPurchasesTable.ForeignKeys[3].RefTable = SubscriptionItemsTable - ChargeCreditPurchasesTable.ForeignKeys[4].RefTable = SubscriptionPhasesTable - ChargeCreditPurchasesTable.ForeignKeys[5].RefTable = TaxCodesTable + ChargeCreditPurchasesTable.ForeignKeys[0].RefTable = ChargeCreditPurchaseCostBasesTable + ChargeCreditPurchasesTable.ForeignKeys[1].RefTable = CustomCurrenciesTable + ChargeCreditPurchasesTable.ForeignKeys[2].RefTable = CustomersTable + ChargeCreditPurchasesTable.ForeignKeys[3].RefTable = SubscriptionsTable + ChargeCreditPurchasesTable.ForeignKeys[4].RefTable = SubscriptionItemsTable + ChargeCreditPurchasesTable.ForeignKeys[5].RefTable = SubscriptionPhasesTable + ChargeCreditPurchasesTable.ForeignKeys[6].RefTable = TaxCodesTable ChargeCreditPurchasesTable.Annotation = &entsql.Annotation{} ChargeCreditPurchasesTable.Annotation.Checks = map[string]string{ "currency_not_empty": "currency IS NULL OR currency <> ''", "currency_reference": "(currency IS NULL) <> (custom_currency_id IS NULL)", } + ChargeCreditPurchaseCostBasesTable.ForeignKeys[0].RefTable = CurrencyCostBasesTable + ChargeCreditPurchaseCostBasesTable.ForeignKeys[1].RefTable = CurrencyCostBasesTable + ChargeCreditPurchaseCostBasesTable.ForeignKeys[2].RefTable = CustomCurrenciesTable + ChargeCreditPurchaseCostBasesTable.Annotation = &entsql.Annotation{ + Table: "charge_credit_purchase_cost_bases", + } + ChargeCreditPurchaseCostBasesTable.Annotation.Checks = map[string]string{ + "fiat_currency_not_empty": "fiat_currency <> ''", + "resolved_cost_basis_positive": "resolved_cost_basis IS NULL OR resolved_cost_basis > 0", + "state": "\n\t\t\t\t(\n\t\t\t\t\tmode = 'dynamic'\n\t\t\t\t\tAND currency_cost_basis_id IS NULL\n\t\t\t\t\tAND manual_rate IS NULL\n\t\t\t\t\tAND (\n\t\t\t\t\t\t(resolved_cost_basis_id IS NULL AND resolved_cost_basis IS NULL AND resolved_at IS NULL)\n\t\t\t\t\t\tOR (resolved_cost_basis_id IS NOT NULL AND resolved_cost_basis IS NOT NULL AND resolved_at IS NOT NULL)\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\tOR (\n\t\t\t\t\tmode = 'pinned'\n\t\t\t\t\tAND currency_cost_basis_id IS NOT NULL\n\t\t\t\t\tAND resolved_cost_basis_id IS NOT NULL\n\t\t\t\t\tAND resolved_cost_basis_id = currency_cost_basis_id\n\t\t\t\t\tAND manual_rate IS NULL\n\t\t\t\t\tAND resolved_cost_basis IS NOT NULL\n\t\t\t\t\tAND resolved_at IS NOT NULL\n\t\t\t\t)\n\t\t\t\tOR (\n\t\t\t\t\tmode = 'manual'\n\t\t\t\t\tAND currency_cost_basis_id IS NULL\n\t\t\t\t\tAND resolved_cost_basis_id IS NULL\n\t\t\t\t\tAND manual_rate > 0\n\t\t\t\t\tAND resolved_cost_basis IS NOT NULL\n\t\t\t\t\tAND resolved_at IS NOT NULL\n\t\t\t\t)\n\t\t\t", + } ChargeCreditPurchaseCreditGrantsTable.ForeignKeys[0].RefTable = ChargeCreditPurchasesTable ChargeCreditPurchaseExternalPaymentsTable.ForeignKeys[0].RefTable = ChargeCreditPurchasesTable ChargeCreditPurchaseInvoicedPaymentsTable.ForeignKeys[0].RefTable = BillingInvoiceLinesTable ChargeCreditPurchaseInvoicedPaymentsTable.ForeignKeys[1].RefTable = ChargeCreditPurchasesTable ChargeFlatFeesTable.ForeignKeys[0].RefTable = ChargeFlatFeeRunsTable - ChargeFlatFeesTable.ForeignKeys[1].RefTable = CustomCurrenciesTable - ChargeFlatFeesTable.ForeignKeys[2].RefTable = CustomersTable - ChargeFlatFeesTable.ForeignKeys[3].RefTable = FeaturesTable - ChargeFlatFeesTable.ForeignKeys[4].RefTable = SubscriptionsTable - ChargeFlatFeesTable.ForeignKeys[5].RefTable = SubscriptionItemsTable - ChargeFlatFeesTable.ForeignKeys[6].RefTable = SubscriptionPhasesTable - ChargeFlatFeesTable.ForeignKeys[7].RefTable = TaxCodesTable + ChargeFlatFeesTable.ForeignKeys[1].RefTable = ChargeFlatFeeCostBasesTable + ChargeFlatFeesTable.ForeignKeys[2].RefTable = CustomCurrenciesTable + ChargeFlatFeesTable.ForeignKeys[3].RefTable = CustomersTable + ChargeFlatFeesTable.ForeignKeys[4].RefTable = FeaturesTable + ChargeFlatFeesTable.ForeignKeys[5].RefTable = SubscriptionsTable + ChargeFlatFeesTable.ForeignKeys[6].RefTable = SubscriptionItemsTable + ChargeFlatFeesTable.ForeignKeys[7].RefTable = SubscriptionPhasesTable + ChargeFlatFeesTable.ForeignKeys[8].RefTable = TaxCodesTable ChargeFlatFeesTable.Annotation = &entsql.Annotation{} ChargeFlatFeesTable.Annotation.Checks = map[string]string{ "currency_not_empty": "currency IS NULL OR currency <> ''", "currency_reference": "(currency IS NULL) <> (custom_currency_id IS NULL)", } + ChargeFlatFeeCostBasesTable.ForeignKeys[0].RefTable = CurrencyCostBasesTable + ChargeFlatFeeCostBasesTable.ForeignKeys[1].RefTable = CurrencyCostBasesTable + ChargeFlatFeeCostBasesTable.ForeignKeys[2].RefTable = CustomCurrenciesTable + ChargeFlatFeeCostBasesTable.Annotation = &entsql.Annotation{ + Table: "charge_flat_fee_cost_bases", + } + ChargeFlatFeeCostBasesTable.Annotation.Checks = map[string]string{ + "fiat_currency_not_empty": "fiat_currency <> ''", + "resolved_cost_basis_positive": "resolved_cost_basis IS NULL OR resolved_cost_basis > 0", + "state": "\n\t\t\t\t(\n\t\t\t\t\tmode = 'dynamic'\n\t\t\t\t\tAND currency_cost_basis_id IS NULL\n\t\t\t\t\tAND manual_rate IS NULL\n\t\t\t\t\tAND (\n\t\t\t\t\t\t(resolved_cost_basis_id IS NULL AND resolved_cost_basis IS NULL AND resolved_at IS NULL)\n\t\t\t\t\t\tOR (resolved_cost_basis_id IS NOT NULL AND resolved_cost_basis IS NOT NULL AND resolved_at IS NOT NULL)\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\tOR (\n\t\t\t\t\tmode = 'pinned'\n\t\t\t\t\tAND currency_cost_basis_id IS NOT NULL\n\t\t\t\t\tAND resolved_cost_basis_id IS NOT NULL\n\t\t\t\t\tAND resolved_cost_basis_id = currency_cost_basis_id\n\t\t\t\t\tAND manual_rate IS NULL\n\t\t\t\t\tAND resolved_cost_basis IS NOT NULL\n\t\t\t\t\tAND resolved_at IS NOT NULL\n\t\t\t\t)\n\t\t\t\tOR (\n\t\t\t\t\tmode = 'manual'\n\t\t\t\t\tAND currency_cost_basis_id IS NULL\n\t\t\t\t\tAND resolved_cost_basis_id IS NULL\n\t\t\t\t\tAND manual_rate > 0\n\t\t\t\t\tAND resolved_cost_basis IS NOT NULL\n\t\t\t\t\tAND resolved_at IS NOT NULL\n\t\t\t\t)\n\t\t\t", + } ChargeFlatFeeOverridesTable.ForeignKeys[0].RefTable = ChargeFlatFeesTable ChargeFlatFeeOverridesTable.ForeignKeys[1].RefTable = TaxCodesTable ChargeFlatFeeRunsTable.ForeignKeys[0].RefTable = BillingInvoicesTable @@ -5796,13 +6051,14 @@ func init() { ChargeFlatFeeRunPaymentsTable.ForeignKeys[0].RefTable = BillingInvoiceLinesTable ChargeFlatFeeRunPaymentsTable.ForeignKeys[1].RefTable = ChargeFlatFeeRunsTable ChargeUsageBasedTable.ForeignKeys[0].RefTable = ChargeUsageBasedRunsTable - ChargeUsageBasedTable.ForeignKeys[1].RefTable = CustomCurrenciesTable - ChargeUsageBasedTable.ForeignKeys[2].RefTable = CustomersTable - ChargeUsageBasedTable.ForeignKeys[3].RefTable = FeaturesTable - ChargeUsageBasedTable.ForeignKeys[4].RefTable = SubscriptionsTable - ChargeUsageBasedTable.ForeignKeys[5].RefTable = SubscriptionItemsTable - ChargeUsageBasedTable.ForeignKeys[6].RefTable = SubscriptionPhasesTable - ChargeUsageBasedTable.ForeignKeys[7].RefTable = TaxCodesTable + ChargeUsageBasedTable.ForeignKeys[1].RefTable = ChargeUsageBasedCostBasesTable + ChargeUsageBasedTable.ForeignKeys[2].RefTable = CustomCurrenciesTable + ChargeUsageBasedTable.ForeignKeys[3].RefTable = CustomersTable + ChargeUsageBasedTable.ForeignKeys[4].RefTable = FeaturesTable + ChargeUsageBasedTable.ForeignKeys[5].RefTable = SubscriptionsTable + ChargeUsageBasedTable.ForeignKeys[6].RefTable = SubscriptionItemsTable + ChargeUsageBasedTable.ForeignKeys[7].RefTable = SubscriptionPhasesTable + ChargeUsageBasedTable.ForeignKeys[8].RefTable = TaxCodesTable ChargeUsageBasedTable.Annotation = &entsql.Annotation{ Table: "charge_usage_based", } @@ -5810,6 +6066,17 @@ func init() { "currency_not_empty": "currency IS NULL OR currency <> ''", "currency_reference": "(currency IS NULL) <> (custom_currency_id IS NULL)", } + ChargeUsageBasedCostBasesTable.ForeignKeys[0].RefTable = CurrencyCostBasesTable + ChargeUsageBasedCostBasesTable.ForeignKeys[1].RefTable = CurrencyCostBasesTable + ChargeUsageBasedCostBasesTable.ForeignKeys[2].RefTable = CustomCurrenciesTable + ChargeUsageBasedCostBasesTable.Annotation = &entsql.Annotation{ + Table: "charge_usage_based_cost_bases", + } + ChargeUsageBasedCostBasesTable.Annotation.Checks = map[string]string{ + "fiat_currency_not_empty": "fiat_currency <> ''", + "resolved_cost_basis_positive": "resolved_cost_basis IS NULL OR resolved_cost_basis > 0", + "state": "\n\t\t\t\t(\n\t\t\t\t\tmode = 'dynamic'\n\t\t\t\t\tAND currency_cost_basis_id IS NULL\n\t\t\t\t\tAND manual_rate IS NULL\n\t\t\t\t\tAND (\n\t\t\t\t\t\t(resolved_cost_basis_id IS NULL AND resolved_cost_basis IS NULL AND resolved_at IS NULL)\n\t\t\t\t\t\tOR (resolved_cost_basis_id IS NOT NULL AND resolved_cost_basis IS NOT NULL AND resolved_at IS NOT NULL)\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\tOR (\n\t\t\t\t\tmode = 'pinned'\n\t\t\t\t\tAND currency_cost_basis_id IS NOT NULL\n\t\t\t\t\tAND resolved_cost_basis_id IS NOT NULL\n\t\t\t\t\tAND resolved_cost_basis_id = currency_cost_basis_id\n\t\t\t\t\tAND manual_rate IS NULL\n\t\t\t\t\tAND resolved_cost_basis IS NOT NULL\n\t\t\t\t\tAND resolved_at IS NOT NULL\n\t\t\t\t)\n\t\t\t\tOR (\n\t\t\t\t\tmode = 'manual'\n\t\t\t\t\tAND currency_cost_basis_id IS NULL\n\t\t\t\t\tAND resolved_cost_basis_id IS NULL\n\t\t\t\t\tAND manual_rate > 0\n\t\t\t\t\tAND resolved_cost_basis IS NOT NULL\n\t\t\t\t\tAND resolved_at IS NOT NULL\n\t\t\t\t)\n\t\t\t", + } ChargeUsageBasedOverridesTable.ForeignKeys[0].RefTable = ChargeUsageBasedTable ChargeUsageBasedOverridesTable.ForeignKeys[1].RefTable = TaxCodesTable ChargeUsageBasedRunCreditAllocationsTable.ForeignKeys[0].RefTable = ChargeUsageBasedRunCreditAllocationsTable diff --git a/openmeter/ent/db/mutation.go b/openmeter/ent/db/mutation.go index 1e1e116a49..71c1518831 100644 --- a/openmeter/ent/db/mutation.go +++ b/openmeter/ent/db/mutation.go @@ -18,6 +18,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/billing/charges/creditpurchase" "github.com/openmeterio/openmeter/openmeter/billing/charges/flatfee" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/creditrealization" "github.com/openmeterio/openmeter/openmeter/billing/charges/models/payment" "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased" @@ -53,10 +54,12 @@ import ( "github.com/openmeterio/openmeter/openmeter/ent/db/billingworkflowconfig" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecreditgrant" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseexternalpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseinvoicedpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfee" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeerun" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeruncreditallocations" @@ -64,6 +67,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeruninvoicedusage" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeerunpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebased" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedcostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedruncreditallocations" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedrundetailedline" @@ -158,10 +162,12 @@ const ( TypeBillingWorkflowConfig = "BillingWorkflowConfig" TypeCharge = "Charge" TypeChargeCreditPurchase = "ChargeCreditPurchase" + TypeChargeCreditPurchaseCostBasis = "ChargeCreditPurchaseCostBasis" TypeChargeCreditPurchaseCreditGrant = "ChargeCreditPurchaseCreditGrant" TypeChargeCreditPurchaseExternalPayment = "ChargeCreditPurchaseExternalPayment" TypeChargeCreditPurchaseInvoicedPayment = "ChargeCreditPurchaseInvoicedPayment" TypeChargeFlatFee = "ChargeFlatFee" + TypeChargeFlatFeeCostBasis = "ChargeFlatFeeCostBasis" TypeChargeFlatFeeOverride = "ChargeFlatFeeOverride" TypeChargeFlatFeeRun = "ChargeFlatFeeRun" TypeChargeFlatFeeRunCreditAllocations = "ChargeFlatFeeRunCreditAllocations" @@ -169,6 +175,7 @@ const ( TypeChargeFlatFeeRunInvoicedUsage = "ChargeFlatFeeRunInvoicedUsage" TypeChargeFlatFeeRunPayment = "ChargeFlatFeeRunPayment" TypeChargeUsageBased = "ChargeUsageBased" + TypeChargeUsageBasedCostBasis = "ChargeUsageBasedCostBasis" TypeChargeUsageBasedOverride = "ChargeUsageBasedOverride" TypeChargeUsageBasedRunCreditAllocations = "ChargeUsageBasedRunCreditAllocations" TypeChargeUsageBasedRunDetailedLine = "ChargeUsageBasedRunDetailedLine" @@ -39301,6 +39308,8 @@ type ChargeCreditPurchaseMutation struct { clearedinvoiced_payment bool credit_grant *string clearedcredit_grant bool + cost_basis *string + clearedcost_basis bool charge *string clearedcharge bool subscription *string @@ -40939,6 +40948,55 @@ func (m *ChargeCreditPurchaseMutation) ResetVoidedAt() { delete(m.clearedFields, chargecreditpurchase.FieldVoidedAt) } +// SetCostBasisID sets the "cost_basis_id" field. +func (m *ChargeCreditPurchaseMutation) SetCostBasisID(s string) { + m.cost_basis = &s +} + +// CostBasisID returns the value of the "cost_basis_id" field in the mutation. +func (m *ChargeCreditPurchaseMutation) CostBasisID() (r string, exists bool) { + v := m.cost_basis + if v == nil { + return + } + return *v, true +} + +// OldCostBasisID returns the old "cost_basis_id" field's value of the ChargeCreditPurchase entity. +// If the ChargeCreditPurchase 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 *ChargeCreditPurchaseMutation) OldCostBasisID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCostBasisID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCostBasisID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCostBasisID: %w", err) + } + return oldValue.CostBasisID, nil +} + +// ClearCostBasisID clears the value of the "cost_basis_id" field. +func (m *ChargeCreditPurchaseMutation) ClearCostBasisID() { + m.cost_basis = nil + m.clearedFields[chargecreditpurchase.FieldCostBasisID] = struct{}{} +} + +// CostBasisIDCleared returns if the "cost_basis_id" field was cleared in this mutation. +func (m *ChargeCreditPurchaseMutation) CostBasisIDCleared() bool { + _, ok := m.clearedFields[chargecreditpurchase.FieldCostBasisID] + return ok +} + +// ResetCostBasisID resets all changes to the "cost_basis_id" field. +func (m *ChargeCreditPurchaseMutation) ResetCostBasisID() { + m.cost_basis = nil + delete(m.clearedFields, chargecreditpurchase.FieldCostBasisID) +} + // SetExternalPaymentID sets the "external_payment" edge to the ChargeCreditPurchaseExternalPayment entity by id. func (m *ChargeCreditPurchaseMutation) SetExternalPaymentID(id string) { m.external_payment = &id @@ -41056,6 +41114,33 @@ func (m *ChargeCreditPurchaseMutation) ResetCreditGrant() { m.clearedcredit_grant = false } +// ClearCostBasis clears the "cost_basis" edge to the ChargeCreditPurchaseCostBasis entity. +func (m *ChargeCreditPurchaseMutation) ClearCostBasis() { + m.clearedcost_basis = true + m.clearedFields[chargecreditpurchase.FieldCostBasisID] = struct{}{} +} + +// CostBasisCleared reports if the "cost_basis" edge to the ChargeCreditPurchaseCostBasis entity was cleared. +func (m *ChargeCreditPurchaseMutation) CostBasisCleared() bool { + return m.CostBasisIDCleared() || m.clearedcost_basis +} + +// CostBasisIDs returns the "cost_basis" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CostBasisID instead. It exists only for internal usage by the builders. +func (m *ChargeCreditPurchaseMutation) CostBasisIDs() (ids []string) { + if id := m.cost_basis; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetCostBasis resets all changes to the "cost_basis" edge. +func (m *ChargeCreditPurchaseMutation) ResetCostBasis() { + m.cost_basis = nil + m.clearedcost_basis = false +} + // SetChargeID sets the "charge" edge to the Charge entity by id. func (m *ChargeCreditPurchaseMutation) SetChargeID(id string) { m.charge = &id @@ -41291,7 +41376,7 @@ func (m *ChargeCreditPurchaseMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *ChargeCreditPurchaseMutation) Fields() []string { - fields := make([]string, 0, 35) + fields := make([]string, 0, 36) if m.customer != nil { fields = append(fields, chargecreditpurchase.FieldCustomerID) } @@ -41397,6 +41482,9 @@ func (m *ChargeCreditPurchaseMutation) Fields() []string { if m.voided_at != nil { fields = append(fields, chargecreditpurchase.FieldVoidedAt) } + if m.cost_basis != nil { + fields = append(fields, chargecreditpurchase.FieldCostBasisID) + } return fields } @@ -41475,6 +41563,8 @@ func (m *ChargeCreditPurchaseMutation) Field(name string) (ent.Value, bool) { return m.Key() case chargecreditpurchase.FieldVoidedAt: return m.VoidedAt() + case chargecreditpurchase.FieldCostBasisID: + return m.CostBasisID() } return nil, false } @@ -41554,6 +41644,8 @@ func (m *ChargeCreditPurchaseMutation) OldField(ctx context.Context, name string return m.OldKey(ctx) case chargecreditpurchase.FieldVoidedAt: return m.OldVoidedAt(ctx) + case chargecreditpurchase.FieldCostBasisID: + return m.OldCostBasisID(ctx) } return nil, fmt.Errorf("unknown ChargeCreditPurchase field %s", name) } @@ -41808,6 +41900,13 @@ func (m *ChargeCreditPurchaseMutation) SetField(name string, value ent.Value) er } m.SetVoidedAt(v) return nil + case chargecreditpurchase.FieldCostBasisID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCostBasisID(v) + return nil } return fmt.Errorf("unknown ChargeCreditPurchase field %s", name) } @@ -41907,6 +42006,9 @@ func (m *ChargeCreditPurchaseMutation) ClearedFields() []string { if m.FieldCleared(chargecreditpurchase.FieldVoidedAt) { fields = append(fields, chargecreditpurchase.FieldVoidedAt) } + if m.FieldCleared(chargecreditpurchase.FieldCostBasisID) { + fields = append(fields, chargecreditpurchase.FieldCostBasisID) + } return fields } @@ -41975,6 +42077,9 @@ func (m *ChargeCreditPurchaseMutation) ClearField(name string) error { case chargecreditpurchase.FieldVoidedAt: m.ClearVoidedAt() return nil + case chargecreditpurchase.FieldCostBasisID: + m.ClearCostBasisID() + return nil } return fmt.Errorf("unknown ChargeCreditPurchase nullable field %s", name) } @@ -42088,13 +42193,16 @@ func (m *ChargeCreditPurchaseMutation) ResetField(name string) error { case chargecreditpurchase.FieldVoidedAt: m.ResetVoidedAt() return nil + case chargecreditpurchase.FieldCostBasisID: + m.ResetCostBasisID() + return nil } return fmt.Errorf("unknown ChargeCreditPurchase field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *ChargeCreditPurchaseMutation) AddedEdges() []string { - edges := make([]string, 0, 10) + edges := make([]string, 0, 11) if m.external_payment != nil { edges = append(edges, chargecreditpurchase.EdgeExternalPayment) } @@ -42104,6 +42212,9 @@ func (m *ChargeCreditPurchaseMutation) AddedEdges() []string { if m.credit_grant != nil { edges = append(edges, chargecreditpurchase.EdgeCreditGrant) } + if m.cost_basis != nil { + edges = append(edges, chargecreditpurchase.EdgeCostBasis) + } if m.charge != nil { edges = append(edges, chargecreditpurchase.EdgeCharge) } @@ -42144,6 +42255,10 @@ func (m *ChargeCreditPurchaseMutation) AddedIDs(name string) []ent.Value { if id := m.credit_grant; id != nil { return []ent.Value{*id} } + case chargecreditpurchase.EdgeCostBasis: + if id := m.cost_basis; id != nil { + return []ent.Value{*id} + } case chargecreditpurchase.EdgeCharge: if id := m.charge; id != nil { return []ent.Value{*id} @@ -42178,7 +42293,7 @@ func (m *ChargeCreditPurchaseMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *ChargeCreditPurchaseMutation) RemovedEdges() []string { - edges := make([]string, 0, 10) + edges := make([]string, 0, 11) return edges } @@ -42190,7 +42305,7 @@ func (m *ChargeCreditPurchaseMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *ChargeCreditPurchaseMutation) ClearedEdges() []string { - edges := make([]string, 0, 10) + edges := make([]string, 0, 11) if m.clearedexternal_payment { edges = append(edges, chargecreditpurchase.EdgeExternalPayment) } @@ -42200,6 +42315,9 @@ func (m *ChargeCreditPurchaseMutation) ClearedEdges() []string { if m.clearedcredit_grant { edges = append(edges, chargecreditpurchase.EdgeCreditGrant) } + if m.clearedcost_basis { + edges = append(edges, chargecreditpurchase.EdgeCostBasis) + } if m.clearedcharge { edges = append(edges, chargecreditpurchase.EdgeCharge) } @@ -42234,6 +42352,8 @@ func (m *ChargeCreditPurchaseMutation) EdgeCleared(name string) bool { return m.clearedinvoiced_payment case chargecreditpurchase.EdgeCreditGrant: return m.clearedcredit_grant + case chargecreditpurchase.EdgeCostBasis: + return m.clearedcost_basis case chargecreditpurchase.EdgeCharge: return m.clearedcharge case chargecreditpurchase.EdgeSubscription: @@ -42265,6 +42385,9 @@ func (m *ChargeCreditPurchaseMutation) ClearEdge(name string) error { case chargecreditpurchase.EdgeCreditGrant: m.ClearCreditGrant() return nil + case chargecreditpurchase.EdgeCostBasis: + m.ClearCostBasis() + return nil case chargecreditpurchase.EdgeCharge: m.ClearCharge() return nil @@ -42303,6 +42426,9 @@ func (m *ChargeCreditPurchaseMutation) ResetEdge(name string) error { case chargecreditpurchase.EdgeCreditGrant: m.ResetCreditGrant() return nil + case chargecreditpurchase.EdgeCostBasis: + m.ResetCostBasis() + return nil case chargecreditpurchase.EdgeCharge: m.ResetCharge() return nil @@ -42328,37 +42454,44 @@ func (m *ChargeCreditPurchaseMutation) ResetEdge(name string) error { return fmt.Errorf("unknown ChargeCreditPurchase edge %s", name) } -// ChargeCreditPurchaseCreditGrantMutation represents an operation that mutates the ChargeCreditPurchaseCreditGrant nodes in the graph. -type ChargeCreditPurchaseCreditGrantMutation struct { +// ChargeCreditPurchaseCostBasisMutation represents an operation that mutates the ChargeCreditPurchaseCostBasis nodes in the graph. +type ChargeCreditPurchaseCostBasisMutation struct { config - op Op - typ string - id *string - namespace *string - created_at *time.Time - updated_at *time.Time - deleted_at *time.Time - transaction_group_id *string - granted_at *time.Time - clearedFields map[string]struct{} - credit_purchase *string - clearedcredit_purchase bool - done bool - oldValue func(context.Context) (*ChargeCreditPurchaseCreditGrant, error) - predicates []predicate.ChargeCreditPurchaseCreditGrant + op Op + typ string + id *string + mode *costbasis.Mode + fiat_currency *currencyx.FiatCode + manual_rate *alpacadecimal.Decimal + resolved_cost_basis *alpacadecimal.Decimal + resolved_at *time.Time + namespace *string + created_at *time.Time + updated_at *time.Time + deleted_at *time.Time + clearedFields map[string]struct{} + currency_cost_basis *string + clearedcurrency_cost_basis bool + resolved_currency_cost_basis *string + clearedresolved_currency_cost_basis bool + custom_currency *string + clearedcustom_currency bool + done bool + oldValue func(context.Context) (*ChargeCreditPurchaseCostBasis, error) + predicates []predicate.ChargeCreditPurchaseCostBasis } -var _ ent.Mutation = (*ChargeCreditPurchaseCreditGrantMutation)(nil) +var _ ent.Mutation = (*ChargeCreditPurchaseCostBasisMutation)(nil) -// chargecreditpurchasecreditgrantOption allows management of the mutation configuration using functional options. -type chargecreditpurchasecreditgrantOption func(*ChargeCreditPurchaseCreditGrantMutation) +// chargecreditpurchasecostbasisOption allows management of the mutation configuration using functional options. +type chargecreditpurchasecostbasisOption func(*ChargeCreditPurchaseCostBasisMutation) -// newChargeCreditPurchaseCreditGrantMutation creates new mutation for the ChargeCreditPurchaseCreditGrant entity. -func newChargeCreditPurchaseCreditGrantMutation(c config, op Op, opts ...chargecreditpurchasecreditgrantOption) *ChargeCreditPurchaseCreditGrantMutation { - m := &ChargeCreditPurchaseCreditGrantMutation{ +// newChargeCreditPurchaseCostBasisMutation creates new mutation for the ChargeCreditPurchaseCostBasis entity. +func newChargeCreditPurchaseCostBasisMutation(c config, op Op, opts ...chargecreditpurchasecostbasisOption) *ChargeCreditPurchaseCostBasisMutation { + m := &ChargeCreditPurchaseCostBasisMutation{ config: c, op: op, - typ: TypeChargeCreditPurchaseCreditGrant, + typ: TypeChargeCreditPurchaseCostBasis, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -42367,20 +42500,20 @@ func newChargeCreditPurchaseCreditGrantMutation(c config, op Op, opts ...chargec return m } -// withChargeCreditPurchaseCreditGrantID sets the ID field of the mutation. -func withChargeCreditPurchaseCreditGrantID(id string) chargecreditpurchasecreditgrantOption { - return func(m *ChargeCreditPurchaseCreditGrantMutation) { +// withChargeCreditPurchaseCostBasisID sets the ID field of the mutation. +func withChargeCreditPurchaseCostBasisID(id string) chargecreditpurchasecostbasisOption { + return func(m *ChargeCreditPurchaseCostBasisMutation) { var ( err error once sync.Once - value *ChargeCreditPurchaseCreditGrant + value *ChargeCreditPurchaseCostBasis ) - m.oldValue = func(ctx context.Context) (*ChargeCreditPurchaseCreditGrant, error) { + m.oldValue = func(ctx context.Context) (*ChargeCreditPurchaseCostBasis, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { - value, err = m.Client().ChargeCreditPurchaseCreditGrant.Get(ctx, id) + value, err = m.Client().ChargeCreditPurchaseCostBasis.Get(ctx, id) } }) return value, err @@ -42389,10 +42522,10 @@ func withChargeCreditPurchaseCreditGrantID(id string) chargecreditpurchasecredit } } -// withChargeCreditPurchaseCreditGrant sets the old ChargeCreditPurchaseCreditGrant of the mutation. -func withChargeCreditPurchaseCreditGrant(node *ChargeCreditPurchaseCreditGrant) chargecreditpurchasecreditgrantOption { - return func(m *ChargeCreditPurchaseCreditGrantMutation) { - m.oldValue = func(context.Context) (*ChargeCreditPurchaseCreditGrant, error) { +// withChargeCreditPurchaseCostBasis sets the old ChargeCreditPurchaseCostBasis of the mutation. +func withChargeCreditPurchaseCostBasis(node *ChargeCreditPurchaseCostBasis) chargecreditpurchasecostbasisOption { + return func(m *ChargeCreditPurchaseCostBasisMutation) { + m.oldValue = func(context.Context) (*ChargeCreditPurchaseCostBasis, error) { return node, nil } m.id = &node.ID @@ -42401,7 +42534,7 @@ func withChargeCreditPurchaseCreditGrant(node *ChargeCreditPurchaseCreditGrant) // 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 ChargeCreditPurchaseCreditGrantMutation) Client() *Client { +func (m ChargeCreditPurchaseCostBasisMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -42409,7 +42542,7 @@ func (m ChargeCreditPurchaseCreditGrantMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m ChargeCreditPurchaseCreditGrantMutation) Tx() (*Tx, error) { +func (m ChargeCreditPurchaseCostBasisMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("db: mutation is not running in a transaction") } @@ -42419,14 +42552,14 @@ func (m ChargeCreditPurchaseCreditGrantMutation) Tx() (*Tx, error) { } // SetID sets the value of the id field. Note that this -// operation is only accepted on creation of ChargeCreditPurchaseCreditGrant entities. -func (m *ChargeCreditPurchaseCreditGrantMutation) SetID(id string) { +// operation is only accepted on creation of ChargeCreditPurchaseCostBasis entities. +func (m *ChargeCreditPurchaseCostBasisMutation) 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 *ChargeCreditPurchaseCreditGrantMutation) ID() (id string, exists bool) { +func (m *ChargeCreditPurchaseCostBasisMutation) ID() (id string, exists bool) { if m.id == nil { return } @@ -42437,7 +42570,7 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) ID() (id string, exists bool) // 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 *ChargeCreditPurchaseCreditGrantMutation) IDs(ctx context.Context) ([]string, error) { +func (m *ChargeCreditPurchaseCostBasisMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() @@ -42446,19 +42579,372 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) IDs(ctx context.Context) ([]st } fallthrough case m.op.Is(OpUpdate | OpDelete): - return m.Client().ChargeCreditPurchaseCreditGrant.Query().Where(m.predicates...).IDs(ctx) + return m.Client().ChargeCreditPurchaseCostBasis.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } +// SetMode sets the "mode" field. +func (m *ChargeCreditPurchaseCostBasisMutation) SetMode(c costbasis.Mode) { + m.mode = &c +} + +// Mode returns the value of the "mode" field in the mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) Mode() (r costbasis.Mode, exists bool) { + v := m.mode + if v == nil { + return + } + return *v, true +} + +// OldMode returns the old "mode" field's value of the ChargeCreditPurchaseCostBasis entity. +// If the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCostBasisMutation) OldMode(ctx context.Context) (v costbasis.Mode, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMode is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMode: %w", err) + } + return oldValue.Mode, nil +} + +// ResetMode resets all changes to the "mode" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ResetMode() { + m.mode = nil +} + +// SetFiatCurrency sets the "fiat_currency" field. +func (m *ChargeCreditPurchaseCostBasisMutation) SetFiatCurrency(cc currencyx.FiatCode) { + m.fiat_currency = &cc +} + +// FiatCurrency returns the value of the "fiat_currency" field in the mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) FiatCurrency() (r currencyx.FiatCode, exists bool) { + v := m.fiat_currency + if v == nil { + return + } + return *v, true +} + +// OldFiatCurrency returns the old "fiat_currency" field's value of the ChargeCreditPurchaseCostBasis entity. +// If the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCostBasisMutation) OldFiatCurrency(ctx context.Context) (v currencyx.FiatCode, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFiatCurrency is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFiatCurrency requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFiatCurrency: %w", err) + } + return oldValue.FiatCurrency, nil +} + +// ResetFiatCurrency resets all changes to the "fiat_currency" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ResetFiatCurrency() { + m.fiat_currency = nil +} + +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (m *ChargeCreditPurchaseCostBasisMutation) SetCurrencyCostBasisID(s string) { + m.currency_cost_basis = &s +} + +// CurrencyCostBasisID returns the value of the "currency_cost_basis_id" field in the mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) CurrencyCostBasisID() (r string, exists bool) { + v := m.currency_cost_basis + if v == nil { + return + } + return *v, true +} + +// OldCurrencyCostBasisID returns the old "currency_cost_basis_id" field's value of the ChargeCreditPurchaseCostBasis entity. +// If the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCostBasisMutation) OldCurrencyCostBasisID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCurrencyCostBasisID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCurrencyCostBasisID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCurrencyCostBasisID: %w", err) + } + return oldValue.CurrencyCostBasisID, nil +} + +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ClearCurrencyCostBasisID() { + m.currency_cost_basis = nil + m.clearedFields[chargecreditpurchasecostbasis.FieldCurrencyCostBasisID] = struct{}{} +} + +// CurrencyCostBasisIDCleared returns if the "currency_cost_basis_id" field was cleared in this mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) CurrencyCostBasisIDCleared() bool { + _, ok := m.clearedFields[chargecreditpurchasecostbasis.FieldCurrencyCostBasisID] + return ok +} + +// ResetCurrencyCostBasisID resets all changes to the "currency_cost_basis_id" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ResetCurrencyCostBasisID() { + m.currency_cost_basis = nil + delete(m.clearedFields, chargecreditpurchasecostbasis.FieldCurrencyCostBasisID) +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (m *ChargeCreditPurchaseCostBasisMutation) SetResolvedCostBasisID(s string) { + m.resolved_currency_cost_basis = &s +} + +// ResolvedCostBasisID returns the value of the "resolved_cost_basis_id" field in the mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) ResolvedCostBasisID() (r string, exists bool) { + v := m.resolved_currency_cost_basis + if v == nil { + return + } + return *v, true +} + +// OldResolvedCostBasisID returns the old "resolved_cost_basis_id" field's value of the ChargeCreditPurchaseCostBasis entity. +// If the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCostBasisMutation) OldResolvedCostBasisID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldResolvedCostBasisID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldResolvedCostBasisID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldResolvedCostBasisID: %w", err) + } + return oldValue.ResolvedCostBasisID, nil +} + +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ClearResolvedCostBasisID() { + m.resolved_currency_cost_basis = nil + m.clearedFields[chargecreditpurchasecostbasis.FieldResolvedCostBasisID] = struct{}{} +} + +// ResolvedCostBasisIDCleared returns if the "resolved_cost_basis_id" field was cleared in this mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) ResolvedCostBasisIDCleared() bool { + _, ok := m.clearedFields[chargecreditpurchasecostbasis.FieldResolvedCostBasisID] + return ok +} + +// ResetResolvedCostBasisID resets all changes to the "resolved_cost_basis_id" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ResetResolvedCostBasisID() { + m.resolved_currency_cost_basis = nil + delete(m.clearedFields, chargecreditpurchasecostbasis.FieldResolvedCostBasisID) +} + +// SetCurrencyID sets the "currency_id" field. +func (m *ChargeCreditPurchaseCostBasisMutation) SetCurrencyID(s string) { + m.custom_currency = &s +} + +// CurrencyID returns the value of the "currency_id" field in the mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) CurrencyID() (r string, exists bool) { + v := m.custom_currency + if v == nil { + return + } + return *v, true +} + +// OldCurrencyID returns the old "currency_id" field's value of the ChargeCreditPurchaseCostBasis entity. +// If the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCostBasisMutation) OldCurrencyID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCurrencyID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCurrencyID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCurrencyID: %w", err) + } + return oldValue.CurrencyID, nil +} + +// ResetCurrencyID resets all changes to the "currency_id" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ResetCurrencyID() { + m.custom_currency = nil +} + +// SetManualRate sets the "manual_rate" field. +func (m *ChargeCreditPurchaseCostBasisMutation) SetManualRate(a alpacadecimal.Decimal) { + m.manual_rate = &a +} + +// ManualRate returns the value of the "manual_rate" field in the mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) ManualRate() (r alpacadecimal.Decimal, exists bool) { + v := m.manual_rate + if v == nil { + return + } + return *v, true +} + +// OldManualRate returns the old "manual_rate" field's value of the ChargeCreditPurchaseCostBasis entity. +// If the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCostBasisMutation) OldManualRate(ctx context.Context) (v *alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldManualRate is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldManualRate requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldManualRate: %w", err) + } + return oldValue.ManualRate, nil +} + +// ClearManualRate clears the value of the "manual_rate" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ClearManualRate() { + m.manual_rate = nil + m.clearedFields[chargecreditpurchasecostbasis.FieldManualRate] = struct{}{} +} + +// ManualRateCleared returns if the "manual_rate" field was cleared in this mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) ManualRateCleared() bool { + _, ok := m.clearedFields[chargecreditpurchasecostbasis.FieldManualRate] + return ok +} + +// ResetManualRate resets all changes to the "manual_rate" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ResetManualRate() { + m.manual_rate = nil + delete(m.clearedFields, chargecreditpurchasecostbasis.FieldManualRate) +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (m *ChargeCreditPurchaseCostBasisMutation) SetResolvedCostBasis(a alpacadecimal.Decimal) { + m.resolved_cost_basis = &a +} + +// ResolvedCostBasis returns the value of the "resolved_cost_basis" field in the mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) ResolvedCostBasis() (r alpacadecimal.Decimal, exists bool) { + v := m.resolved_cost_basis + if v == nil { + return + } + return *v, true +} + +// OldResolvedCostBasis returns the old "resolved_cost_basis" field's value of the ChargeCreditPurchaseCostBasis entity. +// If the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCostBasisMutation) OldResolvedCostBasis(ctx context.Context) (v *alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldResolvedCostBasis is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldResolvedCostBasis requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldResolvedCostBasis: %w", err) + } + return oldValue.ResolvedCostBasis, nil +} + +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ClearResolvedCostBasis() { + m.resolved_cost_basis = nil + m.clearedFields[chargecreditpurchasecostbasis.FieldResolvedCostBasis] = struct{}{} +} + +// ResolvedCostBasisCleared returns if the "resolved_cost_basis" field was cleared in this mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) ResolvedCostBasisCleared() bool { + _, ok := m.clearedFields[chargecreditpurchasecostbasis.FieldResolvedCostBasis] + return ok +} + +// ResetResolvedCostBasis resets all changes to the "resolved_cost_basis" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ResetResolvedCostBasis() { + m.resolved_cost_basis = nil + delete(m.clearedFields, chargecreditpurchasecostbasis.FieldResolvedCostBasis) +} + +// SetResolvedAt sets the "resolved_at" field. +func (m *ChargeCreditPurchaseCostBasisMutation) SetResolvedAt(t time.Time) { + m.resolved_at = &t +} + +// ResolvedAt returns the value of the "resolved_at" field in the mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) ResolvedAt() (r time.Time, exists bool) { + v := m.resolved_at + if v == nil { + return + } + return *v, true +} + +// OldResolvedAt returns the old "resolved_at" field's value of the ChargeCreditPurchaseCostBasis entity. +// If the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCostBasisMutation) OldResolvedAt(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldResolvedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldResolvedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldResolvedAt: %w", err) + } + return oldValue.ResolvedAt, nil +} + +// ClearResolvedAt clears the value of the "resolved_at" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ClearResolvedAt() { + m.resolved_at = nil + m.clearedFields[chargecreditpurchasecostbasis.FieldResolvedAt] = struct{}{} +} + +// ResolvedAtCleared returns if the "resolved_at" field was cleared in this mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) ResolvedAtCleared() bool { + _, ok := m.clearedFields[chargecreditpurchasecostbasis.FieldResolvedAt] + return ok +} + +// ResetResolvedAt resets all changes to the "resolved_at" field. +func (m *ChargeCreditPurchaseCostBasisMutation) ResetResolvedAt() { + m.resolved_at = nil + delete(m.clearedFields, chargecreditpurchasecostbasis.FieldResolvedAt) +} + // SetNamespace sets the "namespace" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) SetNamespace(s string) { +func (m *ChargeCreditPurchaseCostBasisMutation) SetNamespace(s string) { m.namespace = &s } // Namespace returns the value of the "namespace" field in the mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) Namespace() (r string, exists bool) { +func (m *ChargeCreditPurchaseCostBasisMutation) Namespace() (r string, exists bool) { v := m.namespace if v == nil { return @@ -42466,10 +42952,10 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) Namespace() (r string, exists return *v, true } -// OldNamespace returns the old "namespace" field's value of the ChargeCreditPurchaseCreditGrant entity. -// If the ChargeCreditPurchaseCreditGrant object wasn't provided to the builder, the object is fetched from the database. +// OldNamespace returns the old "namespace" field's value of the ChargeCreditPurchaseCostBasis entity. +// If the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCreditGrantMutation) OldNamespace(ctx context.Context) (v string, err error) { +func (m *ChargeCreditPurchaseCostBasisMutation) OldNamespace(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldNamespace is only allowed on UpdateOne operations") } @@ -42484,17 +42970,17 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) OldNamespace(ctx context.Conte } // ResetNamespace resets all changes to the "namespace" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) ResetNamespace() { +func (m *ChargeCreditPurchaseCostBasisMutation) ResetNamespace() { m.namespace = nil } // SetCreatedAt sets the "created_at" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) SetCreatedAt(t time.Time) { +func (m *ChargeCreditPurchaseCostBasisMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) CreatedAt() (r time.Time, exists bool) { +func (m *ChargeCreditPurchaseCostBasisMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return @@ -42502,10 +42988,10 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) CreatedAt() (r time.Time, exis return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the ChargeCreditPurchaseCreditGrant entity. -// If the ChargeCreditPurchaseCreditGrant object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the ChargeCreditPurchaseCostBasis entity. +// If the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCreditGrantMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseCostBasisMutation) 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") } @@ -42520,17 +43006,17 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) OldCreatedAt(ctx context.Conte } // ResetCreatedAt resets all changes to the "created_at" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) ResetCreatedAt() { +func (m *ChargeCreditPurchaseCostBasisMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) SetUpdatedAt(t time.Time) { +func (m *ChargeCreditPurchaseCostBasisMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) UpdatedAt() (r time.Time, exists bool) { +func (m *ChargeCreditPurchaseCostBasisMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return @@ -42538,10 +43024,10 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) UpdatedAt() (r time.Time, exis return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the ChargeCreditPurchaseCreditGrant entity. -// If the ChargeCreditPurchaseCreditGrant object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the ChargeCreditPurchaseCostBasis entity. +// If the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCreditGrantMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseCostBasisMutation) 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") } @@ -42556,17 +43042,17 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) OldUpdatedAt(ctx context.Conte } // ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) ResetUpdatedAt() { +func (m *ChargeCreditPurchaseCostBasisMutation) ResetUpdatedAt() { m.updated_at = nil } // SetDeletedAt sets the "deleted_at" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) SetDeletedAt(t time.Time) { +func (m *ChargeCreditPurchaseCostBasisMutation) SetDeletedAt(t time.Time) { m.deleted_at = &t } // DeletedAt returns the value of the "deleted_at" field in the mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) DeletedAt() (r time.Time, exists bool) { +func (m *ChargeCreditPurchaseCostBasisMutation) DeletedAt() (r time.Time, exists bool) { v := m.deleted_at if v == nil { return @@ -42574,10 +43060,10 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) DeletedAt() (r time.Time, exis return *v, true } -// OldDeletedAt returns the old "deleted_at" field's value of the ChargeCreditPurchaseCreditGrant entity. -// If the ChargeCreditPurchaseCreditGrant object wasn't provided to the builder, the object is fetched from the database. +// OldDeletedAt returns the old "deleted_at" field's value of the ChargeCreditPurchaseCostBasis entity. +// If the ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCreditGrantMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeCreditPurchaseCostBasisMutation) 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") } @@ -42592,180 +43078,139 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) OldDeletedAt(ctx context.Conte } // ClearDeletedAt clears the value of the "deleted_at" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) ClearDeletedAt() { +func (m *ChargeCreditPurchaseCostBasisMutation) ClearDeletedAt() { m.deleted_at = nil - m.clearedFields[chargecreditpurchasecreditgrant.FieldDeletedAt] = struct{}{} + m.clearedFields[chargecreditpurchasecostbasis.FieldDeletedAt] = struct{}{} } // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) DeletedAtCleared() bool { - _, ok := m.clearedFields[chargecreditpurchasecreditgrant.FieldDeletedAt] +func (m *ChargeCreditPurchaseCostBasisMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargecreditpurchasecostbasis.FieldDeletedAt] return ok } // ResetDeletedAt resets all changes to the "deleted_at" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) ResetDeletedAt() { +func (m *ChargeCreditPurchaseCostBasisMutation) ResetDeletedAt() { m.deleted_at = nil - delete(m.clearedFields, chargecreditpurchasecreditgrant.FieldDeletedAt) + delete(m.clearedFields, chargecreditpurchasecostbasis.FieldDeletedAt) } -// SetChargeID sets the "charge_id" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) SetChargeID(s string) { - m.credit_purchase = &s +// ClearCurrencyCostBasis clears the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (m *ChargeCreditPurchaseCostBasisMutation) ClearCurrencyCostBasis() { + m.clearedcurrency_cost_basis = true + m.clearedFields[chargecreditpurchasecostbasis.FieldCurrencyCostBasisID] = struct{}{} } -// ChargeID returns the value of the "charge_id" field in the mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) ChargeID() (r string, exists bool) { - v := m.credit_purchase - if v == nil { - return - } - return *v, true +// CurrencyCostBasisCleared reports if the "currency_cost_basis" edge to the CurrencyCostBasis entity was cleared. +func (m *ChargeCreditPurchaseCostBasisMutation) CurrencyCostBasisCleared() bool { + return m.CurrencyCostBasisIDCleared() || m.clearedcurrency_cost_basis } -// OldChargeID returns the old "charge_id" field's value of the ChargeCreditPurchaseCreditGrant entity. -// If the ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseCreditGrantMutation) 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) +// CurrencyCostBasisIDs returns the "currency_cost_basis" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CurrencyCostBasisID instead. It exists only for internal usage by the builders. +func (m *ChargeCreditPurchaseCostBasisMutation) CurrencyCostBasisIDs() (ids []string) { + if id := m.currency_cost_basis; id != nil { + ids = append(ids, *id) } - return oldValue.ChargeID, nil -} - -// ResetChargeID resets all changes to the "charge_id" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) ResetChargeID() { - m.credit_purchase = nil -} - -// SetTransactionGroupID sets the "transaction_group_id" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) SetTransactionGroupID(s string) { - m.transaction_group_id = &s + return } -// TransactionGroupID returns the value of the "transaction_group_id" field in the mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) TransactionGroupID() (r string, exists bool) { - v := m.transaction_group_id - if v == nil { - return - } - return *v, true +// ResetCurrencyCostBasis resets all changes to the "currency_cost_basis" edge. +func (m *ChargeCreditPurchaseCostBasisMutation) ResetCurrencyCostBasis() { + m.currency_cost_basis = nil + m.clearedcurrency_cost_basis = false } -// OldTransactionGroupID returns the old "transaction_group_id" field's value of the ChargeCreditPurchaseCreditGrant entity. -// If the ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseCreditGrantMutation) OldTransactionGroupID(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTransactionGroupID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTransactionGroupID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTransactionGroupID: %w", err) - } - return oldValue.TransactionGroupID, nil +// SetResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by id. +func (m *ChargeCreditPurchaseCostBasisMutation) SetResolvedCurrencyCostBasisID(id string) { + m.resolved_currency_cost_basis = &id } -// ResetTransactionGroupID resets all changes to the "transaction_group_id" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) ResetTransactionGroupID() { - m.transaction_group_id = nil +// ClearResolvedCurrencyCostBasis clears the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (m *ChargeCreditPurchaseCostBasisMutation) ClearResolvedCurrencyCostBasis() { + m.clearedresolved_currency_cost_basis = true + m.clearedFields[chargecreditpurchasecostbasis.FieldResolvedCostBasisID] = struct{}{} } -// SetGrantedAt sets the "granted_at" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) SetGrantedAt(t time.Time) { - m.granted_at = &t +// ResolvedCurrencyCostBasisCleared reports if the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity was cleared. +func (m *ChargeCreditPurchaseCostBasisMutation) ResolvedCurrencyCostBasisCleared() bool { + return m.ResolvedCostBasisIDCleared() || m.clearedresolved_currency_cost_basis } -// GrantedAt returns the value of the "granted_at" field in the mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) GrantedAt() (r time.Time, exists bool) { - v := m.granted_at - if v == nil { - return +// ResolvedCurrencyCostBasisID returns the "resolved_currency_cost_basis" edge ID in the mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) ResolvedCurrencyCostBasisID() (id string, exists bool) { + if m.resolved_currency_cost_basis != nil { + return *m.resolved_currency_cost_basis, true } - return *v, true + return } -// OldGrantedAt returns the old "granted_at" field's value of the ChargeCreditPurchaseCreditGrant entity. -// If the ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseCreditGrantMutation) OldGrantedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldGrantedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldGrantedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldGrantedAt: %w", err) +// ResolvedCurrencyCostBasisIDs returns the "resolved_currency_cost_basis" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ResolvedCurrencyCostBasisID instead. It exists only for internal usage by the builders. +func (m *ChargeCreditPurchaseCostBasisMutation) ResolvedCurrencyCostBasisIDs() (ids []string) { + if id := m.resolved_currency_cost_basis; id != nil { + ids = append(ids, *id) } - return oldValue.GrantedAt, nil + return } -// ResetGrantedAt resets all changes to the "granted_at" field. -func (m *ChargeCreditPurchaseCreditGrantMutation) ResetGrantedAt() { - m.granted_at = nil +// ResetResolvedCurrencyCostBasis resets all changes to the "resolved_currency_cost_basis" edge. +func (m *ChargeCreditPurchaseCostBasisMutation) ResetResolvedCurrencyCostBasis() { + m.resolved_currency_cost_basis = nil + m.clearedresolved_currency_cost_basis = false } -// SetCreditPurchaseID sets the "credit_purchase" edge to the ChargeCreditPurchase entity by id. -func (m *ChargeCreditPurchaseCreditGrantMutation) SetCreditPurchaseID(id string) { - m.credit_purchase = &id +// SetCustomCurrencyID sets the "custom_currency" edge to the CustomCurrency entity by id. +func (m *ChargeCreditPurchaseCostBasisMutation) SetCustomCurrencyID(id string) { + m.custom_currency = &id } -// ClearCreditPurchase clears the "credit_purchase" edge to the ChargeCreditPurchase entity. -func (m *ChargeCreditPurchaseCreditGrantMutation) ClearCreditPurchase() { - m.clearedcredit_purchase = true - m.clearedFields[chargecreditpurchasecreditgrant.FieldChargeID] = struct{}{} +// ClearCustomCurrency clears the "custom_currency" edge to the CustomCurrency entity. +func (m *ChargeCreditPurchaseCostBasisMutation) ClearCustomCurrency() { + m.clearedcustom_currency = true + m.clearedFields[chargecreditpurchasecostbasis.FieldCurrencyID] = struct{}{} } -// CreditPurchaseCleared reports if the "credit_purchase" edge to the ChargeCreditPurchase entity was cleared. -func (m *ChargeCreditPurchaseCreditGrantMutation) CreditPurchaseCleared() bool { - return m.clearedcredit_purchase +// CustomCurrencyCleared reports if the "custom_currency" edge to the CustomCurrency entity was cleared. +func (m *ChargeCreditPurchaseCostBasisMutation) CustomCurrencyCleared() bool { + return m.clearedcustom_currency } -// CreditPurchaseID returns the "credit_purchase" edge ID in the mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) CreditPurchaseID() (id string, exists bool) { - if m.credit_purchase != nil { - return *m.credit_purchase, true +// CustomCurrencyID returns the "custom_currency" edge ID in the mutation. +func (m *ChargeCreditPurchaseCostBasisMutation) CustomCurrencyID() (id string, exists bool) { + if m.custom_currency != nil { + return *m.custom_currency, true } return } -// CreditPurchaseIDs returns the "credit_purchase" edge IDs in the mutation. +// CustomCurrencyIDs returns the "custom_currency" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// CreditPurchaseID instead. It exists only for internal usage by the builders. -func (m *ChargeCreditPurchaseCreditGrantMutation) CreditPurchaseIDs() (ids []string) { - if id := m.credit_purchase; id != nil { +// CustomCurrencyID instead. It exists only for internal usage by the builders. +func (m *ChargeCreditPurchaseCostBasisMutation) CustomCurrencyIDs() (ids []string) { + if id := m.custom_currency; id != nil { ids = append(ids, *id) } return } -// ResetCreditPurchase resets all changes to the "credit_purchase" edge. -func (m *ChargeCreditPurchaseCreditGrantMutation) ResetCreditPurchase() { - m.credit_purchase = nil - m.clearedcredit_purchase = false +// ResetCustomCurrency resets all changes to the "custom_currency" edge. +func (m *ChargeCreditPurchaseCostBasisMutation) ResetCustomCurrency() { + m.custom_currency = nil + m.clearedcustom_currency = false } -// Where appends a list predicates to the ChargeCreditPurchaseCreditGrantMutation builder. -func (m *ChargeCreditPurchaseCreditGrantMutation) Where(ps ...predicate.ChargeCreditPurchaseCreditGrant) { +// Where appends a list predicates to the ChargeCreditPurchaseCostBasisMutation builder. +func (m *ChargeCreditPurchaseCostBasisMutation) Where(ps ...predicate.ChargeCreditPurchaseCostBasis) { m.predicates = append(m.predicates, ps...) } -// WhereP appends storage-level predicates to the ChargeCreditPurchaseCreditGrantMutation builder. Using this method, +// WhereP appends storage-level predicates to the ChargeCreditPurchaseCostBasisMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. -func (m *ChargeCreditPurchaseCreditGrantMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.ChargeCreditPurchaseCreditGrant, len(ps)) +func (m *ChargeCreditPurchaseCostBasisMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeCreditPurchaseCostBasis, len(ps)) for i := range ps { p[i] = ps[i] } @@ -42773,45 +43218,60 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) WhereP(ps ...func(*sql.Selecto } // Op returns the operation name. -func (m *ChargeCreditPurchaseCreditGrantMutation) Op() Op { +func (m *ChargeCreditPurchaseCostBasisMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. -func (m *ChargeCreditPurchaseCreditGrantMutation) SetOp(op Op) { +func (m *ChargeCreditPurchaseCostBasisMutation) SetOp(op Op) { m.op = op } -// Type returns the node type of this mutation (ChargeCreditPurchaseCreditGrant). -func (m *ChargeCreditPurchaseCreditGrantMutation) Type() string { +// Type returns the node type of this mutation (ChargeCreditPurchaseCostBasis). +func (m *ChargeCreditPurchaseCostBasisMutation) 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 *ChargeCreditPurchaseCreditGrantMutation) Fields() []string { - fields := make([]string, 0, 7) +func (m *ChargeCreditPurchaseCostBasisMutation) Fields() []string { + fields := make([]string, 0, 12) + if m.mode != nil { + fields = append(fields, chargecreditpurchasecostbasis.FieldMode) + } + if m.fiat_currency != nil { + fields = append(fields, chargecreditpurchasecostbasis.FieldFiatCurrency) + } + if m.currency_cost_basis != nil { + fields = append(fields, chargecreditpurchasecostbasis.FieldCurrencyCostBasisID) + } + if m.resolved_currency_cost_basis != nil { + fields = append(fields, chargecreditpurchasecostbasis.FieldResolvedCostBasisID) + } + if m.custom_currency != nil { + fields = append(fields, chargecreditpurchasecostbasis.FieldCurrencyID) + } + if m.manual_rate != nil { + fields = append(fields, chargecreditpurchasecostbasis.FieldManualRate) + } + if m.resolved_cost_basis != nil { + fields = append(fields, chargecreditpurchasecostbasis.FieldResolvedCostBasis) + } + if m.resolved_at != nil { + fields = append(fields, chargecreditpurchasecostbasis.FieldResolvedAt) + } if m.namespace != nil { - fields = append(fields, chargecreditpurchasecreditgrant.FieldNamespace) + fields = append(fields, chargecreditpurchasecostbasis.FieldNamespace) } if m.created_at != nil { - fields = append(fields, chargecreditpurchasecreditgrant.FieldCreatedAt) + fields = append(fields, chargecreditpurchasecostbasis.FieldCreatedAt) } if m.updated_at != nil { - fields = append(fields, chargecreditpurchasecreditgrant.FieldUpdatedAt) + fields = append(fields, chargecreditpurchasecostbasis.FieldUpdatedAt) } if m.deleted_at != nil { - fields = append(fields, chargecreditpurchasecreditgrant.FieldDeletedAt) - } - if m.credit_purchase != nil { - fields = append(fields, chargecreditpurchasecreditgrant.FieldChargeID) - } - if m.transaction_group_id != nil { - fields = append(fields, chargecreditpurchasecreditgrant.FieldTransactionGroupID) - } - if m.granted_at != nil { - fields = append(fields, chargecreditpurchasecreditgrant.FieldGrantedAt) + fields = append(fields, chargecreditpurchasecostbasis.FieldDeletedAt) } return fields } @@ -42819,22 +43279,32 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) Fields() []string { // 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 *ChargeCreditPurchaseCreditGrantMutation) Field(name string) (ent.Value, bool) { - switch name { - case chargecreditpurchasecreditgrant.FieldNamespace: +func (m *ChargeCreditPurchaseCostBasisMutation) Field(name string) (ent.Value, bool) { + switch name { + case chargecreditpurchasecostbasis.FieldMode: + return m.Mode() + case chargecreditpurchasecostbasis.FieldFiatCurrency: + return m.FiatCurrency() + case chargecreditpurchasecostbasis.FieldCurrencyCostBasisID: + return m.CurrencyCostBasisID() + case chargecreditpurchasecostbasis.FieldResolvedCostBasisID: + return m.ResolvedCostBasisID() + case chargecreditpurchasecostbasis.FieldCurrencyID: + return m.CurrencyID() + case chargecreditpurchasecostbasis.FieldManualRate: + return m.ManualRate() + case chargecreditpurchasecostbasis.FieldResolvedCostBasis: + return m.ResolvedCostBasis() + case chargecreditpurchasecostbasis.FieldResolvedAt: + return m.ResolvedAt() + case chargecreditpurchasecostbasis.FieldNamespace: return m.Namespace() - case chargecreditpurchasecreditgrant.FieldCreatedAt: + case chargecreditpurchasecostbasis.FieldCreatedAt: return m.CreatedAt() - case chargecreditpurchasecreditgrant.FieldUpdatedAt: + case chargecreditpurchasecostbasis.FieldUpdatedAt: return m.UpdatedAt() - case chargecreditpurchasecreditgrant.FieldDeletedAt: + case chargecreditpurchasecostbasis.FieldDeletedAt: return m.DeletedAt() - case chargecreditpurchasecreditgrant.FieldChargeID: - return m.ChargeID() - case chargecreditpurchasecreditgrant.FieldTransactionGroupID: - return m.TransactionGroupID() - case chargecreditpurchasecreditgrant.FieldGrantedAt: - return m.GrantedAt() } return nil, false } @@ -42842,178 +43312,282 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) Field(name string) (ent.Value, // 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 *ChargeCreditPurchaseCreditGrantMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case chargecreditpurchasecreditgrant.FieldNamespace: +func (m *ChargeCreditPurchaseCostBasisMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case chargecreditpurchasecostbasis.FieldMode: + return m.OldMode(ctx) + case chargecreditpurchasecostbasis.FieldFiatCurrency: + return m.OldFiatCurrency(ctx) + case chargecreditpurchasecostbasis.FieldCurrencyCostBasisID: + return m.OldCurrencyCostBasisID(ctx) + case chargecreditpurchasecostbasis.FieldResolvedCostBasisID: + return m.OldResolvedCostBasisID(ctx) + case chargecreditpurchasecostbasis.FieldCurrencyID: + return m.OldCurrencyID(ctx) + case chargecreditpurchasecostbasis.FieldManualRate: + return m.OldManualRate(ctx) + case chargecreditpurchasecostbasis.FieldResolvedCostBasis: + return m.OldResolvedCostBasis(ctx) + case chargecreditpurchasecostbasis.FieldResolvedAt: + return m.OldResolvedAt(ctx) + case chargecreditpurchasecostbasis.FieldNamespace: return m.OldNamespace(ctx) - case chargecreditpurchasecreditgrant.FieldCreatedAt: + case chargecreditpurchasecostbasis.FieldCreatedAt: return m.OldCreatedAt(ctx) - case chargecreditpurchasecreditgrant.FieldUpdatedAt: + case chargecreditpurchasecostbasis.FieldUpdatedAt: return m.OldUpdatedAt(ctx) - case chargecreditpurchasecreditgrant.FieldDeletedAt: + case chargecreditpurchasecostbasis.FieldDeletedAt: return m.OldDeletedAt(ctx) - case chargecreditpurchasecreditgrant.FieldChargeID: - return m.OldChargeID(ctx) - case chargecreditpurchasecreditgrant.FieldTransactionGroupID: - return m.OldTransactionGroupID(ctx) - case chargecreditpurchasecreditgrant.FieldGrantedAt: - return m.OldGrantedAt(ctx) } - return nil, fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant field %s", name) + return nil, fmt.Errorf("unknown ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCreditGrantMutation) SetField(name string, value ent.Value) error { +func (m *ChargeCreditPurchaseCostBasisMutation) SetField(name string, value ent.Value) error { switch name { - case chargecreditpurchasecreditgrant.FieldNamespace: + case chargecreditpurchasecostbasis.FieldMode: + v, ok := value.(costbasis.Mode) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMode(v) + return nil + case chargecreditpurchasecostbasis.FieldFiatCurrency: + v, ok := value.(currencyx.FiatCode) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFiatCurrency(v) + return nil + case chargecreditpurchasecostbasis.FieldCurrencyCostBasisID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetNamespace(v) + m.SetCurrencyCostBasisID(v) return nil - case chargecreditpurchasecreditgrant.FieldCreatedAt: - v, ok := value.(time.Time) + case chargecreditpurchasecostbasis.FieldResolvedCostBasisID: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCreatedAt(v) + m.SetResolvedCostBasisID(v) return nil - case chargecreditpurchasecreditgrant.FieldUpdatedAt: - v, ok := value.(time.Time) + case chargecreditpurchasecostbasis.FieldCurrencyID: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetUpdatedAt(v) + m.SetCurrencyID(v) return nil - case chargecreditpurchasecreditgrant.FieldDeletedAt: + case chargecreditpurchasecostbasis.FieldManualRate: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetManualRate(v) + return nil + case chargecreditpurchasecostbasis.FieldResolvedCostBasis: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetResolvedCostBasis(v) + return nil + case chargecreditpurchasecostbasis.FieldResolvedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDeletedAt(v) + m.SetResolvedAt(v) return nil - case chargecreditpurchasecreditgrant.FieldChargeID: + case chargecreditpurchasecostbasis.FieldNamespace: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetChargeID(v) + m.SetNamespace(v) return nil - case chargecreditpurchasecreditgrant.FieldTransactionGroupID: - v, ok := value.(string) + case chargecreditpurchasecostbasis.FieldCreatedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetTransactionGroupID(v) + m.SetCreatedAt(v) return nil - case chargecreditpurchasecreditgrant.FieldGrantedAt: + case chargecreditpurchasecostbasis.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetGrantedAt(v) + m.SetUpdatedAt(v) + return nil + case chargecreditpurchasecostbasis.FieldDeletedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDeletedAt(v) return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant field %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseCostBasis field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) AddedFields() []string { +func (m *ChargeCreditPurchaseCostBasisMutation) 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 *ChargeCreditPurchaseCreditGrantMutation) AddedField(name string) (ent.Value, bool) { +func (m *ChargeCreditPurchaseCostBasisMutation) 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 *ChargeCreditPurchaseCreditGrantMutation) AddField(name string, value ent.Value) error { +func (m *ChargeCreditPurchaseCostBasisMutation) AddField(name string, value ent.Value) error { switch name { } - return fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant numeric field %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseCostBasis numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) ClearedFields() []string { +func (m *ChargeCreditPurchaseCostBasisMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(chargecreditpurchasecreditgrant.FieldDeletedAt) { - fields = append(fields, chargecreditpurchasecreditgrant.FieldDeletedAt) + if m.FieldCleared(chargecreditpurchasecostbasis.FieldCurrencyCostBasisID) { + fields = append(fields, chargecreditpurchasecostbasis.FieldCurrencyCostBasisID) + } + if m.FieldCleared(chargecreditpurchasecostbasis.FieldResolvedCostBasisID) { + fields = append(fields, chargecreditpurchasecostbasis.FieldResolvedCostBasisID) + } + if m.FieldCleared(chargecreditpurchasecostbasis.FieldManualRate) { + fields = append(fields, chargecreditpurchasecostbasis.FieldManualRate) + } + if m.FieldCleared(chargecreditpurchasecostbasis.FieldResolvedCostBasis) { + fields = append(fields, chargecreditpurchasecostbasis.FieldResolvedCostBasis) + } + if m.FieldCleared(chargecreditpurchasecostbasis.FieldResolvedAt) { + fields = append(fields, chargecreditpurchasecostbasis.FieldResolvedAt) + } + if m.FieldCleared(chargecreditpurchasecostbasis.FieldDeletedAt) { + fields = append(fields, chargecreditpurchasecostbasis.FieldDeletedAt) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) FieldCleared(name string) bool { +func (m *ChargeCreditPurchaseCostBasisMutation) 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 *ChargeCreditPurchaseCreditGrantMutation) ClearField(name string) error { +func (m *ChargeCreditPurchaseCostBasisMutation) ClearField(name string) error { switch name { - case chargecreditpurchasecreditgrant.FieldDeletedAt: + case chargecreditpurchasecostbasis.FieldCurrencyCostBasisID: + m.ClearCurrencyCostBasisID() + return nil + case chargecreditpurchasecostbasis.FieldResolvedCostBasisID: + m.ClearResolvedCostBasisID() + return nil + case chargecreditpurchasecostbasis.FieldManualRate: + m.ClearManualRate() + return nil + case chargecreditpurchasecostbasis.FieldResolvedCostBasis: + m.ClearResolvedCostBasis() + return nil + case chargecreditpurchasecostbasis.FieldResolvedAt: + m.ClearResolvedAt() + return nil + case chargecreditpurchasecostbasis.FieldDeletedAt: m.ClearDeletedAt() return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant nullable field %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCreditGrantMutation) ResetField(name string) error { +func (m *ChargeCreditPurchaseCostBasisMutation) ResetField(name string) error { switch name { - case chargecreditpurchasecreditgrant.FieldNamespace: + case chargecreditpurchasecostbasis.FieldMode: + m.ResetMode() + return nil + case chargecreditpurchasecostbasis.FieldFiatCurrency: + m.ResetFiatCurrency() + return nil + case chargecreditpurchasecostbasis.FieldCurrencyCostBasisID: + m.ResetCurrencyCostBasisID() + return nil + case chargecreditpurchasecostbasis.FieldResolvedCostBasisID: + m.ResetResolvedCostBasisID() + return nil + case chargecreditpurchasecostbasis.FieldCurrencyID: + m.ResetCurrencyID() + return nil + case chargecreditpurchasecostbasis.FieldManualRate: + m.ResetManualRate() + return nil + case chargecreditpurchasecostbasis.FieldResolvedCostBasis: + m.ResetResolvedCostBasis() + return nil + case chargecreditpurchasecostbasis.FieldResolvedAt: + m.ResetResolvedAt() + return nil + case chargecreditpurchasecostbasis.FieldNamespace: m.ResetNamespace() return nil - case chargecreditpurchasecreditgrant.FieldCreatedAt: + case chargecreditpurchasecostbasis.FieldCreatedAt: m.ResetCreatedAt() return nil - case chargecreditpurchasecreditgrant.FieldUpdatedAt: + case chargecreditpurchasecostbasis.FieldUpdatedAt: m.ResetUpdatedAt() return nil - case chargecreditpurchasecreditgrant.FieldDeletedAt: + case chargecreditpurchasecostbasis.FieldDeletedAt: m.ResetDeletedAt() return nil - case chargecreditpurchasecreditgrant.FieldChargeID: - m.ResetChargeID() - return nil - case chargecreditpurchasecreditgrant.FieldTransactionGroupID: - m.ResetTransactionGroupID() - return nil - case chargecreditpurchasecreditgrant.FieldGrantedAt: - m.ResetGrantedAt() - return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant field %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseCostBasis field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) AddedEdges() []string { - edges := make([]string, 0, 1) - if m.credit_purchase != nil { - edges = append(edges, chargecreditpurchasecreditgrant.EdgeCreditPurchase) +func (m *ChargeCreditPurchaseCostBasisMutation) AddedEdges() []string { + edges := make([]string, 0, 3) + if m.currency_cost_basis != nil { + edges = append(edges, chargecreditpurchasecostbasis.EdgeCurrencyCostBasis) + } + if m.resolved_currency_cost_basis != nil { + edges = append(edges, chargecreditpurchasecostbasis.EdgeResolvedCurrencyCostBasis) + } + if m.custom_currency != nil { + edges = append(edges, chargecreditpurchasecostbasis.EdgeCustomCurrency) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) AddedIDs(name string) []ent.Value { +func (m *ChargeCreditPurchaseCostBasisMutation) AddedIDs(name string) []ent.Value { switch name { - case chargecreditpurchasecreditgrant.EdgeCreditPurchase: - if id := m.credit_purchase; id != nil { + case chargecreditpurchasecostbasis.EdgeCurrencyCostBasis: + if id := m.currency_cost_basis; id != nil { + return []ent.Value{*id} + } + case chargecreditpurchasecostbasis.EdgeResolvedCurrencyCostBasis: + if id := m.resolved_currency_cost_basis; id != nil { + return []ent.Value{*id} + } + case chargecreditpurchasecostbasis.EdgeCustomCurrency: + if id := m.custom_currency; id != nil { return []ent.Value{*id} } } @@ -43021,96 +43595,111 @@ func (m *ChargeCreditPurchaseCreditGrantMutation) AddedIDs(name string) []ent.Va } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) +func (m *ChargeCreditPurchaseCostBasisMutation) RemovedEdges() []string { + edges := make([]string, 0, 3) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) RemovedIDs(name string) []ent.Value { +func (m *ChargeCreditPurchaseCostBasisMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) - if m.clearedcredit_purchase { - edges = append(edges, chargecreditpurchasecreditgrant.EdgeCreditPurchase) +func (m *ChargeCreditPurchaseCostBasisMutation) ClearedEdges() []string { + edges := make([]string, 0, 3) + if m.clearedcurrency_cost_basis { + edges = append(edges, chargecreditpurchasecostbasis.EdgeCurrencyCostBasis) + } + if m.clearedresolved_currency_cost_basis { + edges = append(edges, chargecreditpurchasecostbasis.EdgeResolvedCurrencyCostBasis) + } + if m.clearedcustom_currency { + edges = append(edges, chargecreditpurchasecostbasis.EdgeCustomCurrency) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *ChargeCreditPurchaseCreditGrantMutation) EdgeCleared(name string) bool { +func (m *ChargeCreditPurchaseCostBasisMutation) EdgeCleared(name string) bool { switch name { - case chargecreditpurchasecreditgrant.EdgeCreditPurchase: - return m.clearedcredit_purchase + case chargecreditpurchasecostbasis.EdgeCurrencyCostBasis: + return m.clearedcurrency_cost_basis + case chargecreditpurchasecostbasis.EdgeResolvedCurrencyCostBasis: + return m.clearedresolved_currency_cost_basis + case chargecreditpurchasecostbasis.EdgeCustomCurrency: + return m.clearedcustom_currency } 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 *ChargeCreditPurchaseCreditGrantMutation) ClearEdge(name string) error { +func (m *ChargeCreditPurchaseCostBasisMutation) ClearEdge(name string) error { switch name { - case chargecreditpurchasecreditgrant.EdgeCreditPurchase: - m.ClearCreditPurchase() + case chargecreditpurchasecostbasis.EdgeCurrencyCostBasis: + m.ClearCurrencyCostBasis() + return nil + case chargecreditpurchasecostbasis.EdgeResolvedCurrencyCostBasis: + m.ClearResolvedCurrencyCostBasis() + return nil + case chargecreditpurchasecostbasis.EdgeCustomCurrency: + m.ClearCustomCurrency() return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant unique edge %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseCostBasis 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 *ChargeCreditPurchaseCreditGrantMutation) ResetEdge(name string) error { +func (m *ChargeCreditPurchaseCostBasisMutation) ResetEdge(name string) error { switch name { - case chargecreditpurchasecreditgrant.EdgeCreditPurchase: - m.ResetCreditPurchase() + case chargecreditpurchasecostbasis.EdgeCurrencyCostBasis: + m.ResetCurrencyCostBasis() + return nil + case chargecreditpurchasecostbasis.EdgeResolvedCurrencyCostBasis: + m.ResetResolvedCurrencyCostBasis() + return nil + case chargecreditpurchasecostbasis.EdgeCustomCurrency: + m.ResetCustomCurrency() return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant edge %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseCostBasis edge %s", name) } -// ChargeCreditPurchaseExternalPaymentMutation represents an operation that mutates the ChargeCreditPurchaseExternalPayment nodes in the graph. -type ChargeCreditPurchaseExternalPaymentMutation struct { +// ChargeCreditPurchaseCreditGrantMutation represents an operation that mutates the ChargeCreditPurchaseCreditGrant nodes in the graph. +type ChargeCreditPurchaseCreditGrantMutation struct { config - op Op - typ string - id *string - service_period_from *time.Time - service_period_to *time.Time - status *payment.Status - amount *alpacadecimal.Decimal - authorized_transaction_group_id *string - authorized_at *time.Time - settled_transaction_group_id *string - settled_at *time.Time - namespace *string - created_at *time.Time - updated_at *time.Time - deleted_at *time.Time - annotations *models.Annotations - clearedFields map[string]struct{} - credit_purchase *string - clearedcredit_purchase bool - done bool - oldValue func(context.Context) (*ChargeCreditPurchaseExternalPayment, error) - predicates []predicate.ChargeCreditPurchaseExternalPayment + op Op + typ string + id *string + namespace *string + created_at *time.Time + updated_at *time.Time + deleted_at *time.Time + transaction_group_id *string + granted_at *time.Time + clearedFields map[string]struct{} + credit_purchase *string + clearedcredit_purchase bool + done bool + oldValue func(context.Context) (*ChargeCreditPurchaseCreditGrant, error) + predicates []predicate.ChargeCreditPurchaseCreditGrant } -var _ ent.Mutation = (*ChargeCreditPurchaseExternalPaymentMutation)(nil) +var _ ent.Mutation = (*ChargeCreditPurchaseCreditGrantMutation)(nil) -// chargecreditpurchaseexternalpaymentOption allows management of the mutation configuration using functional options. -type chargecreditpurchaseexternalpaymentOption func(*ChargeCreditPurchaseExternalPaymentMutation) +// chargecreditpurchasecreditgrantOption allows management of the mutation configuration using functional options. +type chargecreditpurchasecreditgrantOption func(*ChargeCreditPurchaseCreditGrantMutation) -// newChargeCreditPurchaseExternalPaymentMutation creates new mutation for the ChargeCreditPurchaseExternalPayment entity. -func newChargeCreditPurchaseExternalPaymentMutation(c config, op Op, opts ...chargecreditpurchaseexternalpaymentOption) *ChargeCreditPurchaseExternalPaymentMutation { - m := &ChargeCreditPurchaseExternalPaymentMutation{ +// newChargeCreditPurchaseCreditGrantMutation creates new mutation for the ChargeCreditPurchaseCreditGrant entity. +func newChargeCreditPurchaseCreditGrantMutation(c config, op Op, opts ...chargecreditpurchasecreditgrantOption) *ChargeCreditPurchaseCreditGrantMutation { + m := &ChargeCreditPurchaseCreditGrantMutation{ config: c, op: op, - typ: TypeChargeCreditPurchaseExternalPayment, + typ: TypeChargeCreditPurchaseCreditGrant, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -43119,20 +43708,20 @@ func newChargeCreditPurchaseExternalPaymentMutation(c config, op Op, opts ...cha return m } -// withChargeCreditPurchaseExternalPaymentID sets the ID field of the mutation. -func withChargeCreditPurchaseExternalPaymentID(id string) chargecreditpurchaseexternalpaymentOption { - return func(m *ChargeCreditPurchaseExternalPaymentMutation) { +// withChargeCreditPurchaseCreditGrantID sets the ID field of the mutation. +func withChargeCreditPurchaseCreditGrantID(id string) chargecreditpurchasecreditgrantOption { + return func(m *ChargeCreditPurchaseCreditGrantMutation) { var ( err error once sync.Once - value *ChargeCreditPurchaseExternalPayment + value *ChargeCreditPurchaseCreditGrant ) - m.oldValue = func(ctx context.Context) (*ChargeCreditPurchaseExternalPayment, error) { + m.oldValue = func(ctx context.Context) (*ChargeCreditPurchaseCreditGrant, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { - value, err = m.Client().ChargeCreditPurchaseExternalPayment.Get(ctx, id) + value, err = m.Client().ChargeCreditPurchaseCreditGrant.Get(ctx, id) } }) return value, err @@ -43141,10 +43730,10 @@ func withChargeCreditPurchaseExternalPaymentID(id string) chargecreditpurchaseex } } -// withChargeCreditPurchaseExternalPayment sets the old ChargeCreditPurchaseExternalPayment of the mutation. -func withChargeCreditPurchaseExternalPayment(node *ChargeCreditPurchaseExternalPayment) chargecreditpurchaseexternalpaymentOption { - return func(m *ChargeCreditPurchaseExternalPaymentMutation) { - m.oldValue = func(context.Context) (*ChargeCreditPurchaseExternalPayment, error) { +// withChargeCreditPurchaseCreditGrant sets the old ChargeCreditPurchaseCreditGrant of the mutation. +func withChargeCreditPurchaseCreditGrant(node *ChargeCreditPurchaseCreditGrant) chargecreditpurchasecreditgrantOption { + return func(m *ChargeCreditPurchaseCreditGrantMutation) { + m.oldValue = func(context.Context) (*ChargeCreditPurchaseCreditGrant, error) { return node, nil } m.id = &node.ID @@ -43153,7 +43742,7 @@ func withChargeCreditPurchaseExternalPayment(node *ChargeCreditPurchaseExternalP // 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 ChargeCreditPurchaseExternalPaymentMutation) Client() *Client { +func (m ChargeCreditPurchaseCreditGrantMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -43161,7 +43750,7 @@ func (m ChargeCreditPurchaseExternalPaymentMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m ChargeCreditPurchaseExternalPaymentMutation) Tx() (*Tx, error) { +func (m ChargeCreditPurchaseCreditGrantMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("db: mutation is not running in a transaction") } @@ -43171,14 +43760,14 @@ func (m ChargeCreditPurchaseExternalPaymentMutation) Tx() (*Tx, error) { } // SetID sets the value of the id field. Note that this -// operation is only accepted on creation of ChargeCreditPurchaseExternalPayment entities. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetID(id string) { +// operation is only accepted on creation of ChargeCreditPurchaseCreditGrant entities. +func (m *ChargeCreditPurchaseCreditGrantMutation) 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 *ChargeCreditPurchaseExternalPaymentMutation) ID() (id string, exists bool) { +func (m *ChargeCreditPurchaseCreditGrantMutation) ID() (id string, exists bool) { if m.id == nil { return } @@ -43189,7 +43778,7 @@ func (m *ChargeCreditPurchaseExternalPaymentMutation) ID() (id string, exists bo // 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 *ChargeCreditPurchaseExternalPaymentMutation) IDs(ctx context.Context) ([]string, error) { +func (m *ChargeCreditPurchaseCreditGrantMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() @@ -43198,612 +43787,295 @@ func (m *ChargeCreditPurchaseExternalPaymentMutation) IDs(ctx context.Context) ( } fallthrough case m.op.Is(OpUpdate | OpDelete): - return m.Client().ChargeCreditPurchaseExternalPayment.Query().Where(m.predicates...).IDs(ctx) + return m.Client().ChargeCreditPurchaseCreditGrant.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } -// SetServicePeriodFrom sets the "service_period_from" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetServicePeriodFrom(t time.Time) { - m.service_period_from = &t +// SetNamespace sets the "namespace" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) SetNamespace(s string) { + m.namespace = &s } -// ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ServicePeriodFrom() (r time.Time, exists bool) { - v := m.service_period_from +// Namespace returns the value of the "namespace" field in the mutation. +func (m *ChargeCreditPurchaseCreditGrantMutation) Namespace() (r string, exists bool) { + v := m.namespace if v == nil { return } return *v, true } -// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment object wasn't provided to the builder, the object is fetched from the database. +// OldNamespace returns the old "namespace" field's value of the ChargeCreditPurchaseCreditGrant entity. +// If the ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseExternalPaymentMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseCreditGrantMutation) OldNamespace(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") + return v, errors.New("OldNamespace is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldServicePeriodFrom requires an ID field in the mutation") + 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 OldServicePeriodFrom: %w", err) + return v, fmt.Errorf("querying old value for OldNamespace: %w", err) } - return oldValue.ServicePeriodFrom, nil + return oldValue.Namespace, nil } -// ResetServicePeriodFrom resets all changes to the "service_period_from" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetServicePeriodFrom() { - m.service_period_from = nil +// ResetNamespace resets all changes to the "namespace" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) ResetNamespace() { + m.namespace = nil } -// SetServicePeriodTo sets the "service_period_to" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetServicePeriodTo(t time.Time) { - m.service_period_to = &t +// SetCreatedAt sets the "created_at" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) SetCreatedAt(t time.Time) { + m.created_at = &t } -// ServicePeriodTo returns the value of the "service_period_to" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ServicePeriodTo() (r time.Time, exists bool) { - v := m.service_period_to +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ChargeCreditPurchaseCreditGrantMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at if v == nil { return } return *v, true } -// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the ChargeCreditPurchaseCreditGrant entity. +// If the ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseExternalPaymentMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseCreditGrantMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldServicePeriodTo requires an ID field in the mutation") + 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 OldServicePeriodTo: %w", err) + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } - return oldValue.ServicePeriodTo, nil + return oldValue.CreatedAt, nil } -// ResetServicePeriodTo resets all changes to the "service_period_to" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetServicePeriodTo() { - m.service_period_to = nil +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) ResetCreatedAt() { + m.created_at = nil } -// SetStatus sets the "status" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetStatus(pa payment.Status) { - m.status = &pa +// SetUpdatedAt sets the "updated_at" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t } -// Status returns the value of the "status" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) Status() (r payment.Status, exists bool) { - v := m.status +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ChargeCreditPurchaseCreditGrantMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at if v == nil { return } return *v, true } -// OldStatus returns the old "status" field's value of the ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the ChargeCreditPurchaseCreditGrant entity. +// If the ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseExternalPaymentMutation) OldStatus(ctx context.Context) (v payment.Status, err error) { +func (m *ChargeCreditPurchaseCreditGrantMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldStatus is only allowed on UpdateOne operations") + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldStatus requires an ID field in the mutation") + 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 OldStatus: %w", err) + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } - return oldValue.Status, nil + return oldValue.UpdatedAt, nil } -// ResetStatus resets all changes to the "status" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetStatus() { - m.status = nil +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) ResetUpdatedAt() { + m.updated_at = nil } -// SetAmount sets the "amount" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetAmount(a alpacadecimal.Decimal) { - m.amount = &a +// SetDeletedAt sets the "deleted_at" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) SetDeletedAt(t time.Time) { + m.deleted_at = &t } -// Amount returns the value of the "amount" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) Amount() (r alpacadecimal.Decimal, exists bool) { - v := m.amount +// DeletedAt returns the value of the "deleted_at" field in the mutation. +func (m *ChargeCreditPurchaseCreditGrantMutation) DeletedAt() (r time.Time, exists bool) { + v := m.deleted_at if v == nil { return } return *v, true } -// OldAmount returns the old "amount" field's value of the ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment object wasn't provided to the builder, the object is fetched from the database. +// OldDeletedAt returns the old "deleted_at" field's value of the ChargeCreditPurchaseCreditGrant entity. +// If the ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseExternalPaymentMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeCreditPurchaseCreditGrantMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAmount is only allowed on UpdateOne operations") + return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAmount requires an ID field in the mutation") + 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 OldAmount: %w", err) + return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) } - return oldValue.Amount, nil + return oldValue.DeletedAt, nil } -// ResetAmount resets all changes to the "amount" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetAmount() { - m.amount = nil +// ClearDeletedAt clears the value of the "deleted_at" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) ClearDeletedAt() { + m.deleted_at = nil + m.clearedFields[chargecreditpurchasecreditgrant.FieldDeletedAt] = struct{}{} } -// SetAuthorizedTransactionGroupID sets the "authorized_transaction_group_id" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetAuthorizedTransactionGroupID(s string) { - m.authorized_transaction_group_id = &s +// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. +func (m *ChargeCreditPurchaseCreditGrantMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargecreditpurchasecreditgrant.FieldDeletedAt] + return ok } -// AuthorizedTransactionGroupID returns the value of the "authorized_transaction_group_id" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) AuthorizedTransactionGroupID() (r string, exists bool) { - v := m.authorized_transaction_group_id +// ResetDeletedAt resets all changes to the "deleted_at" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) ResetDeletedAt() { + m.deleted_at = nil + delete(m.clearedFields, chargecreditpurchasecreditgrant.FieldDeletedAt) +} + +// SetChargeID sets the "charge_id" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) SetChargeID(s string) { + m.credit_purchase = &s +} + +// ChargeID returns the value of the "charge_id" field in the mutation. +func (m *ChargeCreditPurchaseCreditGrantMutation) ChargeID() (r string, exists bool) { + v := m.credit_purchase if v == nil { return } return *v, true } -// OldAuthorizedTransactionGroupID returns the old "authorized_transaction_group_id" field's value of the ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment object wasn't provided to the builder, the object is fetched from the database. +// OldChargeID returns the old "charge_id" field's value of the ChargeCreditPurchaseCreditGrant entity. +// If the ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseExternalPaymentMutation) OldAuthorizedTransactionGroupID(ctx context.Context) (v *string, err error) { +func (m *ChargeCreditPurchaseCreditGrantMutation) OldChargeID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAuthorizedTransactionGroupID is only allowed on UpdateOne operations") + return v, errors.New("OldChargeID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAuthorizedTransactionGroupID requires an ID field in the mutation") + 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 OldAuthorizedTransactionGroupID: %w", err) + return v, fmt.Errorf("querying old value for OldChargeID: %w", err) } - return oldValue.AuthorizedTransactionGroupID, nil -} - -// ClearAuthorizedTransactionGroupID clears the value of the "authorized_transaction_group_id" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearAuthorizedTransactionGroupID() { - m.authorized_transaction_group_id = nil - m.clearedFields[chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID] = struct{}{} -} - -// AuthorizedTransactionGroupIDCleared returns if the "authorized_transaction_group_id" field was cleared in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) AuthorizedTransactionGroupIDCleared() bool { - _, ok := m.clearedFields[chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID] - return ok + return oldValue.ChargeID, nil } -// ResetAuthorizedTransactionGroupID resets all changes to the "authorized_transaction_group_id" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetAuthorizedTransactionGroupID() { - m.authorized_transaction_group_id = nil - delete(m.clearedFields, chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID) +// ResetChargeID resets all changes to the "charge_id" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) ResetChargeID() { + m.credit_purchase = nil } -// SetAuthorizedAt sets the "authorized_at" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetAuthorizedAt(t time.Time) { - m.authorized_at = &t +// SetTransactionGroupID sets the "transaction_group_id" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) SetTransactionGroupID(s string) { + m.transaction_group_id = &s } -// AuthorizedAt returns the value of the "authorized_at" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) AuthorizedAt() (r time.Time, exists bool) { - v := m.authorized_at +// TransactionGroupID returns the value of the "transaction_group_id" field in the mutation. +func (m *ChargeCreditPurchaseCreditGrantMutation) TransactionGroupID() (r string, exists bool) { + v := m.transaction_group_id if v == nil { return } return *v, true } -// OldAuthorizedAt returns the old "authorized_at" field's value of the ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment object wasn't provided to the builder, the object is fetched from the database. +// OldTransactionGroupID returns the old "transaction_group_id" field's value of the ChargeCreditPurchaseCreditGrant entity. +// If the ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseExternalPaymentMutation) OldAuthorizedAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeCreditPurchaseCreditGrantMutation) OldTransactionGroupID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAuthorizedAt is only allowed on UpdateOne operations") + return v, errors.New("OldTransactionGroupID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAuthorizedAt requires an ID field in the mutation") + return v, errors.New("OldTransactionGroupID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldAuthorizedAt: %w", err) + return v, fmt.Errorf("querying old value for OldTransactionGroupID: %w", err) } - return oldValue.AuthorizedAt, nil -} - -// ClearAuthorizedAt clears the value of the "authorized_at" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearAuthorizedAt() { - m.authorized_at = nil - m.clearedFields[chargecreditpurchaseexternalpayment.FieldAuthorizedAt] = struct{}{} -} - -// AuthorizedAtCleared returns if the "authorized_at" field was cleared in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) AuthorizedAtCleared() bool { - _, ok := m.clearedFields[chargecreditpurchaseexternalpayment.FieldAuthorizedAt] - return ok + return oldValue.TransactionGroupID, nil } -// ResetAuthorizedAt resets all changes to the "authorized_at" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetAuthorizedAt() { - m.authorized_at = nil - delete(m.clearedFields, chargecreditpurchaseexternalpayment.FieldAuthorizedAt) +// ResetTransactionGroupID resets all changes to the "transaction_group_id" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) ResetTransactionGroupID() { + m.transaction_group_id = nil } -// SetSettledTransactionGroupID sets the "settled_transaction_group_id" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetSettledTransactionGroupID(s string) { - m.settled_transaction_group_id = &s +// SetGrantedAt sets the "granted_at" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) SetGrantedAt(t time.Time) { + m.granted_at = &t } -// SettledTransactionGroupID returns the value of the "settled_transaction_group_id" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SettledTransactionGroupID() (r string, exists bool) { - v := m.settled_transaction_group_id +// GrantedAt returns the value of the "granted_at" field in the mutation. +func (m *ChargeCreditPurchaseCreditGrantMutation) GrantedAt() (r time.Time, exists bool) { + v := m.granted_at if v == nil { return } return *v, true } -// OldSettledTransactionGroupID returns the old "settled_transaction_group_id" field's value of the ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment object wasn't provided to the builder, the object is fetched from the database. +// OldGrantedAt returns the old "granted_at" field's value of the ChargeCreditPurchaseCreditGrant entity. +// If the ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseExternalPaymentMutation) OldSettledTransactionGroupID(ctx context.Context) (v *string, err error) { +func (m *ChargeCreditPurchaseCreditGrantMutation) OldGrantedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSettledTransactionGroupID is only allowed on UpdateOne operations") + return v, errors.New("OldGrantedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSettledTransactionGroupID requires an ID field in the mutation") + return v, errors.New("OldGrantedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldSettledTransactionGroupID: %w", err) + return v, fmt.Errorf("querying old value for OldGrantedAt: %w", err) } - return oldValue.SettledTransactionGroupID, nil + return oldValue.GrantedAt, nil } -// ClearSettledTransactionGroupID clears the value of the "settled_transaction_group_id" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearSettledTransactionGroupID() { - m.settled_transaction_group_id = nil - m.clearedFields[chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID] = struct{}{} +// ResetGrantedAt resets all changes to the "granted_at" field. +func (m *ChargeCreditPurchaseCreditGrantMutation) ResetGrantedAt() { + m.granted_at = nil } -// SettledTransactionGroupIDCleared returns if the "settled_transaction_group_id" field was cleared in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SettledTransactionGroupIDCleared() bool { - _, ok := m.clearedFields[chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID] - return ok -} - -// ResetSettledTransactionGroupID resets all changes to the "settled_transaction_group_id" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetSettledTransactionGroupID() { - m.settled_transaction_group_id = nil - delete(m.clearedFields, chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID) -} - -// SetSettledAt sets the "settled_at" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetSettledAt(t time.Time) { - m.settled_at = &t -} - -// SettledAt returns the value of the "settled_at" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SettledAt() (r time.Time, exists bool) { - v := m.settled_at - if v == nil { - return - } - return *v, true -} - -// OldSettledAt returns the old "settled_at" field's value of the ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseExternalPaymentMutation) OldSettledAt(ctx context.Context) (v *time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSettledAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSettledAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldSettledAt: %w", err) - } - return oldValue.SettledAt, nil -} - -// ClearSettledAt clears the value of the "settled_at" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearSettledAt() { - m.settled_at = nil - m.clearedFields[chargecreditpurchaseexternalpayment.FieldSettledAt] = struct{}{} -} - -// SettledAtCleared returns if the "settled_at" field was cleared in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SettledAtCleared() bool { - _, ok := m.clearedFields[chargecreditpurchaseexternalpayment.FieldSettledAt] - return ok -} - -// ResetSettledAt resets all changes to the "settled_at" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetSettledAt() { - m.settled_at = nil - delete(m.clearedFields, chargecreditpurchaseexternalpayment.FieldSettledAt) -} - -// SetNamespace sets the "namespace" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetNamespace(s string) { - m.namespace = &s -} - -// Namespace returns the value of the "namespace" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) 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 ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseExternalPaymentMutation) 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 *ChargeCreditPurchaseExternalPaymentMutation) ResetNamespace() { - m.namespace = nil -} - -// SetCreatedAt sets the "created_at" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) 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 ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseExternalPaymentMutation) 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 *ChargeCreditPurchaseExternalPaymentMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) 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 ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseExternalPaymentMutation) 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 *ChargeCreditPurchaseExternalPaymentMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// SetDeletedAt sets the "deleted_at" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetDeletedAt(t time.Time) { - m.deleted_at = &t -} - -// DeletedAt returns the value of the "deleted_at" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) 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 ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseExternalPaymentMutation) 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 *ChargeCreditPurchaseExternalPaymentMutation) ClearDeletedAt() { - m.deleted_at = nil - m.clearedFields[chargecreditpurchaseexternalpayment.FieldDeletedAt] = struct{}{} -} - -// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) DeletedAtCleared() bool { - _, ok := m.clearedFields[chargecreditpurchaseexternalpayment.FieldDeletedAt] - return ok -} - -// ResetDeletedAt resets all changes to the "deleted_at" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetDeletedAt() { - m.deleted_at = nil - delete(m.clearedFields, chargecreditpurchaseexternalpayment.FieldDeletedAt) -} - -// SetAnnotations sets the "annotations" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetAnnotations(value models.Annotations) { - m.annotations = &value -} - -// Annotations returns the value of the "annotations" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) 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 ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseExternalPaymentMutation) 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 *ChargeCreditPurchaseExternalPaymentMutation) ClearAnnotations() { - m.annotations = nil - m.clearedFields[chargecreditpurchaseexternalpayment.FieldAnnotations] = struct{}{} -} - -// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) AnnotationsCleared() bool { - _, ok := m.clearedFields[chargecreditpurchaseexternalpayment.FieldAnnotations] - return ok -} - -// ResetAnnotations resets all changes to the "annotations" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetAnnotations() { - m.annotations = nil - delete(m.clearedFields, chargecreditpurchaseexternalpayment.FieldAnnotations) -} - -// SetChargeID sets the "charge_id" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetChargeID(s string) { - m.credit_purchase = &s -} - -// ChargeID returns the value of the "charge_id" field in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ChargeID() (r string, exists bool) { - v := m.credit_purchase - if v == nil { - return - } - return *v, true -} - -// OldChargeID returns the old "charge_id" field's value of the ChargeCreditPurchaseExternalPayment entity. -// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseExternalPaymentMutation) 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 -} - -// ResetChargeID resets all changes to the "charge_id" field. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetChargeID() { - m.credit_purchase = nil -} - -// SetCreditPurchaseID sets the "credit_purchase" edge to the ChargeCreditPurchase entity by id. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetCreditPurchaseID(id string) { - m.credit_purchase = &id +// SetCreditPurchaseID sets the "credit_purchase" edge to the ChargeCreditPurchase entity by id. +func (m *ChargeCreditPurchaseCreditGrantMutation) SetCreditPurchaseID(id string) { + m.credit_purchase = &id } // ClearCreditPurchase clears the "credit_purchase" edge to the ChargeCreditPurchase entity. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearCreditPurchase() { +func (m *ChargeCreditPurchaseCreditGrantMutation) ClearCreditPurchase() { m.clearedcredit_purchase = true - m.clearedFields[chargecreditpurchaseexternalpayment.FieldChargeID] = struct{}{} + m.clearedFields[chargecreditpurchasecreditgrant.FieldChargeID] = struct{}{} } // CreditPurchaseCleared reports if the "credit_purchase" edge to the ChargeCreditPurchase entity was cleared. -func (m *ChargeCreditPurchaseExternalPaymentMutation) CreditPurchaseCleared() bool { +func (m *ChargeCreditPurchaseCreditGrantMutation) CreditPurchaseCleared() bool { return m.clearedcredit_purchase } // CreditPurchaseID returns the "credit_purchase" edge ID in the mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) CreditPurchaseID() (id string, exists bool) { +func (m *ChargeCreditPurchaseCreditGrantMutation) CreditPurchaseID() (id string, exists bool) { if m.credit_purchase != nil { return *m.credit_purchase, true } @@ -43813,7 +44085,7 @@ func (m *ChargeCreditPurchaseExternalPaymentMutation) CreditPurchaseID() (id str // CreditPurchaseIDs returns the "credit_purchase" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // CreditPurchaseID instead. It exists only for internal usage by the builders. -func (m *ChargeCreditPurchaseExternalPaymentMutation) CreditPurchaseIDs() (ids []string) { +func (m *ChargeCreditPurchaseCreditGrantMutation) CreditPurchaseIDs() (ids []string) { if id := m.credit_purchase; id != nil { ids = append(ids, *id) } @@ -43821,20 +44093,20 @@ func (m *ChargeCreditPurchaseExternalPaymentMutation) CreditPurchaseIDs() (ids [ } // ResetCreditPurchase resets all changes to the "credit_purchase" edge. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetCreditPurchase() { +func (m *ChargeCreditPurchaseCreditGrantMutation) ResetCreditPurchase() { m.credit_purchase = nil m.clearedcredit_purchase = false } -// Where appends a list predicates to the ChargeCreditPurchaseExternalPaymentMutation builder. -func (m *ChargeCreditPurchaseExternalPaymentMutation) Where(ps ...predicate.ChargeCreditPurchaseExternalPayment) { +// Where appends a list predicates to the ChargeCreditPurchaseCreditGrantMutation builder. +func (m *ChargeCreditPurchaseCreditGrantMutation) Where(ps ...predicate.ChargeCreditPurchaseCreditGrant) { m.predicates = append(m.predicates, ps...) } -// WhereP appends storage-level predicates to the ChargeCreditPurchaseExternalPaymentMutation builder. Using this method, +// WhereP appends storage-level predicates to the ChargeCreditPurchaseCreditGrantMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. -func (m *ChargeCreditPurchaseExternalPaymentMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.ChargeCreditPurchaseExternalPayment, len(ps)) +func (m *ChargeCreditPurchaseCreditGrantMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeCreditPurchaseCreditGrant, len(ps)) for i := range ps { p[i] = ps[i] } @@ -43842,66 +44114,45 @@ func (m *ChargeCreditPurchaseExternalPaymentMutation) WhereP(ps ...func(*sql.Sel } // Op returns the operation name. -func (m *ChargeCreditPurchaseExternalPaymentMutation) Op() Op { +func (m *ChargeCreditPurchaseCreditGrantMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) SetOp(op Op) { +func (m *ChargeCreditPurchaseCreditGrantMutation) SetOp(op Op) { m.op = op } -// Type returns the node type of this mutation (ChargeCreditPurchaseExternalPayment). -func (m *ChargeCreditPurchaseExternalPaymentMutation) Type() string { +// Type returns the node type of this mutation (ChargeCreditPurchaseCreditGrant). +func (m *ChargeCreditPurchaseCreditGrantMutation) 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 *ChargeCreditPurchaseExternalPaymentMutation) Fields() []string { - fields := make([]string, 0, 14) - if m.service_period_from != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldServicePeriodFrom) - } - if m.service_period_to != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldServicePeriodTo) - } - if m.status != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldStatus) - } - if m.amount != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldAmount) - } - if m.authorized_transaction_group_id != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID) - } - if m.authorized_at != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldAuthorizedAt) - } - if m.settled_transaction_group_id != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID) - } - if m.settled_at != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldSettledAt) - } +func (m *ChargeCreditPurchaseCreditGrantMutation) Fields() []string { + fields := make([]string, 0, 7) if m.namespace != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldNamespace) + fields = append(fields, chargecreditpurchasecreditgrant.FieldNamespace) } if m.created_at != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldCreatedAt) + fields = append(fields, chargecreditpurchasecreditgrant.FieldCreatedAt) } if m.updated_at != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldUpdatedAt) + fields = append(fields, chargecreditpurchasecreditgrant.FieldUpdatedAt) } if m.deleted_at != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldDeletedAt) - } - if m.annotations != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldAnnotations) + fields = append(fields, chargecreditpurchasecreditgrant.FieldDeletedAt) } if m.credit_purchase != nil { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldChargeID) + fields = append(fields, chargecreditpurchasecreditgrant.FieldChargeID) + } + if m.transaction_group_id != nil { + fields = append(fields, chargecreditpurchasecreditgrant.FieldTransactionGroupID) + } + if m.granted_at != nil { + fields = append(fields, chargecreditpurchasecreditgrant.FieldGrantedAt) } return fields } @@ -43909,36 +44160,22 @@ func (m *ChargeCreditPurchaseExternalPaymentMutation) Fields() []string { // 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 *ChargeCreditPurchaseExternalPaymentMutation) Field(name string) (ent.Value, bool) { +func (m *ChargeCreditPurchaseCreditGrantMutation) Field(name string) (ent.Value, bool) { switch name { - case chargecreditpurchaseexternalpayment.FieldServicePeriodFrom: - return m.ServicePeriodFrom() - case chargecreditpurchaseexternalpayment.FieldServicePeriodTo: - return m.ServicePeriodTo() - case chargecreditpurchaseexternalpayment.FieldStatus: - return m.Status() - case chargecreditpurchaseexternalpayment.FieldAmount: - return m.Amount() - case chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID: - return m.AuthorizedTransactionGroupID() - case chargecreditpurchaseexternalpayment.FieldAuthorizedAt: - return m.AuthorizedAt() - case chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID: - return m.SettledTransactionGroupID() - case chargecreditpurchaseexternalpayment.FieldSettledAt: - return m.SettledAt() - case chargecreditpurchaseexternalpayment.FieldNamespace: + case chargecreditpurchasecreditgrant.FieldNamespace: return m.Namespace() - case chargecreditpurchaseexternalpayment.FieldCreatedAt: + case chargecreditpurchasecreditgrant.FieldCreatedAt: return m.CreatedAt() - case chargecreditpurchaseexternalpayment.FieldUpdatedAt: + case chargecreditpurchasecreditgrant.FieldUpdatedAt: return m.UpdatedAt() - case chargecreditpurchaseexternalpayment.FieldDeletedAt: + case chargecreditpurchasecreditgrant.FieldDeletedAt: return m.DeletedAt() - case chargecreditpurchaseexternalpayment.FieldAnnotations: - return m.Annotations() - case chargecreditpurchaseexternalpayment.FieldChargeID: + case chargecreditpurchasecreditgrant.FieldChargeID: return m.ChargeID() + case chargecreditpurchasecreditgrant.FieldTransactionGroupID: + return m.TransactionGroupID() + case chargecreditpurchasecreditgrant.FieldGrantedAt: + return m.GrantedAt() } return nil, false } @@ -43946,291 +44183,177 @@ func (m *ChargeCreditPurchaseExternalPaymentMutation) Field(name string) (ent.Va // 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 *ChargeCreditPurchaseExternalPaymentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *ChargeCreditPurchaseCreditGrantMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case chargecreditpurchaseexternalpayment.FieldServicePeriodFrom: - return m.OldServicePeriodFrom(ctx) - case chargecreditpurchaseexternalpayment.FieldServicePeriodTo: - return m.OldServicePeriodTo(ctx) - case chargecreditpurchaseexternalpayment.FieldStatus: - return m.OldStatus(ctx) - case chargecreditpurchaseexternalpayment.FieldAmount: - return m.OldAmount(ctx) - case chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID: - return m.OldAuthorizedTransactionGroupID(ctx) - case chargecreditpurchaseexternalpayment.FieldAuthorizedAt: - return m.OldAuthorizedAt(ctx) - case chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID: - return m.OldSettledTransactionGroupID(ctx) - case chargecreditpurchaseexternalpayment.FieldSettledAt: - return m.OldSettledAt(ctx) - case chargecreditpurchaseexternalpayment.FieldNamespace: + case chargecreditpurchasecreditgrant.FieldNamespace: return m.OldNamespace(ctx) - case chargecreditpurchaseexternalpayment.FieldCreatedAt: + case chargecreditpurchasecreditgrant.FieldCreatedAt: return m.OldCreatedAt(ctx) - case chargecreditpurchaseexternalpayment.FieldUpdatedAt: + case chargecreditpurchasecreditgrant.FieldUpdatedAt: return m.OldUpdatedAt(ctx) - case chargecreditpurchaseexternalpayment.FieldDeletedAt: + case chargecreditpurchasecreditgrant.FieldDeletedAt: return m.OldDeletedAt(ctx) - case chargecreditpurchaseexternalpayment.FieldAnnotations: - return m.OldAnnotations(ctx) - case chargecreditpurchaseexternalpayment.FieldChargeID: + case chargecreditpurchasecreditgrant.FieldChargeID: return m.OldChargeID(ctx) + case chargecreditpurchasecreditgrant.FieldTransactionGroupID: + return m.OldTransactionGroupID(ctx) + case chargecreditpurchasecreditgrant.FieldGrantedAt: + return m.OldGrantedAt(ctx) } - return nil, fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment field %s", name) + return nil, fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseExternalPaymentMutation) SetField(name string, value ent.Value) error { +func (m *ChargeCreditPurchaseCreditGrantMutation) SetField(name string, value ent.Value) error { switch name { - case chargecreditpurchaseexternalpayment.FieldServicePeriodFrom: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetServicePeriodFrom(v) - return nil - case chargecreditpurchaseexternalpayment.FieldServicePeriodTo: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetServicePeriodTo(v) - return nil - case chargecreditpurchaseexternalpayment.FieldStatus: - v, ok := value.(payment.Status) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetStatus(v) - return nil - case chargecreditpurchaseexternalpayment.FieldAmount: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetAmount(v) - return nil - case chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID: + case chargecreditpurchasecreditgrant.FieldNamespace: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetAuthorizedTransactionGroupID(v) + m.SetNamespace(v) return nil - case chargecreditpurchaseexternalpayment.FieldAuthorizedAt: + case chargecreditpurchasecreditgrant.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetAuthorizedAt(v) + m.SetCreatedAt(v) return nil - case chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID: - v, ok := value.(string) + case chargecreditpurchasecreditgrant.FieldUpdatedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetSettledTransactionGroupID(v) + m.SetUpdatedAt(v) return nil - case chargecreditpurchaseexternalpayment.FieldSettledAt: + case chargecreditpurchasecreditgrant.FieldDeletedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetSettledAt(v) + m.SetDeletedAt(v) return nil - case chargecreditpurchaseexternalpayment.FieldNamespace: + case chargecreditpurchasecreditgrant.FieldChargeID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetNamespace(v) + m.SetChargeID(v) return nil - case chargecreditpurchaseexternalpayment.FieldCreatedAt: - v, ok := value.(time.Time) + case chargecreditpurchasecreditgrant.FieldTransactionGroupID: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCreatedAt(v) + m.SetTransactionGroupID(v) return nil - case chargecreditpurchaseexternalpayment.FieldUpdatedAt: + case chargecreditpurchasecreditgrant.FieldGrantedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetUpdatedAt(v) - return nil - case chargecreditpurchaseexternalpayment.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 chargecreditpurchaseexternalpayment.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 chargecreditpurchaseexternalpayment.FieldChargeID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetChargeID(v) + m.SetGrantedAt(v) return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment field %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) AddedFields() []string { +func (m *ChargeCreditPurchaseCreditGrantMutation) 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 *ChargeCreditPurchaseExternalPaymentMutation) AddedField(name string) (ent.Value, bool) { +func (m *ChargeCreditPurchaseCreditGrantMutation) 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 *ChargeCreditPurchaseExternalPaymentMutation) AddField(name string, value ent.Value) error { +func (m *ChargeCreditPurchaseCreditGrantMutation) AddField(name string, value ent.Value) error { switch name { } - return fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment numeric field %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearedFields() []string { +func (m *ChargeCreditPurchaseCreditGrantMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID) { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID) - } - if m.FieldCleared(chargecreditpurchaseexternalpayment.FieldAuthorizedAt) { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldAuthorizedAt) - } - if m.FieldCleared(chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID) { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID) - } - if m.FieldCleared(chargecreditpurchaseexternalpayment.FieldSettledAt) { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldSettledAt) - } - if m.FieldCleared(chargecreditpurchaseexternalpayment.FieldDeletedAt) { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldDeletedAt) - } - if m.FieldCleared(chargecreditpurchaseexternalpayment.FieldAnnotations) { - fields = append(fields, chargecreditpurchaseexternalpayment.FieldAnnotations) + if m.FieldCleared(chargecreditpurchasecreditgrant.FieldDeletedAt) { + fields = append(fields, chargecreditpurchasecreditgrant.FieldDeletedAt) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) FieldCleared(name string) bool { +func (m *ChargeCreditPurchaseCreditGrantMutation) 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 *ChargeCreditPurchaseExternalPaymentMutation) ClearField(name string) error { +func (m *ChargeCreditPurchaseCreditGrantMutation) ClearField(name string) error { switch name { - case chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID: - m.ClearAuthorizedTransactionGroupID() - return nil - case chargecreditpurchaseexternalpayment.FieldAuthorizedAt: - m.ClearAuthorizedAt() - return nil - case chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID: - m.ClearSettledTransactionGroupID() - return nil - case chargecreditpurchaseexternalpayment.FieldSettledAt: - m.ClearSettledAt() - return nil - case chargecreditpurchaseexternalpayment.FieldDeletedAt: + case chargecreditpurchasecreditgrant.FieldDeletedAt: m.ClearDeletedAt() return nil - case chargecreditpurchaseexternalpayment.FieldAnnotations: - m.ClearAnnotations() - return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment nullable field %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseExternalPaymentMutation) ResetField(name string) error { +func (m *ChargeCreditPurchaseCreditGrantMutation) ResetField(name string) error { switch name { - case chargecreditpurchaseexternalpayment.FieldServicePeriodFrom: - m.ResetServicePeriodFrom() - return nil - case chargecreditpurchaseexternalpayment.FieldServicePeriodTo: - m.ResetServicePeriodTo() - return nil - case chargecreditpurchaseexternalpayment.FieldStatus: - m.ResetStatus() - return nil - case chargecreditpurchaseexternalpayment.FieldAmount: - m.ResetAmount() - return nil - case chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID: - m.ResetAuthorizedTransactionGroupID() - return nil - case chargecreditpurchaseexternalpayment.FieldAuthorizedAt: - m.ResetAuthorizedAt() - return nil - case chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID: - m.ResetSettledTransactionGroupID() - return nil - case chargecreditpurchaseexternalpayment.FieldSettledAt: - m.ResetSettledAt() - return nil - case chargecreditpurchaseexternalpayment.FieldNamespace: + case chargecreditpurchasecreditgrant.FieldNamespace: m.ResetNamespace() return nil - case chargecreditpurchaseexternalpayment.FieldCreatedAt: + case chargecreditpurchasecreditgrant.FieldCreatedAt: m.ResetCreatedAt() return nil - case chargecreditpurchaseexternalpayment.FieldUpdatedAt: + case chargecreditpurchasecreditgrant.FieldUpdatedAt: m.ResetUpdatedAt() return nil - case chargecreditpurchaseexternalpayment.FieldDeletedAt: + case chargecreditpurchasecreditgrant.FieldDeletedAt: m.ResetDeletedAt() return nil - case chargecreditpurchaseexternalpayment.FieldAnnotations: - m.ResetAnnotations() - return nil - case chargecreditpurchaseexternalpayment.FieldChargeID: + case chargecreditpurchasecreditgrant.FieldChargeID: m.ResetChargeID() return nil + case chargecreditpurchasecreditgrant.FieldTransactionGroupID: + m.ResetTransactionGroupID() + return nil + case chargecreditpurchasecreditgrant.FieldGrantedAt: + m.ResetGrantedAt() + return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment field %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) AddedEdges() []string { +func (m *ChargeCreditPurchaseCreditGrantMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.credit_purchase != nil { - edges = append(edges, chargecreditpurchaseexternalpayment.EdgeCreditPurchase) + edges = append(edges, chargecreditpurchasecreditgrant.EdgeCreditPurchase) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) AddedIDs(name string) []ent.Value { +func (m *ChargeCreditPurchaseCreditGrantMutation) AddedIDs(name string) []ent.Value { switch name { - case chargecreditpurchaseexternalpayment.EdgeCreditPurchase: + case chargecreditpurchasecreditgrant.EdgeCreditPurchase: if id := m.credit_purchase; id != nil { return []ent.Value{*id} } @@ -44239,31 +44362,31 @@ func (m *ChargeCreditPurchaseExternalPaymentMutation) AddedIDs(name string) []en } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) RemovedEdges() []string { +func (m *ChargeCreditPurchaseCreditGrantMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) RemovedIDs(name string) []ent.Value { +func (m *ChargeCreditPurchaseCreditGrantMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearedEdges() []string { +func (m *ChargeCreditPurchaseCreditGrantMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedcredit_purchase { - edges = append(edges, chargecreditpurchaseexternalpayment.EdgeCreditPurchase) + edges = append(edges, chargecreditpurchasecreditgrant.EdgeCreditPurchase) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *ChargeCreditPurchaseExternalPaymentMutation) EdgeCleared(name string) bool { +func (m *ChargeCreditPurchaseCreditGrantMutation) EdgeCleared(name string) bool { switch name { - case chargecreditpurchaseexternalpayment.EdgeCreditPurchase: + case chargecreditpurchasecreditgrant.EdgeCreditPurchase: return m.clearedcredit_purchase } return false @@ -44271,33 +44394,32 @@ func (m *ChargeCreditPurchaseExternalPaymentMutation) EdgeCleared(name string) b // 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 *ChargeCreditPurchaseExternalPaymentMutation) ClearEdge(name string) error { +func (m *ChargeCreditPurchaseCreditGrantMutation) ClearEdge(name string) error { switch name { - case chargecreditpurchaseexternalpayment.EdgeCreditPurchase: + case chargecreditpurchasecreditgrant.EdgeCreditPurchase: m.ClearCreditPurchase() return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment unique edge %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant 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 *ChargeCreditPurchaseExternalPaymentMutation) ResetEdge(name string) error { +func (m *ChargeCreditPurchaseCreditGrantMutation) ResetEdge(name string) error { switch name { - case chargecreditpurchaseexternalpayment.EdgeCreditPurchase: + case chargecreditpurchasecreditgrant.EdgeCreditPurchase: m.ResetCreditPurchase() return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment edge %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseCreditGrant edge %s", name) } -// ChargeCreditPurchaseInvoicedPaymentMutation represents an operation that mutates the ChargeCreditPurchaseInvoicedPayment nodes in the graph. -type ChargeCreditPurchaseInvoicedPaymentMutation struct { +// ChargeCreditPurchaseExternalPaymentMutation represents an operation that mutates the ChargeCreditPurchaseExternalPayment nodes in the graph. +type ChargeCreditPurchaseExternalPaymentMutation struct { config op Op typ string id *string - invoice_id *string service_period_from *time.Time service_period_to *time.Time status *payment.Status @@ -44312,26 +44434,24 @@ type ChargeCreditPurchaseInvoicedPaymentMutation struct { deleted_at *time.Time annotations *models.Annotations clearedFields map[string]struct{} - billing_invoice_line *string - clearedbilling_invoice_line bool credit_purchase *string clearedcredit_purchase bool done bool - oldValue func(context.Context) (*ChargeCreditPurchaseInvoicedPayment, error) - predicates []predicate.ChargeCreditPurchaseInvoicedPayment + oldValue func(context.Context) (*ChargeCreditPurchaseExternalPayment, error) + predicates []predicate.ChargeCreditPurchaseExternalPayment } -var _ ent.Mutation = (*ChargeCreditPurchaseInvoicedPaymentMutation)(nil) +var _ ent.Mutation = (*ChargeCreditPurchaseExternalPaymentMutation)(nil) -// chargecreditpurchaseinvoicedpaymentOption allows management of the mutation configuration using functional options. -type chargecreditpurchaseinvoicedpaymentOption func(*ChargeCreditPurchaseInvoicedPaymentMutation) +// chargecreditpurchaseexternalpaymentOption allows management of the mutation configuration using functional options. +type chargecreditpurchaseexternalpaymentOption func(*ChargeCreditPurchaseExternalPaymentMutation) -// newChargeCreditPurchaseInvoicedPaymentMutation creates new mutation for the ChargeCreditPurchaseInvoicedPayment entity. -func newChargeCreditPurchaseInvoicedPaymentMutation(c config, op Op, opts ...chargecreditpurchaseinvoicedpaymentOption) *ChargeCreditPurchaseInvoicedPaymentMutation { - m := &ChargeCreditPurchaseInvoicedPaymentMutation{ +// newChargeCreditPurchaseExternalPaymentMutation creates new mutation for the ChargeCreditPurchaseExternalPayment entity. +func newChargeCreditPurchaseExternalPaymentMutation(c config, op Op, opts ...chargecreditpurchaseexternalpaymentOption) *ChargeCreditPurchaseExternalPaymentMutation { + m := &ChargeCreditPurchaseExternalPaymentMutation{ config: c, op: op, - typ: TypeChargeCreditPurchaseInvoicedPayment, + typ: TypeChargeCreditPurchaseExternalPayment, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -44340,20 +44460,20 @@ func newChargeCreditPurchaseInvoicedPaymentMutation(c config, op Op, opts ...cha return m } -// withChargeCreditPurchaseInvoicedPaymentID sets the ID field of the mutation. -func withChargeCreditPurchaseInvoicedPaymentID(id string) chargecreditpurchaseinvoicedpaymentOption { - return func(m *ChargeCreditPurchaseInvoicedPaymentMutation) { +// withChargeCreditPurchaseExternalPaymentID sets the ID field of the mutation. +func withChargeCreditPurchaseExternalPaymentID(id string) chargecreditpurchaseexternalpaymentOption { + return func(m *ChargeCreditPurchaseExternalPaymentMutation) { var ( err error once sync.Once - value *ChargeCreditPurchaseInvoicedPayment + value *ChargeCreditPurchaseExternalPayment ) - m.oldValue = func(ctx context.Context) (*ChargeCreditPurchaseInvoicedPayment, error) { + m.oldValue = func(ctx context.Context) (*ChargeCreditPurchaseExternalPayment, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { - value, err = m.Client().ChargeCreditPurchaseInvoicedPayment.Get(ctx, id) + value, err = m.Client().ChargeCreditPurchaseExternalPayment.Get(ctx, id) } }) return value, err @@ -44362,10 +44482,10 @@ func withChargeCreditPurchaseInvoicedPaymentID(id string) chargecreditpurchasein } } -// withChargeCreditPurchaseInvoicedPayment sets the old ChargeCreditPurchaseInvoicedPayment of the mutation. -func withChargeCreditPurchaseInvoicedPayment(node *ChargeCreditPurchaseInvoicedPayment) chargecreditpurchaseinvoicedpaymentOption { - return func(m *ChargeCreditPurchaseInvoicedPaymentMutation) { - m.oldValue = func(context.Context) (*ChargeCreditPurchaseInvoicedPayment, error) { +// withChargeCreditPurchaseExternalPayment sets the old ChargeCreditPurchaseExternalPayment of the mutation. +func withChargeCreditPurchaseExternalPayment(node *ChargeCreditPurchaseExternalPayment) chargecreditpurchaseexternalpaymentOption { + return func(m *ChargeCreditPurchaseExternalPaymentMutation) { + m.oldValue = func(context.Context) (*ChargeCreditPurchaseExternalPayment, error) { return node, nil } m.id = &node.ID @@ -44374,7 +44494,7 @@ func withChargeCreditPurchaseInvoicedPayment(node *ChargeCreditPurchaseInvoicedP // 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 ChargeCreditPurchaseInvoicedPaymentMutation) Client() *Client { +func (m ChargeCreditPurchaseExternalPaymentMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -44382,7 +44502,7 @@ func (m ChargeCreditPurchaseInvoicedPaymentMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m ChargeCreditPurchaseInvoicedPaymentMutation) Tx() (*Tx, error) { +func (m ChargeCreditPurchaseExternalPaymentMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("db: mutation is not running in a transaction") } @@ -44392,14 +44512,14 @@ func (m ChargeCreditPurchaseInvoicedPaymentMutation) Tx() (*Tx, error) { } // SetID sets the value of the id field. Note that this -// operation is only accepted on creation of ChargeCreditPurchaseInvoicedPayment entities. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetID(id string) { +// operation is only accepted on creation of ChargeCreditPurchaseExternalPayment entities. +func (m *ChargeCreditPurchaseExternalPaymentMutation) 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 *ChargeCreditPurchaseInvoicedPaymentMutation) ID() (id string, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ID() (id string, exists bool) { if m.id == nil { return } @@ -44410,7 +44530,7 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ID() (id string, exists bo // 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 *ChargeCreditPurchaseInvoicedPaymentMutation) IDs(ctx context.Context) ([]string, error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() @@ -44419,91 +44539,19 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) IDs(ctx context.Context) ( } fallthrough case m.op.Is(OpUpdate | OpDelete): - return m.Client().ChargeCreditPurchaseInvoicedPayment.Query().Where(m.predicates...).IDs(ctx) + return m.Client().ChargeCreditPurchaseExternalPayment.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } -// SetLineID sets the "line_id" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetLineID(s string) { - m.billing_invoice_line = &s -} - -// LineID returns the value of the "line_id" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) LineID() (r string, exists bool) { - v := m.billing_invoice_line - if v == nil { - return - } - return *v, true -} - -// OldLineID returns the old "line_id" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldLineID(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldLineID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldLineID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldLineID: %w", err) - } - return oldValue.LineID, nil -} - -// ResetLineID resets all changes to the "line_id" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetLineID() { - m.billing_invoice_line = nil -} - -// SetInvoiceID sets the "invoice_id" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetInvoiceID(s string) { - m.invoice_id = &s -} - -// InvoiceID returns the value of the "invoice_id" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) InvoiceID() (r string, exists bool) { - v := m.invoice_id - if v == nil { - return - } - return *v, true -} - -// OldInvoiceID returns the old "invoice_id" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) 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 *ChargeCreditPurchaseInvoicedPaymentMutation) ResetInvoiceID() { - m.invoice_id = nil -} - // SetServicePeriodFrom sets the "service_period_from" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetServicePeriodFrom(t time.Time) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetServicePeriodFrom(t time.Time) { m.service_period_from = &t } // ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ServicePeriodFrom() (r time.Time, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ServicePeriodFrom() (r time.Time, exists bool) { v := m.service_period_from if v == nil { return @@ -44511,10 +44559,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ServicePeriodFrom() (r tim return *v, true } -// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") } @@ -44529,17 +44577,17 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldServicePeriodFrom(ctx c } // ResetServicePeriodFrom resets all changes to the "service_period_from" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetServicePeriodFrom() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetServicePeriodFrom() { m.service_period_from = nil } // SetServicePeriodTo sets the "service_period_to" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetServicePeriodTo(t time.Time) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetServicePeriodTo(t time.Time) { m.service_period_to = &t } // ServicePeriodTo returns the value of the "service_period_to" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ServicePeriodTo() (r time.Time, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ServicePeriodTo() (r time.Time, exists bool) { v := m.service_period_to if v == nil { return @@ -44547,10 +44595,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ServicePeriodTo() (r time. return *v, true } -// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") } @@ -44565,17 +44613,17 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldServicePeriodTo(ctx con } // ResetServicePeriodTo resets all changes to the "service_period_to" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetServicePeriodTo() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetServicePeriodTo() { m.service_period_to = nil } // SetStatus sets the "status" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetStatus(pa payment.Status) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetStatus(pa payment.Status) { m.status = &pa } // Status returns the value of the "status" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Status() (r payment.Status, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) Status() (r payment.Status, exists bool) { v := m.status if v == nil { return @@ -44583,10 +44631,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Status() (r payment.Status return *v, true } -// OldStatus returns the old "status" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldStatus returns the old "status" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldStatus(ctx context.Context) (v payment.Status, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) OldStatus(ctx context.Context) (v payment.Status, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldStatus is only allowed on UpdateOne operations") } @@ -44601,17 +44649,17 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldStatus(ctx context.Cont } // ResetStatus resets all changes to the "status" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetStatus() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetStatus() { m.status = nil } // SetAmount sets the "amount" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetAmount(a alpacadecimal.Decimal) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetAmount(a alpacadecimal.Decimal) { m.amount = &a } // Amount returns the value of the "amount" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Amount() (r alpacadecimal.Decimal, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) Amount() (r alpacadecimal.Decimal, exists bool) { v := m.amount if v == nil { return @@ -44619,10 +44667,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Amount() (r alpacadecimal. return *v, true } -// OldAmount returns the old "amount" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldAmount returns the old "amount" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAmount is only allowed on UpdateOne operations") } @@ -44637,17 +44685,17 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldAmount(ctx context.Cont } // ResetAmount resets all changes to the "amount" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetAmount() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetAmount() { m.amount = nil } // SetAuthorizedTransactionGroupID sets the "authorized_transaction_group_id" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetAuthorizedTransactionGroupID(s string) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetAuthorizedTransactionGroupID(s string) { m.authorized_transaction_group_id = &s } // AuthorizedTransactionGroupID returns the value of the "authorized_transaction_group_id" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AuthorizedTransactionGroupID() (r string, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) AuthorizedTransactionGroupID() (r string, exists bool) { v := m.authorized_transaction_group_id if v == nil { return @@ -44655,10 +44703,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AuthorizedTransactionGroup return *v, true } -// OldAuthorizedTransactionGroupID returns the old "authorized_transaction_group_id" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldAuthorizedTransactionGroupID returns the old "authorized_transaction_group_id" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldAuthorizedTransactionGroupID(ctx context.Context) (v *string, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) OldAuthorizedTransactionGroupID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAuthorizedTransactionGroupID is only allowed on UpdateOne operations") } @@ -44673,30 +44721,30 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldAuthorizedTransactionGr } // ClearAuthorizedTransactionGroupID clears the value of the "authorized_transaction_group_id" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearAuthorizedTransactionGroupID() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearAuthorizedTransactionGroupID() { m.authorized_transaction_group_id = nil - m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID] = struct{}{} + m.clearedFields[chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID] = struct{}{} } // AuthorizedTransactionGroupIDCleared returns if the "authorized_transaction_group_id" field was cleared in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AuthorizedTransactionGroupIDCleared() bool { - _, ok := m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID] +func (m *ChargeCreditPurchaseExternalPaymentMutation) AuthorizedTransactionGroupIDCleared() bool { + _, ok := m.clearedFields[chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID] return ok } // ResetAuthorizedTransactionGroupID resets all changes to the "authorized_transaction_group_id" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetAuthorizedTransactionGroupID() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetAuthorizedTransactionGroupID() { m.authorized_transaction_group_id = nil - delete(m.clearedFields, chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID) + delete(m.clearedFields, chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID) } // SetAuthorizedAt sets the "authorized_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetAuthorizedAt(t time.Time) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetAuthorizedAt(t time.Time) { m.authorized_at = &t } // AuthorizedAt returns the value of the "authorized_at" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AuthorizedAt() (r time.Time, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) AuthorizedAt() (r time.Time, exists bool) { v := m.authorized_at if v == nil { return @@ -44704,10 +44752,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AuthorizedAt() (r time.Tim return *v, true } -// OldAuthorizedAt returns the old "authorized_at" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldAuthorizedAt returns the old "authorized_at" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldAuthorizedAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) OldAuthorizedAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAuthorizedAt is only allowed on UpdateOne operations") } @@ -44722,30 +44770,30 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldAuthorizedAt(ctx contex } // ClearAuthorizedAt clears the value of the "authorized_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearAuthorizedAt() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearAuthorizedAt() { m.authorized_at = nil - m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt] = struct{}{} + m.clearedFields[chargecreditpurchaseexternalpayment.FieldAuthorizedAt] = struct{}{} } // AuthorizedAtCleared returns if the "authorized_at" field was cleared in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AuthorizedAtCleared() bool { - _, ok := m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt] +func (m *ChargeCreditPurchaseExternalPaymentMutation) AuthorizedAtCleared() bool { + _, ok := m.clearedFields[chargecreditpurchaseexternalpayment.FieldAuthorizedAt] return ok } // ResetAuthorizedAt resets all changes to the "authorized_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetAuthorizedAt() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetAuthorizedAt() { m.authorized_at = nil - delete(m.clearedFields, chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt) + delete(m.clearedFields, chargecreditpurchaseexternalpayment.FieldAuthorizedAt) } // SetSettledTransactionGroupID sets the "settled_transaction_group_id" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetSettledTransactionGroupID(s string) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetSettledTransactionGroupID(s string) { m.settled_transaction_group_id = &s } // SettledTransactionGroupID returns the value of the "settled_transaction_group_id" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SettledTransactionGroupID() (r string, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SettledTransactionGroupID() (r string, exists bool) { v := m.settled_transaction_group_id if v == nil { return @@ -44753,10 +44801,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SettledTransactionGroupID( return *v, true } -// OldSettledTransactionGroupID returns the old "settled_transaction_group_id" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldSettledTransactionGroupID returns the old "settled_transaction_group_id" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldSettledTransactionGroupID(ctx context.Context) (v *string, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) OldSettledTransactionGroupID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSettledTransactionGroupID is only allowed on UpdateOne operations") } @@ -44771,30 +44819,30 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldSettledTransactionGroup } // ClearSettledTransactionGroupID clears the value of the "settled_transaction_group_id" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearSettledTransactionGroupID() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearSettledTransactionGroupID() { m.settled_transaction_group_id = nil - m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID] = struct{}{} + m.clearedFields[chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID] = struct{}{} } // SettledTransactionGroupIDCleared returns if the "settled_transaction_group_id" field was cleared in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SettledTransactionGroupIDCleared() bool { - _, ok := m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID] +func (m *ChargeCreditPurchaseExternalPaymentMutation) SettledTransactionGroupIDCleared() bool { + _, ok := m.clearedFields[chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID] return ok } // ResetSettledTransactionGroupID resets all changes to the "settled_transaction_group_id" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetSettledTransactionGroupID() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetSettledTransactionGroupID() { m.settled_transaction_group_id = nil - delete(m.clearedFields, chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID) + delete(m.clearedFields, chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID) } // SetSettledAt sets the "settled_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetSettledAt(t time.Time) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetSettledAt(t time.Time) { m.settled_at = &t } // SettledAt returns the value of the "settled_at" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SettledAt() (r time.Time, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SettledAt() (r time.Time, exists bool) { v := m.settled_at if v == nil { return @@ -44802,10 +44850,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SettledAt() (r time.Time, return *v, true } -// OldSettledAt returns the old "settled_at" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldSettledAt returns the old "settled_at" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldSettledAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) OldSettledAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSettledAt is only allowed on UpdateOne operations") } @@ -44820,30 +44868,30 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldSettledAt(ctx context.C } // ClearSettledAt clears the value of the "settled_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearSettledAt() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearSettledAt() { m.settled_at = nil - m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldSettledAt] = struct{}{} + m.clearedFields[chargecreditpurchaseexternalpayment.FieldSettledAt] = struct{}{} } // SettledAtCleared returns if the "settled_at" field was cleared in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SettledAtCleared() bool { - _, ok := m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldSettledAt] +func (m *ChargeCreditPurchaseExternalPaymentMutation) SettledAtCleared() bool { + _, ok := m.clearedFields[chargecreditpurchaseexternalpayment.FieldSettledAt] return ok } // ResetSettledAt resets all changes to the "settled_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetSettledAt() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetSettledAt() { m.settled_at = nil - delete(m.clearedFields, chargecreditpurchaseinvoicedpayment.FieldSettledAt) + delete(m.clearedFields, chargecreditpurchaseexternalpayment.FieldSettledAt) } // SetNamespace sets the "namespace" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetNamespace(s string) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetNamespace(s string) { m.namespace = &s } // Namespace returns the value of the "namespace" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Namespace() (r string, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) Namespace() (r string, exists bool) { v := m.namespace if v == nil { return @@ -44851,10 +44899,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Namespace() (r string, exi return *v, true } -// OldNamespace returns the old "namespace" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldNamespace returns the old "namespace" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldNamespace(ctx context.Context) (v string, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) OldNamespace(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldNamespace is only allowed on UpdateOne operations") } @@ -44869,17 +44917,17 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldNamespace(ctx context.C } // ResetNamespace resets all changes to the "namespace" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetNamespace() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetNamespace() { m.namespace = nil } // SetCreatedAt sets the "created_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetCreatedAt(t time.Time) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) CreatedAt() (r time.Time, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return @@ -44887,10 +44935,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) CreatedAt() (r time.Time, return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) 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") } @@ -44905,17 +44953,17 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldCreatedAt(ctx context.C } // ResetCreatedAt resets all changes to the "created_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetCreatedAt() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetUpdatedAt(t time.Time) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) UpdatedAt() (r time.Time, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return @@ -44923,10 +44971,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) UpdatedAt() (r time.Time, return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) 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") } @@ -44941,17 +44989,17 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldUpdatedAt(ctx context.C } // ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetUpdatedAt() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetUpdatedAt() { m.updated_at = nil } // SetDeletedAt sets the "deleted_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetDeletedAt(t time.Time) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetDeletedAt(t time.Time) { m.deleted_at = &t } // DeletedAt returns the value of the "deleted_at" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) DeletedAt() (r time.Time, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) DeletedAt() (r time.Time, exists bool) { v := m.deleted_at if v == nil { return @@ -44959,10 +45007,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) DeletedAt() (r time.Time, return *v, true } -// OldDeletedAt returns the old "deleted_at" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldDeletedAt returns the old "deleted_at" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) 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") } @@ -44977,30 +45025,30 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldDeletedAt(ctx context.C } // ClearDeletedAt clears the value of the "deleted_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearDeletedAt() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearDeletedAt() { m.deleted_at = nil - m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldDeletedAt] = struct{}{} + m.clearedFields[chargecreditpurchaseexternalpayment.FieldDeletedAt] = struct{}{} } // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) DeletedAtCleared() bool { - _, ok := m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldDeletedAt] +func (m *ChargeCreditPurchaseExternalPaymentMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargecreditpurchaseexternalpayment.FieldDeletedAt] return ok } // ResetDeletedAt resets all changes to the "deleted_at" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetDeletedAt() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetDeletedAt() { m.deleted_at = nil - delete(m.clearedFields, chargecreditpurchaseinvoicedpayment.FieldDeletedAt) + delete(m.clearedFields, chargecreditpurchaseexternalpayment.FieldDeletedAt) } // SetAnnotations sets the "annotations" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetAnnotations(value models.Annotations) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetAnnotations(value models.Annotations) { m.annotations = &value } // Annotations returns the value of the "annotations" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Annotations() (r models.Annotations, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) Annotations() (r models.Annotations, exists bool) { v := m.annotations if v == nil { return @@ -45008,10 +45056,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Annotations() (r models.An return *v, true } -// OldAnnotations returns the old "annotations" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldAnnotations returns the old "annotations" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldAnnotations(ctx context.Context) (v models.Annotations, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) 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") } @@ -45026,30 +45074,30 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldAnnotations(ctx context } // ClearAnnotations clears the value of the "annotations" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearAnnotations() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearAnnotations() { m.annotations = nil - m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldAnnotations] = struct{}{} + m.clearedFields[chargecreditpurchaseexternalpayment.FieldAnnotations] = struct{}{} } // AnnotationsCleared returns if the "annotations" field was cleared in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AnnotationsCleared() bool { - _, ok := m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldAnnotations] +func (m *ChargeCreditPurchaseExternalPaymentMutation) AnnotationsCleared() bool { + _, ok := m.clearedFields[chargecreditpurchaseexternalpayment.FieldAnnotations] return ok } // ResetAnnotations resets all changes to the "annotations" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetAnnotations() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetAnnotations() { m.annotations = nil - delete(m.clearedFields, chargecreditpurchaseinvoicedpayment.FieldAnnotations) + delete(m.clearedFields, chargecreditpurchaseexternalpayment.FieldAnnotations) } // SetChargeID sets the "charge_id" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetChargeID(s string) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetChargeID(s string) { m.credit_purchase = &s } // ChargeID returns the value of the "charge_id" field in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ChargeID() (r string, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ChargeID() (r string, exists bool) { v := m.credit_purchase if v == nil { return @@ -45057,10 +45105,10 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ChargeID() (r string, exis return *v, true } -// OldChargeID returns the old "charge_id" field's value of the ChargeCreditPurchaseInvoicedPayment entity. -// If the ChargeCreditPurchaseInvoicedPayment object wasn't provided to the builder, the object is fetched from the database. +// OldChargeID returns the old "charge_id" field's value of the ChargeCreditPurchaseExternalPayment entity. +// If the ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldChargeID(ctx context.Context) (v string, err error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) OldChargeID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldChargeID is only allowed on UpdateOne operations") } @@ -45075,68 +45123,28 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldChargeID(ctx context.Co } // ResetChargeID resets all changes to the "charge_id" field. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetChargeID() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetChargeID() { m.credit_purchase = nil } -// SetBillingInvoiceLineID sets the "billing_invoice_line" edge to the BillingInvoiceLine entity by id. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetBillingInvoiceLineID(id string) { - m.billing_invoice_line = &id -} - -// ClearBillingInvoiceLine clears the "billing_invoice_line" edge to the BillingInvoiceLine entity. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearBillingInvoiceLine() { - m.clearedbilling_invoice_line = true - m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldLineID] = struct{}{} -} - -// BillingInvoiceLineCleared reports if the "billing_invoice_line" edge to the BillingInvoiceLine entity was cleared. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) BillingInvoiceLineCleared() bool { - return m.clearedbilling_invoice_line -} - -// BillingInvoiceLineID returns the "billing_invoice_line" edge ID in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) BillingInvoiceLineID() (id string, exists bool) { - if m.billing_invoice_line != nil { - return *m.billing_invoice_line, true - } - return -} - -// BillingInvoiceLineIDs returns the "billing_invoice_line" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// BillingInvoiceLineID instead. It exists only for internal usage by the builders. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) BillingInvoiceLineIDs() (ids []string) { - if id := m.billing_invoice_line; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetBillingInvoiceLine resets all changes to the "billing_invoice_line" edge. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetBillingInvoiceLine() { - m.billing_invoice_line = nil - m.clearedbilling_invoice_line = false -} - // SetCreditPurchaseID sets the "credit_purchase" edge to the ChargeCreditPurchase entity by id. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetCreditPurchaseID(id string) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetCreditPurchaseID(id string) { m.credit_purchase = &id } // ClearCreditPurchase clears the "credit_purchase" edge to the ChargeCreditPurchase entity. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearCreditPurchase() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearCreditPurchase() { m.clearedcredit_purchase = true - m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldChargeID] = struct{}{} + m.clearedFields[chargecreditpurchaseexternalpayment.FieldChargeID] = struct{}{} } // CreditPurchaseCleared reports if the "credit_purchase" edge to the ChargeCreditPurchase entity was cleared. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) CreditPurchaseCleared() bool { +func (m *ChargeCreditPurchaseExternalPaymentMutation) CreditPurchaseCleared() bool { return m.clearedcredit_purchase } // CreditPurchaseID returns the "credit_purchase" edge ID in the mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) CreditPurchaseID() (id string, exists bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) CreditPurchaseID() (id string, exists bool) { if m.credit_purchase != nil { return *m.credit_purchase, true } @@ -45146,7 +45154,7 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) CreditPurchaseID() (id str // CreditPurchaseIDs returns the "credit_purchase" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // CreditPurchaseID instead. It exists only for internal usage by the builders. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) CreditPurchaseIDs() (ids []string) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) CreditPurchaseIDs() (ids []string) { if id := m.credit_purchase; id != nil { ids = append(ids, *id) } @@ -45154,20 +45162,20 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) CreditPurchaseIDs() (ids [ } // ResetCreditPurchase resets all changes to the "credit_purchase" edge. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetCreditPurchase() { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetCreditPurchase() { m.credit_purchase = nil m.clearedcredit_purchase = false } -// Where appends a list predicates to the ChargeCreditPurchaseInvoicedPaymentMutation builder. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Where(ps ...predicate.ChargeCreditPurchaseInvoicedPayment) { +// Where appends a list predicates to the ChargeCreditPurchaseExternalPaymentMutation builder. +func (m *ChargeCreditPurchaseExternalPaymentMutation) Where(ps ...predicate.ChargeCreditPurchaseExternalPayment) { m.predicates = append(m.predicates, ps...) } -// WhereP appends storage-level predicates to the ChargeCreditPurchaseInvoicedPaymentMutation builder. Using this method, +// WhereP appends storage-level predicates to the ChargeCreditPurchaseExternalPaymentMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.ChargeCreditPurchaseInvoicedPayment, len(ps)) +func (m *ChargeCreditPurchaseExternalPaymentMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeCreditPurchaseExternalPayment, len(ps)) for i := range ps { p[i] = ps[i] } @@ -45175,72 +45183,66 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) WhereP(ps ...func(*sql.Sel } // Op returns the operation name. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Op() Op { +func (m *ChargeCreditPurchaseExternalPaymentMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetOp(op Op) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetOp(op Op) { m.op = op } -// Type returns the node type of this mutation (ChargeCreditPurchaseInvoicedPayment). -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Type() string { +// Type returns the node type of this mutation (ChargeCreditPurchaseExternalPayment). +func (m *ChargeCreditPurchaseExternalPaymentMutation) 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 *ChargeCreditPurchaseInvoicedPaymentMutation) Fields() []string { - fields := make([]string, 0, 16) - if m.billing_invoice_line != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldLineID) - } - if m.invoice_id != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldInvoiceID) - } +func (m *ChargeCreditPurchaseExternalPaymentMutation) Fields() []string { + fields := make([]string, 0, 14) if m.service_period_from != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldServicePeriodFrom) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldServicePeriodFrom) } if m.service_period_to != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldServicePeriodTo) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldServicePeriodTo) } if m.status != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldStatus) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldStatus) } if m.amount != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAmount) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldAmount) } if m.authorized_transaction_group_id != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID) } if m.authorized_at != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldAuthorizedAt) } if m.settled_transaction_group_id != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID) } if m.settled_at != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldSettledAt) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldSettledAt) } if m.namespace != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldNamespace) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldNamespace) } if m.created_at != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldCreatedAt) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldCreatedAt) } if m.updated_at != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldUpdatedAt) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldUpdatedAt) } if m.deleted_at != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldDeletedAt) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldDeletedAt) } if m.annotations != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAnnotations) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldAnnotations) } if m.credit_purchase != nil { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldChargeID) + fields = append(fields, chargecreditpurchaseexternalpayment.FieldChargeID) } return fields } @@ -45248,39 +45250,35 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Fields() []string { // 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 *ChargeCreditPurchaseInvoicedPaymentMutation) Field(name string) (ent.Value, bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) Field(name string) (ent.Value, bool) { switch name { - case chargecreditpurchaseinvoicedpayment.FieldLineID: - return m.LineID() - case chargecreditpurchaseinvoicedpayment.FieldInvoiceID: - return m.InvoiceID() - case chargecreditpurchaseinvoicedpayment.FieldServicePeriodFrom: + case chargecreditpurchaseexternalpayment.FieldServicePeriodFrom: return m.ServicePeriodFrom() - case chargecreditpurchaseinvoicedpayment.FieldServicePeriodTo: + case chargecreditpurchaseexternalpayment.FieldServicePeriodTo: return m.ServicePeriodTo() - case chargecreditpurchaseinvoicedpayment.FieldStatus: + case chargecreditpurchaseexternalpayment.FieldStatus: return m.Status() - case chargecreditpurchaseinvoicedpayment.FieldAmount: + case chargecreditpurchaseexternalpayment.FieldAmount: return m.Amount() - case chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID: + case chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID: return m.AuthorizedTransactionGroupID() - case chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt: + case chargecreditpurchaseexternalpayment.FieldAuthorizedAt: return m.AuthorizedAt() - case chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID: + case chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID: return m.SettledTransactionGroupID() - case chargecreditpurchaseinvoicedpayment.FieldSettledAt: + case chargecreditpurchaseexternalpayment.FieldSettledAt: return m.SettledAt() - case chargecreditpurchaseinvoicedpayment.FieldNamespace: + case chargecreditpurchaseexternalpayment.FieldNamespace: return m.Namespace() - case chargecreditpurchaseinvoicedpayment.FieldCreatedAt: + case chargecreditpurchaseexternalpayment.FieldCreatedAt: return m.CreatedAt() - case chargecreditpurchaseinvoicedpayment.FieldUpdatedAt: + case chargecreditpurchaseexternalpayment.FieldUpdatedAt: return m.UpdatedAt() - case chargecreditpurchaseinvoicedpayment.FieldDeletedAt: + case chargecreditpurchaseexternalpayment.FieldDeletedAt: return m.DeletedAt() - case chargecreditpurchaseinvoicedpayment.FieldAnnotations: + case chargecreditpurchaseexternalpayment.FieldAnnotations: return m.Annotations() - case chargecreditpurchaseinvoicedpayment.FieldChargeID: + case chargecreditpurchaseexternalpayment.FieldChargeID: return m.ChargeID() } return nil, false @@ -45289,155 +45287,137 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Field(name string) (ent.Va // 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case chargecreditpurchaseinvoicedpayment.FieldLineID: - return m.OldLineID(ctx) - case chargecreditpurchaseinvoicedpayment.FieldInvoiceID: - return m.OldInvoiceID(ctx) - case chargecreditpurchaseinvoicedpayment.FieldServicePeriodFrom: + case chargecreditpurchaseexternalpayment.FieldServicePeriodFrom: return m.OldServicePeriodFrom(ctx) - case chargecreditpurchaseinvoicedpayment.FieldServicePeriodTo: + case chargecreditpurchaseexternalpayment.FieldServicePeriodTo: return m.OldServicePeriodTo(ctx) - case chargecreditpurchaseinvoicedpayment.FieldStatus: + case chargecreditpurchaseexternalpayment.FieldStatus: return m.OldStatus(ctx) - case chargecreditpurchaseinvoicedpayment.FieldAmount: + case chargecreditpurchaseexternalpayment.FieldAmount: return m.OldAmount(ctx) - case chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID: + case chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID: return m.OldAuthorizedTransactionGroupID(ctx) - case chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt: + case chargecreditpurchaseexternalpayment.FieldAuthorizedAt: return m.OldAuthorizedAt(ctx) - case chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID: + case chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID: return m.OldSettledTransactionGroupID(ctx) - case chargecreditpurchaseinvoicedpayment.FieldSettledAt: + case chargecreditpurchaseexternalpayment.FieldSettledAt: return m.OldSettledAt(ctx) - case chargecreditpurchaseinvoicedpayment.FieldNamespace: + case chargecreditpurchaseexternalpayment.FieldNamespace: return m.OldNamespace(ctx) - case chargecreditpurchaseinvoicedpayment.FieldCreatedAt: + case chargecreditpurchaseexternalpayment.FieldCreatedAt: return m.OldCreatedAt(ctx) - case chargecreditpurchaseinvoicedpayment.FieldUpdatedAt: + case chargecreditpurchaseexternalpayment.FieldUpdatedAt: return m.OldUpdatedAt(ctx) - case chargecreditpurchaseinvoicedpayment.FieldDeletedAt: + case chargecreditpurchaseexternalpayment.FieldDeletedAt: return m.OldDeletedAt(ctx) - case chargecreditpurchaseinvoicedpayment.FieldAnnotations: + case chargecreditpurchaseexternalpayment.FieldAnnotations: return m.OldAnnotations(ctx) - case chargecreditpurchaseinvoicedpayment.FieldChargeID: + case chargecreditpurchaseexternalpayment.FieldChargeID: return m.OldChargeID(ctx) } - return nil, fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment field %s", name) + return nil, fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) SetField(name string, value ent.Value) error { +func (m *ChargeCreditPurchaseExternalPaymentMutation) SetField(name string, value ent.Value) error { switch name { - case chargecreditpurchaseinvoicedpayment.FieldLineID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetLineID(v) - return nil - case chargecreditpurchaseinvoicedpayment.FieldInvoiceID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetInvoiceID(v) - return nil - case chargecreditpurchaseinvoicedpayment.FieldServicePeriodFrom: + case chargecreditpurchaseexternalpayment.FieldServicePeriodFrom: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetServicePeriodFrom(v) return nil - case chargecreditpurchaseinvoicedpayment.FieldServicePeriodTo: + case chargecreditpurchaseexternalpayment.FieldServicePeriodTo: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetServicePeriodTo(v) return nil - case chargecreditpurchaseinvoicedpayment.FieldStatus: + case chargecreditpurchaseexternalpayment.FieldStatus: v, ok := value.(payment.Status) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetStatus(v) return nil - case chargecreditpurchaseinvoicedpayment.FieldAmount: + case chargecreditpurchaseexternalpayment.FieldAmount: v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAmount(v) return nil - case chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID: + case chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAuthorizedTransactionGroupID(v) return nil - case chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt: + case chargecreditpurchaseexternalpayment.FieldAuthorizedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAuthorizedAt(v) return nil - case chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID: + case chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSettledTransactionGroupID(v) return nil - case chargecreditpurchaseinvoicedpayment.FieldSettledAt: + case chargecreditpurchaseexternalpayment.FieldSettledAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSettledAt(v) return nil - case chargecreditpurchaseinvoicedpayment.FieldNamespace: + case chargecreditpurchaseexternalpayment.FieldNamespace: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetNamespace(v) return nil - case chargecreditpurchaseinvoicedpayment.FieldCreatedAt: + case chargecreditpurchaseexternalpayment.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 chargecreditpurchaseinvoicedpayment.FieldUpdatedAt: + case chargecreditpurchaseexternalpayment.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 chargecreditpurchaseinvoicedpayment.FieldDeletedAt: + case chargecreditpurchaseexternalpayment.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 chargecreditpurchaseinvoicedpayment.FieldAnnotations: + case chargecreditpurchaseexternalpayment.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 chargecreditpurchaseinvoicedpayment.FieldChargeID: + case chargecreditpurchaseexternalpayment.FieldChargeID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) @@ -45445,166 +45425,153 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetField(name string, valu m.SetChargeID(v) return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment field %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AddedFields() []string { +func (m *ChargeCreditPurchaseExternalPaymentMutation) 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 *ChargeCreditPurchaseInvoicedPaymentMutation) AddedField(name string) (ent.Value, bool) { +func (m *ChargeCreditPurchaseExternalPaymentMutation) 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 *ChargeCreditPurchaseInvoicedPaymentMutation) AddField(name string, value ent.Value) error { +func (m *ChargeCreditPurchaseExternalPaymentMutation) AddField(name string, value ent.Value) error { switch name { } - return fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment numeric field %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearedFields() []string { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID) { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID) + if m.FieldCleared(chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID) { + fields = append(fields, chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID) } - if m.FieldCleared(chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt) { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt) + if m.FieldCleared(chargecreditpurchaseexternalpayment.FieldAuthorizedAt) { + fields = append(fields, chargecreditpurchaseexternalpayment.FieldAuthorizedAt) } - if m.FieldCleared(chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID) { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID) + if m.FieldCleared(chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID) { + fields = append(fields, chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID) } - if m.FieldCleared(chargecreditpurchaseinvoicedpayment.FieldSettledAt) { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldSettledAt) + if m.FieldCleared(chargecreditpurchaseexternalpayment.FieldSettledAt) { + fields = append(fields, chargecreditpurchaseexternalpayment.FieldSettledAt) } - if m.FieldCleared(chargecreditpurchaseinvoicedpayment.FieldDeletedAt) { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldDeletedAt) + if m.FieldCleared(chargecreditpurchaseexternalpayment.FieldDeletedAt) { + fields = append(fields, chargecreditpurchaseexternalpayment.FieldDeletedAt) } - if m.FieldCleared(chargecreditpurchaseinvoicedpayment.FieldAnnotations) { - fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAnnotations) + if m.FieldCleared(chargecreditpurchaseexternalpayment.FieldAnnotations) { + fields = append(fields, chargecreditpurchaseexternalpayment.FieldAnnotations) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) FieldCleared(name string) bool { +func (m *ChargeCreditPurchaseExternalPaymentMutation) 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 *ChargeCreditPurchaseInvoicedPaymentMutation) ClearField(name string) error { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearField(name string) error { switch name { - case chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID: + case chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID: m.ClearAuthorizedTransactionGroupID() return nil - case chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt: + case chargecreditpurchaseexternalpayment.FieldAuthorizedAt: m.ClearAuthorizedAt() return nil - case chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID: + case chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID: m.ClearSettledTransactionGroupID() return nil - case chargecreditpurchaseinvoicedpayment.FieldSettledAt: + case chargecreditpurchaseexternalpayment.FieldSettledAt: m.ClearSettledAt() return nil - case chargecreditpurchaseinvoicedpayment.FieldDeletedAt: + case chargecreditpurchaseexternalpayment.FieldDeletedAt: m.ClearDeletedAt() return nil - case chargecreditpurchaseinvoicedpayment.FieldAnnotations: + case chargecreditpurchaseexternalpayment.FieldAnnotations: m.ClearAnnotations() return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment nullable field %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) ResetField(name string) error { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetField(name string) error { switch name { - case chargecreditpurchaseinvoicedpayment.FieldLineID: - m.ResetLineID() - return nil - case chargecreditpurchaseinvoicedpayment.FieldInvoiceID: - m.ResetInvoiceID() - return nil - case chargecreditpurchaseinvoicedpayment.FieldServicePeriodFrom: + case chargecreditpurchaseexternalpayment.FieldServicePeriodFrom: m.ResetServicePeriodFrom() return nil - case chargecreditpurchaseinvoicedpayment.FieldServicePeriodTo: + case chargecreditpurchaseexternalpayment.FieldServicePeriodTo: m.ResetServicePeriodTo() return nil - case chargecreditpurchaseinvoicedpayment.FieldStatus: + case chargecreditpurchaseexternalpayment.FieldStatus: m.ResetStatus() return nil - case chargecreditpurchaseinvoicedpayment.FieldAmount: + case chargecreditpurchaseexternalpayment.FieldAmount: m.ResetAmount() return nil - case chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID: + case chargecreditpurchaseexternalpayment.FieldAuthorizedTransactionGroupID: m.ResetAuthorizedTransactionGroupID() return nil - case chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt: + case chargecreditpurchaseexternalpayment.FieldAuthorizedAt: m.ResetAuthorizedAt() return nil - case chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID: + case chargecreditpurchaseexternalpayment.FieldSettledTransactionGroupID: m.ResetSettledTransactionGroupID() return nil - case chargecreditpurchaseinvoicedpayment.FieldSettledAt: + case chargecreditpurchaseexternalpayment.FieldSettledAt: m.ResetSettledAt() return nil - case chargecreditpurchaseinvoicedpayment.FieldNamespace: + case chargecreditpurchaseexternalpayment.FieldNamespace: m.ResetNamespace() return nil - case chargecreditpurchaseinvoicedpayment.FieldCreatedAt: + case chargecreditpurchaseexternalpayment.FieldCreatedAt: m.ResetCreatedAt() return nil - case chargecreditpurchaseinvoicedpayment.FieldUpdatedAt: + case chargecreditpurchaseexternalpayment.FieldUpdatedAt: m.ResetUpdatedAt() return nil - case chargecreditpurchaseinvoicedpayment.FieldDeletedAt: + case chargecreditpurchaseexternalpayment.FieldDeletedAt: m.ResetDeletedAt() return nil - case chargecreditpurchaseinvoicedpayment.FieldAnnotations: + case chargecreditpurchaseexternalpayment.FieldAnnotations: m.ResetAnnotations() return nil - case chargecreditpurchaseinvoicedpayment.FieldChargeID: + case chargecreditpurchaseexternalpayment.FieldChargeID: m.ResetChargeID() return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment field %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AddedEdges() []string { - edges := make([]string, 0, 2) - if m.billing_invoice_line != nil { - edges = append(edges, chargecreditpurchaseinvoicedpayment.EdgeBillingInvoiceLine) - } +func (m *ChargeCreditPurchaseExternalPaymentMutation) AddedEdges() []string { + edges := make([]string, 0, 1) if m.credit_purchase != nil { - edges = append(edges, chargecreditpurchaseinvoicedpayment.EdgeCreditPurchase) + edges = append(edges, chargecreditpurchaseexternalpayment.EdgeCreditPurchase) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AddedIDs(name string) []ent.Value { +func (m *ChargeCreditPurchaseExternalPaymentMutation) AddedIDs(name string) []ent.Value { switch name { - case chargecreditpurchaseinvoicedpayment.EdgeBillingInvoiceLine: - if id := m.billing_invoice_line; id != nil { - return []ent.Value{*id} - } - case chargecreditpurchaseinvoicedpayment.EdgeCreditPurchase: + case chargecreditpurchaseexternalpayment.EdgeCreditPurchase: if id := m.credit_purchase; id != nil { return []ent.Value{*id} } @@ -45613,36 +45580,31 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AddedIDs(name string) []en } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) RemovedEdges() []string { - edges := make([]string, 0, 2) +func (m *ChargeCreditPurchaseExternalPaymentMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) RemovedIDs(name string) []ent.Value { +func (m *ChargeCreditPurchaseExternalPaymentMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearedEdges() []string { - edges := make([]string, 0, 2) - if m.clearedbilling_invoice_line { - edges = append(edges, chargecreditpurchaseinvoicedpayment.EdgeBillingInvoiceLine) - } +func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) if m.clearedcredit_purchase { - edges = append(edges, chargecreditpurchaseinvoicedpayment.EdgeCreditPurchase) + edges = append(edges, chargecreditpurchaseexternalpayment.EdgeCreditPurchase) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *ChargeCreditPurchaseInvoicedPaymentMutation) EdgeCleared(name string) bool { +func (m *ChargeCreditPurchaseExternalPaymentMutation) EdgeCleared(name string) bool { switch name { - case chargecreditpurchaseinvoicedpayment.EdgeBillingInvoiceLine: - return m.clearedbilling_invoice_line - case chargecreditpurchaseinvoicedpayment.EdgeCreditPurchase: + case chargecreditpurchaseexternalpayment.EdgeCreditPurchase: return m.clearedcredit_purchase } return false @@ -45650,108 +45612,67 @@ func (m *ChargeCreditPurchaseInvoicedPaymentMutation) EdgeCleared(name string) b // 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 *ChargeCreditPurchaseInvoicedPaymentMutation) ClearEdge(name string) error { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ClearEdge(name string) error { switch name { - case chargecreditpurchaseinvoicedpayment.EdgeBillingInvoiceLine: - m.ClearBillingInvoiceLine() - return nil - case chargecreditpurchaseinvoicedpayment.EdgeCreditPurchase: + case chargecreditpurchaseexternalpayment.EdgeCreditPurchase: m.ClearCreditPurchase() return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment unique edge %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) ResetEdge(name string) error { +func (m *ChargeCreditPurchaseExternalPaymentMutation) ResetEdge(name string) error { switch name { - case chargecreditpurchaseinvoicedpayment.EdgeBillingInvoiceLine: - m.ResetBillingInvoiceLine() - return nil - case chargecreditpurchaseinvoicedpayment.EdgeCreditPurchase: + case chargecreditpurchaseexternalpayment.EdgeCreditPurchase: m.ResetCreditPurchase() return nil } - return fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment edge %s", name) + return fmt.Errorf("unknown ChargeCreditPurchaseExternalPayment edge %s", name) } -// ChargeFlatFeeMutation represents an operation that mutates the ChargeFlatFee nodes in the graph. -type ChargeFlatFeeMutation struct { +// ChargeCreditPurchaseInvoicedPaymentMutation represents an operation that mutates the ChargeCreditPurchaseInvoicedPayment nodes in the graph. +type ChargeCreditPurchaseInvoicedPaymentMutation struct { config - op Op - typ string - id *string - service_period_from *time.Time - service_period_to *time.Time - billing_period_from *time.Time - billing_period_to *time.Time - full_service_period_from *time.Time - full_service_period_to *time.Time - status *meta.ChargeStatus - unique_reference_id *string - fiat_currency_code *currencyx.Code - managed_by *billing.InvoiceLineManagedBy - advance_after *time.Time - tax_behavior *productcatalog.TaxBehavior - 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 - payment_term *productcatalog.PaymentTermType - invoice_at *time.Time - settlement_mode *productcatalog.SettlementMode - intent_deleted_at *time.Time - discounts **billing.Discounts - pro_rating *flatfee.ProRatingModeAdapterEnum - feature_key *string - amount_before_proration *alpacadecimal.Decimal - amount_after_proration *alpacadecimal.Decimal - status_detailed *flatfee.Status - clearedFields map[string]struct{} - runs map[string]struct{} - removedruns map[string]struct{} - clearedruns bool - current_run *string - clearedcurrent_run bool - charge *string - clearedcharge bool - intent_override *string - clearedintent_override bool - subscription *string - clearedsubscription bool - subscription_phase *string - clearedsubscription_phase bool - subscription_item *string - clearedsubscription_item bool - customer *string - clearedcustomer bool - feature *string - clearedfeature bool - tax_code *string - clearedtax_code bool - custom_currency *string - clearedcustom_currency bool - done bool - oldValue func(context.Context) (*ChargeFlatFee, error) - predicates []predicate.ChargeFlatFee + op Op + typ string + id *string + invoice_id *string + service_period_from *time.Time + service_period_to *time.Time + status *payment.Status + amount *alpacadecimal.Decimal + authorized_transaction_group_id *string + authorized_at *time.Time + settled_transaction_group_id *string + settled_at *time.Time + namespace *string + created_at *time.Time + updated_at *time.Time + deleted_at *time.Time + annotations *models.Annotations + clearedFields map[string]struct{} + billing_invoice_line *string + clearedbilling_invoice_line bool + credit_purchase *string + clearedcredit_purchase bool + done bool + oldValue func(context.Context) (*ChargeCreditPurchaseInvoicedPayment, error) + predicates []predicate.ChargeCreditPurchaseInvoicedPayment } -var _ ent.Mutation = (*ChargeFlatFeeMutation)(nil) +var _ ent.Mutation = (*ChargeCreditPurchaseInvoicedPaymentMutation)(nil) -// chargeflatfeeOption allows management of the mutation configuration using functional options. -type chargeflatfeeOption func(*ChargeFlatFeeMutation) +// chargecreditpurchaseinvoicedpaymentOption allows management of the mutation configuration using functional options. +type chargecreditpurchaseinvoicedpaymentOption func(*ChargeCreditPurchaseInvoicedPaymentMutation) -// newChargeFlatFeeMutation creates new mutation for the ChargeFlatFee entity. -func newChargeFlatFeeMutation(c config, op Op, opts ...chargeflatfeeOption) *ChargeFlatFeeMutation { - m := &ChargeFlatFeeMutation{ +// newChargeCreditPurchaseInvoicedPaymentMutation creates new mutation for the ChargeCreditPurchaseInvoicedPayment entity. +func newChargeCreditPurchaseInvoicedPaymentMutation(c config, op Op, opts ...chargecreditpurchaseinvoicedpaymentOption) *ChargeCreditPurchaseInvoicedPaymentMutation { + m := &ChargeCreditPurchaseInvoicedPaymentMutation{ config: c, op: op, - typ: TypeChargeFlatFee, + typ: TypeChargeCreditPurchaseInvoicedPayment, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -45760,20 +45681,20 @@ func newChargeFlatFeeMutation(c config, op Op, opts ...chargeflatfeeOption) *Cha return m } -// withChargeFlatFeeID sets the ID field of the mutation. -func withChargeFlatFeeID(id string) chargeflatfeeOption { - return func(m *ChargeFlatFeeMutation) { +// withChargeCreditPurchaseInvoicedPaymentID sets the ID field of the mutation. +func withChargeCreditPurchaseInvoicedPaymentID(id string) chargecreditpurchaseinvoicedpaymentOption { + return func(m *ChargeCreditPurchaseInvoicedPaymentMutation) { var ( err error once sync.Once - value *ChargeFlatFee + value *ChargeCreditPurchaseInvoicedPayment ) - m.oldValue = func(ctx context.Context) (*ChargeFlatFee, error) { + m.oldValue = func(ctx context.Context) (*ChargeCreditPurchaseInvoicedPayment, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { - value, err = m.Client().ChargeFlatFee.Get(ctx, id) + value, err = m.Client().ChargeCreditPurchaseInvoicedPayment.Get(ctx, id) } }) return value, err @@ -45782,10 +45703,10 @@ func withChargeFlatFeeID(id string) chargeflatfeeOption { } } -// withChargeFlatFee sets the old ChargeFlatFee of the mutation. -func withChargeFlatFee(node *ChargeFlatFee) chargeflatfeeOption { - return func(m *ChargeFlatFeeMutation) { - m.oldValue = func(context.Context) (*ChargeFlatFee, error) { +// withChargeCreditPurchaseInvoicedPayment sets the old ChargeCreditPurchaseInvoicedPayment of the mutation. +func withChargeCreditPurchaseInvoicedPayment(node *ChargeCreditPurchaseInvoicedPayment) chargecreditpurchaseinvoicedpaymentOption { + return func(m *ChargeCreditPurchaseInvoicedPaymentMutation) { + m.oldValue = func(context.Context) (*ChargeCreditPurchaseInvoicedPayment, error) { return node, nil } m.id = &node.ID @@ -45794,7 +45715,7 @@ func withChargeFlatFee(node *ChargeFlatFee) chargeflatfeeOption { // 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 ChargeFlatFeeMutation) Client() *Client { +func (m ChargeCreditPurchaseInvoicedPaymentMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -45802,7 +45723,7 @@ func (m ChargeFlatFeeMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m ChargeFlatFeeMutation) Tx() (*Tx, error) { +func (m ChargeCreditPurchaseInvoicedPaymentMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("db: mutation is not running in a transaction") } @@ -45812,14 +45733,14 @@ func (m ChargeFlatFeeMutation) Tx() (*Tx, error) { } // SetID sets the value of the id field. Note that this -// operation is only accepted on creation of ChargeFlatFee entities. -func (m *ChargeFlatFeeMutation) SetID(id string) { +// operation is only accepted on creation of ChargeCreditPurchaseInvoicedPayment entities. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) 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 *ChargeFlatFeeMutation) ID() (id string, exists bool) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ID() (id string, exists bool) { if m.id == nil { return } @@ -45830,7 +45751,7 @@ func (m *ChargeFlatFeeMutation) ID() (id string, exists bool) { // 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 *ChargeFlatFeeMutation) IDs(ctx context.Context) ([]string, error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() @@ -45839,55 +45760,91 @@ func (m *ChargeFlatFeeMutation) IDs(ctx context.Context) ([]string, error) { } fallthrough case m.op.Is(OpUpdate | OpDelete): - return m.Client().ChargeFlatFee.Query().Where(m.predicates...).IDs(ctx) + return m.Client().ChargeCreditPurchaseInvoicedPayment.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } -// SetCustomerID sets the "customer_id" field. -func (m *ChargeFlatFeeMutation) SetCustomerID(s string) { - m.customer = &s +// SetLineID sets the "line_id" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetLineID(s string) { + m.billing_invoice_line = &s } -// CustomerID returns the value of the "customer_id" field in the mutation. -func (m *ChargeFlatFeeMutation) CustomerID() (r string, exists bool) { - v := m.customer +// LineID returns the value of the "line_id" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) LineID() (r string, exists bool) { + v := m.billing_invoice_line if v == nil { return } return *v, true } -// OldCustomerID returns the old "customer_id" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldLineID returns the old "line_id" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldCustomerID(ctx context.Context) (v string, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldLineID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCustomerID is only allowed on UpdateOne operations") + return v, errors.New("OldLineID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCustomerID requires an ID field in the mutation") + return v, errors.New("OldLineID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldCustomerID: %w", err) + return v, fmt.Errorf("querying old value for OldLineID: %w", err) } - return oldValue.CustomerID, nil + return oldValue.LineID, nil } -// ResetCustomerID resets all changes to the "customer_id" field. -func (m *ChargeFlatFeeMutation) ResetCustomerID() { - m.customer = nil +// ResetLineID resets all changes to the "line_id" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetLineID() { + m.billing_invoice_line = nil +} + +// SetInvoiceID sets the "invoice_id" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetInvoiceID(s string) { + m.invoice_id = &s +} + +// InvoiceID returns the value of the "invoice_id" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) InvoiceID() (r string, exists bool) { + v := m.invoice_id + if v == nil { + return + } + return *v, true +} + +// OldInvoiceID returns the old "invoice_id" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeCreditPurchaseInvoicedPaymentMutation) 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 *ChargeCreditPurchaseInvoicedPaymentMutation) ResetInvoiceID() { + m.invoice_id = nil } // SetServicePeriodFrom sets the "service_period_from" field. -func (m *ChargeFlatFeeMutation) SetServicePeriodFrom(t time.Time) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetServicePeriodFrom(t time.Time) { m.service_period_from = &t } // ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. -func (m *ChargeFlatFeeMutation) ServicePeriodFrom() (r time.Time, exists bool) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ServicePeriodFrom() (r time.Time, exists bool) { v := m.service_period_from if v == nil { return @@ -45895,10 +45852,10 @@ func (m *ChargeFlatFeeMutation) ServicePeriodFrom() (r time.Time, exists bool) { return *v, true } -// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") } @@ -45913,17 +45870,17 @@ func (m *ChargeFlatFeeMutation) OldServicePeriodFrom(ctx context.Context) (v tim } // ResetServicePeriodFrom resets all changes to the "service_period_from" field. -func (m *ChargeFlatFeeMutation) ResetServicePeriodFrom() { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetServicePeriodFrom() { m.service_period_from = nil } // SetServicePeriodTo sets the "service_period_to" field. -func (m *ChargeFlatFeeMutation) SetServicePeriodTo(t time.Time) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetServicePeriodTo(t time.Time) { m.service_period_to = &t } // ServicePeriodTo returns the value of the "service_period_to" field in the mutation. -func (m *ChargeFlatFeeMutation) ServicePeriodTo() (r time.Time, exists bool) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ServicePeriodTo() (r time.Time, exists bool) { v := m.service_period_to if v == nil { return @@ -45931,10 +45888,10 @@ func (m *ChargeFlatFeeMutation) ServicePeriodTo() (r time.Time, exists bool) { return *v, true } -// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") } @@ -45949,4144 +45906,3465 @@ func (m *ChargeFlatFeeMutation) OldServicePeriodTo(ctx context.Context) (v time. } // ResetServicePeriodTo resets all changes to the "service_period_to" field. -func (m *ChargeFlatFeeMutation) ResetServicePeriodTo() { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetServicePeriodTo() { m.service_period_to = nil } -// SetBillingPeriodFrom sets the "billing_period_from" field. -func (m *ChargeFlatFeeMutation) SetBillingPeriodFrom(t time.Time) { - m.billing_period_from = &t +// SetStatus sets the "status" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetStatus(pa payment.Status) { + m.status = &pa } -// BillingPeriodFrom returns the value of the "billing_period_from" field in the mutation. -func (m *ChargeFlatFeeMutation) BillingPeriodFrom() (r time.Time, exists bool) { - v := m.billing_period_from +// Status returns the value of the "status" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Status() (r payment.Status, exists bool) { + v := m.status if v == nil { return } return *v, true } -// OldBillingPeriodFrom returns the old "billing_period_from" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldStatus returns the old "status" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldBillingPeriodFrom(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldStatus(ctx context.Context) (v payment.Status, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldBillingPeriodFrom is only allowed on UpdateOne operations") + return v, errors.New("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldBillingPeriodFrom requires an ID field in the mutation") + return v, errors.New("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldBillingPeriodFrom: %w", err) + return v, fmt.Errorf("querying old value for OldStatus: %w", err) } - return oldValue.BillingPeriodFrom, nil + return oldValue.Status, nil } -// ResetBillingPeriodFrom resets all changes to the "billing_period_from" field. -func (m *ChargeFlatFeeMutation) ResetBillingPeriodFrom() { - m.billing_period_from = nil +// ResetStatus resets all changes to the "status" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetStatus() { + m.status = nil } -// SetBillingPeriodTo sets the "billing_period_to" field. -func (m *ChargeFlatFeeMutation) SetBillingPeriodTo(t time.Time) { - m.billing_period_to = &t +// SetAmount sets the "amount" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetAmount(a alpacadecimal.Decimal) { + m.amount = &a } -// BillingPeriodTo returns the value of the "billing_period_to" field in the mutation. -func (m *ChargeFlatFeeMutation) BillingPeriodTo() (r time.Time, exists bool) { - v := m.billing_period_to +// Amount returns the value of the "amount" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Amount() (r alpacadecimal.Decimal, exists bool) { + v := m.amount if v == nil { return } return *v, true } -// OldBillingPeriodTo returns the old "billing_period_to" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldAmount returns the old "amount" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldBillingPeriodTo(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldBillingPeriodTo is only allowed on UpdateOne operations") + return v, errors.New("OldAmount is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldBillingPeriodTo requires an ID field in the mutation") + return v, errors.New("OldAmount requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldBillingPeriodTo: %w", err) + return v, fmt.Errorf("querying old value for OldAmount: %w", err) } - return oldValue.BillingPeriodTo, nil + return oldValue.Amount, nil } -// ResetBillingPeriodTo resets all changes to the "billing_period_to" field. -func (m *ChargeFlatFeeMutation) ResetBillingPeriodTo() { - m.billing_period_to = nil +// ResetAmount resets all changes to the "amount" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetAmount() { + m.amount = nil } -// SetFullServicePeriodFrom sets the "full_service_period_from" field. -func (m *ChargeFlatFeeMutation) SetFullServicePeriodFrom(t time.Time) { - m.full_service_period_from = &t +// SetAuthorizedTransactionGroupID sets the "authorized_transaction_group_id" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetAuthorizedTransactionGroupID(s string) { + m.authorized_transaction_group_id = &s } -// FullServicePeriodFrom returns the value of the "full_service_period_from" field in the mutation. -func (m *ChargeFlatFeeMutation) FullServicePeriodFrom() (r time.Time, exists bool) { - v := m.full_service_period_from +// AuthorizedTransactionGroupID returns the value of the "authorized_transaction_group_id" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AuthorizedTransactionGroupID() (r string, exists bool) { + v := m.authorized_transaction_group_id if v == nil { return } return *v, true } -// OldFullServicePeriodFrom returns the old "full_service_period_from" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldAuthorizedTransactionGroupID returns the old "authorized_transaction_group_id" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldFullServicePeriodFrom(ctx context.Context) (v time.Time, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldAuthorizedTransactionGroupID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldFullServicePeriodFrom is only allowed on UpdateOne operations") + return v, errors.New("OldAuthorizedTransactionGroupID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldFullServicePeriodFrom requires an ID field in the mutation") + return v, errors.New("OldAuthorizedTransactionGroupID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldFullServicePeriodFrom: %w", err) + return v, fmt.Errorf("querying old value for OldAuthorizedTransactionGroupID: %w", err) } - return oldValue.FullServicePeriodFrom, nil -} - -// ResetFullServicePeriodFrom resets all changes to the "full_service_period_from" field. -func (m *ChargeFlatFeeMutation) ResetFullServicePeriodFrom() { - m.full_service_period_from = nil -} - -// SetFullServicePeriodTo sets the "full_service_period_to" field. -func (m *ChargeFlatFeeMutation) SetFullServicePeriodTo(t time.Time) { - m.full_service_period_to = &t + return oldValue.AuthorizedTransactionGroupID, nil } -// FullServicePeriodTo returns the value of the "full_service_period_to" field in the mutation. -func (m *ChargeFlatFeeMutation) FullServicePeriodTo() (r time.Time, exists bool) { - v := m.full_service_period_to - if v == nil { - return - } - return *v, true +// ClearAuthorizedTransactionGroupID clears the value of the "authorized_transaction_group_id" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearAuthorizedTransactionGroupID() { + m.authorized_transaction_group_id = nil + m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID] = struct{}{} } -// OldFullServicePeriodTo returns the old "full_service_period_to" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldFullServicePeriodTo(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldFullServicePeriodTo is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldFullServicePeriodTo requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldFullServicePeriodTo: %w", err) - } - return oldValue.FullServicePeriodTo, nil +// AuthorizedTransactionGroupIDCleared returns if the "authorized_transaction_group_id" field was cleared in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AuthorizedTransactionGroupIDCleared() bool { + _, ok := m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID] + return ok } -// ResetFullServicePeriodTo resets all changes to the "full_service_period_to" field. -func (m *ChargeFlatFeeMutation) ResetFullServicePeriodTo() { - m.full_service_period_to = nil +// ResetAuthorizedTransactionGroupID resets all changes to the "authorized_transaction_group_id" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetAuthorizedTransactionGroupID() { + m.authorized_transaction_group_id = nil + delete(m.clearedFields, chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID) } -// SetStatus sets the "status" field. -func (m *ChargeFlatFeeMutation) SetStatus(ms meta.ChargeStatus) { - m.status = &ms +// SetAuthorizedAt sets the "authorized_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetAuthorizedAt(t time.Time) { + m.authorized_at = &t } -// Status returns the value of the "status" field in the mutation. -func (m *ChargeFlatFeeMutation) Status() (r meta.ChargeStatus, exists bool) { - v := m.status +// AuthorizedAt returns the value of the "authorized_at" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AuthorizedAt() (r time.Time, exists bool) { + v := m.authorized_at if v == nil { return } return *v, true } -// OldStatus returns the old "status" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldAuthorizedAt returns the old "authorized_at" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldStatus(ctx context.Context) (v meta.ChargeStatus, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldAuthorizedAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldStatus is only allowed on UpdateOne operations") + return v, errors.New("OldAuthorizedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldStatus requires an ID field in the mutation") + return v, errors.New("OldAuthorizedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldStatus: %w", err) + return v, fmt.Errorf("querying old value for OldAuthorizedAt: %w", err) } - return oldValue.Status, nil + return oldValue.AuthorizedAt, nil } -// ResetStatus resets all changes to the "status" field. -func (m *ChargeFlatFeeMutation) ResetStatus() { - m.status = nil +// ClearAuthorizedAt clears the value of the "authorized_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearAuthorizedAt() { + m.authorized_at = nil + m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt] = struct{}{} } -// SetUniqueReferenceID sets the "unique_reference_id" field. -func (m *ChargeFlatFeeMutation) SetUniqueReferenceID(s string) { - m.unique_reference_id = &s +// AuthorizedAtCleared returns if the "authorized_at" field was cleared in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AuthorizedAtCleared() bool { + _, ok := m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt] + return ok } -// UniqueReferenceID returns the value of the "unique_reference_id" field in the mutation. -func (m *ChargeFlatFeeMutation) UniqueReferenceID() (r string, exists bool) { - v := m.unique_reference_id +// ResetAuthorizedAt resets all changes to the "authorized_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetAuthorizedAt() { + m.authorized_at = nil + delete(m.clearedFields, chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt) +} + +// SetSettledTransactionGroupID sets the "settled_transaction_group_id" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetSettledTransactionGroupID(s string) { + m.settled_transaction_group_id = &s +} + +// SettledTransactionGroupID returns the value of the "settled_transaction_group_id" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SettledTransactionGroupID() (r string, exists bool) { + v := m.settled_transaction_group_id if v == nil { return } return *v, true } -// OldUniqueReferenceID returns the old "unique_reference_id" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldSettledTransactionGroupID returns the old "settled_transaction_group_id" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldUniqueReferenceID(ctx context.Context) (v *string, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldSettledTransactionGroupID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUniqueReferenceID is only allowed on UpdateOne operations") + return v, errors.New("OldSettledTransactionGroupID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUniqueReferenceID requires an ID field in the mutation") + return v, errors.New("OldSettledTransactionGroupID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldUniqueReferenceID: %w", err) + return v, fmt.Errorf("querying old value for OldSettledTransactionGroupID: %w", err) } - return oldValue.UniqueReferenceID, nil + return oldValue.SettledTransactionGroupID, nil } -// ClearUniqueReferenceID clears the value of the "unique_reference_id" field. -func (m *ChargeFlatFeeMutation) ClearUniqueReferenceID() { - m.unique_reference_id = nil - m.clearedFields[chargeflatfee.FieldUniqueReferenceID] = struct{}{} +// ClearSettledTransactionGroupID clears the value of the "settled_transaction_group_id" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearSettledTransactionGroupID() { + m.settled_transaction_group_id = nil + m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID] = struct{}{} } -// UniqueReferenceIDCleared returns if the "unique_reference_id" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) UniqueReferenceIDCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldUniqueReferenceID] +// SettledTransactionGroupIDCleared returns if the "settled_transaction_group_id" field was cleared in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SettledTransactionGroupIDCleared() bool { + _, ok := m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID] return ok } -// ResetUniqueReferenceID resets all changes to the "unique_reference_id" field. -func (m *ChargeFlatFeeMutation) ResetUniqueReferenceID() { - m.unique_reference_id = nil - delete(m.clearedFields, chargeflatfee.FieldUniqueReferenceID) +// ResetSettledTransactionGroupID resets all changes to the "settled_transaction_group_id" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetSettledTransactionGroupID() { + m.settled_transaction_group_id = nil + delete(m.clearedFields, chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID) } -// SetFiatCurrencyCode sets the "fiat_currency_code" field. -func (m *ChargeFlatFeeMutation) SetFiatCurrencyCode(c currencyx.Code) { - m.fiat_currency_code = &c +// SetSettledAt sets the "settled_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetSettledAt(t time.Time) { + m.settled_at = &t } -// FiatCurrencyCode returns the value of the "fiat_currency_code" field in the mutation. -func (m *ChargeFlatFeeMutation) FiatCurrencyCode() (r currencyx.Code, exists bool) { - v := m.fiat_currency_code +// SettledAt returns the value of the "settled_at" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SettledAt() (r time.Time, exists bool) { + v := m.settled_at if v == nil { return } return *v, true } -// OldFiatCurrencyCode returns the old "fiat_currency_code" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldSettledAt returns the old "settled_at" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldFiatCurrencyCode(ctx context.Context) (v *currencyx.Code, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldSettledAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldFiatCurrencyCode is only allowed on UpdateOne operations") + return v, errors.New("OldSettledAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldFiatCurrencyCode requires an ID field in the mutation") + return v, errors.New("OldSettledAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldFiatCurrencyCode: %w", err) + return v, fmt.Errorf("querying old value for OldSettledAt: %w", err) } - return oldValue.FiatCurrencyCode, nil + return oldValue.SettledAt, nil } -// ClearFiatCurrencyCode clears the value of the "fiat_currency_code" field. -func (m *ChargeFlatFeeMutation) ClearFiatCurrencyCode() { - m.fiat_currency_code = nil - m.clearedFields[chargeflatfee.FieldFiatCurrencyCode] = struct{}{} +// ClearSettledAt clears the value of the "settled_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearSettledAt() { + m.settled_at = nil + m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldSettledAt] = struct{}{} } -// FiatCurrencyCodeCleared returns if the "fiat_currency_code" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) FiatCurrencyCodeCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldFiatCurrencyCode] +// SettledAtCleared returns if the "settled_at" field was cleared in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SettledAtCleared() bool { + _, ok := m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldSettledAt] return ok } -// ResetFiatCurrencyCode resets all changes to the "fiat_currency_code" field. -func (m *ChargeFlatFeeMutation) ResetFiatCurrencyCode() { - m.fiat_currency_code = nil - delete(m.clearedFields, chargeflatfee.FieldFiatCurrencyCode) +// ResetSettledAt resets all changes to the "settled_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetSettledAt() { + m.settled_at = nil + delete(m.clearedFields, chargecreditpurchaseinvoicedpayment.FieldSettledAt) } -// SetCustomCurrencyID sets the "custom_currency_id" field. -func (m *ChargeFlatFeeMutation) SetCustomCurrencyID(s string) { - m.custom_currency = &s +// SetNamespace sets the "namespace" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetNamespace(s string) { + m.namespace = &s } -// CustomCurrencyID returns the value of the "custom_currency_id" field in the mutation. -func (m *ChargeFlatFeeMutation) CustomCurrencyID() (r string, exists bool) { - v := m.custom_currency +// Namespace returns the value of the "namespace" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Namespace() (r string, exists bool) { + v := m.namespace if v == nil { return } return *v, true } -// OldCustomCurrencyID returns the old "custom_currency_id" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldNamespace returns the old "namespace" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldCustomCurrencyID(ctx context.Context) (v *string, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldNamespace(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCustomCurrencyID is only allowed on UpdateOne operations") + return v, errors.New("OldNamespace is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCustomCurrencyID requires an ID field in the mutation") + 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 OldCustomCurrencyID: %w", err) + return v, fmt.Errorf("querying old value for OldNamespace: %w", err) } - return oldValue.CustomCurrencyID, nil -} - -// ClearCustomCurrencyID clears the value of the "custom_currency_id" field. -func (m *ChargeFlatFeeMutation) ClearCustomCurrencyID() { - m.custom_currency = nil - m.clearedFields[chargeflatfee.FieldCustomCurrencyID] = struct{}{} -} - -// CustomCurrencyIDCleared returns if the "custom_currency_id" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) CustomCurrencyIDCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldCustomCurrencyID] - return ok + return oldValue.Namespace, nil } -// ResetCustomCurrencyID resets all changes to the "custom_currency_id" field. -func (m *ChargeFlatFeeMutation) ResetCustomCurrencyID() { - m.custom_currency = nil - delete(m.clearedFields, chargeflatfee.FieldCustomCurrencyID) +// ResetNamespace resets all changes to the "namespace" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetNamespace() { + m.namespace = nil } -// SetManagedBy sets the "managed_by" field. -func (m *ChargeFlatFeeMutation) SetManagedBy(blmb billing.InvoiceLineManagedBy) { - m.managed_by = &blmb +// SetCreatedAt sets the "created_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetCreatedAt(t time.Time) { + m.created_at = &t } -// ManagedBy returns the value of the "managed_by" field in the mutation. -func (m *ChargeFlatFeeMutation) ManagedBy() (r billing.InvoiceLineManagedBy, exists bool) { - v := m.managed_by +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at if v == nil { return } return *v, true } -// OldManagedBy returns the old "managed_by" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldManagedBy(ctx context.Context) (v billing.InvoiceLineManagedBy, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldManagedBy is only allowed on UpdateOne operations") + return v, errors.New("OldCreatedAt 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") + 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 OldManagedBy: %w", err) + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } - return oldValue.ManagedBy, nil + return oldValue.CreatedAt, nil } -// ResetManagedBy resets all changes to the "managed_by" field. -func (m *ChargeFlatFeeMutation) ResetManagedBy() { - m.managed_by = nil +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetCreatedAt() { + m.created_at = nil } -// SetSubscriptionID sets the "subscription_id" field. -func (m *ChargeFlatFeeMutation) SetSubscriptionID(s string) { - m.subscription = &s +// SetUpdatedAt sets the "updated_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t } -// SubscriptionID returns the value of the "subscription_id" field in the mutation. -func (m *ChargeFlatFeeMutation) SubscriptionID() (r string, exists bool) { - v := m.subscription +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at if v == nil { return } return *v, true } -// OldSubscriptionID returns the old "subscription_id" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldSubscriptionID(ctx context.Context) (v *string, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSubscriptionID is only allowed on UpdateOne operations") + return v, errors.New("OldUpdatedAt 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") + 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 OldSubscriptionID: %w", err) + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } - return oldValue.SubscriptionID, nil -} - -// ClearSubscriptionID clears the value of the "subscription_id" field. -func (m *ChargeFlatFeeMutation) ClearSubscriptionID() { - m.subscription = nil - m.clearedFields[chargeflatfee.FieldSubscriptionID] = struct{}{} -} - -// SubscriptionIDCleared returns if the "subscription_id" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) SubscriptionIDCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldSubscriptionID] - return ok + return oldValue.UpdatedAt, nil } -// ResetSubscriptionID resets all changes to the "subscription_id" field. -func (m *ChargeFlatFeeMutation) ResetSubscriptionID() { - m.subscription = nil - delete(m.clearedFields, chargeflatfee.FieldSubscriptionID) +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetUpdatedAt() { + m.updated_at = nil } -// SetSubscriptionPhaseID sets the "subscription_phase_id" field. -func (m *ChargeFlatFeeMutation) SetSubscriptionPhaseID(s string) { - m.subscription_phase = &s +// SetDeletedAt sets the "deleted_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetDeletedAt(t time.Time) { + m.deleted_at = &t } -// SubscriptionPhaseID returns the value of the "subscription_phase_id" field in the mutation. -func (m *ChargeFlatFeeMutation) SubscriptionPhaseID() (r string, exists bool) { - v := m.subscription_phase +// DeletedAt returns the value of the "deleted_at" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) DeletedAt() (r time.Time, exists bool) { + v := m.deleted_at if v == nil { return } return *v, true } -// OldSubscriptionPhaseID returns the old "subscription_phase_id" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldDeletedAt returns the old "deleted_at" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldSubscriptionPhaseID(ctx context.Context) (v *string, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSubscriptionPhaseID is only allowed on UpdateOne operations") + return v, errors.New("OldDeletedAt 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") + 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 OldSubscriptionPhaseID: %w", err) + return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) } - return oldValue.SubscriptionPhaseID, nil + return oldValue.DeletedAt, nil } -// ClearSubscriptionPhaseID clears the value of the "subscription_phase_id" field. -func (m *ChargeFlatFeeMutation) ClearSubscriptionPhaseID() { - m.subscription_phase = nil - m.clearedFields[chargeflatfee.FieldSubscriptionPhaseID] = struct{}{} +// ClearDeletedAt clears the value of the "deleted_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearDeletedAt() { + m.deleted_at = nil + m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldDeletedAt] = struct{}{} } -// SubscriptionPhaseIDCleared returns if the "subscription_phase_id" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) SubscriptionPhaseIDCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldSubscriptionPhaseID] +// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldDeletedAt] return ok } -// ResetSubscriptionPhaseID resets all changes to the "subscription_phase_id" field. -func (m *ChargeFlatFeeMutation) ResetSubscriptionPhaseID() { - m.subscription_phase = nil - delete(m.clearedFields, chargeflatfee.FieldSubscriptionPhaseID) +// ResetDeletedAt resets all changes to the "deleted_at" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetDeletedAt() { + m.deleted_at = nil + delete(m.clearedFields, chargecreditpurchaseinvoicedpayment.FieldDeletedAt) } -// SetSubscriptionItemID sets the "subscription_item_id" field. -func (m *ChargeFlatFeeMutation) SetSubscriptionItemID(s string) { - m.subscription_item = &s +// SetAnnotations sets the "annotations" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetAnnotations(value models.Annotations) { + m.annotations = &value } -// SubscriptionItemID returns the value of the "subscription_item_id" field in the mutation. -func (m *ChargeFlatFeeMutation) SubscriptionItemID() (r string, exists bool) { - v := m.subscription_item +// Annotations returns the value of the "annotations" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Annotations() (r models.Annotations, exists bool) { + v := m.annotations if v == nil { return } return *v, true } -// OldSubscriptionItemID returns the old "subscription_item_id" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldAnnotations returns the old "annotations" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldSubscriptionItemID(ctx context.Context) (v *string, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldAnnotations(ctx context.Context) (v models.Annotations, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSubscriptionItemID is only allowed on UpdateOne operations") + return v, errors.New("OldAnnotations 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") + 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 OldSubscriptionItemID: %w", err) + return v, fmt.Errorf("querying old value for OldAnnotations: %w", err) } - return oldValue.SubscriptionItemID, nil + return oldValue.Annotations, nil } -// ClearSubscriptionItemID clears the value of the "subscription_item_id" field. -func (m *ChargeFlatFeeMutation) ClearSubscriptionItemID() { - m.subscription_item = nil - m.clearedFields[chargeflatfee.FieldSubscriptionItemID] = struct{}{} +// ClearAnnotations clears the value of the "annotations" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearAnnotations() { + m.annotations = nil + m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldAnnotations] = struct{}{} } -// SubscriptionItemIDCleared returns if the "subscription_item_id" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) SubscriptionItemIDCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldSubscriptionItemID] +// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AnnotationsCleared() bool { + _, ok := m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldAnnotations] return ok } -// ResetSubscriptionItemID resets all changes to the "subscription_item_id" field. -func (m *ChargeFlatFeeMutation) ResetSubscriptionItemID() { - m.subscription_item = nil - delete(m.clearedFields, chargeflatfee.FieldSubscriptionItemID) +// ResetAnnotations resets all changes to the "annotations" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetAnnotations() { + m.annotations = nil + delete(m.clearedFields, chargecreditpurchaseinvoicedpayment.FieldAnnotations) } -// SetAdvanceAfter sets the "advance_after" field. -func (m *ChargeFlatFeeMutation) SetAdvanceAfter(t time.Time) { - m.advance_after = &t +// SetChargeID sets the "charge_id" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetChargeID(s string) { + m.credit_purchase = &s } -// AdvanceAfter returns the value of the "advance_after" field in the mutation. -func (m *ChargeFlatFeeMutation) AdvanceAfter() (r time.Time, exists bool) { - v := m.advance_after +// ChargeID returns the value of the "charge_id" field in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ChargeID() (r string, exists bool) { + v := m.credit_purchase if v == nil { return } return *v, true } -// OldAdvanceAfter returns the old "advance_after" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee object wasn't provided to the builder, the object is fetched from the database. +// OldChargeID returns the old "charge_id" field's value of the ChargeCreditPurchaseInvoicedPayment entity. +// If the ChargeCreditPurchaseInvoicedPayment 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 *ChargeFlatFeeMutation) OldAdvanceAfter(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) OldChargeID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAdvanceAfter is only allowed on UpdateOne operations") + return v, errors.New("OldChargeID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAdvanceAfter requires an ID field in the mutation") + 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 OldAdvanceAfter: %w", err) + return v, fmt.Errorf("querying old value for OldChargeID: %w", err) } - return oldValue.AdvanceAfter, nil + return oldValue.ChargeID, nil } -// ClearAdvanceAfter clears the value of the "advance_after" field. -func (m *ChargeFlatFeeMutation) ClearAdvanceAfter() { - m.advance_after = nil - m.clearedFields[chargeflatfee.FieldAdvanceAfter] = struct{}{} +// ResetChargeID resets all changes to the "charge_id" field. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetChargeID() { + m.credit_purchase = nil } -// AdvanceAfterCleared returns if the "advance_after" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) AdvanceAfterCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldAdvanceAfter] - return ok +// SetBillingInvoiceLineID sets the "billing_invoice_line" edge to the BillingInvoiceLine entity by id. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetBillingInvoiceLineID(id string) { + m.billing_invoice_line = &id } -// ResetAdvanceAfter resets all changes to the "advance_after" field. -func (m *ChargeFlatFeeMutation) ResetAdvanceAfter() { - m.advance_after = nil - delete(m.clearedFields, chargeflatfee.FieldAdvanceAfter) +// ClearBillingInvoiceLine clears the "billing_invoice_line" edge to the BillingInvoiceLine entity. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearBillingInvoiceLine() { + m.clearedbilling_invoice_line = true + m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldLineID] = struct{}{} } -// SetTaxCodeID sets the "tax_code_id" field. -func (m *ChargeFlatFeeMutation) SetTaxCodeID(s string) { - m.tax_code = &s +// BillingInvoiceLineCleared reports if the "billing_invoice_line" edge to the BillingInvoiceLine entity was cleared. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) BillingInvoiceLineCleared() bool { + return m.clearedbilling_invoice_line } -// TaxCodeID returns the value of the "tax_code_id" field in the mutation. -func (m *ChargeFlatFeeMutation) TaxCodeID() (r string, exists bool) { - v := m.tax_code - if v == nil { - return +// BillingInvoiceLineID returns the "billing_invoice_line" edge ID in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) BillingInvoiceLineID() (id string, exists bool) { + if m.billing_invoice_line != nil { + return *m.billing_invoice_line, true } - return *v, true + return } -// OldTaxCodeID returns the old "tax_code_id" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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) +// BillingInvoiceLineIDs returns the "billing_invoice_line" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// BillingInvoiceLineID instead. It exists only for internal usage by the builders. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) BillingInvoiceLineIDs() (ids []string) { + if id := m.billing_invoice_line; id != nil { + ids = append(ids, *id) } - return oldValue.TaxCodeID, nil -} - -// ResetTaxCodeID resets all changes to the "tax_code_id" field. -func (m *ChargeFlatFeeMutation) ResetTaxCodeID() { - m.tax_code = nil + return } -// SetTaxBehavior sets the "tax_behavior" field. -func (m *ChargeFlatFeeMutation) SetTaxBehavior(pb productcatalog.TaxBehavior) { - m.tax_behavior = &pb +// ResetBillingInvoiceLine resets all changes to the "billing_invoice_line" edge. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetBillingInvoiceLine() { + m.billing_invoice_line = nil + m.clearedbilling_invoice_line = false } -// TaxBehavior returns the value of the "tax_behavior" field in the mutation. -func (m *ChargeFlatFeeMutation) TaxBehavior() (r productcatalog.TaxBehavior, exists bool) { - v := m.tax_behavior - if v == nil { - return - } - return *v, true +// SetCreditPurchaseID sets the "credit_purchase" edge to the ChargeCreditPurchase entity by id. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetCreditPurchaseID(id string) { + m.credit_purchase = &id } -// OldTaxBehavior returns the old "tax_behavior" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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 +// ClearCreditPurchase clears the "credit_purchase" edge to the ChargeCreditPurchase entity. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearCreditPurchase() { + m.clearedcredit_purchase = true + m.clearedFields[chargecreditpurchaseinvoicedpayment.FieldChargeID] = struct{}{} } -// ClearTaxBehavior clears the value of the "tax_behavior" field. -func (m *ChargeFlatFeeMutation) ClearTaxBehavior() { - m.tax_behavior = nil - m.clearedFields[chargeflatfee.FieldTaxBehavior] = struct{}{} +// CreditPurchaseCleared reports if the "credit_purchase" edge to the ChargeCreditPurchase entity was cleared. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) CreditPurchaseCleared() bool { + return m.clearedcredit_purchase } -// TaxBehaviorCleared returns if the "tax_behavior" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) TaxBehaviorCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldTaxBehavior] - return ok +// CreditPurchaseID returns the "credit_purchase" edge ID in the mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) CreditPurchaseID() (id string, exists bool) { + if m.credit_purchase != nil { + return *m.credit_purchase, true + } + return } -// ResetTaxBehavior resets all changes to the "tax_behavior" field. -func (m *ChargeFlatFeeMutation) ResetTaxBehavior() { - m.tax_behavior = nil - delete(m.clearedFields, chargeflatfee.FieldTaxBehavior) +// CreditPurchaseIDs returns the "credit_purchase" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CreditPurchaseID instead. It exists only for internal usage by the builders. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) CreditPurchaseIDs() (ids []string) { + if id := m.credit_purchase; id != nil { + ids = append(ids, *id) + } + return } -// SetAnnotations sets the "annotations" field. -func (m *ChargeFlatFeeMutation) SetAnnotations(value models.Annotations) { - m.annotations = &value +// ResetCreditPurchase resets all changes to the "credit_purchase" edge. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ResetCreditPurchase() { + m.credit_purchase = nil + m.clearedcredit_purchase = false } -// Annotations returns the value of the "annotations" field in the mutation. -func (m *ChargeFlatFeeMutation) Annotations() (r models.Annotations, exists bool) { - v := m.annotations - if v == nil { - return - } - return *v, true +// Where appends a list predicates to the ChargeCreditPurchaseInvoicedPaymentMutation builder. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Where(ps ...predicate.ChargeCreditPurchaseInvoicedPayment) { + m.predicates = append(m.predicates, ps...) } -// OldAnnotations returns the old "annotations" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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) +// WhereP appends storage-level predicates to the ChargeCreditPurchaseInvoicedPaymentMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeCreditPurchaseInvoicedPayment, len(ps)) + for i := range ps { + p[i] = ps[i] } - return oldValue.Annotations, nil -} - -// ClearAnnotations clears the value of the "annotations" field. -func (m *ChargeFlatFeeMutation) ClearAnnotations() { - m.annotations = nil - m.clearedFields[chargeflatfee.FieldAnnotations] = struct{}{} + m.Where(p...) } -// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) AnnotationsCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldAnnotations] - return ok +// Op returns the operation name. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Op() Op { + return m.op } -// ResetAnnotations resets all changes to the "annotations" field. -func (m *ChargeFlatFeeMutation) ResetAnnotations() { - m.annotations = nil - delete(m.clearedFields, chargeflatfee.FieldAnnotations) +// SetOp allows setting the mutation operation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) SetOp(op Op) { + m.op = op } -// SetNamespace sets the "namespace" field. -func (m *ChargeFlatFeeMutation) SetNamespace(s string) { - m.namespace = &s +// Type returns the node type of this mutation (ChargeCreditPurchaseInvoicedPayment). +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) Type() string { + return m.typ } -// Namespace returns the value of the "namespace" field in the mutation. -func (m *ChargeFlatFeeMutation) Namespace() (r string, exists bool) { - v := m.namespace - if v == nil { - return +// 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 *ChargeCreditPurchaseInvoicedPaymentMutation) Fields() []string { + fields := make([]string, 0, 16) + if m.billing_invoice_line != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldLineID) } - return *v, true -} - -// OldNamespace returns the old "namespace" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.invoice_id != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldInvoiceID) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldNamespace requires an ID field in the mutation") + if m.service_period_from != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldServicePeriodFrom) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldNamespace: %w", err) + if m.service_period_to != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldServicePeriodTo) } - return oldValue.Namespace, nil -} - -// ResetNamespace resets all changes to the "namespace" field. -func (m *ChargeFlatFeeMutation) ResetNamespace() { - m.namespace = nil -} - -// SetMetadata sets the "metadata" field. -func (m *ChargeFlatFeeMutation) SetMetadata(value map[string]string) { - m.metadata = &value -} - -// Metadata returns the value of the "metadata" field in the mutation. -func (m *ChargeFlatFeeMutation) Metadata() (r map[string]string, exists bool) { - v := m.metadata - if v == nil { - return + if m.status != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldStatus) } - return *v, true -} - -// OldMetadata returns the old "metadata" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.amount != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAmount) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldMetadata requires an ID field in the mutation") + if m.authorized_transaction_group_id != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldMetadata: %w", err) + if m.authorized_at != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt) } - return oldValue.Metadata, nil -} - -// ClearMetadata clears the value of the "metadata" field. -func (m *ChargeFlatFeeMutation) ClearMetadata() { - m.metadata = nil - m.clearedFields[chargeflatfee.FieldMetadata] = struct{}{} -} - -// MetadataCleared returns if the "metadata" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) MetadataCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldMetadata] - return ok -} - -// ResetMetadata resets all changes to the "metadata" field. -func (m *ChargeFlatFeeMutation) ResetMetadata() { - m.metadata = nil - delete(m.clearedFields, chargeflatfee.FieldMetadata) -} - -// SetCreatedAt sets the "created_at" field. -func (m *ChargeFlatFeeMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ChargeFlatFeeMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return + if m.settled_transaction_group_id != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID) } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.settled_at != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldSettledAt) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreatedAt requires an ID field in the mutation") + if m.namespace != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldNamespace) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + if m.created_at != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldCreatedAt) } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *ChargeFlatFeeMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *ChargeFlatFeeMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ChargeFlatFeeMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return + if m.updated_at != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldUpdatedAt) } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.deleted_at != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldDeletedAt) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + if m.annotations != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAnnotations) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + if m.credit_purchase != nil { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldChargeID) } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *ChargeFlatFeeMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// SetDeletedAt sets the "deleted_at" field. -func (m *ChargeFlatFeeMutation) SetDeletedAt(t time.Time) { - m.deleted_at = &t + return fields } -// DeletedAt returns the value of the "deleted_at" field in the mutation. -func (m *ChargeFlatFeeMutation) DeletedAt() (r time.Time, exists bool) { - v := m.deleted_at - if v == nil { - return +// 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 *ChargeCreditPurchaseInvoicedPaymentMutation) Field(name string) (ent.Value, bool) { + switch name { + case chargecreditpurchaseinvoicedpayment.FieldLineID: + return m.LineID() + case chargecreditpurchaseinvoicedpayment.FieldInvoiceID: + return m.InvoiceID() + case chargecreditpurchaseinvoicedpayment.FieldServicePeriodFrom: + return m.ServicePeriodFrom() + case chargecreditpurchaseinvoicedpayment.FieldServicePeriodTo: + return m.ServicePeriodTo() + case chargecreditpurchaseinvoicedpayment.FieldStatus: + return m.Status() + case chargecreditpurchaseinvoicedpayment.FieldAmount: + return m.Amount() + case chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID: + return m.AuthorizedTransactionGroupID() + case chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt: + return m.AuthorizedAt() + case chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID: + return m.SettledTransactionGroupID() + case chargecreditpurchaseinvoicedpayment.FieldSettledAt: + return m.SettledAt() + case chargecreditpurchaseinvoicedpayment.FieldNamespace: + return m.Namespace() + case chargecreditpurchaseinvoicedpayment.FieldCreatedAt: + return m.CreatedAt() + case chargecreditpurchaseinvoicedpayment.FieldUpdatedAt: + return m.UpdatedAt() + case chargecreditpurchaseinvoicedpayment.FieldDeletedAt: + return m.DeletedAt() + case chargecreditpurchaseinvoicedpayment.FieldAnnotations: + return m.Annotations() + case chargecreditpurchaseinvoicedpayment.FieldChargeID: + return m.ChargeID() } - return *v, true + return nil, false } -// OldDeletedAt returns the old "deleted_at" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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) +// 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 *ChargeCreditPurchaseInvoicedPaymentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case chargecreditpurchaseinvoicedpayment.FieldLineID: + return m.OldLineID(ctx) + case chargecreditpurchaseinvoicedpayment.FieldInvoiceID: + return m.OldInvoiceID(ctx) + case chargecreditpurchaseinvoicedpayment.FieldServicePeriodFrom: + return m.OldServicePeriodFrom(ctx) + case chargecreditpurchaseinvoicedpayment.FieldServicePeriodTo: + return m.OldServicePeriodTo(ctx) + case chargecreditpurchaseinvoicedpayment.FieldStatus: + return m.OldStatus(ctx) + case chargecreditpurchaseinvoicedpayment.FieldAmount: + return m.OldAmount(ctx) + case chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID: + return m.OldAuthorizedTransactionGroupID(ctx) + case chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt: + return m.OldAuthorizedAt(ctx) + case chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID: + return m.OldSettledTransactionGroupID(ctx) + case chargecreditpurchaseinvoicedpayment.FieldSettledAt: + return m.OldSettledAt(ctx) + case chargecreditpurchaseinvoicedpayment.FieldNamespace: + return m.OldNamespace(ctx) + case chargecreditpurchaseinvoicedpayment.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case chargecreditpurchaseinvoicedpayment.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case chargecreditpurchaseinvoicedpayment.FieldDeletedAt: + return m.OldDeletedAt(ctx) + case chargecreditpurchaseinvoicedpayment.FieldAnnotations: + return m.OldAnnotations(ctx) + case chargecreditpurchaseinvoicedpayment.FieldChargeID: + return m.OldChargeID(ctx) } - return oldValue.DeletedAt, nil -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (m *ChargeFlatFeeMutation) ClearDeletedAt() { - m.deleted_at = nil - m.clearedFields[chargeflatfee.FieldDeletedAt] = struct{}{} + return nil, fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment field %s", name) } -// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) DeletedAtCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldDeletedAt] - return ok +// 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 *ChargeCreditPurchaseInvoicedPaymentMutation) SetField(name string, value ent.Value) error { + switch name { + case chargecreditpurchaseinvoicedpayment.FieldLineID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLineID(v) + return nil + case chargecreditpurchaseinvoicedpayment.FieldInvoiceID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetInvoiceID(v) + return nil + case chargecreditpurchaseinvoicedpayment.FieldServicePeriodFrom: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServicePeriodFrom(v) + return nil + case chargecreditpurchaseinvoicedpayment.FieldServicePeriodTo: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServicePeriodTo(v) + return nil + case chargecreditpurchaseinvoicedpayment.FieldStatus: + v, ok := value.(payment.Status) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + case chargecreditpurchaseinvoicedpayment.FieldAmount: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAmount(v) + return nil + case chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAuthorizedTransactionGroupID(v) + return nil + case chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAuthorizedAt(v) + return nil + case chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSettledTransactionGroupID(v) + return nil + case chargecreditpurchaseinvoicedpayment.FieldSettledAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSettledAt(v) + return nil + case chargecreditpurchaseinvoicedpayment.FieldNamespace: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNamespace(v) + return nil + case chargecreditpurchaseinvoicedpayment.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 chargecreditpurchaseinvoicedpayment.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 chargecreditpurchaseinvoicedpayment.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 chargecreditpurchaseinvoicedpayment.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 chargecreditpurchaseinvoicedpayment.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 ChargeCreditPurchaseInvoicedPayment field %s", name) } -// ResetDeletedAt resets all changes to the "deleted_at" field. -func (m *ChargeFlatFeeMutation) ResetDeletedAt() { - m.deleted_at = nil - delete(m.clearedFields, chargeflatfee.FieldDeletedAt) +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AddedFields() []string { + return nil } -// SetName sets the "name" field. -func (m *ChargeFlatFeeMutation) SetName(s string) { - m.name = &s +// 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 *ChargeCreditPurchaseInvoicedPaymentMutation) AddedField(name string) (ent.Value, bool) { + return nil, false } -// Name returns the value of the "name" field in the mutation. -func (m *ChargeFlatFeeMutation) Name() (r string, exists bool) { - v := m.name - if v == nil { - return +// 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 *ChargeCreditPurchaseInvoicedPaymentMutation) AddField(name string, value ent.Value) error { + switch name { } - return *v, true + return fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment numeric field %s", name) } -// OldName returns the old "name" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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") +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID) { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldName: %w", err) + if m.FieldCleared(chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt) { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt) } - return oldValue.Name, nil -} - -// ResetName resets all changes to the "name" field. -func (m *ChargeFlatFeeMutation) ResetName() { - m.name = nil -} - -// SetDescription sets the "description" field. -func (m *ChargeFlatFeeMutation) SetDescription(s string) { - m.description = &s -} - -// Description returns the value of the "description" field in the mutation. -func (m *ChargeFlatFeeMutation) Description() (r string, exists bool) { - v := m.description - if v == nil { - return + if m.FieldCleared(chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID) { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID) } - return *v, true -} - -// OldDescription returns the old "description" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.FieldCleared(chargecreditpurchaseinvoicedpayment.FieldSettledAt) { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldSettledAt) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDescription requires an ID field in the mutation") + if m.FieldCleared(chargecreditpurchaseinvoicedpayment.FieldDeletedAt) { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldDeletedAt) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDescription: %w", err) + if m.FieldCleared(chargecreditpurchaseinvoicedpayment.FieldAnnotations) { + fields = append(fields, chargecreditpurchaseinvoicedpayment.FieldAnnotations) } - return oldValue.Description, nil -} - -// ClearDescription clears the value of the "description" field. -func (m *ChargeFlatFeeMutation) ClearDescription() { - m.description = nil - m.clearedFields[chargeflatfee.FieldDescription] = struct{}{} + return fields } -// DescriptionCleared returns if the "description" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) DescriptionCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldDescription] +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] return ok } -// ResetDescription resets all changes to the "description" field. -func (m *ChargeFlatFeeMutation) ResetDescription() { - m.description = nil - delete(m.clearedFields, chargeflatfee.FieldDescription) -} - -// SetPaymentTerm sets the "payment_term" field. -func (m *ChargeFlatFeeMutation) SetPaymentTerm(ptt productcatalog.PaymentTermType) { - m.payment_term = &ptt +// 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 *ChargeCreditPurchaseInvoicedPaymentMutation) ClearField(name string) error { + switch name { + case chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID: + m.ClearAuthorizedTransactionGroupID() + return nil + case chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt: + m.ClearAuthorizedAt() + return nil + case chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID: + m.ClearSettledTransactionGroupID() + return nil + case chargecreditpurchaseinvoicedpayment.FieldSettledAt: + m.ClearSettledAt() + return nil + case chargecreditpurchaseinvoicedpayment.FieldDeletedAt: + m.ClearDeletedAt() + return nil + case chargecreditpurchaseinvoicedpayment.FieldAnnotations: + m.ClearAnnotations() + return nil + } + return fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment nullable field %s", name) } -// PaymentTerm returns the value of the "payment_term" field in the mutation. -func (m *ChargeFlatFeeMutation) PaymentTerm() (r productcatalog.PaymentTermType, exists bool) { - v := m.payment_term - if v == nil { - return +// 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 *ChargeCreditPurchaseInvoicedPaymentMutation) ResetField(name string) error { + switch name { + case chargecreditpurchaseinvoicedpayment.FieldLineID: + m.ResetLineID() + return nil + case chargecreditpurchaseinvoicedpayment.FieldInvoiceID: + m.ResetInvoiceID() + return nil + case chargecreditpurchaseinvoicedpayment.FieldServicePeriodFrom: + m.ResetServicePeriodFrom() + return nil + case chargecreditpurchaseinvoicedpayment.FieldServicePeriodTo: + m.ResetServicePeriodTo() + return nil + case chargecreditpurchaseinvoicedpayment.FieldStatus: + m.ResetStatus() + return nil + case chargecreditpurchaseinvoicedpayment.FieldAmount: + m.ResetAmount() + return nil + case chargecreditpurchaseinvoicedpayment.FieldAuthorizedTransactionGroupID: + m.ResetAuthorizedTransactionGroupID() + return nil + case chargecreditpurchaseinvoicedpayment.FieldAuthorizedAt: + m.ResetAuthorizedAt() + return nil + case chargecreditpurchaseinvoicedpayment.FieldSettledTransactionGroupID: + m.ResetSettledTransactionGroupID() + return nil + case chargecreditpurchaseinvoicedpayment.FieldSettledAt: + m.ResetSettledAt() + return nil + case chargecreditpurchaseinvoicedpayment.FieldNamespace: + m.ResetNamespace() + return nil + case chargecreditpurchaseinvoicedpayment.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case chargecreditpurchaseinvoicedpayment.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case chargecreditpurchaseinvoicedpayment.FieldDeletedAt: + m.ResetDeletedAt() + return nil + case chargecreditpurchaseinvoicedpayment.FieldAnnotations: + m.ResetAnnotations() + return nil + case chargecreditpurchaseinvoicedpayment.FieldChargeID: + m.ResetChargeID() + return nil } - return *v, true + return fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment field %s", name) } -// OldPaymentTerm returns the old "payment_term" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldPaymentTerm(ctx context.Context) (v productcatalog.PaymentTermType, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldPaymentTerm is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldPaymentTerm requires an ID field in the mutation") +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AddedEdges() []string { + edges := make([]string, 0, 2) + if m.billing_invoice_line != nil { + edges = append(edges, chargecreditpurchaseinvoicedpayment.EdgeBillingInvoiceLine) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldPaymentTerm: %w", err) + if m.credit_purchase != nil { + edges = append(edges, chargecreditpurchaseinvoicedpayment.EdgeCreditPurchase) } - return oldValue.PaymentTerm, nil + return edges } -// ResetPaymentTerm resets all changes to the "payment_term" field. -func (m *ChargeFlatFeeMutation) ResetPaymentTerm() { - m.payment_term = nil +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) AddedIDs(name string) []ent.Value { + switch name { + case chargecreditpurchaseinvoicedpayment.EdgeBillingInvoiceLine: + if id := m.billing_invoice_line; id != nil { + return []ent.Value{*id} + } + case chargecreditpurchaseinvoicedpayment.EdgeCreditPurchase: + if id := m.credit_purchase; id != nil { + return []ent.Value{*id} + } + } + return nil } -// SetInvoiceAt sets the "invoice_at" field. -func (m *ChargeFlatFeeMutation) SetInvoiceAt(t time.Time) { - m.invoice_at = &t +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + return edges } -// InvoiceAt returns the value of the "invoice_at" field in the mutation. -func (m *ChargeFlatFeeMutation) InvoiceAt() (r time.Time, exists bool) { - v := m.invoice_at - if v == nil { - return - } - return *v, true +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) RemovedIDs(name string) []ent.Value { + return nil } -// OldInvoiceAt returns the old "invoice_at" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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") +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.clearedbilling_invoice_line { + edges = append(edges, chargecreditpurchaseinvoicedpayment.EdgeBillingInvoiceLine) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldInvoiceAt: %w", err) + if m.clearedcredit_purchase { + edges = append(edges, chargecreditpurchaseinvoicedpayment.EdgeCreditPurchase) } - return oldValue.InvoiceAt, nil -} - -// ResetInvoiceAt resets all changes to the "invoice_at" field. -func (m *ChargeFlatFeeMutation) ResetInvoiceAt() { - m.invoice_at = nil + return edges } -// SetSettlementMode sets the "settlement_mode" field. -func (m *ChargeFlatFeeMutation) SetSettlementMode(pm productcatalog.SettlementMode) { - m.settlement_mode = &pm +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ChargeCreditPurchaseInvoicedPaymentMutation) EdgeCleared(name string) bool { + switch name { + case chargecreditpurchaseinvoicedpayment.EdgeBillingInvoiceLine: + return m.clearedbilling_invoice_line + case chargecreditpurchaseinvoicedpayment.EdgeCreditPurchase: + return m.clearedcredit_purchase + } + return false } -// SettlementMode returns the value of the "settlement_mode" field in the mutation. -func (m *ChargeFlatFeeMutation) SettlementMode() (r productcatalog.SettlementMode, exists bool) { - v := m.settlement_mode - if v == nil { - return +// 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 *ChargeCreditPurchaseInvoicedPaymentMutation) ClearEdge(name string) error { + switch name { + case chargecreditpurchaseinvoicedpayment.EdgeBillingInvoiceLine: + m.ClearBillingInvoiceLine() + return nil + case chargecreditpurchaseinvoicedpayment.EdgeCreditPurchase: + m.ClearCreditPurchase() + return nil } - return *v, true + return fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment unique edge %s", name) } -// OldSettlementMode returns the old "settlement_mode" field's value of the ChargeFlatFee entity. -// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldSettlementMode(ctx context.Context) (v productcatalog.SettlementMode, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSettlementMode is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSettlementMode requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldSettlementMode: %w", err) +// 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 *ChargeCreditPurchaseInvoicedPaymentMutation) ResetEdge(name string) error { + switch name { + case chargecreditpurchaseinvoicedpayment.EdgeBillingInvoiceLine: + m.ResetBillingInvoiceLine() + return nil + case chargecreditpurchaseinvoicedpayment.EdgeCreditPurchase: + m.ResetCreditPurchase() + return nil } - return oldValue.SettlementMode, nil + return fmt.Errorf("unknown ChargeCreditPurchaseInvoicedPayment edge %s", name) } -// ResetSettlementMode resets all changes to the "settlement_mode" field. -func (m *ChargeFlatFeeMutation) ResetSettlementMode() { - m.settlement_mode = nil +// ChargeFlatFeeMutation represents an operation that mutates the ChargeFlatFee nodes in the graph. +type ChargeFlatFeeMutation struct { + config + op Op + typ string + id *string + service_period_from *time.Time + service_period_to *time.Time + billing_period_from *time.Time + billing_period_to *time.Time + full_service_period_from *time.Time + full_service_period_to *time.Time + status *meta.ChargeStatus + unique_reference_id *string + fiat_currency_code *currencyx.Code + managed_by *billing.InvoiceLineManagedBy + advance_after *time.Time + tax_behavior *productcatalog.TaxBehavior + 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 + payment_term *productcatalog.PaymentTermType + invoice_at *time.Time + settlement_mode *productcatalog.SettlementMode + intent_deleted_at *time.Time + discounts **billing.Discounts + pro_rating *flatfee.ProRatingModeAdapterEnum + feature_key *string + amount_before_proration *alpacadecimal.Decimal + amount_after_proration *alpacadecimal.Decimal + status_detailed *flatfee.Status + clearedFields map[string]struct{} + runs map[string]struct{} + removedruns map[string]struct{} + clearedruns bool + current_run *string + clearedcurrent_run bool + cost_basis *string + clearedcost_basis bool + charge *string + clearedcharge bool + intent_override *string + clearedintent_override bool + subscription *string + clearedsubscription bool + subscription_phase *string + clearedsubscription_phase bool + subscription_item *string + clearedsubscription_item bool + customer *string + clearedcustomer bool + feature *string + clearedfeature bool + tax_code *string + clearedtax_code bool + custom_currency *string + clearedcustom_currency bool + done bool + oldValue func(context.Context) (*ChargeFlatFee, error) + predicates []predicate.ChargeFlatFee } -// SetIntentDeletedAt sets the "intent_deleted_at" field. -func (m *ChargeFlatFeeMutation) SetIntentDeletedAt(t time.Time) { - m.intent_deleted_at = &t +var _ ent.Mutation = (*ChargeFlatFeeMutation)(nil) + +// chargeflatfeeOption allows management of the mutation configuration using functional options. +type chargeflatfeeOption func(*ChargeFlatFeeMutation) + +// newChargeFlatFeeMutation creates new mutation for the ChargeFlatFee entity. +func newChargeFlatFeeMutation(c config, op Op, opts ...chargeflatfeeOption) *ChargeFlatFeeMutation { + m := &ChargeFlatFeeMutation{ + config: c, + op: op, + typ: TypeChargeFlatFee, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m } -// IntentDeletedAt returns the value of the "intent_deleted_at" field in the mutation. -func (m *ChargeFlatFeeMutation) IntentDeletedAt() (r time.Time, exists bool) { - v := m.intent_deleted_at +// withChargeFlatFeeID sets the ID field of the mutation. +func withChargeFlatFeeID(id string) chargeflatfeeOption { + return func(m *ChargeFlatFeeMutation) { + var ( + err error + once sync.Once + value *ChargeFlatFee + ) + m.oldValue = func(ctx context.Context) (*ChargeFlatFee, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().ChargeFlatFee.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withChargeFlatFee sets the old ChargeFlatFee of the mutation. +func withChargeFlatFee(node *ChargeFlatFee) chargeflatfeeOption { + return func(m *ChargeFlatFeeMutation) { + m.oldValue = func(context.Context) (*ChargeFlatFee, 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 ChargeFlatFeeMutation) 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 ChargeFlatFeeMutation) 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 ChargeFlatFee entities. +func (m *ChargeFlatFeeMutation) 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 *ChargeFlatFeeMutation) 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 *ChargeFlatFeeMutation) 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().ChargeFlatFee.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetCustomerID sets the "customer_id" field. +func (m *ChargeFlatFeeMutation) SetCustomerID(s string) { + m.customer = &s +} + +// CustomerID returns the value of the "customer_id" field in the mutation. +func (m *ChargeFlatFeeMutation) CustomerID() (r string, exists bool) { + v := m.customer if v == nil { return } return *v, true } -// OldIntentDeletedAt returns the old "intent_deleted_at" field's value of the ChargeFlatFee entity. +// OldCustomerID returns the old "customer_id" field's value of the ChargeFlatFee entity. // If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldIntentDeletedAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeFlatFeeMutation) OldCustomerID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldIntentDeletedAt is only allowed on UpdateOne operations") + return v, errors.New("OldCustomerID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldIntentDeletedAt requires an ID field in the mutation") + return v, errors.New("OldCustomerID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldIntentDeletedAt: %w", err) + return v, fmt.Errorf("querying old value for OldCustomerID: %w", err) } - return oldValue.IntentDeletedAt, nil -} - -// ClearIntentDeletedAt clears the value of the "intent_deleted_at" field. -func (m *ChargeFlatFeeMutation) ClearIntentDeletedAt() { - m.intent_deleted_at = nil - m.clearedFields[chargeflatfee.FieldIntentDeletedAt] = struct{}{} -} - -// IntentDeletedAtCleared returns if the "intent_deleted_at" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) IntentDeletedAtCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldIntentDeletedAt] - return ok + return oldValue.CustomerID, nil } -// ResetIntentDeletedAt resets all changes to the "intent_deleted_at" field. -func (m *ChargeFlatFeeMutation) ResetIntentDeletedAt() { - m.intent_deleted_at = nil - delete(m.clearedFields, chargeflatfee.FieldIntentDeletedAt) +// ResetCustomerID resets all changes to the "customer_id" field. +func (m *ChargeFlatFeeMutation) ResetCustomerID() { + m.customer = nil } -// SetDiscounts sets the "discounts" field. -func (m *ChargeFlatFeeMutation) SetDiscounts(b *billing.Discounts) { - m.discounts = &b +// SetServicePeriodFrom sets the "service_period_from" field. +func (m *ChargeFlatFeeMutation) SetServicePeriodFrom(t time.Time) { + m.service_period_from = &t } -// Discounts returns the value of the "discounts" field in the mutation. -func (m *ChargeFlatFeeMutation) Discounts() (r *billing.Discounts, exists bool) { - v := m.discounts +// ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. +func (m *ChargeFlatFeeMutation) ServicePeriodFrom() (r time.Time, exists bool) { + v := m.service_period_from if v == nil { return } return *v, true } -// OldDiscounts returns the old "discounts" field's value of the ChargeFlatFee entity. +// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeFlatFee entity. // If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldDiscounts(ctx context.Context) (v *billing.Discounts, err error) { +func (m *ChargeFlatFeeMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDiscounts is only allowed on UpdateOne operations") + return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDiscounts requires an ID field in the mutation") + return v, errors.New("OldServicePeriodFrom requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldDiscounts: %w", err) + return v, fmt.Errorf("querying old value for OldServicePeriodFrom: %w", err) } - return oldValue.Discounts, nil -} - -// ClearDiscounts clears the value of the "discounts" field. -func (m *ChargeFlatFeeMutation) ClearDiscounts() { - m.discounts = nil - m.clearedFields[chargeflatfee.FieldDiscounts] = struct{}{} -} - -// DiscountsCleared returns if the "discounts" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) DiscountsCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldDiscounts] - return ok + return oldValue.ServicePeriodFrom, nil } -// ResetDiscounts resets all changes to the "discounts" field. -func (m *ChargeFlatFeeMutation) ResetDiscounts() { - m.discounts = nil - delete(m.clearedFields, chargeflatfee.FieldDiscounts) +// ResetServicePeriodFrom resets all changes to the "service_period_from" field. +func (m *ChargeFlatFeeMutation) ResetServicePeriodFrom() { + m.service_period_from = nil } -// SetProRating sets the "pro_rating" field. -func (m *ChargeFlatFeeMutation) SetProRating(frmae flatfee.ProRatingModeAdapterEnum) { - m.pro_rating = &frmae +// SetServicePeriodTo sets the "service_period_to" field. +func (m *ChargeFlatFeeMutation) SetServicePeriodTo(t time.Time) { + m.service_period_to = &t } -// ProRating returns the value of the "pro_rating" field in the mutation. -func (m *ChargeFlatFeeMutation) ProRating() (r flatfee.ProRatingModeAdapterEnum, exists bool) { - v := m.pro_rating +// ServicePeriodTo returns the value of the "service_period_to" field in the mutation. +func (m *ChargeFlatFeeMutation) ServicePeriodTo() (r time.Time, exists bool) { + v := m.service_period_to if v == nil { return } return *v, true } -// OldProRating returns the old "pro_rating" field's value of the ChargeFlatFee entity. +// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeFlatFee entity. // If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldProRating(ctx context.Context) (v flatfee.ProRatingModeAdapterEnum, err error) { +func (m *ChargeFlatFeeMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldProRating is only allowed on UpdateOne operations") + return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldProRating requires an ID field in the mutation") + return v, errors.New("OldServicePeriodTo requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldProRating: %w", err) + return v, fmt.Errorf("querying old value for OldServicePeriodTo: %w", err) } - return oldValue.ProRating, nil + return oldValue.ServicePeriodTo, nil } -// ResetProRating resets all changes to the "pro_rating" field. -func (m *ChargeFlatFeeMutation) ResetProRating() { - m.pro_rating = nil +// ResetServicePeriodTo resets all changes to the "service_period_to" field. +func (m *ChargeFlatFeeMutation) ResetServicePeriodTo() { + m.service_period_to = nil } -// SetFeatureKey sets the "feature_key" field. -func (m *ChargeFlatFeeMutation) SetFeatureKey(s string) { - m.feature_key = &s +// SetBillingPeriodFrom sets the "billing_period_from" field. +func (m *ChargeFlatFeeMutation) SetBillingPeriodFrom(t time.Time) { + m.billing_period_from = &t } -// FeatureKey returns the value of the "feature_key" field in the mutation. -func (m *ChargeFlatFeeMutation) FeatureKey() (r string, exists bool) { - v := m.feature_key +// BillingPeriodFrom returns the value of the "billing_period_from" field in the mutation. +func (m *ChargeFlatFeeMutation) BillingPeriodFrom() (r time.Time, exists bool) { + v := m.billing_period_from if v == nil { return } return *v, true } -// OldFeatureKey returns the old "feature_key" field's value of the ChargeFlatFee entity. +// OldBillingPeriodFrom returns the old "billing_period_from" field's value of the ChargeFlatFee entity. // If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldFeatureKey(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeMutation) OldBillingPeriodFrom(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldFeatureKey is only allowed on UpdateOne operations") + return v, errors.New("OldBillingPeriodFrom 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") + return v, errors.New("OldBillingPeriodFrom 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 v, fmt.Errorf("querying old value for OldBillingPeriodFrom: %w", err) } - return oldValue.FeatureKey, nil -} - -// ClearFeatureKey clears the value of the "feature_key" field. -func (m *ChargeFlatFeeMutation) ClearFeatureKey() { - m.feature_key = nil - m.clearedFields[chargeflatfee.FieldFeatureKey] = struct{}{} -} - -// FeatureKeyCleared returns if the "feature_key" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) FeatureKeyCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldFeatureKey] - return ok + return oldValue.BillingPeriodFrom, nil } -// ResetFeatureKey resets all changes to the "feature_key" field. -func (m *ChargeFlatFeeMutation) ResetFeatureKey() { - m.feature_key = nil - delete(m.clearedFields, chargeflatfee.FieldFeatureKey) +// ResetBillingPeriodFrom resets all changes to the "billing_period_from" field. +func (m *ChargeFlatFeeMutation) ResetBillingPeriodFrom() { + m.billing_period_from = nil } -// SetFeatureID sets the "feature_id" field. -func (m *ChargeFlatFeeMutation) SetFeatureID(s string) { - m.feature = &s +// SetBillingPeriodTo sets the "billing_period_to" field. +func (m *ChargeFlatFeeMutation) SetBillingPeriodTo(t time.Time) { + m.billing_period_to = &t } -// FeatureID returns the value of the "feature_id" field in the mutation. -func (m *ChargeFlatFeeMutation) FeatureID() (r string, exists bool) { - v := m.feature +// BillingPeriodTo returns the value of the "billing_period_to" field in the mutation. +func (m *ChargeFlatFeeMutation) BillingPeriodTo() (r time.Time, exists bool) { + v := m.billing_period_to if v == nil { return } return *v, true } -// OldFeatureID returns the old "feature_id" field's value of the ChargeFlatFee entity. +// OldBillingPeriodTo returns the old "billing_period_to" field's value of the ChargeFlatFee entity. // If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldFeatureID(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeMutation) OldBillingPeriodTo(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldFeatureID is only allowed on UpdateOne operations") + return v, errors.New("OldBillingPeriodTo is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldFeatureID requires an ID field in the mutation") + return v, errors.New("OldBillingPeriodTo requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldFeatureID: %w", err) + return v, fmt.Errorf("querying old value for OldBillingPeriodTo: %w", err) } - return oldValue.FeatureID, nil -} - -// ClearFeatureID clears the value of the "feature_id" field. -func (m *ChargeFlatFeeMutation) ClearFeatureID() { - m.feature = nil - m.clearedFields[chargeflatfee.FieldFeatureID] = struct{}{} -} - -// FeatureIDCleared returns if the "feature_id" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) FeatureIDCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldFeatureID] - return ok + return oldValue.BillingPeriodTo, nil } -// ResetFeatureID resets all changes to the "feature_id" field. -func (m *ChargeFlatFeeMutation) ResetFeatureID() { - m.feature = nil - delete(m.clearedFields, chargeflatfee.FieldFeatureID) +// ResetBillingPeriodTo resets all changes to the "billing_period_to" field. +func (m *ChargeFlatFeeMutation) ResetBillingPeriodTo() { + m.billing_period_to = nil } -// SetAmountBeforeProration sets the "amount_before_proration" field. -func (m *ChargeFlatFeeMutation) SetAmountBeforeProration(a alpacadecimal.Decimal) { - m.amount_before_proration = &a +// SetFullServicePeriodFrom sets the "full_service_period_from" field. +func (m *ChargeFlatFeeMutation) SetFullServicePeriodFrom(t time.Time) { + m.full_service_period_from = &t } -// AmountBeforeProration returns the value of the "amount_before_proration" field in the mutation. -func (m *ChargeFlatFeeMutation) AmountBeforeProration() (r alpacadecimal.Decimal, exists bool) { - v := m.amount_before_proration +// FullServicePeriodFrom returns the value of the "full_service_period_from" field in the mutation. +func (m *ChargeFlatFeeMutation) FullServicePeriodFrom() (r time.Time, exists bool) { + v := m.full_service_period_from if v == nil { return } return *v, true } -// OldAmountBeforeProration returns the old "amount_before_proration" field's value of the ChargeFlatFee entity. +// OldFullServicePeriodFrom returns the old "full_service_period_from" field's value of the ChargeFlatFee entity. // If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldAmountBeforeProration(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeMutation) OldFullServicePeriodFrom(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAmountBeforeProration is only allowed on UpdateOne operations") + return v, errors.New("OldFullServicePeriodFrom is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAmountBeforeProration requires an ID field in the mutation") + return v, errors.New("OldFullServicePeriodFrom requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldAmountBeforeProration: %w", err) + return v, fmt.Errorf("querying old value for OldFullServicePeriodFrom: %w", err) } - return oldValue.AmountBeforeProration, nil + return oldValue.FullServicePeriodFrom, nil } -// ResetAmountBeforeProration resets all changes to the "amount_before_proration" field. -func (m *ChargeFlatFeeMutation) ResetAmountBeforeProration() { - m.amount_before_proration = nil +// ResetFullServicePeriodFrom resets all changes to the "full_service_period_from" field. +func (m *ChargeFlatFeeMutation) ResetFullServicePeriodFrom() { + m.full_service_period_from = nil } -// SetAmountAfterProration sets the "amount_after_proration" field. -func (m *ChargeFlatFeeMutation) SetAmountAfterProration(a alpacadecimal.Decimal) { - m.amount_after_proration = &a +// SetFullServicePeriodTo sets the "full_service_period_to" field. +func (m *ChargeFlatFeeMutation) SetFullServicePeriodTo(t time.Time) { + m.full_service_period_to = &t } -// AmountAfterProration returns the value of the "amount_after_proration" field in the mutation. -func (m *ChargeFlatFeeMutation) AmountAfterProration() (r alpacadecimal.Decimal, exists bool) { - v := m.amount_after_proration +// FullServicePeriodTo returns the value of the "full_service_period_to" field in the mutation. +func (m *ChargeFlatFeeMutation) FullServicePeriodTo() (r time.Time, exists bool) { + v := m.full_service_period_to if v == nil { return } return *v, true } -// OldAmountAfterProration returns the old "amount_after_proration" field's value of the ChargeFlatFee entity. +// OldFullServicePeriodTo returns the old "full_service_period_to" field's value of the ChargeFlatFee entity. // If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldAmountAfterProration(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeMutation) OldFullServicePeriodTo(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAmountAfterProration is only allowed on UpdateOne operations") + return v, errors.New("OldFullServicePeriodTo is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAmountAfterProration requires an ID field in the mutation") + return v, errors.New("OldFullServicePeriodTo requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldAmountAfterProration: %w", err) + return v, fmt.Errorf("querying old value for OldFullServicePeriodTo: %w", err) } - return oldValue.AmountAfterProration, nil + return oldValue.FullServicePeriodTo, nil } -// ResetAmountAfterProration resets all changes to the "amount_after_proration" field. -func (m *ChargeFlatFeeMutation) ResetAmountAfterProration() { - m.amount_after_proration = nil +// ResetFullServicePeriodTo resets all changes to the "full_service_period_to" field. +func (m *ChargeFlatFeeMutation) ResetFullServicePeriodTo() { + m.full_service_period_to = nil } -// SetCurrentRealizationRunID sets the "current_realization_run_id" field. -func (m *ChargeFlatFeeMutation) SetCurrentRealizationRunID(s string) { - m.current_run = &s +// SetStatus sets the "status" field. +func (m *ChargeFlatFeeMutation) SetStatus(ms meta.ChargeStatus) { + m.status = &ms } -// CurrentRealizationRunID returns the value of the "current_realization_run_id" field in the mutation. -func (m *ChargeFlatFeeMutation) CurrentRealizationRunID() (r string, exists bool) { - v := m.current_run +// Status returns the value of the "status" field in the mutation. +func (m *ChargeFlatFeeMutation) Status() (r meta.ChargeStatus, exists bool) { + v := m.status if v == nil { return } return *v, true } -// OldCurrentRealizationRunID returns the old "current_realization_run_id" field's value of the ChargeFlatFee entity. +// OldStatus returns the old "status" field's value of the ChargeFlatFee entity. // If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldCurrentRealizationRunID(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeMutation) OldStatus(ctx context.Context) (v meta.ChargeStatus, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCurrentRealizationRunID is only allowed on UpdateOne operations") + return v, errors.New("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCurrentRealizationRunID requires an ID field in the mutation") + return v, errors.New("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldCurrentRealizationRunID: %w", err) + return v, fmt.Errorf("querying old value for OldStatus: %w", err) } - return oldValue.CurrentRealizationRunID, nil -} - -// ClearCurrentRealizationRunID clears the value of the "current_realization_run_id" field. -func (m *ChargeFlatFeeMutation) ClearCurrentRealizationRunID() { - m.current_run = nil - m.clearedFields[chargeflatfee.FieldCurrentRealizationRunID] = struct{}{} -} - -// CurrentRealizationRunIDCleared returns if the "current_realization_run_id" field was cleared in this mutation. -func (m *ChargeFlatFeeMutation) CurrentRealizationRunIDCleared() bool { - _, ok := m.clearedFields[chargeflatfee.FieldCurrentRealizationRunID] - return ok + return oldValue.Status, nil } -// ResetCurrentRealizationRunID resets all changes to the "current_realization_run_id" field. -func (m *ChargeFlatFeeMutation) ResetCurrentRealizationRunID() { - m.current_run = nil - delete(m.clearedFields, chargeflatfee.FieldCurrentRealizationRunID) +// ResetStatus resets all changes to the "status" field. +func (m *ChargeFlatFeeMutation) ResetStatus() { + m.status = nil } -// SetStatusDetailed sets the "status_detailed" field. -func (m *ChargeFlatFeeMutation) SetStatusDetailed(f flatfee.Status) { - m.status_detailed = &f +// SetUniqueReferenceID sets the "unique_reference_id" field. +func (m *ChargeFlatFeeMutation) SetUniqueReferenceID(s string) { + m.unique_reference_id = &s } -// StatusDetailed returns the value of the "status_detailed" field in the mutation. -func (m *ChargeFlatFeeMutation) StatusDetailed() (r flatfee.Status, exists bool) { - v := m.status_detailed +// UniqueReferenceID returns the value of the "unique_reference_id" field in the mutation. +func (m *ChargeFlatFeeMutation) UniqueReferenceID() (r string, exists bool) { + v := m.unique_reference_id if v == nil { return } return *v, true } -// OldStatusDetailed returns the old "status_detailed" field's value of the ChargeFlatFee entity. +// OldUniqueReferenceID returns the old "unique_reference_id" field's value of the ChargeFlatFee entity. // If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldStatusDetailed(ctx context.Context) (v flatfee.Status, err error) { +func (m *ChargeFlatFeeMutation) OldUniqueReferenceID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldStatusDetailed is only allowed on UpdateOne operations") + return v, errors.New("OldUniqueReferenceID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldStatusDetailed requires an ID field in the mutation") + return v, errors.New("OldUniqueReferenceID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldStatusDetailed: %w", err) + return v, fmt.Errorf("querying old value for OldUniqueReferenceID: %w", err) } - return oldValue.StatusDetailed, nil + return oldValue.UniqueReferenceID, nil } -// ResetStatusDetailed resets all changes to the "status_detailed" field. -func (m *ChargeFlatFeeMutation) ResetStatusDetailed() { - m.status_detailed = nil +// ClearUniqueReferenceID clears the value of the "unique_reference_id" field. +func (m *ChargeFlatFeeMutation) ClearUniqueReferenceID() { + m.unique_reference_id = nil + m.clearedFields[chargeflatfee.FieldUniqueReferenceID] = struct{}{} } -// AddRunIDs adds the "runs" edge to the ChargeFlatFeeRun entity by ids. -func (m *ChargeFlatFeeMutation) AddRunIDs(ids ...string) { - if m.runs == nil { - m.runs = make(map[string]struct{}) - } - for i := range ids { - m.runs[ids[i]] = struct{}{} - } +// UniqueReferenceIDCleared returns if the "unique_reference_id" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) UniqueReferenceIDCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldUniqueReferenceID] + return ok } -// ClearRuns clears the "runs" edge to the ChargeFlatFeeRun entity. -func (m *ChargeFlatFeeMutation) ClearRuns() { - m.clearedruns = true +// ResetUniqueReferenceID resets all changes to the "unique_reference_id" field. +func (m *ChargeFlatFeeMutation) ResetUniqueReferenceID() { + m.unique_reference_id = nil + delete(m.clearedFields, chargeflatfee.FieldUniqueReferenceID) } -// RunsCleared reports if the "runs" edge to the ChargeFlatFeeRun entity was cleared. -func (m *ChargeFlatFeeMutation) RunsCleared() bool { - return m.clearedruns +// SetFiatCurrencyCode sets the "fiat_currency_code" field. +func (m *ChargeFlatFeeMutation) SetFiatCurrencyCode(c currencyx.Code) { + m.fiat_currency_code = &c } -// RemoveRunIDs removes the "runs" edge to the ChargeFlatFeeRun entity by IDs. -func (m *ChargeFlatFeeMutation) RemoveRunIDs(ids ...string) { - if m.removedruns == nil { - m.removedruns = make(map[string]struct{}) - } - for i := range ids { - delete(m.runs, ids[i]) - m.removedruns[ids[i]] = struct{}{} +// FiatCurrencyCode returns the value of the "fiat_currency_code" field in the mutation. +func (m *ChargeFlatFeeMutation) FiatCurrencyCode() (r currencyx.Code, exists bool) { + v := m.fiat_currency_code + if v == nil { + return } + return *v, true } -// RemovedRuns returns the removed IDs of the "runs" edge to the ChargeFlatFeeRun entity. -func (m *ChargeFlatFeeMutation) RemovedRunsIDs() (ids []string) { - for id := range m.removedruns { - ids = append(ids, id) +// OldFiatCurrencyCode returns the old "fiat_currency_code" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldFiatCurrencyCode(ctx context.Context) (v *currencyx.Code, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFiatCurrencyCode is only allowed on UpdateOne operations") } - return -} - -// RunsIDs returns the "runs" edge IDs in the mutation. -func (m *ChargeFlatFeeMutation) RunsIDs() (ids []string) { - for id := range m.runs { - ids = append(ids, id) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFiatCurrencyCode requires an ID field in the mutation") } - return + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFiatCurrencyCode: %w", err) + } + return oldValue.FiatCurrencyCode, nil } -// ResetRuns resets all changes to the "runs" edge. -func (m *ChargeFlatFeeMutation) ResetRuns() { - m.runs = nil - m.clearedruns = false - m.removedruns = nil +// ClearFiatCurrencyCode clears the value of the "fiat_currency_code" field. +func (m *ChargeFlatFeeMutation) ClearFiatCurrencyCode() { + m.fiat_currency_code = nil + m.clearedFields[chargeflatfee.FieldFiatCurrencyCode] = struct{}{} } -// SetCurrentRunID sets the "current_run" edge to the ChargeFlatFeeRun entity by id. -func (m *ChargeFlatFeeMutation) SetCurrentRunID(id string) { - m.current_run = &id +// FiatCurrencyCodeCleared returns if the "fiat_currency_code" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) FiatCurrencyCodeCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldFiatCurrencyCode] + return ok } -// ClearCurrentRun clears the "current_run" edge to the ChargeFlatFeeRun entity. -func (m *ChargeFlatFeeMutation) ClearCurrentRun() { - m.clearedcurrent_run = true - m.clearedFields[chargeflatfee.FieldCurrentRealizationRunID] = struct{}{} +// ResetFiatCurrencyCode resets all changes to the "fiat_currency_code" field. +func (m *ChargeFlatFeeMutation) ResetFiatCurrencyCode() { + m.fiat_currency_code = nil + delete(m.clearedFields, chargeflatfee.FieldFiatCurrencyCode) } -// CurrentRunCleared reports if the "current_run" edge to the ChargeFlatFeeRun entity was cleared. -func (m *ChargeFlatFeeMutation) CurrentRunCleared() bool { - return m.CurrentRealizationRunIDCleared() || m.clearedcurrent_run +// SetCustomCurrencyID sets the "custom_currency_id" field. +func (m *ChargeFlatFeeMutation) SetCustomCurrencyID(s string) { + m.custom_currency = &s } -// CurrentRunID returns the "current_run" edge ID in the mutation. -func (m *ChargeFlatFeeMutation) CurrentRunID() (id string, exists bool) { - if m.current_run != nil { - return *m.current_run, true +// CustomCurrencyID returns the value of the "custom_currency_id" field in the mutation. +func (m *ChargeFlatFeeMutation) CustomCurrencyID() (r string, exists bool) { + v := m.custom_currency + if v == nil { + return } - return + return *v, true } -// CurrentRunIDs returns the "current_run" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// CurrentRunID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeMutation) CurrentRunIDs() (ids []string) { - if id := m.current_run; id != nil { - ids = append(ids, *id) +// OldCustomCurrencyID returns the old "custom_currency_id" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldCustomCurrencyID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCustomCurrencyID is only allowed on UpdateOne operations") } - return + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCustomCurrencyID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCustomCurrencyID: %w", err) + } + return oldValue.CustomCurrencyID, nil } -// ResetCurrentRun resets all changes to the "current_run" edge. -func (m *ChargeFlatFeeMutation) ResetCurrentRun() { - m.current_run = nil - m.clearedcurrent_run = false +// ClearCustomCurrencyID clears the value of the "custom_currency_id" field. +func (m *ChargeFlatFeeMutation) ClearCustomCurrencyID() { + m.custom_currency = nil + m.clearedFields[chargeflatfee.FieldCustomCurrencyID] = struct{}{} } -// SetChargeID sets the "charge" edge to the Charge entity by id. -func (m *ChargeFlatFeeMutation) SetChargeID(id string) { - m.charge = &id +// CustomCurrencyIDCleared returns if the "custom_currency_id" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) CustomCurrencyIDCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldCustomCurrencyID] + return ok } -// ClearCharge clears the "charge" edge to the Charge entity. -func (m *ChargeFlatFeeMutation) ClearCharge() { - m.clearedcharge = true +// ResetCustomCurrencyID resets all changes to the "custom_currency_id" field. +func (m *ChargeFlatFeeMutation) ResetCustomCurrencyID() { + m.custom_currency = nil + delete(m.clearedFields, chargeflatfee.FieldCustomCurrencyID) } -// ChargeCleared reports if the "charge" edge to the Charge entity was cleared. -func (m *ChargeFlatFeeMutation) ChargeCleared() bool { - return m.clearedcharge +// SetManagedBy sets the "managed_by" field. +func (m *ChargeFlatFeeMutation) SetManagedBy(blmb billing.InvoiceLineManagedBy) { + m.managed_by = &blmb } -// ChargeID returns the "charge" edge ID in the mutation. -func (m *ChargeFlatFeeMutation) ChargeID() (id string, exists bool) { - if m.charge != nil { - return *m.charge, true +// ManagedBy returns the value of the "managed_by" field in the mutation. +func (m *ChargeFlatFeeMutation) ManagedBy() (r billing.InvoiceLineManagedBy, exists bool) { + v := m.managed_by + if v == nil { + return } - return + return *v, true } -// 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 *ChargeFlatFeeMutation) ChargeIDs() (ids []string) { - if id := m.charge; id != nil { - ids = append(ids, *id) +// OldManagedBy returns the old "managed_by" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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") } - return -} - -// ResetCharge resets all changes to the "charge" edge. -func (m *ChargeFlatFeeMutation) ResetCharge() { - m.charge = nil - m.clearedcharge = false + 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 } -// SetIntentOverrideID sets the "intent_override" edge to the ChargeFlatFeeOverride entity by id. -func (m *ChargeFlatFeeMutation) SetIntentOverrideID(id string) { - m.intent_override = &id +// ResetManagedBy resets all changes to the "managed_by" field. +func (m *ChargeFlatFeeMutation) ResetManagedBy() { + m.managed_by = nil } -// ClearIntentOverride clears the "intent_override" edge to the ChargeFlatFeeOverride entity. -func (m *ChargeFlatFeeMutation) ClearIntentOverride() { - m.clearedintent_override = true +// SetSubscriptionID sets the "subscription_id" field. +func (m *ChargeFlatFeeMutation) SetSubscriptionID(s string) { + m.subscription = &s } -// IntentOverrideCleared reports if the "intent_override" edge to the ChargeFlatFeeOverride entity was cleared. -func (m *ChargeFlatFeeMutation) IntentOverrideCleared() bool { - return m.clearedintent_override +// SubscriptionID returns the value of the "subscription_id" field in the mutation. +func (m *ChargeFlatFeeMutation) SubscriptionID() (r string, exists bool) { + v := m.subscription + if v == nil { + return + } + return *v, true } -// IntentOverrideID returns the "intent_override" edge ID in the mutation. -func (m *ChargeFlatFeeMutation) IntentOverrideID() (id string, exists bool) { - if m.intent_override != nil { - return *m.intent_override, true +// OldSubscriptionID returns the old "subscription_id" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldSubscriptionID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSubscriptionID is only allowed on UpdateOne operations") } - return + 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 } -// IntentOverrideIDs returns the "intent_override" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// IntentOverrideID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeMutation) IntentOverrideIDs() (ids []string) { - if id := m.intent_override; id != nil { - ids = append(ids, *id) - } - return +// ClearSubscriptionID clears the value of the "subscription_id" field. +func (m *ChargeFlatFeeMutation) ClearSubscriptionID() { + m.subscription = nil + m.clearedFields[chargeflatfee.FieldSubscriptionID] = struct{}{} } -// ResetIntentOverride resets all changes to the "intent_override" edge. -func (m *ChargeFlatFeeMutation) ResetIntentOverride() { - m.intent_override = nil - m.clearedintent_override = false +// SubscriptionIDCleared returns if the "subscription_id" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) SubscriptionIDCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldSubscriptionID] + return ok } -// ClearSubscription clears the "subscription" edge to the Subscription entity. -func (m *ChargeFlatFeeMutation) ClearSubscription() { - m.clearedsubscription = true - m.clearedFields[chargeflatfee.FieldSubscriptionID] = struct{}{} +// ResetSubscriptionID resets all changes to the "subscription_id" field. +func (m *ChargeFlatFeeMutation) ResetSubscriptionID() { + m.subscription = nil + delete(m.clearedFields, chargeflatfee.FieldSubscriptionID) } -// SubscriptionCleared reports if the "subscription" edge to the Subscription entity was cleared. -func (m *ChargeFlatFeeMutation) SubscriptionCleared() bool { - return m.SubscriptionIDCleared() || m.clearedsubscription +// SetSubscriptionPhaseID sets the "subscription_phase_id" field. +func (m *ChargeFlatFeeMutation) SetSubscriptionPhaseID(s string) { + m.subscription_phase = &s } -// 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 *ChargeFlatFeeMutation) SubscriptionIDs() (ids []string) { - if id := m.subscription; id != nil { - ids = append(ids, *id) +// SubscriptionPhaseID returns the value of the "subscription_phase_id" field in the mutation. +func (m *ChargeFlatFeeMutation) SubscriptionPhaseID() (r string, exists bool) { + v := m.subscription_phase + if v == nil { + return } - return + return *v, true } -// ResetSubscription resets all changes to the "subscription" edge. -func (m *ChargeFlatFeeMutation) ResetSubscription() { - m.subscription = nil - m.clearedsubscription = false +// OldSubscriptionPhaseID returns the old "subscription_phase_id" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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 } -// ClearSubscriptionPhase clears the "subscription_phase" edge to the SubscriptionPhase entity. -func (m *ChargeFlatFeeMutation) ClearSubscriptionPhase() { - m.clearedsubscription_phase = true +// ClearSubscriptionPhaseID clears the value of the "subscription_phase_id" field. +func (m *ChargeFlatFeeMutation) ClearSubscriptionPhaseID() { + m.subscription_phase = nil m.clearedFields[chargeflatfee.FieldSubscriptionPhaseID] = struct{}{} } -// SubscriptionPhaseCleared reports if the "subscription_phase" edge to the SubscriptionPhase entity was cleared. -func (m *ChargeFlatFeeMutation) 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 *ChargeFlatFeeMutation) SubscriptionPhaseIDs() (ids []string) { - if id := m.subscription_phase; id != nil { - ids = append(ids, *id) - } - return +// SubscriptionPhaseIDCleared returns if the "subscription_phase_id" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) SubscriptionPhaseIDCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldSubscriptionPhaseID] + return ok } -// ResetSubscriptionPhase resets all changes to the "subscription_phase" edge. -func (m *ChargeFlatFeeMutation) ResetSubscriptionPhase() { +// ResetSubscriptionPhaseID resets all changes to the "subscription_phase_id" field. +func (m *ChargeFlatFeeMutation) ResetSubscriptionPhaseID() { m.subscription_phase = nil - m.clearedsubscription_phase = false + delete(m.clearedFields, chargeflatfee.FieldSubscriptionPhaseID) } -// ClearSubscriptionItem clears the "subscription_item" edge to the SubscriptionItem entity. -func (m *ChargeFlatFeeMutation) ClearSubscriptionItem() { - m.clearedsubscription_item = true - m.clearedFields[chargeflatfee.FieldSubscriptionItemID] = struct{}{} +// SetSubscriptionItemID sets the "subscription_item_id" field. +func (m *ChargeFlatFeeMutation) SetSubscriptionItemID(s string) { + m.subscription_item = &s } -// SubscriptionItemCleared reports if the "subscription_item" edge to the SubscriptionItem entity was cleared. -func (m *ChargeFlatFeeMutation) SubscriptionItemCleared() bool { - return m.SubscriptionItemIDCleared() || m.clearedsubscription_item +// SubscriptionItemID returns the value of the "subscription_item_id" field in the mutation. +func (m *ChargeFlatFeeMutation) SubscriptionItemID() (r string, exists bool) { + v := m.subscription_item + if v == nil { + return + } + return *v, true } -// 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 *ChargeFlatFeeMutation) SubscriptionItemIDs() (ids []string) { - if id := m.subscription_item; id != nil { - ids = append(ids, *id) +// OldSubscriptionItemID returns the old "subscription_item_id" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldSubscriptionItemID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSubscriptionItemID is only allowed on UpdateOne operations") } - return + 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 } -// ResetSubscriptionItem resets all changes to the "subscription_item" edge. -func (m *ChargeFlatFeeMutation) ResetSubscriptionItem() { +// ClearSubscriptionItemID clears the value of the "subscription_item_id" field. +func (m *ChargeFlatFeeMutation) ClearSubscriptionItemID() { m.subscription_item = nil - m.clearedsubscription_item = false + m.clearedFields[chargeflatfee.FieldSubscriptionItemID] = struct{}{} } -// ClearCustomer clears the "customer" edge to the Customer entity. -func (m *ChargeFlatFeeMutation) ClearCustomer() { - m.clearedcustomer = true - m.clearedFields[chargeflatfee.FieldCustomerID] = struct{}{} +// SubscriptionItemIDCleared returns if the "subscription_item_id" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) SubscriptionItemIDCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldSubscriptionItemID] + return ok } -// CustomerCleared reports if the "customer" edge to the Customer entity was cleared. -func (m *ChargeFlatFeeMutation) CustomerCleared() bool { - return m.clearedcustomer +// ResetSubscriptionItemID resets all changes to the "subscription_item_id" field. +func (m *ChargeFlatFeeMutation) ResetSubscriptionItemID() { + m.subscription_item = nil + delete(m.clearedFields, chargeflatfee.FieldSubscriptionItemID) } -// CustomerIDs returns the "customer" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// CustomerID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeMutation) CustomerIDs() (ids []string) { - if id := m.customer; id != nil { - ids = append(ids, *id) - } - return +// SetAdvanceAfter sets the "advance_after" field. +func (m *ChargeFlatFeeMutation) SetAdvanceAfter(t time.Time) { + m.advance_after = &t } -// ResetCustomer resets all changes to the "customer" edge. -func (m *ChargeFlatFeeMutation) ResetCustomer() { - m.customer = nil - m.clearedcustomer = false +// AdvanceAfter returns the value of the "advance_after" field in the mutation. +func (m *ChargeFlatFeeMutation) AdvanceAfter() (r time.Time, exists bool) { + v := m.advance_after + if v == nil { + return + } + return *v, true } -// ClearFeature clears the "feature" edge to the Feature entity. -func (m *ChargeFlatFeeMutation) ClearFeature() { - m.clearedfeature = true - m.clearedFields[chargeflatfee.FieldFeatureID] = struct{}{} +// OldAdvanceAfter returns the old "advance_after" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldAdvanceAfter(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAdvanceAfter is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAdvanceAfter requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAdvanceAfter: %w", err) + } + return oldValue.AdvanceAfter, nil } -// FeatureCleared reports if the "feature" edge to the Feature entity was cleared. -func (m *ChargeFlatFeeMutation) FeatureCleared() bool { - return m.FeatureIDCleared() || m.clearedfeature +// ClearAdvanceAfter clears the value of the "advance_after" field. +func (m *ChargeFlatFeeMutation) ClearAdvanceAfter() { + m.advance_after = nil + m.clearedFields[chargeflatfee.FieldAdvanceAfter] = struct{}{} } -// FeatureIDs returns the "feature" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// FeatureID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeMutation) FeatureIDs() (ids []string) { - if id := m.feature; id != nil { - ids = append(ids, *id) - } - return +// AdvanceAfterCleared returns if the "advance_after" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) AdvanceAfterCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldAdvanceAfter] + return ok } -// ResetFeature resets all changes to the "feature" edge. -func (m *ChargeFlatFeeMutation) ResetFeature() { - m.feature = nil - m.clearedfeature = false +// ResetAdvanceAfter resets all changes to the "advance_after" field. +func (m *ChargeFlatFeeMutation) ResetAdvanceAfter() { + m.advance_after = nil + delete(m.clearedFields, chargeflatfee.FieldAdvanceAfter) } -// ClearTaxCode clears the "tax_code" edge to the TaxCode entity. -func (m *ChargeFlatFeeMutation) ClearTaxCode() { - m.clearedtax_code = true - m.clearedFields[chargeflatfee.FieldTaxCodeID] = struct{}{} +// SetTaxCodeID sets the "tax_code_id" field. +func (m *ChargeFlatFeeMutation) SetTaxCodeID(s string) { + m.tax_code = &s } -// TaxCodeCleared reports if the "tax_code" edge to the TaxCode entity was cleared. -func (m *ChargeFlatFeeMutation) TaxCodeCleared() bool { - return m.clearedtax_code +// TaxCodeID returns the value of the "tax_code_id" field in the mutation. +func (m *ChargeFlatFeeMutation) TaxCodeID() (r string, exists bool) { + v := m.tax_code + if v == nil { + return + } + return *v, true } -// 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 *ChargeFlatFeeMutation) TaxCodeIDs() (ids []string) { - if id := m.tax_code; id != nil { - ids = append(ids, *id) +// OldTaxCodeID returns the old "tax_code_id" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldTaxCodeID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTaxCodeID is only allowed on UpdateOne operations") } - return + 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 } -// ResetTaxCode resets all changes to the "tax_code" edge. -func (m *ChargeFlatFeeMutation) ResetTaxCode() { +// ResetTaxCodeID resets all changes to the "tax_code_id" field. +func (m *ChargeFlatFeeMutation) ResetTaxCodeID() { m.tax_code = nil - m.clearedtax_code = false } -// ClearCustomCurrency clears the "custom_currency" edge to the CustomCurrency entity. -func (m *ChargeFlatFeeMutation) ClearCustomCurrency() { - m.clearedcustom_currency = true - m.clearedFields[chargeflatfee.FieldCustomCurrencyID] = struct{}{} +// SetTaxBehavior sets the "tax_behavior" field. +func (m *ChargeFlatFeeMutation) SetTaxBehavior(pb productcatalog.TaxBehavior) { + m.tax_behavior = &pb } -// CustomCurrencyCleared reports if the "custom_currency" edge to the CustomCurrency entity was cleared. -func (m *ChargeFlatFeeMutation) CustomCurrencyCleared() bool { - return m.CustomCurrencyIDCleared() || m.clearedcustom_currency +// TaxBehavior returns the value of the "tax_behavior" field in the mutation. +func (m *ChargeFlatFeeMutation) TaxBehavior() (r productcatalog.TaxBehavior, exists bool) { + v := m.tax_behavior + if v == nil { + return + } + return *v, true } -// CustomCurrencyIDs returns the "custom_currency" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// CustomCurrencyID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeMutation) CustomCurrencyIDs() (ids []string) { - if id := m.custom_currency; id != nil { - ids = append(ids, *id) +// OldTaxBehavior returns the old "tax_behavior" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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") } - return + 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 } -// ResetCustomCurrency resets all changes to the "custom_currency" edge. -func (m *ChargeFlatFeeMutation) ResetCustomCurrency() { - m.custom_currency = nil - m.clearedcustom_currency = false +// ClearTaxBehavior clears the value of the "tax_behavior" field. +func (m *ChargeFlatFeeMutation) ClearTaxBehavior() { + m.tax_behavior = nil + m.clearedFields[chargeflatfee.FieldTaxBehavior] = struct{}{} } -// Where appends a list predicates to the ChargeFlatFeeMutation builder. -func (m *ChargeFlatFeeMutation) Where(ps ...predicate.ChargeFlatFee) { - m.predicates = append(m.predicates, ps...) +// TaxBehaviorCleared returns if the "tax_behavior" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) TaxBehaviorCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldTaxBehavior] + return ok } -// WhereP appends storage-level predicates to the ChargeFlatFeeMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *ChargeFlatFeeMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.ChargeFlatFee, len(ps)) - for i := range ps { - p[i] = ps[i] +// ResetTaxBehavior resets all changes to the "tax_behavior" field. +func (m *ChargeFlatFeeMutation) ResetTaxBehavior() { + m.tax_behavior = nil + delete(m.clearedFields, chargeflatfee.FieldTaxBehavior) +} + +// SetAnnotations sets the "annotations" field. +func (m *ChargeFlatFeeMutation) SetAnnotations(value models.Annotations) { + m.annotations = &value +} + +// Annotations returns the value of the "annotations" field in the mutation. +func (m *ChargeFlatFeeMutation) Annotations() (r models.Annotations, exists bool) { + v := m.annotations + if v == nil { + return } - m.Where(p...) + return *v, true } -// Op returns the operation name. -func (m *ChargeFlatFeeMutation) Op() Op { - return m.op +// OldAnnotations returns the old "annotations" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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 } -// SetOp allows setting the mutation operation. -func (m *ChargeFlatFeeMutation) SetOp(op Op) { - m.op = op +// ClearAnnotations clears the value of the "annotations" field. +func (m *ChargeFlatFeeMutation) ClearAnnotations() { + m.annotations = nil + m.clearedFields[chargeflatfee.FieldAnnotations] = struct{}{} } -// Type returns the node type of this mutation (ChargeFlatFee). -func (m *ChargeFlatFeeMutation) Type() string { - return m.typ +// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) AnnotationsCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldAnnotations] + return ok } -// 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 *ChargeFlatFeeMutation) Fields() []string { - fields := make([]string, 0, 38) - if m.customer != nil { - fields = append(fields, chargeflatfee.FieldCustomerID) - } - if m.service_period_from != nil { - fields = append(fields, chargeflatfee.FieldServicePeriodFrom) - } - if m.service_period_to != nil { - fields = append(fields, chargeflatfee.FieldServicePeriodTo) +// ResetAnnotations resets all changes to the "annotations" field. +func (m *ChargeFlatFeeMutation) ResetAnnotations() { + m.annotations = nil + delete(m.clearedFields, chargeflatfee.FieldAnnotations) +} + +// SetNamespace sets the "namespace" field. +func (m *ChargeFlatFeeMutation) SetNamespace(s string) { + m.namespace = &s +} + +// Namespace returns the value of the "namespace" field in the mutation. +func (m *ChargeFlatFeeMutation) Namespace() (r string, exists bool) { + v := m.namespace + if v == nil { + return } - if m.billing_period_from != nil { - fields = append(fields, chargeflatfee.FieldBillingPeriodFrom) + return *v, true +} + +// OldNamespace returns the old "namespace" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.billing_period_to != nil { - fields = append(fields, chargeflatfee.FieldBillingPeriodTo) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNamespace requires an ID field in the mutation") } - if m.full_service_period_from != nil { - fields = append(fields, chargeflatfee.FieldFullServicePeriodFrom) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNamespace: %w", err) } - if m.full_service_period_to != nil { - fields = append(fields, chargeflatfee.FieldFullServicePeriodTo) + return oldValue.Namespace, nil +} + +// ResetNamespace resets all changes to the "namespace" field. +func (m *ChargeFlatFeeMutation) ResetNamespace() { + m.namespace = nil +} + +// SetMetadata sets the "metadata" field. +func (m *ChargeFlatFeeMutation) SetMetadata(value map[string]string) { + m.metadata = &value +} + +// Metadata returns the value of the "metadata" field in the mutation. +func (m *ChargeFlatFeeMutation) Metadata() (r map[string]string, exists bool) { + v := m.metadata + if v == nil { + return } - if m.status != nil { - fields = append(fields, chargeflatfee.FieldStatus) + return *v, true +} + +// OldMetadata returns the old "metadata" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.unique_reference_id != nil { - fields = append(fields, chargeflatfee.FieldUniqueReferenceID) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMetadata requires an ID field in the mutation") } - if m.fiat_currency_code != nil { - fields = append(fields, chargeflatfee.FieldFiatCurrencyCode) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMetadata: %w", err) } - if m.custom_currency != nil { - fields = append(fields, chargeflatfee.FieldCustomCurrencyID) + return oldValue.Metadata, nil +} + +// ClearMetadata clears the value of the "metadata" field. +func (m *ChargeFlatFeeMutation) ClearMetadata() { + m.metadata = nil + m.clearedFields[chargeflatfee.FieldMetadata] = struct{}{} +} + +// MetadataCleared returns if the "metadata" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) MetadataCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldMetadata] + return ok +} + +// ResetMetadata resets all changes to the "metadata" field. +func (m *ChargeFlatFeeMutation) ResetMetadata() { + m.metadata = nil + delete(m.clearedFields, chargeflatfee.FieldMetadata) +} + +// SetCreatedAt sets the "created_at" field. +func (m *ChargeFlatFeeMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ChargeFlatFeeMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return } - if m.managed_by != nil { - fields = append(fields, chargeflatfee.FieldManagedBy) + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.subscription != nil { - fields = append(fields, chargeflatfee.FieldSubscriptionID) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") } - if m.subscription_phase != nil { - fields = append(fields, chargeflatfee.FieldSubscriptionPhaseID) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } - if m.subscription_item != nil { - fields = append(fields, chargeflatfee.FieldSubscriptionItemID) + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ChargeFlatFeeMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *ChargeFlatFeeMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ChargeFlatFeeMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return } - if m.advance_after != nil { - fields = append(fields, chargeflatfee.FieldAdvanceAfter) + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.tax_code != nil { - fields = append(fields, chargeflatfee.FieldTaxCodeID) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } - if m.tax_behavior != nil { - fields = append(fields, chargeflatfee.FieldTaxBehavior) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } - if m.annotations != nil { - fields = append(fields, chargeflatfee.FieldAnnotations) + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *ChargeFlatFeeMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// SetDeletedAt sets the "deleted_at" field. +func (m *ChargeFlatFeeMutation) SetDeletedAt(t time.Time) { + m.deleted_at = &t +} + +// DeletedAt returns the value of the "deleted_at" field in the mutation. +func (m *ChargeFlatFeeMutation) DeletedAt() (r time.Time, exists bool) { + v := m.deleted_at + if v == nil { + return } - if m.namespace != nil { - fields = append(fields, chargeflatfee.FieldNamespace) + return *v, true +} + +// OldDeletedAt returns the old "deleted_at" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.metadata != nil { - fields = append(fields, chargeflatfee.FieldMetadata) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDeletedAt requires an ID field in the mutation") } - if m.created_at != nil { - fields = append(fields, chargeflatfee.FieldCreatedAt) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) } - if m.updated_at != nil { - fields = append(fields, chargeflatfee.FieldUpdatedAt) + return oldValue.DeletedAt, nil +} + +// ClearDeletedAt clears the value of the "deleted_at" field. +func (m *ChargeFlatFeeMutation) ClearDeletedAt() { + m.deleted_at = nil + m.clearedFields[chargeflatfee.FieldDeletedAt] = struct{}{} +} + +// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldDeletedAt] + return ok +} + +// ResetDeletedAt resets all changes to the "deleted_at" field. +func (m *ChargeFlatFeeMutation) ResetDeletedAt() { + m.deleted_at = nil + delete(m.clearedFields, chargeflatfee.FieldDeletedAt) +} + +// SetName sets the "name" field. +func (m *ChargeFlatFeeMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *ChargeFlatFeeMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return } - if m.deleted_at != nil { - fields = append(fields, chargeflatfee.FieldDeletedAt) + return *v, true +} + +// OldName returns the old "name" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.name != nil { - fields = append(fields, chargeflatfee.FieldName) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") } - if m.description != nil { - fields = append(fields, chargeflatfee.FieldDescription) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) } - if m.payment_term != nil { - fields = append(fields, chargeflatfee.FieldPaymentTerm) + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *ChargeFlatFeeMutation) ResetName() { + m.name = nil +} + +// SetDescription sets the "description" field. +func (m *ChargeFlatFeeMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *ChargeFlatFeeMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return } - if m.invoice_at != nil { - fields = append(fields, chargeflatfee.FieldInvoiceAt) + return *v, true +} + +// OldDescription returns the old "description" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.settlement_mode != nil { - fields = append(fields, chargeflatfee.FieldSettlementMode) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDescription requires an ID field in the mutation") } - if m.intent_deleted_at != nil { - fields = append(fields, chargeflatfee.FieldIntentDeletedAt) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) } - if m.discounts != nil { - fields = append(fields, chargeflatfee.FieldDiscounts) + return oldValue.Description, nil +} + +// ClearDescription clears the value of the "description" field. +func (m *ChargeFlatFeeMutation) ClearDescription() { + m.description = nil + m.clearedFields[chargeflatfee.FieldDescription] = struct{}{} +} + +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldDescription] + return ok +} + +// ResetDescription resets all changes to the "description" field. +func (m *ChargeFlatFeeMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, chargeflatfee.FieldDescription) +} + +// SetPaymentTerm sets the "payment_term" field. +func (m *ChargeFlatFeeMutation) SetPaymentTerm(ptt productcatalog.PaymentTermType) { + m.payment_term = &ptt +} + +// PaymentTerm returns the value of the "payment_term" field in the mutation. +func (m *ChargeFlatFeeMutation) PaymentTerm() (r productcatalog.PaymentTermType, exists bool) { + v := m.payment_term + if v == nil { + return } - if m.pro_rating != nil { - fields = append(fields, chargeflatfee.FieldProRating) + return *v, true +} + +// OldPaymentTerm returns the old "payment_term" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldPaymentTerm(ctx context.Context) (v productcatalog.PaymentTermType, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPaymentTerm is only allowed on UpdateOne operations") } - if m.feature_key != nil { - fields = append(fields, chargeflatfee.FieldFeatureKey) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPaymentTerm requires an ID field in the mutation") } - if m.feature != nil { - fields = append(fields, chargeflatfee.FieldFeatureID) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPaymentTerm: %w", err) } - if m.amount_before_proration != nil { - fields = append(fields, chargeflatfee.FieldAmountBeforeProration) + return oldValue.PaymentTerm, nil +} + +// ResetPaymentTerm resets all changes to the "payment_term" field. +func (m *ChargeFlatFeeMutation) ResetPaymentTerm() { + m.payment_term = nil +} + +// SetInvoiceAt sets the "invoice_at" field. +func (m *ChargeFlatFeeMutation) SetInvoiceAt(t time.Time) { + m.invoice_at = &t +} + +// InvoiceAt returns the value of the "invoice_at" field in the mutation. +func (m *ChargeFlatFeeMutation) InvoiceAt() (r time.Time, exists bool) { + v := m.invoice_at + if v == nil { + return } - if m.amount_after_proration != nil { - fields = append(fields, chargeflatfee.FieldAmountAfterProration) + return *v, true +} + +// OldInvoiceAt returns the old "invoice_at" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.current_run != nil { - fields = append(fields, chargeflatfee.FieldCurrentRealizationRunID) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldInvoiceAt requires an ID field in the mutation") } - if m.status_detailed != nil { - fields = append(fields, chargeflatfee.FieldStatusDetailed) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldInvoiceAt: %w", err) } - return fields + return oldValue.InvoiceAt, nil } -// 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 *ChargeFlatFeeMutation) Field(name string) (ent.Value, bool) { - switch name { - case chargeflatfee.FieldCustomerID: - return m.CustomerID() - case chargeflatfee.FieldServicePeriodFrom: - return m.ServicePeriodFrom() - case chargeflatfee.FieldServicePeriodTo: - return m.ServicePeriodTo() - case chargeflatfee.FieldBillingPeriodFrom: - return m.BillingPeriodFrom() - case chargeflatfee.FieldBillingPeriodTo: - return m.BillingPeriodTo() - case chargeflatfee.FieldFullServicePeriodFrom: - return m.FullServicePeriodFrom() - case chargeflatfee.FieldFullServicePeriodTo: - return m.FullServicePeriodTo() - case chargeflatfee.FieldStatus: - return m.Status() - case chargeflatfee.FieldUniqueReferenceID: - return m.UniqueReferenceID() - case chargeflatfee.FieldFiatCurrencyCode: - return m.FiatCurrencyCode() - case chargeflatfee.FieldCustomCurrencyID: - return m.CustomCurrencyID() - case chargeflatfee.FieldManagedBy: - return m.ManagedBy() - case chargeflatfee.FieldSubscriptionID: - return m.SubscriptionID() - case chargeflatfee.FieldSubscriptionPhaseID: - return m.SubscriptionPhaseID() - case chargeflatfee.FieldSubscriptionItemID: - return m.SubscriptionItemID() - case chargeflatfee.FieldAdvanceAfter: - return m.AdvanceAfter() - case chargeflatfee.FieldTaxCodeID: - return m.TaxCodeID() - case chargeflatfee.FieldTaxBehavior: - return m.TaxBehavior() - case chargeflatfee.FieldAnnotations: - return m.Annotations() - case chargeflatfee.FieldNamespace: - return m.Namespace() - case chargeflatfee.FieldMetadata: - return m.Metadata() - case chargeflatfee.FieldCreatedAt: - return m.CreatedAt() - case chargeflatfee.FieldUpdatedAt: - return m.UpdatedAt() - case chargeflatfee.FieldDeletedAt: - return m.DeletedAt() - case chargeflatfee.FieldName: - return m.Name() - case chargeflatfee.FieldDescription: - return m.Description() - case chargeflatfee.FieldPaymentTerm: - return m.PaymentTerm() - case chargeflatfee.FieldInvoiceAt: - return m.InvoiceAt() - case chargeflatfee.FieldSettlementMode: - return m.SettlementMode() - case chargeflatfee.FieldIntentDeletedAt: - return m.IntentDeletedAt() - case chargeflatfee.FieldDiscounts: - return m.Discounts() - case chargeflatfee.FieldProRating: - return m.ProRating() - case chargeflatfee.FieldFeatureKey: - return m.FeatureKey() - case chargeflatfee.FieldFeatureID: - return m.FeatureID() - case chargeflatfee.FieldAmountBeforeProration: - return m.AmountBeforeProration() - case chargeflatfee.FieldAmountAfterProration: - return m.AmountAfterProration() - case chargeflatfee.FieldCurrentRealizationRunID: - return m.CurrentRealizationRunID() - case chargeflatfee.FieldStatusDetailed: - return m.StatusDetailed() - } - return nil, false +// ResetInvoiceAt resets all changes to the "invoice_at" field. +func (m *ChargeFlatFeeMutation) ResetInvoiceAt() { + m.invoice_at = nil } -// 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 *ChargeFlatFeeMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case chargeflatfee.FieldCustomerID: - return m.OldCustomerID(ctx) - case chargeflatfee.FieldServicePeriodFrom: - return m.OldServicePeriodFrom(ctx) - case chargeflatfee.FieldServicePeriodTo: - return m.OldServicePeriodTo(ctx) - case chargeflatfee.FieldBillingPeriodFrom: - return m.OldBillingPeriodFrom(ctx) - case chargeflatfee.FieldBillingPeriodTo: - return m.OldBillingPeriodTo(ctx) - case chargeflatfee.FieldFullServicePeriodFrom: - return m.OldFullServicePeriodFrom(ctx) - case chargeflatfee.FieldFullServicePeriodTo: - return m.OldFullServicePeriodTo(ctx) - case chargeflatfee.FieldStatus: - return m.OldStatus(ctx) - case chargeflatfee.FieldUniqueReferenceID: - return m.OldUniqueReferenceID(ctx) - case chargeflatfee.FieldFiatCurrencyCode: - return m.OldFiatCurrencyCode(ctx) - case chargeflatfee.FieldCustomCurrencyID: - return m.OldCustomCurrencyID(ctx) - case chargeflatfee.FieldManagedBy: - return m.OldManagedBy(ctx) - case chargeflatfee.FieldSubscriptionID: - return m.OldSubscriptionID(ctx) - case chargeflatfee.FieldSubscriptionPhaseID: - return m.OldSubscriptionPhaseID(ctx) - case chargeflatfee.FieldSubscriptionItemID: - return m.OldSubscriptionItemID(ctx) - case chargeflatfee.FieldAdvanceAfter: - return m.OldAdvanceAfter(ctx) - case chargeflatfee.FieldTaxCodeID: - return m.OldTaxCodeID(ctx) - case chargeflatfee.FieldTaxBehavior: - return m.OldTaxBehavior(ctx) - case chargeflatfee.FieldAnnotations: - return m.OldAnnotations(ctx) - case chargeflatfee.FieldNamespace: - return m.OldNamespace(ctx) - case chargeflatfee.FieldMetadata: - return m.OldMetadata(ctx) - case chargeflatfee.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case chargeflatfee.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - case chargeflatfee.FieldDeletedAt: - return m.OldDeletedAt(ctx) - case chargeflatfee.FieldName: - return m.OldName(ctx) - case chargeflatfee.FieldDescription: - return m.OldDescription(ctx) - case chargeflatfee.FieldPaymentTerm: - return m.OldPaymentTerm(ctx) - case chargeflatfee.FieldInvoiceAt: - return m.OldInvoiceAt(ctx) - case chargeflatfee.FieldSettlementMode: - return m.OldSettlementMode(ctx) - case chargeflatfee.FieldIntentDeletedAt: - return m.OldIntentDeletedAt(ctx) - case chargeflatfee.FieldDiscounts: - return m.OldDiscounts(ctx) - case chargeflatfee.FieldProRating: - return m.OldProRating(ctx) - case chargeflatfee.FieldFeatureKey: - return m.OldFeatureKey(ctx) - case chargeflatfee.FieldFeatureID: - return m.OldFeatureID(ctx) - case chargeflatfee.FieldAmountBeforeProration: - return m.OldAmountBeforeProration(ctx) - case chargeflatfee.FieldAmountAfterProration: - return m.OldAmountAfterProration(ctx) - case chargeflatfee.FieldCurrentRealizationRunID: - return m.OldCurrentRealizationRunID(ctx) - case chargeflatfee.FieldStatusDetailed: - return m.OldStatusDetailed(ctx) +// SetSettlementMode sets the "settlement_mode" field. +func (m *ChargeFlatFeeMutation) SetSettlementMode(pm productcatalog.SettlementMode) { + m.settlement_mode = &pm +} + +// SettlementMode returns the value of the "settlement_mode" field in the mutation. +func (m *ChargeFlatFeeMutation) SettlementMode() (r productcatalog.SettlementMode, exists bool) { + v := m.settlement_mode + if v == nil { + return } - return nil, fmt.Errorf("unknown ChargeFlatFee field %s", name) + return *v, true } -// 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 *ChargeFlatFeeMutation) SetField(name string, value ent.Value) error { - switch name { - case chargeflatfee.FieldCustomerID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCustomerID(v) - return nil - case chargeflatfee.FieldServicePeriodFrom: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetServicePeriodFrom(v) - return nil - case chargeflatfee.FieldServicePeriodTo: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetServicePeriodTo(v) - return nil - case chargeflatfee.FieldBillingPeriodFrom: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetBillingPeriodFrom(v) - return nil - case chargeflatfee.FieldBillingPeriodTo: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetBillingPeriodTo(v) - return nil - case chargeflatfee.FieldFullServicePeriodFrom: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetFullServicePeriodFrom(v) - return nil - case chargeflatfee.FieldFullServicePeriodTo: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetFullServicePeriodTo(v) - return nil - case chargeflatfee.FieldStatus: - v, ok := value.(meta.ChargeStatus) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetStatus(v) - return nil - case chargeflatfee.FieldUniqueReferenceID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUniqueReferenceID(v) - return nil - case chargeflatfee.FieldFiatCurrencyCode: - v, ok := value.(currencyx.Code) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetFiatCurrencyCode(v) - return nil - case chargeflatfee.FieldCustomCurrencyID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCustomCurrencyID(v) - return nil - case chargeflatfee.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 chargeflatfee.FieldSubscriptionID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetSubscriptionID(v) - return nil - case chargeflatfee.FieldSubscriptionPhaseID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetSubscriptionPhaseID(v) - return nil - case chargeflatfee.FieldSubscriptionItemID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetSubscriptionItemID(v) - return nil - case chargeflatfee.FieldAdvanceAfter: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetAdvanceAfter(v) - return nil - case chargeflatfee.FieldTaxCodeID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetTaxCodeID(v) - return nil - case chargeflatfee.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 chargeflatfee.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 chargeflatfee.FieldNamespace: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetNamespace(v) - return nil - case chargeflatfee.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 chargeflatfee.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 chargeflatfee.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 chargeflatfee.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 chargeflatfee.FieldName: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetName(v) - return nil - case chargeflatfee.FieldDescription: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDescription(v) - return nil - case chargeflatfee.FieldPaymentTerm: - v, ok := value.(productcatalog.PaymentTermType) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetPaymentTerm(v) - return nil - case chargeflatfee.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 chargeflatfee.FieldSettlementMode: - v, ok := value.(productcatalog.SettlementMode) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetSettlementMode(v) - return nil - case chargeflatfee.FieldIntentDeletedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetIntentDeletedAt(v) - return nil - case chargeflatfee.FieldDiscounts: - v, ok := value.(*billing.Discounts) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDiscounts(v) - return nil - case chargeflatfee.FieldProRating: - v, ok := value.(flatfee.ProRatingModeAdapterEnum) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetProRating(v) - return nil - case chargeflatfee.FieldFeatureKey: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetFeatureKey(v) - return nil - case chargeflatfee.FieldFeatureID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetFeatureID(v) - return nil - case chargeflatfee.FieldAmountBeforeProration: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetAmountBeforeProration(v) - return nil - case chargeflatfee.FieldAmountAfterProration: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetAmountAfterProration(v) - return nil - case chargeflatfee.FieldCurrentRealizationRunID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCurrentRealizationRunID(v) - return nil - case chargeflatfee.FieldStatusDetailed: - v, ok := value.(flatfee.Status) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetStatusDetailed(v) - return nil +// OldSettlementMode returns the old "settlement_mode" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldSettlementMode(ctx context.Context) (v productcatalog.SettlementMode, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSettlementMode is only allowed on UpdateOne operations") } - return fmt.Errorf("unknown ChargeFlatFee field %s", name) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSettlementMode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSettlementMode: %w", err) + } + return oldValue.SettlementMode, nil } -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *ChargeFlatFeeMutation) AddedFields() []string { - return nil +// ResetSettlementMode resets all changes to the "settlement_mode" field. +func (m *ChargeFlatFeeMutation) ResetSettlementMode() { + m.settlement_mode = 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 *ChargeFlatFeeMutation) AddedField(name string) (ent.Value, bool) { - return nil, false +// SetIntentDeletedAt sets the "intent_deleted_at" field. +func (m *ChargeFlatFeeMutation) SetIntentDeletedAt(t time.Time) { + m.intent_deleted_at = &t } -// 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 *ChargeFlatFeeMutation) AddField(name string, value ent.Value) error { - switch name { +// IntentDeletedAt returns the value of the "intent_deleted_at" field in the mutation. +func (m *ChargeFlatFeeMutation) IntentDeletedAt() (r time.Time, exists bool) { + v := m.intent_deleted_at + if v == nil { + return } - return fmt.Errorf("unknown ChargeFlatFee numeric field %s", name) + return *v, true } -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *ChargeFlatFeeMutation) ClearedFields() []string { - var fields []string - if m.FieldCleared(chargeflatfee.FieldUniqueReferenceID) { - fields = append(fields, chargeflatfee.FieldUniqueReferenceID) - } - if m.FieldCleared(chargeflatfee.FieldFiatCurrencyCode) { - fields = append(fields, chargeflatfee.FieldFiatCurrencyCode) - } - if m.FieldCleared(chargeflatfee.FieldCustomCurrencyID) { - fields = append(fields, chargeflatfee.FieldCustomCurrencyID) - } - if m.FieldCleared(chargeflatfee.FieldSubscriptionID) { - fields = append(fields, chargeflatfee.FieldSubscriptionID) - } - if m.FieldCleared(chargeflatfee.FieldSubscriptionPhaseID) { - fields = append(fields, chargeflatfee.FieldSubscriptionPhaseID) +// OldIntentDeletedAt returns the old "intent_deleted_at" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldIntentDeletedAt(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIntentDeletedAt is only allowed on UpdateOne operations") } - if m.FieldCleared(chargeflatfee.FieldSubscriptionItemID) { - fields = append(fields, chargeflatfee.FieldSubscriptionItemID) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIntentDeletedAt requires an ID field in the mutation") } - if m.FieldCleared(chargeflatfee.FieldAdvanceAfter) { - fields = append(fields, chargeflatfee.FieldAdvanceAfter) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIntentDeletedAt: %w", err) } - if m.FieldCleared(chargeflatfee.FieldTaxBehavior) { - fields = append(fields, chargeflatfee.FieldTaxBehavior) - } - if m.FieldCleared(chargeflatfee.FieldAnnotations) { - fields = append(fields, chargeflatfee.FieldAnnotations) - } - if m.FieldCleared(chargeflatfee.FieldMetadata) { - fields = append(fields, chargeflatfee.FieldMetadata) - } - if m.FieldCleared(chargeflatfee.FieldDeletedAt) { - fields = append(fields, chargeflatfee.FieldDeletedAt) - } - if m.FieldCleared(chargeflatfee.FieldDescription) { - fields = append(fields, chargeflatfee.FieldDescription) - } - if m.FieldCleared(chargeflatfee.FieldIntentDeletedAt) { - fields = append(fields, chargeflatfee.FieldIntentDeletedAt) - } - if m.FieldCleared(chargeflatfee.FieldDiscounts) { - fields = append(fields, chargeflatfee.FieldDiscounts) + return oldValue.IntentDeletedAt, nil +} + +// ClearIntentDeletedAt clears the value of the "intent_deleted_at" field. +func (m *ChargeFlatFeeMutation) ClearIntentDeletedAt() { + m.intent_deleted_at = nil + m.clearedFields[chargeflatfee.FieldIntentDeletedAt] = struct{}{} +} + +// IntentDeletedAtCleared returns if the "intent_deleted_at" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) IntentDeletedAtCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldIntentDeletedAt] + return ok +} + +// ResetIntentDeletedAt resets all changes to the "intent_deleted_at" field. +func (m *ChargeFlatFeeMutation) ResetIntentDeletedAt() { + m.intent_deleted_at = nil + delete(m.clearedFields, chargeflatfee.FieldIntentDeletedAt) +} + +// SetDiscounts sets the "discounts" field. +func (m *ChargeFlatFeeMutation) SetDiscounts(b *billing.Discounts) { + m.discounts = &b +} + +// Discounts returns the value of the "discounts" field in the mutation. +func (m *ChargeFlatFeeMutation) Discounts() (r *billing.Discounts, exists bool) { + v := m.discounts + if v == nil { + return } - if m.FieldCleared(chargeflatfee.FieldFeatureKey) { - fields = append(fields, chargeflatfee.FieldFeatureKey) + return *v, true +} + +// OldDiscounts returns the old "discounts" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldDiscounts(ctx context.Context) (v *billing.Discounts, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDiscounts is only allowed on UpdateOne operations") } - if m.FieldCleared(chargeflatfee.FieldFeatureID) { - fields = append(fields, chargeflatfee.FieldFeatureID) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDiscounts requires an ID field in the mutation") } - if m.FieldCleared(chargeflatfee.FieldCurrentRealizationRunID) { - fields = append(fields, chargeflatfee.FieldCurrentRealizationRunID) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDiscounts: %w", err) } - return fields + return oldValue.Discounts, nil } -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *ChargeFlatFeeMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] +// ClearDiscounts clears the value of the "discounts" field. +func (m *ChargeFlatFeeMutation) ClearDiscounts() { + m.discounts = nil + m.clearedFields[chargeflatfee.FieldDiscounts] = struct{}{} +} + +// DiscountsCleared returns if the "discounts" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) DiscountsCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldDiscounts] 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 *ChargeFlatFeeMutation) ClearField(name string) error { - switch name { - case chargeflatfee.FieldUniqueReferenceID: - m.ClearUniqueReferenceID() - return nil - case chargeflatfee.FieldFiatCurrencyCode: - m.ClearFiatCurrencyCode() - return nil - case chargeflatfee.FieldCustomCurrencyID: - m.ClearCustomCurrencyID() - return nil - case chargeflatfee.FieldSubscriptionID: - m.ClearSubscriptionID() - return nil - case chargeflatfee.FieldSubscriptionPhaseID: - m.ClearSubscriptionPhaseID() - return nil - case chargeflatfee.FieldSubscriptionItemID: - m.ClearSubscriptionItemID() - return nil - case chargeflatfee.FieldAdvanceAfter: - m.ClearAdvanceAfter() - return nil - case chargeflatfee.FieldTaxBehavior: - m.ClearTaxBehavior() - return nil - case chargeflatfee.FieldAnnotations: - m.ClearAnnotations() - return nil - case chargeflatfee.FieldMetadata: - m.ClearMetadata() - return nil - case chargeflatfee.FieldDeletedAt: - m.ClearDeletedAt() - return nil - case chargeflatfee.FieldDescription: - m.ClearDescription() - return nil - case chargeflatfee.FieldIntentDeletedAt: - m.ClearIntentDeletedAt() - return nil - case chargeflatfee.FieldDiscounts: - m.ClearDiscounts() - return nil - case chargeflatfee.FieldFeatureKey: - m.ClearFeatureKey() - return nil - case chargeflatfee.FieldFeatureID: - m.ClearFeatureID() - return nil - case chargeflatfee.FieldCurrentRealizationRunID: - m.ClearCurrentRealizationRunID() - return nil - } - return fmt.Errorf("unknown ChargeFlatFee nullable field %s", name) +// ResetDiscounts resets all changes to the "discounts" field. +func (m *ChargeFlatFeeMutation) ResetDiscounts() { + m.discounts = nil + delete(m.clearedFields, chargeflatfee.FieldDiscounts) } -// 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 *ChargeFlatFeeMutation) ResetField(name string) error { - switch name { - case chargeflatfee.FieldCustomerID: - m.ResetCustomerID() - return nil - case chargeflatfee.FieldServicePeriodFrom: - m.ResetServicePeriodFrom() - return nil - case chargeflatfee.FieldServicePeriodTo: - m.ResetServicePeriodTo() - return nil - case chargeflatfee.FieldBillingPeriodFrom: - m.ResetBillingPeriodFrom() - return nil - case chargeflatfee.FieldBillingPeriodTo: - m.ResetBillingPeriodTo() - return nil - case chargeflatfee.FieldFullServicePeriodFrom: - m.ResetFullServicePeriodFrom() - return nil - case chargeflatfee.FieldFullServicePeriodTo: - m.ResetFullServicePeriodTo() - return nil - case chargeflatfee.FieldStatus: - m.ResetStatus() - return nil - case chargeflatfee.FieldUniqueReferenceID: - m.ResetUniqueReferenceID() - return nil - case chargeflatfee.FieldFiatCurrencyCode: - m.ResetFiatCurrencyCode() - return nil - case chargeflatfee.FieldCustomCurrencyID: - m.ResetCustomCurrencyID() - return nil - case chargeflatfee.FieldManagedBy: - m.ResetManagedBy() - return nil - case chargeflatfee.FieldSubscriptionID: - m.ResetSubscriptionID() - return nil - case chargeflatfee.FieldSubscriptionPhaseID: - m.ResetSubscriptionPhaseID() - return nil - case chargeflatfee.FieldSubscriptionItemID: - m.ResetSubscriptionItemID() - return nil - case chargeflatfee.FieldAdvanceAfter: - m.ResetAdvanceAfter() - return nil - case chargeflatfee.FieldTaxCodeID: - m.ResetTaxCodeID() - return nil - case chargeflatfee.FieldTaxBehavior: - m.ResetTaxBehavior() - return nil - case chargeflatfee.FieldAnnotations: - m.ResetAnnotations() - return nil - case chargeflatfee.FieldNamespace: - m.ResetNamespace() - return nil - case chargeflatfee.FieldMetadata: - m.ResetMetadata() - return nil - case chargeflatfee.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case chargeflatfee.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - case chargeflatfee.FieldDeletedAt: - m.ResetDeletedAt() - return nil - case chargeflatfee.FieldName: - m.ResetName() - return nil - case chargeflatfee.FieldDescription: - m.ResetDescription() - return nil - case chargeflatfee.FieldPaymentTerm: - m.ResetPaymentTerm() - return nil - case chargeflatfee.FieldInvoiceAt: - m.ResetInvoiceAt() - return nil - case chargeflatfee.FieldSettlementMode: - m.ResetSettlementMode() - return nil - case chargeflatfee.FieldIntentDeletedAt: - m.ResetIntentDeletedAt() - return nil - case chargeflatfee.FieldDiscounts: - m.ResetDiscounts() - return nil - case chargeflatfee.FieldProRating: - m.ResetProRating() - return nil - case chargeflatfee.FieldFeatureKey: - m.ResetFeatureKey() - return nil - case chargeflatfee.FieldFeatureID: - m.ResetFeatureID() - return nil - case chargeflatfee.FieldAmountBeforeProration: - m.ResetAmountBeforeProration() - return nil - case chargeflatfee.FieldAmountAfterProration: - m.ResetAmountAfterProration() - return nil - case chargeflatfee.FieldCurrentRealizationRunID: - m.ResetCurrentRealizationRunID() - return nil - case chargeflatfee.FieldStatusDetailed: - m.ResetStatusDetailed() - return nil +// SetProRating sets the "pro_rating" field. +func (m *ChargeFlatFeeMutation) SetProRating(frmae flatfee.ProRatingModeAdapterEnum) { + m.pro_rating = &frmae +} + +// ProRating returns the value of the "pro_rating" field in the mutation. +func (m *ChargeFlatFeeMutation) ProRating() (r flatfee.ProRatingModeAdapterEnum, exists bool) { + v := m.pro_rating + if v == nil { + return } - return fmt.Errorf("unknown ChargeFlatFee field %s", name) + return *v, true } -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *ChargeFlatFeeMutation) AddedEdges() []string { - edges := make([]string, 0, 11) - if m.runs != nil { - edges = append(edges, chargeflatfee.EdgeRuns) +// OldProRating returns the old "pro_rating" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldProRating(ctx context.Context) (v flatfee.ProRatingModeAdapterEnum, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldProRating is only allowed on UpdateOne operations") } - if m.current_run != nil { - edges = append(edges, chargeflatfee.EdgeCurrentRun) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldProRating requires an ID field in the mutation") } - if m.charge != nil { - edges = append(edges, chargeflatfee.EdgeCharge) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldProRating: %w", err) } - if m.intent_override != nil { - edges = append(edges, chargeflatfee.EdgeIntentOverride) + return oldValue.ProRating, nil +} + +// ResetProRating resets all changes to the "pro_rating" field. +func (m *ChargeFlatFeeMutation) ResetProRating() { + m.pro_rating = nil +} + +// SetFeatureKey sets the "feature_key" field. +func (m *ChargeFlatFeeMutation) SetFeatureKey(s string) { + m.feature_key = &s +} + +// FeatureKey returns the value of the "feature_key" field in the mutation. +func (m *ChargeFlatFeeMutation) FeatureKey() (r string, exists bool) { + v := m.feature_key + if v == nil { + return } - if m.subscription != nil { - edges = append(edges, chargeflatfee.EdgeSubscription) + return *v, true +} + +// OldFeatureKey returns the old "feature_key" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) 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.subscription_phase != nil { - edges = append(edges, chargeflatfee.EdgeSubscriptionPhase) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFeatureKey requires an ID field in the mutation") } - if m.subscription_item != nil { - edges = append(edges, chargeflatfee.EdgeSubscriptionItem) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFeatureKey: %w", err) } - if m.customer != nil { - edges = append(edges, chargeflatfee.EdgeCustomer) + return oldValue.FeatureKey, nil +} + +// ClearFeatureKey clears the value of the "feature_key" field. +func (m *ChargeFlatFeeMutation) ClearFeatureKey() { + m.feature_key = nil + m.clearedFields[chargeflatfee.FieldFeatureKey] = struct{}{} +} + +// FeatureKeyCleared returns if the "feature_key" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) FeatureKeyCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldFeatureKey] + return ok +} + +// ResetFeatureKey resets all changes to the "feature_key" field. +func (m *ChargeFlatFeeMutation) ResetFeatureKey() { + m.feature_key = nil + delete(m.clearedFields, chargeflatfee.FieldFeatureKey) +} + +// SetFeatureID sets the "feature_id" field. +func (m *ChargeFlatFeeMutation) SetFeatureID(s string) { + m.feature = &s +} + +// FeatureID returns the value of the "feature_id" field in the mutation. +func (m *ChargeFlatFeeMutation) FeatureID() (r string, exists bool) { + v := m.feature + if v == nil { + return } - if m.feature != nil { - edges = append(edges, chargeflatfee.EdgeFeature) + return *v, true +} + +// OldFeatureID returns the old "feature_id" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldFeatureID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFeatureID is only allowed on UpdateOne operations") } - if m.tax_code != nil { - edges = append(edges, chargeflatfee.EdgeTaxCode) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFeatureID requires an ID field in the mutation") } - if m.custom_currency != nil { - edges = append(edges, chargeflatfee.EdgeCustomCurrency) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFeatureID: %w", err) } - return edges + return oldValue.FeatureID, nil } -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *ChargeFlatFeeMutation) AddedIDs(name string) []ent.Value { - switch name { - case chargeflatfee.EdgeRuns: - ids := make([]ent.Value, 0, len(m.runs)) - for id := range m.runs { - ids = append(ids, id) - } - return ids - case chargeflatfee.EdgeCurrentRun: - if id := m.current_run; id != nil { - return []ent.Value{*id} - } - case chargeflatfee.EdgeCharge: - if id := m.charge; id != nil { - return []ent.Value{*id} - } - case chargeflatfee.EdgeIntentOverride: - if id := m.intent_override; id != nil { - return []ent.Value{*id} - } - case chargeflatfee.EdgeSubscription: - if id := m.subscription; id != nil { - return []ent.Value{*id} - } - case chargeflatfee.EdgeSubscriptionPhase: - if id := m.subscription_phase; id != nil { - return []ent.Value{*id} - } - case chargeflatfee.EdgeSubscriptionItem: - if id := m.subscription_item; id != nil { - return []ent.Value{*id} - } - case chargeflatfee.EdgeCustomer: - if id := m.customer; id != nil { - return []ent.Value{*id} - } - case chargeflatfee.EdgeFeature: - if id := m.feature; id != nil { - return []ent.Value{*id} - } - case chargeflatfee.EdgeTaxCode: - if id := m.tax_code; id != nil { - return []ent.Value{*id} - } - case chargeflatfee.EdgeCustomCurrency: - if id := m.custom_currency; id != nil { - return []ent.Value{*id} - } - } - return nil +// ClearFeatureID clears the value of the "feature_id" field. +func (m *ChargeFlatFeeMutation) ClearFeatureID() { + m.feature = nil + m.clearedFields[chargeflatfee.FieldFeatureID] = struct{}{} } -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *ChargeFlatFeeMutation) RemovedEdges() []string { - edges := make([]string, 0, 11) - if m.removedruns != nil { - edges = append(edges, chargeflatfee.EdgeRuns) - } - return edges +// FeatureIDCleared returns if the "feature_id" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) FeatureIDCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldFeatureID] + return ok } -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *ChargeFlatFeeMutation) RemovedIDs(name string) []ent.Value { - switch name { - case chargeflatfee.EdgeRuns: - ids := make([]ent.Value, 0, len(m.removedruns)) - for id := range m.removedruns { - ids = append(ids, id) - } - return ids - } - return nil +// ResetFeatureID resets all changes to the "feature_id" field. +func (m *ChargeFlatFeeMutation) ResetFeatureID() { + m.feature = nil + delete(m.clearedFields, chargeflatfee.FieldFeatureID) } -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ChargeFlatFeeMutation) ClearedEdges() []string { - edges := make([]string, 0, 11) - if m.clearedruns { - edges = append(edges, chargeflatfee.EdgeRuns) +// SetAmountBeforeProration sets the "amount_before_proration" field. +func (m *ChargeFlatFeeMutation) SetAmountBeforeProration(a alpacadecimal.Decimal) { + m.amount_before_proration = &a +} + +// AmountBeforeProration returns the value of the "amount_before_proration" field in the mutation. +func (m *ChargeFlatFeeMutation) AmountBeforeProration() (r alpacadecimal.Decimal, exists bool) { + v := m.amount_before_proration + if v == nil { + return } - if m.clearedcurrent_run { - edges = append(edges, chargeflatfee.EdgeCurrentRun) + return *v, true +} + +// OldAmountBeforeProration returns the old "amount_before_proration" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeMutation) OldAmountBeforeProration(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAmountBeforeProration is only allowed on UpdateOne operations") } - if m.clearedcharge { - edges = append(edges, chargeflatfee.EdgeCharge) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAmountBeforeProration requires an ID field in the mutation") } - if m.clearedintent_override { - edges = append(edges, chargeflatfee.EdgeIntentOverride) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAmountBeforeProration: %w", err) } - if m.clearedsubscription { - edges = append(edges, chargeflatfee.EdgeSubscription) - } - if m.clearedsubscription_phase { - edges = append(edges, chargeflatfee.EdgeSubscriptionPhase) - } - if m.clearedsubscription_item { - edges = append(edges, chargeflatfee.EdgeSubscriptionItem) - } - if m.clearedcustomer { - edges = append(edges, chargeflatfee.EdgeCustomer) - } - if m.clearedfeature { - edges = append(edges, chargeflatfee.EdgeFeature) - } - if m.clearedtax_code { - edges = append(edges, chargeflatfee.EdgeTaxCode) - } - if m.clearedcustom_currency { - edges = append(edges, chargeflatfee.EdgeCustomCurrency) - } - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *ChargeFlatFeeMutation) EdgeCleared(name string) bool { - switch name { - case chargeflatfee.EdgeRuns: - return m.clearedruns - case chargeflatfee.EdgeCurrentRun: - return m.clearedcurrent_run - case chargeflatfee.EdgeCharge: - return m.clearedcharge - case chargeflatfee.EdgeIntentOverride: - return m.clearedintent_override - case chargeflatfee.EdgeSubscription: - return m.clearedsubscription - case chargeflatfee.EdgeSubscriptionPhase: - return m.clearedsubscription_phase - case chargeflatfee.EdgeSubscriptionItem: - return m.clearedsubscription_item - case chargeflatfee.EdgeCustomer: - return m.clearedcustomer - case chargeflatfee.EdgeFeature: - return m.clearedfeature - case chargeflatfee.EdgeTaxCode: - return m.clearedtax_code - case chargeflatfee.EdgeCustomCurrency: - return m.clearedcustom_currency - } - 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 *ChargeFlatFeeMutation) ClearEdge(name string) error { - switch name { - case chargeflatfee.EdgeCurrentRun: - m.ClearCurrentRun() - return nil - case chargeflatfee.EdgeCharge: - m.ClearCharge() - return nil - case chargeflatfee.EdgeIntentOverride: - m.ClearIntentOverride() - return nil - case chargeflatfee.EdgeSubscription: - m.ClearSubscription() - return nil - case chargeflatfee.EdgeSubscriptionPhase: - m.ClearSubscriptionPhase() - return nil - case chargeflatfee.EdgeSubscriptionItem: - m.ClearSubscriptionItem() - return nil - case chargeflatfee.EdgeCustomer: - m.ClearCustomer() - return nil - case chargeflatfee.EdgeFeature: - m.ClearFeature() - return nil - case chargeflatfee.EdgeTaxCode: - m.ClearTaxCode() - return nil - case chargeflatfee.EdgeCustomCurrency: - m.ClearCustomCurrency() - return nil - } - return fmt.Errorf("unknown ChargeFlatFee 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 *ChargeFlatFeeMutation) ResetEdge(name string) error { - switch name { - case chargeflatfee.EdgeRuns: - m.ResetRuns() - return nil - case chargeflatfee.EdgeCurrentRun: - m.ResetCurrentRun() - return nil - case chargeflatfee.EdgeCharge: - m.ResetCharge() - return nil - case chargeflatfee.EdgeIntentOverride: - m.ResetIntentOverride() - return nil - case chargeflatfee.EdgeSubscription: - m.ResetSubscription() - return nil - case chargeflatfee.EdgeSubscriptionPhase: - m.ResetSubscriptionPhase() - return nil - case chargeflatfee.EdgeSubscriptionItem: - m.ResetSubscriptionItem() - return nil - case chargeflatfee.EdgeCustomer: - m.ResetCustomer() - return nil - case chargeflatfee.EdgeFeature: - m.ResetFeature() - return nil - case chargeflatfee.EdgeTaxCode: - m.ResetTaxCode() - return nil - case chargeflatfee.EdgeCustomCurrency: - m.ResetCustomCurrency() - return nil - } - return fmt.Errorf("unknown ChargeFlatFee edge %s", name) -} - -// ChargeFlatFeeOverrideMutation represents an operation that mutates the ChargeFlatFeeOverride nodes in the graph. -type ChargeFlatFeeOverrideMutation struct { - config - op Op - typ string - id *string - namespace *string - name *string - description *string - metadata **models.Metadata - tax_behavior *productcatalog.TaxBehavior - intent_deleted_at *time.Time - service_period_from *time.Time - service_period_to *time.Time - full_service_period_from *time.Time - full_service_period_to *time.Time - billing_period_from *time.Time - billing_period_to *time.Time - invoice_at *time.Time - feature_key *string - payment_term *productcatalog.PaymentTermType - pro_rating **productcatalog.ProRatingConfig - amount_before_proration *alpacadecimal.Decimal - discounts **billing.Discounts - percentage_discounts **billing.PercentageDiscount - clearedFields map[string]struct{} - flat_fee *string - clearedflat_fee bool - tax_code *string - clearedtax_code bool - done bool - oldValue func(context.Context) (*ChargeFlatFeeOverride, error) - predicates []predicate.ChargeFlatFeeOverride -} - -var _ ent.Mutation = (*ChargeFlatFeeOverrideMutation)(nil) - -// chargeflatfeeoverrideOption allows management of the mutation configuration using functional options. -type chargeflatfeeoverrideOption func(*ChargeFlatFeeOverrideMutation) - -// newChargeFlatFeeOverrideMutation creates new mutation for the ChargeFlatFeeOverride entity. -func newChargeFlatFeeOverrideMutation(c config, op Op, opts ...chargeflatfeeoverrideOption) *ChargeFlatFeeOverrideMutation { - m := &ChargeFlatFeeOverrideMutation{ - config: c, - op: op, - typ: TypeChargeFlatFeeOverride, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withChargeFlatFeeOverrideID sets the ID field of the mutation. -func withChargeFlatFeeOverrideID(id string) chargeflatfeeoverrideOption { - return func(m *ChargeFlatFeeOverrideMutation) { - var ( - err error - once sync.Once - value *ChargeFlatFeeOverride - ) - m.oldValue = func(ctx context.Context) (*ChargeFlatFeeOverride, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().ChargeFlatFeeOverride.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withChargeFlatFeeOverride sets the old ChargeFlatFeeOverride of the mutation. -func withChargeFlatFeeOverride(node *ChargeFlatFeeOverride) chargeflatfeeoverrideOption { - return func(m *ChargeFlatFeeOverrideMutation) { - m.oldValue = func(context.Context) (*ChargeFlatFeeOverride, 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 ChargeFlatFeeOverrideMutation) 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 ChargeFlatFeeOverrideMutation) 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 ChargeFlatFeeOverride entities. -func (m *ChargeFlatFeeOverrideMutation) 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 *ChargeFlatFeeOverrideMutation) ID() (id string, exists bool) { - if m.id == nil { - return - } - return *m.id, true + return oldValue.AmountBeforeProration, nil } -// 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 *ChargeFlatFeeOverrideMutation) 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().ChargeFlatFeeOverride.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } +// ResetAmountBeforeProration resets all changes to the "amount_before_proration" field. +func (m *ChargeFlatFeeMutation) ResetAmountBeforeProration() { + m.amount_before_proration = nil } -// SetNamespace sets the "namespace" field. -func (m *ChargeFlatFeeOverrideMutation) SetNamespace(s string) { - m.namespace = &s +// SetAmountAfterProration sets the "amount_after_proration" field. +func (m *ChargeFlatFeeMutation) SetAmountAfterProration(a alpacadecimal.Decimal) { + m.amount_after_proration = &a } -// Namespace returns the value of the "namespace" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) Namespace() (r string, exists bool) { - v := m.namespace +// AmountAfterProration returns the value of the "amount_after_proration" field in the mutation. +func (m *ChargeFlatFeeMutation) AmountAfterProration() (r alpacadecimal.Decimal, exists bool) { + v := m.amount_after_proration if v == nil { return } return *v, true } -// OldNamespace returns the old "namespace" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride object wasn't provided to the builder, the object is fetched from the database. +// OldAmountAfterProration returns the old "amount_after_proration" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeOverrideMutation) OldNamespace(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeMutation) OldAmountAfterProration(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldNamespace is only allowed on UpdateOne operations") + return v, errors.New("OldAmountAfterProration 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") + return v, errors.New("OldAmountAfterProration 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 v, fmt.Errorf("querying old value for OldAmountAfterProration: %w", err) } - return oldValue.Namespace, nil + return oldValue.AmountAfterProration, nil } -// ResetNamespace resets all changes to the "namespace" field. -func (m *ChargeFlatFeeOverrideMutation) ResetNamespace() { - m.namespace = nil +// ResetAmountAfterProration resets all changes to the "amount_after_proration" field. +func (m *ChargeFlatFeeMutation) ResetAmountAfterProration() { + m.amount_after_proration = nil } -// SetChargeID sets the "charge_id" field. -func (m *ChargeFlatFeeOverrideMutation) SetChargeID(s string) { - m.flat_fee = &s +// SetCurrentRealizationRunID sets the "current_realization_run_id" field. +func (m *ChargeFlatFeeMutation) SetCurrentRealizationRunID(s string) { + m.current_run = &s } -// ChargeID returns the value of the "charge_id" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) ChargeID() (r string, exists bool) { - v := m.flat_fee +// CurrentRealizationRunID returns the value of the "current_realization_run_id" field in the mutation. +func (m *ChargeFlatFeeMutation) CurrentRealizationRunID() (r string, exists bool) { + v := m.current_run if v == nil { return } return *v, true } -// OldChargeID returns the old "charge_id" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride object wasn't provided to the builder, the object is fetched from the database. +// OldCurrentRealizationRunID returns the old "current_realization_run_id" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeOverrideMutation) OldChargeID(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeMutation) OldCurrentRealizationRunID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldChargeID is only allowed on UpdateOne operations") + return v, errors.New("OldCurrentRealizationRunID 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") + return v, errors.New("OldCurrentRealizationRunID 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 v, fmt.Errorf("querying old value for OldCurrentRealizationRunID: %w", err) } - return oldValue.ChargeID, nil -} - -// ResetChargeID resets all changes to the "charge_id" field. -func (m *ChargeFlatFeeOverrideMutation) ResetChargeID() { - m.flat_fee = nil -} - -// SetName sets the "name" field. -func (m *ChargeFlatFeeOverrideMutation) SetName(s string) { - m.name = &s + return oldValue.CurrentRealizationRunID, nil } -// Name returns the value of the "name" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) Name() (r string, exists bool) { - v := m.name - if v == nil { - return - } - return *v, true +// ClearCurrentRealizationRunID clears the value of the "current_realization_run_id" field. +func (m *ChargeFlatFeeMutation) ClearCurrentRealizationRunID() { + m.current_run = nil + m.clearedFields[chargeflatfee.FieldCurrentRealizationRunID] = struct{}{} } -// OldName returns the old "name" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) 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 +// CurrentRealizationRunIDCleared returns if the "current_realization_run_id" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) CurrentRealizationRunIDCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldCurrentRealizationRunID] + return ok } -// ResetName resets all changes to the "name" field. -func (m *ChargeFlatFeeOverrideMutation) ResetName() { - m.name = nil +// ResetCurrentRealizationRunID resets all changes to the "current_realization_run_id" field. +func (m *ChargeFlatFeeMutation) ResetCurrentRealizationRunID() { + m.current_run = nil + delete(m.clearedFields, chargeflatfee.FieldCurrentRealizationRunID) } -// SetDescription sets the "description" field. -func (m *ChargeFlatFeeOverrideMutation) SetDescription(s string) { - m.description = &s +// SetCostBasisID sets the "cost_basis_id" field. +func (m *ChargeFlatFeeMutation) SetCostBasisID(s string) { + m.cost_basis = &s } -// Description returns the value of the "description" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) Description() (r string, exists bool) { - v := m.description +// CostBasisID returns the value of the "cost_basis_id" field in the mutation. +func (m *ChargeFlatFeeMutation) CostBasisID() (r string, exists bool) { + v := m.cost_basis if v == nil { return } return *v, true } -// OldDescription returns the old "description" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride object wasn't provided to the builder, the object is fetched from the database. +// OldCostBasisID returns the old "cost_basis_id" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeOverrideMutation) OldDescription(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeMutation) OldCostBasisID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDescription is only allowed on UpdateOne operations") + return v, errors.New("OldCostBasisID 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") + return v, errors.New("OldCostBasisID 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 v, fmt.Errorf("querying old value for OldCostBasisID: %w", err) } - return oldValue.Description, nil + return oldValue.CostBasisID, nil } -// ClearDescription clears the value of the "description" field. -func (m *ChargeFlatFeeOverrideMutation) ClearDescription() { - m.description = nil - m.clearedFields[chargeflatfeeoverride.FieldDescription] = struct{}{} +// ClearCostBasisID clears the value of the "cost_basis_id" field. +func (m *ChargeFlatFeeMutation) ClearCostBasisID() { + m.cost_basis = nil + m.clearedFields[chargeflatfee.FieldCostBasisID] = struct{}{} } -// DescriptionCleared returns if the "description" field was cleared in this mutation. -func (m *ChargeFlatFeeOverrideMutation) DescriptionCleared() bool { - _, ok := m.clearedFields[chargeflatfeeoverride.FieldDescription] +// CostBasisIDCleared returns if the "cost_basis_id" field was cleared in this mutation. +func (m *ChargeFlatFeeMutation) CostBasisIDCleared() bool { + _, ok := m.clearedFields[chargeflatfee.FieldCostBasisID] return ok } -// ResetDescription resets all changes to the "description" field. -func (m *ChargeFlatFeeOverrideMutation) ResetDescription() { - m.description = nil - delete(m.clearedFields, chargeflatfeeoverride.FieldDescription) +// ResetCostBasisID resets all changes to the "cost_basis_id" field. +func (m *ChargeFlatFeeMutation) ResetCostBasisID() { + m.cost_basis = nil + delete(m.clearedFields, chargeflatfee.FieldCostBasisID) } -// SetMetadata sets the "metadata" field. -func (m *ChargeFlatFeeOverrideMutation) SetMetadata(value *models.Metadata) { - m.metadata = &value +// SetStatusDetailed sets the "status_detailed" field. +func (m *ChargeFlatFeeMutation) SetStatusDetailed(f flatfee.Status) { + m.status_detailed = &f } -// Metadata returns the value of the "metadata" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) Metadata() (r *models.Metadata, exists bool) { - v := m.metadata +// StatusDetailed returns the value of the "status_detailed" field in the mutation. +func (m *ChargeFlatFeeMutation) StatusDetailed() (r flatfee.Status, exists bool) { + v := m.status_detailed if v == nil { return } return *v, true } -// OldMetadata returns the old "metadata" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride object wasn't provided to the builder, the object is fetched from the database. +// OldStatusDetailed returns the old "status_detailed" field's value of the ChargeFlatFee entity. +// If the ChargeFlatFee 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 *ChargeFlatFeeOverrideMutation) OldMetadata(ctx context.Context) (v *models.Metadata, err error) { +func (m *ChargeFlatFeeMutation) OldStatusDetailed(ctx context.Context) (v flatfee.Status, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldMetadata is only allowed on UpdateOne operations") + return v, errors.New("OldStatusDetailed 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") + return v, errors.New("OldStatusDetailed 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 v, fmt.Errorf("querying old value for OldStatusDetailed: %w", err) } - return oldValue.Metadata, nil + return oldValue.StatusDetailed, nil } -// ClearMetadata clears the value of the "metadata" field. -func (m *ChargeFlatFeeOverrideMutation) ClearMetadata() { - m.metadata = nil - m.clearedFields[chargeflatfeeoverride.FieldMetadata] = struct{}{} +// ResetStatusDetailed resets all changes to the "status_detailed" field. +func (m *ChargeFlatFeeMutation) ResetStatusDetailed() { + m.status_detailed = nil } -// MetadataCleared returns if the "metadata" field was cleared in this mutation. -func (m *ChargeFlatFeeOverrideMutation) MetadataCleared() bool { - _, ok := m.clearedFields[chargeflatfeeoverride.FieldMetadata] - return ok +// AddRunIDs adds the "runs" edge to the ChargeFlatFeeRun entity by ids. +func (m *ChargeFlatFeeMutation) AddRunIDs(ids ...string) { + if m.runs == nil { + m.runs = make(map[string]struct{}) + } + for i := range ids { + m.runs[ids[i]] = struct{}{} + } } -// ResetMetadata resets all changes to the "metadata" field. -func (m *ChargeFlatFeeOverrideMutation) ResetMetadata() { - m.metadata = nil - delete(m.clearedFields, chargeflatfeeoverride.FieldMetadata) +// ClearRuns clears the "runs" edge to the ChargeFlatFeeRun entity. +func (m *ChargeFlatFeeMutation) ClearRuns() { + m.clearedruns = true } -// SetTaxBehavior sets the "tax_behavior" field. -func (m *ChargeFlatFeeOverrideMutation) SetTaxBehavior(pb productcatalog.TaxBehavior) { - m.tax_behavior = &pb +// RunsCleared reports if the "runs" edge to the ChargeFlatFeeRun entity was cleared. +func (m *ChargeFlatFeeMutation) RunsCleared() bool { + return m.clearedruns } -// TaxBehavior returns the value of the "tax_behavior" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) TaxBehavior() (r productcatalog.TaxBehavior, exists bool) { - v := m.tax_behavior - if v == nil { - return +// RemoveRunIDs removes the "runs" edge to the ChargeFlatFeeRun entity by IDs. +func (m *ChargeFlatFeeMutation) RemoveRunIDs(ids ...string) { + if m.removedruns == nil { + m.removedruns = make(map[string]struct{}) + } + for i := range ids { + delete(m.runs, ids[i]) + m.removedruns[ids[i]] = struct{}{} } - return *v, true } -// OldTaxBehavior returns the old "tax_behavior" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) 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") +// RemovedRuns returns the removed IDs of the "runs" edge to the ChargeFlatFeeRun entity. +func (m *ChargeFlatFeeMutation) RemovedRunsIDs() (ids []string) { + for id := range m.removedruns { + ids = append(ids, id) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTaxBehavior: %w", err) + return +} + +// RunsIDs returns the "runs" edge IDs in the mutation. +func (m *ChargeFlatFeeMutation) RunsIDs() (ids []string) { + for id := range m.runs { + ids = append(ids, id) } - return oldValue.TaxBehavior, nil + return } -// ClearTaxBehavior clears the value of the "tax_behavior" field. -func (m *ChargeFlatFeeOverrideMutation) ClearTaxBehavior() { - m.tax_behavior = nil - m.clearedFields[chargeflatfeeoverride.FieldTaxBehavior] = struct{}{} +// ResetRuns resets all changes to the "runs" edge. +func (m *ChargeFlatFeeMutation) ResetRuns() { + m.runs = nil + m.clearedruns = false + m.removedruns = nil } -// TaxBehaviorCleared returns if the "tax_behavior" field was cleared in this mutation. -func (m *ChargeFlatFeeOverrideMutation) TaxBehaviorCleared() bool { - _, ok := m.clearedFields[chargeflatfeeoverride.FieldTaxBehavior] - return ok +// SetCurrentRunID sets the "current_run" edge to the ChargeFlatFeeRun entity by id. +func (m *ChargeFlatFeeMutation) SetCurrentRunID(id string) { + m.current_run = &id } -// ResetTaxBehavior resets all changes to the "tax_behavior" field. -func (m *ChargeFlatFeeOverrideMutation) ResetTaxBehavior() { - m.tax_behavior = nil - delete(m.clearedFields, chargeflatfeeoverride.FieldTaxBehavior) +// ClearCurrentRun clears the "current_run" edge to the ChargeFlatFeeRun entity. +func (m *ChargeFlatFeeMutation) ClearCurrentRun() { + m.clearedcurrent_run = true + m.clearedFields[chargeflatfee.FieldCurrentRealizationRunID] = struct{}{} } -// SetTaxCodeID sets the "tax_code_id" field. -func (m *ChargeFlatFeeOverrideMutation) SetTaxCodeID(s string) { - m.tax_code = &s +// CurrentRunCleared reports if the "current_run" edge to the ChargeFlatFeeRun entity was cleared. +func (m *ChargeFlatFeeMutation) CurrentRunCleared() bool { + return m.CurrentRealizationRunIDCleared() || m.clearedcurrent_run } -// TaxCodeID returns the value of the "tax_code_id" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) TaxCodeID() (r string, exists bool) { - v := m.tax_code - if v == nil { - return +// CurrentRunID returns the "current_run" edge ID in the mutation. +func (m *ChargeFlatFeeMutation) CurrentRunID() (id string, exists bool) { + if m.current_run != nil { + return *m.current_run, true } - return *v, true + return } -// OldTaxCodeID returns the old "tax_code_id" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) 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) +// CurrentRunIDs returns the "current_run" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CurrentRunID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeMutation) CurrentRunIDs() (ids []string) { + if id := m.current_run; id != nil { + ids = append(ids, *id) } - return oldValue.TaxCodeID, nil -} - -// ClearTaxCodeID clears the value of the "tax_code_id" field. -func (m *ChargeFlatFeeOverrideMutation) ClearTaxCodeID() { - m.tax_code = nil - m.clearedFields[chargeflatfeeoverride.FieldTaxCodeID] = struct{}{} + return } -// TaxCodeIDCleared returns if the "tax_code_id" field was cleared in this mutation. -func (m *ChargeFlatFeeOverrideMutation) TaxCodeIDCleared() bool { - _, ok := m.clearedFields[chargeflatfeeoverride.FieldTaxCodeID] - return ok +// ResetCurrentRun resets all changes to the "current_run" edge. +func (m *ChargeFlatFeeMutation) ResetCurrentRun() { + m.current_run = nil + m.clearedcurrent_run = false } -// ResetTaxCodeID resets all changes to the "tax_code_id" field. -func (m *ChargeFlatFeeOverrideMutation) ResetTaxCodeID() { - m.tax_code = nil - delete(m.clearedFields, chargeflatfeeoverride.FieldTaxCodeID) +// ClearCostBasis clears the "cost_basis" edge to the ChargeFlatFeeCostBasis entity. +func (m *ChargeFlatFeeMutation) ClearCostBasis() { + m.clearedcost_basis = true + m.clearedFields[chargeflatfee.FieldCostBasisID] = struct{}{} } -// SetIntentDeletedAt sets the "intent_deleted_at" field. -func (m *ChargeFlatFeeOverrideMutation) SetIntentDeletedAt(t time.Time) { - m.intent_deleted_at = &t +// CostBasisCleared reports if the "cost_basis" edge to the ChargeFlatFeeCostBasis entity was cleared. +func (m *ChargeFlatFeeMutation) CostBasisCleared() bool { + return m.CostBasisIDCleared() || m.clearedcost_basis } -// IntentDeletedAt returns the value of the "intent_deleted_at" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) IntentDeletedAt() (r time.Time, exists bool) { - v := m.intent_deleted_at - if v == nil { - return +// CostBasisIDs returns the "cost_basis" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CostBasisID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeMutation) CostBasisIDs() (ids []string) { + if id := m.cost_basis; id != nil { + ids = append(ids, *id) } - return *v, true + return } -// OldIntentDeletedAt returns the old "intent_deleted_at" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldIntentDeletedAt(ctx context.Context) (v *time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldIntentDeletedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldIntentDeletedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldIntentDeletedAt: %w", err) - } - return oldValue.IntentDeletedAt, nil +// ResetCostBasis resets all changes to the "cost_basis" edge. +func (m *ChargeFlatFeeMutation) ResetCostBasis() { + m.cost_basis = nil + m.clearedcost_basis = false } -// ClearIntentDeletedAt clears the value of the "intent_deleted_at" field. -func (m *ChargeFlatFeeOverrideMutation) ClearIntentDeletedAt() { - m.intent_deleted_at = nil - m.clearedFields[chargeflatfeeoverride.FieldIntentDeletedAt] = struct{}{} +// SetChargeID sets the "charge" edge to the Charge entity by id. +func (m *ChargeFlatFeeMutation) SetChargeID(id string) { + m.charge = &id } -// IntentDeletedAtCleared returns if the "intent_deleted_at" field was cleared in this mutation. -func (m *ChargeFlatFeeOverrideMutation) IntentDeletedAtCleared() bool { - _, ok := m.clearedFields[chargeflatfeeoverride.FieldIntentDeletedAt] - return ok +// ClearCharge clears the "charge" edge to the Charge entity. +func (m *ChargeFlatFeeMutation) ClearCharge() { + m.clearedcharge = true } -// ResetIntentDeletedAt resets all changes to the "intent_deleted_at" field. -func (m *ChargeFlatFeeOverrideMutation) ResetIntentDeletedAt() { - m.intent_deleted_at = nil - delete(m.clearedFields, chargeflatfeeoverride.FieldIntentDeletedAt) +// ChargeCleared reports if the "charge" edge to the Charge entity was cleared. +func (m *ChargeFlatFeeMutation) ChargeCleared() bool { + return m.clearedcharge } -// SetServicePeriodFrom sets the "service_period_from" field. -func (m *ChargeFlatFeeOverrideMutation) SetServicePeriodFrom(t time.Time) { - m.service_period_from = &t +// ChargeID returns the "charge" edge ID in the mutation. +func (m *ChargeFlatFeeMutation) ChargeID() (id string, exists bool) { + if m.charge != nil { + return *m.charge, true + } + return } -// ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) ServicePeriodFrom() (r time.Time, exists bool) { - v := m.service_period_from - if v == nil { - return +// 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 *ChargeFlatFeeMutation) ChargeIDs() (ids []string) { + if id := m.charge; id != nil { + ids = append(ids, *id) } - return *v, true + return } -// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldServicePeriodFrom requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldServicePeriodFrom: %w", err) - } - return oldValue.ServicePeriodFrom, nil +// ResetCharge resets all changes to the "charge" edge. +func (m *ChargeFlatFeeMutation) ResetCharge() { + m.charge = nil + m.clearedcharge = false } -// ResetServicePeriodFrom resets all changes to the "service_period_from" field. -func (m *ChargeFlatFeeOverrideMutation) ResetServicePeriodFrom() { - m.service_period_from = nil +// SetIntentOverrideID sets the "intent_override" edge to the ChargeFlatFeeOverride entity by id. +func (m *ChargeFlatFeeMutation) SetIntentOverrideID(id string) { + m.intent_override = &id } -// SetServicePeriodTo sets the "service_period_to" field. -func (m *ChargeFlatFeeOverrideMutation) SetServicePeriodTo(t time.Time) { - m.service_period_to = &t +// ClearIntentOverride clears the "intent_override" edge to the ChargeFlatFeeOverride entity. +func (m *ChargeFlatFeeMutation) ClearIntentOverride() { + m.clearedintent_override = true } -// ServicePeriodTo returns the value of the "service_period_to" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) ServicePeriodTo() (r time.Time, exists bool) { - v := m.service_period_to - if v == nil { - return - } - return *v, true +// IntentOverrideCleared reports if the "intent_override" edge to the ChargeFlatFeeOverride entity was cleared. +func (m *ChargeFlatFeeMutation) IntentOverrideCleared() bool { + return m.clearedintent_override } -// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldServicePeriodTo requires an ID field in the mutation") +// IntentOverrideID returns the "intent_override" edge ID in the mutation. +func (m *ChargeFlatFeeMutation) IntentOverrideID() (id string, exists bool) { + if m.intent_override != nil { + return *m.intent_override, true } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldServicePeriodTo: %w", err) + return +} + +// IntentOverrideIDs returns the "intent_override" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// IntentOverrideID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeMutation) IntentOverrideIDs() (ids []string) { + if id := m.intent_override; id != nil { + ids = append(ids, *id) } - return oldValue.ServicePeriodTo, nil + return } -// ResetServicePeriodTo resets all changes to the "service_period_to" field. -func (m *ChargeFlatFeeOverrideMutation) ResetServicePeriodTo() { - m.service_period_to = nil +// ResetIntentOverride resets all changes to the "intent_override" edge. +func (m *ChargeFlatFeeMutation) ResetIntentOverride() { + m.intent_override = nil + m.clearedintent_override = false } -// SetFullServicePeriodFrom sets the "full_service_period_from" field. -func (m *ChargeFlatFeeOverrideMutation) SetFullServicePeriodFrom(t time.Time) { - m.full_service_period_from = &t +// ClearSubscription clears the "subscription" edge to the Subscription entity. +func (m *ChargeFlatFeeMutation) ClearSubscription() { + m.clearedsubscription = true + m.clearedFields[chargeflatfee.FieldSubscriptionID] = struct{}{} } -// FullServicePeriodFrom returns the value of the "full_service_period_from" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) FullServicePeriodFrom() (r time.Time, exists bool) { - v := m.full_service_period_from - if v == nil { - return - } - return *v, true +// SubscriptionCleared reports if the "subscription" edge to the Subscription entity was cleared. +func (m *ChargeFlatFeeMutation) SubscriptionCleared() bool { + return m.SubscriptionIDCleared() || m.clearedsubscription } -// OldFullServicePeriodFrom returns the old "full_service_period_from" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldFullServicePeriodFrom(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldFullServicePeriodFrom is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldFullServicePeriodFrom requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldFullServicePeriodFrom: %w", err) +// 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 *ChargeFlatFeeMutation) SubscriptionIDs() (ids []string) { + if id := m.subscription; id != nil { + ids = append(ids, *id) } - return oldValue.FullServicePeriodFrom, nil + return } -// ResetFullServicePeriodFrom resets all changes to the "full_service_period_from" field. -func (m *ChargeFlatFeeOverrideMutation) ResetFullServicePeriodFrom() { - m.full_service_period_from = nil +// ResetSubscription resets all changes to the "subscription" edge. +func (m *ChargeFlatFeeMutation) ResetSubscription() { + m.subscription = nil + m.clearedsubscription = false } -// SetFullServicePeriodTo sets the "full_service_period_to" field. -func (m *ChargeFlatFeeOverrideMutation) SetFullServicePeriodTo(t time.Time) { - m.full_service_period_to = &t +// ClearSubscriptionPhase clears the "subscription_phase" edge to the SubscriptionPhase entity. +func (m *ChargeFlatFeeMutation) ClearSubscriptionPhase() { + m.clearedsubscription_phase = true + m.clearedFields[chargeflatfee.FieldSubscriptionPhaseID] = struct{}{} } -// FullServicePeriodTo returns the value of the "full_service_period_to" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) FullServicePeriodTo() (r time.Time, exists bool) { - v := m.full_service_period_to - if v == nil { - return - } - return *v, true +// SubscriptionPhaseCleared reports if the "subscription_phase" edge to the SubscriptionPhase entity was cleared. +func (m *ChargeFlatFeeMutation) SubscriptionPhaseCleared() bool { + return m.SubscriptionPhaseIDCleared() || m.clearedsubscription_phase } -// OldFullServicePeriodTo returns the old "full_service_period_to" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldFullServicePeriodTo(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldFullServicePeriodTo is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldFullServicePeriodTo requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldFullServicePeriodTo: %w", err) +// 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 *ChargeFlatFeeMutation) SubscriptionPhaseIDs() (ids []string) { + if id := m.subscription_phase; id != nil { + ids = append(ids, *id) } - return oldValue.FullServicePeriodTo, nil + return } -// ResetFullServicePeriodTo resets all changes to the "full_service_period_to" field. -func (m *ChargeFlatFeeOverrideMutation) ResetFullServicePeriodTo() { - m.full_service_period_to = nil +// ResetSubscriptionPhase resets all changes to the "subscription_phase" edge. +func (m *ChargeFlatFeeMutation) ResetSubscriptionPhase() { + m.subscription_phase = nil + m.clearedsubscription_phase = false } -// SetBillingPeriodFrom sets the "billing_period_from" field. -func (m *ChargeFlatFeeOverrideMutation) SetBillingPeriodFrom(t time.Time) { - m.billing_period_from = &t +// ClearSubscriptionItem clears the "subscription_item" edge to the SubscriptionItem entity. +func (m *ChargeFlatFeeMutation) ClearSubscriptionItem() { + m.clearedsubscription_item = true + m.clearedFields[chargeflatfee.FieldSubscriptionItemID] = struct{}{} } -// BillingPeriodFrom returns the value of the "billing_period_from" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) BillingPeriodFrom() (r time.Time, exists bool) { - v := m.billing_period_from - if v == nil { - return - } - return *v, true +// SubscriptionItemCleared reports if the "subscription_item" edge to the SubscriptionItem entity was cleared. +func (m *ChargeFlatFeeMutation) SubscriptionItemCleared() bool { + return m.SubscriptionItemIDCleared() || m.clearedsubscription_item } -// OldBillingPeriodFrom returns the old "billing_period_from" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldBillingPeriodFrom(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldBillingPeriodFrom is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldBillingPeriodFrom requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldBillingPeriodFrom: %w", err) +// 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 *ChargeFlatFeeMutation) SubscriptionItemIDs() (ids []string) { + if id := m.subscription_item; id != nil { + ids = append(ids, *id) } - return oldValue.BillingPeriodFrom, nil + return } -// ResetBillingPeriodFrom resets all changes to the "billing_period_from" field. -func (m *ChargeFlatFeeOverrideMutation) ResetBillingPeriodFrom() { - m.billing_period_from = nil +// ResetSubscriptionItem resets all changes to the "subscription_item" edge. +func (m *ChargeFlatFeeMutation) ResetSubscriptionItem() { + m.subscription_item = nil + m.clearedsubscription_item = false } -// SetBillingPeriodTo sets the "billing_period_to" field. -func (m *ChargeFlatFeeOverrideMutation) SetBillingPeriodTo(t time.Time) { - m.billing_period_to = &t +// ClearCustomer clears the "customer" edge to the Customer entity. +func (m *ChargeFlatFeeMutation) ClearCustomer() { + m.clearedcustomer = true + m.clearedFields[chargeflatfee.FieldCustomerID] = struct{}{} } -// BillingPeriodTo returns the value of the "billing_period_to" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) BillingPeriodTo() (r time.Time, exists bool) { - v := m.billing_period_to - if v == nil { - return - } - return *v, true +// CustomerCleared reports if the "customer" edge to the Customer entity was cleared. +func (m *ChargeFlatFeeMutation) CustomerCleared() bool { + return m.clearedcustomer } -// OldBillingPeriodTo returns the old "billing_period_to" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldBillingPeriodTo(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldBillingPeriodTo is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldBillingPeriodTo requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldBillingPeriodTo: %w", err) +// CustomerIDs returns the "customer" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CustomerID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeMutation) CustomerIDs() (ids []string) { + if id := m.customer; id != nil { + ids = append(ids, *id) } - return oldValue.BillingPeriodTo, nil + return } -// ResetBillingPeriodTo resets all changes to the "billing_period_to" field. -func (m *ChargeFlatFeeOverrideMutation) ResetBillingPeriodTo() { - m.billing_period_to = nil +// ResetCustomer resets all changes to the "customer" edge. +func (m *ChargeFlatFeeMutation) ResetCustomer() { + m.customer = nil + m.clearedcustomer = false } -// SetInvoiceAt sets the "invoice_at" field. -func (m *ChargeFlatFeeOverrideMutation) SetInvoiceAt(t time.Time) { - m.invoice_at = &t +// ClearFeature clears the "feature" edge to the Feature entity. +func (m *ChargeFlatFeeMutation) ClearFeature() { + m.clearedfeature = true + m.clearedFields[chargeflatfee.FieldFeatureID] = struct{}{} } -// InvoiceAt returns the value of the "invoice_at" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) InvoiceAt() (r time.Time, exists bool) { - v := m.invoice_at - if v == nil { - return - } - return *v, true +// FeatureCleared reports if the "feature" edge to the Feature entity was cleared. +func (m *ChargeFlatFeeMutation) FeatureCleared() bool { + return m.FeatureIDCleared() || m.clearedfeature } -// OldInvoiceAt returns the old "invoice_at" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) 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) +// FeatureIDs returns the "feature" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// FeatureID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeMutation) FeatureIDs() (ids []string) { + if id := m.feature; id != nil { + ids = append(ids, *id) } - return oldValue.InvoiceAt, nil + return } -// ResetInvoiceAt resets all changes to the "invoice_at" field. -func (m *ChargeFlatFeeOverrideMutation) ResetInvoiceAt() { - m.invoice_at = nil +// ResetFeature resets all changes to the "feature" edge. +func (m *ChargeFlatFeeMutation) ResetFeature() { + m.feature = nil + m.clearedfeature = false } -// SetFeatureKey sets the "feature_key" field. -func (m *ChargeFlatFeeOverrideMutation) SetFeatureKey(s string) { - m.feature_key = &s +// ClearTaxCode clears the "tax_code" edge to the TaxCode entity. +func (m *ChargeFlatFeeMutation) ClearTaxCode() { + m.clearedtax_code = true + m.clearedFields[chargeflatfee.FieldTaxCodeID] = struct{}{} } -// FeatureKey returns the value of the "feature_key" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) FeatureKey() (r string, exists bool) { - v := m.feature_key - if v == nil { - return - } - return *v, true +// TaxCodeCleared reports if the "tax_code" edge to the TaxCode entity was cleared. +func (m *ChargeFlatFeeMutation) TaxCodeCleared() bool { + return m.clearedtax_code } -// OldFeatureKey returns the old "feature_key" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) 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) +// 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 *ChargeFlatFeeMutation) TaxCodeIDs() (ids []string) { + if id := m.tax_code; id != nil { + ids = append(ids, *id) } - return oldValue.FeatureKey, nil + return } -// ClearFeatureKey clears the value of the "feature_key" field. -func (m *ChargeFlatFeeOverrideMutation) ClearFeatureKey() { - m.feature_key = nil - m.clearedFields[chargeflatfeeoverride.FieldFeatureKey] = struct{}{} +// ResetTaxCode resets all changes to the "tax_code" edge. +func (m *ChargeFlatFeeMutation) ResetTaxCode() { + m.tax_code = nil + m.clearedtax_code = false } -// FeatureKeyCleared returns if the "feature_key" field was cleared in this mutation. -func (m *ChargeFlatFeeOverrideMutation) FeatureKeyCleared() bool { - _, ok := m.clearedFields[chargeflatfeeoverride.FieldFeatureKey] - return ok +// ClearCustomCurrency clears the "custom_currency" edge to the CustomCurrency entity. +func (m *ChargeFlatFeeMutation) ClearCustomCurrency() { + m.clearedcustom_currency = true + m.clearedFields[chargeflatfee.FieldCustomCurrencyID] = struct{}{} } -// ResetFeatureKey resets all changes to the "feature_key" field. -func (m *ChargeFlatFeeOverrideMutation) ResetFeatureKey() { - m.feature_key = nil - delete(m.clearedFields, chargeflatfeeoverride.FieldFeatureKey) +// CustomCurrencyCleared reports if the "custom_currency" edge to the CustomCurrency entity was cleared. +func (m *ChargeFlatFeeMutation) CustomCurrencyCleared() bool { + return m.CustomCurrencyIDCleared() || m.clearedcustom_currency } -// SetPaymentTerm sets the "payment_term" field. -func (m *ChargeFlatFeeOverrideMutation) SetPaymentTerm(ptt productcatalog.PaymentTermType) { - m.payment_term = &ptt +// CustomCurrencyIDs returns the "custom_currency" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CustomCurrencyID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeMutation) CustomCurrencyIDs() (ids []string) { + if id := m.custom_currency; id != nil { + ids = append(ids, *id) + } + return } -// PaymentTerm returns the value of the "payment_term" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) PaymentTerm() (r productcatalog.PaymentTermType, exists bool) { - v := m.payment_term - if v == nil { - return - } - return *v, true -} - -// OldPaymentTerm returns the old "payment_term" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldPaymentTerm(ctx context.Context) (v productcatalog.PaymentTermType, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldPaymentTerm is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldPaymentTerm requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldPaymentTerm: %w", err) - } - return oldValue.PaymentTerm, nil -} - -// ResetPaymentTerm resets all changes to the "payment_term" field. -func (m *ChargeFlatFeeOverrideMutation) ResetPaymentTerm() { - m.payment_term = nil +// ResetCustomCurrency resets all changes to the "custom_currency" edge. +func (m *ChargeFlatFeeMutation) ResetCustomCurrency() { + m.custom_currency = nil + m.clearedcustom_currency = false } -// SetProRating sets the "pro_rating" field. -func (m *ChargeFlatFeeOverrideMutation) SetProRating(prc *productcatalog.ProRatingConfig) { - m.pro_rating = &prc +// Where appends a list predicates to the ChargeFlatFeeMutation builder. +func (m *ChargeFlatFeeMutation) Where(ps ...predicate.ChargeFlatFee) { + m.predicates = append(m.predicates, ps...) } -// ProRating returns the value of the "pro_rating" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) ProRating() (r *productcatalog.ProRatingConfig, exists bool) { - v := m.pro_rating - if v == nil { - return +// WhereP appends storage-level predicates to the ChargeFlatFeeMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ChargeFlatFeeMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeFlatFee, len(ps)) + for i := range ps { + p[i] = ps[i] } - return *v, true + m.Where(p...) } -// OldProRating returns the old "pro_rating" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldProRating(ctx context.Context) (v *productcatalog.ProRatingConfig, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldProRating is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldProRating requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldProRating: %w", err) - } - return oldValue.ProRating, nil +// Op returns the operation name. +func (m *ChargeFlatFeeMutation) Op() Op { + return m.op } -// ResetProRating resets all changes to the "pro_rating" field. -func (m *ChargeFlatFeeOverrideMutation) ResetProRating() { - m.pro_rating = nil +// SetOp allows setting the mutation operation. +func (m *ChargeFlatFeeMutation) SetOp(op Op) { + m.op = op } -// SetAmountBeforeProration sets the "amount_before_proration" field. -func (m *ChargeFlatFeeOverrideMutation) SetAmountBeforeProration(a alpacadecimal.Decimal) { - m.amount_before_proration = &a +// Type returns the node type of this mutation (ChargeFlatFee). +func (m *ChargeFlatFeeMutation) Type() string { + return m.typ } -// AmountBeforeProration returns the value of the "amount_before_proration" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) AmountBeforeProration() (r alpacadecimal.Decimal, exists bool) { - v := m.amount_before_proration - if v == nil { - return +// 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 *ChargeFlatFeeMutation) Fields() []string { + fields := make([]string, 0, 39) + if m.customer != nil { + fields = append(fields, chargeflatfee.FieldCustomerID) } - return *v, true -} - -// OldAmountBeforeProration returns the old "amount_before_proration" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldAmountBeforeProration(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAmountBeforeProration is only allowed on UpdateOne operations") + if m.service_period_from != nil { + fields = append(fields, chargeflatfee.FieldServicePeriodFrom) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAmountBeforeProration requires an ID field in the mutation") + if m.service_period_to != nil { + fields = append(fields, chargeflatfee.FieldServicePeriodTo) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldAmountBeforeProration: %w", err) + if m.billing_period_from != nil { + fields = append(fields, chargeflatfee.FieldBillingPeriodFrom) } - return oldValue.AmountBeforeProration, nil -} - -// ResetAmountBeforeProration resets all changes to the "amount_before_proration" field. -func (m *ChargeFlatFeeOverrideMutation) ResetAmountBeforeProration() { - m.amount_before_proration = nil -} - -// SetDiscounts sets the "discounts" field. -func (m *ChargeFlatFeeOverrideMutation) SetDiscounts(b *billing.Discounts) { - m.discounts = &b -} - -// Discounts returns the value of the "discounts" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) Discounts() (r *billing.Discounts, exists bool) { - v := m.discounts - if v == nil { - return + if m.billing_period_to != nil { + fields = append(fields, chargeflatfee.FieldBillingPeriodTo) } - return *v, true -} - -// OldDiscounts returns the old "discounts" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldDiscounts(ctx context.Context) (v *billing.Discounts, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDiscounts is only allowed on UpdateOne operations") + if m.full_service_period_from != nil { + fields = append(fields, chargeflatfee.FieldFullServicePeriodFrom) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDiscounts requires an ID field in the mutation") + if m.full_service_period_to != nil { + fields = append(fields, chargeflatfee.FieldFullServicePeriodTo) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDiscounts: %w", err) + if m.status != nil { + fields = append(fields, chargeflatfee.FieldStatus) } - return oldValue.Discounts, nil -} - -// ClearDiscounts clears the value of the "discounts" field. -func (m *ChargeFlatFeeOverrideMutation) ClearDiscounts() { - m.discounts = nil - m.clearedFields[chargeflatfeeoverride.FieldDiscounts] = struct{}{} -} - -// DiscountsCleared returns if the "discounts" field was cleared in this mutation. -func (m *ChargeFlatFeeOverrideMutation) DiscountsCleared() bool { - _, ok := m.clearedFields[chargeflatfeeoverride.FieldDiscounts] - return ok -} - -// ResetDiscounts resets all changes to the "discounts" field. -func (m *ChargeFlatFeeOverrideMutation) ResetDiscounts() { - m.discounts = nil - delete(m.clearedFields, chargeflatfeeoverride.FieldDiscounts) -} - -// SetPercentageDiscounts sets the "percentage_discounts" field. -func (m *ChargeFlatFeeOverrideMutation) SetPercentageDiscounts(bd *billing.PercentageDiscount) { - m.percentage_discounts = &bd -} - -// PercentageDiscounts returns the value of the "percentage_discounts" field in the mutation. -func (m *ChargeFlatFeeOverrideMutation) PercentageDiscounts() (r *billing.PercentageDiscount, exists bool) { - v := m.percentage_discounts - if v == nil { - return + if m.unique_reference_id != nil { + fields = append(fields, chargeflatfee.FieldUniqueReferenceID) } - return *v, true -} - -// OldPercentageDiscounts returns the old "percentage_discounts" field's value of the ChargeFlatFeeOverride entity. -// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldPercentageDiscounts(ctx context.Context) (v *billing.PercentageDiscount, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldPercentageDiscounts is only allowed on UpdateOne operations") + if m.fiat_currency_code != nil { + fields = append(fields, chargeflatfee.FieldFiatCurrencyCode) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldPercentageDiscounts requires an ID field in the mutation") + if m.custom_currency != nil { + fields = append(fields, chargeflatfee.FieldCustomCurrencyID) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldPercentageDiscounts: %w", err) + if m.managed_by != nil { + fields = append(fields, chargeflatfee.FieldManagedBy) } - return oldValue.PercentageDiscounts, nil -} - -// ClearPercentageDiscounts clears the value of the "percentage_discounts" field. -func (m *ChargeFlatFeeOverrideMutation) ClearPercentageDiscounts() { - m.percentage_discounts = nil - m.clearedFields[chargeflatfeeoverride.FieldPercentageDiscounts] = struct{}{} -} - -// PercentageDiscountsCleared returns if the "percentage_discounts" field was cleared in this mutation. -func (m *ChargeFlatFeeOverrideMutation) PercentageDiscountsCleared() bool { - _, ok := m.clearedFields[chargeflatfeeoverride.FieldPercentageDiscounts] - return ok -} - -// ResetPercentageDiscounts resets all changes to the "percentage_discounts" field. -func (m *ChargeFlatFeeOverrideMutation) ResetPercentageDiscounts() { - m.percentage_discounts = nil - delete(m.clearedFields, chargeflatfeeoverride.FieldPercentageDiscounts) -} - -// SetFlatFeeID sets the "flat_fee" edge to the ChargeFlatFee entity by id. -func (m *ChargeFlatFeeOverrideMutation) SetFlatFeeID(id string) { - m.flat_fee = &id -} - -// ClearFlatFee clears the "flat_fee" edge to the ChargeFlatFee entity. -func (m *ChargeFlatFeeOverrideMutation) ClearFlatFee() { - m.clearedflat_fee = true - m.clearedFields[chargeflatfeeoverride.FieldChargeID] = struct{}{} -} - -// FlatFeeCleared reports if the "flat_fee" edge to the ChargeFlatFee entity was cleared. -func (m *ChargeFlatFeeOverrideMutation) FlatFeeCleared() bool { - return m.clearedflat_fee -} - -// FlatFeeID returns the "flat_fee" edge ID in the mutation. -func (m *ChargeFlatFeeOverrideMutation) FlatFeeID() (id string, exists bool) { - if m.flat_fee != nil { - return *m.flat_fee, true + if m.subscription != nil { + fields = append(fields, chargeflatfee.FieldSubscriptionID) } - return -} - -// FlatFeeIDs returns the "flat_fee" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// FlatFeeID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeOverrideMutation) FlatFeeIDs() (ids []string) { - if id := m.flat_fee; id != nil { - ids = append(ids, *id) + if m.subscription_phase != nil { + fields = append(fields, chargeflatfee.FieldSubscriptionPhaseID) } - return -} - -// ResetFlatFee resets all changes to the "flat_fee" edge. -func (m *ChargeFlatFeeOverrideMutation) ResetFlatFee() { - m.flat_fee = nil - m.clearedflat_fee = false -} - -// ClearTaxCode clears the "tax_code" edge to the TaxCode entity. -func (m *ChargeFlatFeeOverrideMutation) ClearTaxCode() { - m.clearedtax_code = true - m.clearedFields[chargeflatfeeoverride.FieldTaxCodeID] = struct{}{} -} - -// TaxCodeCleared reports if the "tax_code" edge to the TaxCode entity was cleared. -func (m *ChargeFlatFeeOverrideMutation) 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 *ChargeFlatFeeOverrideMutation) TaxCodeIDs() (ids []string) { - if id := m.tax_code; id != nil { - ids = append(ids, *id) + if m.subscription_item != nil { + fields = append(fields, chargeflatfee.FieldSubscriptionItemID) } - return -} - -// ResetTaxCode resets all changes to the "tax_code" edge. -func (m *ChargeFlatFeeOverrideMutation) ResetTaxCode() { - m.tax_code = nil - m.clearedtax_code = false -} - -// Where appends a list predicates to the ChargeFlatFeeOverrideMutation builder. -func (m *ChargeFlatFeeOverrideMutation) Where(ps ...predicate.ChargeFlatFeeOverride) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the ChargeFlatFeeOverrideMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *ChargeFlatFeeOverrideMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.ChargeFlatFeeOverride, len(ps)) - for i := range ps { - p[i] = ps[i] + if m.advance_after != nil { + fields = append(fields, chargeflatfee.FieldAdvanceAfter) } - m.Where(p...) -} - -// Op returns the operation name. -func (m *ChargeFlatFeeOverrideMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *ChargeFlatFeeOverrideMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (ChargeFlatFeeOverride). -func (m *ChargeFlatFeeOverrideMutation) 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 *ChargeFlatFeeOverrideMutation) Fields() []string { - fields := make([]string, 0, 21) - if m.namespace != nil { - fields = append(fields, chargeflatfeeoverride.FieldNamespace) + if m.tax_code != nil { + fields = append(fields, chargeflatfee.FieldTaxCodeID) } - if m.flat_fee != nil { - fields = append(fields, chargeflatfeeoverride.FieldChargeID) + if m.tax_behavior != nil { + fields = append(fields, chargeflatfee.FieldTaxBehavior) } - if m.name != nil { - fields = append(fields, chargeflatfeeoverride.FieldName) + if m.annotations != nil { + fields = append(fields, chargeflatfee.FieldAnnotations) } - if m.description != nil { - fields = append(fields, chargeflatfeeoverride.FieldDescription) + if m.namespace != nil { + fields = append(fields, chargeflatfee.FieldNamespace) } if m.metadata != nil { - fields = append(fields, chargeflatfeeoverride.FieldMetadata) + fields = append(fields, chargeflatfee.FieldMetadata) } - if m.tax_behavior != nil { - fields = append(fields, chargeflatfeeoverride.FieldTaxBehavior) + if m.created_at != nil { + fields = append(fields, chargeflatfee.FieldCreatedAt) } - if m.tax_code != nil { - fields = append(fields, chargeflatfeeoverride.FieldTaxCodeID) + if m.updated_at != nil { + fields = append(fields, chargeflatfee.FieldUpdatedAt) } - if m.intent_deleted_at != nil { - fields = append(fields, chargeflatfeeoverride.FieldIntentDeletedAt) + if m.deleted_at != nil { + fields = append(fields, chargeflatfee.FieldDeletedAt) } - if m.service_period_from != nil { - fields = append(fields, chargeflatfeeoverride.FieldServicePeriodFrom) + if m.name != nil { + fields = append(fields, chargeflatfee.FieldName) } - if m.service_period_to != nil { - fields = append(fields, chargeflatfeeoverride.FieldServicePeriodTo) + if m.description != nil { + fields = append(fields, chargeflatfee.FieldDescription) } - if m.full_service_period_from != nil { - fields = append(fields, chargeflatfeeoverride.FieldFullServicePeriodFrom) + if m.payment_term != nil { + fields = append(fields, chargeflatfee.FieldPaymentTerm) } - if m.full_service_period_to != nil { - fields = append(fields, chargeflatfeeoverride.FieldFullServicePeriodTo) + if m.invoice_at != nil { + fields = append(fields, chargeflatfee.FieldInvoiceAt) } - if m.billing_period_from != nil { - fields = append(fields, chargeflatfeeoverride.FieldBillingPeriodFrom) + if m.settlement_mode != nil { + fields = append(fields, chargeflatfee.FieldSettlementMode) } - if m.billing_period_to != nil { - fields = append(fields, chargeflatfeeoverride.FieldBillingPeriodTo) + if m.intent_deleted_at != nil { + fields = append(fields, chargeflatfee.FieldIntentDeletedAt) } - if m.invoice_at != nil { - fields = append(fields, chargeflatfeeoverride.FieldInvoiceAt) + if m.discounts != nil { + fields = append(fields, chargeflatfee.FieldDiscounts) } - if m.feature_key != nil { - fields = append(fields, chargeflatfeeoverride.FieldFeatureKey) + if m.pro_rating != nil { + fields = append(fields, chargeflatfee.FieldProRating) } - if m.payment_term != nil { - fields = append(fields, chargeflatfeeoverride.FieldPaymentTerm) + if m.feature_key != nil { + fields = append(fields, chargeflatfee.FieldFeatureKey) } - if m.pro_rating != nil { - fields = append(fields, chargeflatfeeoverride.FieldProRating) + if m.feature != nil { + fields = append(fields, chargeflatfee.FieldFeatureID) } if m.amount_before_proration != nil { - fields = append(fields, chargeflatfeeoverride.FieldAmountBeforeProration) + fields = append(fields, chargeflatfee.FieldAmountBeforeProration) } - if m.discounts != nil { - fields = append(fields, chargeflatfeeoverride.FieldDiscounts) + if m.amount_after_proration != nil { + fields = append(fields, chargeflatfee.FieldAmountAfterProration) } - if m.percentage_discounts != nil { - fields = append(fields, chargeflatfeeoverride.FieldPercentageDiscounts) + if m.current_run != nil { + fields = append(fields, chargeflatfee.FieldCurrentRealizationRunID) + } + if m.cost_basis != nil { + fields = append(fields, chargeflatfee.FieldCostBasisID) + } + if m.status_detailed != nil { + fields = append(fields, chargeflatfee.FieldStatusDetailed) } return fields } @@ -50094,574 +49372,1056 @@ func (m *ChargeFlatFeeOverrideMutation) Fields() []string { // 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 *ChargeFlatFeeOverrideMutation) Field(name string) (ent.Value, bool) { +func (m *ChargeFlatFeeMutation) Field(name string) (ent.Value, bool) { switch name { - case chargeflatfeeoverride.FieldNamespace: - return m.Namespace() - case chargeflatfeeoverride.FieldChargeID: - return m.ChargeID() - case chargeflatfeeoverride.FieldName: - return m.Name() - case chargeflatfeeoverride.FieldDescription: - return m.Description() - case chargeflatfeeoverride.FieldMetadata: - return m.Metadata() - case chargeflatfeeoverride.FieldTaxBehavior: - return m.TaxBehavior() - case chargeflatfeeoverride.FieldTaxCodeID: - return m.TaxCodeID() - case chargeflatfeeoverride.FieldIntentDeletedAt: - return m.IntentDeletedAt() - case chargeflatfeeoverride.FieldServicePeriodFrom: + case chargeflatfee.FieldCustomerID: + return m.CustomerID() + case chargeflatfee.FieldServicePeriodFrom: return m.ServicePeriodFrom() - case chargeflatfeeoverride.FieldServicePeriodTo: + case chargeflatfee.FieldServicePeriodTo: return m.ServicePeriodTo() - case chargeflatfeeoverride.FieldFullServicePeriodFrom: - return m.FullServicePeriodFrom() - case chargeflatfeeoverride.FieldFullServicePeriodTo: - return m.FullServicePeriodTo() - case chargeflatfeeoverride.FieldBillingPeriodFrom: + case chargeflatfee.FieldBillingPeriodFrom: return m.BillingPeriodFrom() - case chargeflatfeeoverride.FieldBillingPeriodTo: + case chargeflatfee.FieldBillingPeriodTo: return m.BillingPeriodTo() - case chargeflatfeeoverride.FieldInvoiceAt: - return m.InvoiceAt() - case chargeflatfeeoverride.FieldFeatureKey: - return m.FeatureKey() - case chargeflatfeeoverride.FieldPaymentTerm: + case chargeflatfee.FieldFullServicePeriodFrom: + return m.FullServicePeriodFrom() + case chargeflatfee.FieldFullServicePeriodTo: + return m.FullServicePeriodTo() + case chargeflatfee.FieldStatus: + return m.Status() + case chargeflatfee.FieldUniqueReferenceID: + return m.UniqueReferenceID() + case chargeflatfee.FieldFiatCurrencyCode: + return m.FiatCurrencyCode() + case chargeflatfee.FieldCustomCurrencyID: + return m.CustomCurrencyID() + case chargeflatfee.FieldManagedBy: + return m.ManagedBy() + case chargeflatfee.FieldSubscriptionID: + return m.SubscriptionID() + case chargeflatfee.FieldSubscriptionPhaseID: + return m.SubscriptionPhaseID() + case chargeflatfee.FieldSubscriptionItemID: + return m.SubscriptionItemID() + case chargeflatfee.FieldAdvanceAfter: + return m.AdvanceAfter() + case chargeflatfee.FieldTaxCodeID: + return m.TaxCodeID() + case chargeflatfee.FieldTaxBehavior: + return m.TaxBehavior() + case chargeflatfee.FieldAnnotations: + return m.Annotations() + case chargeflatfee.FieldNamespace: + return m.Namespace() + case chargeflatfee.FieldMetadata: + return m.Metadata() + case chargeflatfee.FieldCreatedAt: + return m.CreatedAt() + case chargeflatfee.FieldUpdatedAt: + return m.UpdatedAt() + case chargeflatfee.FieldDeletedAt: + return m.DeletedAt() + case chargeflatfee.FieldName: + return m.Name() + case chargeflatfee.FieldDescription: + return m.Description() + case chargeflatfee.FieldPaymentTerm: return m.PaymentTerm() - case chargeflatfeeoverride.FieldProRating: - return m.ProRating() - case chargeflatfeeoverride.FieldAmountBeforeProration: - return m.AmountBeforeProration() - case chargeflatfeeoverride.FieldDiscounts: + case chargeflatfee.FieldInvoiceAt: + return m.InvoiceAt() + case chargeflatfee.FieldSettlementMode: + return m.SettlementMode() + case chargeflatfee.FieldIntentDeletedAt: + return m.IntentDeletedAt() + case chargeflatfee.FieldDiscounts: return m.Discounts() - case chargeflatfeeoverride.FieldPercentageDiscounts: - return m.PercentageDiscounts() - } + case chargeflatfee.FieldProRating: + return m.ProRating() + case chargeflatfee.FieldFeatureKey: + return m.FeatureKey() + case chargeflatfee.FieldFeatureID: + return m.FeatureID() + case chargeflatfee.FieldAmountBeforeProration: + return m.AmountBeforeProration() + case chargeflatfee.FieldAmountAfterProration: + return m.AmountAfterProration() + case chargeflatfee.FieldCurrentRealizationRunID: + return m.CurrentRealizationRunID() + case chargeflatfee.FieldCostBasisID: + return m.CostBasisID() + case chargeflatfee.FieldStatusDetailed: + return m.StatusDetailed() + } 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 *ChargeFlatFeeOverrideMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *ChargeFlatFeeMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case chargeflatfeeoverride.FieldNamespace: - return m.OldNamespace(ctx) - case chargeflatfeeoverride.FieldChargeID: - return m.OldChargeID(ctx) - case chargeflatfeeoverride.FieldName: - return m.OldName(ctx) - case chargeflatfeeoverride.FieldDescription: - return m.OldDescription(ctx) - case chargeflatfeeoverride.FieldMetadata: - return m.OldMetadata(ctx) - case chargeflatfeeoverride.FieldTaxBehavior: - return m.OldTaxBehavior(ctx) - case chargeflatfeeoverride.FieldTaxCodeID: - return m.OldTaxCodeID(ctx) - case chargeflatfeeoverride.FieldIntentDeletedAt: - return m.OldIntentDeletedAt(ctx) - case chargeflatfeeoverride.FieldServicePeriodFrom: + case chargeflatfee.FieldCustomerID: + return m.OldCustomerID(ctx) + case chargeflatfee.FieldServicePeriodFrom: return m.OldServicePeriodFrom(ctx) - case chargeflatfeeoverride.FieldServicePeriodTo: + case chargeflatfee.FieldServicePeriodTo: return m.OldServicePeriodTo(ctx) - case chargeflatfeeoverride.FieldFullServicePeriodFrom: - return m.OldFullServicePeriodFrom(ctx) - case chargeflatfeeoverride.FieldFullServicePeriodTo: - return m.OldFullServicePeriodTo(ctx) - case chargeflatfeeoverride.FieldBillingPeriodFrom: + case chargeflatfee.FieldBillingPeriodFrom: return m.OldBillingPeriodFrom(ctx) - case chargeflatfeeoverride.FieldBillingPeriodTo: + case chargeflatfee.FieldBillingPeriodTo: return m.OldBillingPeriodTo(ctx) - case chargeflatfeeoverride.FieldInvoiceAt: - return m.OldInvoiceAt(ctx) - case chargeflatfeeoverride.FieldFeatureKey: - return m.OldFeatureKey(ctx) - case chargeflatfeeoverride.FieldPaymentTerm: + case chargeflatfee.FieldFullServicePeriodFrom: + return m.OldFullServicePeriodFrom(ctx) + case chargeflatfee.FieldFullServicePeriodTo: + return m.OldFullServicePeriodTo(ctx) + case chargeflatfee.FieldStatus: + return m.OldStatus(ctx) + case chargeflatfee.FieldUniqueReferenceID: + return m.OldUniqueReferenceID(ctx) + case chargeflatfee.FieldFiatCurrencyCode: + return m.OldFiatCurrencyCode(ctx) + case chargeflatfee.FieldCustomCurrencyID: + return m.OldCustomCurrencyID(ctx) + case chargeflatfee.FieldManagedBy: + return m.OldManagedBy(ctx) + case chargeflatfee.FieldSubscriptionID: + return m.OldSubscriptionID(ctx) + case chargeflatfee.FieldSubscriptionPhaseID: + return m.OldSubscriptionPhaseID(ctx) + case chargeflatfee.FieldSubscriptionItemID: + return m.OldSubscriptionItemID(ctx) + case chargeflatfee.FieldAdvanceAfter: + return m.OldAdvanceAfter(ctx) + case chargeflatfee.FieldTaxCodeID: + return m.OldTaxCodeID(ctx) + case chargeflatfee.FieldTaxBehavior: + return m.OldTaxBehavior(ctx) + case chargeflatfee.FieldAnnotations: + return m.OldAnnotations(ctx) + case chargeflatfee.FieldNamespace: + return m.OldNamespace(ctx) + case chargeflatfee.FieldMetadata: + return m.OldMetadata(ctx) + case chargeflatfee.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case chargeflatfee.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case chargeflatfee.FieldDeletedAt: + return m.OldDeletedAt(ctx) + case chargeflatfee.FieldName: + return m.OldName(ctx) + case chargeflatfee.FieldDescription: + return m.OldDescription(ctx) + case chargeflatfee.FieldPaymentTerm: return m.OldPaymentTerm(ctx) - case chargeflatfeeoverride.FieldProRating: + case chargeflatfee.FieldInvoiceAt: + return m.OldInvoiceAt(ctx) + case chargeflatfee.FieldSettlementMode: + return m.OldSettlementMode(ctx) + case chargeflatfee.FieldIntentDeletedAt: + return m.OldIntentDeletedAt(ctx) + case chargeflatfee.FieldDiscounts: + return m.OldDiscounts(ctx) + case chargeflatfee.FieldProRating: return m.OldProRating(ctx) - case chargeflatfeeoverride.FieldAmountBeforeProration: + case chargeflatfee.FieldFeatureKey: + return m.OldFeatureKey(ctx) + case chargeflatfee.FieldFeatureID: + return m.OldFeatureID(ctx) + case chargeflatfee.FieldAmountBeforeProration: return m.OldAmountBeforeProration(ctx) - case chargeflatfeeoverride.FieldDiscounts: - return m.OldDiscounts(ctx) - case chargeflatfeeoverride.FieldPercentageDiscounts: - return m.OldPercentageDiscounts(ctx) + case chargeflatfee.FieldAmountAfterProration: + return m.OldAmountAfterProration(ctx) + case chargeflatfee.FieldCurrentRealizationRunID: + return m.OldCurrentRealizationRunID(ctx) + case chargeflatfee.FieldCostBasisID: + return m.OldCostBasisID(ctx) + case chargeflatfee.FieldStatusDetailed: + return m.OldStatusDetailed(ctx) } - return nil, fmt.Errorf("unknown ChargeFlatFeeOverride field %s", name) + return nil, fmt.Errorf("unknown ChargeFlatFee 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 *ChargeFlatFeeOverrideMutation) SetField(name string, value ent.Value) error { +func (m *ChargeFlatFeeMutation) SetField(name string, value ent.Value) error { switch name { - case chargeflatfeeoverride.FieldNamespace: + case chargeflatfee.FieldCustomerID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetNamespace(v) + m.SetCustomerID(v) return nil - case chargeflatfeeoverride.FieldChargeID: + case chargeflatfee.FieldServicePeriodFrom: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServicePeriodFrom(v) + return nil + case chargeflatfee.FieldServicePeriodTo: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServicePeriodTo(v) + return nil + case chargeflatfee.FieldBillingPeriodFrom: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBillingPeriodFrom(v) + return nil + case chargeflatfee.FieldBillingPeriodTo: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBillingPeriodTo(v) + return nil + case chargeflatfee.FieldFullServicePeriodFrom: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFullServicePeriodFrom(v) + return nil + case chargeflatfee.FieldFullServicePeriodTo: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFullServicePeriodTo(v) + return nil + case chargeflatfee.FieldStatus: + v, ok := value.(meta.ChargeStatus) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + case chargeflatfee.FieldUniqueReferenceID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetChargeID(v) + m.SetUniqueReferenceID(v) return nil - case chargeflatfeeoverride.FieldName: + case chargeflatfee.FieldFiatCurrencyCode: + v, ok := value.(currencyx.Code) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFiatCurrencyCode(v) + return nil + case chargeflatfee.FieldCustomCurrencyID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetName(v) + m.SetCustomCurrencyID(v) return nil - case chargeflatfeeoverride.FieldDescription: + case chargeflatfee.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 chargeflatfee.FieldSubscriptionID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDescription(v) + m.SetSubscriptionID(v) return nil - case chargeflatfeeoverride.FieldMetadata: - v, ok := value.(*models.Metadata) + case chargeflatfee.FieldSubscriptionPhaseID: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetMetadata(v) + m.SetSubscriptionPhaseID(v) return nil - case chargeflatfeeoverride.FieldTaxBehavior: - v, ok := value.(productcatalog.TaxBehavior) + case chargeflatfee.FieldSubscriptionItemID: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetTaxBehavior(v) + m.SetSubscriptionItemID(v) return nil - case chargeflatfeeoverride.FieldTaxCodeID: + case chargeflatfee.FieldAdvanceAfter: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAdvanceAfter(v) + return nil + case chargeflatfee.FieldTaxCodeID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTaxCodeID(v) return nil - case chargeflatfeeoverride.FieldIntentDeletedAt: - v, ok := value.(time.Time) + case chargeflatfee.FieldTaxBehavior: + v, ok := value.(productcatalog.TaxBehavior) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetIntentDeletedAt(v) + m.SetTaxBehavior(v) return nil - case chargeflatfeeoverride.FieldServicePeriodFrom: - v, ok := value.(time.Time) + case chargeflatfee.FieldAnnotations: + v, ok := value.(models.Annotations) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetServicePeriodFrom(v) + m.SetAnnotations(v) return nil - case chargeflatfeeoverride.FieldServicePeriodTo: - v, ok := value.(time.Time) + case chargeflatfee.FieldNamespace: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetServicePeriodTo(v) + m.SetNamespace(v) return nil - case chargeflatfeeoverride.FieldFullServicePeriodFrom: - v, ok := value.(time.Time) + case chargeflatfee.FieldMetadata: + v, ok := value.(map[string]string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetFullServicePeriodFrom(v) + m.SetMetadata(v) return nil - case chargeflatfeeoverride.FieldFullServicePeriodTo: + case chargeflatfee.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetFullServicePeriodTo(v) + m.SetCreatedAt(v) return nil - case chargeflatfeeoverride.FieldBillingPeriodFrom: + case chargeflatfee.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetBillingPeriodFrom(v) + m.SetUpdatedAt(v) return nil - case chargeflatfeeoverride.FieldBillingPeriodTo: + case chargeflatfee.FieldDeletedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetBillingPeriodTo(v) + m.SetDeletedAt(v) return nil - case chargeflatfeeoverride.FieldInvoiceAt: - v, ok := value.(time.Time) + case chargeflatfee.FieldName: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetInvoiceAt(v) + m.SetName(v) return nil - case chargeflatfeeoverride.FieldFeatureKey: + case chargeflatfee.FieldDescription: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetFeatureKey(v) + m.SetDescription(v) return nil - case chargeflatfeeoverride.FieldPaymentTerm: + case chargeflatfee.FieldPaymentTerm: v, ok := value.(productcatalog.PaymentTermType) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPaymentTerm(v) return nil - case chargeflatfeeoverride.FieldProRating: - v, ok := value.(*productcatalog.ProRatingConfig) + case chargeflatfee.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 chargeflatfee.FieldSettlementMode: + v, ok := value.(productcatalog.SettlementMode) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSettlementMode(v) + return nil + case chargeflatfee.FieldIntentDeletedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIntentDeletedAt(v) + return nil + case chargeflatfee.FieldDiscounts: + v, ok := value.(*billing.Discounts) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDiscounts(v) + return nil + case chargeflatfee.FieldProRating: + v, ok := value.(flatfee.ProRatingModeAdapterEnum) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetProRating(v) return nil - case chargeflatfeeoverride.FieldAmountBeforeProration: + case chargeflatfee.FieldFeatureKey: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFeatureKey(v) + return nil + case chargeflatfee.FieldFeatureID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFeatureID(v) + return nil + case chargeflatfee.FieldAmountBeforeProration: v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAmountBeforeProration(v) return nil - case chargeflatfeeoverride.FieldDiscounts: - v, ok := value.(*billing.Discounts) + case chargeflatfee.FieldAmountAfterProration: + v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDiscounts(v) + m.SetAmountAfterProration(v) return nil - case chargeflatfeeoverride.FieldPercentageDiscounts: - v, ok := value.(*billing.PercentageDiscount) + case chargeflatfee.FieldCurrentRealizationRunID: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetPercentageDiscounts(v) + m.SetCurrentRealizationRunID(v) + return nil + case chargeflatfee.FieldCostBasisID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCostBasisID(v) + return nil + case chargeflatfee.FieldStatusDetailed: + v, ok := value.(flatfee.Status) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatusDetailed(v) return nil } - return fmt.Errorf("unknown ChargeFlatFeeOverride field %s", name) + return fmt.Errorf("unknown ChargeFlatFee field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *ChargeFlatFeeOverrideMutation) AddedFields() []string { +func (m *ChargeFlatFeeMutation) 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 *ChargeFlatFeeOverrideMutation) AddedField(name string) (ent.Value, bool) { +func (m *ChargeFlatFeeMutation) 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 *ChargeFlatFeeOverrideMutation) AddField(name string, value ent.Value) error { +func (m *ChargeFlatFeeMutation) AddField(name string, value ent.Value) error { switch name { } - return fmt.Errorf("unknown ChargeFlatFeeOverride numeric field %s", name) + return fmt.Errorf("unknown ChargeFlatFee numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *ChargeFlatFeeOverrideMutation) ClearedFields() []string { +func (m *ChargeFlatFeeMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(chargeflatfeeoverride.FieldDescription) { - fields = append(fields, chargeflatfeeoverride.FieldDescription) + if m.FieldCleared(chargeflatfee.FieldUniqueReferenceID) { + fields = append(fields, chargeflatfee.FieldUniqueReferenceID) } - if m.FieldCleared(chargeflatfeeoverride.FieldMetadata) { - fields = append(fields, chargeflatfeeoverride.FieldMetadata) + if m.FieldCleared(chargeflatfee.FieldFiatCurrencyCode) { + fields = append(fields, chargeflatfee.FieldFiatCurrencyCode) } - if m.FieldCleared(chargeflatfeeoverride.FieldTaxBehavior) { - fields = append(fields, chargeflatfeeoverride.FieldTaxBehavior) + if m.FieldCleared(chargeflatfee.FieldCustomCurrencyID) { + fields = append(fields, chargeflatfee.FieldCustomCurrencyID) } - if m.FieldCleared(chargeflatfeeoverride.FieldTaxCodeID) { - fields = append(fields, chargeflatfeeoverride.FieldTaxCodeID) + if m.FieldCleared(chargeflatfee.FieldSubscriptionID) { + fields = append(fields, chargeflatfee.FieldSubscriptionID) } - if m.FieldCleared(chargeflatfeeoverride.FieldIntentDeletedAt) { - fields = append(fields, chargeflatfeeoverride.FieldIntentDeletedAt) + if m.FieldCleared(chargeflatfee.FieldSubscriptionPhaseID) { + fields = append(fields, chargeflatfee.FieldSubscriptionPhaseID) } - if m.FieldCleared(chargeflatfeeoverride.FieldFeatureKey) { - fields = append(fields, chargeflatfeeoverride.FieldFeatureKey) + if m.FieldCleared(chargeflatfee.FieldSubscriptionItemID) { + fields = append(fields, chargeflatfee.FieldSubscriptionItemID) } - if m.FieldCleared(chargeflatfeeoverride.FieldDiscounts) { - fields = append(fields, chargeflatfeeoverride.FieldDiscounts) + if m.FieldCleared(chargeflatfee.FieldAdvanceAfter) { + fields = append(fields, chargeflatfee.FieldAdvanceAfter) } - if m.FieldCleared(chargeflatfeeoverride.FieldPercentageDiscounts) { - fields = append(fields, chargeflatfeeoverride.FieldPercentageDiscounts) + if m.FieldCleared(chargeflatfee.FieldTaxBehavior) { + fields = append(fields, chargeflatfee.FieldTaxBehavior) + } + if m.FieldCleared(chargeflatfee.FieldAnnotations) { + fields = append(fields, chargeflatfee.FieldAnnotations) + } + if m.FieldCleared(chargeflatfee.FieldMetadata) { + fields = append(fields, chargeflatfee.FieldMetadata) + } + if m.FieldCleared(chargeflatfee.FieldDeletedAt) { + fields = append(fields, chargeflatfee.FieldDeletedAt) + } + if m.FieldCleared(chargeflatfee.FieldDescription) { + fields = append(fields, chargeflatfee.FieldDescription) + } + if m.FieldCleared(chargeflatfee.FieldIntentDeletedAt) { + fields = append(fields, chargeflatfee.FieldIntentDeletedAt) + } + if m.FieldCleared(chargeflatfee.FieldDiscounts) { + fields = append(fields, chargeflatfee.FieldDiscounts) + } + if m.FieldCleared(chargeflatfee.FieldFeatureKey) { + fields = append(fields, chargeflatfee.FieldFeatureKey) + } + if m.FieldCleared(chargeflatfee.FieldFeatureID) { + fields = append(fields, chargeflatfee.FieldFeatureID) + } + if m.FieldCleared(chargeflatfee.FieldCurrentRealizationRunID) { + fields = append(fields, chargeflatfee.FieldCurrentRealizationRunID) + } + if m.FieldCleared(chargeflatfee.FieldCostBasisID) { + fields = append(fields, chargeflatfee.FieldCostBasisID) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *ChargeFlatFeeOverrideMutation) FieldCleared(name string) bool { +func (m *ChargeFlatFeeMutation) 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 *ChargeFlatFeeOverrideMutation) ClearField(name string) error { +func (m *ChargeFlatFeeMutation) ClearField(name string) error { switch name { - case chargeflatfeeoverride.FieldDescription: - m.ClearDescription() + case chargeflatfee.FieldUniqueReferenceID: + m.ClearUniqueReferenceID() return nil - case chargeflatfeeoverride.FieldMetadata: - m.ClearMetadata() + case chargeflatfee.FieldFiatCurrencyCode: + m.ClearFiatCurrencyCode() return nil - case chargeflatfeeoverride.FieldTaxBehavior: + case chargeflatfee.FieldCustomCurrencyID: + m.ClearCustomCurrencyID() + return nil + case chargeflatfee.FieldSubscriptionID: + m.ClearSubscriptionID() + return nil + case chargeflatfee.FieldSubscriptionPhaseID: + m.ClearSubscriptionPhaseID() + return nil + case chargeflatfee.FieldSubscriptionItemID: + m.ClearSubscriptionItemID() + return nil + case chargeflatfee.FieldAdvanceAfter: + m.ClearAdvanceAfter() + return nil + case chargeflatfee.FieldTaxBehavior: m.ClearTaxBehavior() return nil - case chargeflatfeeoverride.FieldTaxCodeID: - m.ClearTaxCodeID() + case chargeflatfee.FieldAnnotations: + m.ClearAnnotations() return nil - case chargeflatfeeoverride.FieldIntentDeletedAt: + case chargeflatfee.FieldMetadata: + m.ClearMetadata() + return nil + case chargeflatfee.FieldDeletedAt: + m.ClearDeletedAt() + return nil + case chargeflatfee.FieldDescription: + m.ClearDescription() + return nil + case chargeflatfee.FieldIntentDeletedAt: m.ClearIntentDeletedAt() return nil - case chargeflatfeeoverride.FieldFeatureKey: + case chargeflatfee.FieldDiscounts: + m.ClearDiscounts() + return nil + case chargeflatfee.FieldFeatureKey: m.ClearFeatureKey() return nil - case chargeflatfeeoverride.FieldDiscounts: - m.ClearDiscounts() + case chargeflatfee.FieldFeatureID: + m.ClearFeatureID() return nil - case chargeflatfeeoverride.FieldPercentageDiscounts: - m.ClearPercentageDiscounts() + case chargeflatfee.FieldCurrentRealizationRunID: + m.ClearCurrentRealizationRunID() + return nil + case chargeflatfee.FieldCostBasisID: + m.ClearCostBasisID() return nil } - return fmt.Errorf("unknown ChargeFlatFeeOverride nullable field %s", name) + return fmt.Errorf("unknown ChargeFlatFee 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 *ChargeFlatFeeOverrideMutation) ResetField(name string) error { +func (m *ChargeFlatFeeMutation) ResetField(name string) error { switch name { - case chargeflatfeeoverride.FieldNamespace: - m.ResetNamespace() + case chargeflatfee.FieldCustomerID: + m.ResetCustomerID() return nil - case chargeflatfeeoverride.FieldChargeID: - m.ResetChargeID() + case chargeflatfee.FieldServicePeriodFrom: + m.ResetServicePeriodFrom() return nil - case chargeflatfeeoverride.FieldName: - m.ResetName() + case chargeflatfee.FieldServicePeriodTo: + m.ResetServicePeriodTo() return nil - case chargeflatfeeoverride.FieldDescription: - m.ResetDescription() + case chargeflatfee.FieldBillingPeriodFrom: + m.ResetBillingPeriodFrom() return nil - case chargeflatfeeoverride.FieldMetadata: - m.ResetMetadata() + case chargeflatfee.FieldBillingPeriodTo: + m.ResetBillingPeriodTo() return nil - case chargeflatfeeoverride.FieldTaxBehavior: - m.ResetTaxBehavior() + case chargeflatfee.FieldFullServicePeriodFrom: + m.ResetFullServicePeriodFrom() return nil - case chargeflatfeeoverride.FieldTaxCodeID: - m.ResetTaxCodeID() + case chargeflatfee.FieldFullServicePeriodTo: + m.ResetFullServicePeriodTo() return nil - case chargeflatfeeoverride.FieldIntentDeletedAt: - m.ResetIntentDeletedAt() + case chargeflatfee.FieldStatus: + m.ResetStatus() return nil - case chargeflatfeeoverride.FieldServicePeriodFrom: - m.ResetServicePeriodFrom() + case chargeflatfee.FieldUniqueReferenceID: + m.ResetUniqueReferenceID() return nil - case chargeflatfeeoverride.FieldServicePeriodTo: - m.ResetServicePeriodTo() + case chargeflatfee.FieldFiatCurrencyCode: + m.ResetFiatCurrencyCode() return nil - case chargeflatfeeoverride.FieldFullServicePeriodFrom: - m.ResetFullServicePeriodFrom() + case chargeflatfee.FieldCustomCurrencyID: + m.ResetCustomCurrencyID() return nil - case chargeflatfeeoverride.FieldFullServicePeriodTo: - m.ResetFullServicePeriodTo() + case chargeflatfee.FieldManagedBy: + m.ResetManagedBy() return nil - case chargeflatfeeoverride.FieldBillingPeriodFrom: - m.ResetBillingPeriodFrom() + case chargeflatfee.FieldSubscriptionID: + m.ResetSubscriptionID() return nil - case chargeflatfeeoverride.FieldBillingPeriodTo: - m.ResetBillingPeriodTo() + case chargeflatfee.FieldSubscriptionPhaseID: + m.ResetSubscriptionPhaseID() return nil - case chargeflatfeeoverride.FieldInvoiceAt: - m.ResetInvoiceAt() + case chargeflatfee.FieldSubscriptionItemID: + m.ResetSubscriptionItemID() return nil - case chargeflatfeeoverride.FieldFeatureKey: - m.ResetFeatureKey() + case chargeflatfee.FieldAdvanceAfter: + m.ResetAdvanceAfter() return nil - case chargeflatfeeoverride.FieldPaymentTerm: + case chargeflatfee.FieldTaxCodeID: + m.ResetTaxCodeID() + return nil + case chargeflatfee.FieldTaxBehavior: + m.ResetTaxBehavior() + return nil + case chargeflatfee.FieldAnnotations: + m.ResetAnnotations() + return nil + case chargeflatfee.FieldNamespace: + m.ResetNamespace() + return nil + case chargeflatfee.FieldMetadata: + m.ResetMetadata() + return nil + case chargeflatfee.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case chargeflatfee.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case chargeflatfee.FieldDeletedAt: + m.ResetDeletedAt() + return nil + case chargeflatfee.FieldName: + m.ResetName() + return nil + case chargeflatfee.FieldDescription: + m.ResetDescription() + return nil + case chargeflatfee.FieldPaymentTerm: m.ResetPaymentTerm() return nil - case chargeflatfeeoverride.FieldProRating: + case chargeflatfee.FieldInvoiceAt: + m.ResetInvoiceAt() + return nil + case chargeflatfee.FieldSettlementMode: + m.ResetSettlementMode() + return nil + case chargeflatfee.FieldIntentDeletedAt: + m.ResetIntentDeletedAt() + return nil + case chargeflatfee.FieldDiscounts: + m.ResetDiscounts() + return nil + case chargeflatfee.FieldProRating: m.ResetProRating() return nil - case chargeflatfeeoverride.FieldAmountBeforeProration: + case chargeflatfee.FieldFeatureKey: + m.ResetFeatureKey() + return nil + case chargeflatfee.FieldFeatureID: + m.ResetFeatureID() + return nil + case chargeflatfee.FieldAmountBeforeProration: m.ResetAmountBeforeProration() return nil - case chargeflatfeeoverride.FieldDiscounts: - m.ResetDiscounts() + case chargeflatfee.FieldAmountAfterProration: + m.ResetAmountAfterProration() return nil - case chargeflatfeeoverride.FieldPercentageDiscounts: - m.ResetPercentageDiscounts() + case chargeflatfee.FieldCurrentRealizationRunID: + m.ResetCurrentRealizationRunID() + return nil + case chargeflatfee.FieldCostBasisID: + m.ResetCostBasisID() + return nil + case chargeflatfee.FieldStatusDetailed: + m.ResetStatusDetailed() return nil } - return fmt.Errorf("unknown ChargeFlatFeeOverride field %s", name) + return fmt.Errorf("unknown ChargeFlatFee field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *ChargeFlatFeeOverrideMutation) AddedEdges() []string { - edges := make([]string, 0, 2) - if m.flat_fee != nil { - edges = append(edges, chargeflatfeeoverride.EdgeFlatFee) +func (m *ChargeFlatFeeMutation) AddedEdges() []string { + edges := make([]string, 0, 12) + if m.runs != nil { + edges = append(edges, chargeflatfee.EdgeRuns) + } + if m.current_run != nil { + edges = append(edges, chargeflatfee.EdgeCurrentRun) + } + if m.cost_basis != nil { + edges = append(edges, chargeflatfee.EdgeCostBasis) + } + if m.charge != nil { + edges = append(edges, chargeflatfee.EdgeCharge) + } + if m.intent_override != nil { + edges = append(edges, chargeflatfee.EdgeIntentOverride) + } + if m.subscription != nil { + edges = append(edges, chargeflatfee.EdgeSubscription) + } + if m.subscription_phase != nil { + edges = append(edges, chargeflatfee.EdgeSubscriptionPhase) + } + if m.subscription_item != nil { + edges = append(edges, chargeflatfee.EdgeSubscriptionItem) + } + if m.customer != nil { + edges = append(edges, chargeflatfee.EdgeCustomer) + } + if m.feature != nil { + edges = append(edges, chargeflatfee.EdgeFeature) } if m.tax_code != nil { - edges = append(edges, chargeflatfeeoverride.EdgeTaxCode) + edges = append(edges, chargeflatfee.EdgeTaxCode) + } + if m.custom_currency != nil { + edges = append(edges, chargeflatfee.EdgeCustomCurrency) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *ChargeFlatFeeOverrideMutation) AddedIDs(name string) []ent.Value { +func (m *ChargeFlatFeeMutation) AddedIDs(name string) []ent.Value { switch name { - case chargeflatfeeoverride.EdgeFlatFee: - if id := m.flat_fee; id != nil { + case chargeflatfee.EdgeRuns: + ids := make([]ent.Value, 0, len(m.runs)) + for id := range m.runs { + ids = append(ids, id) + } + return ids + case chargeflatfee.EdgeCurrentRun: + if id := m.current_run; id != nil { return []ent.Value{*id} } - case chargeflatfeeoverride.EdgeTaxCode: + case chargeflatfee.EdgeCostBasis: + if id := m.cost_basis; id != nil { + return []ent.Value{*id} + } + case chargeflatfee.EdgeCharge: + if id := m.charge; id != nil { + return []ent.Value{*id} + } + case chargeflatfee.EdgeIntentOverride: + if id := m.intent_override; id != nil { + return []ent.Value{*id} + } + case chargeflatfee.EdgeSubscription: + if id := m.subscription; id != nil { + return []ent.Value{*id} + } + case chargeflatfee.EdgeSubscriptionPhase: + if id := m.subscription_phase; id != nil { + return []ent.Value{*id} + } + case chargeflatfee.EdgeSubscriptionItem: + if id := m.subscription_item; id != nil { + return []ent.Value{*id} + } + case chargeflatfee.EdgeCustomer: + if id := m.customer; id != nil { + return []ent.Value{*id} + } + case chargeflatfee.EdgeFeature: + if id := m.feature; id != nil { + return []ent.Value{*id} + } + case chargeflatfee.EdgeTaxCode: if id := m.tax_code; id != nil { return []ent.Value{*id} } + case chargeflatfee.EdgeCustomCurrency: + if id := m.custom_currency; id != nil { + return []ent.Value{*id} + } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *ChargeFlatFeeOverrideMutation) RemovedEdges() []string { - edges := make([]string, 0, 2) +func (m *ChargeFlatFeeMutation) RemovedEdges() []string { + edges := make([]string, 0, 12) + if m.removedruns != nil { + edges = append(edges, chargeflatfee.EdgeRuns) + } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *ChargeFlatFeeOverrideMutation) RemovedIDs(name string) []ent.Value { +func (m *ChargeFlatFeeMutation) RemovedIDs(name string) []ent.Value { + switch name { + case chargeflatfee.EdgeRuns: + ids := make([]ent.Value, 0, len(m.removedruns)) + for id := range m.removedruns { + ids = append(ids, id) + } + return ids + } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ChargeFlatFeeOverrideMutation) ClearedEdges() []string { - edges := make([]string, 0, 2) - if m.clearedflat_fee { - edges = append(edges, chargeflatfeeoverride.EdgeFlatFee) +func (m *ChargeFlatFeeMutation) ClearedEdges() []string { + edges := make([]string, 0, 12) + if m.clearedruns { + edges = append(edges, chargeflatfee.EdgeRuns) + } + if m.clearedcurrent_run { + edges = append(edges, chargeflatfee.EdgeCurrentRun) + } + if m.clearedcost_basis { + edges = append(edges, chargeflatfee.EdgeCostBasis) + } + if m.clearedcharge { + edges = append(edges, chargeflatfee.EdgeCharge) + } + if m.clearedintent_override { + edges = append(edges, chargeflatfee.EdgeIntentOverride) + } + if m.clearedsubscription { + edges = append(edges, chargeflatfee.EdgeSubscription) + } + if m.clearedsubscription_phase { + edges = append(edges, chargeflatfee.EdgeSubscriptionPhase) + } + if m.clearedsubscription_item { + edges = append(edges, chargeflatfee.EdgeSubscriptionItem) + } + if m.clearedcustomer { + edges = append(edges, chargeflatfee.EdgeCustomer) + } + if m.clearedfeature { + edges = append(edges, chargeflatfee.EdgeFeature) } if m.clearedtax_code { - edges = append(edges, chargeflatfeeoverride.EdgeTaxCode) + edges = append(edges, chargeflatfee.EdgeTaxCode) + } + if m.clearedcustom_currency { + edges = append(edges, chargeflatfee.EdgeCustomCurrency) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *ChargeFlatFeeOverrideMutation) EdgeCleared(name string) bool { +func (m *ChargeFlatFeeMutation) EdgeCleared(name string) bool { switch name { - case chargeflatfeeoverride.EdgeFlatFee: - return m.clearedflat_fee - case chargeflatfeeoverride.EdgeTaxCode: + case chargeflatfee.EdgeRuns: + return m.clearedruns + case chargeflatfee.EdgeCurrentRun: + return m.clearedcurrent_run + case chargeflatfee.EdgeCostBasis: + return m.clearedcost_basis + case chargeflatfee.EdgeCharge: + return m.clearedcharge + case chargeflatfee.EdgeIntentOverride: + return m.clearedintent_override + case chargeflatfee.EdgeSubscription: + return m.clearedsubscription + case chargeflatfee.EdgeSubscriptionPhase: + return m.clearedsubscription_phase + case chargeflatfee.EdgeSubscriptionItem: + return m.clearedsubscription_item + case chargeflatfee.EdgeCustomer: + return m.clearedcustomer + case chargeflatfee.EdgeFeature: + return m.clearedfeature + case chargeflatfee.EdgeTaxCode: return m.clearedtax_code + case chargeflatfee.EdgeCustomCurrency: + return m.clearedcustom_currency } 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 *ChargeFlatFeeOverrideMutation) ClearEdge(name string) error { +func (m *ChargeFlatFeeMutation) ClearEdge(name string) error { switch name { - case chargeflatfeeoverride.EdgeFlatFee: - m.ClearFlatFee() + case chargeflatfee.EdgeCurrentRun: + m.ClearCurrentRun() return nil - case chargeflatfeeoverride.EdgeTaxCode: + case chargeflatfee.EdgeCostBasis: + m.ClearCostBasis() + return nil + case chargeflatfee.EdgeCharge: + m.ClearCharge() + return nil + case chargeflatfee.EdgeIntentOverride: + m.ClearIntentOverride() + return nil + case chargeflatfee.EdgeSubscription: + m.ClearSubscription() + return nil + case chargeflatfee.EdgeSubscriptionPhase: + m.ClearSubscriptionPhase() + return nil + case chargeflatfee.EdgeSubscriptionItem: + m.ClearSubscriptionItem() + return nil + case chargeflatfee.EdgeCustomer: + m.ClearCustomer() + return nil + case chargeflatfee.EdgeFeature: + m.ClearFeature() + return nil + case chargeflatfee.EdgeTaxCode: m.ClearTaxCode() return nil + case chargeflatfee.EdgeCustomCurrency: + m.ClearCustomCurrency() + return nil } - return fmt.Errorf("unknown ChargeFlatFeeOverride unique edge %s", name) + return fmt.Errorf("unknown ChargeFlatFee 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 *ChargeFlatFeeOverrideMutation) ResetEdge(name string) error { +func (m *ChargeFlatFeeMutation) ResetEdge(name string) error { switch name { - case chargeflatfeeoverride.EdgeFlatFee: - m.ResetFlatFee() + case chargeflatfee.EdgeRuns: + m.ResetRuns() return nil - case chargeflatfeeoverride.EdgeTaxCode: + case chargeflatfee.EdgeCurrentRun: + m.ResetCurrentRun() + return nil + case chargeflatfee.EdgeCostBasis: + m.ResetCostBasis() + return nil + case chargeflatfee.EdgeCharge: + m.ResetCharge() + return nil + case chargeflatfee.EdgeIntentOverride: + m.ResetIntentOverride() + return nil + case chargeflatfee.EdgeSubscription: + m.ResetSubscription() + return nil + case chargeflatfee.EdgeSubscriptionPhase: + m.ResetSubscriptionPhase() + return nil + case chargeflatfee.EdgeSubscriptionItem: + m.ResetSubscriptionItem() + return nil + case chargeflatfee.EdgeCustomer: + m.ResetCustomer() + return nil + case chargeflatfee.EdgeFeature: + m.ResetFeature() + return nil + case chargeflatfee.EdgeTaxCode: m.ResetTaxCode() return nil + case chargeflatfee.EdgeCustomCurrency: + m.ResetCustomCurrency() + return nil } - return fmt.Errorf("unknown ChargeFlatFeeOverride edge %s", name) + return fmt.Errorf("unknown ChargeFlatFee edge %s", name) } -// ChargeFlatFeeRunMutation represents an operation that mutates the ChargeFlatFeeRun nodes in the graph. -type ChargeFlatFeeRunMutation struct { +// ChargeFlatFeeCostBasisMutation represents an operation that mutates the ChargeFlatFeeCostBasis nodes in the graph. +type ChargeFlatFeeCostBasisMutation struct { config - op Op - typ string - id *string - namespace *string - created_at *time.Time - updated_at *time.Time - deleted_at *time.Time - amount *alpacadecimal.Decimal - taxes_total *alpacadecimal.Decimal - taxes_inclusive_total *alpacadecimal.Decimal - taxes_exclusive_total *alpacadecimal.Decimal - charges_total *alpacadecimal.Decimal - discounts_total *alpacadecimal.Decimal - credits_total *alpacadecimal.Decimal - total *alpacadecimal.Decimal - _type *flatfee.RealizationRunType - initial_type *flatfee.RealizationRunType - service_period_from *time.Time - service_period_to *time.Time - amount_after_proration *alpacadecimal.Decimal - no_fiat_transaction_required *bool - immutable *bool - clearedFields map[string]struct{} - flat_fee *string - clearedflat_fee bool - billing_invoice_line *string - clearedbilling_invoice_line bool - billing_invoice *string - clearedbilling_invoice bool - credit_allocations map[string]struct{} - removedcredit_allocations map[string]struct{} - clearedcredit_allocations bool - detailed_lines map[string]struct{} - removeddetailed_lines map[string]struct{} - cleareddetailed_lines bool - invoiced_usage *string - clearedinvoiced_usage bool - payment *string - clearedpayment bool - done bool - oldValue func(context.Context) (*ChargeFlatFeeRun, error) - predicates []predicate.ChargeFlatFeeRun + op Op + typ string + id *string + mode *costbasis.Mode + fiat_currency *currencyx.FiatCode + manual_rate *alpacadecimal.Decimal + resolved_cost_basis *alpacadecimal.Decimal + resolved_at *time.Time + namespace *string + created_at *time.Time + updated_at *time.Time + deleted_at *time.Time + clearedFields map[string]struct{} + currency_cost_basis *string + clearedcurrency_cost_basis bool + resolved_currency_cost_basis *string + clearedresolved_currency_cost_basis bool + custom_currency *string + clearedcustom_currency bool + done bool + oldValue func(context.Context) (*ChargeFlatFeeCostBasis, error) + predicates []predicate.ChargeFlatFeeCostBasis } -var _ ent.Mutation = (*ChargeFlatFeeRunMutation)(nil) +var _ ent.Mutation = (*ChargeFlatFeeCostBasisMutation)(nil) -// chargeflatfeerunOption allows management of the mutation configuration using functional options. -type chargeflatfeerunOption func(*ChargeFlatFeeRunMutation) +// chargeflatfeecostbasisOption allows management of the mutation configuration using functional options. +type chargeflatfeecostbasisOption func(*ChargeFlatFeeCostBasisMutation) -// newChargeFlatFeeRunMutation creates new mutation for the ChargeFlatFeeRun entity. -func newChargeFlatFeeRunMutation(c config, op Op, opts ...chargeflatfeerunOption) *ChargeFlatFeeRunMutation { - m := &ChargeFlatFeeRunMutation{ +// newChargeFlatFeeCostBasisMutation creates new mutation for the ChargeFlatFeeCostBasis entity. +func newChargeFlatFeeCostBasisMutation(c config, op Op, opts ...chargeflatfeecostbasisOption) *ChargeFlatFeeCostBasisMutation { + m := &ChargeFlatFeeCostBasisMutation{ config: c, op: op, - typ: TypeChargeFlatFeeRun, + typ: TypeChargeFlatFeeCostBasis, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -50670,20 +50430,20 @@ func newChargeFlatFeeRunMutation(c config, op Op, opts ...chargeflatfeerunOption return m } -// withChargeFlatFeeRunID sets the ID field of the mutation. -func withChargeFlatFeeRunID(id string) chargeflatfeerunOption { - return func(m *ChargeFlatFeeRunMutation) { +// withChargeFlatFeeCostBasisID sets the ID field of the mutation. +func withChargeFlatFeeCostBasisID(id string) chargeflatfeecostbasisOption { + return func(m *ChargeFlatFeeCostBasisMutation) { var ( err error once sync.Once - value *ChargeFlatFeeRun + value *ChargeFlatFeeCostBasis ) - m.oldValue = func(ctx context.Context) (*ChargeFlatFeeRun, error) { + m.oldValue = func(ctx context.Context) (*ChargeFlatFeeCostBasis, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { - value, err = m.Client().ChargeFlatFeeRun.Get(ctx, id) + value, err = m.Client().ChargeFlatFeeCostBasis.Get(ctx, id) } }) return value, err @@ -50692,10 +50452,10 @@ func withChargeFlatFeeRunID(id string) chargeflatfeerunOption { } } -// withChargeFlatFeeRun sets the old ChargeFlatFeeRun of the mutation. -func withChargeFlatFeeRun(node *ChargeFlatFeeRun) chargeflatfeerunOption { - return func(m *ChargeFlatFeeRunMutation) { - m.oldValue = func(context.Context) (*ChargeFlatFeeRun, error) { +// withChargeFlatFeeCostBasis sets the old ChargeFlatFeeCostBasis of the mutation. +func withChargeFlatFeeCostBasis(node *ChargeFlatFeeCostBasis) chargeflatfeecostbasisOption { + return func(m *ChargeFlatFeeCostBasisMutation) { + m.oldValue = func(context.Context) (*ChargeFlatFeeCostBasis, error) { return node, nil } m.id = &node.ID @@ -50704,7 +50464,7 @@ func withChargeFlatFeeRun(node *ChargeFlatFeeRun) chargeflatfeerunOption { // 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 ChargeFlatFeeRunMutation) Client() *Client { +func (m ChargeFlatFeeCostBasisMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -50712,7 +50472,7 @@ func (m ChargeFlatFeeRunMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m ChargeFlatFeeRunMutation) Tx() (*Tx, error) { +func (m ChargeFlatFeeCostBasisMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("db: mutation is not running in a transaction") } @@ -50722,14 +50482,14 @@ func (m ChargeFlatFeeRunMutation) Tx() (*Tx, error) { } // SetID sets the value of the id field. Note that this -// operation is only accepted on creation of ChargeFlatFeeRun entities. -func (m *ChargeFlatFeeRunMutation) SetID(id string) { +// operation is only accepted on creation of ChargeFlatFeeCostBasis entities. +func (m *ChargeFlatFeeCostBasisMutation) 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 *ChargeFlatFeeRunMutation) ID() (id string, exists bool) { +func (m *ChargeFlatFeeCostBasisMutation) ID() (id string, exists bool) { if m.id == nil { return } @@ -50740,7 +50500,7 @@ func (m *ChargeFlatFeeRunMutation) ID() (id string, exists bool) { // 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 *ChargeFlatFeeRunMutation) IDs(ctx context.Context) ([]string, error) { +func (m *ChargeFlatFeeCostBasisMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() @@ -50749,3164 +50509,2706 @@ func (m *ChargeFlatFeeRunMutation) IDs(ctx context.Context) ([]string, error) { } fallthrough case m.op.Is(OpUpdate | OpDelete): - return m.Client().ChargeFlatFeeRun.Query().Where(m.predicates...).IDs(ctx) + return m.Client().ChargeFlatFeeCostBasis.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } -// SetNamespace sets the "namespace" field. -func (m *ChargeFlatFeeRunMutation) SetNamespace(s string) { - m.namespace = &s +// SetMode sets the "mode" field. +func (m *ChargeFlatFeeCostBasisMutation) SetMode(c costbasis.Mode) { + m.mode = &c } -// Namespace returns the value of the "namespace" field in the mutation. -func (m *ChargeFlatFeeRunMutation) Namespace() (r string, exists bool) { - v := m.namespace +// Mode returns the value of the "mode" field in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) Mode() (r costbasis.Mode, exists bool) { + v := m.mode if v == nil { return } return *v, true } -// OldNamespace returns the old "namespace" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun object wasn't provided to the builder, the object is fetched from the database. +// OldMode returns the old "mode" field's value of the ChargeFlatFeeCostBasis entity. +// If the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeRunMutation) OldNamespace(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeCostBasisMutation) OldMode(ctx context.Context) (v costbasis.Mode, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldNamespace is only allowed on UpdateOne operations") + return v, errors.New("OldMode 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") + return v, errors.New("OldMode 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 v, fmt.Errorf("querying old value for OldMode: %w", err) } - return oldValue.Namespace, nil + return oldValue.Mode, nil } -// ResetNamespace resets all changes to the "namespace" field. -func (m *ChargeFlatFeeRunMutation) ResetNamespace() { - m.namespace = nil +// ResetMode resets all changes to the "mode" field. +func (m *ChargeFlatFeeCostBasisMutation) ResetMode() { + m.mode = nil } -// SetCreatedAt sets the "created_at" field. -func (m *ChargeFlatFeeRunMutation) SetCreatedAt(t time.Time) { - m.created_at = &t +// SetFiatCurrency sets the "fiat_currency" field. +func (m *ChargeFlatFeeCostBasisMutation) SetFiatCurrency(cc currencyx.FiatCode) { + m.fiat_currency = &cc } -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ChargeFlatFeeRunMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at +// FiatCurrency returns the value of the "fiat_currency" field in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) FiatCurrency() (r currencyx.FiatCode, exists bool) { + v := m.fiat_currency if v == nil { return } return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun object wasn't provided to the builder, the object is fetched from the database. +// OldFiatCurrency returns the old "fiat_currency" field's value of the ChargeFlatFeeCostBasis entity. +// If the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeRunMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeCostBasisMutation) OldFiatCurrency(ctx context.Context) (v currencyx.FiatCode, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + return v, errors.New("OldFiatCurrency 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") + return v, errors.New("OldFiatCurrency 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 v, fmt.Errorf("querying old value for OldFiatCurrency: %w", err) } - return oldValue.CreatedAt, nil + return oldValue.FiatCurrency, nil } -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *ChargeFlatFeeRunMutation) ResetCreatedAt() { - m.created_at = nil +// ResetFiatCurrency resets all changes to the "fiat_currency" field. +func (m *ChargeFlatFeeCostBasisMutation) ResetFiatCurrency() { + m.fiat_currency = nil } -// SetUpdatedAt sets the "updated_at" field. -func (m *ChargeFlatFeeRunMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (m *ChargeFlatFeeCostBasisMutation) SetCurrencyCostBasisID(s string) { + m.currency_cost_basis = &s } -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ChargeFlatFeeRunMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at +// CurrencyCostBasisID returns the value of the "currency_cost_basis_id" field in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) CurrencyCostBasisID() (r string, exists bool) { + v := m.currency_cost_basis if v == nil { return } return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun object wasn't provided to the builder, the object is fetched from the database. +// OldCurrencyCostBasisID returns the old "currency_cost_basis_id" field's value of the ChargeFlatFeeCostBasis entity. +// If the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeRunMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeCostBasisMutation) OldCurrencyCostBasisID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + return v, errors.New("OldCurrencyCostBasisID 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") + return v, errors.New("OldCurrencyCostBasisID 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 v, fmt.Errorf("querying old value for OldCurrencyCostBasisID: %w", err) } - return oldValue.UpdatedAt, nil + return oldValue.CurrencyCostBasisID, nil } -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *ChargeFlatFeeRunMutation) ResetUpdatedAt() { - m.updated_at = nil +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (m *ChargeFlatFeeCostBasisMutation) ClearCurrencyCostBasisID() { + m.currency_cost_basis = nil + m.clearedFields[chargeflatfeecostbasis.FieldCurrencyCostBasisID] = struct{}{} } -// SetDeletedAt sets the "deleted_at" field. -func (m *ChargeFlatFeeRunMutation) SetDeletedAt(t time.Time) { - m.deleted_at = &t +// CurrencyCostBasisIDCleared returns if the "currency_cost_basis_id" field was cleared in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) CurrencyCostBasisIDCleared() bool { + _, ok := m.clearedFields[chargeflatfeecostbasis.FieldCurrencyCostBasisID] + return ok } -// DeletedAt returns the value of the "deleted_at" field in the mutation. -func (m *ChargeFlatFeeRunMutation) DeletedAt() (r time.Time, exists bool) { - v := m.deleted_at +// ResetCurrencyCostBasisID resets all changes to the "currency_cost_basis_id" field. +func (m *ChargeFlatFeeCostBasisMutation) ResetCurrencyCostBasisID() { + m.currency_cost_basis = nil + delete(m.clearedFields, chargeflatfeecostbasis.FieldCurrencyCostBasisID) +} + +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (m *ChargeFlatFeeCostBasisMutation) SetResolvedCostBasisID(s string) { + m.resolved_currency_cost_basis = &s +} + +// ResolvedCostBasisID returns the value of the "resolved_cost_basis_id" field in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) ResolvedCostBasisID() (r string, exists bool) { + v := m.resolved_currency_cost_basis if v == nil { return } return *v, true } -// OldDeletedAt returns the old "deleted_at" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun object wasn't provided to the builder, the object is fetched from the database. +// OldResolvedCostBasisID returns the old "resolved_cost_basis_id" field's value of the ChargeFlatFeeCostBasis entity. +// If the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeRunMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeFlatFeeCostBasisMutation) OldResolvedCostBasisID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") + return v, errors.New("OldResolvedCostBasisID 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") + return v, errors.New("OldResolvedCostBasisID 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 v, fmt.Errorf("querying old value for OldResolvedCostBasisID: %w", err) } - return oldValue.DeletedAt, nil + return oldValue.ResolvedCostBasisID, nil } -// ClearDeletedAt clears the value of the "deleted_at" field. -func (m *ChargeFlatFeeRunMutation) ClearDeletedAt() { - m.deleted_at = nil - m.clearedFields[chargeflatfeerun.FieldDeletedAt] = struct{}{} +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (m *ChargeFlatFeeCostBasisMutation) ClearResolvedCostBasisID() { + m.resolved_currency_cost_basis = nil + m.clearedFields[chargeflatfeecostbasis.FieldResolvedCostBasisID] = struct{}{} } -// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. -func (m *ChargeFlatFeeRunMutation) DeletedAtCleared() bool { - _, ok := m.clearedFields[chargeflatfeerun.FieldDeletedAt] +// ResolvedCostBasisIDCleared returns if the "resolved_cost_basis_id" field was cleared in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) ResolvedCostBasisIDCleared() bool { + _, ok := m.clearedFields[chargeflatfeecostbasis.FieldResolvedCostBasisID] return ok } -// ResetDeletedAt resets all changes to the "deleted_at" field. -func (m *ChargeFlatFeeRunMutation) ResetDeletedAt() { - m.deleted_at = nil - delete(m.clearedFields, chargeflatfeerun.FieldDeletedAt) +// ResetResolvedCostBasisID resets all changes to the "resolved_cost_basis_id" field. +func (m *ChargeFlatFeeCostBasisMutation) ResetResolvedCostBasisID() { + m.resolved_currency_cost_basis = nil + delete(m.clearedFields, chargeflatfeecostbasis.FieldResolvedCostBasisID) } -// SetAmount sets the "amount" field. -func (m *ChargeFlatFeeRunMutation) SetAmount(a alpacadecimal.Decimal) { - m.amount = &a +// SetCurrencyID sets the "currency_id" field. +func (m *ChargeFlatFeeCostBasisMutation) SetCurrencyID(s string) { + m.custom_currency = &s } -// Amount returns the value of the "amount" field in the mutation. -func (m *ChargeFlatFeeRunMutation) Amount() (r alpacadecimal.Decimal, exists bool) { - v := m.amount +// CurrencyID returns the value of the "currency_id" field in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) CurrencyID() (r string, exists bool) { + v := m.custom_currency if v == nil { return } return *v, true } -// OldAmount returns the old "amount" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun object wasn't provided to the builder, the object is fetched from the database. +// OldCurrencyID returns the old "currency_id" field's value of the ChargeFlatFeeCostBasis entity. +// If the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeRunMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeCostBasisMutation) OldCurrencyID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAmount is only allowed on UpdateOne operations") + return v, errors.New("OldCurrencyID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAmount requires an ID field in the mutation") + return v, errors.New("OldCurrencyID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldAmount: %w", err) + return v, fmt.Errorf("querying old value for OldCurrencyID: %w", err) } - return oldValue.Amount, nil + return oldValue.CurrencyID, nil } -// ResetAmount resets all changes to the "amount" field. -func (m *ChargeFlatFeeRunMutation) ResetAmount() { - m.amount = nil +// ResetCurrencyID resets all changes to the "currency_id" field. +func (m *ChargeFlatFeeCostBasisMutation) ResetCurrencyID() { + m.custom_currency = nil } -// SetTaxesTotal sets the "taxes_total" field. -func (m *ChargeFlatFeeRunMutation) SetTaxesTotal(a alpacadecimal.Decimal) { - m.taxes_total = &a +// SetManualRate sets the "manual_rate" field. +func (m *ChargeFlatFeeCostBasisMutation) SetManualRate(a alpacadecimal.Decimal) { + m.manual_rate = &a } -// TaxesTotal returns the value of the "taxes_total" field in the mutation. -func (m *ChargeFlatFeeRunMutation) TaxesTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.taxes_total +// ManualRate returns the value of the "manual_rate" field in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) ManualRate() (r alpacadecimal.Decimal, exists bool) { + v := m.manual_rate if v == nil { return } return *v, true } -// OldTaxesTotal returns the old "taxes_total" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun object wasn't provided to the builder, the object is fetched from the database. +// OldManualRate returns the old "manual_rate" field's value of the ChargeFlatFeeCostBasis entity. +// If the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeRunMutation) OldTaxesTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeCostBasisMutation) OldManualRate(ctx context.Context) (v *alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTaxesTotal is only allowed on UpdateOne operations") + return v, errors.New("OldManualRate is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTaxesTotal requires an ID field in the mutation") + return v, errors.New("OldManualRate requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldTaxesTotal: %w", err) + return v, fmt.Errorf("querying old value for OldManualRate: %w", err) } - return oldValue.TaxesTotal, nil -} - -// ResetTaxesTotal resets all changes to the "taxes_total" field. -func (m *ChargeFlatFeeRunMutation) ResetTaxesTotal() { - m.taxes_total = nil -} - -// SetTaxesInclusiveTotal sets the "taxes_inclusive_total" field. -func (m *ChargeFlatFeeRunMutation) SetTaxesInclusiveTotal(a alpacadecimal.Decimal) { - m.taxes_inclusive_total = &a + return oldValue.ManualRate, nil } -// TaxesInclusiveTotal returns the value of the "taxes_inclusive_total" field in the mutation. -func (m *ChargeFlatFeeRunMutation) TaxesInclusiveTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.taxes_inclusive_total - if v == nil { - return - } - return *v, true +// ClearManualRate clears the value of the "manual_rate" field. +func (m *ChargeFlatFeeCostBasisMutation) ClearManualRate() { + m.manual_rate = nil + m.clearedFields[chargeflatfeecostbasis.FieldManualRate] = struct{}{} } -// OldTaxesInclusiveTotal returns the old "taxes_inclusive_total" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) OldTaxesInclusiveTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTaxesInclusiveTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTaxesInclusiveTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTaxesInclusiveTotal: %w", err) - } - return oldValue.TaxesInclusiveTotal, nil +// ManualRateCleared returns if the "manual_rate" field was cleared in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) ManualRateCleared() bool { + _, ok := m.clearedFields[chargeflatfeecostbasis.FieldManualRate] + return ok } -// ResetTaxesInclusiveTotal resets all changes to the "taxes_inclusive_total" field. -func (m *ChargeFlatFeeRunMutation) ResetTaxesInclusiveTotal() { - m.taxes_inclusive_total = nil +// ResetManualRate resets all changes to the "manual_rate" field. +func (m *ChargeFlatFeeCostBasisMutation) ResetManualRate() { + m.manual_rate = nil + delete(m.clearedFields, chargeflatfeecostbasis.FieldManualRate) } -// SetTaxesExclusiveTotal sets the "taxes_exclusive_total" field. -func (m *ChargeFlatFeeRunMutation) SetTaxesExclusiveTotal(a alpacadecimal.Decimal) { - m.taxes_exclusive_total = &a +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (m *ChargeFlatFeeCostBasisMutation) SetResolvedCostBasis(a alpacadecimal.Decimal) { + m.resolved_cost_basis = &a } -// TaxesExclusiveTotal returns the value of the "taxes_exclusive_total" field in the mutation. -func (m *ChargeFlatFeeRunMutation) TaxesExclusiveTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.taxes_exclusive_total +// ResolvedCostBasis returns the value of the "resolved_cost_basis" field in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) ResolvedCostBasis() (r alpacadecimal.Decimal, exists bool) { + v := m.resolved_cost_basis if v == nil { return } return *v, true } -// OldTaxesExclusiveTotal returns the old "taxes_exclusive_total" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun object wasn't provided to the builder, the object is fetched from the database. +// OldResolvedCostBasis returns the old "resolved_cost_basis" field's value of the ChargeFlatFeeCostBasis entity. +// If the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeRunMutation) OldTaxesExclusiveTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeCostBasisMutation) OldResolvedCostBasis(ctx context.Context) (v *alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTaxesExclusiveTotal is only allowed on UpdateOne operations") + return v, errors.New("OldResolvedCostBasis is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTaxesExclusiveTotal requires an ID field in the mutation") + return v, errors.New("OldResolvedCostBasis requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldTaxesExclusiveTotal: %w", err) + return v, fmt.Errorf("querying old value for OldResolvedCostBasis: %w", err) } - return oldValue.TaxesExclusiveTotal, nil -} - -// ResetTaxesExclusiveTotal resets all changes to the "taxes_exclusive_total" field. -func (m *ChargeFlatFeeRunMutation) ResetTaxesExclusiveTotal() { - m.taxes_exclusive_total = nil -} - -// SetChargesTotal sets the "charges_total" field. -func (m *ChargeFlatFeeRunMutation) SetChargesTotal(a alpacadecimal.Decimal) { - m.charges_total = &a + return oldValue.ResolvedCostBasis, nil } -// ChargesTotal returns the value of the "charges_total" field in the mutation. -func (m *ChargeFlatFeeRunMutation) ChargesTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.charges_total - if v == nil { - return - } - return *v, true +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (m *ChargeFlatFeeCostBasisMutation) ClearResolvedCostBasis() { + m.resolved_cost_basis = nil + m.clearedFields[chargeflatfeecostbasis.FieldResolvedCostBasis] = struct{}{} } -// OldChargesTotal returns the old "charges_total" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) OldChargesTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldChargesTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldChargesTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldChargesTotal: %w", err) - } - return oldValue.ChargesTotal, nil +// ResolvedCostBasisCleared returns if the "resolved_cost_basis" field was cleared in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) ResolvedCostBasisCleared() bool { + _, ok := m.clearedFields[chargeflatfeecostbasis.FieldResolvedCostBasis] + return ok } -// ResetChargesTotal resets all changes to the "charges_total" field. -func (m *ChargeFlatFeeRunMutation) ResetChargesTotal() { - m.charges_total = nil +// ResetResolvedCostBasis resets all changes to the "resolved_cost_basis" field. +func (m *ChargeFlatFeeCostBasisMutation) ResetResolvedCostBasis() { + m.resolved_cost_basis = nil + delete(m.clearedFields, chargeflatfeecostbasis.FieldResolvedCostBasis) } -// SetDiscountsTotal sets the "discounts_total" field. -func (m *ChargeFlatFeeRunMutation) SetDiscountsTotal(a alpacadecimal.Decimal) { - m.discounts_total = &a +// SetResolvedAt sets the "resolved_at" field. +func (m *ChargeFlatFeeCostBasisMutation) SetResolvedAt(t time.Time) { + m.resolved_at = &t } -// DiscountsTotal returns the value of the "discounts_total" field in the mutation. -func (m *ChargeFlatFeeRunMutation) DiscountsTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.discounts_total +// ResolvedAt returns the value of the "resolved_at" field in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) ResolvedAt() (r time.Time, exists bool) { + v := m.resolved_at if v == nil { return } return *v, true } -// OldDiscountsTotal returns the old "discounts_total" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun object wasn't provided to the builder, the object is fetched from the database. +// OldResolvedAt returns the old "resolved_at" field's value of the ChargeFlatFeeCostBasis entity. +// If the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeRunMutation) OldDiscountsTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeCostBasisMutation) OldResolvedAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDiscountsTotal is only allowed on UpdateOne operations") + return v, errors.New("OldResolvedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDiscountsTotal requires an ID field in the mutation") + return v, errors.New("OldResolvedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldDiscountsTotal: %w", err) + return v, fmt.Errorf("querying old value for OldResolvedAt: %w", err) } - return oldValue.DiscountsTotal, nil -} - -// ResetDiscountsTotal resets all changes to the "discounts_total" field. -func (m *ChargeFlatFeeRunMutation) ResetDiscountsTotal() { - m.discounts_total = nil -} - -// SetCreditsTotal sets the "credits_total" field. -func (m *ChargeFlatFeeRunMutation) SetCreditsTotal(a alpacadecimal.Decimal) { - m.credits_total = &a + return oldValue.ResolvedAt, nil } -// CreditsTotal returns the value of the "credits_total" field in the mutation. -func (m *ChargeFlatFeeRunMutation) CreditsTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.credits_total - if v == nil { - return - } - return *v, true +// ClearResolvedAt clears the value of the "resolved_at" field. +func (m *ChargeFlatFeeCostBasisMutation) ClearResolvedAt() { + m.resolved_at = nil + m.clearedFields[chargeflatfeecostbasis.FieldResolvedAt] = struct{}{} } -// OldCreditsTotal returns the old "credits_total" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) OldCreditsTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreditsTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreditsTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreditsTotal: %w", err) - } - return oldValue.CreditsTotal, nil +// ResolvedAtCleared returns if the "resolved_at" field was cleared in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) ResolvedAtCleared() bool { + _, ok := m.clearedFields[chargeflatfeecostbasis.FieldResolvedAt] + return ok } -// ResetCreditsTotal resets all changes to the "credits_total" field. -func (m *ChargeFlatFeeRunMutation) ResetCreditsTotal() { - m.credits_total = nil +// ResetResolvedAt resets all changes to the "resolved_at" field. +func (m *ChargeFlatFeeCostBasisMutation) ResetResolvedAt() { + m.resolved_at = nil + delete(m.clearedFields, chargeflatfeecostbasis.FieldResolvedAt) } -// SetTotal sets the "total" field. -func (m *ChargeFlatFeeRunMutation) SetTotal(a alpacadecimal.Decimal) { - m.total = &a +// SetNamespace sets the "namespace" field. +func (m *ChargeFlatFeeCostBasisMutation) SetNamespace(s string) { + m.namespace = &s } -// Total returns the value of the "total" field in the mutation. -func (m *ChargeFlatFeeRunMutation) Total() (r alpacadecimal.Decimal, exists bool) { - v := m.total +// Namespace returns the value of the "namespace" field in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) Namespace() (r string, exists bool) { + v := m.namespace if v == nil { return } return *v, true } -// OldTotal returns the old "total" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun object wasn't provided to the builder, the object is fetched from the database. +// OldNamespace returns the old "namespace" field's value of the ChargeFlatFeeCostBasis entity. +// If the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeRunMutation) OldTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeCostBasisMutation) OldNamespace(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTotal is only allowed on UpdateOne operations") + return v, errors.New("OldNamespace is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTotal requires an ID field in the mutation") + 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 OldTotal: %w", err) + return v, fmt.Errorf("querying old value for OldNamespace: %w", err) } - return oldValue.Total, nil + return oldValue.Namespace, nil } -// ResetTotal resets all changes to the "total" field. -func (m *ChargeFlatFeeRunMutation) ResetTotal() { - m.total = nil +// ResetNamespace resets all changes to the "namespace" field. +func (m *ChargeFlatFeeCostBasisMutation) ResetNamespace() { + m.namespace = nil } -// SetChargeID sets the "charge_id" field. -func (m *ChargeFlatFeeRunMutation) SetChargeID(s string) { - m.flat_fee = &s +// SetCreatedAt sets the "created_at" field. +func (m *ChargeFlatFeeCostBasisMutation) SetCreatedAt(t time.Time) { + m.created_at = &t } -// ChargeID returns the value of the "charge_id" field in the mutation. -func (m *ChargeFlatFeeRunMutation) ChargeID() (r string, exists bool) { - v := m.flat_fee +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at if v == nil { return } return *v, true } -// OldChargeID returns the old "charge_id" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the ChargeFlatFeeCostBasis entity. +// If the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeRunMutation) OldChargeID(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeCostBasisMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldChargeID is only allowed on UpdateOne operations") + return v, errors.New("OldCreatedAt 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") + 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 OldChargeID: %w", err) + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } - return oldValue.ChargeID, nil + return oldValue.CreatedAt, nil } -// ResetChargeID resets all changes to the "charge_id" field. -func (m *ChargeFlatFeeRunMutation) ResetChargeID() { - m.flat_fee = nil +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ChargeFlatFeeCostBasisMutation) ResetCreatedAt() { + m.created_at = nil } -// SetType sets the "type" field. -func (m *ChargeFlatFeeRunMutation) SetType(frt flatfee.RealizationRunType) { - m._type = &frt +// SetUpdatedAt sets the "updated_at" field. +func (m *ChargeFlatFeeCostBasisMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t } -// GetType returns the value of the "type" field in the mutation. -func (m *ChargeFlatFeeRunMutation) GetType() (r flatfee.RealizationRunType, exists bool) { - v := m._type +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at if v == nil { return } return *v, true } -// OldType returns the old "type" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the ChargeFlatFeeCostBasis entity. +// If the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeRunMutation) OldType(ctx context.Context) (v flatfee.RealizationRunType, err error) { +func (m *ChargeFlatFeeCostBasisMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldType is only allowed on UpdateOne operations") + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldType requires an ID field in the mutation") + 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 OldType: %w", err) + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } - return oldValue.Type, nil + return oldValue.UpdatedAt, nil } -// ResetType resets all changes to the "type" field. -func (m *ChargeFlatFeeRunMutation) ResetType() { - m._type = nil +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *ChargeFlatFeeCostBasisMutation) ResetUpdatedAt() { + m.updated_at = nil } -// SetInitialType sets the "initial_type" field. -func (m *ChargeFlatFeeRunMutation) SetInitialType(frt flatfee.RealizationRunType) { - m.initial_type = &frt +// SetDeletedAt sets the "deleted_at" field. +func (m *ChargeFlatFeeCostBasisMutation) SetDeletedAt(t time.Time) { + m.deleted_at = &t } -// InitialType returns the value of the "initial_type" field in the mutation. -func (m *ChargeFlatFeeRunMutation) InitialType() (r flatfee.RealizationRunType, exists bool) { - v := m.initial_type +// DeletedAt returns the value of the "deleted_at" field in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) DeletedAt() (r time.Time, exists bool) { + v := m.deleted_at if v == nil { return } return *v, true } -// OldInitialType returns the old "initial_type" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun object wasn't provided to the builder, the object is fetched from the database. +// OldDeletedAt returns the old "deleted_at" field's value of the ChargeFlatFeeCostBasis entity. +// If the ChargeFlatFeeCostBasis 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 *ChargeFlatFeeRunMutation) OldInitialType(ctx context.Context) (v flatfee.RealizationRunType, err error) { +func (m *ChargeFlatFeeCostBasisMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldInitialType is only allowed on UpdateOne operations") + return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldInitialType requires an ID field in the mutation") + 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 OldInitialType: %w", err) + return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) } - return oldValue.InitialType, nil + return oldValue.DeletedAt, nil } -// ResetInitialType resets all changes to the "initial_type" field. -func (m *ChargeFlatFeeRunMutation) ResetInitialType() { - m.initial_type = nil +// ClearDeletedAt clears the value of the "deleted_at" field. +func (m *ChargeFlatFeeCostBasisMutation) ClearDeletedAt() { + m.deleted_at = nil + m.clearedFields[chargeflatfeecostbasis.FieldDeletedAt] = struct{}{} } -// SetServicePeriodFrom sets the "service_period_from" field. -func (m *ChargeFlatFeeRunMutation) SetServicePeriodFrom(t time.Time) { - m.service_period_from = &t +// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargeflatfeecostbasis.FieldDeletedAt] + return ok } -// ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. -func (m *ChargeFlatFeeRunMutation) ServicePeriodFrom() (r time.Time, exists bool) { - v := m.service_period_from - if v == nil { - return - } - return *v, true +// ResetDeletedAt resets all changes to the "deleted_at" field. +func (m *ChargeFlatFeeCostBasisMutation) ResetDeletedAt() { + m.deleted_at = nil + delete(m.clearedFields, chargeflatfeecostbasis.FieldDeletedAt) } -// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldServicePeriodFrom requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldServicePeriodFrom: %w", err) - } - return oldValue.ServicePeriodFrom, nil +// ClearCurrencyCostBasis clears the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (m *ChargeFlatFeeCostBasisMutation) ClearCurrencyCostBasis() { + m.clearedcurrency_cost_basis = true + m.clearedFields[chargeflatfeecostbasis.FieldCurrencyCostBasisID] = struct{}{} } -// ResetServicePeriodFrom resets all changes to the "service_period_from" field. -func (m *ChargeFlatFeeRunMutation) ResetServicePeriodFrom() { - m.service_period_from = nil +// CurrencyCostBasisCleared reports if the "currency_cost_basis" edge to the CurrencyCostBasis entity was cleared. +func (m *ChargeFlatFeeCostBasisMutation) CurrencyCostBasisCleared() bool { + return m.CurrencyCostBasisIDCleared() || m.clearedcurrency_cost_basis } -// SetServicePeriodTo sets the "service_period_to" field. -func (m *ChargeFlatFeeRunMutation) SetServicePeriodTo(t time.Time) { - m.service_period_to = &t +// CurrencyCostBasisIDs returns the "currency_cost_basis" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CurrencyCostBasisID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeCostBasisMutation) CurrencyCostBasisIDs() (ids []string) { + if id := m.currency_cost_basis; id != nil { + ids = append(ids, *id) + } + return } -// ServicePeriodTo returns the value of the "service_period_to" field in the mutation. -func (m *ChargeFlatFeeRunMutation) ServicePeriodTo() (r time.Time, exists bool) { - v := m.service_period_to - if v == nil { - return - } - return *v, true +// ResetCurrencyCostBasis resets all changes to the "currency_cost_basis" edge. +func (m *ChargeFlatFeeCostBasisMutation) ResetCurrencyCostBasis() { + m.currency_cost_basis = nil + m.clearedcurrency_cost_basis = false } -// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldServicePeriodTo requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldServicePeriodTo: %w", err) - } - return oldValue.ServicePeriodTo, nil +// SetResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by id. +func (m *ChargeFlatFeeCostBasisMutation) SetResolvedCurrencyCostBasisID(id string) { + m.resolved_currency_cost_basis = &id } -// ResetServicePeriodTo resets all changes to the "service_period_to" field. -func (m *ChargeFlatFeeRunMutation) ResetServicePeriodTo() { - m.service_period_to = nil +// ClearResolvedCurrencyCostBasis clears the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (m *ChargeFlatFeeCostBasisMutation) ClearResolvedCurrencyCostBasis() { + m.clearedresolved_currency_cost_basis = true + m.clearedFields[chargeflatfeecostbasis.FieldResolvedCostBasisID] = struct{}{} } -// SetLineID sets the "line_id" field. -func (m *ChargeFlatFeeRunMutation) SetLineID(s string) { - m.billing_invoice_line = &s +// ResolvedCurrencyCostBasisCleared reports if the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity was cleared. +func (m *ChargeFlatFeeCostBasisMutation) ResolvedCurrencyCostBasisCleared() bool { + return m.ResolvedCostBasisIDCleared() || m.clearedresolved_currency_cost_basis } -// LineID returns the value of the "line_id" field in the mutation. -func (m *ChargeFlatFeeRunMutation) LineID() (r string, exists bool) { - v := m.billing_invoice_line - if v == nil { - return +// ResolvedCurrencyCostBasisID returns the "resolved_currency_cost_basis" edge ID in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) ResolvedCurrencyCostBasisID() (id string, exists bool) { + if m.resolved_currency_cost_basis != nil { + return *m.resolved_currency_cost_basis, true } - return *v, true + return } -// OldLineID returns the old "line_id" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) OldLineID(ctx context.Context) (v *string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldLineID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldLineID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldLineID: %w", err) +// ResolvedCurrencyCostBasisIDs returns the "resolved_currency_cost_basis" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ResolvedCurrencyCostBasisID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeCostBasisMutation) ResolvedCurrencyCostBasisIDs() (ids []string) { + if id := m.resolved_currency_cost_basis; id != nil { + ids = append(ids, *id) } - return oldValue.LineID, nil + return } -// ClearLineID clears the value of the "line_id" field. -func (m *ChargeFlatFeeRunMutation) ClearLineID() { - m.billing_invoice_line = nil - m.clearedFields[chargeflatfeerun.FieldLineID] = struct{}{} +// ResetResolvedCurrencyCostBasis resets all changes to the "resolved_currency_cost_basis" edge. +func (m *ChargeFlatFeeCostBasisMutation) ResetResolvedCurrencyCostBasis() { + m.resolved_currency_cost_basis = nil + m.clearedresolved_currency_cost_basis = false } -// LineIDCleared returns if the "line_id" field was cleared in this mutation. -func (m *ChargeFlatFeeRunMutation) LineIDCleared() bool { - _, ok := m.clearedFields[chargeflatfeerun.FieldLineID] - return ok +// SetCustomCurrencyID sets the "custom_currency" edge to the CustomCurrency entity by id. +func (m *ChargeFlatFeeCostBasisMutation) SetCustomCurrencyID(id string) { + m.custom_currency = &id } -// ResetLineID resets all changes to the "line_id" field. -func (m *ChargeFlatFeeRunMutation) ResetLineID() { - m.billing_invoice_line = nil - delete(m.clearedFields, chargeflatfeerun.FieldLineID) +// ClearCustomCurrency clears the "custom_currency" edge to the CustomCurrency entity. +func (m *ChargeFlatFeeCostBasisMutation) ClearCustomCurrency() { + m.clearedcustom_currency = true + m.clearedFields[chargeflatfeecostbasis.FieldCurrencyID] = struct{}{} } -// SetInvoiceID sets the "invoice_id" field. -func (m *ChargeFlatFeeRunMutation) SetInvoiceID(s string) { - m.billing_invoice = &s +// CustomCurrencyCleared reports if the "custom_currency" edge to the CustomCurrency entity was cleared. +func (m *ChargeFlatFeeCostBasisMutation) CustomCurrencyCleared() bool { + return m.clearedcustom_currency } -// InvoiceID returns the value of the "invoice_id" field in the mutation. -func (m *ChargeFlatFeeRunMutation) InvoiceID() (r string, exists bool) { - v := m.billing_invoice - if v == nil { - return +// CustomCurrencyID returns the "custom_currency" edge ID in the mutation. +func (m *ChargeFlatFeeCostBasisMutation) CustomCurrencyID() (id string, exists bool) { + if m.custom_currency != nil { + return *m.custom_currency, true } - return *v, true + return } -// OldInvoiceID returns the old "invoice_id" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) 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) +// CustomCurrencyIDs returns the "custom_currency" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CustomCurrencyID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeCostBasisMutation) CustomCurrencyIDs() (ids []string) { + if id := m.custom_currency; id != nil { + ids = append(ids, *id) } - return oldValue.InvoiceID, nil -} - -// ClearInvoiceID clears the value of the "invoice_id" field. -func (m *ChargeFlatFeeRunMutation) ClearInvoiceID() { - m.billing_invoice = nil - m.clearedFields[chargeflatfeerun.FieldInvoiceID] = struct{}{} -} - -// InvoiceIDCleared returns if the "invoice_id" field was cleared in this mutation. -func (m *ChargeFlatFeeRunMutation) InvoiceIDCleared() bool { - _, ok := m.clearedFields[chargeflatfeerun.FieldInvoiceID] - return ok + return } -// ResetInvoiceID resets all changes to the "invoice_id" field. -func (m *ChargeFlatFeeRunMutation) ResetInvoiceID() { - m.billing_invoice = nil - delete(m.clearedFields, chargeflatfeerun.FieldInvoiceID) +// ResetCustomCurrency resets all changes to the "custom_currency" edge. +func (m *ChargeFlatFeeCostBasisMutation) ResetCustomCurrency() { + m.custom_currency = nil + m.clearedcustom_currency = false } -// SetAmountAfterProration sets the "amount_after_proration" field. -func (m *ChargeFlatFeeRunMutation) SetAmountAfterProration(a alpacadecimal.Decimal) { - m.amount_after_proration = &a +// Where appends a list predicates to the ChargeFlatFeeCostBasisMutation builder. +func (m *ChargeFlatFeeCostBasisMutation) Where(ps ...predicate.ChargeFlatFeeCostBasis) { + m.predicates = append(m.predicates, ps...) } -// AmountAfterProration returns the value of the "amount_after_proration" field in the mutation. -func (m *ChargeFlatFeeRunMutation) AmountAfterProration() (r alpacadecimal.Decimal, exists bool) { - v := m.amount_after_proration - if v == nil { - return +// WhereP appends storage-level predicates to the ChargeFlatFeeCostBasisMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ChargeFlatFeeCostBasisMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeFlatFeeCostBasis, len(ps)) + for i := range ps { + p[i] = ps[i] } - return *v, true + m.Where(p...) } -// OldAmountAfterProration returns the old "amount_after_proration" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) OldAmountAfterProration(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAmountAfterProration is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAmountAfterProration requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldAmountAfterProration: %w", err) - } - return oldValue.AmountAfterProration, nil +// Op returns the operation name. +func (m *ChargeFlatFeeCostBasisMutation) Op() Op { + return m.op } -// ResetAmountAfterProration resets all changes to the "amount_after_proration" field. -func (m *ChargeFlatFeeRunMutation) ResetAmountAfterProration() { - m.amount_after_proration = nil +// SetOp allows setting the mutation operation. +func (m *ChargeFlatFeeCostBasisMutation) SetOp(op Op) { + m.op = op } -// SetNoFiatTransactionRequired sets the "no_fiat_transaction_required" field. -func (m *ChargeFlatFeeRunMutation) SetNoFiatTransactionRequired(b bool) { - m.no_fiat_transaction_required = &b +// Type returns the node type of this mutation (ChargeFlatFeeCostBasis). +func (m *ChargeFlatFeeCostBasisMutation) Type() string { + return m.typ } -// NoFiatTransactionRequired returns the value of the "no_fiat_transaction_required" field in the mutation. -func (m *ChargeFlatFeeRunMutation) NoFiatTransactionRequired() (r bool, exists bool) { - v := m.no_fiat_transaction_required - if v == nil { - return +// 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 *ChargeFlatFeeCostBasisMutation) Fields() []string { + fields := make([]string, 0, 12) + if m.mode != nil { + fields = append(fields, chargeflatfeecostbasis.FieldMode) } - return *v, true -} - -// OldNoFiatTransactionRequired returns the old "no_fiat_transaction_required" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) OldNoFiatTransactionRequired(ctx context.Context) (v bool, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldNoFiatTransactionRequired is only allowed on UpdateOne operations") + if m.fiat_currency != nil { + fields = append(fields, chargeflatfeecostbasis.FieldFiatCurrency) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldNoFiatTransactionRequired requires an ID field in the mutation") + if m.currency_cost_basis != nil { + fields = append(fields, chargeflatfeecostbasis.FieldCurrencyCostBasisID) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldNoFiatTransactionRequired: %w", err) + if m.resolved_currency_cost_basis != nil { + fields = append(fields, chargeflatfeecostbasis.FieldResolvedCostBasisID) } - return oldValue.NoFiatTransactionRequired, nil -} - -// ResetNoFiatTransactionRequired resets all changes to the "no_fiat_transaction_required" field. -func (m *ChargeFlatFeeRunMutation) ResetNoFiatTransactionRequired() { - m.no_fiat_transaction_required = nil -} - -// SetImmutable sets the "immutable" field. -func (m *ChargeFlatFeeRunMutation) SetImmutable(b bool) { - m.immutable = &b -} - -// Immutable returns the value of the "immutable" field in the mutation. -func (m *ChargeFlatFeeRunMutation) Immutable() (r bool, exists bool) { - v := m.immutable - if v == nil { - return + if m.custom_currency != nil { + fields = append(fields, chargeflatfeecostbasis.FieldCurrencyID) } - return *v, true -} - -// OldImmutable returns the old "immutable" field's value of the ChargeFlatFeeRun entity. -// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) OldImmutable(ctx context.Context) (v bool, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldImmutable is only allowed on UpdateOne operations") + if m.manual_rate != nil { + fields = append(fields, chargeflatfeecostbasis.FieldManualRate) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldImmutable requires an ID field in the mutation") + if m.resolved_cost_basis != nil { + fields = append(fields, chargeflatfeecostbasis.FieldResolvedCostBasis) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldImmutable: %w", err) + if m.resolved_at != nil { + fields = append(fields, chargeflatfeecostbasis.FieldResolvedAt) } - return oldValue.Immutable, nil -} - -// ResetImmutable resets all changes to the "immutable" field. -func (m *ChargeFlatFeeRunMutation) ResetImmutable() { - m.immutable = nil -} - -// SetFlatFeeID sets the "flat_fee" edge to the ChargeFlatFee entity by id. -func (m *ChargeFlatFeeRunMutation) SetFlatFeeID(id string) { - m.flat_fee = &id + if m.namespace != nil { + fields = append(fields, chargeflatfeecostbasis.FieldNamespace) + } + if m.created_at != nil { + fields = append(fields, chargeflatfeecostbasis.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, chargeflatfeecostbasis.FieldUpdatedAt) + } + if m.deleted_at != nil { + fields = append(fields, chargeflatfeecostbasis.FieldDeletedAt) + } + return fields } -// ClearFlatFee clears the "flat_fee" edge to the ChargeFlatFee entity. -func (m *ChargeFlatFeeRunMutation) ClearFlatFee() { - m.clearedflat_fee = true - m.clearedFields[chargeflatfeerun.FieldChargeID] = struct{}{} +// 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 *ChargeFlatFeeCostBasisMutation) Field(name string) (ent.Value, bool) { + switch name { + case chargeflatfeecostbasis.FieldMode: + return m.Mode() + case chargeflatfeecostbasis.FieldFiatCurrency: + return m.FiatCurrency() + case chargeflatfeecostbasis.FieldCurrencyCostBasisID: + return m.CurrencyCostBasisID() + case chargeflatfeecostbasis.FieldResolvedCostBasisID: + return m.ResolvedCostBasisID() + case chargeflatfeecostbasis.FieldCurrencyID: + return m.CurrencyID() + case chargeflatfeecostbasis.FieldManualRate: + return m.ManualRate() + case chargeflatfeecostbasis.FieldResolvedCostBasis: + return m.ResolvedCostBasis() + case chargeflatfeecostbasis.FieldResolvedAt: + return m.ResolvedAt() + case chargeflatfeecostbasis.FieldNamespace: + return m.Namespace() + case chargeflatfeecostbasis.FieldCreatedAt: + return m.CreatedAt() + case chargeflatfeecostbasis.FieldUpdatedAt: + return m.UpdatedAt() + case chargeflatfeecostbasis.FieldDeletedAt: + return m.DeletedAt() + } + return nil, false } -// FlatFeeCleared reports if the "flat_fee" edge to the ChargeFlatFee entity was cleared. -func (m *ChargeFlatFeeRunMutation) FlatFeeCleared() bool { - return m.clearedflat_fee +// 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 *ChargeFlatFeeCostBasisMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case chargeflatfeecostbasis.FieldMode: + return m.OldMode(ctx) + case chargeflatfeecostbasis.FieldFiatCurrency: + return m.OldFiatCurrency(ctx) + case chargeflatfeecostbasis.FieldCurrencyCostBasisID: + return m.OldCurrencyCostBasisID(ctx) + case chargeflatfeecostbasis.FieldResolvedCostBasisID: + return m.OldResolvedCostBasisID(ctx) + case chargeflatfeecostbasis.FieldCurrencyID: + return m.OldCurrencyID(ctx) + case chargeflatfeecostbasis.FieldManualRate: + return m.OldManualRate(ctx) + case chargeflatfeecostbasis.FieldResolvedCostBasis: + return m.OldResolvedCostBasis(ctx) + case chargeflatfeecostbasis.FieldResolvedAt: + return m.OldResolvedAt(ctx) + case chargeflatfeecostbasis.FieldNamespace: + return m.OldNamespace(ctx) + case chargeflatfeecostbasis.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case chargeflatfeecostbasis.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case chargeflatfeecostbasis.FieldDeletedAt: + return m.OldDeletedAt(ctx) + } + return nil, fmt.Errorf("unknown ChargeFlatFeeCostBasis field %s", name) } -// FlatFeeID returns the "flat_fee" edge ID in the mutation. -func (m *ChargeFlatFeeRunMutation) FlatFeeID() (id string, exists bool) { - if m.flat_fee != nil { - return *m.flat_fee, true +// 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 *ChargeFlatFeeCostBasisMutation) SetField(name string, value ent.Value) error { + switch name { + case chargeflatfeecostbasis.FieldMode: + v, ok := value.(costbasis.Mode) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMode(v) + return nil + case chargeflatfeecostbasis.FieldFiatCurrency: + v, ok := value.(currencyx.FiatCode) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFiatCurrency(v) + return nil + case chargeflatfeecostbasis.FieldCurrencyCostBasisID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCurrencyCostBasisID(v) + return nil + case chargeflatfeecostbasis.FieldResolvedCostBasisID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetResolvedCostBasisID(v) + return nil + case chargeflatfeecostbasis.FieldCurrencyID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCurrencyID(v) + return nil + case chargeflatfeecostbasis.FieldManualRate: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetManualRate(v) + return nil + case chargeflatfeecostbasis.FieldResolvedCostBasis: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetResolvedCostBasis(v) + return nil + case chargeflatfeecostbasis.FieldResolvedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetResolvedAt(v) + return nil + case chargeflatfeecostbasis.FieldNamespace: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNamespace(v) + return nil + case chargeflatfeecostbasis.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 chargeflatfeecostbasis.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 chargeflatfeecostbasis.FieldDeletedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDeletedAt(v) + return nil } - return + return fmt.Errorf("unknown ChargeFlatFeeCostBasis field %s", name) } -// FlatFeeIDs returns the "flat_fee" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// FlatFeeID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeRunMutation) FlatFeeIDs() (ids []string) { - if id := m.flat_fee; id != nil { - ids = append(ids, *id) - } - return +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ChargeFlatFeeCostBasisMutation) AddedFields() []string { + return nil } -// ResetFlatFee resets all changes to the "flat_fee" edge. -func (m *ChargeFlatFeeRunMutation) ResetFlatFee() { - m.flat_fee = nil - m.clearedflat_fee = false +// 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 *ChargeFlatFeeCostBasisMutation) AddedField(name string) (ent.Value, bool) { + return nil, false } -// SetBillingInvoiceLineID sets the "billing_invoice_line" edge to the BillingInvoiceLine entity by id. -func (m *ChargeFlatFeeRunMutation) SetBillingInvoiceLineID(id string) { - m.billing_invoice_line = &id +// 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 *ChargeFlatFeeCostBasisMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown ChargeFlatFeeCostBasis numeric field %s", name) } -// ClearBillingInvoiceLine clears the "billing_invoice_line" edge to the BillingInvoiceLine entity. -func (m *ChargeFlatFeeRunMutation) ClearBillingInvoiceLine() { - m.clearedbilling_invoice_line = true - m.clearedFields[chargeflatfeerun.FieldLineID] = struct{}{} +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ChargeFlatFeeCostBasisMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(chargeflatfeecostbasis.FieldCurrencyCostBasisID) { + fields = append(fields, chargeflatfeecostbasis.FieldCurrencyCostBasisID) + } + if m.FieldCleared(chargeflatfeecostbasis.FieldResolvedCostBasisID) { + fields = append(fields, chargeflatfeecostbasis.FieldResolvedCostBasisID) + } + if m.FieldCleared(chargeflatfeecostbasis.FieldManualRate) { + fields = append(fields, chargeflatfeecostbasis.FieldManualRate) + } + if m.FieldCleared(chargeflatfeecostbasis.FieldResolvedCostBasis) { + fields = append(fields, chargeflatfeecostbasis.FieldResolvedCostBasis) + } + if m.FieldCleared(chargeflatfeecostbasis.FieldResolvedAt) { + fields = append(fields, chargeflatfeecostbasis.FieldResolvedAt) + } + if m.FieldCleared(chargeflatfeecostbasis.FieldDeletedAt) { + fields = append(fields, chargeflatfeecostbasis.FieldDeletedAt) + } + return fields } -// BillingInvoiceLineCleared reports if the "billing_invoice_line" edge to the BillingInvoiceLine entity was cleared. -func (m *ChargeFlatFeeRunMutation) BillingInvoiceLineCleared() bool { - return m.LineIDCleared() || m.clearedbilling_invoice_line +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok } -// BillingInvoiceLineID returns the "billing_invoice_line" edge ID in the mutation. -func (m *ChargeFlatFeeRunMutation) BillingInvoiceLineID() (id string, exists bool) { - if m.billing_invoice_line != nil { - return *m.billing_invoice_line, true +// 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 *ChargeFlatFeeCostBasisMutation) ClearField(name string) error { + switch name { + case chargeflatfeecostbasis.FieldCurrencyCostBasisID: + m.ClearCurrencyCostBasisID() + return nil + case chargeflatfeecostbasis.FieldResolvedCostBasisID: + m.ClearResolvedCostBasisID() + return nil + case chargeflatfeecostbasis.FieldManualRate: + m.ClearManualRate() + return nil + case chargeflatfeecostbasis.FieldResolvedCostBasis: + m.ClearResolvedCostBasis() + return nil + case chargeflatfeecostbasis.FieldResolvedAt: + m.ClearResolvedAt() + return nil + case chargeflatfeecostbasis.FieldDeletedAt: + m.ClearDeletedAt() + return nil } - return + return fmt.Errorf("unknown ChargeFlatFeeCostBasis nullable field %s", name) } -// BillingInvoiceLineIDs returns the "billing_invoice_line" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// BillingInvoiceLineID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeRunMutation) BillingInvoiceLineIDs() (ids []string) { - if id := m.billing_invoice_line; id != nil { - ids = append(ids, *id) +// 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 *ChargeFlatFeeCostBasisMutation) ResetField(name string) error { + switch name { + case chargeflatfeecostbasis.FieldMode: + m.ResetMode() + return nil + case chargeflatfeecostbasis.FieldFiatCurrency: + m.ResetFiatCurrency() + return nil + case chargeflatfeecostbasis.FieldCurrencyCostBasisID: + m.ResetCurrencyCostBasisID() + return nil + case chargeflatfeecostbasis.FieldResolvedCostBasisID: + m.ResetResolvedCostBasisID() + return nil + case chargeflatfeecostbasis.FieldCurrencyID: + m.ResetCurrencyID() + return nil + case chargeflatfeecostbasis.FieldManualRate: + m.ResetManualRate() + return nil + case chargeflatfeecostbasis.FieldResolvedCostBasis: + m.ResetResolvedCostBasis() + return nil + case chargeflatfeecostbasis.FieldResolvedAt: + m.ResetResolvedAt() + return nil + case chargeflatfeecostbasis.FieldNamespace: + m.ResetNamespace() + return nil + case chargeflatfeecostbasis.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case chargeflatfeecostbasis.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case chargeflatfeecostbasis.FieldDeletedAt: + m.ResetDeletedAt() + return nil } - return + return fmt.Errorf("unknown ChargeFlatFeeCostBasis field %s", name) } -// ResetBillingInvoiceLine resets all changes to the "billing_invoice_line" edge. -func (m *ChargeFlatFeeRunMutation) ResetBillingInvoiceLine() { - m.billing_invoice_line = nil - m.clearedbilling_invoice_line = false +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) AddedEdges() []string { + edges := make([]string, 0, 3) + if m.currency_cost_basis != nil { + edges = append(edges, chargeflatfeecostbasis.EdgeCurrencyCostBasis) + } + if m.resolved_currency_cost_basis != nil { + edges = append(edges, chargeflatfeecostbasis.EdgeResolvedCurrencyCostBasis) + } + if m.custom_currency != nil { + edges = append(edges, chargeflatfeecostbasis.EdgeCustomCurrency) + } + return edges } -// SetBillingInvoiceID sets the "billing_invoice" edge to the BillingInvoice entity by id. -func (m *ChargeFlatFeeRunMutation) SetBillingInvoiceID(id string) { - m.billing_invoice = &id +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) AddedIDs(name string) []ent.Value { + switch name { + case chargeflatfeecostbasis.EdgeCurrencyCostBasis: + if id := m.currency_cost_basis; id != nil { + return []ent.Value{*id} + } + case chargeflatfeecostbasis.EdgeResolvedCurrencyCostBasis: + if id := m.resolved_currency_cost_basis; id != nil { + return []ent.Value{*id} + } + case chargeflatfeecostbasis.EdgeCustomCurrency: + if id := m.custom_currency; id != nil { + return []ent.Value{*id} + } + } + return nil } -// ClearBillingInvoice clears the "billing_invoice" edge to the BillingInvoice entity. -func (m *ChargeFlatFeeRunMutation) ClearBillingInvoice() { - m.clearedbilling_invoice = true - m.clearedFields[chargeflatfeerun.FieldInvoiceID] = struct{}{} +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) RemovedEdges() []string { + edges := make([]string, 0, 3) + return edges } -// BillingInvoiceCleared reports if the "billing_invoice" edge to the BillingInvoice entity was cleared. -func (m *ChargeFlatFeeRunMutation) BillingInvoiceCleared() bool { - return m.InvoiceIDCleared() || m.clearedbilling_invoice +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) RemovedIDs(name string) []ent.Value { + return nil } -// BillingInvoiceID returns the "billing_invoice" edge ID in the mutation. -func (m *ChargeFlatFeeRunMutation) BillingInvoiceID() (id string, exists bool) { - if m.billing_invoice != nil { - return *m.billing_invoice, true +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) ClearedEdges() []string { + edges := make([]string, 0, 3) + if m.clearedcurrency_cost_basis { + edges = append(edges, chargeflatfeecostbasis.EdgeCurrencyCostBasis) } - return + if m.clearedresolved_currency_cost_basis { + edges = append(edges, chargeflatfeecostbasis.EdgeResolvedCurrencyCostBasis) + } + if m.clearedcustom_currency { + edges = append(edges, chargeflatfeecostbasis.EdgeCustomCurrency) + } + return edges } -// 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 *ChargeFlatFeeRunMutation) BillingInvoiceIDs() (ids []string) { - if id := m.billing_invoice; id != nil { - ids = append(ids, *id) +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ChargeFlatFeeCostBasisMutation) EdgeCleared(name string) bool { + switch name { + case chargeflatfeecostbasis.EdgeCurrencyCostBasis: + return m.clearedcurrency_cost_basis + case chargeflatfeecostbasis.EdgeResolvedCurrencyCostBasis: + return m.clearedresolved_currency_cost_basis + case chargeflatfeecostbasis.EdgeCustomCurrency: + return m.clearedcustom_currency } - return + return false } -// ResetBillingInvoice resets all changes to the "billing_invoice" edge. -func (m *ChargeFlatFeeRunMutation) ResetBillingInvoice() { - m.billing_invoice = nil - m.clearedbilling_invoice = 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 *ChargeFlatFeeCostBasisMutation) ClearEdge(name string) error { + switch name { + case chargeflatfeecostbasis.EdgeCurrencyCostBasis: + m.ClearCurrencyCostBasis() + return nil + case chargeflatfeecostbasis.EdgeResolvedCurrencyCostBasis: + m.ClearResolvedCurrencyCostBasis() + return nil + case chargeflatfeecostbasis.EdgeCustomCurrency: + m.ClearCustomCurrency() + return nil + } + return fmt.Errorf("unknown ChargeFlatFeeCostBasis unique edge %s", name) } -// AddCreditAllocationIDs adds the "credit_allocations" edge to the ChargeFlatFeeRunCreditAllocations entity by ids. -func (m *ChargeFlatFeeRunMutation) AddCreditAllocationIDs(ids ...string) { - if m.credit_allocations == nil { - m.credit_allocations = make(map[string]struct{}) - } - for i := range ids { - m.credit_allocations[ids[i]] = struct{}{} +// 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 *ChargeFlatFeeCostBasisMutation) ResetEdge(name string) error { + switch name { + case chargeflatfeecostbasis.EdgeCurrencyCostBasis: + m.ResetCurrencyCostBasis() + return nil + case chargeflatfeecostbasis.EdgeResolvedCurrencyCostBasis: + m.ResetResolvedCurrencyCostBasis() + return nil + case chargeflatfeecostbasis.EdgeCustomCurrency: + m.ResetCustomCurrency() + return nil } + return fmt.Errorf("unknown ChargeFlatFeeCostBasis edge %s", name) } -// ClearCreditAllocations clears the "credit_allocations" edge to the ChargeFlatFeeRunCreditAllocations entity. -func (m *ChargeFlatFeeRunMutation) ClearCreditAllocations() { - m.clearedcredit_allocations = true +// ChargeFlatFeeOverrideMutation represents an operation that mutates the ChargeFlatFeeOverride nodes in the graph. +type ChargeFlatFeeOverrideMutation struct { + config + op Op + typ string + id *string + namespace *string + name *string + description *string + metadata **models.Metadata + tax_behavior *productcatalog.TaxBehavior + intent_deleted_at *time.Time + service_period_from *time.Time + service_period_to *time.Time + full_service_period_from *time.Time + full_service_period_to *time.Time + billing_period_from *time.Time + billing_period_to *time.Time + invoice_at *time.Time + feature_key *string + payment_term *productcatalog.PaymentTermType + pro_rating **productcatalog.ProRatingConfig + amount_before_proration *alpacadecimal.Decimal + discounts **billing.Discounts + percentage_discounts **billing.PercentageDiscount + clearedFields map[string]struct{} + flat_fee *string + clearedflat_fee bool + tax_code *string + clearedtax_code bool + done bool + oldValue func(context.Context) (*ChargeFlatFeeOverride, error) + predicates []predicate.ChargeFlatFeeOverride } -// CreditAllocationsCleared reports if the "credit_allocations" edge to the ChargeFlatFeeRunCreditAllocations entity was cleared. -func (m *ChargeFlatFeeRunMutation) CreditAllocationsCleared() bool { - return m.clearedcredit_allocations -} +var _ ent.Mutation = (*ChargeFlatFeeOverrideMutation)(nil) -// RemoveCreditAllocationIDs removes the "credit_allocations" edge to the ChargeFlatFeeRunCreditAllocations entity by IDs. -func (m *ChargeFlatFeeRunMutation) RemoveCreditAllocationIDs(ids ...string) { - if m.removedcredit_allocations == nil { - m.removedcredit_allocations = make(map[string]struct{}) +// chargeflatfeeoverrideOption allows management of the mutation configuration using functional options. +type chargeflatfeeoverrideOption func(*ChargeFlatFeeOverrideMutation) + +// newChargeFlatFeeOverrideMutation creates new mutation for the ChargeFlatFeeOverride entity. +func newChargeFlatFeeOverrideMutation(c config, op Op, opts ...chargeflatfeeoverrideOption) *ChargeFlatFeeOverrideMutation { + m := &ChargeFlatFeeOverrideMutation{ + config: c, + op: op, + typ: TypeChargeFlatFeeOverride, + clearedFields: make(map[string]struct{}), } - for i := range ids { - delete(m.credit_allocations, ids[i]) - m.removedcredit_allocations[ids[i]] = struct{}{} + for _, opt := range opts { + opt(m) } + return m } -// RemovedCreditAllocations returns the removed IDs of the "credit_allocations" edge to the ChargeFlatFeeRunCreditAllocations entity. -func (m *ChargeFlatFeeRunMutation) RemovedCreditAllocationsIDs() (ids []string) { - for id := range m.removedcredit_allocations { - ids = append(ids, id) +// withChargeFlatFeeOverrideID sets the ID field of the mutation. +func withChargeFlatFeeOverrideID(id string) chargeflatfeeoverrideOption { + return func(m *ChargeFlatFeeOverrideMutation) { + var ( + err error + once sync.Once + value *ChargeFlatFeeOverride + ) + m.oldValue = func(ctx context.Context) (*ChargeFlatFeeOverride, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().ChargeFlatFeeOverride.Get(ctx, id) + } + }) + return value, err + } + m.id = &id } - return } -// CreditAllocationsIDs returns the "credit_allocations" edge IDs in the mutation. -func (m *ChargeFlatFeeRunMutation) CreditAllocationsIDs() (ids []string) { - for id := range m.credit_allocations { - ids = append(ids, id) +// withChargeFlatFeeOverride sets the old ChargeFlatFeeOverride of the mutation. +func withChargeFlatFeeOverride(node *ChargeFlatFeeOverride) chargeflatfeeoverrideOption { + return func(m *ChargeFlatFeeOverrideMutation) { + m.oldValue = func(context.Context) (*ChargeFlatFeeOverride, error) { + return node, nil + } + m.id = &node.ID } - return } -// ResetCreditAllocations resets all changes to the "credit_allocations" edge. -func (m *ChargeFlatFeeRunMutation) ResetCreditAllocations() { - m.credit_allocations = nil - m.clearedcredit_allocations = false - m.removedcredit_allocations = nil +// 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 ChargeFlatFeeOverrideMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client } -// AddDetailedLineIDs adds the "detailed_lines" edge to the ChargeFlatFeeRunDetailedLine entity by ids. -func (m *ChargeFlatFeeRunMutation) AddDetailedLineIDs(ids ...string) { - if m.detailed_lines == nil { - m.detailed_lines = make(map[string]struct{}) - } - for i := range ids { - m.detailed_lines[ids[i]] = struct{}{} +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m ChargeFlatFeeOverrideMutation) 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 } -// ClearDetailedLines clears the "detailed_lines" edge to the ChargeFlatFeeRunDetailedLine entity. -func (m *ChargeFlatFeeRunMutation) ClearDetailedLines() { - m.cleareddetailed_lines = true +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of ChargeFlatFeeOverride entities. +func (m *ChargeFlatFeeOverrideMutation) SetID(id string) { + m.id = &id } -// DetailedLinesCleared reports if the "detailed_lines" edge to the ChargeFlatFeeRunDetailedLine entity was cleared. -func (m *ChargeFlatFeeRunMutation) DetailedLinesCleared() bool { - return m.cleareddetailed_lines +// 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 *ChargeFlatFeeOverrideMutation) ID() (id string, exists bool) { + if m.id == nil { + return + } + return *m.id, true } -// RemoveDetailedLineIDs removes the "detailed_lines" edge to the ChargeFlatFeeRunDetailedLine entity by IDs. -func (m *ChargeFlatFeeRunMutation) RemoveDetailedLineIDs(ids ...string) { - if m.removeddetailed_lines == nil { - m.removeddetailed_lines = make(map[string]struct{}) - } - for i := range ids { - delete(m.detailed_lines, ids[i]) - m.removeddetailed_lines[ids[i]] = struct{}{} +// 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 *ChargeFlatFeeOverrideMutation) 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().ChargeFlatFeeOverride.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } -// RemovedDetailedLines returns the removed IDs of the "detailed_lines" edge to the ChargeFlatFeeRunDetailedLine entity. -func (m *ChargeFlatFeeRunMutation) RemovedDetailedLinesIDs() (ids []string) { - for id := range m.removeddetailed_lines { - ids = append(ids, id) - } - return +// SetNamespace sets the "namespace" field. +func (m *ChargeFlatFeeOverrideMutation) SetNamespace(s string) { + m.namespace = &s } -// DetailedLinesIDs returns the "detailed_lines" edge IDs in the mutation. -func (m *ChargeFlatFeeRunMutation) DetailedLinesIDs() (ids []string) { - for id := range m.detailed_lines { - ids = append(ids, id) +// Namespace returns the value of the "namespace" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) Namespace() (r string, exists bool) { + v := m.namespace + if v == nil { + return } - return + return *v, true } -// ResetDetailedLines resets all changes to the "detailed_lines" edge. -func (m *ChargeFlatFeeRunMutation) ResetDetailedLines() { - m.detailed_lines = nil - m.cleareddetailed_lines = false - m.removeddetailed_lines = nil +// OldNamespace returns the old "namespace" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) 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 } -// SetInvoicedUsageID sets the "invoiced_usage" edge to the ChargeFlatFeeRunInvoicedUsage entity by id. -func (m *ChargeFlatFeeRunMutation) SetInvoicedUsageID(id string) { - m.invoiced_usage = &id +// ResetNamespace resets all changes to the "namespace" field. +func (m *ChargeFlatFeeOverrideMutation) ResetNamespace() { + m.namespace = nil } -// ClearInvoicedUsage clears the "invoiced_usage" edge to the ChargeFlatFeeRunInvoicedUsage entity. -func (m *ChargeFlatFeeRunMutation) ClearInvoicedUsage() { - m.clearedinvoiced_usage = true +// SetChargeID sets the "charge_id" field. +func (m *ChargeFlatFeeOverrideMutation) SetChargeID(s string) { + m.flat_fee = &s } -// InvoicedUsageCleared reports if the "invoiced_usage" edge to the ChargeFlatFeeRunInvoicedUsage entity was cleared. -func (m *ChargeFlatFeeRunMutation) InvoicedUsageCleared() bool { - return m.clearedinvoiced_usage +// ChargeID returns the value of the "charge_id" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) ChargeID() (r string, exists bool) { + v := m.flat_fee + if v == nil { + return + } + return *v, true } -// InvoicedUsageID returns the "invoiced_usage" edge ID in the mutation. -func (m *ChargeFlatFeeRunMutation) InvoicedUsageID() (id string, exists bool) { - if m.invoiced_usage != nil { - return *m.invoiced_usage, true +// OldChargeID returns the old "charge_id" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldChargeID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldChargeID is only allowed on UpdateOne operations") } - return + 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 } -// InvoicedUsageIDs returns the "invoiced_usage" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// InvoicedUsageID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeRunMutation) InvoicedUsageIDs() (ids []string) { - if id := m.invoiced_usage; id != nil { - ids = append(ids, *id) - } - return +// ResetChargeID resets all changes to the "charge_id" field. +func (m *ChargeFlatFeeOverrideMutation) ResetChargeID() { + m.flat_fee = nil } -// ResetInvoicedUsage resets all changes to the "invoiced_usage" edge. -func (m *ChargeFlatFeeRunMutation) ResetInvoicedUsage() { - m.invoiced_usage = nil - m.clearedinvoiced_usage = false +// SetName sets the "name" field. +func (m *ChargeFlatFeeOverrideMutation) SetName(s string) { + m.name = &s } -// SetPaymentID sets the "payment" edge to the ChargeFlatFeeRunPayment entity by id. -func (m *ChargeFlatFeeRunMutation) SetPaymentID(id string) { - m.payment = &id +// Name returns the value of the "name" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true } -// ClearPayment clears the "payment" edge to the ChargeFlatFeeRunPayment entity. -func (m *ChargeFlatFeeRunMutation) ClearPayment() { - m.clearedpayment = true +// OldName returns the old "name" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) 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 } -// PaymentCleared reports if the "payment" edge to the ChargeFlatFeeRunPayment entity was cleared. -func (m *ChargeFlatFeeRunMutation) PaymentCleared() bool { - return m.clearedpayment +// ResetName resets all changes to the "name" field. +func (m *ChargeFlatFeeOverrideMutation) ResetName() { + m.name = nil } -// PaymentID returns the "payment" edge ID in the mutation. -func (m *ChargeFlatFeeRunMutation) PaymentID() (id string, exists bool) { - if m.payment != nil { - return *m.payment, true - } - return +// SetDescription sets the "description" field. +func (m *ChargeFlatFeeOverrideMutation) SetDescription(s string) { + m.description = &s } -// PaymentIDs returns the "payment" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// PaymentID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeRunMutation) PaymentIDs() (ids []string) { - if id := m.payment; id != nil { - ids = append(ids, *id) +// Description returns the value of the "description" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return } - return + return *v, true } -// ResetPayment resets all changes to the "payment" edge. -func (m *ChargeFlatFeeRunMutation) ResetPayment() { - m.payment = nil - m.clearedpayment = false +// OldDescription returns the old "description" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) 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 } -// Where appends a list predicates to the ChargeFlatFeeRunMutation builder. -func (m *ChargeFlatFeeRunMutation) Where(ps ...predicate.ChargeFlatFeeRun) { - m.predicates = append(m.predicates, ps...) +// ClearDescription clears the value of the "description" field. +func (m *ChargeFlatFeeOverrideMutation) ClearDescription() { + m.description = nil + m.clearedFields[chargeflatfeeoverride.FieldDescription] = struct{}{} } -// WhereP appends storage-level predicates to the ChargeFlatFeeRunMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *ChargeFlatFeeRunMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.ChargeFlatFeeRun, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *ChargeFlatFeeOverrideMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[chargeflatfeeoverride.FieldDescription] + return ok } -// Op returns the operation name. -func (m *ChargeFlatFeeRunMutation) Op() Op { - return m.op +// ResetDescription resets all changes to the "description" field. +func (m *ChargeFlatFeeOverrideMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, chargeflatfeeoverride.FieldDescription) } -// SetOp allows setting the mutation operation. -func (m *ChargeFlatFeeRunMutation) SetOp(op Op) { - m.op = op +// SetMetadata sets the "metadata" field. +func (m *ChargeFlatFeeOverrideMutation) SetMetadata(value *models.Metadata) { + m.metadata = &value } -// Type returns the node type of this mutation (ChargeFlatFeeRun). -func (m *ChargeFlatFeeRunMutation) Type() string { - return m.typ +// Metadata returns the value of the "metadata" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) Metadata() (r *models.Metadata, exists bool) { + v := m.metadata + if v == nil { + return + } + return *v, true } -// 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 *ChargeFlatFeeRunMutation) Fields() []string { - fields := make([]string, 0, 22) - if m.namespace != nil { - fields = append(fields, chargeflatfeerun.FieldNamespace) +// OldMetadata returns the old "metadata" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldMetadata(ctx context.Context) (v *models.Metadata, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMetadata is only allowed on UpdateOne operations") } - if m.created_at != nil { - fields = append(fields, chargeflatfeerun.FieldCreatedAt) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMetadata requires an ID field in the mutation") } - if m.updated_at != nil { - fields = append(fields, chargeflatfeerun.FieldUpdatedAt) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMetadata: %w", err) } - if m.deleted_at != nil { - fields = append(fields, chargeflatfeerun.FieldDeletedAt) + return oldValue.Metadata, nil +} + +// ClearMetadata clears the value of the "metadata" field. +func (m *ChargeFlatFeeOverrideMutation) ClearMetadata() { + m.metadata = nil + m.clearedFields[chargeflatfeeoverride.FieldMetadata] = struct{}{} +} + +// MetadataCleared returns if the "metadata" field was cleared in this mutation. +func (m *ChargeFlatFeeOverrideMutation) MetadataCleared() bool { + _, ok := m.clearedFields[chargeflatfeeoverride.FieldMetadata] + return ok +} + +// ResetMetadata resets all changes to the "metadata" field. +func (m *ChargeFlatFeeOverrideMutation) ResetMetadata() { + m.metadata = nil + delete(m.clearedFields, chargeflatfeeoverride.FieldMetadata) +} + +// SetTaxBehavior sets the "tax_behavior" field. +func (m *ChargeFlatFeeOverrideMutation) SetTaxBehavior(pb productcatalog.TaxBehavior) { + m.tax_behavior = &pb +} + +// TaxBehavior returns the value of the "tax_behavior" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) TaxBehavior() (r productcatalog.TaxBehavior, exists bool) { + v := m.tax_behavior + if v == nil { + return } - if m.amount != nil { - fields = append(fields, chargeflatfeerun.FieldAmount) + return *v, true +} + +// OldTaxBehavior returns the old "tax_behavior" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) 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.taxes_total != nil { - fields = append(fields, chargeflatfeerun.FieldTaxesTotal) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTaxBehavior requires an ID field in the mutation") } - if m.taxes_inclusive_total != nil { - fields = append(fields, chargeflatfeerun.FieldTaxesInclusiveTotal) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTaxBehavior: %w", err) } - if m.taxes_exclusive_total != nil { - fields = append(fields, chargeflatfeerun.FieldTaxesExclusiveTotal) + return oldValue.TaxBehavior, nil +} + +// ClearTaxBehavior clears the value of the "tax_behavior" field. +func (m *ChargeFlatFeeOverrideMutation) ClearTaxBehavior() { + m.tax_behavior = nil + m.clearedFields[chargeflatfeeoverride.FieldTaxBehavior] = struct{}{} +} + +// TaxBehaviorCleared returns if the "tax_behavior" field was cleared in this mutation. +func (m *ChargeFlatFeeOverrideMutation) TaxBehaviorCleared() bool { + _, ok := m.clearedFields[chargeflatfeeoverride.FieldTaxBehavior] + return ok +} + +// ResetTaxBehavior resets all changes to the "tax_behavior" field. +func (m *ChargeFlatFeeOverrideMutation) ResetTaxBehavior() { + m.tax_behavior = nil + delete(m.clearedFields, chargeflatfeeoverride.FieldTaxBehavior) +} + +// SetTaxCodeID sets the "tax_code_id" field. +func (m *ChargeFlatFeeOverrideMutation) SetTaxCodeID(s string) { + m.tax_code = &s +} + +// TaxCodeID returns the value of the "tax_code_id" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) TaxCodeID() (r string, exists bool) { + v := m.tax_code + if v == nil { + return } - if m.charges_total != nil { - fields = append(fields, chargeflatfeerun.FieldChargesTotal) + return *v, true +} + +// OldTaxCodeID returns the old "tax_code_id" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) 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.discounts_total != nil { - fields = append(fields, chargeflatfeerun.FieldDiscountsTotal) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTaxCodeID requires an ID field in the mutation") } - if m.credits_total != nil { - fields = append(fields, chargeflatfeerun.FieldCreditsTotal) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTaxCodeID: %w", err) } - if m.total != nil { - fields = append(fields, chargeflatfeerun.FieldTotal) + return oldValue.TaxCodeID, nil +} + +// ClearTaxCodeID clears the value of the "tax_code_id" field. +func (m *ChargeFlatFeeOverrideMutation) ClearTaxCodeID() { + m.tax_code = nil + m.clearedFields[chargeflatfeeoverride.FieldTaxCodeID] = struct{}{} +} + +// TaxCodeIDCleared returns if the "tax_code_id" field was cleared in this mutation. +func (m *ChargeFlatFeeOverrideMutation) TaxCodeIDCleared() bool { + _, ok := m.clearedFields[chargeflatfeeoverride.FieldTaxCodeID] + return ok +} + +// ResetTaxCodeID resets all changes to the "tax_code_id" field. +func (m *ChargeFlatFeeOverrideMutation) ResetTaxCodeID() { + m.tax_code = nil + delete(m.clearedFields, chargeflatfeeoverride.FieldTaxCodeID) +} + +// SetIntentDeletedAt sets the "intent_deleted_at" field. +func (m *ChargeFlatFeeOverrideMutation) SetIntentDeletedAt(t time.Time) { + m.intent_deleted_at = &t +} + +// IntentDeletedAt returns the value of the "intent_deleted_at" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) IntentDeletedAt() (r time.Time, exists bool) { + v := m.intent_deleted_at + if v == nil { + return } - if m.flat_fee != nil { - fields = append(fields, chargeflatfeerun.FieldChargeID) + return *v, true +} + +// OldIntentDeletedAt returns the old "intent_deleted_at" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldIntentDeletedAt(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIntentDeletedAt is only allowed on UpdateOne operations") } - if m._type != nil { - fields = append(fields, chargeflatfeerun.FieldType) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIntentDeletedAt requires an ID field in the mutation") } - if m.initial_type != nil { - fields = append(fields, chargeflatfeerun.FieldInitialType) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIntentDeletedAt: %w", err) } - if m.service_period_from != nil { - fields = append(fields, chargeflatfeerun.FieldServicePeriodFrom) + return oldValue.IntentDeletedAt, nil +} + +// ClearIntentDeletedAt clears the value of the "intent_deleted_at" field. +func (m *ChargeFlatFeeOverrideMutation) ClearIntentDeletedAt() { + m.intent_deleted_at = nil + m.clearedFields[chargeflatfeeoverride.FieldIntentDeletedAt] = struct{}{} +} + +// IntentDeletedAtCleared returns if the "intent_deleted_at" field was cleared in this mutation. +func (m *ChargeFlatFeeOverrideMutation) IntentDeletedAtCleared() bool { + _, ok := m.clearedFields[chargeflatfeeoverride.FieldIntentDeletedAt] + return ok +} + +// ResetIntentDeletedAt resets all changes to the "intent_deleted_at" field. +func (m *ChargeFlatFeeOverrideMutation) ResetIntentDeletedAt() { + m.intent_deleted_at = nil + delete(m.clearedFields, chargeflatfeeoverride.FieldIntentDeletedAt) +} + +// SetServicePeriodFrom sets the "service_period_from" field. +func (m *ChargeFlatFeeOverrideMutation) SetServicePeriodFrom(t time.Time) { + m.service_period_from = &t +} + +// ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) ServicePeriodFrom() (r time.Time, exists bool) { + v := m.service_period_from + if v == nil { + return } - if m.service_period_to != nil { - fields = append(fields, chargeflatfeerun.FieldServicePeriodTo) + return *v, true +} + +// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") } - if m.billing_invoice_line != nil { - fields = append(fields, chargeflatfeerun.FieldLineID) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldServicePeriodFrom requires an ID field in the mutation") } - if m.billing_invoice != nil { - fields = append(fields, chargeflatfeerun.FieldInvoiceID) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldServicePeriodFrom: %w", err) } - if m.amount_after_proration != nil { - fields = append(fields, chargeflatfeerun.FieldAmountAfterProration) + return oldValue.ServicePeriodFrom, nil +} + +// ResetServicePeriodFrom resets all changes to the "service_period_from" field. +func (m *ChargeFlatFeeOverrideMutation) ResetServicePeriodFrom() { + m.service_period_from = nil +} + +// SetServicePeriodTo sets the "service_period_to" field. +func (m *ChargeFlatFeeOverrideMutation) SetServicePeriodTo(t time.Time) { + m.service_period_to = &t +} + +// ServicePeriodTo returns the value of the "service_period_to" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) ServicePeriodTo() (r time.Time, exists bool) { + v := m.service_period_to + if v == nil { + return } - if m.no_fiat_transaction_required != nil { - fields = append(fields, chargeflatfeerun.FieldNoFiatTransactionRequired) + return *v, true +} + +// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") } - if m.immutable != nil { - fields = append(fields, chargeflatfeerun.FieldImmutable) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldServicePeriodTo requires an ID field in the mutation") } - return fields + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldServicePeriodTo: %w", err) + } + return oldValue.ServicePeriodTo, nil } -// 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 *ChargeFlatFeeRunMutation) Field(name string) (ent.Value, bool) { - switch name { - case chargeflatfeerun.FieldNamespace: - return m.Namespace() - case chargeflatfeerun.FieldCreatedAt: - return m.CreatedAt() - case chargeflatfeerun.FieldUpdatedAt: - return m.UpdatedAt() - case chargeflatfeerun.FieldDeletedAt: - return m.DeletedAt() - case chargeflatfeerun.FieldAmount: - return m.Amount() - case chargeflatfeerun.FieldTaxesTotal: - return m.TaxesTotal() - case chargeflatfeerun.FieldTaxesInclusiveTotal: - return m.TaxesInclusiveTotal() - case chargeflatfeerun.FieldTaxesExclusiveTotal: - return m.TaxesExclusiveTotal() - case chargeflatfeerun.FieldChargesTotal: - return m.ChargesTotal() - case chargeflatfeerun.FieldDiscountsTotal: - return m.DiscountsTotal() - case chargeflatfeerun.FieldCreditsTotal: - return m.CreditsTotal() - case chargeflatfeerun.FieldTotal: - return m.Total() - case chargeflatfeerun.FieldChargeID: - return m.ChargeID() - case chargeflatfeerun.FieldType: - return m.GetType() - case chargeflatfeerun.FieldInitialType: - return m.InitialType() - case chargeflatfeerun.FieldServicePeriodFrom: - return m.ServicePeriodFrom() - case chargeflatfeerun.FieldServicePeriodTo: - return m.ServicePeriodTo() - case chargeflatfeerun.FieldLineID: - return m.LineID() - case chargeflatfeerun.FieldInvoiceID: - return m.InvoiceID() - case chargeflatfeerun.FieldAmountAfterProration: - return m.AmountAfterProration() - case chargeflatfeerun.FieldNoFiatTransactionRequired: - return m.NoFiatTransactionRequired() - case chargeflatfeerun.FieldImmutable: - return m.Immutable() +// ResetServicePeriodTo resets all changes to the "service_period_to" field. +func (m *ChargeFlatFeeOverrideMutation) ResetServicePeriodTo() { + m.service_period_to = nil +} + +// SetFullServicePeriodFrom sets the "full_service_period_from" field. +func (m *ChargeFlatFeeOverrideMutation) SetFullServicePeriodFrom(t time.Time) { + m.full_service_period_from = &t +} + +// FullServicePeriodFrom returns the value of the "full_service_period_from" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) FullServicePeriodFrom() (r time.Time, exists bool) { + v := m.full_service_period_from + if v == nil { + return } - return nil, false + return *v, true } -// 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 *ChargeFlatFeeRunMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case chargeflatfeerun.FieldNamespace: - return m.OldNamespace(ctx) - case chargeflatfeerun.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case chargeflatfeerun.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - case chargeflatfeerun.FieldDeletedAt: - return m.OldDeletedAt(ctx) - case chargeflatfeerun.FieldAmount: - return m.OldAmount(ctx) - case chargeflatfeerun.FieldTaxesTotal: - return m.OldTaxesTotal(ctx) - case chargeflatfeerun.FieldTaxesInclusiveTotal: - return m.OldTaxesInclusiveTotal(ctx) - case chargeflatfeerun.FieldTaxesExclusiveTotal: - return m.OldTaxesExclusiveTotal(ctx) - case chargeflatfeerun.FieldChargesTotal: - return m.OldChargesTotal(ctx) - case chargeflatfeerun.FieldDiscountsTotal: - return m.OldDiscountsTotal(ctx) - case chargeflatfeerun.FieldCreditsTotal: - return m.OldCreditsTotal(ctx) - case chargeflatfeerun.FieldTotal: - return m.OldTotal(ctx) - case chargeflatfeerun.FieldChargeID: - return m.OldChargeID(ctx) - case chargeflatfeerun.FieldType: - return m.OldType(ctx) - case chargeflatfeerun.FieldInitialType: - return m.OldInitialType(ctx) - case chargeflatfeerun.FieldServicePeriodFrom: - return m.OldServicePeriodFrom(ctx) - case chargeflatfeerun.FieldServicePeriodTo: - return m.OldServicePeriodTo(ctx) - case chargeflatfeerun.FieldLineID: - return m.OldLineID(ctx) - case chargeflatfeerun.FieldInvoiceID: - return m.OldInvoiceID(ctx) - case chargeflatfeerun.FieldAmountAfterProration: - return m.OldAmountAfterProration(ctx) - case chargeflatfeerun.FieldNoFiatTransactionRequired: - return m.OldNoFiatTransactionRequired(ctx) - case chargeflatfeerun.FieldImmutable: - return m.OldImmutable(ctx) +// OldFullServicePeriodFrom returns the old "full_service_period_from" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldFullServicePeriodFrom(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFullServicePeriodFrom is only allowed on UpdateOne operations") } - return nil, fmt.Errorf("unknown ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) SetField(name string, value ent.Value) error { - switch name { - case chargeflatfeerun.FieldNamespace: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetNamespace(v) - return nil - case chargeflatfeerun.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 chargeflatfeerun.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 chargeflatfeerun.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 chargeflatfeerun.FieldAmount: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetAmount(v) - return nil - case chargeflatfeerun.FieldTaxesTotal: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetTaxesTotal(v) - return nil - case chargeflatfeerun.FieldTaxesInclusiveTotal: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetTaxesInclusiveTotal(v) - return nil - case chargeflatfeerun.FieldTaxesExclusiveTotal: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetTaxesExclusiveTotal(v) - return nil - case chargeflatfeerun.FieldChargesTotal: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetChargesTotal(v) - return nil - case chargeflatfeerun.FieldDiscountsTotal: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDiscountsTotal(v) - return nil - case chargeflatfeerun.FieldCreditsTotal: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreditsTotal(v) - return nil - case chargeflatfeerun.FieldTotal: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetTotal(v) - return nil - case chargeflatfeerun.FieldChargeID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetChargeID(v) - return nil - case chargeflatfeerun.FieldType: - v, ok := value.(flatfee.RealizationRunType) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetType(v) - return nil - case chargeflatfeerun.FieldInitialType: - v, ok := value.(flatfee.RealizationRunType) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetInitialType(v) - return nil - case chargeflatfeerun.FieldServicePeriodFrom: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetServicePeriodFrom(v) - return nil - case chargeflatfeerun.FieldServicePeriodTo: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetServicePeriodTo(v) - return nil - case chargeflatfeerun.FieldLineID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetLineID(v) - return nil - case chargeflatfeerun.FieldInvoiceID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetInvoiceID(v) - return nil - case chargeflatfeerun.FieldAmountAfterProration: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetAmountAfterProration(v) - return nil - case chargeflatfeerun.FieldNoFiatTransactionRequired: - v, ok := value.(bool) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetNoFiatTransactionRequired(v) - return nil - case chargeflatfeerun.FieldImmutable: - v, ok := value.(bool) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetImmutable(v) - return nil + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFullServicePeriodFrom requires an ID field in the mutation") } - return fmt.Errorf("unknown ChargeFlatFeeRun field %s", name) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFullServicePeriodFrom: %w", err) + } + return oldValue.FullServicePeriodFrom, nil } -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *ChargeFlatFeeRunMutation) AddedFields() []string { - return nil +// ResetFullServicePeriodFrom resets all changes to the "full_service_period_from" field. +func (m *ChargeFlatFeeOverrideMutation) ResetFullServicePeriodFrom() { + m.full_service_period_from = 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 *ChargeFlatFeeRunMutation) AddedField(name string) (ent.Value, bool) { - return nil, false +// SetFullServicePeriodTo sets the "full_service_period_to" field. +func (m *ChargeFlatFeeOverrideMutation) SetFullServicePeriodTo(t time.Time) { + m.full_service_period_to = &t } -// 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 *ChargeFlatFeeRunMutation) AddField(name string, value ent.Value) error { - switch name { +// FullServicePeriodTo returns the value of the "full_service_period_to" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) FullServicePeriodTo() (r time.Time, exists bool) { + v := m.full_service_period_to + if v == nil { + return } - return fmt.Errorf("unknown ChargeFlatFeeRun numeric field %s", name) + return *v, true } -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *ChargeFlatFeeRunMutation) ClearedFields() []string { - var fields []string - if m.FieldCleared(chargeflatfeerun.FieldDeletedAt) { - fields = append(fields, chargeflatfeerun.FieldDeletedAt) +// OldFullServicePeriodTo returns the old "full_service_period_to" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldFullServicePeriodTo(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFullServicePeriodTo is only allowed on UpdateOne operations") } - if m.FieldCleared(chargeflatfeerun.FieldLineID) { - fields = append(fields, chargeflatfeerun.FieldLineID) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFullServicePeriodTo requires an ID field in the mutation") } - if m.FieldCleared(chargeflatfeerun.FieldInvoiceID) { - fields = append(fields, chargeflatfeerun.FieldInvoiceID) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFullServicePeriodTo: %w", err) } - return fields + return oldValue.FullServicePeriodTo, nil } -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *ChargeFlatFeeRunMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok +// ResetFullServicePeriodTo resets all changes to the "full_service_period_to" field. +func (m *ChargeFlatFeeOverrideMutation) ResetFullServicePeriodTo() { + m.full_service_period_to = nil } -// 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 *ChargeFlatFeeRunMutation) ClearField(name string) error { - switch name { - case chargeflatfeerun.FieldDeletedAt: - m.ClearDeletedAt() - return nil - case chargeflatfeerun.FieldLineID: - m.ClearLineID() - return nil - case chargeflatfeerun.FieldInvoiceID: - m.ClearInvoiceID() - return nil - } - return fmt.Errorf("unknown ChargeFlatFeeRun nullable field %s", name) +// SetBillingPeriodFrom sets the "billing_period_from" field. +func (m *ChargeFlatFeeOverrideMutation) SetBillingPeriodFrom(t time.Time) { + m.billing_period_from = &t } -// 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 *ChargeFlatFeeRunMutation) ResetField(name string) error { - switch name { - case chargeflatfeerun.FieldNamespace: - m.ResetNamespace() - return nil - case chargeflatfeerun.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case chargeflatfeerun.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - case chargeflatfeerun.FieldDeletedAt: - m.ResetDeletedAt() - return nil - case chargeflatfeerun.FieldAmount: - m.ResetAmount() - return nil - case chargeflatfeerun.FieldTaxesTotal: - m.ResetTaxesTotal() - return nil - case chargeflatfeerun.FieldTaxesInclusiveTotal: - m.ResetTaxesInclusiveTotal() - return nil - case chargeflatfeerun.FieldTaxesExclusiveTotal: - m.ResetTaxesExclusiveTotal() - return nil - case chargeflatfeerun.FieldChargesTotal: - m.ResetChargesTotal() - return nil - case chargeflatfeerun.FieldDiscountsTotal: - m.ResetDiscountsTotal() - return nil - case chargeflatfeerun.FieldCreditsTotal: - m.ResetCreditsTotal() - return nil - case chargeflatfeerun.FieldTotal: - m.ResetTotal() - return nil - case chargeflatfeerun.FieldChargeID: - m.ResetChargeID() - return nil - case chargeflatfeerun.FieldType: - m.ResetType() - return nil - case chargeflatfeerun.FieldInitialType: - m.ResetInitialType() - return nil - case chargeflatfeerun.FieldServicePeriodFrom: - m.ResetServicePeriodFrom() - return nil - case chargeflatfeerun.FieldServicePeriodTo: - m.ResetServicePeriodTo() - return nil - case chargeflatfeerun.FieldLineID: - m.ResetLineID() - return nil - case chargeflatfeerun.FieldInvoiceID: - m.ResetInvoiceID() - return nil - case chargeflatfeerun.FieldAmountAfterProration: - m.ResetAmountAfterProration() - return nil - case chargeflatfeerun.FieldNoFiatTransactionRequired: - m.ResetNoFiatTransactionRequired() - return nil - case chargeflatfeerun.FieldImmutable: - m.ResetImmutable() - return nil +// BillingPeriodFrom returns the value of the "billing_period_from" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) BillingPeriodFrom() (r time.Time, exists bool) { + v := m.billing_period_from + if v == nil { + return } - return fmt.Errorf("unknown ChargeFlatFeeRun field %s", name) + return *v, true } -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *ChargeFlatFeeRunMutation) AddedEdges() []string { - edges := make([]string, 0, 7) - if m.flat_fee != nil { - edges = append(edges, chargeflatfeerun.EdgeFlatFee) +// OldBillingPeriodFrom returns the old "billing_period_from" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldBillingPeriodFrom(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBillingPeriodFrom is only allowed on UpdateOne operations") } - if m.billing_invoice_line != nil { - edges = append(edges, chargeflatfeerun.EdgeBillingInvoiceLine) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBillingPeriodFrom requires an ID field in the mutation") } - if m.billing_invoice != nil { - edges = append(edges, chargeflatfeerun.EdgeBillingInvoice) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBillingPeriodFrom: %w", err) } - if m.credit_allocations != nil { - edges = append(edges, chargeflatfeerun.EdgeCreditAllocations) + return oldValue.BillingPeriodFrom, nil +} + +// ResetBillingPeriodFrom resets all changes to the "billing_period_from" field. +func (m *ChargeFlatFeeOverrideMutation) ResetBillingPeriodFrom() { + m.billing_period_from = nil +} + +// SetBillingPeriodTo sets the "billing_period_to" field. +func (m *ChargeFlatFeeOverrideMutation) SetBillingPeriodTo(t time.Time) { + m.billing_period_to = &t +} + +// BillingPeriodTo returns the value of the "billing_period_to" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) BillingPeriodTo() (r time.Time, exists bool) { + v := m.billing_period_to + if v == nil { + return } - if m.detailed_lines != nil { - edges = append(edges, chargeflatfeerun.EdgeDetailedLines) + return *v, true +} + +// OldBillingPeriodTo returns the old "billing_period_to" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) OldBillingPeriodTo(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBillingPeriodTo is only allowed on UpdateOne operations") } - if m.invoiced_usage != nil { - edges = append(edges, chargeflatfeerun.EdgeInvoicedUsage) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBillingPeriodTo requires an ID field in the mutation") } - if m.payment != nil { - edges = append(edges, chargeflatfeerun.EdgePayment) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBillingPeriodTo: %w", err) } - return edges + return oldValue.BillingPeriodTo, nil } -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *ChargeFlatFeeRunMutation) AddedIDs(name string) []ent.Value { - switch name { - case chargeflatfeerun.EdgeFlatFee: - if id := m.flat_fee; id != nil { - return []ent.Value{*id} - } - case chargeflatfeerun.EdgeBillingInvoiceLine: - if id := m.billing_invoice_line; id != nil { - return []ent.Value{*id} - } - case chargeflatfeerun.EdgeBillingInvoice: - if id := m.billing_invoice; id != nil { - return []ent.Value{*id} - } - case chargeflatfeerun.EdgeCreditAllocations: - ids := make([]ent.Value, 0, len(m.credit_allocations)) - for id := range m.credit_allocations { - ids = append(ids, id) - } - return ids - case chargeflatfeerun.EdgeDetailedLines: - ids := make([]ent.Value, 0, len(m.detailed_lines)) - for id := range m.detailed_lines { - ids = append(ids, id) - } - return ids - case chargeflatfeerun.EdgeInvoicedUsage: - if id := m.invoiced_usage; id != nil { - return []ent.Value{*id} - } - case chargeflatfeerun.EdgePayment: - if id := m.payment; id != nil { - return []ent.Value{*id} - } - } - return nil +// ResetBillingPeriodTo resets all changes to the "billing_period_to" field. +func (m *ChargeFlatFeeOverrideMutation) ResetBillingPeriodTo() { + m.billing_period_to = nil } -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *ChargeFlatFeeRunMutation) RemovedEdges() []string { - edges := make([]string, 0, 7) - if m.removedcredit_allocations != nil { - edges = append(edges, chargeflatfeerun.EdgeCreditAllocations) - } - if m.removeddetailed_lines != nil { - edges = append(edges, chargeflatfeerun.EdgeDetailedLines) - } - return edges +// SetInvoiceAt sets the "invoice_at" field. +func (m *ChargeFlatFeeOverrideMutation) SetInvoiceAt(t time.Time) { + m.invoice_at = &t } -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *ChargeFlatFeeRunMutation) RemovedIDs(name string) []ent.Value { - switch name { - case chargeflatfeerun.EdgeCreditAllocations: - ids := make([]ent.Value, 0, len(m.removedcredit_allocations)) - for id := range m.removedcredit_allocations { - ids = append(ids, id) - } - return ids - case chargeflatfeerun.EdgeDetailedLines: - ids := make([]ent.Value, 0, len(m.removeddetailed_lines)) - for id := range m.removeddetailed_lines { - ids = append(ids, id) - } - return ids +// InvoiceAt returns the value of the "invoice_at" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) InvoiceAt() (r time.Time, exists bool) { + v := m.invoice_at + if v == nil { + return } - return nil + return *v, true } -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ChargeFlatFeeRunMutation) ClearedEdges() []string { - edges := make([]string, 0, 7) - if m.clearedflat_fee { - edges = append(edges, chargeflatfeerun.EdgeFlatFee) - } - if m.clearedbilling_invoice_line { - edges = append(edges, chargeflatfeerun.EdgeBillingInvoiceLine) - } - if m.clearedbilling_invoice { - edges = append(edges, chargeflatfeerun.EdgeBillingInvoice) - } - if m.clearedcredit_allocations { - edges = append(edges, chargeflatfeerun.EdgeCreditAllocations) - } - if m.cleareddetailed_lines { - edges = append(edges, chargeflatfeerun.EdgeDetailedLines) - } - if m.clearedinvoiced_usage { - edges = append(edges, chargeflatfeerun.EdgeInvoicedUsage) - } - if m.clearedpayment { - edges = append(edges, chargeflatfeerun.EdgePayment) - } - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *ChargeFlatFeeRunMutation) EdgeCleared(name string) bool { - switch name { - case chargeflatfeerun.EdgeFlatFee: - return m.clearedflat_fee - case chargeflatfeerun.EdgeBillingInvoiceLine: - return m.clearedbilling_invoice_line - case chargeflatfeerun.EdgeBillingInvoice: - return m.clearedbilling_invoice - case chargeflatfeerun.EdgeCreditAllocations: - return m.clearedcredit_allocations - case chargeflatfeerun.EdgeDetailedLines: - return m.cleareddetailed_lines - case chargeflatfeerun.EdgeInvoicedUsage: - return m.clearedinvoiced_usage - case chargeflatfeerun.EdgePayment: - return m.clearedpayment - } - 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 *ChargeFlatFeeRunMutation) ClearEdge(name string) error { - switch name { - case chargeflatfeerun.EdgeFlatFee: - m.ClearFlatFee() - return nil - case chargeflatfeerun.EdgeBillingInvoiceLine: - m.ClearBillingInvoiceLine() - return nil - case chargeflatfeerun.EdgeBillingInvoice: - m.ClearBillingInvoice() - return nil - case chargeflatfeerun.EdgeInvoicedUsage: - m.ClearInvoicedUsage() - return nil - case chargeflatfeerun.EdgePayment: - m.ClearPayment() - return nil - } - return fmt.Errorf("unknown ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) ResetEdge(name string) error { - switch name { - case chargeflatfeerun.EdgeFlatFee: - m.ResetFlatFee() - return nil - case chargeflatfeerun.EdgeBillingInvoiceLine: - m.ResetBillingInvoiceLine() - return nil - case chargeflatfeerun.EdgeBillingInvoice: - m.ResetBillingInvoice() - return nil - case chargeflatfeerun.EdgeCreditAllocations: - m.ResetCreditAllocations() - return nil - case chargeflatfeerun.EdgeDetailedLines: - m.ResetDetailedLines() - return nil - case chargeflatfeerun.EdgeInvoicedUsage: - m.ResetInvoicedUsage() - return nil - case chargeflatfeerun.EdgePayment: - m.ResetPayment() - return nil - } - return fmt.Errorf("unknown ChargeFlatFeeRun edge %s", name) -} - -// ChargeFlatFeeRunCreditAllocationsMutation represents an operation that mutates the ChargeFlatFeeRunCreditAllocations nodes in the graph. -type ChargeFlatFeeRunCreditAllocationsMutation struct { - config - op Op - typ string - id *string - amount *alpacadecimal.Decimal - service_period_from *time.Time - service_period_to *time.Time - ledger_transaction_group_id *string - sort_hint *int - addsort_hint *int - _type *creditrealization.Type - namespace *string - created_at *time.Time - updated_at *time.Time - deleted_at *time.Time - annotations *models.Annotations - clearedFields map[string]struct{} - corrections map[string]struct{} - removedcorrections map[string]struct{} - clearedcorrections bool - allocation *string - clearedallocation bool - run *string - clearedrun bool - billing_invoice_line *string - clearedbilling_invoice_line bool - done bool - oldValue func(context.Context) (*ChargeFlatFeeRunCreditAllocations, error) - predicates []predicate.ChargeFlatFeeRunCreditAllocations -} - -var _ ent.Mutation = (*ChargeFlatFeeRunCreditAllocationsMutation)(nil) - -// chargeflatfeeruncreditallocationsOption allows management of the mutation configuration using functional options. -type chargeflatfeeruncreditallocationsOption func(*ChargeFlatFeeRunCreditAllocationsMutation) - -// newChargeFlatFeeRunCreditAllocationsMutation creates new mutation for the ChargeFlatFeeRunCreditAllocations entity. -func newChargeFlatFeeRunCreditAllocationsMutation(c config, op Op, opts ...chargeflatfeeruncreditallocationsOption) *ChargeFlatFeeRunCreditAllocationsMutation { - m := &ChargeFlatFeeRunCreditAllocationsMutation{ - config: c, - op: op, - typ: TypeChargeFlatFeeRunCreditAllocations, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withChargeFlatFeeRunCreditAllocationsID sets the ID field of the mutation. -func withChargeFlatFeeRunCreditAllocationsID(id string) chargeflatfeeruncreditallocationsOption { - return func(m *ChargeFlatFeeRunCreditAllocationsMutation) { - var ( - err error - once sync.Once - value *ChargeFlatFeeRunCreditAllocations - ) - m.oldValue = func(ctx context.Context) (*ChargeFlatFeeRunCreditAllocations, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().ChargeFlatFeeRunCreditAllocations.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withChargeFlatFeeRunCreditAllocations sets the old ChargeFlatFeeRunCreditAllocations of the mutation. -func withChargeFlatFeeRunCreditAllocations(node *ChargeFlatFeeRunCreditAllocations) chargeflatfeeruncreditallocationsOption { - return func(m *ChargeFlatFeeRunCreditAllocationsMutation) { - m.oldValue = func(context.Context) (*ChargeFlatFeeRunCreditAllocations, error) { - return node, nil - } - m.id = &node.ID +// OldInvoiceAt returns the old "invoice_at" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeOverrideMutation) 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") } -} - -// 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 ChargeFlatFeeRunCreditAllocationsMutation) 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 ChargeFlatFeeRunCreditAllocationsMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, errors.New("db: mutation is not running in a transaction") + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldInvoiceAt requires an ID field in the mutation") } - 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 ChargeFlatFeeRunCreditAllocations entities. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) 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 *ChargeFlatFeeRunCreditAllocationsMutation) ID() (id string, exists bool) { - if m.id == nil { - return + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldInvoiceAt: %w", err) } - return *m.id, true + return oldValue.InvoiceAt, nil } -// 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 *ChargeFlatFeeRunCreditAllocationsMutation) 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().ChargeFlatFeeRunCreditAllocations.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } +// ResetInvoiceAt resets all changes to the "invoice_at" field. +func (m *ChargeFlatFeeOverrideMutation) ResetInvoiceAt() { + m.invoice_at = nil } -// SetLineID sets the "line_id" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetLineID(s string) { - m.billing_invoice_line = &s +// SetFeatureKey sets the "feature_key" field. +func (m *ChargeFlatFeeOverrideMutation) SetFeatureKey(s string) { + m.feature_key = &s } -// LineID returns the value of the "line_id" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) LineID() (r string, exists bool) { - v := m.billing_invoice_line +// FeatureKey returns the value of the "feature_key" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) FeatureKey() (r string, exists bool) { + v := m.feature_key if v == nil { return } return *v, true } -// OldLineID returns the old "line_id" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations object wasn't provided to the builder, the object is fetched from the database. +// OldFeatureKey returns the old "feature_key" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldLineID(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeOverrideMutation) OldFeatureKey(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldLineID is only allowed on UpdateOne operations") + return v, errors.New("OldFeatureKey is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldLineID requires an ID field in the mutation") + 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 OldLineID: %w", err) + return v, fmt.Errorf("querying old value for OldFeatureKey: %w", err) } - return oldValue.LineID, nil + return oldValue.FeatureKey, nil } -// ClearLineID clears the value of the "line_id" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearLineID() { - m.billing_invoice_line = nil - m.clearedFields[chargeflatfeeruncreditallocations.FieldLineID] = struct{}{} +// ClearFeatureKey clears the value of the "feature_key" field. +func (m *ChargeFlatFeeOverrideMutation) ClearFeatureKey() { + m.feature_key = nil + m.clearedFields[chargeflatfeeoverride.FieldFeatureKey] = struct{}{} } -// LineIDCleared returns if the "line_id" field was cleared in this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) LineIDCleared() bool { - _, ok := m.clearedFields[chargeflatfeeruncreditallocations.FieldLineID] +// FeatureKeyCleared returns if the "feature_key" field was cleared in this mutation. +func (m *ChargeFlatFeeOverrideMutation) FeatureKeyCleared() bool { + _, ok := m.clearedFields[chargeflatfeeoverride.FieldFeatureKey] return ok } -// ResetLineID resets all changes to the "line_id" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetLineID() { - m.billing_invoice_line = nil - delete(m.clearedFields, chargeflatfeeruncreditallocations.FieldLineID) +// ResetFeatureKey resets all changes to the "feature_key" field. +func (m *ChargeFlatFeeOverrideMutation) ResetFeatureKey() { + m.feature_key = nil + delete(m.clearedFields, chargeflatfeeoverride.FieldFeatureKey) } -// SetAmount sets the "amount" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetAmount(a alpacadecimal.Decimal) { - m.amount = &a +// SetPaymentTerm sets the "payment_term" field. +func (m *ChargeFlatFeeOverrideMutation) SetPaymentTerm(ptt productcatalog.PaymentTermType) { + m.payment_term = &ptt } -// Amount returns the value of the "amount" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) Amount() (r alpacadecimal.Decimal, exists bool) { - v := m.amount +// PaymentTerm returns the value of the "payment_term" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) PaymentTerm() (r productcatalog.PaymentTermType, exists bool) { + v := m.payment_term if v == nil { return } return *v, true } -// OldAmount returns the old "amount" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations object wasn't provided to the builder, the object is fetched from the database. +// OldPaymentTerm returns the old "payment_term" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeOverrideMutation) OldPaymentTerm(ctx context.Context) (v productcatalog.PaymentTermType, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAmount is only allowed on UpdateOne operations") + return v, errors.New("OldPaymentTerm is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAmount requires an ID field in the mutation") + return v, errors.New("OldPaymentTerm requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldAmount: %w", err) + return v, fmt.Errorf("querying old value for OldPaymentTerm: %w", err) } - return oldValue.Amount, nil + return oldValue.PaymentTerm, nil } -// ResetAmount resets all changes to the "amount" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetAmount() { - m.amount = nil +// ResetPaymentTerm resets all changes to the "payment_term" field. +func (m *ChargeFlatFeeOverrideMutation) ResetPaymentTerm() { + m.payment_term = nil } -// SetServicePeriodFrom sets the "service_period_from" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetServicePeriodFrom(t time.Time) { - m.service_period_from = &t +// SetProRating sets the "pro_rating" field. +func (m *ChargeFlatFeeOverrideMutation) SetProRating(prc *productcatalog.ProRatingConfig) { + m.pro_rating = &prc } -// ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ServicePeriodFrom() (r time.Time, exists bool) { - v := m.service_period_from +// ProRating returns the value of the "pro_rating" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) ProRating() (r *productcatalog.ProRatingConfig, exists bool) { + v := m.pro_rating if v == nil { return } return *v, true } -// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations object wasn't provided to the builder, the object is fetched from the database. +// OldProRating returns the old "pro_rating" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeOverrideMutation) OldProRating(ctx context.Context) (v *productcatalog.ProRatingConfig, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") + return v, errors.New("OldProRating is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldServicePeriodFrom requires an ID field in the mutation") + return v, errors.New("OldProRating requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldServicePeriodFrom: %w", err) + return v, fmt.Errorf("querying old value for OldProRating: %w", err) } - return oldValue.ServicePeriodFrom, nil + return oldValue.ProRating, nil } -// ResetServicePeriodFrom resets all changes to the "service_period_from" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetServicePeriodFrom() { - m.service_period_from = nil +// ResetProRating resets all changes to the "pro_rating" field. +func (m *ChargeFlatFeeOverrideMutation) ResetProRating() { + m.pro_rating = nil } -// SetServicePeriodTo sets the "service_period_to" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetServicePeriodTo(t time.Time) { - m.service_period_to = &t +// SetAmountBeforeProration sets the "amount_before_proration" field. +func (m *ChargeFlatFeeOverrideMutation) SetAmountBeforeProration(a alpacadecimal.Decimal) { + m.amount_before_proration = &a } -// ServicePeriodTo returns the value of the "service_period_to" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ServicePeriodTo() (r time.Time, exists bool) { - v := m.service_period_to +// AmountBeforeProration returns the value of the "amount_before_proration" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) AmountBeforeProration() (r alpacadecimal.Decimal, exists bool) { + v := m.amount_before_proration if v == nil { return } return *v, true } -// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations object wasn't provided to the builder, the object is fetched from the database. +// OldAmountBeforeProration returns the old "amount_before_proration" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeOverrideMutation) OldAmountBeforeProration(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") + return v, errors.New("OldAmountBeforeProration is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldServicePeriodTo requires an ID field in the mutation") + return v, errors.New("OldAmountBeforeProration requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldServicePeriodTo: %w", err) + return v, fmt.Errorf("querying old value for OldAmountBeforeProration: %w", err) } - return oldValue.ServicePeriodTo, nil + return oldValue.AmountBeforeProration, nil } -// ResetServicePeriodTo resets all changes to the "service_period_to" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetServicePeriodTo() { - m.service_period_to = nil +// ResetAmountBeforeProration resets all changes to the "amount_before_proration" field. +func (m *ChargeFlatFeeOverrideMutation) ResetAmountBeforeProration() { + m.amount_before_proration = nil } -// SetLedgerTransactionGroupID sets the "ledger_transaction_group_id" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetLedgerTransactionGroupID(s string) { - m.ledger_transaction_group_id = &s +// SetDiscounts sets the "discounts" field. +func (m *ChargeFlatFeeOverrideMutation) SetDiscounts(b *billing.Discounts) { + m.discounts = &b } -// LedgerTransactionGroupID returns the value of the "ledger_transaction_group_id" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) LedgerTransactionGroupID() (r string, exists bool) { - v := m.ledger_transaction_group_id +// Discounts returns the value of the "discounts" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) Discounts() (r *billing.Discounts, exists bool) { + v := m.discounts if v == nil { return } return *v, true } -// OldLedgerTransactionGroupID returns the old "ledger_transaction_group_id" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations object wasn't provided to the builder, the object is fetched from the database. +// OldDiscounts returns the old "discounts" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldLedgerTransactionGroupID(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeOverrideMutation) OldDiscounts(ctx context.Context) (v *billing.Discounts, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldLedgerTransactionGroupID is only allowed on UpdateOne operations") + return v, errors.New("OldDiscounts is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldLedgerTransactionGroupID requires an ID field in the mutation") + return v, errors.New("OldDiscounts requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldLedgerTransactionGroupID: %w", err) + return v, fmt.Errorf("querying old value for OldDiscounts: %w", err) } - return oldValue.LedgerTransactionGroupID, nil + return oldValue.Discounts, nil } -// ResetLedgerTransactionGroupID resets all changes to the "ledger_transaction_group_id" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetLedgerTransactionGroupID() { - m.ledger_transaction_group_id = nil +// ClearDiscounts clears the value of the "discounts" field. +func (m *ChargeFlatFeeOverrideMutation) ClearDiscounts() { + m.discounts = nil + m.clearedFields[chargeflatfeeoverride.FieldDiscounts] = struct{}{} } -// SetSortHint sets the "sort_hint" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetSortHint(i int) { - m.sort_hint = &i - m.addsort_hint = nil +// DiscountsCleared returns if the "discounts" field was cleared in this mutation. +func (m *ChargeFlatFeeOverrideMutation) DiscountsCleared() bool { + _, ok := m.clearedFields[chargeflatfeeoverride.FieldDiscounts] + return ok } -// SortHint returns the value of the "sort_hint" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SortHint() (r int, exists bool) { - v := m.sort_hint +// ResetDiscounts resets all changes to the "discounts" field. +func (m *ChargeFlatFeeOverrideMutation) ResetDiscounts() { + m.discounts = nil + delete(m.clearedFields, chargeflatfeeoverride.FieldDiscounts) +} + +// SetPercentageDiscounts sets the "percentage_discounts" field. +func (m *ChargeFlatFeeOverrideMutation) SetPercentageDiscounts(bd *billing.PercentageDiscount) { + m.percentage_discounts = &bd +} + +// PercentageDiscounts returns the value of the "percentage_discounts" field in the mutation. +func (m *ChargeFlatFeeOverrideMutation) PercentageDiscounts() (r *billing.PercentageDiscount, exists bool) { + v := m.percentage_discounts if v == nil { return } return *v, true } -// OldSortHint returns the old "sort_hint" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations object wasn't provided to the builder, the object is fetched from the database. +// OldPercentageDiscounts returns the old "percentage_discounts" field's value of the ChargeFlatFeeOverride entity. +// If the ChargeFlatFeeOverride 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldSortHint(ctx context.Context) (v int, err error) { +func (m *ChargeFlatFeeOverrideMutation) OldPercentageDiscounts(ctx context.Context) (v *billing.PercentageDiscount, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSortHint is only allowed on UpdateOne operations") + return v, errors.New("OldPercentageDiscounts is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSortHint requires an ID field in the mutation") + return v, errors.New("OldPercentageDiscounts requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldSortHint: %w", err) + return v, fmt.Errorf("querying old value for OldPercentageDiscounts: %w", err) } - return oldValue.SortHint, nil + return oldValue.PercentageDiscounts, nil } -// AddSortHint adds i to the "sort_hint" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddSortHint(i int) { - if m.addsort_hint != nil { - *m.addsort_hint += i - } else { - m.addsort_hint = &i - } +// ClearPercentageDiscounts clears the value of the "percentage_discounts" field. +func (m *ChargeFlatFeeOverrideMutation) ClearPercentageDiscounts() { + m.percentage_discounts = nil + m.clearedFields[chargeflatfeeoverride.FieldPercentageDiscounts] = struct{}{} } -// AddedSortHint returns the value that was added to the "sort_hint" field in this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddedSortHint() (r int, exists bool) { - v := m.addsort_hint - if v == nil { - return - } - return *v, true +// PercentageDiscountsCleared returns if the "percentage_discounts" field was cleared in this mutation. +func (m *ChargeFlatFeeOverrideMutation) PercentageDiscountsCleared() bool { + _, ok := m.clearedFields[chargeflatfeeoverride.FieldPercentageDiscounts] + return ok } -// ResetSortHint resets all changes to the "sort_hint" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetSortHint() { - m.sort_hint = nil - m.addsort_hint = nil +// ResetPercentageDiscounts resets all changes to the "percentage_discounts" field. +func (m *ChargeFlatFeeOverrideMutation) ResetPercentageDiscounts() { + m.percentage_discounts = nil + delete(m.clearedFields, chargeflatfeeoverride.FieldPercentageDiscounts) } -// SetType sets the "type" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetType(c creditrealization.Type) { - m._type = &c +// SetFlatFeeID sets the "flat_fee" edge to the ChargeFlatFee entity by id. +func (m *ChargeFlatFeeOverrideMutation) SetFlatFeeID(id string) { + m.flat_fee = &id } -// GetType returns the value of the "type" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) GetType() (r creditrealization.Type, exists bool) { - v := m._type - if v == nil { - return - } - return *v, true +// ClearFlatFee clears the "flat_fee" edge to the ChargeFlatFee entity. +func (m *ChargeFlatFeeOverrideMutation) ClearFlatFee() { + m.clearedflat_fee = true + m.clearedFields[chargeflatfeeoverride.FieldChargeID] = struct{}{} } -// OldType returns the old "type" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldType(ctx context.Context) (v creditrealization.Type, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldType is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldType requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldType: %w", err) - } - return oldValue.Type, nil -} - -// ResetType resets all changes to the "type" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetType() { - m._type = nil -} - -// SetCorrectsRealizationID sets the "corrects_realization_id" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetCorrectsRealizationID(s string) { - m.allocation = &s +// FlatFeeCleared reports if the "flat_fee" edge to the ChargeFlatFee entity was cleared. +func (m *ChargeFlatFeeOverrideMutation) FlatFeeCleared() bool { + return m.clearedflat_fee } -// CorrectsRealizationID returns the value of the "corrects_realization_id" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) CorrectsRealizationID() (r string, exists bool) { - v := m.allocation - if v == nil { - return +// FlatFeeID returns the "flat_fee" edge ID in the mutation. +func (m *ChargeFlatFeeOverrideMutation) FlatFeeID() (id string, exists bool) { + if m.flat_fee != nil { + return *m.flat_fee, true } - return *v, true + return } -// OldCorrectsRealizationID returns the old "corrects_realization_id" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldCorrectsRealizationID(ctx context.Context) (v *string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCorrectsRealizationID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCorrectsRealizationID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCorrectsRealizationID: %w", err) +// FlatFeeIDs returns the "flat_fee" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// FlatFeeID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeOverrideMutation) FlatFeeIDs() (ids []string) { + if id := m.flat_fee; id != nil { + ids = append(ids, *id) } - return oldValue.CorrectsRealizationID, nil -} - -// ClearCorrectsRealizationID clears the value of the "corrects_realization_id" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearCorrectsRealizationID() { - m.allocation = nil - m.clearedFields[chargeflatfeeruncreditallocations.FieldCorrectsRealizationID] = struct{}{} -} - -// CorrectsRealizationIDCleared returns if the "corrects_realization_id" field was cleared in this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) CorrectsRealizationIDCleared() bool { - _, ok := m.clearedFields[chargeflatfeeruncreditallocations.FieldCorrectsRealizationID] - return ok + return } -// ResetCorrectsRealizationID resets all changes to the "corrects_realization_id" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetCorrectsRealizationID() { - m.allocation = nil - delete(m.clearedFields, chargeflatfeeruncreditallocations.FieldCorrectsRealizationID) +// ResetFlatFee resets all changes to the "flat_fee" edge. +func (m *ChargeFlatFeeOverrideMutation) ResetFlatFee() { + m.flat_fee = nil + m.clearedflat_fee = false } -// SetNamespace sets the "namespace" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetNamespace(s string) { - m.namespace = &s +// ClearTaxCode clears the "tax_code" edge to the TaxCode entity. +func (m *ChargeFlatFeeOverrideMutation) ClearTaxCode() { + m.clearedtax_code = true + m.clearedFields[chargeflatfeeoverride.FieldTaxCodeID] = struct{}{} } -// Namespace returns the value of the "namespace" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) Namespace() (r string, exists bool) { - v := m.namespace - if v == nil { - return - } - return *v, true +// TaxCodeCleared reports if the "tax_code" edge to the TaxCode entity was cleared. +func (m *ChargeFlatFeeOverrideMutation) TaxCodeCleared() bool { + return m.TaxCodeIDCleared() || m.clearedtax_code } -// OldNamespace returns the old "namespace" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) 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) +// 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 *ChargeFlatFeeOverrideMutation) TaxCodeIDs() (ids []string) { + if id := m.tax_code; id != nil { + ids = append(ids, *id) } - return oldValue.Namespace, nil + return } -// ResetNamespace resets all changes to the "namespace" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetNamespace() { - m.namespace = nil +// ResetTaxCode resets all changes to the "tax_code" edge. +func (m *ChargeFlatFeeOverrideMutation) ResetTaxCode() { + m.tax_code = nil + m.clearedtax_code = false } -// SetCreatedAt sets the "created_at" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetCreatedAt(t time.Time) { - m.created_at = &t +// Where appends a list predicates to the ChargeFlatFeeOverrideMutation builder. +func (m *ChargeFlatFeeOverrideMutation) Where(ps ...predicate.ChargeFlatFeeOverride) { + m.predicates = append(m.predicates, ps...) } -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return +// WhereP appends storage-level predicates to the ChargeFlatFeeOverrideMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ChargeFlatFeeOverrideMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeFlatFeeOverride, len(ps)) + for i := range ps { + p[i] = ps[i] } - return *v, true + m.Where(p...) } -// OldCreatedAt returns the old "created_at" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) 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 +// Op returns the operation name. +func (m *ChargeFlatFeeOverrideMutation) Op() Op { + return m.op } -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetCreatedAt() { - m.created_at = nil +// SetOp allows setting the mutation operation. +func (m *ChargeFlatFeeOverrideMutation) SetOp(op Op) { + m.op = op } -// SetUpdatedAt sets the "updated_at" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t +// Type returns the node type of this mutation (ChargeFlatFeeOverride). +func (m *ChargeFlatFeeOverrideMutation) Type() string { + return m.typ } -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return +// 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 *ChargeFlatFeeOverrideMutation) Fields() []string { + fields := make([]string, 0, 21) + if m.namespace != nil { + fields = append(fields, chargeflatfeeoverride.FieldNamespace) } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) 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.flat_fee != nil { + fields = append(fields, chargeflatfeeoverride.FieldChargeID) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + if m.name != nil { + fields = append(fields, chargeflatfeeoverride.FieldName) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + if m.description != nil { + fields = append(fields, chargeflatfeeoverride.FieldDescription) } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// SetDeletedAt sets the "deleted_at" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetDeletedAt(t time.Time) { - m.deleted_at = &t -} - -// DeletedAt returns the value of the "deleted_at" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) DeletedAt() (r time.Time, exists bool) { - v := m.deleted_at - if v == nil { - return + if m.metadata != nil { + fields = append(fields, chargeflatfeeoverride.FieldMetadata) } - return *v, true -} - -// OldDeletedAt returns the old "deleted_at" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) 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.tax_behavior != nil { + fields = append(fields, chargeflatfeeoverride.FieldTaxBehavior) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDeletedAt requires an ID field in the mutation") + if m.tax_code != nil { + fields = append(fields, chargeflatfeeoverride.FieldTaxCodeID) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) + if m.intent_deleted_at != nil { + fields = append(fields, chargeflatfeeoverride.FieldIntentDeletedAt) } - return oldValue.DeletedAt, nil -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearDeletedAt() { - m.deleted_at = nil - m.clearedFields[chargeflatfeeruncreditallocations.FieldDeletedAt] = struct{}{} -} - -// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) DeletedAtCleared() bool { - _, ok := m.clearedFields[chargeflatfeeruncreditallocations.FieldDeletedAt] - return ok -} - -// ResetDeletedAt resets all changes to the "deleted_at" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetDeletedAt() { - m.deleted_at = nil - delete(m.clearedFields, chargeflatfeeruncreditallocations.FieldDeletedAt) -} - -// SetAnnotations sets the "annotations" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetAnnotations(value models.Annotations) { - m.annotations = &value -} - -// Annotations returns the value of the "annotations" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) Annotations() (r models.Annotations, exists bool) { - v := m.annotations - if v == nil { - return + if m.service_period_from != nil { + fields = append(fields, chargeflatfeeoverride.FieldServicePeriodFrom) } - return *v, true -} - -// OldAnnotations returns the old "annotations" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) 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.service_period_to != nil { + fields = append(fields, chargeflatfeeoverride.FieldServicePeriodTo) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAnnotations requires an ID field in the mutation") + if m.full_service_period_from != nil { + fields = append(fields, chargeflatfeeoverride.FieldFullServicePeriodFrom) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldAnnotations: %w", err) + if m.full_service_period_to != nil { + fields = append(fields, chargeflatfeeoverride.FieldFullServicePeriodTo) } - return oldValue.Annotations, nil -} - -// ClearAnnotations clears the value of the "annotations" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearAnnotations() { - m.annotations = nil - m.clearedFields[chargeflatfeeruncreditallocations.FieldAnnotations] = struct{}{} -} - -// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) AnnotationsCleared() bool { - _, ok := m.clearedFields[chargeflatfeeruncreditallocations.FieldAnnotations] - return ok -} - -// ResetAnnotations resets all changes to the "annotations" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetAnnotations() { - m.annotations = nil - delete(m.clearedFields, chargeflatfeeruncreditallocations.FieldAnnotations) -} - -// SetRunID sets the "run_id" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetRunID(s string) { - m.run = &s -} - -// RunID returns the value of the "run_id" field in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) RunID() (r string, exists bool) { - v := m.run - if v == nil { - return + if m.billing_period_from != nil { + fields = append(fields, chargeflatfeeoverride.FieldBillingPeriodFrom) } - return *v, true -} - -// OldRunID returns the old "run_id" field's value of the ChargeFlatFeeRunCreditAllocations entity. -// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldRunID(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldRunID is only allowed on UpdateOne operations") + if m.billing_period_to != nil { + fields = append(fields, chargeflatfeeoverride.FieldBillingPeriodTo) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldRunID requires an ID field in the mutation") + if m.invoice_at != nil { + fields = append(fields, chargeflatfeeoverride.FieldInvoiceAt) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldRunID: %w", err) + if m.feature_key != nil { + fields = append(fields, chargeflatfeeoverride.FieldFeatureKey) } - return oldValue.RunID, nil -} - -// ResetRunID resets all changes to the "run_id" field. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetRunID() { - m.run = nil -} - -// AddCorrectionIDs adds the "corrections" edge to the ChargeFlatFeeRunCreditAllocations entity by ids. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddCorrectionIDs(ids ...string) { - if m.corrections == nil { - m.corrections = make(map[string]struct{}) + if m.payment_term != nil { + fields = append(fields, chargeflatfeeoverride.FieldPaymentTerm) } - for i := range ids { - m.corrections[ids[i]] = struct{}{} + if m.pro_rating != nil { + fields = append(fields, chargeflatfeeoverride.FieldProRating) } -} - -// ClearCorrections clears the "corrections" edge to the ChargeFlatFeeRunCreditAllocations entity. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearCorrections() { - m.clearedcorrections = true -} - -// CorrectionsCleared reports if the "corrections" edge to the ChargeFlatFeeRunCreditAllocations entity was cleared. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) CorrectionsCleared() bool { - return m.clearedcorrections -} - -// RemoveCorrectionIDs removes the "corrections" edge to the ChargeFlatFeeRunCreditAllocations entity by IDs. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) RemoveCorrectionIDs(ids ...string) { - if m.removedcorrections == nil { - m.removedcorrections = make(map[string]struct{}) + if m.amount_before_proration != nil { + fields = append(fields, chargeflatfeeoverride.FieldAmountBeforeProration) } - for i := range ids { - delete(m.corrections, ids[i]) - m.removedcorrections[ids[i]] = struct{}{} + if m.discounts != nil { + fields = append(fields, chargeflatfeeoverride.FieldDiscounts) } -} - -// RemovedCorrections returns the removed IDs of the "corrections" edge to the ChargeFlatFeeRunCreditAllocations entity. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) RemovedCorrectionsIDs() (ids []string) { - for id := range m.removedcorrections { - ids = append(ids, id) + if m.percentage_discounts != nil { + fields = append(fields, chargeflatfeeoverride.FieldPercentageDiscounts) } - return + return fields } -// CorrectionsIDs returns the "corrections" edge IDs in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) CorrectionsIDs() (ids []string) { - for id := range m.corrections { - ids = append(ids, id) +// 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 *ChargeFlatFeeOverrideMutation) Field(name string) (ent.Value, bool) { + switch name { + case chargeflatfeeoverride.FieldNamespace: + return m.Namespace() + case chargeflatfeeoverride.FieldChargeID: + return m.ChargeID() + case chargeflatfeeoverride.FieldName: + return m.Name() + case chargeflatfeeoverride.FieldDescription: + return m.Description() + case chargeflatfeeoverride.FieldMetadata: + return m.Metadata() + case chargeflatfeeoverride.FieldTaxBehavior: + return m.TaxBehavior() + case chargeflatfeeoverride.FieldTaxCodeID: + return m.TaxCodeID() + case chargeflatfeeoverride.FieldIntentDeletedAt: + return m.IntentDeletedAt() + case chargeflatfeeoverride.FieldServicePeriodFrom: + return m.ServicePeriodFrom() + case chargeflatfeeoverride.FieldServicePeriodTo: + return m.ServicePeriodTo() + case chargeflatfeeoverride.FieldFullServicePeriodFrom: + return m.FullServicePeriodFrom() + case chargeflatfeeoverride.FieldFullServicePeriodTo: + return m.FullServicePeriodTo() + case chargeflatfeeoverride.FieldBillingPeriodFrom: + return m.BillingPeriodFrom() + case chargeflatfeeoverride.FieldBillingPeriodTo: + return m.BillingPeriodTo() + case chargeflatfeeoverride.FieldInvoiceAt: + return m.InvoiceAt() + case chargeflatfeeoverride.FieldFeatureKey: + return m.FeatureKey() + case chargeflatfeeoverride.FieldPaymentTerm: + return m.PaymentTerm() + case chargeflatfeeoverride.FieldProRating: + return m.ProRating() + case chargeflatfeeoverride.FieldAmountBeforeProration: + return m.AmountBeforeProration() + case chargeflatfeeoverride.FieldDiscounts: + return m.Discounts() + case chargeflatfeeoverride.FieldPercentageDiscounts: + return m.PercentageDiscounts() } - return -} - -// ResetCorrections resets all changes to the "corrections" edge. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetCorrections() { - m.corrections = nil - m.clearedcorrections = false - m.removedcorrections = nil + return nil, false } -// SetAllocationID sets the "allocation" edge to the ChargeFlatFeeRunCreditAllocations entity by id. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetAllocationID(id string) { - m.allocation = &id -} - -// ClearAllocation clears the "allocation" edge to the ChargeFlatFeeRunCreditAllocations entity. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearAllocation() { - m.clearedallocation = true - m.clearedFields[chargeflatfeeruncreditallocations.FieldCorrectsRealizationID] = struct{}{} -} - -// AllocationCleared reports if the "allocation" edge to the ChargeFlatFeeRunCreditAllocations entity was cleared. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) AllocationCleared() bool { - return m.CorrectsRealizationIDCleared() || m.clearedallocation -} - -// AllocationID returns the "allocation" edge ID in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) AllocationID() (id string, exists bool) { - if m.allocation != nil { - return *m.allocation, true - } - return -} - -// AllocationIDs returns the "allocation" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// AllocationID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) AllocationIDs() (ids []string) { - if id := m.allocation; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetAllocation resets all changes to the "allocation" edge. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetAllocation() { - m.allocation = nil - m.clearedallocation = false -} - -// ClearRun clears the "run" edge to the ChargeFlatFeeRun entity. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearRun() { - m.clearedrun = true - m.clearedFields[chargeflatfeeruncreditallocations.FieldRunID] = struct{}{} -} - -// RunCleared reports if the "run" edge to the ChargeFlatFeeRun entity was cleared. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) RunCleared() bool { - return m.clearedrun -} - -// RunIDs returns the "run" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// RunID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) RunIDs() (ids []string) { - if id := m.run; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetRun resets all changes to the "run" edge. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetRun() { - m.run = nil - m.clearedrun = false -} - -// SetBillingInvoiceLineID sets the "billing_invoice_line" edge to the BillingInvoiceLine entity by id. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetBillingInvoiceLineID(id string) { - m.billing_invoice_line = &id -} - -// ClearBillingInvoiceLine clears the "billing_invoice_line" edge to the BillingInvoiceLine entity. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearBillingInvoiceLine() { - m.clearedbilling_invoice_line = true - m.clearedFields[chargeflatfeeruncreditallocations.FieldLineID] = struct{}{} -} - -// BillingInvoiceLineCleared reports if the "billing_invoice_line" edge to the BillingInvoiceLine entity was cleared. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) BillingInvoiceLineCleared() bool { - return m.LineIDCleared() || m.clearedbilling_invoice_line -} - -// BillingInvoiceLineID returns the "billing_invoice_line" edge ID in the mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) BillingInvoiceLineID() (id string, exists bool) { - if m.billing_invoice_line != nil { - return *m.billing_invoice_line, true - } - return -} - -// BillingInvoiceLineIDs returns the "billing_invoice_line" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// BillingInvoiceLineID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) BillingInvoiceLineIDs() (ids []string) { - if id := m.billing_invoice_line; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetBillingInvoiceLine resets all changes to the "billing_invoice_line" edge. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetBillingInvoiceLine() { - m.billing_invoice_line = nil - m.clearedbilling_invoice_line = false -} - -// Where appends a list predicates to the ChargeFlatFeeRunCreditAllocationsMutation builder. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) Where(ps ...predicate.ChargeFlatFeeRunCreditAllocations) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the ChargeFlatFeeRunCreditAllocationsMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.ChargeFlatFeeRunCreditAllocations, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) -} - -// Op returns the operation name. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (ChargeFlatFeeRunCreditAllocations). -func (m *ChargeFlatFeeRunCreditAllocationsMutation) 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 *ChargeFlatFeeRunCreditAllocationsMutation) Fields() []string { - fields := make([]string, 0, 14) - if m.billing_invoice_line != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldLineID) - } - if m.amount != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldAmount) - } - if m.service_period_from != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldServicePeriodFrom) - } - if m.service_period_to != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldServicePeriodTo) - } - if m.ledger_transaction_group_id != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldLedgerTransactionGroupID) - } - if m.sort_hint != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldSortHint) - } - if m._type != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldType) - } - if m.allocation != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldCorrectsRealizationID) - } - if m.namespace != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldNamespace) - } - if m.created_at != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldUpdatedAt) - } - if m.deleted_at != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldDeletedAt) - } - if m.annotations != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldAnnotations) - } - if m.run != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldRunID) - } - 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 *ChargeFlatFeeRunCreditAllocationsMutation) Field(name string) (ent.Value, bool) { - switch name { - case chargeflatfeeruncreditallocations.FieldLineID: - return m.LineID() - case chargeflatfeeruncreditallocations.FieldAmount: - return m.Amount() - case chargeflatfeeruncreditallocations.FieldServicePeriodFrom: - return m.ServicePeriodFrom() - case chargeflatfeeruncreditallocations.FieldServicePeriodTo: - return m.ServicePeriodTo() - case chargeflatfeeruncreditallocations.FieldLedgerTransactionGroupID: - return m.LedgerTransactionGroupID() - case chargeflatfeeruncreditallocations.FieldSortHint: - return m.SortHint() - case chargeflatfeeruncreditallocations.FieldType: - return m.GetType() - case chargeflatfeeruncreditallocations.FieldCorrectsRealizationID: - return m.CorrectsRealizationID() - case chargeflatfeeruncreditallocations.FieldNamespace: - return m.Namespace() - case chargeflatfeeruncreditallocations.FieldCreatedAt: - return m.CreatedAt() - case chargeflatfeeruncreditallocations.FieldUpdatedAt: - return m.UpdatedAt() - case chargeflatfeeruncreditallocations.FieldDeletedAt: - return m.DeletedAt() - case chargeflatfeeruncreditallocations.FieldAnnotations: - return m.Annotations() - case chargeflatfeeruncreditallocations.FieldRunID: - return m.RunID() - } - 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case chargeflatfeeruncreditallocations.FieldLineID: - return m.OldLineID(ctx) - case chargeflatfeeruncreditallocations.FieldAmount: - return m.OldAmount(ctx) - case chargeflatfeeruncreditallocations.FieldServicePeriodFrom: - return m.OldServicePeriodFrom(ctx) - case chargeflatfeeruncreditallocations.FieldServicePeriodTo: - return m.OldServicePeriodTo(ctx) - case chargeflatfeeruncreditallocations.FieldLedgerTransactionGroupID: - return m.OldLedgerTransactionGroupID(ctx) - case chargeflatfeeruncreditallocations.FieldSortHint: - return m.OldSortHint(ctx) - case chargeflatfeeruncreditallocations.FieldType: - return m.OldType(ctx) - case chargeflatfeeruncreditallocations.FieldCorrectsRealizationID: - return m.OldCorrectsRealizationID(ctx) - case chargeflatfeeruncreditallocations.FieldNamespace: - return m.OldNamespace(ctx) - case chargeflatfeeruncreditallocations.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case chargeflatfeeruncreditallocations.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - case chargeflatfeeruncreditallocations.FieldDeletedAt: - return m.OldDeletedAt(ctx) - case chargeflatfeeruncreditallocations.FieldAnnotations: - return m.OldAnnotations(ctx) - case chargeflatfeeruncreditallocations.FieldRunID: - return m.OldRunID(ctx) - } - return nil, fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations field %s", name) +// 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 *ChargeFlatFeeOverrideMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case chargeflatfeeoverride.FieldNamespace: + return m.OldNamespace(ctx) + case chargeflatfeeoverride.FieldChargeID: + return m.OldChargeID(ctx) + case chargeflatfeeoverride.FieldName: + return m.OldName(ctx) + case chargeflatfeeoverride.FieldDescription: + return m.OldDescription(ctx) + case chargeflatfeeoverride.FieldMetadata: + return m.OldMetadata(ctx) + case chargeflatfeeoverride.FieldTaxBehavior: + return m.OldTaxBehavior(ctx) + case chargeflatfeeoverride.FieldTaxCodeID: + return m.OldTaxCodeID(ctx) + case chargeflatfeeoverride.FieldIntentDeletedAt: + return m.OldIntentDeletedAt(ctx) + case chargeflatfeeoverride.FieldServicePeriodFrom: + return m.OldServicePeriodFrom(ctx) + case chargeflatfeeoverride.FieldServicePeriodTo: + return m.OldServicePeriodTo(ctx) + case chargeflatfeeoverride.FieldFullServicePeriodFrom: + return m.OldFullServicePeriodFrom(ctx) + case chargeflatfeeoverride.FieldFullServicePeriodTo: + return m.OldFullServicePeriodTo(ctx) + case chargeflatfeeoverride.FieldBillingPeriodFrom: + return m.OldBillingPeriodFrom(ctx) + case chargeflatfeeoverride.FieldBillingPeriodTo: + return m.OldBillingPeriodTo(ctx) + case chargeflatfeeoverride.FieldInvoiceAt: + return m.OldInvoiceAt(ctx) + case chargeflatfeeoverride.FieldFeatureKey: + return m.OldFeatureKey(ctx) + case chargeflatfeeoverride.FieldPaymentTerm: + return m.OldPaymentTerm(ctx) + case chargeflatfeeoverride.FieldProRating: + return m.OldProRating(ctx) + case chargeflatfeeoverride.FieldAmountBeforeProration: + return m.OldAmountBeforeProration(ctx) + case chargeflatfeeoverride.FieldDiscounts: + return m.OldDiscounts(ctx) + case chargeflatfeeoverride.FieldPercentageDiscounts: + return m.OldPercentageDiscounts(ctx) + } + return nil, fmt.Errorf("unknown ChargeFlatFeeOverride 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 *ChargeFlatFeeRunCreditAllocationsMutation) SetField(name string, value ent.Value) error { +func (m *ChargeFlatFeeOverrideMutation) SetField(name string, value ent.Value) error { switch name { - case chargeflatfeeruncreditallocations.FieldLineID: + case chargeflatfeeoverride.FieldNamespace: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetLineID(v) + m.SetNamespace(v) return nil - case chargeflatfeeruncreditallocations.FieldAmount: - v, ok := value.(alpacadecimal.Decimal) + case chargeflatfeeoverride.FieldChargeID: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetAmount(v) + m.SetChargeID(v) return nil - case chargeflatfeeruncreditallocations.FieldServicePeriodFrom: - v, ok := value.(time.Time) + case chargeflatfeeoverride.FieldName: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetServicePeriodFrom(v) + m.SetName(v) return nil - case chargeflatfeeruncreditallocations.FieldServicePeriodTo: - v, ok := value.(time.Time) + case chargeflatfeeoverride.FieldDescription: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetServicePeriodTo(v) + m.SetDescription(v) return nil - case chargeflatfeeruncreditallocations.FieldLedgerTransactionGroupID: + case chargeflatfeeoverride.FieldMetadata: + v, ok := value.(*models.Metadata) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMetadata(v) + return nil + case chargeflatfeeoverride.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 chargeflatfeeoverride.FieldTaxCodeID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetLedgerTransactionGroupID(v) + m.SetTaxCodeID(v) return nil - case chargeflatfeeruncreditallocations.FieldSortHint: - v, ok := value.(int) + case chargeflatfeeoverride.FieldIntentDeletedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetSortHint(v) + m.SetIntentDeletedAt(v) return nil - case chargeflatfeeruncreditallocations.FieldType: - v, ok := value.(creditrealization.Type) + case chargeflatfeeoverride.FieldServicePeriodFrom: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetType(v) + m.SetServicePeriodFrom(v) return nil - case chargeflatfeeruncreditallocations.FieldCorrectsRealizationID: - v, ok := value.(string) + case chargeflatfeeoverride.FieldServicePeriodTo: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCorrectsRealizationID(v) + m.SetServicePeriodTo(v) return nil - case chargeflatfeeruncreditallocations.FieldNamespace: - v, ok := value.(string) + case chargeflatfeeoverride.FieldFullServicePeriodFrom: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetNamespace(v) + m.SetFullServicePeriodFrom(v) return nil - case chargeflatfeeruncreditallocations.FieldCreatedAt: + case chargeflatfeeoverride.FieldFullServicePeriodTo: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCreatedAt(v) + m.SetFullServicePeriodTo(v) return nil - case chargeflatfeeruncreditallocations.FieldUpdatedAt: + case chargeflatfeeoverride.FieldBillingPeriodFrom: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetUpdatedAt(v) + m.SetBillingPeriodFrom(v) return nil - case chargeflatfeeruncreditallocations.FieldDeletedAt: + case chargeflatfeeoverride.FieldBillingPeriodTo: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDeletedAt(v) + m.SetBillingPeriodTo(v) return nil - case chargeflatfeeruncreditallocations.FieldAnnotations: - v, ok := value.(models.Annotations) + case chargeflatfeeoverride.FieldInvoiceAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetAnnotations(v) + m.SetInvoiceAt(v) return nil - case chargeflatfeeruncreditallocations.FieldRunID: + case chargeflatfeeoverride.FieldFeatureKey: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetRunID(v) + m.SetFeatureKey(v) + return nil + case chargeflatfeeoverride.FieldPaymentTerm: + v, ok := value.(productcatalog.PaymentTermType) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPaymentTerm(v) + return nil + case chargeflatfeeoverride.FieldProRating: + v, ok := value.(*productcatalog.ProRatingConfig) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetProRating(v) + return nil + case chargeflatfeeoverride.FieldAmountBeforeProration: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAmountBeforeProration(v) + return nil + case chargeflatfeeoverride.FieldDiscounts: + v, ok := value.(*billing.Discounts) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDiscounts(v) + return nil + case chargeflatfeeoverride.FieldPercentageDiscounts: + v, ok := value.(*billing.PercentageDiscount) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPercentageDiscounts(v) return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeOverride field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddedFields() []string { - var fields []string - if m.addsort_hint != nil { - fields = append(fields, chargeflatfeeruncreditallocations.FieldSortHint) - } - return fields +func (m *ChargeFlatFeeOverrideMutation) 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 *ChargeFlatFeeRunCreditAllocationsMutation) AddedField(name string) (ent.Value, bool) { - switch name { - case chargeflatfeeruncreditallocations.FieldSortHint: - return m.AddedSortHint() - } +func (m *ChargeFlatFeeOverrideMutation) 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 *ChargeFlatFeeRunCreditAllocationsMutation) AddField(name string, value ent.Value) error { +func (m *ChargeFlatFeeOverrideMutation) AddField(name string, value ent.Value) error { switch name { - case chargeflatfeeruncreditallocations.FieldSortHint: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.AddSortHint(v) - return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations numeric field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeOverride numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearedFields() []string { +func (m *ChargeFlatFeeOverrideMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(chargeflatfeeruncreditallocations.FieldLineID) { - fields = append(fields, chargeflatfeeruncreditallocations.FieldLineID) + if m.FieldCleared(chargeflatfeeoverride.FieldDescription) { + fields = append(fields, chargeflatfeeoverride.FieldDescription) } - if m.FieldCleared(chargeflatfeeruncreditallocations.FieldCorrectsRealizationID) { - fields = append(fields, chargeflatfeeruncreditallocations.FieldCorrectsRealizationID) + if m.FieldCleared(chargeflatfeeoverride.FieldMetadata) { + fields = append(fields, chargeflatfeeoverride.FieldMetadata) } - if m.FieldCleared(chargeflatfeeruncreditallocations.FieldDeletedAt) { - fields = append(fields, chargeflatfeeruncreditallocations.FieldDeletedAt) + if m.FieldCleared(chargeflatfeeoverride.FieldTaxBehavior) { + fields = append(fields, chargeflatfeeoverride.FieldTaxBehavior) } - if m.FieldCleared(chargeflatfeeruncreditallocations.FieldAnnotations) { - fields = append(fields, chargeflatfeeruncreditallocations.FieldAnnotations) + if m.FieldCleared(chargeflatfeeoverride.FieldTaxCodeID) { + fields = append(fields, chargeflatfeeoverride.FieldTaxCodeID) + } + if m.FieldCleared(chargeflatfeeoverride.FieldIntentDeletedAt) { + fields = append(fields, chargeflatfeeoverride.FieldIntentDeletedAt) + } + if m.FieldCleared(chargeflatfeeoverride.FieldFeatureKey) { + fields = append(fields, chargeflatfeeoverride.FieldFeatureKey) + } + if m.FieldCleared(chargeflatfeeoverride.FieldDiscounts) { + fields = append(fields, chargeflatfeeoverride.FieldDiscounts) + } + if m.FieldCleared(chargeflatfeeoverride.FieldPercentageDiscounts) { + fields = append(fields, chargeflatfeeoverride.FieldPercentageDiscounts) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) FieldCleared(name string) bool { +func (m *ChargeFlatFeeOverrideMutation) 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 *ChargeFlatFeeRunCreditAllocationsMutation) ClearField(name string) error { +func (m *ChargeFlatFeeOverrideMutation) ClearField(name string) error { switch name { - case chargeflatfeeruncreditallocations.FieldLineID: - m.ClearLineID() + case chargeflatfeeoverride.FieldDescription: + m.ClearDescription() return nil - case chargeflatfeeruncreditallocations.FieldCorrectsRealizationID: - m.ClearCorrectsRealizationID() + case chargeflatfeeoverride.FieldMetadata: + m.ClearMetadata() return nil - case chargeflatfeeruncreditallocations.FieldDeletedAt: - m.ClearDeletedAt() + case chargeflatfeeoverride.FieldTaxBehavior: + m.ClearTaxBehavior() return nil - case chargeflatfeeruncreditallocations.FieldAnnotations: - m.ClearAnnotations() + case chargeflatfeeoverride.FieldTaxCodeID: + m.ClearTaxCodeID() + return nil + case chargeflatfeeoverride.FieldIntentDeletedAt: + m.ClearIntentDeletedAt() + return nil + case chargeflatfeeoverride.FieldFeatureKey: + m.ClearFeatureKey() + return nil + case chargeflatfeeoverride.FieldDiscounts: + m.ClearDiscounts() + return nil + case chargeflatfeeoverride.FieldPercentageDiscounts: + m.ClearPercentageDiscounts() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations nullable field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeOverride 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 *ChargeFlatFeeRunCreditAllocationsMutation) ResetField(name string) error { +func (m *ChargeFlatFeeOverrideMutation) ResetField(name string) error { switch name { - case chargeflatfeeruncreditallocations.FieldLineID: - m.ResetLineID() + case chargeflatfeeoverride.FieldNamespace: + m.ResetNamespace() return nil - case chargeflatfeeruncreditallocations.FieldAmount: - m.ResetAmount() + case chargeflatfeeoverride.FieldChargeID: + m.ResetChargeID() return nil - case chargeflatfeeruncreditallocations.FieldServicePeriodFrom: - m.ResetServicePeriodFrom() + case chargeflatfeeoverride.FieldName: + m.ResetName() return nil - case chargeflatfeeruncreditallocations.FieldServicePeriodTo: - m.ResetServicePeriodTo() + case chargeflatfeeoverride.FieldDescription: + m.ResetDescription() return nil - case chargeflatfeeruncreditallocations.FieldLedgerTransactionGroupID: - m.ResetLedgerTransactionGroupID() + case chargeflatfeeoverride.FieldMetadata: + m.ResetMetadata() return nil - case chargeflatfeeruncreditallocations.FieldSortHint: - m.ResetSortHint() + case chargeflatfeeoverride.FieldTaxBehavior: + m.ResetTaxBehavior() return nil - case chargeflatfeeruncreditallocations.FieldType: - m.ResetType() + case chargeflatfeeoverride.FieldTaxCodeID: + m.ResetTaxCodeID() return nil - case chargeflatfeeruncreditallocations.FieldCorrectsRealizationID: - m.ResetCorrectsRealizationID() + case chargeflatfeeoverride.FieldIntentDeletedAt: + m.ResetIntentDeletedAt() return nil - case chargeflatfeeruncreditallocations.FieldNamespace: - m.ResetNamespace() + case chargeflatfeeoverride.FieldServicePeriodFrom: + m.ResetServicePeriodFrom() return nil - case chargeflatfeeruncreditallocations.FieldCreatedAt: - m.ResetCreatedAt() + case chargeflatfeeoverride.FieldServicePeriodTo: + m.ResetServicePeriodTo() return nil - case chargeflatfeeruncreditallocations.FieldUpdatedAt: - m.ResetUpdatedAt() + case chargeflatfeeoverride.FieldFullServicePeriodFrom: + m.ResetFullServicePeriodFrom() return nil - case chargeflatfeeruncreditallocations.FieldDeletedAt: - m.ResetDeletedAt() + case chargeflatfeeoverride.FieldFullServicePeriodTo: + m.ResetFullServicePeriodTo() return nil - case chargeflatfeeruncreditallocations.FieldAnnotations: - m.ResetAnnotations() + case chargeflatfeeoverride.FieldBillingPeriodFrom: + m.ResetBillingPeriodFrom() return nil - case chargeflatfeeruncreditallocations.FieldRunID: - m.ResetRunID() + case chargeflatfeeoverride.FieldBillingPeriodTo: + m.ResetBillingPeriodTo() + return nil + case chargeflatfeeoverride.FieldInvoiceAt: + m.ResetInvoiceAt() + return nil + case chargeflatfeeoverride.FieldFeatureKey: + m.ResetFeatureKey() + return nil + case chargeflatfeeoverride.FieldPaymentTerm: + m.ResetPaymentTerm() + return nil + case chargeflatfeeoverride.FieldProRating: + m.ResetProRating() + return nil + case chargeflatfeeoverride.FieldAmountBeforeProration: + m.ResetAmountBeforeProration() + return nil + case chargeflatfeeoverride.FieldDiscounts: + m.ResetDiscounts() + return nil + case chargeflatfeeoverride.FieldPercentageDiscounts: + m.ResetPercentageDiscounts() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeOverride field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddedEdges() []string { - edges := make([]string, 0, 4) - if m.corrections != nil { - edges = append(edges, chargeflatfeeruncreditallocations.EdgeCorrections) - } - if m.allocation != nil { - edges = append(edges, chargeflatfeeruncreditallocations.EdgeAllocation) - } - if m.run != nil { - edges = append(edges, chargeflatfeeruncreditallocations.EdgeRun) +func (m *ChargeFlatFeeOverrideMutation) AddedEdges() []string { + edges := make([]string, 0, 2) + if m.flat_fee != nil { + edges = append(edges, chargeflatfeeoverride.EdgeFlatFee) } - if m.billing_invoice_line != nil { - edges = append(edges, chargeflatfeeruncreditallocations.EdgeBillingInvoiceLine) + if m.tax_code != nil { + edges = append(edges, chargeflatfeeoverride.EdgeTaxCode) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddedIDs(name string) []ent.Value { +func (m *ChargeFlatFeeOverrideMutation) AddedIDs(name string) []ent.Value { switch name { - case chargeflatfeeruncreditallocations.EdgeCorrections: - ids := make([]ent.Value, 0, len(m.corrections)) - for id := range m.corrections { - ids = append(ids, id) - } - return ids - case chargeflatfeeruncreditallocations.EdgeAllocation: - if id := m.allocation; id != nil { - return []ent.Value{*id} - } - case chargeflatfeeruncreditallocations.EdgeRun: - if id := m.run; id != nil { + case chargeflatfeeoverride.EdgeFlatFee: + if id := m.flat_fee; id != nil { return []ent.Value{*id} } - case chargeflatfeeruncreditallocations.EdgeBillingInvoiceLine: - if id := m.billing_invoice_line; id != nil { + case chargeflatfeeoverride.EdgeTaxCode: + if id := m.tax_code; id != nil { return []ent.Value{*id} } } @@ -53914,153 +53216,127 @@ func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddedIDs(name string) []ent. } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) RemovedEdges() []string { - edges := make([]string, 0, 4) - if m.removedcorrections != nil { - edges = append(edges, chargeflatfeeruncreditallocations.EdgeCorrections) - } +func (m *ChargeFlatFeeOverrideMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) RemovedIDs(name string) []ent.Value { - switch name { - case chargeflatfeeruncreditallocations.EdgeCorrections: - ids := make([]ent.Value, 0, len(m.removedcorrections)) - for id := range m.removedcorrections { - ids = append(ids, id) - } - return ids - } +func (m *ChargeFlatFeeOverrideMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearedEdges() []string { - edges := make([]string, 0, 4) - if m.clearedcorrections { - edges = append(edges, chargeflatfeeruncreditallocations.EdgeCorrections) - } - if m.clearedallocation { - edges = append(edges, chargeflatfeeruncreditallocations.EdgeAllocation) - } - if m.clearedrun { - edges = append(edges, chargeflatfeeruncreditallocations.EdgeRun) +func (m *ChargeFlatFeeOverrideMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.clearedflat_fee { + edges = append(edges, chargeflatfeeoverride.EdgeFlatFee) } - if m.clearedbilling_invoice_line { - edges = append(edges, chargeflatfeeruncreditallocations.EdgeBillingInvoiceLine) + if m.clearedtax_code { + edges = append(edges, chargeflatfeeoverride.EdgeTaxCode) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *ChargeFlatFeeRunCreditAllocationsMutation) EdgeCleared(name string) bool { +func (m *ChargeFlatFeeOverrideMutation) EdgeCleared(name string) bool { switch name { - case chargeflatfeeruncreditallocations.EdgeCorrections: - return m.clearedcorrections - case chargeflatfeeruncreditallocations.EdgeAllocation: - return m.clearedallocation - case chargeflatfeeruncreditallocations.EdgeRun: - return m.clearedrun - case chargeflatfeeruncreditallocations.EdgeBillingInvoiceLine: - return m.clearedbilling_invoice_line + case chargeflatfeeoverride.EdgeFlatFee: + return m.clearedflat_fee + case chargeflatfeeoverride.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 *ChargeFlatFeeRunCreditAllocationsMutation) ClearEdge(name string) error { +func (m *ChargeFlatFeeOverrideMutation) ClearEdge(name string) error { switch name { - case chargeflatfeeruncreditallocations.EdgeAllocation: - m.ClearAllocation() - return nil - case chargeflatfeeruncreditallocations.EdgeRun: - m.ClearRun() + case chargeflatfeeoverride.EdgeFlatFee: + m.ClearFlatFee() return nil - case chargeflatfeeruncreditallocations.EdgeBillingInvoiceLine: - m.ClearBillingInvoiceLine() + case chargeflatfeeoverride.EdgeTaxCode: + m.ClearTaxCode() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations unique edge %s", name) + return fmt.Errorf("unknown ChargeFlatFeeOverride 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 *ChargeFlatFeeRunCreditAllocationsMutation) ResetEdge(name string) error { +func (m *ChargeFlatFeeOverrideMutation) ResetEdge(name string) error { switch name { - case chargeflatfeeruncreditallocations.EdgeCorrections: - m.ResetCorrections() - return nil - case chargeflatfeeruncreditallocations.EdgeAllocation: - m.ResetAllocation() - return nil - case chargeflatfeeruncreditallocations.EdgeRun: - m.ResetRun() + case chargeflatfeeoverride.EdgeFlatFee: + m.ResetFlatFee() return nil - case chargeflatfeeruncreditallocations.EdgeBillingInvoiceLine: - m.ResetBillingInvoiceLine() + case chargeflatfeeoverride.EdgeTaxCode: + m.ResetTaxCode() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations edge %s", name) + return fmt.Errorf("unknown ChargeFlatFeeOverride edge %s", name) } -// ChargeFlatFeeRunDetailedLineMutation represents an operation that mutates the ChargeFlatFeeRunDetailedLine nodes in the graph. -type ChargeFlatFeeRunDetailedLineMutation struct { +// ChargeFlatFeeRunMutation represents an operation that mutates the ChargeFlatFeeRun nodes in the graph. +type ChargeFlatFeeRunMutation struct { config - op Op - typ string - id *string - currency *currencyx.Code - service_period_start *time.Time - service_period_end *time.Time - quantity *alpacadecimal.Decimal - invoicing_app_external_id *string - child_unique_reference_id *string - per_unit_amount *alpacadecimal.Decimal - category *stddetailedline.Category - payment_term *productcatalog.PaymentTermType - index *int - addindex *int - credits_applied **creditsapplied.CreditsApplied - 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 - amount *alpacadecimal.Decimal - taxes_total *alpacadecimal.Decimal - taxes_inclusive_total *alpacadecimal.Decimal - taxes_exclusive_total *alpacadecimal.Decimal - charges_total *alpacadecimal.Decimal - discounts_total *alpacadecimal.Decimal - credits_total *alpacadecimal.Decimal - total *alpacadecimal.Decimal - pricer_reference_id *string - clearedFields map[string]struct{} - run *string - clearedrun bool - done bool - oldValue func(context.Context) (*ChargeFlatFeeRunDetailedLine, error) - predicates []predicate.ChargeFlatFeeRunDetailedLine + op Op + typ string + id *string + namespace *string + created_at *time.Time + updated_at *time.Time + deleted_at *time.Time + amount *alpacadecimal.Decimal + taxes_total *alpacadecimal.Decimal + taxes_inclusive_total *alpacadecimal.Decimal + taxes_exclusive_total *alpacadecimal.Decimal + charges_total *alpacadecimal.Decimal + discounts_total *alpacadecimal.Decimal + credits_total *alpacadecimal.Decimal + total *alpacadecimal.Decimal + _type *flatfee.RealizationRunType + initial_type *flatfee.RealizationRunType + service_period_from *time.Time + service_period_to *time.Time + amount_after_proration *alpacadecimal.Decimal + no_fiat_transaction_required *bool + immutable *bool + clearedFields map[string]struct{} + flat_fee *string + clearedflat_fee bool + billing_invoice_line *string + clearedbilling_invoice_line bool + billing_invoice *string + clearedbilling_invoice bool + credit_allocations map[string]struct{} + removedcredit_allocations map[string]struct{} + clearedcredit_allocations bool + detailed_lines map[string]struct{} + removeddetailed_lines map[string]struct{} + cleareddetailed_lines bool + invoiced_usage *string + clearedinvoiced_usage bool + payment *string + clearedpayment bool + done bool + oldValue func(context.Context) (*ChargeFlatFeeRun, error) + predicates []predicate.ChargeFlatFeeRun } -var _ ent.Mutation = (*ChargeFlatFeeRunDetailedLineMutation)(nil) +var _ ent.Mutation = (*ChargeFlatFeeRunMutation)(nil) -// chargeflatfeerundetailedlineOption allows management of the mutation configuration using functional options. -type chargeflatfeerundetailedlineOption func(*ChargeFlatFeeRunDetailedLineMutation) +// chargeflatfeerunOption allows management of the mutation configuration using functional options. +type chargeflatfeerunOption func(*ChargeFlatFeeRunMutation) -// newChargeFlatFeeRunDetailedLineMutation creates new mutation for the ChargeFlatFeeRunDetailedLine entity. -func newChargeFlatFeeRunDetailedLineMutation(c config, op Op, opts ...chargeflatfeerundetailedlineOption) *ChargeFlatFeeRunDetailedLineMutation { - m := &ChargeFlatFeeRunDetailedLineMutation{ +// newChargeFlatFeeRunMutation creates new mutation for the ChargeFlatFeeRun entity. +func newChargeFlatFeeRunMutation(c config, op Op, opts ...chargeflatfeerunOption) *ChargeFlatFeeRunMutation { + m := &ChargeFlatFeeRunMutation{ config: c, op: op, - typ: TypeChargeFlatFeeRunDetailedLine, + typ: TypeChargeFlatFeeRun, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -54069,20 +53345,20 @@ func newChargeFlatFeeRunDetailedLineMutation(c config, op Op, opts ...chargeflat return m } -// withChargeFlatFeeRunDetailedLineID sets the ID field of the mutation. -func withChargeFlatFeeRunDetailedLineID(id string) chargeflatfeerundetailedlineOption { - return func(m *ChargeFlatFeeRunDetailedLineMutation) { +// withChargeFlatFeeRunID sets the ID field of the mutation. +func withChargeFlatFeeRunID(id string) chargeflatfeerunOption { + return func(m *ChargeFlatFeeRunMutation) { var ( err error once sync.Once - value *ChargeFlatFeeRunDetailedLine + value *ChargeFlatFeeRun ) - m.oldValue = func(ctx context.Context) (*ChargeFlatFeeRunDetailedLine, error) { + m.oldValue = func(ctx context.Context) (*ChargeFlatFeeRun, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { - value, err = m.Client().ChargeFlatFeeRunDetailedLine.Get(ctx, id) + value, err = m.Client().ChargeFlatFeeRun.Get(ctx, id) } }) return value, err @@ -54091,10 +53367,10 @@ func withChargeFlatFeeRunDetailedLineID(id string) chargeflatfeerundetailedlineO } } -// withChargeFlatFeeRunDetailedLine sets the old ChargeFlatFeeRunDetailedLine of the mutation. -func withChargeFlatFeeRunDetailedLine(node *ChargeFlatFeeRunDetailedLine) chargeflatfeerundetailedlineOption { - return func(m *ChargeFlatFeeRunDetailedLineMutation) { - m.oldValue = func(context.Context) (*ChargeFlatFeeRunDetailedLine, error) { +// withChargeFlatFeeRun sets the old ChargeFlatFeeRun of the mutation. +func withChargeFlatFeeRun(node *ChargeFlatFeeRun) chargeflatfeerunOption { + return func(m *ChargeFlatFeeRunMutation) { + m.oldValue = func(context.Context) (*ChargeFlatFeeRun, error) { return node, nil } m.id = &node.ID @@ -54103,7 +53379,7 @@ func withChargeFlatFeeRunDetailedLine(node *ChargeFlatFeeRunDetailedLine) charge // 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 ChargeFlatFeeRunDetailedLineMutation) Client() *Client { +func (m ChargeFlatFeeRunMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -54111,7 +53387,7 @@ func (m ChargeFlatFeeRunDetailedLineMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m ChargeFlatFeeRunDetailedLineMutation) Tx() (*Tx, error) { +func (m ChargeFlatFeeRunMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("db: mutation is not running in a transaction") } @@ -54121,14 +53397,14 @@ func (m ChargeFlatFeeRunDetailedLineMutation) Tx() (*Tx, error) { } // SetID sets the value of the id field. Note that this -// operation is only accepted on creation of ChargeFlatFeeRunDetailedLine entities. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetID(id string) { +// operation is only accepted on creation of ChargeFlatFeeRun entities. +func (m *ChargeFlatFeeRunMutation) 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 *ChargeFlatFeeRunDetailedLineMutation) ID() (id string, exists bool) { +func (m *ChargeFlatFeeRunMutation) ID() (id string, exists bool) { if m.id == nil { return } @@ -54139,7 +53415,7 @@ func (m *ChargeFlatFeeRunDetailedLineMutation) ID() (id string, exists bool) { // 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 *ChargeFlatFeeRunDetailedLineMutation) IDs(ctx context.Context) ([]string, error) { +func (m *ChargeFlatFeeRunMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() @@ -54148,1329 +53424,1249 @@ func (m *ChargeFlatFeeRunDetailedLineMutation) IDs(ctx context.Context) ([]strin } fallthrough case m.op.Is(OpUpdate | OpDelete): - return m.Client().ChargeFlatFeeRunDetailedLine.Query().Where(m.predicates...).IDs(ctx) + return m.Client().ChargeFlatFeeRun.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } -// SetCurrency sets the "currency" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetCurrency(c currencyx.Code) { - m.currency = &c +// SetNamespace sets the "namespace" field. +func (m *ChargeFlatFeeRunMutation) SetNamespace(s string) { + m.namespace = &s } -// Currency returns the value of the "currency" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) Currency() (r currencyx.Code, exists bool) { - v := m.currency +// Namespace returns the value of the "namespace" field in the mutation. +func (m *ChargeFlatFeeRunMutation) Namespace() (r string, exists bool) { + v := m.namespace if v == nil { return } return *v, true } -// OldCurrency returns the old "currency" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldNamespace returns the old "namespace" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldCurrency(ctx context.Context) (v *currencyx.Code, err error) { +func (m *ChargeFlatFeeRunMutation) OldNamespace(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCurrency is only allowed on UpdateOne operations") + return v, errors.New("OldNamespace 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") + 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 OldCurrency: %w", err) + return v, fmt.Errorf("querying old value for OldNamespace: %w", err) } - return oldValue.Currency, nil -} - -// ClearCurrency clears the value of the "currency" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ClearCurrency() { - m.currency = nil - m.clearedFields[chargeflatfeerundetailedline.FieldCurrency] = struct{}{} -} - -// CurrencyCleared returns if the "currency" field was cleared in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) CurrencyCleared() bool { - _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldCurrency] - return ok + return oldValue.Namespace, nil } -// ResetCurrency resets all changes to the "currency" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetCurrency() { - m.currency = nil - delete(m.clearedFields, chargeflatfeerundetailedline.FieldCurrency) +// ResetNamespace resets all changes to the "namespace" field. +func (m *ChargeFlatFeeRunMutation) ResetNamespace() { + m.namespace = nil } -// SetServicePeriodStart sets the "service_period_start" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetServicePeriodStart(t time.Time) { - m.service_period_start = &t +// SetCreatedAt sets the "created_at" field. +func (m *ChargeFlatFeeRunMutation) SetCreatedAt(t time.Time) { + m.created_at = &t } -// ServicePeriodStart returns the value of the "service_period_start" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) ServicePeriodStart() (r time.Time, exists bool) { - v := m.service_period_start +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ChargeFlatFeeRunMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at if v == nil { return } return *v, true } -// OldServicePeriodStart returns the old "service_period_start" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldServicePeriodStart(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodStart is only allowed on UpdateOne operations") + return v, errors.New("OldCreatedAt 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") + 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 OldServicePeriodStart: %w", err) + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } - return oldValue.ServicePeriodStart, nil + return oldValue.CreatedAt, nil } -// ResetServicePeriodStart resets all changes to the "service_period_start" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetServicePeriodStart() { - m.service_period_start = nil +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ChargeFlatFeeRunMutation) ResetCreatedAt() { + m.created_at = nil } -// SetServicePeriodEnd sets the "service_period_end" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetServicePeriodEnd(t time.Time) { - m.service_period_end = &t +// SetUpdatedAt sets the "updated_at" field. +func (m *ChargeFlatFeeRunMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t } -// ServicePeriodEnd returns the value of the "service_period_end" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) ServicePeriodEnd() (r time.Time, exists bool) { - v := m.service_period_end +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ChargeFlatFeeRunMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at if v == nil { return } return *v, true } -// OldServicePeriodEnd returns the old "service_period_end" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldServicePeriodEnd(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodEnd is only allowed on UpdateOne operations") + return v, errors.New("OldUpdatedAt 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") + 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 OldServicePeriodEnd: %w", err) + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } - return oldValue.ServicePeriodEnd, nil + return oldValue.UpdatedAt, nil } -// ResetServicePeriodEnd resets all changes to the "service_period_end" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetServicePeriodEnd() { - m.service_period_end = nil +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *ChargeFlatFeeRunMutation) ResetUpdatedAt() { + m.updated_at = nil } -// SetQuantity sets the "quantity" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetQuantity(a alpacadecimal.Decimal) { - m.quantity = &a +// SetDeletedAt sets the "deleted_at" field. +func (m *ChargeFlatFeeRunMutation) SetDeletedAt(t time.Time) { + m.deleted_at = &t } -// Quantity returns the value of the "quantity" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) Quantity() (r alpacadecimal.Decimal, exists bool) { - v := m.quantity +// DeletedAt returns the value of the "deleted_at" field in the mutation. +func (m *ChargeFlatFeeRunMutation) DeletedAt() (r time.Time, exists bool) { + v := m.deleted_at if v == nil { return } return *v, true } -// OldQuantity returns the old "quantity" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldDeletedAt returns the old "deleted_at" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldQuantity(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeRunMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldQuantity is only allowed on UpdateOne operations") + return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldQuantity requires an ID field in the mutation") + 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 OldQuantity: %w", err) + return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) } - return oldValue.Quantity, nil + return oldValue.DeletedAt, nil } -// ResetQuantity resets all changes to the "quantity" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetQuantity() { - m.quantity = nil +// ClearDeletedAt clears the value of the "deleted_at" field. +func (m *ChargeFlatFeeRunMutation) ClearDeletedAt() { + m.deleted_at = nil + m.clearedFields[chargeflatfeerun.FieldDeletedAt] = struct{}{} } -// SetInvoicingAppExternalID sets the "invoicing_app_external_id" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetInvoicingAppExternalID(s string) { - m.invoicing_app_external_id = &s +// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. +func (m *ChargeFlatFeeRunMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargeflatfeerun.FieldDeletedAt] + return ok } -// InvoicingAppExternalID returns the value of the "invoicing_app_external_id" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) InvoicingAppExternalID() (r string, exists bool) { - v := m.invoicing_app_external_id +// ResetDeletedAt resets all changes to the "deleted_at" field. +func (m *ChargeFlatFeeRunMutation) ResetDeletedAt() { + m.deleted_at = nil + delete(m.clearedFields, chargeflatfeerun.FieldDeletedAt) +} + +// SetAmount sets the "amount" field. +func (m *ChargeFlatFeeRunMutation) SetAmount(a alpacadecimal.Decimal) { + m.amount = &a +} + +// Amount returns the value of the "amount" field in the mutation. +func (m *ChargeFlatFeeRunMutation) Amount() (r alpacadecimal.Decimal, exists bool) { + v := m.amount if v == nil { return } return *v, true } -// OldInvoicingAppExternalID returns the old "invoicing_app_external_id" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldAmount returns the old "amount" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldInvoicingAppExternalID(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeRunMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldInvoicingAppExternalID is only allowed on UpdateOne operations") + return v, errors.New("OldAmount is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldInvoicingAppExternalID requires an ID field in the mutation") + return v, errors.New("OldAmount requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldInvoicingAppExternalID: %w", err) + return v, fmt.Errorf("querying old value for OldAmount: %w", err) } - return oldValue.InvoicingAppExternalID, nil -} - -// ClearInvoicingAppExternalID clears the value of the "invoicing_app_external_id" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ClearInvoicingAppExternalID() { - m.invoicing_app_external_id = nil - m.clearedFields[chargeflatfeerundetailedline.FieldInvoicingAppExternalID] = struct{}{} -} - -// InvoicingAppExternalIDCleared returns if the "invoicing_app_external_id" field was cleared in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) InvoicingAppExternalIDCleared() bool { - _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldInvoicingAppExternalID] - return ok + return oldValue.Amount, nil } -// ResetInvoicingAppExternalID resets all changes to the "invoicing_app_external_id" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetInvoicingAppExternalID() { - m.invoicing_app_external_id = nil - delete(m.clearedFields, chargeflatfeerundetailedline.FieldInvoicingAppExternalID) +// ResetAmount resets all changes to the "amount" field. +func (m *ChargeFlatFeeRunMutation) ResetAmount() { + m.amount = nil } -// SetChildUniqueReferenceID sets the "child_unique_reference_id" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetChildUniqueReferenceID(s string) { - m.child_unique_reference_id = &s +// SetTaxesTotal sets the "taxes_total" field. +func (m *ChargeFlatFeeRunMutation) SetTaxesTotal(a alpacadecimal.Decimal) { + m.taxes_total = &a } -// ChildUniqueReferenceID returns the value of the "child_unique_reference_id" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) ChildUniqueReferenceID() (r string, exists bool) { - v := m.child_unique_reference_id +// TaxesTotal returns the value of the "taxes_total" field in the mutation. +func (m *ChargeFlatFeeRunMutation) TaxesTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.taxes_total if v == nil { return } return *v, true } -// OldChildUniqueReferenceID returns the old "child_unique_reference_id" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldTaxesTotal returns the old "taxes_total" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldChildUniqueReferenceID(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeRunMutation) OldTaxesTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldChildUniqueReferenceID is only allowed on UpdateOne operations") + return v, errors.New("OldTaxesTotal 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") + return v, errors.New("OldTaxesTotal 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 v, fmt.Errorf("querying old value for OldTaxesTotal: %w", err) } - return oldValue.ChildUniqueReferenceID, nil + return oldValue.TaxesTotal, nil } -// ResetChildUniqueReferenceID resets all changes to the "child_unique_reference_id" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetChildUniqueReferenceID() { - m.child_unique_reference_id = nil +// ResetTaxesTotal resets all changes to the "taxes_total" field. +func (m *ChargeFlatFeeRunMutation) ResetTaxesTotal() { + m.taxes_total = nil } -// SetPerUnitAmount sets the "per_unit_amount" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetPerUnitAmount(a alpacadecimal.Decimal) { - m.per_unit_amount = &a +// SetTaxesInclusiveTotal sets the "taxes_inclusive_total" field. +func (m *ChargeFlatFeeRunMutation) SetTaxesInclusiveTotal(a alpacadecimal.Decimal) { + m.taxes_inclusive_total = &a } -// PerUnitAmount returns the value of the "per_unit_amount" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) PerUnitAmount() (r alpacadecimal.Decimal, exists bool) { - v := m.per_unit_amount +// TaxesInclusiveTotal returns the value of the "taxes_inclusive_total" field in the mutation. +func (m *ChargeFlatFeeRunMutation) TaxesInclusiveTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.taxes_inclusive_total if v == nil { return } return *v, true } -// OldPerUnitAmount returns the old "per_unit_amount" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldTaxesInclusiveTotal returns the old "taxes_inclusive_total" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldPerUnitAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeRunMutation) OldTaxesInclusiveTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldPerUnitAmount is only allowed on UpdateOne operations") + return v, errors.New("OldTaxesInclusiveTotal is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldPerUnitAmount requires an ID field in the mutation") + return v, errors.New("OldTaxesInclusiveTotal requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldPerUnitAmount: %w", err) + return v, fmt.Errorf("querying old value for OldTaxesInclusiveTotal: %w", err) } - return oldValue.PerUnitAmount, nil + return oldValue.TaxesInclusiveTotal, nil } -// ResetPerUnitAmount resets all changes to the "per_unit_amount" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetPerUnitAmount() { - m.per_unit_amount = nil +// ResetTaxesInclusiveTotal resets all changes to the "taxes_inclusive_total" field. +func (m *ChargeFlatFeeRunMutation) ResetTaxesInclusiveTotal() { + m.taxes_inclusive_total = nil } -// SetCategory sets the "category" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetCategory(s stddetailedline.Category) { - m.category = &s +// SetTaxesExclusiveTotal sets the "taxes_exclusive_total" field. +func (m *ChargeFlatFeeRunMutation) SetTaxesExclusiveTotal(a alpacadecimal.Decimal) { + m.taxes_exclusive_total = &a } -// Category returns the value of the "category" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) Category() (r stddetailedline.Category, exists bool) { - v := m.category +// TaxesExclusiveTotal returns the value of the "taxes_exclusive_total" field in the mutation. +func (m *ChargeFlatFeeRunMutation) TaxesExclusiveTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.taxes_exclusive_total if v == nil { return } return *v, true } -// OldCategory returns the old "category" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldTaxesExclusiveTotal returns the old "taxes_exclusive_total" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldCategory(ctx context.Context) (v stddetailedline.Category, err error) { +func (m *ChargeFlatFeeRunMutation) OldTaxesExclusiveTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCategory is only allowed on UpdateOne operations") + return v, errors.New("OldTaxesExclusiveTotal is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCategory requires an ID field in the mutation") + return v, errors.New("OldTaxesExclusiveTotal requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldCategory: %w", err) + return v, fmt.Errorf("querying old value for OldTaxesExclusiveTotal: %w", err) } - return oldValue.Category, nil + return oldValue.TaxesExclusiveTotal, nil } -// ResetCategory resets all changes to the "category" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetCategory() { - m.category = nil +// ResetTaxesExclusiveTotal resets all changes to the "taxes_exclusive_total" field. +func (m *ChargeFlatFeeRunMutation) ResetTaxesExclusiveTotal() { + m.taxes_exclusive_total = nil } -// SetPaymentTerm sets the "payment_term" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetPaymentTerm(ptt productcatalog.PaymentTermType) { - m.payment_term = &ptt +// SetChargesTotal sets the "charges_total" field. +func (m *ChargeFlatFeeRunMutation) SetChargesTotal(a alpacadecimal.Decimal) { + m.charges_total = &a } -// PaymentTerm returns the value of the "payment_term" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) PaymentTerm() (r productcatalog.PaymentTermType, exists bool) { - v := m.payment_term +// ChargesTotal returns the value of the "charges_total" field in the mutation. +func (m *ChargeFlatFeeRunMutation) ChargesTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.charges_total if v == nil { return } return *v, true } -// OldPaymentTerm returns the old "payment_term" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldChargesTotal returns the old "charges_total" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldPaymentTerm(ctx context.Context) (v productcatalog.PaymentTermType, err error) { +func (m *ChargeFlatFeeRunMutation) OldChargesTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldPaymentTerm is only allowed on UpdateOne operations") + return v, errors.New("OldChargesTotal is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldPaymentTerm requires an ID field in the mutation") + return v, errors.New("OldChargesTotal requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldPaymentTerm: %w", err) + return v, fmt.Errorf("querying old value for OldChargesTotal: %w", err) } - return oldValue.PaymentTerm, nil + return oldValue.ChargesTotal, nil } -// ResetPaymentTerm resets all changes to the "payment_term" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetPaymentTerm() { - m.payment_term = nil +// ResetChargesTotal resets all changes to the "charges_total" field. +func (m *ChargeFlatFeeRunMutation) ResetChargesTotal() { + m.charges_total = nil } -// SetIndex sets the "index" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetIndex(i int) { - m.index = &i - m.addindex = nil +// SetDiscountsTotal sets the "discounts_total" field. +func (m *ChargeFlatFeeRunMutation) SetDiscountsTotal(a alpacadecimal.Decimal) { + m.discounts_total = &a } -// Index returns the value of the "index" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) Index() (r int, exists bool) { - v := m.index +// DiscountsTotal returns the value of the "discounts_total" field in the mutation. +func (m *ChargeFlatFeeRunMutation) DiscountsTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.discounts_total if v == nil { return } return *v, true } -// OldIndex returns the old "index" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldDiscountsTotal returns the old "discounts_total" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldIndex(ctx context.Context) (v *int, err error) { +func (m *ChargeFlatFeeRunMutation) OldDiscountsTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldIndex is only allowed on UpdateOne operations") + return v, errors.New("OldDiscountsTotal is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldIndex requires an ID field in the mutation") + return v, errors.New("OldDiscountsTotal requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldIndex: %w", err) + return v, fmt.Errorf("querying old value for OldDiscountsTotal: %w", err) } - return oldValue.Index, nil + return oldValue.DiscountsTotal, nil } -// AddIndex adds i to the "index" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) AddIndex(i int) { - if m.addindex != nil { - *m.addindex += i - } else { - m.addindex = &i - } +// ResetDiscountsTotal resets all changes to the "discounts_total" field. +func (m *ChargeFlatFeeRunMutation) ResetDiscountsTotal() { + m.discounts_total = nil } -// AddedIndex returns the value that was added to the "index" field in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) AddedIndex() (r int, exists bool) { - v := m.addindex +// SetCreditsTotal sets the "credits_total" field. +func (m *ChargeFlatFeeRunMutation) SetCreditsTotal(a alpacadecimal.Decimal) { + m.credits_total = &a +} + +// CreditsTotal returns the value of the "credits_total" field in the mutation. +func (m *ChargeFlatFeeRunMutation) CreditsTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.credits_total if v == nil { return } return *v, true } -// ClearIndex clears the value of the "index" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ClearIndex() { - m.index = nil - m.addindex = nil - m.clearedFields[chargeflatfeerundetailedline.FieldIndex] = struct{}{} -} - -// IndexCleared returns if the "index" field was cleared in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) IndexCleared() bool { - _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldIndex] - return ok +// OldCreditsTotal returns the old "credits_total" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunMutation) OldCreditsTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreditsTotal is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreditsTotal requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreditsTotal: %w", err) + } + return oldValue.CreditsTotal, nil } -// ResetIndex resets all changes to the "index" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetIndex() { - m.index = nil - m.addindex = nil - delete(m.clearedFields, chargeflatfeerundetailedline.FieldIndex) +// ResetCreditsTotal resets all changes to the "credits_total" field. +func (m *ChargeFlatFeeRunMutation) ResetCreditsTotal() { + m.credits_total = nil } -// SetCreditsApplied sets the "credits_applied" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetCreditsApplied(ca *creditsapplied.CreditsApplied) { - m.credits_applied = &ca +// SetTotal sets the "total" field. +func (m *ChargeFlatFeeRunMutation) SetTotal(a alpacadecimal.Decimal) { + m.total = &a } -// CreditsApplied returns the value of the "credits_applied" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) CreditsApplied() (r *creditsapplied.CreditsApplied, exists bool) { - v := m.credits_applied +// Total returns the value of the "total" field in the mutation. +func (m *ChargeFlatFeeRunMutation) Total() (r alpacadecimal.Decimal, exists bool) { + v := m.total if v == nil { return } return *v, true } -// OldCreditsApplied returns the old "credits_applied" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldTotal returns the old "total" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldCreditsApplied(ctx context.Context) (v *creditsapplied.CreditsApplied, err error) { +func (m *ChargeFlatFeeRunMutation) OldTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreditsApplied is only allowed on UpdateOne operations") + return v, errors.New("OldTotal is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreditsApplied requires an ID field in the mutation") + return v, errors.New("OldTotal requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldCreditsApplied: %w", err) + return v, fmt.Errorf("querying old value for OldTotal: %w", err) } - return oldValue.CreditsApplied, nil -} - -// ClearCreditsApplied clears the value of the "credits_applied" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ClearCreditsApplied() { - m.credits_applied = nil - m.clearedFields[chargeflatfeerundetailedline.FieldCreditsApplied] = struct{}{} -} - -// CreditsAppliedCleared returns if the "credits_applied" field was cleared in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) CreditsAppliedCleared() bool { - _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldCreditsApplied] - return ok + return oldValue.Total, nil } -// ResetCreditsApplied resets all changes to the "credits_applied" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetCreditsApplied() { - m.credits_applied = nil - delete(m.clearedFields, chargeflatfeerundetailedline.FieldCreditsApplied) +// ResetTotal resets all changes to the "total" field. +func (m *ChargeFlatFeeRunMutation) ResetTotal() { + m.total = nil } -// SetAnnotations sets the "annotations" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetAnnotations(value models.Annotations) { - m.annotations = &value +// SetChargeID sets the "charge_id" field. +func (m *ChargeFlatFeeRunMutation) SetChargeID(s string) { + m.flat_fee = &s } -// Annotations returns the value of the "annotations" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) Annotations() (r models.Annotations, exists bool) { - v := m.annotations +// ChargeID returns the value of the "charge_id" field in the mutation. +func (m *ChargeFlatFeeRunMutation) ChargeID() (r string, exists bool) { + v := m.flat_fee if v == nil { return } return *v, true } -// OldAnnotations returns the old "annotations" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldChargeID returns the old "charge_id" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldAnnotations(ctx context.Context) (v models.Annotations, err error) { +func (m *ChargeFlatFeeRunMutation) OldChargeID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAnnotations is only allowed on UpdateOne operations") + return v, errors.New("OldChargeID 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") + 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 OldAnnotations: %w", err) + return v, fmt.Errorf("querying old value for OldChargeID: %w", err) } - return oldValue.Annotations, nil -} - -// ClearAnnotations clears the value of the "annotations" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ClearAnnotations() { - m.annotations = nil - m.clearedFields[chargeflatfeerundetailedline.FieldAnnotations] = struct{}{} -} - -// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) AnnotationsCleared() bool { - _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldAnnotations] - return ok + return oldValue.ChargeID, nil } -// ResetAnnotations resets all changes to the "annotations" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetAnnotations() { - m.annotations = nil - delete(m.clearedFields, chargeflatfeerundetailedline.FieldAnnotations) +// ResetChargeID resets all changes to the "charge_id" field. +func (m *ChargeFlatFeeRunMutation) ResetChargeID() { + m.flat_fee = nil } -// SetNamespace sets the "namespace" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetNamespace(s string) { - m.namespace = &s +// SetType sets the "type" field. +func (m *ChargeFlatFeeRunMutation) SetType(frt flatfee.RealizationRunType) { + m._type = &frt } -// Namespace returns the value of the "namespace" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) Namespace() (r string, exists bool) { - v := m.namespace +// GetType returns the value of the "type" field in the mutation. +func (m *ChargeFlatFeeRunMutation) GetType() (r flatfee.RealizationRunType, exists bool) { + v := m._type if v == nil { return } return *v, true } -// OldNamespace returns the old "namespace" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldType returns the old "type" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldNamespace(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeRunMutation) OldType(ctx context.Context) (v flatfee.RealizationRunType, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldNamespace is only allowed on UpdateOne operations") + return v, errors.New("OldType 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") + return v, errors.New("OldType 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 v, fmt.Errorf("querying old value for OldType: %w", err) } - return oldValue.Namespace, nil + return oldValue.Type, nil } -// ResetNamespace resets all changes to the "namespace" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetNamespace() { - m.namespace = nil +// ResetType resets all changes to the "type" field. +func (m *ChargeFlatFeeRunMutation) ResetType() { + m._type = nil } -// SetMetadata sets the "metadata" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetMetadata(value map[string]string) { - m.metadata = &value +// SetInitialType sets the "initial_type" field. +func (m *ChargeFlatFeeRunMutation) SetInitialType(frt flatfee.RealizationRunType) { + m.initial_type = &frt } -// Metadata returns the value of the "metadata" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) Metadata() (r map[string]string, exists bool) { - v := m.metadata +// InitialType returns the value of the "initial_type" field in the mutation. +func (m *ChargeFlatFeeRunMutation) InitialType() (r flatfee.RealizationRunType, exists bool) { + v := m.initial_type if v == nil { return } return *v, true } -// OldMetadata returns the old "metadata" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldInitialType returns the old "initial_type" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldMetadata(ctx context.Context) (v map[string]string, err error) { +func (m *ChargeFlatFeeRunMutation) OldInitialType(ctx context.Context) (v flatfee.RealizationRunType, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldMetadata is only allowed on UpdateOne operations") + return v, errors.New("OldInitialType 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") + return v, errors.New("OldInitialType 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 v, fmt.Errorf("querying old value for OldInitialType: %w", err) } - return oldValue.Metadata, nil -} - -// ClearMetadata clears the value of the "metadata" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ClearMetadata() { - m.metadata = nil - m.clearedFields[chargeflatfeerundetailedline.FieldMetadata] = struct{}{} -} - -// MetadataCleared returns if the "metadata" field was cleared in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) MetadataCleared() bool { - _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldMetadata] - return ok + return oldValue.InitialType, nil } -// ResetMetadata resets all changes to the "metadata" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetMetadata() { - m.metadata = nil - delete(m.clearedFields, chargeflatfeerundetailedline.FieldMetadata) +// ResetInitialType resets all changes to the "initial_type" field. +func (m *ChargeFlatFeeRunMutation) ResetInitialType() { + m.initial_type = nil } -// SetCreatedAt sets the "created_at" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetCreatedAt(t time.Time) { - m.created_at = &t +// SetServicePeriodFrom sets the "service_period_from" field. +func (m *ChargeFlatFeeRunMutation) SetServicePeriodFrom(t time.Time) { + m.service_period_from = &t } -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at +// ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. +func (m *ChargeFlatFeeRunMutation) ServicePeriodFrom() (r time.Time, exists bool) { + v := m.service_period_from if v == nil { return } return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + return v, errors.New("OldServicePeriodFrom 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") + return v, errors.New("OldServicePeriodFrom 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 v, fmt.Errorf("querying old value for OldServicePeriodFrom: %w", err) } - return oldValue.CreatedAt, nil + return oldValue.ServicePeriodFrom, nil } -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetCreatedAt() { - m.created_at = nil +// ResetServicePeriodFrom resets all changes to the "service_period_from" field. +func (m *ChargeFlatFeeRunMutation) ResetServicePeriodFrom() { + m.service_period_from = nil } -// SetUpdatedAt sets the "updated_at" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t +// SetServicePeriodTo sets the "service_period_to" field. +func (m *ChargeFlatFeeRunMutation) SetServicePeriodTo(t time.Time) { + m.service_period_to = &t } -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at +// ServicePeriodTo returns the value of the "service_period_to" field in the mutation. +func (m *ChargeFlatFeeRunMutation) ServicePeriodTo() (r time.Time, exists bool) { + v := m.service_period_to if v == nil { return } return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + return v, errors.New("OldServicePeriodTo 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") + return v, errors.New("OldServicePeriodTo 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 v, fmt.Errorf("querying old value for OldServicePeriodTo: %w", err) } - return oldValue.UpdatedAt, nil + return oldValue.ServicePeriodTo, nil } -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetUpdatedAt() { - m.updated_at = nil +// ResetServicePeriodTo resets all changes to the "service_period_to" field. +func (m *ChargeFlatFeeRunMutation) ResetServicePeriodTo() { + m.service_period_to = nil } -// SetDeletedAt sets the "deleted_at" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetDeletedAt(t time.Time) { - m.deleted_at = &t +// SetLineID sets the "line_id" field. +func (m *ChargeFlatFeeRunMutation) SetLineID(s string) { + m.billing_invoice_line = &s } -// DeletedAt returns the value of the "deleted_at" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) DeletedAt() (r time.Time, exists bool) { - v := m.deleted_at +// LineID returns the value of the "line_id" field in the mutation. +func (m *ChargeFlatFeeRunMutation) LineID() (r string, exists bool) { + v := m.billing_invoice_line if v == nil { return } return *v, true } -// OldDeletedAt returns the old "deleted_at" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldLineID returns the old "line_id" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeFlatFeeRunMutation) OldLineID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") + return v, errors.New("OldLineID 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") + return v, errors.New("OldLineID 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 v, fmt.Errorf("querying old value for OldLineID: %w", err) } - return oldValue.DeletedAt, nil + return oldValue.LineID, nil } -// ClearDeletedAt clears the value of the "deleted_at" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ClearDeletedAt() { - m.deleted_at = nil - m.clearedFields[chargeflatfeerundetailedline.FieldDeletedAt] = struct{}{} +// ClearLineID clears the value of the "line_id" field. +func (m *ChargeFlatFeeRunMutation) ClearLineID() { + m.billing_invoice_line = nil + m.clearedFields[chargeflatfeerun.FieldLineID] = struct{}{} } -// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) DeletedAtCleared() bool { - _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldDeletedAt] +// LineIDCleared returns if the "line_id" field was cleared in this mutation. +func (m *ChargeFlatFeeRunMutation) LineIDCleared() bool { + _, ok := m.clearedFields[chargeflatfeerun.FieldLineID] return ok } -// ResetDeletedAt resets all changes to the "deleted_at" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetDeletedAt() { - m.deleted_at = nil - delete(m.clearedFields, chargeflatfeerundetailedline.FieldDeletedAt) +// ResetLineID resets all changes to the "line_id" field. +func (m *ChargeFlatFeeRunMutation) ResetLineID() { + m.billing_invoice_line = nil + delete(m.clearedFields, chargeflatfeerun.FieldLineID) } -// SetName sets the "name" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetName(s string) { - m.name = &s +// SetInvoiceID sets the "invoice_id" field. +func (m *ChargeFlatFeeRunMutation) SetInvoiceID(s string) { + m.billing_invoice = &s } -// Name returns the value of the "name" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) Name() (r string, exists bool) { - v := m.name +// InvoiceID returns the value of the "invoice_id" field in the mutation. +func (m *ChargeFlatFeeRunMutation) InvoiceID() (r string, exists bool) { + v := m.billing_invoice if v == nil { return } return *v, true } -// OldName returns the old "name" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldInvoiceID returns the old "invoice_id" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldName(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeRunMutation) OldInvoiceID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldName is only allowed on UpdateOne operations") + return v, errors.New("OldInvoiceID 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") + 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 OldName: %w", err) + return v, fmt.Errorf("querying old value for OldInvoiceID: %w", err) } - return oldValue.Name, nil -} - -// ResetName resets all changes to the "name" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetName() { - m.name = nil + return oldValue.InvoiceID, nil } -// SetDescription sets the "description" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetDescription(s string) { - m.description = &s +// ClearInvoiceID clears the value of the "invoice_id" field. +func (m *ChargeFlatFeeRunMutation) ClearInvoiceID() { + m.billing_invoice = nil + m.clearedFields[chargeflatfeerun.FieldInvoiceID] = struct{}{} } -// Description returns the value of the "description" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) Description() (r string, exists bool) { - v := m.description - if v == nil { - return - } - return *v, true +// InvoiceIDCleared returns if the "invoice_id" field was cleared in this mutation. +func (m *ChargeFlatFeeRunMutation) InvoiceIDCleared() bool { + _, ok := m.clearedFields[chargeflatfeerun.FieldInvoiceID] + return ok } -// OldDescription returns the old "description" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) 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 *ChargeFlatFeeRunDetailedLineMutation) ClearDescription() { - m.description = nil - m.clearedFields[chargeflatfeerundetailedline.FieldDescription] = struct{}{} -} - -// DescriptionCleared returns if the "description" field was cleared in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) DescriptionCleared() bool { - _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldDescription] - return ok -} - -// ResetDescription resets all changes to the "description" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetDescription() { - m.description = nil - delete(m.clearedFields, chargeflatfeerundetailedline.FieldDescription) +// ResetInvoiceID resets all changes to the "invoice_id" field. +func (m *ChargeFlatFeeRunMutation) ResetInvoiceID() { + m.billing_invoice = nil + delete(m.clearedFields, chargeflatfeerun.FieldInvoiceID) } -// SetAmount sets the "amount" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetAmount(a alpacadecimal.Decimal) { - m.amount = &a +// SetAmountAfterProration sets the "amount_after_proration" field. +func (m *ChargeFlatFeeRunMutation) SetAmountAfterProration(a alpacadecimal.Decimal) { + m.amount_after_proration = &a } -// Amount returns the value of the "amount" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) Amount() (r alpacadecimal.Decimal, exists bool) { - v := m.amount +// AmountAfterProration returns the value of the "amount_after_proration" field in the mutation. +func (m *ChargeFlatFeeRunMutation) AmountAfterProration() (r alpacadecimal.Decimal, exists bool) { + v := m.amount_after_proration if v == nil { return } return *v, true } -// OldAmount returns the old "amount" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldAmountAfterProration returns the old "amount_after_proration" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeRunMutation) OldAmountAfterProration(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAmount is only allowed on UpdateOne operations") + return v, errors.New("OldAmountAfterProration is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAmount requires an ID field in the mutation") + return v, errors.New("OldAmountAfterProration requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldAmount: %w", err) + return v, fmt.Errorf("querying old value for OldAmountAfterProration: %w", err) } - return oldValue.Amount, nil + return oldValue.AmountAfterProration, nil } -// ResetAmount resets all changes to the "amount" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetAmount() { - m.amount = nil +// ResetAmountAfterProration resets all changes to the "amount_after_proration" field. +func (m *ChargeFlatFeeRunMutation) ResetAmountAfterProration() { + m.amount_after_proration = nil } -// SetTaxesTotal sets the "taxes_total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetTaxesTotal(a alpacadecimal.Decimal) { - m.taxes_total = &a +// SetNoFiatTransactionRequired sets the "no_fiat_transaction_required" field. +func (m *ChargeFlatFeeRunMutation) SetNoFiatTransactionRequired(b bool) { + m.no_fiat_transaction_required = &b } -// TaxesTotal returns the value of the "taxes_total" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) TaxesTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.taxes_total +// NoFiatTransactionRequired returns the value of the "no_fiat_transaction_required" field in the mutation. +func (m *ChargeFlatFeeRunMutation) NoFiatTransactionRequired() (r bool, exists bool) { + v := m.no_fiat_transaction_required if v == nil { return } return *v, true } -// OldTaxesTotal returns the old "taxes_total" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldNoFiatTransactionRequired returns the old "no_fiat_transaction_required" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldTaxesTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeRunMutation) OldNoFiatTransactionRequired(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTaxesTotal is only allowed on UpdateOne operations") + return v, errors.New("OldNoFiatTransactionRequired is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTaxesTotal requires an ID field in the mutation") + return v, errors.New("OldNoFiatTransactionRequired requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldTaxesTotal: %w", err) + return v, fmt.Errorf("querying old value for OldNoFiatTransactionRequired: %w", err) } - return oldValue.TaxesTotal, nil + return oldValue.NoFiatTransactionRequired, nil } -// ResetTaxesTotal resets all changes to the "taxes_total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetTaxesTotal() { - m.taxes_total = nil +// ResetNoFiatTransactionRequired resets all changes to the "no_fiat_transaction_required" field. +func (m *ChargeFlatFeeRunMutation) ResetNoFiatTransactionRequired() { + m.no_fiat_transaction_required = nil } -// SetTaxesInclusiveTotal sets the "taxes_inclusive_total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetTaxesInclusiveTotal(a alpacadecimal.Decimal) { - m.taxes_inclusive_total = &a +// SetImmutable sets the "immutable" field. +func (m *ChargeFlatFeeRunMutation) SetImmutable(b bool) { + m.immutable = &b } -// TaxesInclusiveTotal returns the value of the "taxes_inclusive_total" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) TaxesInclusiveTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.taxes_inclusive_total +// Immutable returns the value of the "immutable" field in the mutation. +func (m *ChargeFlatFeeRunMutation) Immutable() (r bool, exists bool) { + v := m.immutable if v == nil { return } return *v, true } -// OldTaxesInclusiveTotal returns the old "taxes_inclusive_total" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine object wasn't provided to the builder, the object is fetched from the database. +// OldImmutable returns the old "immutable" field's value of the ChargeFlatFeeRun entity. +// If the ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) OldTaxesInclusiveTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeRunMutation) OldImmutable(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTaxesInclusiveTotal is only allowed on UpdateOne operations") + return v, errors.New("OldImmutable is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTaxesInclusiveTotal requires an ID field in the mutation") + return v, errors.New("OldImmutable requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldTaxesInclusiveTotal: %w", err) + return v, fmt.Errorf("querying old value for OldImmutable: %w", err) } - return oldValue.TaxesInclusiveTotal, nil + return oldValue.Immutable, nil } -// ResetTaxesInclusiveTotal resets all changes to the "taxes_inclusive_total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetTaxesInclusiveTotal() { - m.taxes_inclusive_total = nil +// ResetImmutable resets all changes to the "immutable" field. +func (m *ChargeFlatFeeRunMutation) ResetImmutable() { + m.immutable = nil } -// SetTaxesExclusiveTotal sets the "taxes_exclusive_total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetTaxesExclusiveTotal(a alpacadecimal.Decimal) { - m.taxes_exclusive_total = &a +// SetFlatFeeID sets the "flat_fee" edge to the ChargeFlatFee entity by id. +func (m *ChargeFlatFeeRunMutation) SetFlatFeeID(id string) { + m.flat_fee = &id } -// TaxesExclusiveTotal returns the value of the "taxes_exclusive_total" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) TaxesExclusiveTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.taxes_exclusive_total - if v == nil { - return - } - return *v, true +// ClearFlatFee clears the "flat_fee" edge to the ChargeFlatFee entity. +func (m *ChargeFlatFeeRunMutation) ClearFlatFee() { + m.clearedflat_fee = true + m.clearedFields[chargeflatfeerun.FieldChargeID] = struct{}{} } -// OldTaxesExclusiveTotal returns the old "taxes_exclusive_total" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldTaxesExclusiveTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTaxesExclusiveTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTaxesExclusiveTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTaxesExclusiveTotal: %w", err) - } - return oldValue.TaxesExclusiveTotal, nil +// FlatFeeCleared reports if the "flat_fee" edge to the ChargeFlatFee entity was cleared. +func (m *ChargeFlatFeeRunMutation) FlatFeeCleared() bool { + return m.clearedflat_fee } -// ResetTaxesExclusiveTotal resets all changes to the "taxes_exclusive_total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetTaxesExclusiveTotal() { - m.taxes_exclusive_total = nil +// FlatFeeID returns the "flat_fee" edge ID in the mutation. +func (m *ChargeFlatFeeRunMutation) FlatFeeID() (id string, exists bool) { + if m.flat_fee != nil { + return *m.flat_fee, true + } + return } -// SetChargesTotal sets the "charges_total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetChargesTotal(a alpacadecimal.Decimal) { - m.charges_total = &a +// FlatFeeIDs returns the "flat_fee" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// FlatFeeID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeRunMutation) FlatFeeIDs() (ids []string) { + if id := m.flat_fee; id != nil { + ids = append(ids, *id) + } + return } -// ChargesTotal returns the value of the "charges_total" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) ChargesTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.charges_total - if v == nil { - return - } - return *v, true +// ResetFlatFee resets all changes to the "flat_fee" edge. +func (m *ChargeFlatFeeRunMutation) ResetFlatFee() { + m.flat_fee = nil + m.clearedflat_fee = false } -// OldChargesTotal returns the old "charges_total" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldChargesTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldChargesTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldChargesTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldChargesTotal: %w", err) - } - return oldValue.ChargesTotal, nil +// SetBillingInvoiceLineID sets the "billing_invoice_line" edge to the BillingInvoiceLine entity by id. +func (m *ChargeFlatFeeRunMutation) SetBillingInvoiceLineID(id string) { + m.billing_invoice_line = &id } -// ResetChargesTotal resets all changes to the "charges_total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetChargesTotal() { - m.charges_total = nil +// ClearBillingInvoiceLine clears the "billing_invoice_line" edge to the BillingInvoiceLine entity. +func (m *ChargeFlatFeeRunMutation) ClearBillingInvoiceLine() { + m.clearedbilling_invoice_line = true + m.clearedFields[chargeflatfeerun.FieldLineID] = struct{}{} } -// SetDiscountsTotal sets the "discounts_total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetDiscountsTotal(a alpacadecimal.Decimal) { - m.discounts_total = &a +// BillingInvoiceLineCleared reports if the "billing_invoice_line" edge to the BillingInvoiceLine entity was cleared. +func (m *ChargeFlatFeeRunMutation) BillingInvoiceLineCleared() bool { + return m.LineIDCleared() || m.clearedbilling_invoice_line } -// DiscountsTotal returns the value of the "discounts_total" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) DiscountsTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.discounts_total - if v == nil { - return +// BillingInvoiceLineID returns the "billing_invoice_line" edge ID in the mutation. +func (m *ChargeFlatFeeRunMutation) BillingInvoiceLineID() (id string, exists bool) { + if m.billing_invoice_line != nil { + return *m.billing_invoice_line, true } - return *v, true + return } -// OldDiscountsTotal returns the old "discounts_total" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldDiscountsTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDiscountsTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDiscountsTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDiscountsTotal: %w", err) +// BillingInvoiceLineIDs returns the "billing_invoice_line" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// BillingInvoiceLineID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeRunMutation) BillingInvoiceLineIDs() (ids []string) { + if id := m.billing_invoice_line; id != nil { + ids = append(ids, *id) } - return oldValue.DiscountsTotal, nil + return } -// ResetDiscountsTotal resets all changes to the "discounts_total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetDiscountsTotal() { - m.discounts_total = nil +// ResetBillingInvoiceLine resets all changes to the "billing_invoice_line" edge. +func (m *ChargeFlatFeeRunMutation) ResetBillingInvoiceLine() { + m.billing_invoice_line = nil + m.clearedbilling_invoice_line = false } -// SetCreditsTotal sets the "credits_total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetCreditsTotal(a alpacadecimal.Decimal) { - m.credits_total = &a +// SetBillingInvoiceID sets the "billing_invoice" edge to the BillingInvoice entity by id. +func (m *ChargeFlatFeeRunMutation) SetBillingInvoiceID(id string) { + m.billing_invoice = &id } -// CreditsTotal returns the value of the "credits_total" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) CreditsTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.credits_total - if v == nil { - return - } - return *v, true +// ClearBillingInvoice clears the "billing_invoice" edge to the BillingInvoice entity. +func (m *ChargeFlatFeeRunMutation) ClearBillingInvoice() { + m.clearedbilling_invoice = true + m.clearedFields[chargeflatfeerun.FieldInvoiceID] = struct{}{} } -// OldCreditsTotal returns the old "credits_total" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldCreditsTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreditsTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreditsTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreditsTotal: %w", err) - } - return oldValue.CreditsTotal, nil +// BillingInvoiceCleared reports if the "billing_invoice" edge to the BillingInvoice entity was cleared. +func (m *ChargeFlatFeeRunMutation) BillingInvoiceCleared() bool { + return m.InvoiceIDCleared() || m.clearedbilling_invoice } -// ResetCreditsTotal resets all changes to the "credits_total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetCreditsTotal() { - m.credits_total = nil +// BillingInvoiceID returns the "billing_invoice" edge ID in the mutation. +func (m *ChargeFlatFeeRunMutation) BillingInvoiceID() (id string, exists bool) { + if m.billing_invoice != nil { + return *m.billing_invoice, true + } + return } -// SetTotal sets the "total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetTotal(a alpacadecimal.Decimal) { - m.total = &a +// 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 *ChargeFlatFeeRunMutation) BillingInvoiceIDs() (ids []string) { + if id := m.billing_invoice; id != nil { + ids = append(ids, *id) + } + return } -// Total returns the value of the "total" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) Total() (r alpacadecimal.Decimal, exists bool) { - v := m.total - if v == nil { - return - } - return *v, true +// ResetBillingInvoice resets all changes to the "billing_invoice" edge. +func (m *ChargeFlatFeeRunMutation) ResetBillingInvoice() { + m.billing_invoice = nil + m.clearedbilling_invoice = false } -// OldTotal returns the old "total" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTotal requires an ID field in the mutation") +// AddCreditAllocationIDs adds the "credit_allocations" edge to the ChargeFlatFeeRunCreditAllocations entity by ids. +func (m *ChargeFlatFeeRunMutation) AddCreditAllocationIDs(ids ...string) { + if m.credit_allocations == nil { + m.credit_allocations = make(map[string]struct{}) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTotal: %w", err) + for i := range ids { + m.credit_allocations[ids[i]] = struct{}{} } - return oldValue.Total, nil } -// ResetTotal resets all changes to the "total" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetTotal() { - m.total = nil +// ClearCreditAllocations clears the "credit_allocations" edge to the ChargeFlatFeeRunCreditAllocations entity. +func (m *ChargeFlatFeeRunMutation) ClearCreditAllocations() { + m.clearedcredit_allocations = true } -// SetRunID sets the "run_id" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetRunID(s string) { - m.run = &s +// CreditAllocationsCleared reports if the "credit_allocations" edge to the ChargeFlatFeeRunCreditAllocations entity was cleared. +func (m *ChargeFlatFeeRunMutation) CreditAllocationsCleared() bool { + return m.clearedcredit_allocations } -// RunID returns the value of the "run_id" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) RunID() (r string, exists bool) { - v := m.run - if v == nil { - return +// RemoveCreditAllocationIDs removes the "credit_allocations" edge to the ChargeFlatFeeRunCreditAllocations entity by IDs. +func (m *ChargeFlatFeeRunMutation) RemoveCreditAllocationIDs(ids ...string) { + if m.removedcredit_allocations == nil { + m.removedcredit_allocations = make(map[string]struct{}) + } + for i := range ids { + delete(m.credit_allocations, ids[i]) + m.removedcredit_allocations[ids[i]] = struct{}{} } - return *v, true } -// OldRunID returns the old "run_id" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldRunID(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldRunID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldRunID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldRunID: %w", err) +// RemovedCreditAllocations returns the removed IDs of the "credit_allocations" edge to the ChargeFlatFeeRunCreditAllocations entity. +func (m *ChargeFlatFeeRunMutation) RemovedCreditAllocationsIDs() (ids []string) { + for id := range m.removedcredit_allocations { + ids = append(ids, id) } - return oldValue.RunID, nil + return } -// ResetRunID resets all changes to the "run_id" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetRunID() { - m.run = nil +// CreditAllocationsIDs returns the "credit_allocations" edge IDs in the mutation. +func (m *ChargeFlatFeeRunMutation) CreditAllocationsIDs() (ids []string) { + for id := range m.credit_allocations { + ids = append(ids, id) + } + return } -// SetPricerReferenceID sets the "pricer_reference_id" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetPricerReferenceID(s string) { - m.pricer_reference_id = &s +// ResetCreditAllocations resets all changes to the "credit_allocations" edge. +func (m *ChargeFlatFeeRunMutation) ResetCreditAllocations() { + m.credit_allocations = nil + m.clearedcredit_allocations = false + m.removedcredit_allocations = nil } -// PricerReferenceID returns the value of the "pricer_reference_id" field in the mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) PricerReferenceID() (r string, exists bool) { - v := m.pricer_reference_id - if v == nil { - return +// AddDetailedLineIDs adds the "detailed_lines" edge to the ChargeFlatFeeRunDetailedLine entity by ids. +func (m *ChargeFlatFeeRunMutation) AddDetailedLineIDs(ids ...string) { + if m.detailed_lines == nil { + m.detailed_lines = make(map[string]struct{}) + } + for i := range ids { + m.detailed_lines[ids[i]] = struct{}{} } - return *v, true } -// OldPricerReferenceID returns the old "pricer_reference_id" field's value of the ChargeFlatFeeRunDetailedLine entity. -// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldPricerReferenceID(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldPricerReferenceID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldPricerReferenceID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldPricerReferenceID: %w", err) - } - return oldValue.PricerReferenceID, nil +// ClearDetailedLines clears the "detailed_lines" edge to the ChargeFlatFeeRunDetailedLine entity. +func (m *ChargeFlatFeeRunMutation) ClearDetailedLines() { + m.cleareddetailed_lines = true } -// ResetPricerReferenceID resets all changes to the "pricer_reference_id" field. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetPricerReferenceID() { - m.pricer_reference_id = nil +// DetailedLinesCleared reports if the "detailed_lines" edge to the ChargeFlatFeeRunDetailedLine entity was cleared. +func (m *ChargeFlatFeeRunMutation) DetailedLinesCleared() bool { + return m.cleareddetailed_lines } -// ClearRun clears the "run" edge to the ChargeFlatFeeRun entity. -func (m *ChargeFlatFeeRunDetailedLineMutation) ClearRun() { - m.clearedrun = true - m.clearedFields[chargeflatfeerundetailedline.FieldRunID] = struct{}{} +// RemoveDetailedLineIDs removes the "detailed_lines" edge to the ChargeFlatFeeRunDetailedLine entity by IDs. +func (m *ChargeFlatFeeRunMutation) RemoveDetailedLineIDs(ids ...string) { + if m.removeddetailed_lines == nil { + m.removeddetailed_lines = make(map[string]struct{}) + } + for i := range ids { + delete(m.detailed_lines, ids[i]) + m.removeddetailed_lines[ids[i]] = struct{}{} + } } -// RunCleared reports if the "run" edge to the ChargeFlatFeeRun entity was cleared. -func (m *ChargeFlatFeeRunDetailedLineMutation) RunCleared() bool { - return m.clearedrun +// RemovedDetailedLines returns the removed IDs of the "detailed_lines" edge to the ChargeFlatFeeRunDetailedLine entity. +func (m *ChargeFlatFeeRunMutation) RemovedDetailedLinesIDs() (ids []string) { + for id := range m.removeddetailed_lines { + ids = append(ids, id) + } + return } -// RunIDs returns the "run" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// RunID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeRunDetailedLineMutation) RunIDs() (ids []string) { - if id := m.run; id != nil { - ids = append(ids, *id) +// DetailedLinesIDs returns the "detailed_lines" edge IDs in the mutation. +func (m *ChargeFlatFeeRunMutation) DetailedLinesIDs() (ids []string) { + for id := range m.detailed_lines { + ids = append(ids, id) } return } -// ResetRun resets all changes to the "run" edge. -func (m *ChargeFlatFeeRunDetailedLineMutation) ResetRun() { - m.run = nil - m.clearedrun = false +// ResetDetailedLines resets all changes to the "detailed_lines" edge. +func (m *ChargeFlatFeeRunMutation) ResetDetailedLines() { + m.detailed_lines = nil + m.cleareddetailed_lines = false + m.removeddetailed_lines = nil } -// Where appends a list predicates to the ChargeFlatFeeRunDetailedLineMutation builder. -func (m *ChargeFlatFeeRunDetailedLineMutation) Where(ps ...predicate.ChargeFlatFeeRunDetailedLine) { - m.predicates = append(m.predicates, ps...) +// SetInvoicedUsageID sets the "invoiced_usage" edge to the ChargeFlatFeeRunInvoicedUsage entity by id. +func (m *ChargeFlatFeeRunMutation) SetInvoicedUsageID(id string) { + m.invoiced_usage = &id } -// WhereP appends storage-level predicates to the ChargeFlatFeeRunDetailedLineMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *ChargeFlatFeeRunDetailedLineMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.ChargeFlatFeeRunDetailedLine, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) +// ClearInvoicedUsage clears the "invoiced_usage" edge to the ChargeFlatFeeRunInvoicedUsage entity. +func (m *ChargeFlatFeeRunMutation) ClearInvoicedUsage() { + m.clearedinvoiced_usage = true } -// Op returns the operation name. -func (m *ChargeFlatFeeRunDetailedLineMutation) Op() Op { +// InvoicedUsageCleared reports if the "invoiced_usage" edge to the ChargeFlatFeeRunInvoicedUsage entity was cleared. +func (m *ChargeFlatFeeRunMutation) InvoicedUsageCleared() bool { + return m.clearedinvoiced_usage +} + +// InvoicedUsageID returns the "invoiced_usage" edge ID in the mutation. +func (m *ChargeFlatFeeRunMutation) InvoicedUsageID() (id string, exists bool) { + if m.invoiced_usage != nil { + return *m.invoiced_usage, true + } + return +} + +// InvoicedUsageIDs returns the "invoiced_usage" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// InvoicedUsageID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeRunMutation) InvoicedUsageIDs() (ids []string) { + if id := m.invoiced_usage; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetInvoicedUsage resets all changes to the "invoiced_usage" edge. +func (m *ChargeFlatFeeRunMutation) ResetInvoicedUsage() { + m.invoiced_usage = nil + m.clearedinvoiced_usage = false +} + +// SetPaymentID sets the "payment" edge to the ChargeFlatFeeRunPayment entity by id. +func (m *ChargeFlatFeeRunMutation) SetPaymentID(id string) { + m.payment = &id +} + +// ClearPayment clears the "payment" edge to the ChargeFlatFeeRunPayment entity. +func (m *ChargeFlatFeeRunMutation) ClearPayment() { + m.clearedpayment = true +} + +// PaymentCleared reports if the "payment" edge to the ChargeFlatFeeRunPayment entity was cleared. +func (m *ChargeFlatFeeRunMutation) PaymentCleared() bool { + return m.clearedpayment +} + +// PaymentID returns the "payment" edge ID in the mutation. +func (m *ChargeFlatFeeRunMutation) PaymentID() (id string, exists bool) { + if m.payment != nil { + return *m.payment, true + } + return +} + +// PaymentIDs returns the "payment" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// PaymentID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeRunMutation) PaymentIDs() (ids []string) { + if id := m.payment; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetPayment resets all changes to the "payment" edge. +func (m *ChargeFlatFeeRunMutation) ResetPayment() { + m.payment = nil + m.clearedpayment = false +} + +// Where appends a list predicates to the ChargeFlatFeeRunMutation builder. +func (m *ChargeFlatFeeRunMutation) Where(ps ...predicate.ChargeFlatFeeRun) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the ChargeFlatFeeRunMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ChargeFlatFeeRunMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeFlatFeeRun, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *ChargeFlatFeeRunMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. -func (m *ChargeFlatFeeRunDetailedLineMutation) SetOp(op Op) { +func (m *ChargeFlatFeeRunMutation) SetOp(op Op) { m.op = op } -// Type returns the node type of this mutation (ChargeFlatFeeRunDetailedLine). -func (m *ChargeFlatFeeRunDetailedLineMutation) Type() string { +// Type returns the node type of this mutation (ChargeFlatFeeRun). +func (m *ChargeFlatFeeRunMutation) 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 *ChargeFlatFeeRunDetailedLineMutation) Fields() []string { - fields := make([]string, 0, 29) - if m.currency != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldCurrency) - } - if m.service_period_start != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldServicePeriodStart) - } - if m.service_period_end != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldServicePeriodEnd) - } - if m.quantity != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldQuantity) - } - if m.invoicing_app_external_id != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldInvoicingAppExternalID) - } - if m.child_unique_reference_id != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldChildUniqueReferenceID) - } - if m.per_unit_amount != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldPerUnitAmount) - } - if m.category != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldCategory) - } - if m.payment_term != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldPaymentTerm) - } - if m.index != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldIndex) - } - if m.credits_applied != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldCreditsApplied) - } - if m.annotations != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldAnnotations) - } +func (m *ChargeFlatFeeRunMutation) Fields() []string { + fields := make([]string, 0, 22) if m.namespace != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldNamespace) - } - if m.metadata != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldMetadata) + fields = append(fields, chargeflatfeerun.FieldNamespace) } if m.created_at != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldCreatedAt) + fields = append(fields, chargeflatfeerun.FieldCreatedAt) } if m.updated_at != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldUpdatedAt) + fields = append(fields, chargeflatfeerun.FieldUpdatedAt) } if m.deleted_at != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldDeletedAt) - } - if m.name != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldName) - } - if m.description != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldDescription) + fields = append(fields, chargeflatfeerun.FieldDeletedAt) } if m.amount != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldAmount) + fields = append(fields, chargeflatfeerun.FieldAmount) } if m.taxes_total != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldTaxesTotal) + fields = append(fields, chargeflatfeerun.FieldTaxesTotal) } if m.taxes_inclusive_total != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldTaxesInclusiveTotal) + fields = append(fields, chargeflatfeerun.FieldTaxesInclusiveTotal) } if m.taxes_exclusive_total != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldTaxesExclusiveTotal) + fields = append(fields, chargeflatfeerun.FieldTaxesExclusiveTotal) } if m.charges_total != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldChargesTotal) + fields = append(fields, chargeflatfeerun.FieldChargesTotal) } if m.discounts_total != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldDiscountsTotal) + fields = append(fields, chargeflatfeerun.FieldDiscountsTotal) } if m.credits_total != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldCreditsTotal) + fields = append(fields, chargeflatfeerun.FieldCreditsTotal) } if m.total != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldTotal) + fields = append(fields, chargeflatfeerun.FieldTotal) } - if m.run != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldRunID) + if m.flat_fee != nil { + fields = append(fields, chargeflatfeerun.FieldChargeID) } - if m.pricer_reference_id != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldPricerReferenceID) + if m._type != nil { + fields = append(fields, chargeflatfeerun.FieldType) + } + if m.initial_type != nil { + fields = append(fields, chargeflatfeerun.FieldInitialType) + } + if m.service_period_from != nil { + fields = append(fields, chargeflatfeerun.FieldServicePeriodFrom) + } + if m.service_period_to != nil { + fields = append(fields, chargeflatfeerun.FieldServicePeriodTo) + } + if m.billing_invoice_line != nil { + fields = append(fields, chargeflatfeerun.FieldLineID) + } + if m.billing_invoice != nil { + fields = append(fields, chargeflatfeerun.FieldInvoiceID) + } + if m.amount_after_proration != nil { + fields = append(fields, chargeflatfeerun.FieldAmountAfterProration) + } + if m.no_fiat_transaction_required != nil { + fields = append(fields, chargeflatfeerun.FieldNoFiatTransactionRequired) + } + if m.immutable != nil { + fields = append(fields, chargeflatfeerun.FieldImmutable) } return fields } @@ -55478,66 +54674,52 @@ func (m *ChargeFlatFeeRunDetailedLineMutation) Fields() []string { // 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 *ChargeFlatFeeRunDetailedLineMutation) Field(name string) (ent.Value, bool) { +func (m *ChargeFlatFeeRunMutation) Field(name string) (ent.Value, bool) { switch name { - case chargeflatfeerundetailedline.FieldCurrency: - return m.Currency() - case chargeflatfeerundetailedline.FieldServicePeriodStart: - return m.ServicePeriodStart() - case chargeflatfeerundetailedline.FieldServicePeriodEnd: - return m.ServicePeriodEnd() - case chargeflatfeerundetailedline.FieldQuantity: - return m.Quantity() - case chargeflatfeerundetailedline.FieldInvoicingAppExternalID: - return m.InvoicingAppExternalID() - case chargeflatfeerundetailedline.FieldChildUniqueReferenceID: - return m.ChildUniqueReferenceID() - case chargeflatfeerundetailedline.FieldPerUnitAmount: - return m.PerUnitAmount() - case chargeflatfeerundetailedline.FieldCategory: - return m.Category() - case chargeflatfeerundetailedline.FieldPaymentTerm: - return m.PaymentTerm() - case chargeflatfeerundetailedline.FieldIndex: - return m.Index() - case chargeflatfeerundetailedline.FieldCreditsApplied: - return m.CreditsApplied() - case chargeflatfeerundetailedline.FieldAnnotations: - return m.Annotations() - case chargeflatfeerundetailedline.FieldNamespace: + case chargeflatfeerun.FieldNamespace: return m.Namespace() - case chargeflatfeerundetailedline.FieldMetadata: - return m.Metadata() - case chargeflatfeerundetailedline.FieldCreatedAt: + case chargeflatfeerun.FieldCreatedAt: return m.CreatedAt() - case chargeflatfeerundetailedline.FieldUpdatedAt: + case chargeflatfeerun.FieldUpdatedAt: return m.UpdatedAt() - case chargeflatfeerundetailedline.FieldDeletedAt: + case chargeflatfeerun.FieldDeletedAt: return m.DeletedAt() - case chargeflatfeerundetailedline.FieldName: - return m.Name() - case chargeflatfeerundetailedline.FieldDescription: - return m.Description() - case chargeflatfeerundetailedline.FieldAmount: + case chargeflatfeerun.FieldAmount: return m.Amount() - case chargeflatfeerundetailedline.FieldTaxesTotal: + case chargeflatfeerun.FieldTaxesTotal: return m.TaxesTotal() - case chargeflatfeerundetailedline.FieldTaxesInclusiveTotal: + case chargeflatfeerun.FieldTaxesInclusiveTotal: return m.TaxesInclusiveTotal() - case chargeflatfeerundetailedline.FieldTaxesExclusiveTotal: + case chargeflatfeerun.FieldTaxesExclusiveTotal: return m.TaxesExclusiveTotal() - case chargeflatfeerundetailedline.FieldChargesTotal: + case chargeflatfeerun.FieldChargesTotal: return m.ChargesTotal() - case chargeflatfeerundetailedline.FieldDiscountsTotal: + case chargeflatfeerun.FieldDiscountsTotal: return m.DiscountsTotal() - case chargeflatfeerundetailedline.FieldCreditsTotal: + case chargeflatfeerun.FieldCreditsTotal: return m.CreditsTotal() - case chargeflatfeerundetailedline.FieldTotal: + case chargeflatfeerun.FieldTotal: return m.Total() - case chargeflatfeerundetailedline.FieldRunID: - return m.RunID() - case chargeflatfeerundetailedline.FieldPricerReferenceID: - return m.PricerReferenceID() + case chargeflatfeerun.FieldChargeID: + return m.ChargeID() + case chargeflatfeerun.FieldType: + return m.GetType() + case chargeflatfeerun.FieldInitialType: + return m.InitialType() + case chargeflatfeerun.FieldServicePeriodFrom: + return m.ServicePeriodFrom() + case chargeflatfeerun.FieldServicePeriodTo: + return m.ServicePeriodTo() + case chargeflatfeerun.FieldLineID: + return m.LineID() + case chargeflatfeerun.FieldInvoiceID: + return m.InvoiceID() + case chargeflatfeerun.FieldAmountAfterProration: + return m.AmountAfterProration() + case chargeflatfeerun.FieldNoFiatTransactionRequired: + return m.NoFiatTransactionRequired() + case chargeflatfeerun.FieldImmutable: + return m.Immutable() } return nil, false } @@ -55545,499 +54727,416 @@ func (m *ChargeFlatFeeRunDetailedLineMutation) Field(name string) (ent.Value, bo // 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 *ChargeFlatFeeRunDetailedLineMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *ChargeFlatFeeRunMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case chargeflatfeerundetailedline.FieldCurrency: - return m.OldCurrency(ctx) - case chargeflatfeerundetailedline.FieldServicePeriodStart: - return m.OldServicePeriodStart(ctx) - case chargeflatfeerundetailedline.FieldServicePeriodEnd: - return m.OldServicePeriodEnd(ctx) - case chargeflatfeerundetailedline.FieldQuantity: - return m.OldQuantity(ctx) - case chargeflatfeerundetailedline.FieldInvoicingAppExternalID: - return m.OldInvoicingAppExternalID(ctx) - case chargeflatfeerundetailedline.FieldChildUniqueReferenceID: - return m.OldChildUniqueReferenceID(ctx) - case chargeflatfeerundetailedline.FieldPerUnitAmount: - return m.OldPerUnitAmount(ctx) - case chargeflatfeerundetailedline.FieldCategory: - return m.OldCategory(ctx) - case chargeflatfeerundetailedline.FieldPaymentTerm: - return m.OldPaymentTerm(ctx) - case chargeflatfeerundetailedline.FieldIndex: - return m.OldIndex(ctx) - case chargeflatfeerundetailedline.FieldCreditsApplied: - return m.OldCreditsApplied(ctx) - case chargeflatfeerundetailedline.FieldAnnotations: - return m.OldAnnotations(ctx) - case chargeflatfeerundetailedline.FieldNamespace: + case chargeflatfeerun.FieldNamespace: return m.OldNamespace(ctx) - case chargeflatfeerundetailedline.FieldMetadata: - return m.OldMetadata(ctx) - case chargeflatfeerundetailedline.FieldCreatedAt: + case chargeflatfeerun.FieldCreatedAt: return m.OldCreatedAt(ctx) - case chargeflatfeerundetailedline.FieldUpdatedAt: + case chargeflatfeerun.FieldUpdatedAt: return m.OldUpdatedAt(ctx) - case chargeflatfeerundetailedline.FieldDeletedAt: + case chargeflatfeerun.FieldDeletedAt: return m.OldDeletedAt(ctx) - case chargeflatfeerundetailedline.FieldName: - return m.OldName(ctx) - case chargeflatfeerundetailedline.FieldDescription: - return m.OldDescription(ctx) - case chargeflatfeerundetailedline.FieldAmount: + case chargeflatfeerun.FieldAmount: return m.OldAmount(ctx) - case chargeflatfeerundetailedline.FieldTaxesTotal: + case chargeflatfeerun.FieldTaxesTotal: return m.OldTaxesTotal(ctx) - case chargeflatfeerundetailedline.FieldTaxesInclusiveTotal: + case chargeflatfeerun.FieldTaxesInclusiveTotal: return m.OldTaxesInclusiveTotal(ctx) - case chargeflatfeerundetailedline.FieldTaxesExclusiveTotal: + case chargeflatfeerun.FieldTaxesExclusiveTotal: return m.OldTaxesExclusiveTotal(ctx) - case chargeflatfeerundetailedline.FieldChargesTotal: + case chargeflatfeerun.FieldChargesTotal: return m.OldChargesTotal(ctx) - case chargeflatfeerundetailedline.FieldDiscountsTotal: + case chargeflatfeerun.FieldDiscountsTotal: return m.OldDiscountsTotal(ctx) - case chargeflatfeerundetailedline.FieldCreditsTotal: + case chargeflatfeerun.FieldCreditsTotal: return m.OldCreditsTotal(ctx) - case chargeflatfeerundetailedline.FieldTotal: + case chargeflatfeerun.FieldTotal: return m.OldTotal(ctx) - case chargeflatfeerundetailedline.FieldRunID: - return m.OldRunID(ctx) - case chargeflatfeerundetailedline.FieldPricerReferenceID: - return m.OldPricerReferenceID(ctx) + case chargeflatfeerun.FieldChargeID: + return m.OldChargeID(ctx) + case chargeflatfeerun.FieldType: + return m.OldType(ctx) + case chargeflatfeerun.FieldInitialType: + return m.OldInitialType(ctx) + case chargeflatfeerun.FieldServicePeriodFrom: + return m.OldServicePeriodFrom(ctx) + case chargeflatfeerun.FieldServicePeriodTo: + return m.OldServicePeriodTo(ctx) + case chargeflatfeerun.FieldLineID: + return m.OldLineID(ctx) + case chargeflatfeerun.FieldInvoiceID: + return m.OldInvoiceID(ctx) + case chargeflatfeerun.FieldAmountAfterProration: + return m.OldAmountAfterProration(ctx) + case chargeflatfeerun.FieldNoFiatTransactionRequired: + return m.OldNoFiatTransactionRequired(ctx) + case chargeflatfeerun.FieldImmutable: + return m.OldImmutable(ctx) } - return nil, fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine field %s", name) + return nil, fmt.Errorf("unknown ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) SetField(name string, value ent.Value) error { +func (m *ChargeFlatFeeRunMutation) SetField(name string, value ent.Value) error { switch name { - case chargeflatfeerundetailedline.FieldCurrency: - v, ok := value.(currencyx.Code) + case chargeflatfeerun.FieldNamespace: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCurrency(v) + m.SetNamespace(v) return nil - case chargeflatfeerundetailedline.FieldServicePeriodStart: + case chargeflatfeerun.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetServicePeriodStart(v) + m.SetCreatedAt(v) return nil - case chargeflatfeerundetailedline.FieldServicePeriodEnd: + case chargeflatfeerun.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetServicePeriodEnd(v) + m.SetUpdatedAt(v) return nil - case chargeflatfeerundetailedline.FieldQuantity: - v, ok := value.(alpacadecimal.Decimal) + case chargeflatfeerun.FieldDeletedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetQuantity(v) + m.SetDeletedAt(v) return nil - case chargeflatfeerundetailedline.FieldInvoicingAppExternalID: - v, ok := value.(string) + case chargeflatfeerun.FieldAmount: + v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetInvoicingAppExternalID(v) + m.SetAmount(v) return nil - case chargeflatfeerundetailedline.FieldChildUniqueReferenceID: - v, ok := value.(string) + case chargeflatfeerun.FieldTaxesTotal: + v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetChildUniqueReferenceID(v) + m.SetTaxesTotal(v) return nil - case chargeflatfeerundetailedline.FieldPerUnitAmount: + case chargeflatfeerun.FieldTaxesInclusiveTotal: v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetPerUnitAmount(v) + m.SetTaxesInclusiveTotal(v) return nil - case chargeflatfeerundetailedline.FieldCategory: - v, ok := value.(stddetailedline.Category) + case chargeflatfeerun.FieldTaxesExclusiveTotal: + v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCategory(v) + m.SetTaxesExclusiveTotal(v) return nil - case chargeflatfeerundetailedline.FieldPaymentTerm: - v, ok := value.(productcatalog.PaymentTermType) + case chargeflatfeerun.FieldChargesTotal: + v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetPaymentTerm(v) + m.SetChargesTotal(v) return nil - case chargeflatfeerundetailedline.FieldIndex: - v, ok := value.(int) + case chargeflatfeerun.FieldDiscountsTotal: + v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetIndex(v) + m.SetDiscountsTotal(v) return nil - case chargeflatfeerundetailedline.FieldCreditsApplied: - v, ok := value.(*creditsapplied.CreditsApplied) + case chargeflatfeerun.FieldCreditsTotal: + v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCreditsApplied(v) + m.SetCreditsTotal(v) return nil - case chargeflatfeerundetailedline.FieldAnnotations: - v, ok := value.(models.Annotations) + case chargeflatfeerun.FieldTotal: + v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetAnnotations(v) + m.SetTotal(v) return nil - case chargeflatfeerundetailedline.FieldNamespace: + case chargeflatfeerun.FieldChargeID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetNamespace(v) + m.SetChargeID(v) return nil - case chargeflatfeerundetailedline.FieldMetadata: - v, ok := value.(map[string]string) + case chargeflatfeerun.FieldType: + v, ok := value.(flatfee.RealizationRunType) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetMetadata(v) + m.SetType(v) return nil - case chargeflatfeerundetailedline.FieldCreatedAt: - v, ok := value.(time.Time) + case chargeflatfeerun.FieldInitialType: + v, ok := value.(flatfee.RealizationRunType) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCreatedAt(v) + m.SetInitialType(v) return nil - case chargeflatfeerundetailedline.FieldUpdatedAt: + case chargeflatfeerun.FieldServicePeriodFrom: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetUpdatedAt(v) + m.SetServicePeriodFrom(v) return nil - case chargeflatfeerundetailedline.FieldDeletedAt: + case chargeflatfeerun.FieldServicePeriodTo: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDeletedAt(v) + m.SetServicePeriodTo(v) return nil - case chargeflatfeerundetailedline.FieldName: + case chargeflatfeerun.FieldLineID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetName(v) + m.SetLineID(v) return nil - case chargeflatfeerundetailedline.FieldDescription: + case chargeflatfeerun.FieldInvoiceID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDescription(v) - return nil - case chargeflatfeerundetailedline.FieldAmount: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetAmount(v) - return nil - case chargeflatfeerundetailedline.FieldTaxesTotal: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetTaxesTotal(v) - return nil - case chargeflatfeerundetailedline.FieldTaxesInclusiveTotal: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetTaxesInclusiveTotal(v) - return nil - case chargeflatfeerundetailedline.FieldTaxesExclusiveTotal: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetTaxesExclusiveTotal(v) - return nil - case chargeflatfeerundetailedline.FieldChargesTotal: - v, ok := value.(alpacadecimal.Decimal) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetChargesTotal(v) + m.SetInvoiceID(v) return nil - case chargeflatfeerundetailedline.FieldDiscountsTotal: + case chargeflatfeerun.FieldAmountAfterProration: v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDiscountsTotal(v) + m.SetAmountAfterProration(v) return nil - case chargeflatfeerundetailedline.FieldCreditsTotal: - v, ok := value.(alpacadecimal.Decimal) + case chargeflatfeerun.FieldNoFiatTransactionRequired: + v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCreditsTotal(v) + m.SetNoFiatTransactionRequired(v) return nil - case chargeflatfeerundetailedline.FieldTotal: - v, ok := value.(alpacadecimal.Decimal) + case chargeflatfeerun.FieldImmutable: + v, ok := value.(bool) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetTotal(v) - return nil - case chargeflatfeerundetailedline.FieldRunID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetRunID(v) - return nil - case chargeflatfeerundetailedline.FieldPricerReferenceID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetPricerReferenceID(v) + m.SetImmutable(v) return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRun field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) AddedFields() []string { - var fields []string - if m.addindex != nil { - fields = append(fields, chargeflatfeerundetailedline.FieldIndex) - } - return fields +func (m *ChargeFlatFeeRunMutation) 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 *ChargeFlatFeeRunDetailedLineMutation) AddedField(name string) (ent.Value, bool) { - switch name { - case chargeflatfeerundetailedline.FieldIndex: - return m.AddedIndex() - } +func (m *ChargeFlatFeeRunMutation) 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 *ChargeFlatFeeRunDetailedLineMutation) AddField(name string, value ent.Value) error { +func (m *ChargeFlatFeeRunMutation) AddField(name string, value ent.Value) error { switch name { - case chargeflatfeerundetailedline.FieldIndex: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.AddIndex(v) - return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine numeric field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRun numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) ClearedFields() []string { +func (m *ChargeFlatFeeRunMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(chargeflatfeerundetailedline.FieldCurrency) { - fields = append(fields, chargeflatfeerundetailedline.FieldCurrency) - } - if m.FieldCleared(chargeflatfeerundetailedline.FieldInvoicingAppExternalID) { - fields = append(fields, chargeflatfeerundetailedline.FieldInvoicingAppExternalID) - } - if m.FieldCleared(chargeflatfeerundetailedline.FieldIndex) { - fields = append(fields, chargeflatfeerundetailedline.FieldIndex) - } - if m.FieldCleared(chargeflatfeerundetailedline.FieldCreditsApplied) { - fields = append(fields, chargeflatfeerundetailedline.FieldCreditsApplied) - } - if m.FieldCleared(chargeflatfeerundetailedline.FieldAnnotations) { - fields = append(fields, chargeflatfeerundetailedline.FieldAnnotations) - } - if m.FieldCleared(chargeflatfeerundetailedline.FieldMetadata) { - fields = append(fields, chargeflatfeerundetailedline.FieldMetadata) + if m.FieldCleared(chargeflatfeerun.FieldDeletedAt) { + fields = append(fields, chargeflatfeerun.FieldDeletedAt) } - if m.FieldCleared(chargeflatfeerundetailedline.FieldDeletedAt) { - fields = append(fields, chargeflatfeerundetailedline.FieldDeletedAt) + if m.FieldCleared(chargeflatfeerun.FieldLineID) { + fields = append(fields, chargeflatfeerun.FieldLineID) } - if m.FieldCleared(chargeflatfeerundetailedline.FieldDescription) { - fields = append(fields, chargeflatfeerundetailedline.FieldDescription) + if m.FieldCleared(chargeflatfeerun.FieldInvoiceID) { + fields = append(fields, chargeflatfeerun.FieldInvoiceID) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) FieldCleared(name string) bool { +func (m *ChargeFlatFeeRunMutation) 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 *ChargeFlatFeeRunDetailedLineMutation) ClearField(name string) error { +func (m *ChargeFlatFeeRunMutation) ClearField(name string) error { switch name { - case chargeflatfeerundetailedline.FieldCurrency: - m.ClearCurrency() - return nil - case chargeflatfeerundetailedline.FieldInvoicingAppExternalID: - m.ClearInvoicingAppExternalID() - return nil - case chargeflatfeerundetailedline.FieldIndex: - m.ClearIndex() - return nil - case chargeflatfeerundetailedline.FieldCreditsApplied: - m.ClearCreditsApplied() - return nil - case chargeflatfeerundetailedline.FieldAnnotations: - m.ClearAnnotations() - return nil - case chargeflatfeerundetailedline.FieldMetadata: - m.ClearMetadata() - return nil - case chargeflatfeerundetailedline.FieldDeletedAt: + case chargeflatfeerun.FieldDeletedAt: m.ClearDeletedAt() return nil - case chargeflatfeerundetailedline.FieldDescription: - m.ClearDescription() + case chargeflatfeerun.FieldLineID: + m.ClearLineID() + return nil + case chargeflatfeerun.FieldInvoiceID: + m.ClearInvoiceID() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine nullable field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) ResetField(name string) error { +func (m *ChargeFlatFeeRunMutation) ResetField(name string) error { switch name { - case chargeflatfeerundetailedline.FieldCurrency: - m.ResetCurrency() - return nil - case chargeflatfeerundetailedline.FieldServicePeriodStart: - m.ResetServicePeriodStart() - return nil - case chargeflatfeerundetailedline.FieldServicePeriodEnd: - m.ResetServicePeriodEnd() - return nil - case chargeflatfeerundetailedline.FieldQuantity: - m.ResetQuantity() - return nil - case chargeflatfeerundetailedline.FieldInvoicingAppExternalID: - m.ResetInvoicingAppExternalID() - return nil - case chargeflatfeerundetailedline.FieldChildUniqueReferenceID: - m.ResetChildUniqueReferenceID() - return nil - case chargeflatfeerundetailedline.FieldPerUnitAmount: - m.ResetPerUnitAmount() - return nil - case chargeflatfeerundetailedline.FieldCategory: - m.ResetCategory() - return nil - case chargeflatfeerundetailedline.FieldPaymentTerm: - m.ResetPaymentTerm() - return nil - case chargeflatfeerundetailedline.FieldIndex: - m.ResetIndex() - return nil - case chargeflatfeerundetailedline.FieldCreditsApplied: - m.ResetCreditsApplied() - return nil - case chargeflatfeerundetailedline.FieldAnnotations: - m.ResetAnnotations() - return nil - case chargeflatfeerundetailedline.FieldNamespace: + case chargeflatfeerun.FieldNamespace: m.ResetNamespace() return nil - case chargeflatfeerundetailedline.FieldMetadata: - m.ResetMetadata() - return nil - case chargeflatfeerundetailedline.FieldCreatedAt: + case chargeflatfeerun.FieldCreatedAt: m.ResetCreatedAt() return nil - case chargeflatfeerundetailedline.FieldUpdatedAt: + case chargeflatfeerun.FieldUpdatedAt: m.ResetUpdatedAt() return nil - case chargeflatfeerundetailedline.FieldDeletedAt: + case chargeflatfeerun.FieldDeletedAt: m.ResetDeletedAt() return nil - case chargeflatfeerundetailedline.FieldName: - m.ResetName() - return nil - case chargeflatfeerundetailedline.FieldDescription: - m.ResetDescription() - return nil - case chargeflatfeerundetailedline.FieldAmount: + case chargeflatfeerun.FieldAmount: m.ResetAmount() return nil - case chargeflatfeerundetailedline.FieldTaxesTotal: + case chargeflatfeerun.FieldTaxesTotal: m.ResetTaxesTotal() return nil - case chargeflatfeerundetailedline.FieldTaxesInclusiveTotal: + case chargeflatfeerun.FieldTaxesInclusiveTotal: m.ResetTaxesInclusiveTotal() return nil - case chargeflatfeerundetailedline.FieldTaxesExclusiveTotal: + case chargeflatfeerun.FieldTaxesExclusiveTotal: m.ResetTaxesExclusiveTotal() return nil - case chargeflatfeerundetailedline.FieldChargesTotal: + case chargeflatfeerun.FieldChargesTotal: m.ResetChargesTotal() return nil - case chargeflatfeerundetailedline.FieldDiscountsTotal: + case chargeflatfeerun.FieldDiscountsTotal: m.ResetDiscountsTotal() return nil - case chargeflatfeerundetailedline.FieldCreditsTotal: + case chargeflatfeerun.FieldCreditsTotal: m.ResetCreditsTotal() return nil - case chargeflatfeerundetailedline.FieldTotal: + case chargeflatfeerun.FieldTotal: m.ResetTotal() return nil - case chargeflatfeerundetailedline.FieldRunID: - m.ResetRunID() + case chargeflatfeerun.FieldChargeID: + m.ResetChargeID() return nil - case chargeflatfeerundetailedline.FieldPricerReferenceID: - m.ResetPricerReferenceID() + case chargeflatfeerun.FieldType: + m.ResetType() + return nil + case chargeflatfeerun.FieldInitialType: + m.ResetInitialType() + return nil + case chargeflatfeerun.FieldServicePeriodFrom: + m.ResetServicePeriodFrom() + return nil + case chargeflatfeerun.FieldServicePeriodTo: + m.ResetServicePeriodTo() + return nil + case chargeflatfeerun.FieldLineID: + m.ResetLineID() + return nil + case chargeflatfeerun.FieldInvoiceID: + m.ResetInvoiceID() + return nil + case chargeflatfeerun.FieldAmountAfterProration: + m.ResetAmountAfterProration() + return nil + case chargeflatfeerun.FieldNoFiatTransactionRequired: + m.ResetNoFiatTransactionRequired() + return nil + case chargeflatfeerun.FieldImmutable: + m.ResetImmutable() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRun field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) AddedEdges() []string { - edges := make([]string, 0, 1) - if m.run != nil { - edges = append(edges, chargeflatfeerundetailedline.EdgeRun) +func (m *ChargeFlatFeeRunMutation) AddedEdges() []string { + edges := make([]string, 0, 7) + if m.flat_fee != nil { + edges = append(edges, chargeflatfeerun.EdgeFlatFee) + } + if m.billing_invoice_line != nil { + edges = append(edges, chargeflatfeerun.EdgeBillingInvoiceLine) + } + if m.billing_invoice != nil { + edges = append(edges, chargeflatfeerun.EdgeBillingInvoice) + } + if m.credit_allocations != nil { + edges = append(edges, chargeflatfeerun.EdgeCreditAllocations) + } + if m.detailed_lines != nil { + edges = append(edges, chargeflatfeerun.EdgeDetailedLines) + } + if m.invoiced_usage != nil { + edges = append(edges, chargeflatfeerun.EdgeInvoicedUsage) + } + if m.payment != nil { + edges = append(edges, chargeflatfeerun.EdgePayment) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) AddedIDs(name string) []ent.Value { +func (m *ChargeFlatFeeRunMutation) AddedIDs(name string) []ent.Value { switch name { - case chargeflatfeerundetailedline.EdgeRun: - if id := m.run; id != nil { + case chargeflatfeerun.EdgeFlatFee: + if id := m.flat_fee; id != nil { + return []ent.Value{*id} + } + case chargeflatfeerun.EdgeBillingInvoiceLine: + if id := m.billing_invoice_line; id != nil { + return []ent.Value{*id} + } + case chargeflatfeerun.EdgeBillingInvoice: + if id := m.billing_invoice; id != nil { + return []ent.Value{*id} + } + case chargeflatfeerun.EdgeCreditAllocations: + ids := make([]ent.Value, 0, len(m.credit_allocations)) + for id := range m.credit_allocations { + ids = append(ids, id) + } + return ids + case chargeflatfeerun.EdgeDetailedLines: + ids := make([]ent.Value, 0, len(m.detailed_lines)) + for id := range m.detailed_lines { + ids = append(ids, id) + } + return ids + case chargeflatfeerun.EdgeInvoicedUsage: + if id := m.invoiced_usage; id != nil { + return []ent.Value{*id} + } + case chargeflatfeerun.EdgePayment: + if id := m.payment; id != nil { return []ent.Value{*id} } } @@ -56045,99 +55144,182 @@ func (m *ChargeFlatFeeRunDetailedLineMutation) AddedIDs(name string) []ent.Value } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) +func (m *ChargeFlatFeeRunMutation) RemovedEdges() []string { + edges := make([]string, 0, 7) + if m.removedcredit_allocations != nil { + edges = append(edges, chargeflatfeerun.EdgeCreditAllocations) + } + if m.removeddetailed_lines != nil { + edges = append(edges, chargeflatfeerun.EdgeDetailedLines) + } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) RemovedIDs(name string) []ent.Value { +func (m *ChargeFlatFeeRunMutation) RemovedIDs(name string) []ent.Value { + switch name { + case chargeflatfeerun.EdgeCreditAllocations: + ids := make([]ent.Value, 0, len(m.removedcredit_allocations)) + for id := range m.removedcredit_allocations { + ids = append(ids, id) + } + return ids + case chargeflatfeerun.EdgeDetailedLines: + ids := make([]ent.Value, 0, len(m.removeddetailed_lines)) + for id := range m.removeddetailed_lines { + ids = append(ids, id) + } + return ids + } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) - if m.clearedrun { - edges = append(edges, chargeflatfeerundetailedline.EdgeRun) +func (m *ChargeFlatFeeRunMutation) ClearedEdges() []string { + edges := make([]string, 0, 7) + if m.clearedflat_fee { + edges = append(edges, chargeflatfeerun.EdgeFlatFee) + } + if m.clearedbilling_invoice_line { + edges = append(edges, chargeflatfeerun.EdgeBillingInvoiceLine) + } + if m.clearedbilling_invoice { + edges = append(edges, chargeflatfeerun.EdgeBillingInvoice) + } + if m.clearedcredit_allocations { + edges = append(edges, chargeflatfeerun.EdgeCreditAllocations) + } + if m.cleareddetailed_lines { + edges = append(edges, chargeflatfeerun.EdgeDetailedLines) + } + if m.clearedinvoiced_usage { + edges = append(edges, chargeflatfeerun.EdgeInvoicedUsage) + } + if m.clearedpayment { + edges = append(edges, chargeflatfeerun.EdgePayment) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *ChargeFlatFeeRunDetailedLineMutation) EdgeCleared(name string) bool { +func (m *ChargeFlatFeeRunMutation) EdgeCleared(name string) bool { switch name { - case chargeflatfeerundetailedline.EdgeRun: - return m.clearedrun + case chargeflatfeerun.EdgeFlatFee: + return m.clearedflat_fee + case chargeflatfeerun.EdgeBillingInvoiceLine: + return m.clearedbilling_invoice_line + case chargeflatfeerun.EdgeBillingInvoice: + return m.clearedbilling_invoice + case chargeflatfeerun.EdgeCreditAllocations: + return m.clearedcredit_allocations + case chargeflatfeerun.EdgeDetailedLines: + return m.cleareddetailed_lines + case chargeflatfeerun.EdgeInvoicedUsage: + return m.clearedinvoiced_usage + case chargeflatfeerun.EdgePayment: + return m.clearedpayment } 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 *ChargeFlatFeeRunDetailedLineMutation) ClearEdge(name string) error { +func (m *ChargeFlatFeeRunMutation) ClearEdge(name string) error { switch name { - case chargeflatfeerundetailedline.EdgeRun: - m.ClearRun() + case chargeflatfeerun.EdgeFlatFee: + m.ClearFlatFee() + return nil + case chargeflatfeerun.EdgeBillingInvoiceLine: + m.ClearBillingInvoiceLine() + return nil + case chargeflatfeerun.EdgeBillingInvoice: + m.ClearBillingInvoice() + return nil + case chargeflatfeerun.EdgeInvoicedUsage: + m.ClearInvoicedUsage() + return nil + case chargeflatfeerun.EdgePayment: + m.ClearPayment() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine unique edge %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRun 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 *ChargeFlatFeeRunDetailedLineMutation) ResetEdge(name string) error { +func (m *ChargeFlatFeeRunMutation) ResetEdge(name string) error { switch name { - case chargeflatfeerundetailedline.EdgeRun: - m.ResetRun() + case chargeflatfeerun.EdgeFlatFee: + m.ResetFlatFee() + return nil + case chargeflatfeerun.EdgeBillingInvoiceLine: + m.ResetBillingInvoiceLine() + return nil + case chargeflatfeerun.EdgeBillingInvoice: + m.ResetBillingInvoice() + return nil + case chargeflatfeerun.EdgeCreditAllocations: + m.ResetCreditAllocations() + return nil + case chargeflatfeerun.EdgeDetailedLines: + m.ResetDetailedLines() + return nil + case chargeflatfeerun.EdgeInvoicedUsage: + m.ResetInvoicedUsage() + return nil + case chargeflatfeerun.EdgePayment: + m.ResetPayment() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine edge %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRun edge %s", name) } -// ChargeFlatFeeRunInvoicedUsageMutation represents an operation that mutates the ChargeFlatFeeRunInvoicedUsage nodes in the graph. -type ChargeFlatFeeRunInvoicedUsageMutation struct { +// ChargeFlatFeeRunCreditAllocationsMutation represents an operation that mutates the ChargeFlatFeeRunCreditAllocations nodes in the graph. +type ChargeFlatFeeRunCreditAllocationsMutation struct { config op Op typ string id *string + amount *alpacadecimal.Decimal service_period_from *time.Time service_period_to *time.Time ledger_transaction_group_id *string + sort_hint *int + addsort_hint *int + _type *creditrealization.Type namespace *string created_at *time.Time updated_at *time.Time deleted_at *time.Time annotations *models.Annotations - amount *alpacadecimal.Decimal - taxes_total *alpacadecimal.Decimal - taxes_inclusive_total *alpacadecimal.Decimal - taxes_exclusive_total *alpacadecimal.Decimal - charges_total *alpacadecimal.Decimal - discounts_total *alpacadecimal.Decimal - credits_total *alpacadecimal.Decimal - total *alpacadecimal.Decimal clearedFields map[string]struct{} + corrections map[string]struct{} + removedcorrections map[string]struct{} + clearedcorrections bool + allocation *string + clearedallocation bool run *string clearedrun bool + billing_invoice_line *string + clearedbilling_invoice_line bool done bool - oldValue func(context.Context) (*ChargeFlatFeeRunInvoicedUsage, error) - predicates []predicate.ChargeFlatFeeRunInvoicedUsage + oldValue func(context.Context) (*ChargeFlatFeeRunCreditAllocations, error) + predicates []predicate.ChargeFlatFeeRunCreditAllocations } -var _ ent.Mutation = (*ChargeFlatFeeRunInvoicedUsageMutation)(nil) +var _ ent.Mutation = (*ChargeFlatFeeRunCreditAllocationsMutation)(nil) -// chargeflatfeeruninvoicedusageOption allows management of the mutation configuration using functional options. -type chargeflatfeeruninvoicedusageOption func(*ChargeFlatFeeRunInvoicedUsageMutation) +// chargeflatfeeruncreditallocationsOption allows management of the mutation configuration using functional options. +type chargeflatfeeruncreditallocationsOption func(*ChargeFlatFeeRunCreditAllocationsMutation) -// newChargeFlatFeeRunInvoicedUsageMutation creates new mutation for the ChargeFlatFeeRunInvoicedUsage entity. -func newChargeFlatFeeRunInvoicedUsageMutation(c config, op Op, opts ...chargeflatfeeruninvoicedusageOption) *ChargeFlatFeeRunInvoicedUsageMutation { - m := &ChargeFlatFeeRunInvoicedUsageMutation{ +// newChargeFlatFeeRunCreditAllocationsMutation creates new mutation for the ChargeFlatFeeRunCreditAllocations entity. +func newChargeFlatFeeRunCreditAllocationsMutation(c config, op Op, opts ...chargeflatfeeruncreditallocationsOption) *ChargeFlatFeeRunCreditAllocationsMutation { + m := &ChargeFlatFeeRunCreditAllocationsMutation{ config: c, op: op, - typ: TypeChargeFlatFeeRunInvoicedUsage, + typ: TypeChargeFlatFeeRunCreditAllocations, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -56146,20 +55328,20 @@ func newChargeFlatFeeRunInvoicedUsageMutation(c config, op Op, opts ...chargefla return m } -// withChargeFlatFeeRunInvoicedUsageID sets the ID field of the mutation. -func withChargeFlatFeeRunInvoicedUsageID(id string) chargeflatfeeruninvoicedusageOption { - return func(m *ChargeFlatFeeRunInvoicedUsageMutation) { +// withChargeFlatFeeRunCreditAllocationsID sets the ID field of the mutation. +func withChargeFlatFeeRunCreditAllocationsID(id string) chargeflatfeeruncreditallocationsOption { + return func(m *ChargeFlatFeeRunCreditAllocationsMutation) { var ( err error once sync.Once - value *ChargeFlatFeeRunInvoicedUsage + value *ChargeFlatFeeRunCreditAllocations ) - m.oldValue = func(ctx context.Context) (*ChargeFlatFeeRunInvoicedUsage, error) { + m.oldValue = func(ctx context.Context) (*ChargeFlatFeeRunCreditAllocations, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { - value, err = m.Client().ChargeFlatFeeRunInvoicedUsage.Get(ctx, id) + value, err = m.Client().ChargeFlatFeeRunCreditAllocations.Get(ctx, id) } }) return value, err @@ -56168,10 +55350,10 @@ func withChargeFlatFeeRunInvoicedUsageID(id string) chargeflatfeeruninvoicedusag } } -// withChargeFlatFeeRunInvoicedUsage sets the old ChargeFlatFeeRunInvoicedUsage of the mutation. -func withChargeFlatFeeRunInvoicedUsage(node *ChargeFlatFeeRunInvoicedUsage) chargeflatfeeruninvoicedusageOption { - return func(m *ChargeFlatFeeRunInvoicedUsageMutation) { - m.oldValue = func(context.Context) (*ChargeFlatFeeRunInvoicedUsage, error) { +// withChargeFlatFeeRunCreditAllocations sets the old ChargeFlatFeeRunCreditAllocations of the mutation. +func withChargeFlatFeeRunCreditAllocations(node *ChargeFlatFeeRunCreditAllocations) chargeflatfeeruncreditallocationsOption { + return func(m *ChargeFlatFeeRunCreditAllocationsMutation) { + m.oldValue = func(context.Context) (*ChargeFlatFeeRunCreditAllocations, error) { return node, nil } m.id = &node.ID @@ -56180,7 +55362,7 @@ func withChargeFlatFeeRunInvoicedUsage(node *ChargeFlatFeeRunInvoicedUsage) char // 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 ChargeFlatFeeRunInvoicedUsageMutation) Client() *Client { +func (m ChargeFlatFeeRunCreditAllocationsMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -56188,7 +55370,7 @@ func (m ChargeFlatFeeRunInvoicedUsageMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m ChargeFlatFeeRunInvoicedUsageMutation) Tx() (*Tx, error) { +func (m ChargeFlatFeeRunCreditAllocationsMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("db: mutation is not running in a transaction") } @@ -56198,14 +55380,14 @@ func (m ChargeFlatFeeRunInvoicedUsageMutation) Tx() (*Tx, error) { } // SetID sets the value of the id field. Note that this -// operation is only accepted on creation of ChargeFlatFeeRunInvoicedUsage entities. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetID(id string) { +// operation is only accepted on creation of ChargeFlatFeeRunCreditAllocations entities. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) 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 *ChargeFlatFeeRunInvoicedUsageMutation) ID() (id string, exists bool) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ID() (id string, exists bool) { if m.id == nil { return } @@ -56216,7 +55398,7 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) ID() (id string, exists bool) { // 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 *ChargeFlatFeeRunInvoicedUsageMutation) IDs(ctx context.Context) ([]string, error) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() @@ -56225,66 +55407,151 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) IDs(ctx context.Context) ([]stri } fallthrough case m.op.Is(OpUpdate | OpDelete): - return m.Client().ChargeFlatFeeRunInvoicedUsage.Query().Where(m.predicates...).IDs(ctx) + return m.Client().ChargeFlatFeeRunCreditAllocations.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } -// SetServicePeriodFrom sets the "service_period_from" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetServicePeriodFrom(t time.Time) { - m.service_period_from = &t +// SetLineID sets the "line_id" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetLineID(s string) { + m.billing_invoice_line = &s } -// ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ServicePeriodFrom() (r time.Time, exists bool) { - v := m.service_period_from +// LineID returns the value of the "line_id" field in the mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) LineID() (r string, exists bool) { + v := m.billing_invoice_line if v == nil { return } return *v, true } -// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage object wasn't provided to the builder, the object is fetched from the database. +// OldLineID returns the old "line_id" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) OldLineID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") + return v, errors.New("OldLineID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldServicePeriodFrom requires an ID field in the mutation") + return v, errors.New("OldLineID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldServicePeriodFrom: %w", err) + return v, fmt.Errorf("querying old value for OldLineID: %w", err) } - return oldValue.ServicePeriodFrom, nil + return oldValue.LineID, nil } -// ResetServicePeriodFrom resets all changes to the "service_period_from" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetServicePeriodFrom() { - m.service_period_from = nil +// ClearLineID clears the value of the "line_id" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearLineID() { + m.billing_invoice_line = nil + m.clearedFields[chargeflatfeeruncreditallocations.FieldLineID] = struct{}{} } -// SetServicePeriodTo sets the "service_period_to" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetServicePeriodTo(t time.Time) { - m.service_period_to = &t +// LineIDCleared returns if the "line_id" field was cleared in this mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) LineIDCleared() bool { + _, ok := m.clearedFields[chargeflatfeeruncreditallocations.FieldLineID] + return ok } -// ServicePeriodTo returns the value of the "service_period_to" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ServicePeriodTo() (r time.Time, exists bool) { - v := m.service_period_to - if v == nil { - return - } - return *v, true +// ResetLineID resets all changes to the "line_id" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetLineID() { + m.billing_invoice_line = nil + delete(m.clearedFields, chargeflatfeeruncreditallocations.FieldLineID) } -// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { +// SetAmount sets the "amount" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetAmount(a alpacadecimal.Decimal) { + m.amount = &a +} + +// Amount returns the value of the "amount" field in the mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) Amount() (r alpacadecimal.Decimal, exists bool) { + v := m.amount + if v == nil { + return + } + return *v, true +} + +// OldAmount returns the old "amount" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAmount is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAmount requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAmount: %w", err) + } + return oldValue.Amount, nil +} + +// ResetAmount resets all changes to the "amount" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetAmount() { + m.amount = nil +} + +// SetServicePeriodFrom sets the "service_period_from" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetServicePeriodFrom(t time.Time) { + m.service_period_from = &t +} + +// ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ServicePeriodFrom() (r time.Time, exists bool) { + v := m.service_period_from + if v == nil { + return + } + return *v, true +} + +// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldServicePeriodFrom requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldServicePeriodFrom: %w", err) + } + return oldValue.ServicePeriodFrom, nil +} + +// ResetServicePeriodFrom resets all changes to the "service_period_from" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetServicePeriodFrom() { + m.service_period_from = nil +} + +// SetServicePeriodTo sets the "service_period_to" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetServicePeriodTo(t time.Time) { + m.service_period_to = &t +} + +// ServicePeriodTo returns the value of the "service_period_to" field in the mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ServicePeriodTo() (r time.Time, exists bool) { + v := m.service_period_to + if v == nil { + return + } + return *v, true +} + +// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") } @@ -56299,17 +55566,17 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldServicePeriodTo(ctx context.C } // ResetServicePeriodTo resets all changes to the "service_period_to" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetServicePeriodTo() { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetServicePeriodTo() { m.service_period_to = nil } // SetLedgerTransactionGroupID sets the "ledger_transaction_group_id" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetLedgerTransactionGroupID(s string) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetLedgerTransactionGroupID(s string) { m.ledger_transaction_group_id = &s } // LedgerTransactionGroupID returns the value of the "ledger_transaction_group_id" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) LedgerTransactionGroupID() (r string, exists bool) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) LedgerTransactionGroupID() (r string, exists bool) { v := m.ledger_transaction_group_id if v == nil { return @@ -56317,10 +55584,10 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) LedgerTransactionGroupID() (r st return *v, true } -// OldLedgerTransactionGroupID returns the old "ledger_transaction_group_id" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage object wasn't provided to the builder, the object is fetched from the database. +// OldLedgerTransactionGroupID returns the old "ledger_transaction_group_id" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldLedgerTransactionGroupID(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) OldLedgerTransactionGroupID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldLedgerTransactionGroupID is only allowed on UpdateOne operations") } @@ -56334,31 +55601,159 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldLedgerTransactionGroupID(ctx return oldValue.LedgerTransactionGroupID, nil } -// ClearLedgerTransactionGroupID clears the value of the "ledger_transaction_group_id" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ClearLedgerTransactionGroupID() { +// ResetLedgerTransactionGroupID resets all changes to the "ledger_transaction_group_id" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetLedgerTransactionGroupID() { m.ledger_transaction_group_id = nil - m.clearedFields[chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID] = struct{}{} } -// LedgerTransactionGroupIDCleared returns if the "ledger_transaction_group_id" field was cleared in this mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) LedgerTransactionGroupIDCleared() bool { - _, ok := m.clearedFields[chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID] +// SetSortHint sets the "sort_hint" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetSortHint(i int) { + m.sort_hint = &i + m.addsort_hint = nil +} + +// SortHint returns the value of the "sort_hint" field in the mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SortHint() (r int, exists bool) { + v := m.sort_hint + if v == nil { + return + } + return *v, true +} + +// OldSortHint returns the old "sort_hint" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldSortHint(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSortHint is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSortHint requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSortHint: %w", err) + } + return oldValue.SortHint, nil +} + +// AddSortHint adds i to the "sort_hint" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddSortHint(i int) { + if m.addsort_hint != nil { + *m.addsort_hint += i + } else { + m.addsort_hint = &i + } +} + +// AddedSortHint returns the value that was added to the "sort_hint" field in this mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddedSortHint() (r int, exists bool) { + v := m.addsort_hint + if v == nil { + return + } + return *v, true +} + +// ResetSortHint resets all changes to the "sort_hint" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetSortHint() { + m.sort_hint = nil + m.addsort_hint = nil +} + +// SetType sets the "type" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetType(c creditrealization.Type) { + m._type = &c +} + +// GetType returns the value of the "type" field in the mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) GetType() (r creditrealization.Type, exists bool) { + v := m._type + if v == nil { + return + } + return *v, true +} + +// OldType returns the old "type" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldType(ctx context.Context) (v creditrealization.Type, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldType: %w", err) + } + return oldValue.Type, nil +} + +// ResetType resets all changes to the "type" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetType() { + m._type = nil +} + +// SetCorrectsRealizationID sets the "corrects_realization_id" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetCorrectsRealizationID(s string) { + m.allocation = &s +} + +// CorrectsRealizationID returns the value of the "corrects_realization_id" field in the mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) CorrectsRealizationID() (r string, exists bool) { + v := m.allocation + if v == nil { + return + } + return *v, true +} + +// OldCorrectsRealizationID returns the old "corrects_realization_id" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunCreditAllocationsMutation) OldCorrectsRealizationID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCorrectsRealizationID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCorrectsRealizationID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCorrectsRealizationID: %w", err) + } + return oldValue.CorrectsRealizationID, nil +} + +// ClearCorrectsRealizationID clears the value of the "corrects_realization_id" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearCorrectsRealizationID() { + m.allocation = nil + m.clearedFields[chargeflatfeeruncreditallocations.FieldCorrectsRealizationID] = struct{}{} +} + +// CorrectsRealizationIDCleared returns if the "corrects_realization_id" field was cleared in this mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) CorrectsRealizationIDCleared() bool { + _, ok := m.clearedFields[chargeflatfeeruncreditallocations.FieldCorrectsRealizationID] return ok } -// ResetLedgerTransactionGroupID resets all changes to the "ledger_transaction_group_id" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetLedgerTransactionGroupID() { - m.ledger_transaction_group_id = nil - delete(m.clearedFields, chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID) +// ResetCorrectsRealizationID resets all changes to the "corrects_realization_id" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetCorrectsRealizationID() { + m.allocation = nil + delete(m.clearedFields, chargeflatfeeruncreditallocations.FieldCorrectsRealizationID) } // SetNamespace sets the "namespace" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetNamespace(s string) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetNamespace(s string) { m.namespace = &s } // Namespace returns the value of the "namespace" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) Namespace() (r string, exists bool) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) Namespace() (r string, exists bool) { v := m.namespace if v == nil { return @@ -56366,10 +55761,10 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) Namespace() (r string, exists bo return *v, true } -// OldNamespace returns the old "namespace" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage object wasn't provided to the builder, the object is fetched from the database. +// OldNamespace returns the old "namespace" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldNamespace(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) OldNamespace(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldNamespace is only allowed on UpdateOne operations") } @@ -56384,17 +55779,17 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldNamespace(ctx context.Context } // ResetNamespace resets all changes to the "namespace" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetNamespace() { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetNamespace() { m.namespace = nil } // SetCreatedAt sets the "created_at" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetCreatedAt(t time.Time) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) CreatedAt() (r time.Time, exists bool) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return @@ -56402,10 +55797,10 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) CreatedAt() (r time.Time, exists return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) 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") } @@ -56420,17 +55815,17 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldCreatedAt(ctx context.Context } // ResetCreatedAt resets all changes to the "created_at" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetCreatedAt() { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetUpdatedAt(t time.Time) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) UpdatedAt() (r time.Time, exists bool) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return @@ -56438,10 +55833,10 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) UpdatedAt() (r time.Time, exists return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) 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") } @@ -56456,17 +55851,17 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldUpdatedAt(ctx context.Context } // ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetUpdatedAt() { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetUpdatedAt() { m.updated_at = nil } // SetDeletedAt sets the "deleted_at" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetDeletedAt(t time.Time) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetDeletedAt(t time.Time) { m.deleted_at = &t } // DeletedAt returns the value of the "deleted_at" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) DeletedAt() (r time.Time, exists bool) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) DeletedAt() (r time.Time, exists bool) { v := m.deleted_at if v == nil { return @@ -56474,10 +55869,10 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) DeletedAt() (r time.Time, exists return *v, true } -// OldDeletedAt returns the old "deleted_at" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage object wasn't provided to the builder, the object is fetched from the database. +// OldDeletedAt returns the old "deleted_at" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) 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") } @@ -56492,30 +55887,30 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldDeletedAt(ctx context.Context } // ClearDeletedAt clears the value of the "deleted_at" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ClearDeletedAt() { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearDeletedAt() { m.deleted_at = nil - m.clearedFields[chargeflatfeeruninvoicedusage.FieldDeletedAt] = struct{}{} + m.clearedFields[chargeflatfeeruncreditallocations.FieldDeletedAt] = struct{}{} } // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) DeletedAtCleared() bool { - _, ok := m.clearedFields[chargeflatfeeruninvoicedusage.FieldDeletedAt] +func (m *ChargeFlatFeeRunCreditAllocationsMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargeflatfeeruncreditallocations.FieldDeletedAt] return ok } // ResetDeletedAt resets all changes to the "deleted_at" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetDeletedAt() { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetDeletedAt() { m.deleted_at = nil - delete(m.clearedFields, chargeflatfeeruninvoicedusage.FieldDeletedAt) + delete(m.clearedFields, chargeflatfeeruncreditallocations.FieldDeletedAt) } // SetAnnotations sets the "annotations" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetAnnotations(value models.Annotations) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetAnnotations(value models.Annotations) { m.annotations = &value } // Annotations returns the value of the "annotations" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) Annotations() (r models.Annotations, exists bool) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) Annotations() (r models.Annotations, exists bool) { v := m.annotations if v == nil { return @@ -56523,10 +55918,10 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) Annotations() (r models.Annotati return *v, true } -// OldAnnotations returns the old "annotations" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage object wasn't provided to the builder, the object is fetched from the database. +// OldAnnotations returns the old "annotations" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldAnnotations(ctx context.Context) (v models.Annotations, err error) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) 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") } @@ -56541,383 +55936,229 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldAnnotations(ctx context.Conte } // ClearAnnotations clears the value of the "annotations" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ClearAnnotations() { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearAnnotations() { m.annotations = nil - m.clearedFields[chargeflatfeeruninvoicedusage.FieldAnnotations] = struct{}{} + m.clearedFields[chargeflatfeeruncreditallocations.FieldAnnotations] = struct{}{} } // AnnotationsCleared returns if the "annotations" field was cleared in this mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) AnnotationsCleared() bool { - _, ok := m.clearedFields[chargeflatfeeruninvoicedusage.FieldAnnotations] +func (m *ChargeFlatFeeRunCreditAllocationsMutation) AnnotationsCleared() bool { + _, ok := m.clearedFields[chargeflatfeeruncreditallocations.FieldAnnotations] return ok } // ResetAnnotations resets all changes to the "annotations" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetAnnotations() { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetAnnotations() { m.annotations = nil - delete(m.clearedFields, chargeflatfeeruninvoicedusage.FieldAnnotations) + delete(m.clearedFields, chargeflatfeeruncreditallocations.FieldAnnotations) } -// SetAmount sets the "amount" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetAmount(a alpacadecimal.Decimal) { - m.amount = &a +// SetRunID sets the "run_id" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetRunID(s string) { + m.run = &s } -// Amount returns the value of the "amount" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) Amount() (r alpacadecimal.Decimal, exists bool) { - v := m.amount +// RunID returns the value of the "run_id" field in the mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) RunID() (r string, exists bool) { + v := m.run if v == nil { return } return *v, true } -// OldAmount returns the old "amount" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage object wasn't provided to the builder, the object is fetched from the database. +// OldRunID returns the old "run_id" field's value of the ChargeFlatFeeRunCreditAllocations entity. +// If the ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) OldRunID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAmount is only allowed on UpdateOne operations") + return v, errors.New("OldRunID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAmount requires an ID field in the mutation") + return v, errors.New("OldRunID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldAmount: %w", err) + return v, fmt.Errorf("querying old value for OldRunID: %w", err) } - return oldValue.Amount, nil + return oldValue.RunID, nil } -// ResetAmount resets all changes to the "amount" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetAmount() { - m.amount = nil +// ResetRunID resets all changes to the "run_id" field. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetRunID() { + m.run = nil } -// SetTaxesTotal sets the "taxes_total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetTaxesTotal(a alpacadecimal.Decimal) { - m.taxes_total = &a +// AddCorrectionIDs adds the "corrections" edge to the ChargeFlatFeeRunCreditAllocations entity by ids. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddCorrectionIDs(ids ...string) { + if m.corrections == nil { + m.corrections = make(map[string]struct{}) + } + for i := range ids { + m.corrections[ids[i]] = struct{}{} + } } -// TaxesTotal returns the value of the "taxes_total" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) TaxesTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.taxes_total - if v == nil { - return - } - return *v, true +// ClearCorrections clears the "corrections" edge to the ChargeFlatFeeRunCreditAllocations entity. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearCorrections() { + m.clearedcorrections = true } -// OldTaxesTotal returns the old "taxes_total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldTaxesTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTaxesTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTaxesTotal requires an ID field in the mutation") +// CorrectionsCleared reports if the "corrections" edge to the ChargeFlatFeeRunCreditAllocations entity was cleared. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) CorrectionsCleared() bool { + return m.clearedcorrections +} + +// RemoveCorrectionIDs removes the "corrections" edge to the ChargeFlatFeeRunCreditAllocations entity by IDs. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) RemoveCorrectionIDs(ids ...string) { + if m.removedcorrections == nil { + m.removedcorrections = make(map[string]struct{}) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTaxesTotal: %w", err) + for i := range ids { + delete(m.corrections, ids[i]) + m.removedcorrections[ids[i]] = struct{}{} } - return oldValue.TaxesTotal, nil } -// ResetTaxesTotal resets all changes to the "taxes_total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetTaxesTotal() { - m.taxes_total = nil +// RemovedCorrections returns the removed IDs of the "corrections" edge to the ChargeFlatFeeRunCreditAllocations entity. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) RemovedCorrectionsIDs() (ids []string) { + for id := range m.removedcorrections { + ids = append(ids, id) + } + return } -// SetTaxesInclusiveTotal sets the "taxes_inclusive_total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetTaxesInclusiveTotal(a alpacadecimal.Decimal) { - m.taxes_inclusive_total = &a +// CorrectionsIDs returns the "corrections" edge IDs in the mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) CorrectionsIDs() (ids []string) { + for id := range m.corrections { + ids = append(ids, id) + } + return } -// TaxesInclusiveTotal returns the value of the "taxes_inclusive_total" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) TaxesInclusiveTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.taxes_inclusive_total - if v == nil { - return - } - return *v, true +// ResetCorrections resets all changes to the "corrections" edge. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetCorrections() { + m.corrections = nil + m.clearedcorrections = false + m.removedcorrections = nil } -// OldTaxesInclusiveTotal returns the old "taxes_inclusive_total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldTaxesInclusiveTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTaxesInclusiveTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTaxesInclusiveTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTaxesInclusiveTotal: %w", err) - } - return oldValue.TaxesInclusiveTotal, nil +// SetAllocationID sets the "allocation" edge to the ChargeFlatFeeRunCreditAllocations entity by id. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetAllocationID(id string) { + m.allocation = &id } -// ResetTaxesInclusiveTotal resets all changes to the "taxes_inclusive_total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetTaxesInclusiveTotal() { - m.taxes_inclusive_total = nil +// ClearAllocation clears the "allocation" edge to the ChargeFlatFeeRunCreditAllocations entity. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearAllocation() { + m.clearedallocation = true + m.clearedFields[chargeflatfeeruncreditallocations.FieldCorrectsRealizationID] = struct{}{} } -// SetTaxesExclusiveTotal sets the "taxes_exclusive_total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetTaxesExclusiveTotal(a alpacadecimal.Decimal) { - m.taxes_exclusive_total = &a +// AllocationCleared reports if the "allocation" edge to the ChargeFlatFeeRunCreditAllocations entity was cleared. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) AllocationCleared() bool { + return m.CorrectsRealizationIDCleared() || m.clearedallocation } -// TaxesExclusiveTotal returns the value of the "taxes_exclusive_total" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) TaxesExclusiveTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.taxes_exclusive_total - if v == nil { - return +// AllocationID returns the "allocation" edge ID in the mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) AllocationID() (id string, exists bool) { + if m.allocation != nil { + return *m.allocation, true } - return *v, true + return } -// OldTaxesExclusiveTotal returns the old "taxes_exclusive_total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldTaxesExclusiveTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTaxesExclusiveTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTaxesExclusiveTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTaxesExclusiveTotal: %w", err) +// AllocationIDs returns the "allocation" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// AllocationID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) AllocationIDs() (ids []string) { + if id := m.allocation; id != nil { + ids = append(ids, *id) } - return oldValue.TaxesExclusiveTotal, nil + return } -// ResetTaxesExclusiveTotal resets all changes to the "taxes_exclusive_total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetTaxesExclusiveTotal() { - m.taxes_exclusive_total = nil +// ResetAllocation resets all changes to the "allocation" edge. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetAllocation() { + m.allocation = nil + m.clearedallocation = false } -// SetChargesTotal sets the "charges_total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetChargesTotal(a alpacadecimal.Decimal) { - m.charges_total = &a -} - -// ChargesTotal returns the value of the "charges_total" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ChargesTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.charges_total - if v == nil { - return - } - return *v, true -} - -// OldChargesTotal returns the old "charges_total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldChargesTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldChargesTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldChargesTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldChargesTotal: %w", err) - } - return oldValue.ChargesTotal, nil -} - -// ResetChargesTotal resets all changes to the "charges_total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetChargesTotal() { - m.charges_total = nil -} - -// SetDiscountsTotal sets the "discounts_total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetDiscountsTotal(a alpacadecimal.Decimal) { - m.discounts_total = &a -} - -// DiscountsTotal returns the value of the "discounts_total" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) DiscountsTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.discounts_total - if v == nil { - return - } - return *v, true -} - -// OldDiscountsTotal returns the old "discounts_total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldDiscountsTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDiscountsTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDiscountsTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDiscountsTotal: %w", err) - } - return oldValue.DiscountsTotal, nil -} - -// ResetDiscountsTotal resets all changes to the "discounts_total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetDiscountsTotal() { - m.discounts_total = nil -} - -// SetCreditsTotal sets the "credits_total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetCreditsTotal(a alpacadecimal.Decimal) { - m.credits_total = &a -} - -// CreditsTotal returns the value of the "credits_total" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) CreditsTotal() (r alpacadecimal.Decimal, exists bool) { - v := m.credits_total - if v == nil { - return - } - return *v, true -} - -// OldCreditsTotal returns the old "credits_total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldCreditsTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreditsTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreditsTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreditsTotal: %w", err) - } - return oldValue.CreditsTotal, nil -} - -// ResetCreditsTotal resets all changes to the "credits_total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetCreditsTotal() { - m.credits_total = nil +// ClearRun clears the "run" edge to the ChargeFlatFeeRun entity. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearRun() { + m.clearedrun = true + m.clearedFields[chargeflatfeeruncreditallocations.FieldRunID] = struct{}{} } -// SetTotal sets the "total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetTotal(a alpacadecimal.Decimal) { - m.total = &a +// RunCleared reports if the "run" edge to the ChargeFlatFeeRun entity was cleared. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) RunCleared() bool { + return m.clearedrun } -// Total returns the value of the "total" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) Total() (r alpacadecimal.Decimal, exists bool) { - v := m.total - if v == nil { - return +// RunIDs returns the "run" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// RunID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) RunIDs() (ids []string) { + if id := m.run; id != nil { + ids = append(ids, *id) } - return *v, true + return } -// OldTotal returns the old "total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTotal is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTotal requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTotal: %w", err) - } - return oldValue.Total, nil +// ResetRun resets all changes to the "run" edge. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetRun() { + m.run = nil + m.clearedrun = false } -// ResetTotal resets all changes to the "total" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetTotal() { - m.total = nil +// SetBillingInvoiceLineID sets the "billing_invoice_line" edge to the BillingInvoiceLine entity by id. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetBillingInvoiceLineID(id string) { + m.billing_invoice_line = &id } -// SetRunID sets the "run_id" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetRunID(s string) { - m.run = &s +// ClearBillingInvoiceLine clears the "billing_invoice_line" edge to the BillingInvoiceLine entity. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearBillingInvoiceLine() { + m.clearedbilling_invoice_line = true + m.clearedFields[chargeflatfeeruncreditallocations.FieldLineID] = struct{}{} } -// RunID returns the value of the "run_id" field in the mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) RunID() (r string, exists bool) { - v := m.run - if v == nil { - return - } - return *v, true +// BillingInvoiceLineCleared reports if the "billing_invoice_line" edge to the BillingInvoiceLine entity was cleared. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) BillingInvoiceLineCleared() bool { + return m.LineIDCleared() || m.clearedbilling_invoice_line } -// OldRunID returns the old "run_id" field's value of the ChargeFlatFeeRunInvoicedUsage entity. -// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldRunID(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldRunID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldRunID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldRunID: %w", err) +// BillingInvoiceLineID returns the "billing_invoice_line" edge ID in the mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) BillingInvoiceLineID() (id string, exists bool) { + if m.billing_invoice_line != nil { + return *m.billing_invoice_line, true } - return oldValue.RunID, nil -} - -// ResetRunID resets all changes to the "run_id" field. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetRunID() { - m.run = nil -} - -// ClearRun clears the "run" edge to the ChargeFlatFeeRun entity. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ClearRun() { - m.clearedrun = true - m.clearedFields[chargeflatfeeruninvoicedusage.FieldRunID] = struct{}{} -} - -// RunCleared reports if the "run" edge to the ChargeFlatFeeRun entity was cleared. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) RunCleared() bool { - return m.clearedrun + return } -// RunIDs returns the "run" edge IDs in the mutation. +// BillingInvoiceLineIDs returns the "billing_invoice_line" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// RunID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) RunIDs() (ids []string) { - if id := m.run; id != nil { +// BillingInvoiceLineID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) BillingInvoiceLineIDs() (ids []string) { + if id := m.billing_invoice_line; id != nil { ids = append(ids, *id) } return } -// ResetRun resets all changes to the "run" edge. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetRun() { - m.run = nil - m.clearedrun = false +// ResetBillingInvoiceLine resets all changes to the "billing_invoice_line" edge. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetBillingInvoiceLine() { + m.billing_invoice_line = nil + m.clearedbilling_invoice_line = false } -// Where appends a list predicates to the ChargeFlatFeeRunInvoicedUsageMutation builder. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) Where(ps ...predicate.ChargeFlatFeeRunInvoicedUsage) { +// Where appends a list predicates to the ChargeFlatFeeRunCreditAllocationsMutation builder. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) Where(ps ...predicate.ChargeFlatFeeRunCreditAllocations) { m.predicates = append(m.predicates, ps...) } -// WhereP appends storage-level predicates to the ChargeFlatFeeRunInvoicedUsageMutation builder. Using this method, +// WhereP appends storage-level predicates to the ChargeFlatFeeRunCreditAllocationsMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.ChargeFlatFeeRunInvoicedUsage, len(ps)) +func (m *ChargeFlatFeeRunCreditAllocationsMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeFlatFeeRunCreditAllocations, len(ps)) for i := range ps { p[i] = ps[i] } @@ -56925,75 +56166,66 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) WhereP(ps ...func(*sql.Selector) } // Op returns the operation name. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) Op() Op { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetOp(op Op) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetOp(op Op) { m.op = op } -// Type returns the node type of this mutation (ChargeFlatFeeRunInvoicedUsage). -func (m *ChargeFlatFeeRunInvoicedUsageMutation) Type() string { +// Type returns the node type of this mutation (ChargeFlatFeeRunCreditAllocations). +func (m *ChargeFlatFeeRunCreditAllocationsMutation) 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 *ChargeFlatFeeRunInvoicedUsageMutation) Fields() []string { - fields := make([]string, 0, 17) +func (m *ChargeFlatFeeRunCreditAllocationsMutation) Fields() []string { + fields := make([]string, 0, 14) + if m.billing_invoice_line != nil { + fields = append(fields, chargeflatfeeruncreditallocations.FieldLineID) + } + if m.amount != nil { + fields = append(fields, chargeflatfeeruncreditallocations.FieldAmount) + } if m.service_period_from != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldServicePeriodFrom) + fields = append(fields, chargeflatfeeruncreditallocations.FieldServicePeriodFrom) } if m.service_period_to != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldServicePeriodTo) + fields = append(fields, chargeflatfeeruncreditallocations.FieldServicePeriodTo) } if m.ledger_transaction_group_id != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID) + fields = append(fields, chargeflatfeeruncreditallocations.FieldLedgerTransactionGroupID) + } + if m.sort_hint != nil { + fields = append(fields, chargeflatfeeruncreditallocations.FieldSortHint) + } + if m._type != nil { + fields = append(fields, chargeflatfeeruncreditallocations.FieldType) + } + if m.allocation != nil { + fields = append(fields, chargeflatfeeruncreditallocations.FieldCorrectsRealizationID) } if m.namespace != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldNamespace) + fields = append(fields, chargeflatfeeruncreditallocations.FieldNamespace) } if m.created_at != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldCreatedAt) + fields = append(fields, chargeflatfeeruncreditallocations.FieldCreatedAt) } if m.updated_at != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldUpdatedAt) + fields = append(fields, chargeflatfeeruncreditallocations.FieldUpdatedAt) } if m.deleted_at != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldDeletedAt) + fields = append(fields, chargeflatfeeruncreditallocations.FieldDeletedAt) } if m.annotations != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldAnnotations) - } - if m.amount != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldAmount) - } - if m.taxes_total != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldTaxesTotal) - } - if m.taxes_inclusive_total != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldTaxesInclusiveTotal) - } - if m.taxes_exclusive_total != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldTaxesExclusiveTotal) - } - if m.charges_total != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldChargesTotal) - } - if m.discounts_total != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldDiscountsTotal) - } - if m.credits_total != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldCreditsTotal) - } - if m.total != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldTotal) + fields = append(fields, chargeflatfeeruncreditallocations.FieldAnnotations) } if m.run != nil { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldRunID) + fields = append(fields, chargeflatfeeruncreditallocations.FieldRunID) } return fields } @@ -57001,41 +56233,35 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) Fields() []string { // 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 *ChargeFlatFeeRunInvoicedUsageMutation) Field(name string) (ent.Value, bool) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) Field(name string) (ent.Value, bool) { switch name { - case chargeflatfeeruninvoicedusage.FieldServicePeriodFrom: + case chargeflatfeeruncreditallocations.FieldLineID: + return m.LineID() + case chargeflatfeeruncreditallocations.FieldAmount: + return m.Amount() + case chargeflatfeeruncreditallocations.FieldServicePeriodFrom: return m.ServicePeriodFrom() - case chargeflatfeeruninvoicedusage.FieldServicePeriodTo: + case chargeflatfeeruncreditallocations.FieldServicePeriodTo: return m.ServicePeriodTo() - case chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID: + case chargeflatfeeruncreditallocations.FieldLedgerTransactionGroupID: return m.LedgerTransactionGroupID() - case chargeflatfeeruninvoicedusage.FieldNamespace: + case chargeflatfeeruncreditallocations.FieldSortHint: + return m.SortHint() + case chargeflatfeeruncreditallocations.FieldType: + return m.GetType() + case chargeflatfeeruncreditallocations.FieldCorrectsRealizationID: + return m.CorrectsRealizationID() + case chargeflatfeeruncreditallocations.FieldNamespace: return m.Namespace() - case chargeflatfeeruninvoicedusage.FieldCreatedAt: + case chargeflatfeeruncreditallocations.FieldCreatedAt: return m.CreatedAt() - case chargeflatfeeruninvoicedusage.FieldUpdatedAt: + case chargeflatfeeruncreditallocations.FieldUpdatedAt: return m.UpdatedAt() - case chargeflatfeeruninvoicedusage.FieldDeletedAt: + case chargeflatfeeruncreditallocations.FieldDeletedAt: return m.DeletedAt() - case chargeflatfeeruninvoicedusage.FieldAnnotations: + case chargeflatfeeruncreditallocations.FieldAnnotations: return m.Annotations() - case chargeflatfeeruninvoicedusage.FieldAmount: - return m.Amount() - case chargeflatfeeruninvoicedusage.FieldTaxesTotal: - return m.TaxesTotal() - case chargeflatfeeruninvoicedusage.FieldTaxesInclusiveTotal: - return m.TaxesInclusiveTotal() - case chargeflatfeeruninvoicedusage.FieldTaxesExclusiveTotal: - return m.TaxesExclusiveTotal() - case chargeflatfeeruninvoicedusage.FieldChargesTotal: - return m.ChargesTotal() - case chargeflatfeeruninvoicedusage.FieldDiscountsTotal: - return m.DiscountsTotal() - case chargeflatfeeruninvoicedusage.FieldCreditsTotal: - return m.CreditsTotal() - case chargeflatfeeruninvoicedusage.FieldTotal: - return m.Total() - case chargeflatfeeruninvoicedusage.FieldRunID: + case chargeflatfeeruncreditallocations.FieldRunID: return m.RunID() } return nil, false @@ -57044,164 +56270,137 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) Field(name string) (ent.Value, b // 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case chargeflatfeeruninvoicedusage.FieldServicePeriodFrom: + case chargeflatfeeruncreditallocations.FieldLineID: + return m.OldLineID(ctx) + case chargeflatfeeruncreditallocations.FieldAmount: + return m.OldAmount(ctx) + case chargeflatfeeruncreditallocations.FieldServicePeriodFrom: return m.OldServicePeriodFrom(ctx) - case chargeflatfeeruninvoicedusage.FieldServicePeriodTo: + case chargeflatfeeruncreditallocations.FieldServicePeriodTo: return m.OldServicePeriodTo(ctx) - case chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID: + case chargeflatfeeruncreditallocations.FieldLedgerTransactionGroupID: return m.OldLedgerTransactionGroupID(ctx) - case chargeflatfeeruninvoicedusage.FieldNamespace: + case chargeflatfeeruncreditallocations.FieldSortHint: + return m.OldSortHint(ctx) + case chargeflatfeeruncreditallocations.FieldType: + return m.OldType(ctx) + case chargeflatfeeruncreditallocations.FieldCorrectsRealizationID: + return m.OldCorrectsRealizationID(ctx) + case chargeflatfeeruncreditallocations.FieldNamespace: return m.OldNamespace(ctx) - case chargeflatfeeruninvoicedusage.FieldCreatedAt: + case chargeflatfeeruncreditallocations.FieldCreatedAt: return m.OldCreatedAt(ctx) - case chargeflatfeeruninvoicedusage.FieldUpdatedAt: + case chargeflatfeeruncreditallocations.FieldUpdatedAt: return m.OldUpdatedAt(ctx) - case chargeflatfeeruninvoicedusage.FieldDeletedAt: + case chargeflatfeeruncreditallocations.FieldDeletedAt: return m.OldDeletedAt(ctx) - case chargeflatfeeruninvoicedusage.FieldAnnotations: + case chargeflatfeeruncreditallocations.FieldAnnotations: return m.OldAnnotations(ctx) - case chargeflatfeeruninvoicedusage.FieldAmount: - return m.OldAmount(ctx) - case chargeflatfeeruninvoicedusage.FieldTaxesTotal: - return m.OldTaxesTotal(ctx) - case chargeflatfeeruninvoicedusage.FieldTaxesInclusiveTotal: - return m.OldTaxesInclusiveTotal(ctx) - case chargeflatfeeruninvoicedusage.FieldTaxesExclusiveTotal: - return m.OldTaxesExclusiveTotal(ctx) - case chargeflatfeeruninvoicedusage.FieldChargesTotal: - return m.OldChargesTotal(ctx) - case chargeflatfeeruninvoicedusage.FieldDiscountsTotal: - return m.OldDiscountsTotal(ctx) - case chargeflatfeeruninvoicedusage.FieldCreditsTotal: - return m.OldCreditsTotal(ctx) - case chargeflatfeeruninvoicedusage.FieldTotal: - return m.OldTotal(ctx) - case chargeflatfeeruninvoicedusage.FieldRunID: + case chargeflatfeeruncreditallocations.FieldRunID: return m.OldRunID(ctx) } - return nil, fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage field %s", name) + return nil, fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunInvoicedUsageMutation) SetField(name string, value ent.Value) error { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) SetField(name string, value ent.Value) error { switch name { - case chargeflatfeeruninvoicedusage.FieldServicePeriodFrom: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetServicePeriodFrom(v) - return nil - case chargeflatfeeruninvoicedusage.FieldServicePeriodTo: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetServicePeriodTo(v) - return nil - case chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetLedgerTransactionGroupID(v) - return nil - case chargeflatfeeruninvoicedusage.FieldNamespace: + case chargeflatfeeruncreditallocations.FieldLineID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetNamespace(v) + m.SetLineID(v) return nil - case chargeflatfeeruninvoicedusage.FieldCreatedAt: - v, ok := value.(time.Time) + case chargeflatfeeruncreditallocations.FieldAmount: + v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCreatedAt(v) + m.SetAmount(v) return nil - case chargeflatfeeruninvoicedusage.FieldUpdatedAt: + case chargeflatfeeruncreditallocations.FieldServicePeriodFrom: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetUpdatedAt(v) + m.SetServicePeriodFrom(v) return nil - case chargeflatfeeruninvoicedusage.FieldDeletedAt: + case chargeflatfeeruncreditallocations.FieldServicePeriodTo: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDeletedAt(v) + m.SetServicePeriodTo(v) return nil - case chargeflatfeeruninvoicedusage.FieldAnnotations: - v, ok := value.(models.Annotations) + case chargeflatfeeruncreditallocations.FieldLedgerTransactionGroupID: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetAnnotations(v) + m.SetLedgerTransactionGroupID(v) return nil - case chargeflatfeeruninvoicedusage.FieldAmount: - v, ok := value.(alpacadecimal.Decimal) + case chargeflatfeeruncreditallocations.FieldSortHint: + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetAmount(v) + m.SetSortHint(v) return nil - case chargeflatfeeruninvoicedusage.FieldTaxesTotal: - v, ok := value.(alpacadecimal.Decimal) + case chargeflatfeeruncreditallocations.FieldType: + v, ok := value.(creditrealization.Type) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetTaxesTotal(v) + m.SetType(v) return nil - case chargeflatfeeruninvoicedusage.FieldTaxesInclusiveTotal: - v, ok := value.(alpacadecimal.Decimal) + case chargeflatfeeruncreditallocations.FieldCorrectsRealizationID: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetTaxesInclusiveTotal(v) + m.SetCorrectsRealizationID(v) return nil - case chargeflatfeeruninvoicedusage.FieldTaxesExclusiveTotal: - v, ok := value.(alpacadecimal.Decimal) + case chargeflatfeeruncreditallocations.FieldNamespace: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetTaxesExclusiveTotal(v) + m.SetNamespace(v) return nil - case chargeflatfeeruninvoicedusage.FieldChargesTotal: - v, ok := value.(alpacadecimal.Decimal) + case chargeflatfeeruncreditallocations.FieldCreatedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetChargesTotal(v) + m.SetCreatedAt(v) return nil - case chargeflatfeeruninvoicedusage.FieldDiscountsTotal: - v, ok := value.(alpacadecimal.Decimal) + case chargeflatfeeruncreditallocations.FieldUpdatedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDiscountsTotal(v) + m.SetUpdatedAt(v) return nil - case chargeflatfeeruninvoicedusage.FieldCreditsTotal: - v, ok := value.(alpacadecimal.Decimal) + case chargeflatfeeruncreditallocations.FieldDeletedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCreditsTotal(v) + m.SetDeletedAt(v) return nil - case chargeflatfeeruninvoicedusage.FieldTotal: - v, ok := value.(alpacadecimal.Decimal) + case chargeflatfeeruncreditallocations.FieldAnnotations: + v, ok := value.(models.Annotations) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetTotal(v) + m.SetAnnotations(v) return nil - case chargeflatfeeruninvoicedusage.FieldRunID: + case chargeflatfeeruncreditallocations.FieldRunID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) @@ -57209,245 +56408,334 @@ func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetField(name string, value ent. m.SetRunID(v) return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) AddedFields() []string { - return nil +func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddedFields() []string { + var fields []string + if m.addsort_hint != nil { + fields = append(fields, chargeflatfeeruncreditallocations.FieldSortHint) + } + return fields } // 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 *ChargeFlatFeeRunInvoicedUsageMutation) AddedField(name string) (ent.Value, bool) { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case chargeflatfeeruncreditallocations.FieldSortHint: + return m.AddedSortHint() + } 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 *ChargeFlatFeeRunInvoicedUsageMutation) AddField(name string, value ent.Value) error { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddField(name string, value ent.Value) error { switch name { - } - return fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ClearedFields() []string { + case chargeflatfeeruncreditallocations.FieldSortHint: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddSortHint(v) + return nil + } + return fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID) { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID) + if m.FieldCleared(chargeflatfeeruncreditallocations.FieldLineID) { + fields = append(fields, chargeflatfeeruncreditallocations.FieldLineID) } - if m.FieldCleared(chargeflatfeeruninvoicedusage.FieldDeletedAt) { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldDeletedAt) + if m.FieldCleared(chargeflatfeeruncreditallocations.FieldCorrectsRealizationID) { + fields = append(fields, chargeflatfeeruncreditallocations.FieldCorrectsRealizationID) } - if m.FieldCleared(chargeflatfeeruninvoicedusage.FieldAnnotations) { - fields = append(fields, chargeflatfeeruninvoicedusage.FieldAnnotations) + if m.FieldCleared(chargeflatfeeruncreditallocations.FieldDeletedAt) { + fields = append(fields, chargeflatfeeruncreditallocations.FieldDeletedAt) + } + if m.FieldCleared(chargeflatfeeruncreditallocations.FieldAnnotations) { + fields = append(fields, chargeflatfeeruncreditallocations.FieldAnnotations) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) FieldCleared(name string) bool { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) 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 *ChargeFlatFeeRunInvoicedUsageMutation) ClearField(name string) error { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearField(name string) error { switch name { - case chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID: - m.ClearLedgerTransactionGroupID() + case chargeflatfeeruncreditallocations.FieldLineID: + m.ClearLineID() return nil - case chargeflatfeeruninvoicedusage.FieldDeletedAt: + case chargeflatfeeruncreditallocations.FieldCorrectsRealizationID: + m.ClearCorrectsRealizationID() + return nil + case chargeflatfeeruncreditallocations.FieldDeletedAt: m.ClearDeletedAt() return nil - case chargeflatfeeruninvoicedusage.FieldAnnotations: + case chargeflatfeeruncreditallocations.FieldAnnotations: m.ClearAnnotations() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage nullable field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunInvoicedUsageMutation) ResetField(name string) error { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetField(name string) error { switch name { - case chargeflatfeeruninvoicedusage.FieldServicePeriodFrom: + case chargeflatfeeruncreditallocations.FieldLineID: + m.ResetLineID() + return nil + case chargeflatfeeruncreditallocations.FieldAmount: + m.ResetAmount() + return nil + case chargeflatfeeruncreditallocations.FieldServicePeriodFrom: m.ResetServicePeriodFrom() return nil - case chargeflatfeeruninvoicedusage.FieldServicePeriodTo: + case chargeflatfeeruncreditallocations.FieldServicePeriodTo: m.ResetServicePeriodTo() return nil - case chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID: + case chargeflatfeeruncreditallocations.FieldLedgerTransactionGroupID: m.ResetLedgerTransactionGroupID() return nil - case chargeflatfeeruninvoicedusage.FieldNamespace: + case chargeflatfeeruncreditallocations.FieldSortHint: + m.ResetSortHint() + return nil + case chargeflatfeeruncreditallocations.FieldType: + m.ResetType() + return nil + case chargeflatfeeruncreditallocations.FieldCorrectsRealizationID: + m.ResetCorrectsRealizationID() + return nil + case chargeflatfeeruncreditallocations.FieldNamespace: m.ResetNamespace() return nil - case chargeflatfeeruninvoicedusage.FieldCreatedAt: + case chargeflatfeeruncreditallocations.FieldCreatedAt: m.ResetCreatedAt() return nil - case chargeflatfeeruninvoicedusage.FieldUpdatedAt: + case chargeflatfeeruncreditallocations.FieldUpdatedAt: m.ResetUpdatedAt() return nil - case chargeflatfeeruninvoicedusage.FieldDeletedAt: + case chargeflatfeeruncreditallocations.FieldDeletedAt: m.ResetDeletedAt() return nil - case chargeflatfeeruninvoicedusage.FieldAnnotations: + case chargeflatfeeruncreditallocations.FieldAnnotations: m.ResetAnnotations() return nil - case chargeflatfeeruninvoicedusage.FieldAmount: - m.ResetAmount() - return nil - case chargeflatfeeruninvoicedusage.FieldTaxesTotal: - m.ResetTaxesTotal() - return nil - case chargeflatfeeruninvoicedusage.FieldTaxesInclusiveTotal: - m.ResetTaxesInclusiveTotal() - return nil - case chargeflatfeeruninvoicedusage.FieldTaxesExclusiveTotal: - m.ResetTaxesExclusiveTotal() - return nil - case chargeflatfeeruninvoicedusage.FieldChargesTotal: - m.ResetChargesTotal() - return nil - case chargeflatfeeruninvoicedusage.FieldDiscountsTotal: - m.ResetDiscountsTotal() - return nil - case chargeflatfeeruninvoicedusage.FieldCreditsTotal: - m.ResetCreditsTotal() - return nil - case chargeflatfeeruninvoicedusage.FieldTotal: - m.ResetTotal() - return nil - case chargeflatfeeruninvoicedusage.FieldRunID: + case chargeflatfeeruncreditallocations.FieldRunID: m.ResetRunID() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) AddedEdges() []string { - edges := make([]string, 0, 1) +func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddedEdges() []string { + edges := make([]string, 0, 4) + if m.corrections != nil { + edges = append(edges, chargeflatfeeruncreditallocations.EdgeCorrections) + } + if m.allocation != nil { + edges = append(edges, chargeflatfeeruncreditallocations.EdgeAllocation) + } if m.run != nil { - edges = append(edges, chargeflatfeeruninvoicedusage.EdgeRun) + edges = append(edges, chargeflatfeeruncreditallocations.EdgeRun) + } + if m.billing_invoice_line != nil { + edges = append(edges, chargeflatfeeruncreditallocations.EdgeBillingInvoiceLine) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) AddedIDs(name string) []ent.Value { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) AddedIDs(name string) []ent.Value { switch name { - case chargeflatfeeruninvoicedusage.EdgeRun: + case chargeflatfeeruncreditallocations.EdgeCorrections: + ids := make([]ent.Value, 0, len(m.corrections)) + for id := range m.corrections { + ids = append(ids, id) + } + return ids + case chargeflatfeeruncreditallocations.EdgeAllocation: + if id := m.allocation; id != nil { + return []ent.Value{*id} + } + case chargeflatfeeruncreditallocations.EdgeRun: if id := m.run; id != nil { return []ent.Value{*id} } + case chargeflatfeeruncreditallocations.EdgeBillingInvoiceLine: + if id := m.billing_invoice_line; id != nil { + return []ent.Value{*id} + } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) +func (m *ChargeFlatFeeRunCreditAllocationsMutation) RemovedEdges() []string { + edges := make([]string, 0, 4) + if m.removedcorrections != nil { + edges = append(edges, chargeflatfeeruncreditallocations.EdgeCorrections) + } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) RemovedIDs(name string) []ent.Value { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) RemovedIDs(name string) []ent.Value { + switch name { + case chargeflatfeeruncreditallocations.EdgeCorrections: + ids := make([]ent.Value, 0, len(m.removedcorrections)) + for id := range m.removedcorrections { + ids = append(ids, id) + } + return ids + } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearedEdges() []string { + edges := make([]string, 0, 4) + if m.clearedcorrections { + edges = append(edges, chargeflatfeeruncreditallocations.EdgeCorrections) + } + if m.clearedallocation { + edges = append(edges, chargeflatfeeruncreditallocations.EdgeAllocation) + } if m.clearedrun { - edges = append(edges, chargeflatfeeruninvoicedusage.EdgeRun) + edges = append(edges, chargeflatfeeruncreditallocations.EdgeRun) + } + if m.clearedbilling_invoice_line { + edges = append(edges, chargeflatfeeruncreditallocations.EdgeBillingInvoiceLine) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *ChargeFlatFeeRunInvoicedUsageMutation) EdgeCleared(name string) bool { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) EdgeCleared(name string) bool { switch name { - case chargeflatfeeruninvoicedusage.EdgeRun: + case chargeflatfeeruncreditallocations.EdgeCorrections: + return m.clearedcorrections + case chargeflatfeeruncreditallocations.EdgeAllocation: + return m.clearedallocation + case chargeflatfeeruncreditallocations.EdgeRun: return m.clearedrun + case chargeflatfeeruncreditallocations.EdgeBillingInvoiceLine: + return m.clearedbilling_invoice_line } 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 *ChargeFlatFeeRunInvoicedUsageMutation) ClearEdge(name string) error { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ClearEdge(name string) error { switch name { - case chargeflatfeeruninvoicedusage.EdgeRun: + case chargeflatfeeruncreditallocations.EdgeAllocation: + m.ClearAllocation() + return nil + case chargeflatfeeruncreditallocations.EdgeRun: m.ClearRun() return nil + case chargeflatfeeruncreditallocations.EdgeBillingInvoiceLine: + m.ClearBillingInvoiceLine() + return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage unique edge %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations 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 *ChargeFlatFeeRunInvoicedUsageMutation) ResetEdge(name string) error { +func (m *ChargeFlatFeeRunCreditAllocationsMutation) ResetEdge(name string) error { switch name { - case chargeflatfeeruninvoicedusage.EdgeRun: + case chargeflatfeeruncreditallocations.EdgeCorrections: + m.ResetCorrections() + return nil + case chargeflatfeeruncreditallocations.EdgeAllocation: + m.ResetAllocation() + return nil + case chargeflatfeeruncreditallocations.EdgeRun: m.ResetRun() return nil + case chargeflatfeeruncreditallocations.EdgeBillingInvoiceLine: + m.ResetBillingInvoiceLine() + return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage edge %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRunCreditAllocations edge %s", name) } -// ChargeFlatFeeRunPaymentMutation represents an operation that mutates the ChargeFlatFeeRunPayment nodes in the graph. -type ChargeFlatFeeRunPaymentMutation struct { +// ChargeFlatFeeRunDetailedLineMutation represents an operation that mutates the ChargeFlatFeeRunDetailedLine nodes in the graph. +type ChargeFlatFeeRunDetailedLineMutation struct { config - op Op - typ string - id *string - invoice_id *string - service_period_from *time.Time - service_period_to *time.Time - status *payment.Status - amount *alpacadecimal.Decimal - authorized_transaction_group_id *string - authorized_at *time.Time - settled_transaction_group_id *string - settled_at *time.Time - namespace *string - created_at *time.Time - updated_at *time.Time - deleted_at *time.Time - annotations *models.Annotations - clearedFields map[string]struct{} - billing_invoice_line *string - clearedbilling_invoice_line bool - run *string - clearedrun bool - done bool - oldValue func(context.Context) (*ChargeFlatFeeRunPayment, error) - predicates []predicate.ChargeFlatFeeRunPayment + op Op + typ string + id *string + currency *currencyx.Code + service_period_start *time.Time + service_period_end *time.Time + quantity *alpacadecimal.Decimal + invoicing_app_external_id *string + child_unique_reference_id *string + per_unit_amount *alpacadecimal.Decimal + category *stddetailedline.Category + payment_term *productcatalog.PaymentTermType + index *int + addindex *int + credits_applied **creditsapplied.CreditsApplied + 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 + amount *alpacadecimal.Decimal + taxes_total *alpacadecimal.Decimal + taxes_inclusive_total *alpacadecimal.Decimal + taxes_exclusive_total *alpacadecimal.Decimal + charges_total *alpacadecimal.Decimal + discounts_total *alpacadecimal.Decimal + credits_total *alpacadecimal.Decimal + total *alpacadecimal.Decimal + pricer_reference_id *string + clearedFields map[string]struct{} + run *string + clearedrun bool + done bool + oldValue func(context.Context) (*ChargeFlatFeeRunDetailedLine, error) + predicates []predicate.ChargeFlatFeeRunDetailedLine } -var _ ent.Mutation = (*ChargeFlatFeeRunPaymentMutation)(nil) +var _ ent.Mutation = (*ChargeFlatFeeRunDetailedLineMutation)(nil) -// chargeflatfeerunpaymentOption allows management of the mutation configuration using functional options. -type chargeflatfeerunpaymentOption func(*ChargeFlatFeeRunPaymentMutation) +// chargeflatfeerundetailedlineOption allows management of the mutation configuration using functional options. +type chargeflatfeerundetailedlineOption func(*ChargeFlatFeeRunDetailedLineMutation) -// newChargeFlatFeeRunPaymentMutation creates new mutation for the ChargeFlatFeeRunPayment entity. -func newChargeFlatFeeRunPaymentMutation(c config, op Op, opts ...chargeflatfeerunpaymentOption) *ChargeFlatFeeRunPaymentMutation { - m := &ChargeFlatFeeRunPaymentMutation{ +// newChargeFlatFeeRunDetailedLineMutation creates new mutation for the ChargeFlatFeeRunDetailedLine entity. +func newChargeFlatFeeRunDetailedLineMutation(c config, op Op, opts ...chargeflatfeerundetailedlineOption) *ChargeFlatFeeRunDetailedLineMutation { + m := &ChargeFlatFeeRunDetailedLineMutation{ config: c, op: op, - typ: TypeChargeFlatFeeRunPayment, + typ: TypeChargeFlatFeeRunDetailedLine, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -57456,20 +56744,20 @@ func newChargeFlatFeeRunPaymentMutation(c config, op Op, opts ...chargeflatfeeru return m } -// withChargeFlatFeeRunPaymentID sets the ID field of the mutation. -func withChargeFlatFeeRunPaymentID(id string) chargeflatfeerunpaymentOption { - return func(m *ChargeFlatFeeRunPaymentMutation) { +// withChargeFlatFeeRunDetailedLineID sets the ID field of the mutation. +func withChargeFlatFeeRunDetailedLineID(id string) chargeflatfeerundetailedlineOption { + return func(m *ChargeFlatFeeRunDetailedLineMutation) { var ( err error once sync.Once - value *ChargeFlatFeeRunPayment + value *ChargeFlatFeeRunDetailedLine ) - m.oldValue = func(ctx context.Context) (*ChargeFlatFeeRunPayment, error) { + m.oldValue = func(ctx context.Context) (*ChargeFlatFeeRunDetailedLine, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { - value, err = m.Client().ChargeFlatFeeRunPayment.Get(ctx, id) + value, err = m.Client().ChargeFlatFeeRunDetailedLine.Get(ctx, id) } }) return value, err @@ -57478,10 +56766,10 @@ func withChargeFlatFeeRunPaymentID(id string) chargeflatfeerunpaymentOption { } } -// withChargeFlatFeeRunPayment sets the old ChargeFlatFeeRunPayment of the mutation. -func withChargeFlatFeeRunPayment(node *ChargeFlatFeeRunPayment) chargeflatfeerunpaymentOption { - return func(m *ChargeFlatFeeRunPaymentMutation) { - m.oldValue = func(context.Context) (*ChargeFlatFeeRunPayment, error) { +// withChargeFlatFeeRunDetailedLine sets the old ChargeFlatFeeRunDetailedLine of the mutation. +func withChargeFlatFeeRunDetailedLine(node *ChargeFlatFeeRunDetailedLine) chargeflatfeerundetailedlineOption { + return func(m *ChargeFlatFeeRunDetailedLineMutation) { + m.oldValue = func(context.Context) (*ChargeFlatFeeRunDetailedLine, error) { return node, nil } m.id = &node.ID @@ -57490,7 +56778,7 @@ func withChargeFlatFeeRunPayment(node *ChargeFlatFeeRunPayment) chargeflatfeerun // 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 ChargeFlatFeeRunPaymentMutation) Client() *Client { +func (m ChargeFlatFeeRunDetailedLineMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -57498,7 +56786,7 @@ func (m ChargeFlatFeeRunPaymentMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m ChargeFlatFeeRunPaymentMutation) Tx() (*Tx, error) { +func (m ChargeFlatFeeRunDetailedLineMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("db: mutation is not running in a transaction") } @@ -57508,14 +56796,14 @@ func (m ChargeFlatFeeRunPaymentMutation) Tx() (*Tx, error) { } // SetID sets the value of the id field. Note that this -// operation is only accepted on creation of ChargeFlatFeeRunPayment entities. -func (m *ChargeFlatFeeRunPaymentMutation) SetID(id string) { +// operation is only accepted on creation of ChargeFlatFeeRunDetailedLine entities. +func (m *ChargeFlatFeeRunDetailedLineMutation) 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 *ChargeFlatFeeRunPaymentMutation) ID() (id string, exists bool) { +func (m *ChargeFlatFeeRunDetailedLineMutation) ID() (id string, exists bool) { if m.id == nil { return } @@ -57526,7 +56814,7 @@ func (m *ChargeFlatFeeRunPaymentMutation) ID() (id string, exists bool) { // 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 *ChargeFlatFeeRunPaymentMutation) IDs(ctx context.Context) ([]string, error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() @@ -57535,431 +56823,537 @@ func (m *ChargeFlatFeeRunPaymentMutation) IDs(ctx context.Context) ([]string, er } fallthrough case m.op.Is(OpUpdate | OpDelete): - return m.Client().ChargeFlatFeeRunPayment.Query().Where(m.predicates...).IDs(ctx) + return m.Client().ChargeFlatFeeRunDetailedLine.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } -// SetLineID sets the "line_id" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetLineID(s string) { - m.billing_invoice_line = &s +// SetCurrency sets the "currency" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetCurrency(c currencyx.Code) { + m.currency = &c } -// LineID returns the value of the "line_id" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) LineID() (r string, exists bool) { - v := m.billing_invoice_line +// Currency returns the value of the "currency" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) Currency() (r currencyx.Code, exists bool) { + v := m.currency if v == nil { return } return *v, true } -// OldLineID returns the old "line_id" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldCurrency returns the old "currency" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldLineID(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldCurrency(ctx context.Context) (v *currencyx.Code, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldLineID is only allowed on UpdateOne operations") + return v, errors.New("OldCurrency is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldLineID requires an ID field in the mutation") + 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 OldLineID: %w", err) + return v, fmt.Errorf("querying old value for OldCurrency: %w", err) } - return oldValue.LineID, nil + return oldValue.Currency, nil } -// ResetLineID resets all changes to the "line_id" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetLineID() { - m.billing_invoice_line = nil +// ClearCurrency clears the value of the "currency" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ClearCurrency() { + m.currency = nil + m.clearedFields[chargeflatfeerundetailedline.FieldCurrency] = struct{}{} } -// SetInvoiceID sets the "invoice_id" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetInvoiceID(s string) { - m.invoice_id = &s +// CurrencyCleared returns if the "currency" field was cleared in this mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) CurrencyCleared() bool { + _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldCurrency] + return ok } -// InvoiceID returns the value of the "invoice_id" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) InvoiceID() (r string, exists bool) { - v := m.invoice_id +// ResetCurrency resets all changes to the "currency" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetCurrency() { + m.currency = nil + delete(m.clearedFields, chargeflatfeerundetailedline.FieldCurrency) +} + +// SetServicePeriodStart sets the "service_period_start" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetServicePeriodStart(t time.Time) { + m.service_period_start = &t +} + +// ServicePeriodStart returns the value of the "service_period_start" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) ServicePeriodStart() (r time.Time, exists bool) { + v := m.service_period_start if v == nil { return } return *v, true } -// OldInvoiceID returns the old "invoice_id" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldServicePeriodStart returns the old "service_period_start" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldInvoiceID(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldServicePeriodStart(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldInvoiceID is only allowed on UpdateOne operations") + return v, errors.New("OldServicePeriodStart 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") + 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 OldInvoiceID: %w", err) + return v, fmt.Errorf("querying old value for OldServicePeriodStart: %w", err) } - return oldValue.InvoiceID, nil + return oldValue.ServicePeriodStart, nil } -// ResetInvoiceID resets all changes to the "invoice_id" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetInvoiceID() { - m.invoice_id = nil +// ResetServicePeriodStart resets all changes to the "service_period_start" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetServicePeriodStart() { + m.service_period_start = nil } -// SetServicePeriodFrom sets the "service_period_from" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetServicePeriodFrom(t time.Time) { - m.service_period_from = &t +// SetServicePeriodEnd sets the "service_period_end" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetServicePeriodEnd(t time.Time) { + m.service_period_end = &t } -// ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) ServicePeriodFrom() (r time.Time, exists bool) { - v := m.service_period_from +// ServicePeriodEnd returns the value of the "service_period_end" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) ServicePeriodEnd() (r time.Time, exists bool) { + v := m.service_period_end if v == nil { return } return *v, true } -// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldServicePeriodEnd returns the old "service_period_end" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldServicePeriodEnd(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") + return v, errors.New("OldServicePeriodEnd is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldServicePeriodFrom requires an ID field in the mutation") + 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 OldServicePeriodFrom: %w", err) + return v, fmt.Errorf("querying old value for OldServicePeriodEnd: %w", err) } - return oldValue.ServicePeriodFrom, nil + return oldValue.ServicePeriodEnd, nil } -// ResetServicePeriodFrom resets all changes to the "service_period_from" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetServicePeriodFrom() { - m.service_period_from = nil +// ResetServicePeriodEnd resets all changes to the "service_period_end" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetServicePeriodEnd() { + m.service_period_end = nil } -// SetServicePeriodTo sets the "service_period_to" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetServicePeriodTo(t time.Time) { - m.service_period_to = &t +// SetQuantity sets the "quantity" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetQuantity(a alpacadecimal.Decimal) { + m.quantity = &a } -// ServicePeriodTo returns the value of the "service_period_to" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) ServicePeriodTo() (r time.Time, exists bool) { - v := m.service_period_to +// Quantity returns the value of the "quantity" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) Quantity() (r alpacadecimal.Decimal, exists bool) { + v := m.quantity if v == nil { return } return *v, true } -// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldQuantity returns the old "quantity" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldQuantity(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") + return v, errors.New("OldQuantity is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldServicePeriodTo requires an ID field in the mutation") + return v, errors.New("OldQuantity requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldServicePeriodTo: %w", err) + return v, fmt.Errorf("querying old value for OldQuantity: %w", err) } - return oldValue.ServicePeriodTo, nil + return oldValue.Quantity, nil } -// ResetServicePeriodTo resets all changes to the "service_period_to" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetServicePeriodTo() { - m.service_period_to = nil +// ResetQuantity resets all changes to the "quantity" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetQuantity() { + m.quantity = nil } -// SetStatus sets the "status" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetStatus(pa payment.Status) { - m.status = &pa +// SetInvoicingAppExternalID sets the "invoicing_app_external_id" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetInvoicingAppExternalID(s string) { + m.invoicing_app_external_id = &s } -// Status returns the value of the "status" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) Status() (r payment.Status, exists bool) { - v := m.status +// InvoicingAppExternalID returns the value of the "invoicing_app_external_id" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) InvoicingAppExternalID() (r string, exists bool) { + v := m.invoicing_app_external_id if v == nil { return } return *v, true } -// OldStatus returns the old "status" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldInvoicingAppExternalID returns the old "invoicing_app_external_id" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldStatus(ctx context.Context) (v payment.Status, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldInvoicingAppExternalID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldStatus is only allowed on UpdateOne operations") + return v, errors.New("OldInvoicingAppExternalID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldStatus requires an ID field in the mutation") + return v, errors.New("OldInvoicingAppExternalID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldStatus: %w", err) + return v, fmt.Errorf("querying old value for OldInvoicingAppExternalID: %w", err) } - return oldValue.Status, nil + return oldValue.InvoicingAppExternalID, nil } -// ResetStatus resets all changes to the "status" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetStatus() { - m.status = nil +// ClearInvoicingAppExternalID clears the value of the "invoicing_app_external_id" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ClearInvoicingAppExternalID() { + m.invoicing_app_external_id = nil + m.clearedFields[chargeflatfeerundetailedline.FieldInvoicingAppExternalID] = struct{}{} } -// SetAmount sets the "amount" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetAmount(a alpacadecimal.Decimal) { - m.amount = &a +// InvoicingAppExternalIDCleared returns if the "invoicing_app_external_id" field was cleared in this mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) InvoicingAppExternalIDCleared() bool { + _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldInvoicingAppExternalID] + return ok } -// Amount returns the value of the "amount" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) Amount() (r alpacadecimal.Decimal, exists bool) { - v := m.amount - if v == nil { - return - } +// ResetInvoicingAppExternalID resets all changes to the "invoicing_app_external_id" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetInvoicingAppExternalID() { + m.invoicing_app_external_id = nil + delete(m.clearedFields, chargeflatfeerundetailedline.FieldInvoicingAppExternalID) +} + +// SetChildUniqueReferenceID sets the "child_unique_reference_id" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) 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 *ChargeFlatFeeRunDetailedLineMutation) ChildUniqueReferenceID() (r string, exists bool) { + v := m.child_unique_reference_id + if v == nil { + return + } return *v, true } -// OldAmount returns the old "amount" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldChildUniqueReferenceID returns the old "child_unique_reference_id" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldChildUniqueReferenceID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAmount is only allowed on UpdateOne operations") + return v, errors.New("OldChildUniqueReferenceID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAmount requires an ID field in the mutation") + 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 OldAmount: %w", err) + return v, fmt.Errorf("querying old value for OldChildUniqueReferenceID: %w", err) } - return oldValue.Amount, nil + return oldValue.ChildUniqueReferenceID, nil } -// ResetAmount resets all changes to the "amount" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetAmount() { - m.amount = nil +// ResetChildUniqueReferenceID resets all changes to the "child_unique_reference_id" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetChildUniqueReferenceID() { + m.child_unique_reference_id = nil } -// SetAuthorizedTransactionGroupID sets the "authorized_transaction_group_id" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetAuthorizedTransactionGroupID(s string) { - m.authorized_transaction_group_id = &s +// SetPerUnitAmount sets the "per_unit_amount" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetPerUnitAmount(a alpacadecimal.Decimal) { + m.per_unit_amount = &a } -// AuthorizedTransactionGroupID returns the value of the "authorized_transaction_group_id" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) AuthorizedTransactionGroupID() (r string, exists bool) { - v := m.authorized_transaction_group_id +// PerUnitAmount returns the value of the "per_unit_amount" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) PerUnitAmount() (r alpacadecimal.Decimal, exists bool) { + v := m.per_unit_amount if v == nil { return } return *v, true } -// OldAuthorizedTransactionGroupID returns the old "authorized_transaction_group_id" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldPerUnitAmount returns the old "per_unit_amount" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldAuthorizedTransactionGroupID(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldPerUnitAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAuthorizedTransactionGroupID is only allowed on UpdateOne operations") + return v, errors.New("OldPerUnitAmount is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAuthorizedTransactionGroupID requires an ID field in the mutation") + return v, errors.New("OldPerUnitAmount requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldAuthorizedTransactionGroupID: %w", err) + return v, fmt.Errorf("querying old value for OldPerUnitAmount: %w", err) } - return oldValue.AuthorizedTransactionGroupID, nil + return oldValue.PerUnitAmount, nil } -// ClearAuthorizedTransactionGroupID clears the value of the "authorized_transaction_group_id" field. -func (m *ChargeFlatFeeRunPaymentMutation) ClearAuthorizedTransactionGroupID() { - m.authorized_transaction_group_id = nil - m.clearedFields[chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID] = struct{}{} +// ResetPerUnitAmount resets all changes to the "per_unit_amount" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetPerUnitAmount() { + m.per_unit_amount = nil } -// AuthorizedTransactionGroupIDCleared returns if the "authorized_transaction_group_id" field was cleared in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) AuthorizedTransactionGroupIDCleared() bool { - _, ok := m.clearedFields[chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID] - return ok +// SetCategory sets the "category" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetCategory(s stddetailedline.Category) { + m.category = &s } -// ResetAuthorizedTransactionGroupID resets all changes to the "authorized_transaction_group_id" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetAuthorizedTransactionGroupID() { - m.authorized_transaction_group_id = nil - delete(m.clearedFields, chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID) +// Category returns the value of the "category" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) Category() (r stddetailedline.Category, exists bool) { + v := m.category + if v == nil { + return + } + return *v, true } -// SetAuthorizedAt sets the "authorized_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetAuthorizedAt(t time.Time) { - m.authorized_at = &t +// OldCategory returns the old "category" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldCategory(ctx context.Context) (v stddetailedline.Category, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCategory is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCategory requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCategory: %w", err) + } + return oldValue.Category, nil } -// AuthorizedAt returns the value of the "authorized_at" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) AuthorizedAt() (r time.Time, exists bool) { - v := m.authorized_at +// ResetCategory resets all changes to the "category" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetCategory() { + m.category = nil +} + +// SetPaymentTerm sets the "payment_term" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetPaymentTerm(ptt productcatalog.PaymentTermType) { + m.payment_term = &ptt +} + +// PaymentTerm returns the value of the "payment_term" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) PaymentTerm() (r productcatalog.PaymentTermType, exists bool) { + v := m.payment_term if v == nil { return } return *v, true } -// OldAuthorizedAt returns the old "authorized_at" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldPaymentTerm returns the old "payment_term" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldAuthorizedAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldPaymentTerm(ctx context.Context) (v productcatalog.PaymentTermType, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAuthorizedAt is only allowed on UpdateOne operations") + return v, errors.New("OldPaymentTerm is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAuthorizedAt requires an ID field in the mutation") + return v, errors.New("OldPaymentTerm requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldAuthorizedAt: %w", err) + return v, fmt.Errorf("querying old value for OldPaymentTerm: %w", err) } - return oldValue.AuthorizedAt, nil + return oldValue.PaymentTerm, nil } -// ClearAuthorizedAt clears the value of the "authorized_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) ClearAuthorizedAt() { - m.authorized_at = nil - m.clearedFields[chargeflatfeerunpayment.FieldAuthorizedAt] = struct{}{} +// ResetPaymentTerm resets all changes to the "payment_term" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetPaymentTerm() { + m.payment_term = nil } -// AuthorizedAtCleared returns if the "authorized_at" field was cleared in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) AuthorizedAtCleared() bool { - _, ok := m.clearedFields[chargeflatfeerunpayment.FieldAuthorizedAt] +// SetIndex sets the "index" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetIndex(i int) { + m.index = &i + m.addindex = nil +} + +// Index returns the value of the "index" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) Index() (r int, exists bool) { + v := m.index + if v == nil { + return + } + return *v, true +} + +// OldIndex returns the old "index" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldIndex(ctx context.Context) (v *int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIndex is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIndex requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIndex: %w", err) + } + return oldValue.Index, nil +} + +// AddIndex adds i to the "index" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) AddIndex(i int) { + if m.addindex != nil { + *m.addindex += i + } else { + m.addindex = &i + } +} + +// AddedIndex returns the value that was added to the "index" field in this mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) AddedIndex() (r int, exists bool) { + v := m.addindex + if v == nil { + return + } + return *v, true +} + +// ClearIndex clears the value of the "index" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ClearIndex() { + m.index = nil + m.addindex = nil + m.clearedFields[chargeflatfeerundetailedline.FieldIndex] = struct{}{} +} + +// IndexCleared returns if the "index" field was cleared in this mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) IndexCleared() bool { + _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldIndex] return ok } -// ResetAuthorizedAt resets all changes to the "authorized_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetAuthorizedAt() { - m.authorized_at = nil - delete(m.clearedFields, chargeflatfeerunpayment.FieldAuthorizedAt) +// ResetIndex resets all changes to the "index" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetIndex() { + m.index = nil + m.addindex = nil + delete(m.clearedFields, chargeflatfeerundetailedline.FieldIndex) } -// SetSettledTransactionGroupID sets the "settled_transaction_group_id" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetSettledTransactionGroupID(s string) { - m.settled_transaction_group_id = &s +// SetCreditsApplied sets the "credits_applied" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetCreditsApplied(ca *creditsapplied.CreditsApplied) { + m.credits_applied = &ca } -// SettledTransactionGroupID returns the value of the "settled_transaction_group_id" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) SettledTransactionGroupID() (r string, exists bool) { - v := m.settled_transaction_group_id +// CreditsApplied returns the value of the "credits_applied" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) CreditsApplied() (r *creditsapplied.CreditsApplied, exists bool) { + v := m.credits_applied if v == nil { return } return *v, true } -// OldSettledTransactionGroupID returns the old "settled_transaction_group_id" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldCreditsApplied returns the old "credits_applied" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldSettledTransactionGroupID(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldCreditsApplied(ctx context.Context) (v *creditsapplied.CreditsApplied, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSettledTransactionGroupID is only allowed on UpdateOne operations") + return v, errors.New("OldCreditsApplied is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSettledTransactionGroupID requires an ID field in the mutation") + return v, errors.New("OldCreditsApplied requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldSettledTransactionGroupID: %w", err) + return v, fmt.Errorf("querying old value for OldCreditsApplied: %w", err) } - return oldValue.SettledTransactionGroupID, nil + return oldValue.CreditsApplied, nil } -// ClearSettledTransactionGroupID clears the value of the "settled_transaction_group_id" field. -func (m *ChargeFlatFeeRunPaymentMutation) ClearSettledTransactionGroupID() { - m.settled_transaction_group_id = nil - m.clearedFields[chargeflatfeerunpayment.FieldSettledTransactionGroupID] = struct{}{} +// ClearCreditsApplied clears the value of the "credits_applied" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ClearCreditsApplied() { + m.credits_applied = nil + m.clearedFields[chargeflatfeerundetailedline.FieldCreditsApplied] = struct{}{} } -// SettledTransactionGroupIDCleared returns if the "settled_transaction_group_id" field was cleared in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) SettledTransactionGroupIDCleared() bool { - _, ok := m.clearedFields[chargeflatfeerunpayment.FieldSettledTransactionGroupID] +// CreditsAppliedCleared returns if the "credits_applied" field was cleared in this mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) CreditsAppliedCleared() bool { + _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldCreditsApplied] return ok } -// ResetSettledTransactionGroupID resets all changes to the "settled_transaction_group_id" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetSettledTransactionGroupID() { - m.settled_transaction_group_id = nil - delete(m.clearedFields, chargeflatfeerunpayment.FieldSettledTransactionGroupID) +// ResetCreditsApplied resets all changes to the "credits_applied" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetCreditsApplied() { + m.credits_applied = nil + delete(m.clearedFields, chargeflatfeerundetailedline.FieldCreditsApplied) } -// SetSettledAt sets the "settled_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetSettledAt(t time.Time) { - m.settled_at = &t +// SetAnnotations sets the "annotations" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetAnnotations(value models.Annotations) { + m.annotations = &value } -// SettledAt returns the value of the "settled_at" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) SettledAt() (r time.Time, exists bool) { - v := m.settled_at +// Annotations returns the value of the "annotations" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) Annotations() (r models.Annotations, exists bool) { + v := m.annotations if v == nil { return } return *v, true } -// OldSettledAt returns the old "settled_at" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldAnnotations returns the old "annotations" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldSettledAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldAnnotations(ctx context.Context) (v models.Annotations, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSettledAt is only allowed on UpdateOne operations") + return v, errors.New("OldAnnotations is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSettledAt requires an ID field in the mutation") + 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 OldSettledAt: %w", err) + return v, fmt.Errorf("querying old value for OldAnnotations: %w", err) } - return oldValue.SettledAt, nil + return oldValue.Annotations, nil } -// ClearSettledAt clears the value of the "settled_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) ClearSettledAt() { - m.settled_at = nil - m.clearedFields[chargeflatfeerunpayment.FieldSettledAt] = struct{}{} +// ClearAnnotations clears the value of the "annotations" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ClearAnnotations() { + m.annotations = nil + m.clearedFields[chargeflatfeerundetailedline.FieldAnnotations] = struct{}{} } -// SettledAtCleared returns if the "settled_at" field was cleared in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) SettledAtCleared() bool { - _, ok := m.clearedFields[chargeflatfeerunpayment.FieldSettledAt] +// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) AnnotationsCleared() bool { + _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldAnnotations] return ok } -// ResetSettledAt resets all changes to the "settled_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetSettledAt() { - m.settled_at = nil - delete(m.clearedFields, chargeflatfeerunpayment.FieldSettledAt) +// ResetAnnotations resets all changes to the "annotations" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetAnnotations() { + m.annotations = nil + delete(m.clearedFields, chargeflatfeerundetailedline.FieldAnnotations) } // SetNamespace sets the "namespace" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetNamespace(s string) { +func (m *ChargeFlatFeeRunDetailedLineMutation) SetNamespace(s string) { m.namespace = &s } // Namespace returns the value of the "namespace" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) Namespace() (r string, exists bool) { +func (m *ChargeFlatFeeRunDetailedLineMutation) Namespace() (r string, exists bool) { v := m.namespace if v == nil { return @@ -57967,10 +57361,10 @@ func (m *ChargeFlatFeeRunPaymentMutation) Namespace() (r string, exists bool) { return *v, true } -// OldNamespace returns the old "namespace" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldNamespace returns the old "namespace" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldNamespace(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldNamespace(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldNamespace is only allowed on UpdateOne operations") } @@ -57985,17 +57379,66 @@ func (m *ChargeFlatFeeRunPaymentMutation) OldNamespace(ctx context.Context) (v s } // ResetNamespace resets all changes to the "namespace" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetNamespace() { +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetNamespace() { m.namespace = nil } +// SetMetadata sets the "metadata" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetMetadata(value map[string]string) { + m.metadata = &value +} + +// Metadata returns the value of the "metadata" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) 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 ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) 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 *ChargeFlatFeeRunDetailedLineMutation) ClearMetadata() { + m.metadata = nil + m.clearedFields[chargeflatfeerundetailedline.FieldMetadata] = struct{}{} +} + +// MetadataCleared returns if the "metadata" field was cleared in this mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) MetadataCleared() bool { + _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldMetadata] + return ok +} + +// ResetMetadata resets all changes to the "metadata" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetMetadata() { + m.metadata = nil + delete(m.clearedFields, chargeflatfeerundetailedline.FieldMetadata) +} + // SetCreatedAt sets the "created_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetCreatedAt(t time.Time) { +func (m *ChargeFlatFeeRunDetailedLineMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) CreatedAt() (r time.Time, exists bool) { +func (m *ChargeFlatFeeRunDetailedLineMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return @@ -58003,10 +57446,10 @@ func (m *ChargeFlatFeeRunPaymentMutation) CreatedAt() (r time.Time, exists bool) return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) 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") } @@ -58021,17 +57464,17 @@ func (m *ChargeFlatFeeRunPaymentMutation) OldCreatedAt(ctx context.Context) (v t } // ResetCreatedAt resets all changes to the "created_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetCreatedAt() { +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetUpdatedAt(t time.Time) { +func (m *ChargeFlatFeeRunDetailedLineMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) UpdatedAt() (r time.Time, exists bool) { +func (m *ChargeFlatFeeRunDetailedLineMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return @@ -58039,10 +57482,10 @@ func (m *ChargeFlatFeeRunPaymentMutation) UpdatedAt() (r time.Time, exists bool) return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) 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") } @@ -58057,17 +57500,17 @@ func (m *ChargeFlatFeeRunPaymentMutation) OldUpdatedAt(ctx context.Context) (v t } // ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetUpdatedAt() { +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetUpdatedAt() { m.updated_at = nil } // SetDeletedAt sets the "deleted_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetDeletedAt(t time.Time) { +func (m *ChargeFlatFeeRunDetailedLineMutation) SetDeletedAt(t time.Time) { m.deleted_at = &t } // DeletedAt returns the value of the "deleted_at" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) DeletedAt() (r time.Time, exists bool) { +func (m *ChargeFlatFeeRunDetailedLineMutation) DeletedAt() (r time.Time, exists bool) { v := m.deleted_at if v == nil { return @@ -58075,10 +57518,10 @@ func (m *ChargeFlatFeeRunPaymentMutation) DeletedAt() (r time.Time, exists bool) return *v, true } -// OldDeletedAt returns the old "deleted_at" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldDeletedAt returns the old "deleted_at" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) 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") } @@ -58093,163 +57536,483 @@ func (m *ChargeFlatFeeRunPaymentMutation) OldDeletedAt(ctx context.Context) (v * } // ClearDeletedAt clears the value of the "deleted_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) ClearDeletedAt() { +func (m *ChargeFlatFeeRunDetailedLineMutation) ClearDeletedAt() { m.deleted_at = nil - m.clearedFields[chargeflatfeerunpayment.FieldDeletedAt] = struct{}{} + m.clearedFields[chargeflatfeerundetailedline.FieldDeletedAt] = struct{}{} } // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) DeletedAtCleared() bool { - _, ok := m.clearedFields[chargeflatfeerunpayment.FieldDeletedAt] +func (m *ChargeFlatFeeRunDetailedLineMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldDeletedAt] return ok } // ResetDeletedAt resets all changes to the "deleted_at" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetDeletedAt() { +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetDeletedAt() { m.deleted_at = nil - delete(m.clearedFields, chargeflatfeerunpayment.FieldDeletedAt) + delete(m.clearedFields, chargeflatfeerundetailedline.FieldDeletedAt) } -// SetAnnotations sets the "annotations" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetAnnotations(value models.Annotations) { - m.annotations = &value +// SetName sets the "name" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetName(s string) { + m.name = &s } -// Annotations returns the value of the "annotations" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) Annotations() (r models.Annotations, exists bool) { - v := m.annotations +// Name returns the value of the "name" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) Name() (r string, exists bool) { + v := m.name if v == nil { return } return *v, true } -// OldAnnotations returns the old "annotations" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldName returns the old "name" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldAnnotations(ctx context.Context) (v models.Annotations, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAnnotations is only allowed on UpdateOne operations") + return v, errors.New("OldName 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") + 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 OldAnnotations: %w", err) + return v, fmt.Errorf("querying old value for OldName: %w", err) } - return oldValue.Annotations, nil -} - -// ClearAnnotations clears the value of the "annotations" field. -func (m *ChargeFlatFeeRunPaymentMutation) ClearAnnotations() { - m.annotations = nil - m.clearedFields[chargeflatfeerunpayment.FieldAnnotations] = struct{}{} -} - -// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) AnnotationsCleared() bool { - _, ok := m.clearedFields[chargeflatfeerunpayment.FieldAnnotations] - return ok + return oldValue.Name, nil } -// ResetAnnotations resets all changes to the "annotations" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetAnnotations() { - m.annotations = nil - delete(m.clearedFields, chargeflatfeerunpayment.FieldAnnotations) +// ResetName resets all changes to the "name" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetName() { + m.name = nil } -// SetRunID sets the "run_id" field. -func (m *ChargeFlatFeeRunPaymentMutation) SetRunID(s string) { - m.run = &s +// SetDescription sets the "description" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetDescription(s string) { + m.description = &s } -// RunID returns the value of the "run_id" field in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) RunID() (r string, exists bool) { - v := m.run +// Description returns the value of the "description" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) Description() (r string, exists bool) { + v := m.description if v == nil { return } return *v, true } -// OldRunID returns the old "run_id" field's value of the ChargeFlatFeeRunPayment entity. -// If the ChargeFlatFeeRunPayment object wasn't provided to the builder, the object is fetched from the database. +// OldDescription returns the old "description" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) OldRunID(ctx context.Context) (v string, err error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldDescription(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldRunID is only allowed on UpdateOne operations") + return v, errors.New("OldDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldRunID requires an ID field in the mutation") + 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 OldRunID: %w", err) + return v, fmt.Errorf("querying old value for OldDescription: %w", err) } - return oldValue.RunID, nil + return oldValue.Description, nil } -// ResetRunID resets all changes to the "run_id" field. -func (m *ChargeFlatFeeRunPaymentMutation) ResetRunID() { - m.run = nil +// ClearDescription clears the value of the "description" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ClearDescription() { + m.description = nil + m.clearedFields[chargeflatfeerundetailedline.FieldDescription] = struct{}{} } -// SetBillingInvoiceLineID sets the "billing_invoice_line" edge to the BillingInvoiceLine entity by id. -func (m *ChargeFlatFeeRunPaymentMutation) SetBillingInvoiceLineID(id string) { - m.billing_invoice_line = &id +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[chargeflatfeerundetailedline.FieldDescription] + return ok } -// ClearBillingInvoiceLine clears the "billing_invoice_line" edge to the BillingInvoiceLine entity. -func (m *ChargeFlatFeeRunPaymentMutation) ClearBillingInvoiceLine() { - m.clearedbilling_invoice_line = true - m.clearedFields[chargeflatfeerunpayment.FieldLineID] = struct{}{} +// ResetDescription resets all changes to the "description" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, chargeflatfeerundetailedline.FieldDescription) } -// BillingInvoiceLineCleared reports if the "billing_invoice_line" edge to the BillingInvoiceLine entity was cleared. -func (m *ChargeFlatFeeRunPaymentMutation) BillingInvoiceLineCleared() bool { - return m.clearedbilling_invoice_line +// SetAmount sets the "amount" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetAmount(a alpacadecimal.Decimal) { + m.amount = &a } -// BillingInvoiceLineID returns the "billing_invoice_line" edge ID in the mutation. -func (m *ChargeFlatFeeRunPaymentMutation) BillingInvoiceLineID() (id string, exists bool) { - if m.billing_invoice_line != nil { - return *m.billing_invoice_line, true +// Amount returns the value of the "amount" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) Amount() (r alpacadecimal.Decimal, exists bool) { + v := m.amount + if v == nil { + return } - return + return *v, true } -// BillingInvoiceLineIDs returns the "billing_invoice_line" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// BillingInvoiceLineID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeRunPaymentMutation) BillingInvoiceLineIDs() (ids []string) { - if id := m.billing_invoice_line; id != nil { - ids = append(ids, *id) +// OldAmount returns the old "amount" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAmount is only allowed on UpdateOne operations") } - return + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAmount requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAmount: %w", err) + } + return oldValue.Amount, nil } -// ResetBillingInvoiceLine resets all changes to the "billing_invoice_line" edge. -func (m *ChargeFlatFeeRunPaymentMutation) ResetBillingInvoiceLine() { - m.billing_invoice_line = nil - m.clearedbilling_invoice_line = false +// ResetAmount resets all changes to the "amount" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetAmount() { + m.amount = nil +} + +// SetTaxesTotal sets the "taxes_total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetTaxesTotal(a alpacadecimal.Decimal) { + m.taxes_total = &a +} + +// TaxesTotal returns the value of the "taxes_total" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) TaxesTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.taxes_total + if v == nil { + return + } + return *v, true +} + +// OldTaxesTotal returns the old "taxes_total" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldTaxesTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTaxesTotal is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTaxesTotal requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTaxesTotal: %w", err) + } + return oldValue.TaxesTotal, nil +} + +// ResetTaxesTotal resets all changes to the "taxes_total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetTaxesTotal() { + m.taxes_total = nil +} + +// SetTaxesInclusiveTotal sets the "taxes_inclusive_total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetTaxesInclusiveTotal(a alpacadecimal.Decimal) { + m.taxes_inclusive_total = &a +} + +// TaxesInclusiveTotal returns the value of the "taxes_inclusive_total" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) TaxesInclusiveTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.taxes_inclusive_total + if v == nil { + return + } + return *v, true +} + +// OldTaxesInclusiveTotal returns the old "taxes_inclusive_total" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldTaxesInclusiveTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTaxesInclusiveTotal is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTaxesInclusiveTotal requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTaxesInclusiveTotal: %w", err) + } + return oldValue.TaxesInclusiveTotal, nil +} + +// ResetTaxesInclusiveTotal resets all changes to the "taxes_inclusive_total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetTaxesInclusiveTotal() { + m.taxes_inclusive_total = nil +} + +// SetTaxesExclusiveTotal sets the "taxes_exclusive_total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetTaxesExclusiveTotal(a alpacadecimal.Decimal) { + m.taxes_exclusive_total = &a +} + +// TaxesExclusiveTotal returns the value of the "taxes_exclusive_total" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) TaxesExclusiveTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.taxes_exclusive_total + if v == nil { + return + } + return *v, true +} + +// OldTaxesExclusiveTotal returns the old "taxes_exclusive_total" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldTaxesExclusiveTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTaxesExclusiveTotal is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTaxesExclusiveTotal requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTaxesExclusiveTotal: %w", err) + } + return oldValue.TaxesExclusiveTotal, nil +} + +// ResetTaxesExclusiveTotal resets all changes to the "taxes_exclusive_total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetTaxesExclusiveTotal() { + m.taxes_exclusive_total = nil +} + +// SetChargesTotal sets the "charges_total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetChargesTotal(a alpacadecimal.Decimal) { + m.charges_total = &a +} + +// ChargesTotal returns the value of the "charges_total" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) ChargesTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.charges_total + if v == nil { + return + } + return *v, true +} + +// OldChargesTotal returns the old "charges_total" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldChargesTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldChargesTotal is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldChargesTotal requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldChargesTotal: %w", err) + } + return oldValue.ChargesTotal, nil +} + +// ResetChargesTotal resets all changes to the "charges_total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetChargesTotal() { + m.charges_total = nil +} + +// SetDiscountsTotal sets the "discounts_total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetDiscountsTotal(a alpacadecimal.Decimal) { + m.discounts_total = &a +} + +// DiscountsTotal returns the value of the "discounts_total" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) DiscountsTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.discounts_total + if v == nil { + return + } + return *v, true +} + +// OldDiscountsTotal returns the old "discounts_total" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldDiscountsTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDiscountsTotal is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDiscountsTotal requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDiscountsTotal: %w", err) + } + return oldValue.DiscountsTotal, nil +} + +// ResetDiscountsTotal resets all changes to the "discounts_total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetDiscountsTotal() { + m.discounts_total = nil +} + +// SetCreditsTotal sets the "credits_total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetCreditsTotal(a alpacadecimal.Decimal) { + m.credits_total = &a +} + +// CreditsTotal returns the value of the "credits_total" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) CreditsTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.credits_total + if v == nil { + return + } + return *v, true +} + +// OldCreditsTotal returns the old "credits_total" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldCreditsTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreditsTotal is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreditsTotal requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreditsTotal: %w", err) + } + return oldValue.CreditsTotal, nil +} + +// ResetCreditsTotal resets all changes to the "credits_total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetCreditsTotal() { + m.credits_total = nil +} + +// SetTotal sets the "total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetTotal(a alpacadecimal.Decimal) { + m.total = &a +} + +// Total returns the value of the "total" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) Total() (r alpacadecimal.Decimal, exists bool) { + v := m.total + if v == nil { + return + } + return *v, true +} + +// OldTotal returns the old "total" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTotal is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTotal requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTotal: %w", err) + } + return oldValue.Total, nil +} + +// ResetTotal resets all changes to the "total" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetTotal() { + m.total = nil +} + +// SetRunID sets the "run_id" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetRunID(s string) { + m.run = &s +} + +// RunID returns the value of the "run_id" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) RunID() (r string, exists bool) { + v := m.run + if v == nil { + return + } + return *v, true +} + +// OldRunID returns the old "run_id" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldRunID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRunID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRunID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRunID: %w", err) + } + return oldValue.RunID, nil +} + +// ResetRunID resets all changes to the "run_id" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetRunID() { + m.run = nil +} + +// SetPricerReferenceID sets the "pricer_reference_id" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) SetPricerReferenceID(s string) { + m.pricer_reference_id = &s +} + +// PricerReferenceID returns the value of the "pricer_reference_id" field in the mutation. +func (m *ChargeFlatFeeRunDetailedLineMutation) PricerReferenceID() (r string, exists bool) { + v := m.pricer_reference_id + if v == nil { + return + } + return *v, true +} + +// OldPricerReferenceID returns the old "pricer_reference_id" field's value of the ChargeFlatFeeRunDetailedLine entity. +// If the ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunDetailedLineMutation) OldPricerReferenceID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPricerReferenceID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPricerReferenceID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPricerReferenceID: %w", err) + } + return oldValue.PricerReferenceID, nil +} + +// ResetPricerReferenceID resets all changes to the "pricer_reference_id" field. +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetPricerReferenceID() { + m.pricer_reference_id = nil } // ClearRun clears the "run" edge to the ChargeFlatFeeRun entity. -func (m *ChargeFlatFeeRunPaymentMutation) ClearRun() { +func (m *ChargeFlatFeeRunDetailedLineMutation) ClearRun() { m.clearedrun = true - m.clearedFields[chargeflatfeerunpayment.FieldRunID] = struct{}{} + m.clearedFields[chargeflatfeerundetailedline.FieldRunID] = struct{}{} } // RunCleared reports if the "run" edge to the ChargeFlatFeeRun entity was cleared. -func (m *ChargeFlatFeeRunPaymentMutation) RunCleared() bool { +func (m *ChargeFlatFeeRunDetailedLineMutation) RunCleared() bool { return m.clearedrun } // RunIDs returns the "run" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // RunID instead. It exists only for internal usage by the builders. -func (m *ChargeFlatFeeRunPaymentMutation) RunIDs() (ids []string) { +func (m *ChargeFlatFeeRunDetailedLineMutation) RunIDs() (ids []string) { if id := m.run; id != nil { ids = append(ids, *id) } @@ -58257,20 +58020,20 @@ func (m *ChargeFlatFeeRunPaymentMutation) RunIDs() (ids []string) { } // ResetRun resets all changes to the "run" edge. -func (m *ChargeFlatFeeRunPaymentMutation) ResetRun() { +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetRun() { m.run = nil m.clearedrun = false } -// Where appends a list predicates to the ChargeFlatFeeRunPaymentMutation builder. -func (m *ChargeFlatFeeRunPaymentMutation) Where(ps ...predicate.ChargeFlatFeeRunPayment) { +// Where appends a list predicates to the ChargeFlatFeeRunDetailedLineMutation builder. +func (m *ChargeFlatFeeRunDetailedLineMutation) Where(ps ...predicate.ChargeFlatFeeRunDetailedLine) { m.predicates = append(m.predicates, ps...) } -// WhereP appends storage-level predicates to the ChargeFlatFeeRunPaymentMutation builder. Using this method, +// WhereP appends storage-level predicates to the ChargeFlatFeeRunDetailedLineMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. -func (m *ChargeFlatFeeRunPaymentMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.ChargeFlatFeeRunPayment, len(ps)) +func (m *ChargeFlatFeeRunDetailedLineMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeFlatFeeRunDetailedLine, len(ps)) for i := range ps { p[i] = ps[i] } @@ -58278,72 +58041,111 @@ func (m *ChargeFlatFeeRunPaymentMutation) WhereP(ps ...func(*sql.Selector)) { } // Op returns the operation name. -func (m *ChargeFlatFeeRunPaymentMutation) Op() Op { +func (m *ChargeFlatFeeRunDetailedLineMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. -func (m *ChargeFlatFeeRunPaymentMutation) SetOp(op Op) { +func (m *ChargeFlatFeeRunDetailedLineMutation) SetOp(op Op) { m.op = op } -// Type returns the node type of this mutation (ChargeFlatFeeRunPayment). -func (m *ChargeFlatFeeRunPaymentMutation) Type() string { +// Type returns the node type of this mutation (ChargeFlatFeeRunDetailedLine). +func (m *ChargeFlatFeeRunDetailedLineMutation) 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 *ChargeFlatFeeRunPaymentMutation) Fields() []string { - fields := make([]string, 0, 16) - if m.billing_invoice_line != nil { - fields = append(fields, chargeflatfeerunpayment.FieldLineID) +func (m *ChargeFlatFeeRunDetailedLineMutation) Fields() []string { + fields := make([]string, 0, 29) + if m.currency != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldCurrency) } - if m.invoice_id != nil { - fields = append(fields, chargeflatfeerunpayment.FieldInvoiceID) + if m.service_period_start != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldServicePeriodStart) } - if m.service_period_from != nil { - fields = append(fields, chargeflatfeerunpayment.FieldServicePeriodFrom) + if m.service_period_end != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldServicePeriodEnd) } - if m.service_period_to != nil { - fields = append(fields, chargeflatfeerunpayment.FieldServicePeriodTo) + if m.quantity != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldQuantity) } - if m.status != nil { - fields = append(fields, chargeflatfeerunpayment.FieldStatus) + if m.invoicing_app_external_id != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldInvoicingAppExternalID) } - if m.amount != nil { - fields = append(fields, chargeflatfeerunpayment.FieldAmount) + if m.child_unique_reference_id != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldChildUniqueReferenceID) } - if m.authorized_transaction_group_id != nil { - fields = append(fields, chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID) + if m.per_unit_amount != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldPerUnitAmount) } - if m.authorized_at != nil { - fields = append(fields, chargeflatfeerunpayment.FieldAuthorizedAt) + if m.category != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldCategory) } - if m.settled_transaction_group_id != nil { - fields = append(fields, chargeflatfeerunpayment.FieldSettledTransactionGroupID) + if m.payment_term != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldPaymentTerm) } - if m.settled_at != nil { - fields = append(fields, chargeflatfeerunpayment.FieldSettledAt) + if m.index != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldIndex) + } + if m.credits_applied != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldCreditsApplied) + } + if m.annotations != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldAnnotations) } if m.namespace != nil { - fields = append(fields, chargeflatfeerunpayment.FieldNamespace) + fields = append(fields, chargeflatfeerundetailedline.FieldNamespace) + } + if m.metadata != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldMetadata) } if m.created_at != nil { - fields = append(fields, chargeflatfeerunpayment.FieldCreatedAt) + fields = append(fields, chargeflatfeerundetailedline.FieldCreatedAt) } if m.updated_at != nil { - fields = append(fields, chargeflatfeerunpayment.FieldUpdatedAt) + fields = append(fields, chargeflatfeerundetailedline.FieldUpdatedAt) } if m.deleted_at != nil { - fields = append(fields, chargeflatfeerunpayment.FieldDeletedAt) + fields = append(fields, chargeflatfeerundetailedline.FieldDeletedAt) } - if m.annotations != nil { - fields = append(fields, chargeflatfeerunpayment.FieldAnnotations) + if m.name != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldName) + } + if m.description != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldDescription) + } + if m.amount != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldAmount) + } + if m.taxes_total != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldTaxesTotal) + } + if m.taxes_inclusive_total != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldTaxesInclusiveTotal) + } + if m.taxes_exclusive_total != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldTaxesExclusiveTotal) + } + if m.charges_total != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldChargesTotal) + } + if m.discounts_total != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldDiscountsTotal) + } + if m.credits_total != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldCreditsTotal) + } + if m.total != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldTotal) } if m.run != nil { - fields = append(fields, chargeflatfeerunpayment.FieldRunID) + fields = append(fields, chargeflatfeerundetailedline.FieldRunID) + } + if m.pricer_reference_id != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldPricerReferenceID) } return fields } @@ -58351,40 +58153,66 @@ func (m *ChargeFlatFeeRunPaymentMutation) Fields() []string { // 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 *ChargeFlatFeeRunPaymentMutation) Field(name string) (ent.Value, bool) { +func (m *ChargeFlatFeeRunDetailedLineMutation) Field(name string) (ent.Value, bool) { switch name { - case chargeflatfeerunpayment.FieldLineID: - return m.LineID() - case chargeflatfeerunpayment.FieldInvoiceID: - return m.InvoiceID() - case chargeflatfeerunpayment.FieldServicePeriodFrom: - return m.ServicePeriodFrom() - case chargeflatfeerunpayment.FieldServicePeriodTo: - return m.ServicePeriodTo() - case chargeflatfeerunpayment.FieldStatus: - return m.Status() - case chargeflatfeerunpayment.FieldAmount: - return m.Amount() - case chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID: - return m.AuthorizedTransactionGroupID() - case chargeflatfeerunpayment.FieldAuthorizedAt: - return m.AuthorizedAt() - case chargeflatfeerunpayment.FieldSettledTransactionGroupID: - return m.SettledTransactionGroupID() - case chargeflatfeerunpayment.FieldSettledAt: - return m.SettledAt() - case chargeflatfeerunpayment.FieldNamespace: + case chargeflatfeerundetailedline.FieldCurrency: + return m.Currency() + case chargeflatfeerundetailedline.FieldServicePeriodStart: + return m.ServicePeriodStart() + case chargeflatfeerundetailedline.FieldServicePeriodEnd: + return m.ServicePeriodEnd() + case chargeflatfeerundetailedline.FieldQuantity: + return m.Quantity() + case chargeflatfeerundetailedline.FieldInvoicingAppExternalID: + return m.InvoicingAppExternalID() + case chargeflatfeerundetailedline.FieldChildUniqueReferenceID: + return m.ChildUniqueReferenceID() + case chargeflatfeerundetailedline.FieldPerUnitAmount: + return m.PerUnitAmount() + case chargeflatfeerundetailedline.FieldCategory: + return m.Category() + case chargeflatfeerundetailedline.FieldPaymentTerm: + return m.PaymentTerm() + case chargeflatfeerundetailedline.FieldIndex: + return m.Index() + case chargeflatfeerundetailedline.FieldCreditsApplied: + return m.CreditsApplied() + case chargeflatfeerundetailedline.FieldAnnotations: + return m.Annotations() + case chargeflatfeerundetailedline.FieldNamespace: return m.Namespace() - case chargeflatfeerunpayment.FieldCreatedAt: + case chargeflatfeerundetailedline.FieldMetadata: + return m.Metadata() + case chargeflatfeerundetailedline.FieldCreatedAt: return m.CreatedAt() - case chargeflatfeerunpayment.FieldUpdatedAt: + case chargeflatfeerundetailedline.FieldUpdatedAt: return m.UpdatedAt() - case chargeflatfeerunpayment.FieldDeletedAt: + case chargeflatfeerundetailedline.FieldDeletedAt: return m.DeletedAt() - case chargeflatfeerunpayment.FieldAnnotations: - return m.Annotations() - case chargeflatfeerunpayment.FieldRunID: + case chargeflatfeerundetailedline.FieldName: + return m.Name() + case chargeflatfeerundetailedline.FieldDescription: + return m.Description() + case chargeflatfeerundetailedline.FieldAmount: + return m.Amount() + case chargeflatfeerundetailedline.FieldTaxesTotal: + return m.TaxesTotal() + case chargeflatfeerundetailedline.FieldTaxesInclusiveTotal: + return m.TaxesInclusiveTotal() + case chargeflatfeerundetailedline.FieldTaxesExclusiveTotal: + return m.TaxesExclusiveTotal() + case chargeflatfeerundetailedline.FieldChargesTotal: + return m.ChargesTotal() + case chargeflatfeerundetailedline.FieldDiscountsTotal: + return m.DiscountsTotal() + case chargeflatfeerundetailedline.FieldCreditsTotal: + return m.CreditsTotal() + case chargeflatfeerundetailedline.FieldTotal: + return m.Total() + case chargeflatfeerundetailedline.FieldRunID: return m.RunID() + case chargeflatfeerundetailedline.FieldPricerReferenceID: + return m.PricerReferenceID() } return nil, false } @@ -58392,322 +58220,498 @@ func (m *ChargeFlatFeeRunPaymentMutation) Field(name string) (ent.Value, bool) { // 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 *ChargeFlatFeeRunPaymentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *ChargeFlatFeeRunDetailedLineMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case chargeflatfeerunpayment.FieldLineID: - return m.OldLineID(ctx) - case chargeflatfeerunpayment.FieldInvoiceID: - return m.OldInvoiceID(ctx) - case chargeflatfeerunpayment.FieldServicePeriodFrom: - return m.OldServicePeriodFrom(ctx) - case chargeflatfeerunpayment.FieldServicePeriodTo: - return m.OldServicePeriodTo(ctx) - case chargeflatfeerunpayment.FieldStatus: - return m.OldStatus(ctx) - case chargeflatfeerunpayment.FieldAmount: - return m.OldAmount(ctx) - case chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID: - return m.OldAuthorizedTransactionGroupID(ctx) - case chargeflatfeerunpayment.FieldAuthorizedAt: - return m.OldAuthorizedAt(ctx) - case chargeflatfeerunpayment.FieldSettledTransactionGroupID: - return m.OldSettledTransactionGroupID(ctx) - case chargeflatfeerunpayment.FieldSettledAt: - return m.OldSettledAt(ctx) - case chargeflatfeerunpayment.FieldNamespace: + case chargeflatfeerundetailedline.FieldCurrency: + return m.OldCurrency(ctx) + case chargeflatfeerundetailedline.FieldServicePeriodStart: + return m.OldServicePeriodStart(ctx) + case chargeflatfeerundetailedline.FieldServicePeriodEnd: + return m.OldServicePeriodEnd(ctx) + case chargeflatfeerundetailedline.FieldQuantity: + return m.OldQuantity(ctx) + case chargeflatfeerundetailedline.FieldInvoicingAppExternalID: + return m.OldInvoicingAppExternalID(ctx) + case chargeflatfeerundetailedline.FieldChildUniqueReferenceID: + return m.OldChildUniqueReferenceID(ctx) + case chargeflatfeerundetailedline.FieldPerUnitAmount: + return m.OldPerUnitAmount(ctx) + case chargeflatfeerundetailedline.FieldCategory: + return m.OldCategory(ctx) + case chargeflatfeerundetailedline.FieldPaymentTerm: + return m.OldPaymentTerm(ctx) + case chargeflatfeerundetailedline.FieldIndex: + return m.OldIndex(ctx) + case chargeflatfeerundetailedline.FieldCreditsApplied: + return m.OldCreditsApplied(ctx) + case chargeflatfeerundetailedline.FieldAnnotations: + return m.OldAnnotations(ctx) + case chargeflatfeerundetailedline.FieldNamespace: return m.OldNamespace(ctx) - case chargeflatfeerunpayment.FieldCreatedAt: + case chargeflatfeerundetailedline.FieldMetadata: + return m.OldMetadata(ctx) + case chargeflatfeerundetailedline.FieldCreatedAt: return m.OldCreatedAt(ctx) - case chargeflatfeerunpayment.FieldUpdatedAt: + case chargeflatfeerundetailedline.FieldUpdatedAt: return m.OldUpdatedAt(ctx) - case chargeflatfeerunpayment.FieldDeletedAt: + case chargeflatfeerundetailedline.FieldDeletedAt: return m.OldDeletedAt(ctx) - case chargeflatfeerunpayment.FieldAnnotations: - return m.OldAnnotations(ctx) - case chargeflatfeerunpayment.FieldRunID: + case chargeflatfeerundetailedline.FieldName: + return m.OldName(ctx) + case chargeflatfeerundetailedline.FieldDescription: + return m.OldDescription(ctx) + case chargeflatfeerundetailedline.FieldAmount: + return m.OldAmount(ctx) + case chargeflatfeerundetailedline.FieldTaxesTotal: + return m.OldTaxesTotal(ctx) + case chargeflatfeerundetailedline.FieldTaxesInclusiveTotal: + return m.OldTaxesInclusiveTotal(ctx) + case chargeflatfeerundetailedline.FieldTaxesExclusiveTotal: + return m.OldTaxesExclusiveTotal(ctx) + case chargeflatfeerundetailedline.FieldChargesTotal: + return m.OldChargesTotal(ctx) + case chargeflatfeerundetailedline.FieldDiscountsTotal: + return m.OldDiscountsTotal(ctx) + case chargeflatfeerundetailedline.FieldCreditsTotal: + return m.OldCreditsTotal(ctx) + case chargeflatfeerundetailedline.FieldTotal: + return m.OldTotal(ctx) + case chargeflatfeerundetailedline.FieldRunID: return m.OldRunID(ctx) + case chargeflatfeerundetailedline.FieldPricerReferenceID: + return m.OldPricerReferenceID(ctx) } - return nil, fmt.Errorf("unknown ChargeFlatFeeRunPayment field %s", name) + return nil, fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) SetField(name string, value ent.Value) error { +func (m *ChargeFlatFeeRunDetailedLineMutation) SetField(name string, value ent.Value) error { switch name { - case chargeflatfeerunpayment.FieldLineID: - v, ok := value.(string) + case chargeflatfeerundetailedline.FieldCurrency: + v, ok := value.(currencyx.Code) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetLineID(v) + m.SetCurrency(v) return nil - case chargeflatfeerunpayment.FieldInvoiceID: - v, ok := value.(string) + case chargeflatfeerundetailedline.FieldServicePeriodStart: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetInvoiceID(v) + m.SetServicePeriodStart(v) return nil - case chargeflatfeerunpayment.FieldServicePeriodFrom: + case chargeflatfeerundetailedline.FieldServicePeriodEnd: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetServicePeriodFrom(v) + m.SetServicePeriodEnd(v) return nil - case chargeflatfeerunpayment.FieldServicePeriodTo: - v, ok := value.(time.Time) + case chargeflatfeerundetailedline.FieldQuantity: + v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetServicePeriodTo(v) + m.SetQuantity(v) return nil - case chargeflatfeerunpayment.FieldStatus: - v, ok := value.(payment.Status) + case chargeflatfeerundetailedline.FieldInvoicingAppExternalID: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetStatus(v) + m.SetInvoicingAppExternalID(v) return nil - case chargeflatfeerunpayment.FieldAmount: + case chargeflatfeerundetailedline.FieldChildUniqueReferenceID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetChildUniqueReferenceID(v) + return nil + case chargeflatfeerundetailedline.FieldPerUnitAmount: v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetAmount(v) + m.SetPerUnitAmount(v) return nil - case chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID: - v, ok := value.(string) + case chargeflatfeerundetailedline.FieldCategory: + v, ok := value.(stddetailedline.Category) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetAuthorizedTransactionGroupID(v) + m.SetCategory(v) return nil - case chargeflatfeerunpayment.FieldAuthorizedAt: - v, ok := value.(time.Time) + case chargeflatfeerundetailedline.FieldPaymentTerm: + v, ok := value.(productcatalog.PaymentTermType) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetAuthorizedAt(v) + m.SetPaymentTerm(v) return nil - case chargeflatfeerunpayment.FieldSettledTransactionGroupID: - v, ok := value.(string) + case chargeflatfeerundetailedline.FieldIndex: + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetSettledTransactionGroupID(v) + m.SetIndex(v) return nil - case chargeflatfeerunpayment.FieldSettledAt: - v, ok := value.(time.Time) + case chargeflatfeerundetailedline.FieldCreditsApplied: + v, ok := value.(*creditsapplied.CreditsApplied) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetSettledAt(v) + m.SetCreditsApplied(v) return nil - case chargeflatfeerunpayment.FieldNamespace: + case chargeflatfeerundetailedline.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 chargeflatfeerundetailedline.FieldNamespace: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetNamespace(v) return nil - case chargeflatfeerunpayment.FieldCreatedAt: + case chargeflatfeerundetailedline.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 chargeflatfeerundetailedline.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 chargeflatfeerunpayment.FieldUpdatedAt: + case chargeflatfeerundetailedline.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 chargeflatfeerunpayment.FieldDeletedAt: + case chargeflatfeerundetailedline.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 chargeflatfeerunpayment.FieldAnnotations: - v, ok := value.(models.Annotations) + case chargeflatfeerundetailedline.FieldName: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetAnnotations(v) + m.SetName(v) return nil - case chargeflatfeerunpayment.FieldRunID: + case chargeflatfeerundetailedline.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + case chargeflatfeerundetailedline.FieldAmount: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAmount(v) + return nil + case chargeflatfeerundetailedline.FieldTaxesTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTaxesTotal(v) + return nil + case chargeflatfeerundetailedline.FieldTaxesInclusiveTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTaxesInclusiveTotal(v) + return nil + case chargeflatfeerundetailedline.FieldTaxesExclusiveTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTaxesExclusiveTotal(v) + return nil + case chargeflatfeerundetailedline.FieldChargesTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetChargesTotal(v) + return nil + case chargeflatfeerundetailedline.FieldDiscountsTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDiscountsTotal(v) + return nil + case chargeflatfeerundetailedline.FieldCreditsTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreditsTotal(v) + return nil + case chargeflatfeerundetailedline.FieldTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTotal(v) + return nil + case chargeflatfeerundetailedline.FieldRunID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRunID(v) return nil + case chargeflatfeerundetailedline.FieldPricerReferenceID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPricerReferenceID(v) + return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunPayment field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) AddedFields() []string { - return nil +func (m *ChargeFlatFeeRunDetailedLineMutation) AddedFields() []string { + var fields []string + if m.addindex != nil { + fields = append(fields, chargeflatfeerundetailedline.FieldIndex) + } + return fields } // 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 *ChargeFlatFeeRunPaymentMutation) AddedField(name string) (ent.Value, bool) { +func (m *ChargeFlatFeeRunDetailedLineMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case chargeflatfeerundetailedline.FieldIndex: + return m.AddedIndex() + } 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 *ChargeFlatFeeRunPaymentMutation) AddField(name string, value ent.Value) error { +func (m *ChargeFlatFeeRunDetailedLineMutation) AddField(name string, value ent.Value) error { switch name { + case chargeflatfeerundetailedline.FieldIndex: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddIndex(v) + return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunPayment numeric field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *ChargeFlatFeeRunPaymentMutation) ClearedFields() []string { +func (m *ChargeFlatFeeRunDetailedLineMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID) { - fields = append(fields, chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID) + if m.FieldCleared(chargeflatfeerundetailedline.FieldCurrency) { + fields = append(fields, chargeflatfeerundetailedline.FieldCurrency) } - if m.FieldCleared(chargeflatfeerunpayment.FieldAuthorizedAt) { - fields = append(fields, chargeflatfeerunpayment.FieldAuthorizedAt) + if m.FieldCleared(chargeflatfeerundetailedline.FieldInvoicingAppExternalID) { + fields = append(fields, chargeflatfeerundetailedline.FieldInvoicingAppExternalID) } - if m.FieldCleared(chargeflatfeerunpayment.FieldSettledTransactionGroupID) { - fields = append(fields, chargeflatfeerunpayment.FieldSettledTransactionGroupID) + if m.FieldCleared(chargeflatfeerundetailedline.FieldIndex) { + fields = append(fields, chargeflatfeerundetailedline.FieldIndex) } - if m.FieldCleared(chargeflatfeerunpayment.FieldSettledAt) { - fields = append(fields, chargeflatfeerunpayment.FieldSettledAt) + if m.FieldCleared(chargeflatfeerundetailedline.FieldCreditsApplied) { + fields = append(fields, chargeflatfeerundetailedline.FieldCreditsApplied) } - if m.FieldCleared(chargeflatfeerunpayment.FieldDeletedAt) { - fields = append(fields, chargeflatfeerunpayment.FieldDeletedAt) + if m.FieldCleared(chargeflatfeerundetailedline.FieldAnnotations) { + fields = append(fields, chargeflatfeerundetailedline.FieldAnnotations) } - if m.FieldCleared(chargeflatfeerunpayment.FieldAnnotations) { - fields = append(fields, chargeflatfeerunpayment.FieldAnnotations) + if m.FieldCleared(chargeflatfeerundetailedline.FieldMetadata) { + fields = append(fields, chargeflatfeerundetailedline.FieldMetadata) + } + if m.FieldCleared(chargeflatfeerundetailedline.FieldDeletedAt) { + fields = append(fields, chargeflatfeerundetailedline.FieldDeletedAt) + } + if m.FieldCleared(chargeflatfeerundetailedline.FieldDescription) { + fields = append(fields, chargeflatfeerundetailedline.FieldDescription) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) FieldCleared(name string) bool { +func (m *ChargeFlatFeeRunDetailedLineMutation) 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 *ChargeFlatFeeRunPaymentMutation) ClearField(name string) error { +func (m *ChargeFlatFeeRunDetailedLineMutation) ClearField(name string) error { switch name { - case chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID: - m.ClearAuthorizedTransactionGroupID() + case chargeflatfeerundetailedline.FieldCurrency: + m.ClearCurrency() return nil - case chargeflatfeerunpayment.FieldAuthorizedAt: - m.ClearAuthorizedAt() + case chargeflatfeerundetailedline.FieldInvoicingAppExternalID: + m.ClearInvoicingAppExternalID() return nil - case chargeflatfeerunpayment.FieldSettledTransactionGroupID: - m.ClearSettledTransactionGroupID() + case chargeflatfeerundetailedline.FieldIndex: + m.ClearIndex() return nil - case chargeflatfeerunpayment.FieldSettledAt: - m.ClearSettledAt() + case chargeflatfeerundetailedline.FieldCreditsApplied: + m.ClearCreditsApplied() return nil - case chargeflatfeerunpayment.FieldDeletedAt: + case chargeflatfeerundetailedline.FieldAnnotations: + m.ClearAnnotations() + return nil + case chargeflatfeerundetailedline.FieldMetadata: + m.ClearMetadata() + return nil + case chargeflatfeerundetailedline.FieldDeletedAt: m.ClearDeletedAt() return nil - case chargeflatfeerunpayment.FieldAnnotations: - m.ClearAnnotations() + case chargeflatfeerundetailedline.FieldDescription: + m.ClearDescription() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunPayment nullable field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) ResetField(name string) error { +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetField(name string) error { switch name { - case chargeflatfeerunpayment.FieldLineID: - m.ResetLineID() + case chargeflatfeerundetailedline.FieldCurrency: + m.ResetCurrency() return nil - case chargeflatfeerunpayment.FieldInvoiceID: - m.ResetInvoiceID() + case chargeflatfeerundetailedline.FieldServicePeriodStart: + m.ResetServicePeriodStart() return nil - case chargeflatfeerunpayment.FieldServicePeriodFrom: - m.ResetServicePeriodFrom() + case chargeflatfeerundetailedline.FieldServicePeriodEnd: + m.ResetServicePeriodEnd() return nil - case chargeflatfeerunpayment.FieldServicePeriodTo: - m.ResetServicePeriodTo() + case chargeflatfeerundetailedline.FieldQuantity: + m.ResetQuantity() return nil - case chargeflatfeerunpayment.FieldStatus: - m.ResetStatus() + case chargeflatfeerundetailedline.FieldInvoicingAppExternalID: + m.ResetInvoicingAppExternalID() return nil - case chargeflatfeerunpayment.FieldAmount: - m.ResetAmount() + case chargeflatfeerundetailedline.FieldChildUniqueReferenceID: + m.ResetChildUniqueReferenceID() return nil - case chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID: - m.ResetAuthorizedTransactionGroupID() + case chargeflatfeerundetailedline.FieldPerUnitAmount: + m.ResetPerUnitAmount() return nil - case chargeflatfeerunpayment.FieldAuthorizedAt: - m.ResetAuthorizedAt() + case chargeflatfeerundetailedline.FieldCategory: + m.ResetCategory() return nil - case chargeflatfeerunpayment.FieldSettledTransactionGroupID: - m.ResetSettledTransactionGroupID() + case chargeflatfeerundetailedline.FieldPaymentTerm: + m.ResetPaymentTerm() return nil - case chargeflatfeerunpayment.FieldSettledAt: - m.ResetSettledAt() + case chargeflatfeerundetailedline.FieldIndex: + m.ResetIndex() return nil - case chargeflatfeerunpayment.FieldNamespace: + case chargeflatfeerundetailedline.FieldCreditsApplied: + m.ResetCreditsApplied() + return nil + case chargeflatfeerundetailedline.FieldAnnotations: + m.ResetAnnotations() + return nil + case chargeflatfeerundetailedline.FieldNamespace: m.ResetNamespace() return nil - case chargeflatfeerunpayment.FieldCreatedAt: + case chargeflatfeerundetailedline.FieldMetadata: + m.ResetMetadata() + return nil + case chargeflatfeerundetailedline.FieldCreatedAt: m.ResetCreatedAt() return nil - case chargeflatfeerunpayment.FieldUpdatedAt: + case chargeflatfeerundetailedline.FieldUpdatedAt: m.ResetUpdatedAt() return nil - case chargeflatfeerunpayment.FieldDeletedAt: + case chargeflatfeerundetailedline.FieldDeletedAt: m.ResetDeletedAt() return nil - case chargeflatfeerunpayment.FieldAnnotations: - m.ResetAnnotations() + case chargeflatfeerundetailedline.FieldName: + m.ResetName() return nil - case chargeflatfeerunpayment.FieldRunID: + case chargeflatfeerundetailedline.FieldDescription: + m.ResetDescription() + return nil + case chargeflatfeerundetailedline.FieldAmount: + m.ResetAmount() + return nil + case chargeflatfeerundetailedline.FieldTaxesTotal: + m.ResetTaxesTotal() + return nil + case chargeflatfeerundetailedline.FieldTaxesInclusiveTotal: + m.ResetTaxesInclusiveTotal() + return nil + case chargeflatfeerundetailedline.FieldTaxesExclusiveTotal: + m.ResetTaxesExclusiveTotal() + return nil + case chargeflatfeerundetailedline.FieldChargesTotal: + m.ResetChargesTotal() + return nil + case chargeflatfeerundetailedline.FieldDiscountsTotal: + m.ResetDiscountsTotal() + return nil + case chargeflatfeerundetailedline.FieldCreditsTotal: + m.ResetCreditsTotal() + return nil + case chargeflatfeerundetailedline.FieldTotal: + m.ResetTotal() + return nil + case chargeflatfeerundetailedline.FieldRunID: m.ResetRunID() return nil + case chargeflatfeerundetailedline.FieldPricerReferenceID: + m.ResetPricerReferenceID() + return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunPayment field %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) AddedEdges() []string { - edges := make([]string, 0, 2) - if m.billing_invoice_line != nil { - edges = append(edges, chargeflatfeerunpayment.EdgeBillingInvoiceLine) - } +func (m *ChargeFlatFeeRunDetailedLineMutation) AddedEdges() []string { + edges := make([]string, 0, 1) if m.run != nil { - edges = append(edges, chargeflatfeerunpayment.EdgeRun) + edges = append(edges, chargeflatfeerundetailedline.EdgeRun) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) AddedIDs(name string) []ent.Value { +func (m *ChargeFlatFeeRunDetailedLineMutation) AddedIDs(name string) []ent.Value { switch name { - case chargeflatfeerunpayment.EdgeBillingInvoiceLine: - if id := m.billing_invoice_line; id != nil { - return []ent.Value{*id} - } - case chargeflatfeerunpayment.EdgeRun: + case chargeflatfeerundetailedline.EdgeRun: if id := m.run; id != nil { return []ent.Value{*id} } @@ -58716,36 +58720,31 @@ func (m *ChargeFlatFeeRunPaymentMutation) AddedIDs(name string) []ent.Value { } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) RemovedEdges() []string { - edges := make([]string, 0, 2) +func (m *ChargeFlatFeeRunDetailedLineMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) RemovedIDs(name string) []ent.Value { +func (m *ChargeFlatFeeRunDetailedLineMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) ClearedEdges() []string { - edges := make([]string, 0, 2) - if m.clearedbilling_invoice_line { - edges = append(edges, chargeflatfeerunpayment.EdgeBillingInvoiceLine) - } +func (m *ChargeFlatFeeRunDetailedLineMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) if m.clearedrun { - edges = append(edges, chargeflatfeerunpayment.EdgeRun) + edges = append(edges, chargeflatfeerundetailedline.EdgeRun) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *ChargeFlatFeeRunPaymentMutation) EdgeCleared(name string) bool { +func (m *ChargeFlatFeeRunDetailedLineMutation) EdgeCleared(name string) bool { switch name { - case chargeflatfeerunpayment.EdgeBillingInvoiceLine: - return m.clearedbilling_invoice_line - case chargeflatfeerunpayment.EdgeRun: + case chargeflatfeerundetailedline.EdgeRun: return m.clearedrun } return false @@ -58753,110 +58752,67 @@ func (m *ChargeFlatFeeRunPaymentMutation) EdgeCleared(name string) bool { // 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 *ChargeFlatFeeRunPaymentMutation) ClearEdge(name string) error { +func (m *ChargeFlatFeeRunDetailedLineMutation) ClearEdge(name string) error { switch name { - case chargeflatfeerunpayment.EdgeBillingInvoiceLine: - m.ClearBillingInvoiceLine() - return nil - case chargeflatfeerunpayment.EdgeRun: + case chargeflatfeerundetailedline.EdgeRun: m.ClearRun() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunPayment unique edge %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine 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 *ChargeFlatFeeRunPaymentMutation) ResetEdge(name string) error { +func (m *ChargeFlatFeeRunDetailedLineMutation) ResetEdge(name string) error { switch name { - case chargeflatfeerunpayment.EdgeBillingInvoiceLine: - m.ResetBillingInvoiceLine() - return nil - case chargeflatfeerunpayment.EdgeRun: + case chargeflatfeerundetailedline.EdgeRun: m.ResetRun() return nil } - return fmt.Errorf("unknown ChargeFlatFeeRunPayment edge %s", name) + return fmt.Errorf("unknown ChargeFlatFeeRunDetailedLine edge %s", name) } -// ChargeUsageBasedMutation represents an operation that mutates the ChargeUsageBased nodes in the graph. -type ChargeUsageBasedMutation struct { +// ChargeFlatFeeRunInvoicedUsageMutation represents an operation that mutates the ChargeFlatFeeRunInvoicedUsage nodes in the graph. +type ChargeFlatFeeRunInvoicedUsageMutation struct { config - op Op - typ string - id *string - service_period_from *time.Time - service_period_to *time.Time - billing_period_from *time.Time - billing_period_to *time.Time - full_service_period_from *time.Time - full_service_period_to *time.Time - status *meta.ChargeStatus - unique_reference_id *string - fiat_currency_code *currencyx.Code - managed_by *billing.InvoiceLineManagedBy - advance_after *time.Time - tax_behavior *productcatalog.TaxBehavior - 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 - invoice_at *time.Time - settlement_mode *productcatalog.SettlementMode - intent_deleted_at *time.Time - discounts **billing.Discounts - feature_key *string - rating_engine *usagebased.RatingEngine - price **productcatalog.Price - unit_config **productcatalog.UnitConfig - status_detailed *usagebased.Status - clearedFields map[string]struct{} - runs map[string]struct{} - removedruns map[string]struct{} - clearedruns bool - detailed_lines map[string]struct{} - removeddetailed_lines map[string]struct{} - cleareddetailed_lines bool - current_run *string - clearedcurrent_run bool - charge *string - clearedcharge bool - intent_override *string - clearedintent_override bool - subscription *string - clearedsubscription bool - subscription_phase *string - clearedsubscription_phase bool - subscription_item *string - clearedsubscription_item bool - customer *string - clearedcustomer bool - feature *string - clearedfeature bool - tax_code *string - clearedtax_code bool - custom_currency *string - clearedcustom_currency bool - done bool - oldValue func(context.Context) (*ChargeUsageBased, error) - predicates []predicate.ChargeUsageBased + op Op + typ string + id *string + service_period_from *time.Time + service_period_to *time.Time + ledger_transaction_group_id *string + namespace *string + created_at *time.Time + updated_at *time.Time + deleted_at *time.Time + annotations *models.Annotations + amount *alpacadecimal.Decimal + taxes_total *alpacadecimal.Decimal + taxes_inclusive_total *alpacadecimal.Decimal + taxes_exclusive_total *alpacadecimal.Decimal + charges_total *alpacadecimal.Decimal + discounts_total *alpacadecimal.Decimal + credits_total *alpacadecimal.Decimal + total *alpacadecimal.Decimal + clearedFields map[string]struct{} + run *string + clearedrun bool + done bool + oldValue func(context.Context) (*ChargeFlatFeeRunInvoicedUsage, error) + predicates []predicate.ChargeFlatFeeRunInvoicedUsage } -var _ ent.Mutation = (*ChargeUsageBasedMutation)(nil) +var _ ent.Mutation = (*ChargeFlatFeeRunInvoicedUsageMutation)(nil) -// chargeusagebasedOption allows management of the mutation configuration using functional options. -type chargeusagebasedOption func(*ChargeUsageBasedMutation) +// chargeflatfeeruninvoicedusageOption allows management of the mutation configuration using functional options. +type chargeflatfeeruninvoicedusageOption func(*ChargeFlatFeeRunInvoicedUsageMutation) -// newChargeUsageBasedMutation creates new mutation for the ChargeUsageBased entity. -func newChargeUsageBasedMutation(c config, op Op, opts ...chargeusagebasedOption) *ChargeUsageBasedMutation { - m := &ChargeUsageBasedMutation{ +// newChargeFlatFeeRunInvoicedUsageMutation creates new mutation for the ChargeFlatFeeRunInvoicedUsage entity. +func newChargeFlatFeeRunInvoicedUsageMutation(c config, op Op, opts ...chargeflatfeeruninvoicedusageOption) *ChargeFlatFeeRunInvoicedUsageMutation { + m := &ChargeFlatFeeRunInvoicedUsageMutation{ config: c, op: op, - typ: TypeChargeUsageBased, + typ: TypeChargeFlatFeeRunInvoicedUsage, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -58865,20 +58821,20 @@ func newChargeUsageBasedMutation(c config, op Op, opts ...chargeusagebasedOption return m } -// withChargeUsageBasedID sets the ID field of the mutation. -func withChargeUsageBasedID(id string) chargeusagebasedOption { - return func(m *ChargeUsageBasedMutation) { +// withChargeFlatFeeRunInvoicedUsageID sets the ID field of the mutation. +func withChargeFlatFeeRunInvoicedUsageID(id string) chargeflatfeeruninvoicedusageOption { + return func(m *ChargeFlatFeeRunInvoicedUsageMutation) { var ( err error once sync.Once - value *ChargeUsageBased + value *ChargeFlatFeeRunInvoicedUsage ) - m.oldValue = func(ctx context.Context) (*ChargeUsageBased, error) { + m.oldValue = func(ctx context.Context) (*ChargeFlatFeeRunInvoicedUsage, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { - value, err = m.Client().ChargeUsageBased.Get(ctx, id) + value, err = m.Client().ChargeFlatFeeRunInvoicedUsage.Get(ctx, id) } }) return value, err @@ -58887,10 +58843,10 @@ func withChargeUsageBasedID(id string) chargeusagebasedOption { } } -// withChargeUsageBased sets the old ChargeUsageBased of the mutation. -func withChargeUsageBased(node *ChargeUsageBased) chargeusagebasedOption { - return func(m *ChargeUsageBasedMutation) { - m.oldValue = func(context.Context) (*ChargeUsageBased, error) { +// withChargeFlatFeeRunInvoicedUsage sets the old ChargeFlatFeeRunInvoicedUsage of the mutation. +func withChargeFlatFeeRunInvoicedUsage(node *ChargeFlatFeeRunInvoicedUsage) chargeflatfeeruninvoicedusageOption { + return func(m *ChargeFlatFeeRunInvoicedUsageMutation) { + m.oldValue = func(context.Context) (*ChargeFlatFeeRunInvoicedUsage, error) { return node, nil } m.id = &node.ID @@ -58899,7 +58855,7 @@ func withChargeUsageBased(node *ChargeUsageBased) chargeusagebasedOption { // 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 ChargeUsageBasedMutation) Client() *Client { +func (m ChargeFlatFeeRunInvoicedUsageMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -58907,7 +58863,7 @@ func (m ChargeUsageBasedMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m ChargeUsageBasedMutation) Tx() (*Tx, error) { +func (m ChargeFlatFeeRunInvoicedUsageMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("db: mutation is not running in a transaction") } @@ -58917,14 +58873,14 @@ func (m ChargeUsageBasedMutation) Tx() (*Tx, error) { } // SetID sets the value of the id field. Note that this -// operation is only accepted on creation of ChargeUsageBased entities. -func (m *ChargeUsageBasedMutation) SetID(id string) { +// operation is only accepted on creation of ChargeFlatFeeRunInvoicedUsage entities. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) 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 *ChargeUsageBasedMutation) ID() (id string, exists bool) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ID() (id string, exists bool) { if m.id == nil { return } @@ -58935,7 +58891,7 @@ func (m *ChargeUsageBasedMutation) ID() (id string, exists bool) { // 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 *ChargeUsageBasedMutation) IDs(ctx context.Context) ([]string, error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() @@ -58944,55 +58900,19 @@ func (m *ChargeUsageBasedMutation) IDs(ctx context.Context) ([]string, error) { } fallthrough case m.op.Is(OpUpdate | OpDelete): - return m.Client().ChargeUsageBased.Query().Where(m.predicates...).IDs(ctx) + return m.Client().ChargeFlatFeeRunInvoicedUsage.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } -// SetCustomerID sets the "customer_id" field. -func (m *ChargeUsageBasedMutation) SetCustomerID(s string) { - m.customer = &s -} - -// CustomerID returns the value of the "customer_id" field in the mutation. -func (m *ChargeUsageBasedMutation) CustomerID() (r string, exists bool) { - v := m.customer - if v == nil { - return - } - return *v, true -} - -// OldCustomerID returns the old "customer_id" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldCustomerID(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCustomerID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCustomerID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCustomerID: %w", err) - } - return oldValue.CustomerID, nil -} - -// ResetCustomerID resets all changes to the "customer_id" field. -func (m *ChargeUsageBasedMutation) ResetCustomerID() { - m.customer = nil -} - // SetServicePeriodFrom sets the "service_period_from" field. -func (m *ChargeUsageBasedMutation) SetServicePeriodFrom(t time.Time) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetServicePeriodFrom(t time.Time) { m.service_period_from = &t } // ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. -func (m *ChargeUsageBasedMutation) ServicePeriodFrom() (r time.Time, exists bool) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ServicePeriodFrom() (r time.Time, exists bool) { v := m.service_period_from if v == nil { return @@ -59000,10 +58920,10 @@ func (m *ChargeUsageBasedMutation) ServicePeriodFrom() (r time.Time, exists bool return *v, true } -// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") } @@ -59018,17 +58938,17 @@ func (m *ChargeUsageBasedMutation) OldServicePeriodFrom(ctx context.Context) (v } // ResetServicePeriodFrom resets all changes to the "service_period_from" field. -func (m *ChargeUsageBasedMutation) ResetServicePeriodFrom() { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetServicePeriodFrom() { m.service_period_from = nil } // SetServicePeriodTo sets the "service_period_to" field. -func (m *ChargeUsageBasedMutation) SetServicePeriodTo(t time.Time) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetServicePeriodTo(t time.Time) { m.service_period_to = &t } // ServicePeriodTo returns the value of the "service_period_to" field in the mutation. -func (m *ChargeUsageBasedMutation) ServicePeriodTo() (r time.Time, exists bool) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ServicePeriodTo() (r time.Time, exists bool) { v := m.service_period_to if v == nil { return @@ -59036,10 +58956,10 @@ func (m *ChargeUsageBasedMutation) ServicePeriodTo() (r time.Time, exists bool) return *v, true } -// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") } @@ -59054,1845 +58974,6599 @@ func (m *ChargeUsageBasedMutation) OldServicePeriodTo(ctx context.Context) (v ti } // ResetServicePeriodTo resets all changes to the "service_period_to" field. -func (m *ChargeUsageBasedMutation) ResetServicePeriodTo() { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetServicePeriodTo() { m.service_period_to = nil } -// SetBillingPeriodFrom sets the "billing_period_from" field. -func (m *ChargeUsageBasedMutation) SetBillingPeriodFrom(t time.Time) { - m.billing_period_from = &t +// SetLedgerTransactionGroupID sets the "ledger_transaction_group_id" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetLedgerTransactionGroupID(s string) { + m.ledger_transaction_group_id = &s } -// BillingPeriodFrom returns the value of the "billing_period_from" field in the mutation. -func (m *ChargeUsageBasedMutation) BillingPeriodFrom() (r time.Time, exists bool) { - v := m.billing_period_from +// LedgerTransactionGroupID returns the value of the "ledger_transaction_group_id" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) LedgerTransactionGroupID() (r string, exists bool) { + v := m.ledger_transaction_group_id if v == nil { return } return *v, true } -// OldBillingPeriodFrom returns the old "billing_period_from" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldLedgerTransactionGroupID returns the old "ledger_transaction_group_id" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldBillingPeriodFrom(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldLedgerTransactionGroupID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldBillingPeriodFrom is only allowed on UpdateOne operations") + return v, errors.New("OldLedgerTransactionGroupID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldBillingPeriodFrom requires an ID field in the mutation") + return v, errors.New("OldLedgerTransactionGroupID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldBillingPeriodFrom: %w", err) + return v, fmt.Errorf("querying old value for OldLedgerTransactionGroupID: %w", err) } - return oldValue.BillingPeriodFrom, nil + return oldValue.LedgerTransactionGroupID, nil } -// ResetBillingPeriodFrom resets all changes to the "billing_period_from" field. -func (m *ChargeUsageBasedMutation) ResetBillingPeriodFrom() { - m.billing_period_from = nil +// ClearLedgerTransactionGroupID clears the value of the "ledger_transaction_group_id" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ClearLedgerTransactionGroupID() { + m.ledger_transaction_group_id = nil + m.clearedFields[chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID] = struct{}{} } -// SetBillingPeriodTo sets the "billing_period_to" field. -func (m *ChargeUsageBasedMutation) SetBillingPeriodTo(t time.Time) { - m.billing_period_to = &t +// LedgerTransactionGroupIDCleared returns if the "ledger_transaction_group_id" field was cleared in this mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) LedgerTransactionGroupIDCleared() bool { + _, ok := m.clearedFields[chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID] + return ok } -// BillingPeriodTo returns the value of the "billing_period_to" field in the mutation. -func (m *ChargeUsageBasedMutation) BillingPeriodTo() (r time.Time, exists bool) { - v := m.billing_period_to +// ResetLedgerTransactionGroupID resets all changes to the "ledger_transaction_group_id" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetLedgerTransactionGroupID() { + m.ledger_transaction_group_id = nil + delete(m.clearedFields, chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID) +} + +// SetNamespace sets the "namespace" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetNamespace(s string) { + m.namespace = &s +} + +// Namespace returns the value of the "namespace" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) Namespace() (r string, exists bool) { + v := m.namespace if v == nil { return } return *v, true } -// OldBillingPeriodTo returns the old "billing_period_to" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldNamespace returns the old "namespace" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldBillingPeriodTo(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldNamespace(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldBillingPeriodTo is only allowed on UpdateOne operations") + return v, errors.New("OldNamespace is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldBillingPeriodTo requires an ID field in the mutation") + 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 OldBillingPeriodTo: %w", err) + return v, fmt.Errorf("querying old value for OldNamespace: %w", err) } - return oldValue.BillingPeriodTo, nil + return oldValue.Namespace, nil } -// ResetBillingPeriodTo resets all changes to the "billing_period_to" field. -func (m *ChargeUsageBasedMutation) ResetBillingPeriodTo() { - m.billing_period_to = nil +// ResetNamespace resets all changes to the "namespace" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetNamespace() { + m.namespace = nil } -// SetFullServicePeriodFrom sets the "full_service_period_from" field. -func (m *ChargeUsageBasedMutation) SetFullServicePeriodFrom(t time.Time) { - m.full_service_period_from = &t +// SetCreatedAt sets the "created_at" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetCreatedAt(t time.Time) { + m.created_at = &t } -// FullServicePeriodFrom returns the value of the "full_service_period_from" field in the mutation. -func (m *ChargeUsageBasedMutation) FullServicePeriodFrom() (r time.Time, exists bool) { - v := m.full_service_period_from +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at if v == nil { return } return *v, true } -// OldFullServicePeriodFrom returns the old "full_service_period_from" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldFullServicePeriodFrom(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldFullServicePeriodFrom is only allowed on UpdateOne operations") + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldFullServicePeriodFrom requires an ID field in the mutation") + 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 OldFullServicePeriodFrom: %w", err) + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } - return oldValue.FullServicePeriodFrom, nil + return oldValue.CreatedAt, nil } -// ResetFullServicePeriodFrom resets all changes to the "full_service_period_from" field. -func (m *ChargeUsageBasedMutation) ResetFullServicePeriodFrom() { - m.full_service_period_from = nil +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetCreatedAt() { + m.created_at = nil } -// SetFullServicePeriodTo sets the "full_service_period_to" field. -func (m *ChargeUsageBasedMutation) SetFullServicePeriodTo(t time.Time) { - m.full_service_period_to = &t +// SetUpdatedAt sets the "updated_at" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t } -// FullServicePeriodTo returns the value of the "full_service_period_to" field in the mutation. -func (m *ChargeUsageBasedMutation) FullServicePeriodTo() (r time.Time, exists bool) { - v := m.full_service_period_to +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at if v == nil { return } return *v, true } -// OldFullServicePeriodTo returns the old "full_service_period_to" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldFullServicePeriodTo(ctx context.Context) (v time.Time, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldFullServicePeriodTo is only allowed on UpdateOne operations") + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldFullServicePeriodTo requires an ID field in the mutation") + 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 OldFullServicePeriodTo: %w", err) + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } - return oldValue.FullServicePeriodTo, nil + return oldValue.UpdatedAt, nil } -// ResetFullServicePeriodTo resets all changes to the "full_service_period_to" field. -func (m *ChargeUsageBasedMutation) ResetFullServicePeriodTo() { - m.full_service_period_to = nil +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetUpdatedAt() { + m.updated_at = nil } -// SetStatus sets the "status" field. -func (m *ChargeUsageBasedMutation) SetStatus(ms meta.ChargeStatus) { - m.status = &ms +// SetDeletedAt sets the "deleted_at" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetDeletedAt(t time.Time) { + m.deleted_at = &t } -// Status returns the value of the "status" field in the mutation. -func (m *ChargeUsageBasedMutation) Status() (r meta.ChargeStatus, exists bool) { - v := m.status +// DeletedAt returns the value of the "deleted_at" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) DeletedAt() (r time.Time, exists bool) { + v := m.deleted_at if v == nil { return } return *v, true } -// OldStatus returns the old "status" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldDeletedAt returns the old "deleted_at" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldStatus(ctx context.Context) (v meta.ChargeStatus, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldStatus is only allowed on UpdateOne operations") + return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldStatus requires an ID field in the mutation") + 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 OldStatus: %w", err) + return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) } - return oldValue.Status, nil + return oldValue.DeletedAt, nil } -// ResetStatus resets all changes to the "status" field. -func (m *ChargeUsageBasedMutation) ResetStatus() { - m.status = nil +// ClearDeletedAt clears the value of the "deleted_at" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ClearDeletedAt() { + m.deleted_at = nil + m.clearedFields[chargeflatfeeruninvoicedusage.FieldDeletedAt] = struct{}{} } -// SetUniqueReferenceID sets the "unique_reference_id" field. -func (m *ChargeUsageBasedMutation) SetUniqueReferenceID(s string) { - m.unique_reference_id = &s +// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargeflatfeeruninvoicedusage.FieldDeletedAt] + return ok } -// UniqueReferenceID returns the value of the "unique_reference_id" field in the mutation. -func (m *ChargeUsageBasedMutation) UniqueReferenceID() (r string, exists bool) { - v := m.unique_reference_id +// ResetDeletedAt resets all changes to the "deleted_at" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetDeletedAt() { + m.deleted_at = nil + delete(m.clearedFields, chargeflatfeeruninvoicedusage.FieldDeletedAt) +} + +// SetAnnotations sets the "annotations" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetAnnotations(value models.Annotations) { + m.annotations = &value +} + +// Annotations returns the value of the "annotations" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) Annotations() (r models.Annotations, exists bool) { + v := m.annotations if v == nil { return } return *v, true } -// OldUniqueReferenceID returns the old "unique_reference_id" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldAnnotations returns the old "annotations" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldUniqueReferenceID(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldAnnotations(ctx context.Context) (v models.Annotations, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUniqueReferenceID is only allowed on UpdateOne operations") + return v, errors.New("OldAnnotations is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUniqueReferenceID requires an ID field in the mutation") + 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 OldUniqueReferenceID: %w", err) + return v, fmt.Errorf("querying old value for OldAnnotations: %w", err) } - return oldValue.UniqueReferenceID, nil + return oldValue.Annotations, nil } -// ClearUniqueReferenceID clears the value of the "unique_reference_id" field. -func (m *ChargeUsageBasedMutation) ClearUniqueReferenceID() { - m.unique_reference_id = nil - m.clearedFields[chargeusagebased.FieldUniqueReferenceID] = struct{}{} +// ClearAnnotations clears the value of the "annotations" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ClearAnnotations() { + m.annotations = nil + m.clearedFields[chargeflatfeeruninvoicedusage.FieldAnnotations] = struct{}{} } -// UniqueReferenceIDCleared returns if the "unique_reference_id" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) UniqueReferenceIDCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldUniqueReferenceID] +// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) AnnotationsCleared() bool { + _, ok := m.clearedFields[chargeflatfeeruninvoicedusage.FieldAnnotations] return ok } -// ResetUniqueReferenceID resets all changes to the "unique_reference_id" field. -func (m *ChargeUsageBasedMutation) ResetUniqueReferenceID() { - m.unique_reference_id = nil - delete(m.clearedFields, chargeusagebased.FieldUniqueReferenceID) +// ResetAnnotations resets all changes to the "annotations" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetAnnotations() { + m.annotations = nil + delete(m.clearedFields, chargeflatfeeruninvoicedusage.FieldAnnotations) } -// SetFiatCurrencyCode sets the "fiat_currency_code" field. -func (m *ChargeUsageBasedMutation) SetFiatCurrencyCode(c currencyx.Code) { - m.fiat_currency_code = &c +// SetAmount sets the "amount" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetAmount(a alpacadecimal.Decimal) { + m.amount = &a } -// FiatCurrencyCode returns the value of the "fiat_currency_code" field in the mutation. -func (m *ChargeUsageBasedMutation) FiatCurrencyCode() (r currencyx.Code, exists bool) { - v := m.fiat_currency_code +// Amount returns the value of the "amount" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) Amount() (r alpacadecimal.Decimal, exists bool) { + v := m.amount if v == nil { return } return *v, true } -// OldFiatCurrencyCode returns the old "fiat_currency_code" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldAmount returns the old "amount" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldFiatCurrencyCode(ctx context.Context) (v *currencyx.Code, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldFiatCurrencyCode is only allowed on UpdateOne operations") + return v, errors.New("OldAmount is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldFiatCurrencyCode requires an ID field in the mutation") + return v, errors.New("OldAmount requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldFiatCurrencyCode: %w", err) + return v, fmt.Errorf("querying old value for OldAmount: %w", err) } - return oldValue.FiatCurrencyCode, nil + return oldValue.Amount, nil } -// ClearFiatCurrencyCode clears the value of the "fiat_currency_code" field. -func (m *ChargeUsageBasedMutation) ClearFiatCurrencyCode() { - m.fiat_currency_code = nil - m.clearedFields[chargeusagebased.FieldFiatCurrencyCode] = struct{}{} +// ResetAmount resets all changes to the "amount" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetAmount() { + m.amount = nil } -// FiatCurrencyCodeCleared returns if the "fiat_currency_code" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) FiatCurrencyCodeCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldFiatCurrencyCode] - return ok +// SetTaxesTotal sets the "taxes_total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetTaxesTotal(a alpacadecimal.Decimal) { + m.taxes_total = &a } -// ResetFiatCurrencyCode resets all changes to the "fiat_currency_code" field. -func (m *ChargeUsageBasedMutation) ResetFiatCurrencyCode() { - m.fiat_currency_code = nil - delete(m.clearedFields, chargeusagebased.FieldFiatCurrencyCode) +// TaxesTotal returns the value of the "taxes_total" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) TaxesTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.taxes_total + if v == nil { + return + } + return *v, true } -// SetCustomCurrencyID sets the "custom_currency_id" field. -func (m *ChargeUsageBasedMutation) SetCustomCurrencyID(s string) { - m.custom_currency = &s +// OldTaxesTotal returns the old "taxes_total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldTaxesTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTaxesTotal is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTaxesTotal requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTaxesTotal: %w", err) + } + return oldValue.TaxesTotal, nil } -// CustomCurrencyID returns the value of the "custom_currency_id" field in the mutation. -func (m *ChargeUsageBasedMutation) CustomCurrencyID() (r string, exists bool) { - v := m.custom_currency +// ResetTaxesTotal resets all changes to the "taxes_total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetTaxesTotal() { + m.taxes_total = nil +} + +// SetTaxesInclusiveTotal sets the "taxes_inclusive_total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetTaxesInclusiveTotal(a alpacadecimal.Decimal) { + m.taxes_inclusive_total = &a +} + +// TaxesInclusiveTotal returns the value of the "taxes_inclusive_total" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) TaxesInclusiveTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.taxes_inclusive_total if v == nil { return } return *v, true } -// OldCustomCurrencyID returns the old "custom_currency_id" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldTaxesInclusiveTotal returns the old "taxes_inclusive_total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldCustomCurrencyID(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldTaxesInclusiveTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCustomCurrencyID is only allowed on UpdateOne operations") + return v, errors.New("OldTaxesInclusiveTotal is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCustomCurrencyID requires an ID field in the mutation") + return v, errors.New("OldTaxesInclusiveTotal requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldCustomCurrencyID: %w", err) + return v, fmt.Errorf("querying old value for OldTaxesInclusiveTotal: %w", err) } - return oldValue.CustomCurrencyID, nil + return oldValue.TaxesInclusiveTotal, nil } -// ClearCustomCurrencyID clears the value of the "custom_currency_id" field. -func (m *ChargeUsageBasedMutation) ClearCustomCurrencyID() { - m.custom_currency = nil - m.clearedFields[chargeusagebased.FieldCustomCurrencyID] = struct{}{} +// ResetTaxesInclusiveTotal resets all changes to the "taxes_inclusive_total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetTaxesInclusiveTotal() { + m.taxes_inclusive_total = nil } -// CustomCurrencyIDCleared returns if the "custom_currency_id" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) CustomCurrencyIDCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldCustomCurrencyID] - return ok +// SetTaxesExclusiveTotal sets the "taxes_exclusive_total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetTaxesExclusiveTotal(a alpacadecimal.Decimal) { + m.taxes_exclusive_total = &a } -// ResetCustomCurrencyID resets all changes to the "custom_currency_id" field. -func (m *ChargeUsageBasedMutation) ResetCustomCurrencyID() { - m.custom_currency = nil - delete(m.clearedFields, chargeusagebased.FieldCustomCurrencyID) +// TaxesExclusiveTotal returns the value of the "taxes_exclusive_total" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) TaxesExclusiveTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.taxes_exclusive_total + if v == nil { + return + } + return *v, true } -// SetManagedBy sets the "managed_by" field. -func (m *ChargeUsageBasedMutation) SetManagedBy(blmb billing.InvoiceLineManagedBy) { - m.managed_by = &blmb +// OldTaxesExclusiveTotal returns the old "taxes_exclusive_total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldTaxesExclusiveTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTaxesExclusiveTotal is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTaxesExclusiveTotal requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTaxesExclusiveTotal: %w", err) + } + return oldValue.TaxesExclusiveTotal, nil } -// ManagedBy returns the value of the "managed_by" field in the mutation. -func (m *ChargeUsageBasedMutation) ManagedBy() (r billing.InvoiceLineManagedBy, exists bool) { - v := m.managed_by +// ResetTaxesExclusiveTotal resets all changes to the "taxes_exclusive_total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetTaxesExclusiveTotal() { + m.taxes_exclusive_total = nil +} + +// SetChargesTotal sets the "charges_total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetChargesTotal(a alpacadecimal.Decimal) { + m.charges_total = &a +} + +// ChargesTotal returns the value of the "charges_total" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ChargesTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.charges_total if v == nil { return } return *v, true } -// OldManagedBy returns the old "managed_by" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldChargesTotal returns the old "charges_total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldManagedBy(ctx context.Context) (v billing.InvoiceLineManagedBy, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldChargesTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldManagedBy is only allowed on UpdateOne operations") + return v, errors.New("OldChargesTotal 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") + return v, errors.New("OldChargesTotal 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 v, fmt.Errorf("querying old value for OldChargesTotal: %w", err) } - return oldValue.ManagedBy, nil + return oldValue.ChargesTotal, nil } -// ResetManagedBy resets all changes to the "managed_by" field. -func (m *ChargeUsageBasedMutation) ResetManagedBy() { - m.managed_by = nil +// ResetChargesTotal resets all changes to the "charges_total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetChargesTotal() { + m.charges_total = nil } -// SetSubscriptionID sets the "subscription_id" field. -func (m *ChargeUsageBasedMutation) SetSubscriptionID(s string) { - m.subscription = &s +// SetDiscountsTotal sets the "discounts_total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetDiscountsTotal(a alpacadecimal.Decimal) { + m.discounts_total = &a } -// SubscriptionID returns the value of the "subscription_id" field in the mutation. -func (m *ChargeUsageBasedMutation) SubscriptionID() (r string, exists bool) { - v := m.subscription +// DiscountsTotal returns the value of the "discounts_total" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) DiscountsTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.discounts_total if v == nil { return } return *v, true } -// OldSubscriptionID returns the old "subscription_id" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldDiscountsTotal returns the old "discounts_total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldSubscriptionID(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldDiscountsTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSubscriptionID is only allowed on UpdateOne operations") + return v, errors.New("OldDiscountsTotal 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") + return v, errors.New("OldDiscountsTotal 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 v, fmt.Errorf("querying old value for OldDiscountsTotal: %w", err) } - return oldValue.SubscriptionID, nil + return oldValue.DiscountsTotal, nil } -// ClearSubscriptionID clears the value of the "subscription_id" field. -func (m *ChargeUsageBasedMutation) ClearSubscriptionID() { - m.subscription = nil - m.clearedFields[chargeusagebased.FieldSubscriptionID] = struct{}{} +// ResetDiscountsTotal resets all changes to the "discounts_total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetDiscountsTotal() { + m.discounts_total = nil } -// SubscriptionIDCleared returns if the "subscription_id" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) SubscriptionIDCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldSubscriptionID] - return ok +// SetCreditsTotal sets the "credits_total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetCreditsTotal(a alpacadecimal.Decimal) { + m.credits_total = &a } -// ResetSubscriptionID resets all changes to the "subscription_id" field. -func (m *ChargeUsageBasedMutation) ResetSubscriptionID() { - m.subscription = nil - delete(m.clearedFields, chargeusagebased.FieldSubscriptionID) +// CreditsTotal returns the value of the "credits_total" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) CreditsTotal() (r alpacadecimal.Decimal, exists bool) { + v := m.credits_total + if v == nil { + return + } + return *v, true } -// SetSubscriptionPhaseID sets the "subscription_phase_id" field. -func (m *ChargeUsageBasedMutation) SetSubscriptionPhaseID(s string) { - m.subscription_phase = &s +// OldCreditsTotal returns the old "credits_total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldCreditsTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreditsTotal is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreditsTotal requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreditsTotal: %w", err) + } + return oldValue.CreditsTotal, nil } -// SubscriptionPhaseID returns the value of the "subscription_phase_id" field in the mutation. -func (m *ChargeUsageBasedMutation) SubscriptionPhaseID() (r string, exists bool) { - v := m.subscription_phase +// ResetCreditsTotal resets all changes to the "credits_total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetCreditsTotal() { + m.credits_total = nil +} + +// SetTotal sets the "total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetTotal(a alpacadecimal.Decimal) { + m.total = &a +} + +// Total returns the value of the "total" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) Total() (r alpacadecimal.Decimal, exists bool) { + v := m.total if v == nil { return } return *v, true } -// OldSubscriptionPhaseID returns the old "subscription_phase_id" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldTotal returns the old "total" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeUsageBasedMutation) OldSubscriptionPhaseID(ctx context.Context) (v *string, err error) { +func (m *ChargeFlatFeeRunInvoicedUsageMutation) OldTotal(ctx context.Context) (v alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSubscriptionPhaseID is only allowed on UpdateOne operations") + return v, errors.New("OldTotal 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") + return v, errors.New("OldTotal 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 v, fmt.Errorf("querying old value for OldTotal: %w", err) + } + return oldValue.Total, nil +} + +// ResetTotal resets all changes to the "total" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetTotal() { + m.total = nil +} + +// SetRunID sets the "run_id" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetRunID(s string) { + m.run = &s +} + +// RunID returns the value of the "run_id" field in the mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) RunID() (r string, exists bool) { + v := m.run + if v == nil { + return + } + return *v, true +} + +// OldRunID returns the old "run_id" field's value of the ChargeFlatFeeRunInvoicedUsage entity. +// If the ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldRunID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRunID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRunID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRunID: %w", err) + } + return oldValue.RunID, nil +} + +// ResetRunID resets all changes to the "run_id" field. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetRunID() { + m.run = nil +} + +// ClearRun clears the "run" edge to the ChargeFlatFeeRun entity. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ClearRun() { + m.clearedrun = true + m.clearedFields[chargeflatfeeruninvoicedusage.FieldRunID] = struct{}{} +} + +// RunCleared reports if the "run" edge to the ChargeFlatFeeRun entity was cleared. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) RunCleared() bool { + return m.clearedrun +} + +// RunIDs returns the "run" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// RunID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) RunIDs() (ids []string) { + if id := m.run; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetRun resets all changes to the "run" edge. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ResetRun() { + m.run = nil + m.clearedrun = false +} + +// Where appends a list predicates to the ChargeFlatFeeRunInvoicedUsageMutation builder. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) Where(ps ...predicate.ChargeFlatFeeRunInvoicedUsage) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the ChargeFlatFeeRunInvoicedUsageMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeFlatFeeRunInvoicedUsage, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (ChargeFlatFeeRunInvoicedUsage). +func (m *ChargeFlatFeeRunInvoicedUsageMutation) 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 *ChargeFlatFeeRunInvoicedUsageMutation) Fields() []string { + fields := make([]string, 0, 17) + if m.service_period_from != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldServicePeriodFrom) + } + if m.service_period_to != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldServicePeriodTo) + } + if m.ledger_transaction_group_id != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID) + } + if m.namespace != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldNamespace) + } + if m.created_at != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldUpdatedAt) + } + if m.deleted_at != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldDeletedAt) + } + if m.annotations != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldAnnotations) + } + if m.amount != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldAmount) + } + if m.taxes_total != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldTaxesTotal) + } + if m.taxes_inclusive_total != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldTaxesInclusiveTotal) + } + if m.taxes_exclusive_total != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldTaxesExclusiveTotal) + } + if m.charges_total != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldChargesTotal) + } + if m.discounts_total != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldDiscountsTotal) + } + if m.credits_total != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldCreditsTotal) + } + if m.total != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldTotal) + } + if m.run != nil { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldRunID) + } + 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 *ChargeFlatFeeRunInvoicedUsageMutation) Field(name string) (ent.Value, bool) { + switch name { + case chargeflatfeeruninvoicedusage.FieldServicePeriodFrom: + return m.ServicePeriodFrom() + case chargeflatfeeruninvoicedusage.FieldServicePeriodTo: + return m.ServicePeriodTo() + case chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID: + return m.LedgerTransactionGroupID() + case chargeflatfeeruninvoicedusage.FieldNamespace: + return m.Namespace() + case chargeflatfeeruninvoicedusage.FieldCreatedAt: + return m.CreatedAt() + case chargeflatfeeruninvoicedusage.FieldUpdatedAt: + return m.UpdatedAt() + case chargeflatfeeruninvoicedusage.FieldDeletedAt: + return m.DeletedAt() + case chargeflatfeeruninvoicedusage.FieldAnnotations: + return m.Annotations() + case chargeflatfeeruninvoicedusage.FieldAmount: + return m.Amount() + case chargeflatfeeruninvoicedusage.FieldTaxesTotal: + return m.TaxesTotal() + case chargeflatfeeruninvoicedusage.FieldTaxesInclusiveTotal: + return m.TaxesInclusiveTotal() + case chargeflatfeeruninvoicedusage.FieldTaxesExclusiveTotal: + return m.TaxesExclusiveTotal() + case chargeflatfeeruninvoicedusage.FieldChargesTotal: + return m.ChargesTotal() + case chargeflatfeeruninvoicedusage.FieldDiscountsTotal: + return m.DiscountsTotal() + case chargeflatfeeruninvoicedusage.FieldCreditsTotal: + return m.CreditsTotal() + case chargeflatfeeruninvoicedusage.FieldTotal: + return m.Total() + case chargeflatfeeruninvoicedusage.FieldRunID: + return m.RunID() + } + 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 *ChargeFlatFeeRunInvoicedUsageMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case chargeflatfeeruninvoicedusage.FieldServicePeriodFrom: + return m.OldServicePeriodFrom(ctx) + case chargeflatfeeruninvoicedusage.FieldServicePeriodTo: + return m.OldServicePeriodTo(ctx) + case chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID: + return m.OldLedgerTransactionGroupID(ctx) + case chargeflatfeeruninvoicedusage.FieldNamespace: + return m.OldNamespace(ctx) + case chargeflatfeeruninvoicedusage.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case chargeflatfeeruninvoicedusage.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case chargeflatfeeruninvoicedusage.FieldDeletedAt: + return m.OldDeletedAt(ctx) + case chargeflatfeeruninvoicedusage.FieldAnnotations: + return m.OldAnnotations(ctx) + case chargeflatfeeruninvoicedusage.FieldAmount: + return m.OldAmount(ctx) + case chargeflatfeeruninvoicedusage.FieldTaxesTotal: + return m.OldTaxesTotal(ctx) + case chargeflatfeeruninvoicedusage.FieldTaxesInclusiveTotal: + return m.OldTaxesInclusiveTotal(ctx) + case chargeflatfeeruninvoicedusage.FieldTaxesExclusiveTotal: + return m.OldTaxesExclusiveTotal(ctx) + case chargeflatfeeruninvoicedusage.FieldChargesTotal: + return m.OldChargesTotal(ctx) + case chargeflatfeeruninvoicedusage.FieldDiscountsTotal: + return m.OldDiscountsTotal(ctx) + case chargeflatfeeruninvoicedusage.FieldCreditsTotal: + return m.OldCreditsTotal(ctx) + case chargeflatfeeruninvoicedusage.FieldTotal: + return m.OldTotal(ctx) + case chargeflatfeeruninvoicedusage.FieldRunID: + return m.OldRunID(ctx) + } + return nil, fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) SetField(name string, value ent.Value) error { + switch name { + case chargeflatfeeruninvoicedusage.FieldServicePeriodFrom: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServicePeriodFrom(v) + return nil + case chargeflatfeeruninvoicedusage.FieldServicePeriodTo: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServicePeriodTo(v) + return nil + case chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLedgerTransactionGroupID(v) + return nil + case chargeflatfeeruninvoicedusage.FieldNamespace: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNamespace(v) + return nil + case chargeflatfeeruninvoicedusage.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 chargeflatfeeruninvoicedusage.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 chargeflatfeeruninvoicedusage.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 chargeflatfeeruninvoicedusage.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 chargeflatfeeruninvoicedusage.FieldAmount: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAmount(v) + return nil + case chargeflatfeeruninvoicedusage.FieldTaxesTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTaxesTotal(v) + return nil + case chargeflatfeeruninvoicedusage.FieldTaxesInclusiveTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTaxesInclusiveTotal(v) + return nil + case chargeflatfeeruninvoicedusage.FieldTaxesExclusiveTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTaxesExclusiveTotal(v) + return nil + case chargeflatfeeruninvoicedusage.FieldChargesTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetChargesTotal(v) + return nil + case chargeflatfeeruninvoicedusage.FieldDiscountsTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDiscountsTotal(v) + return nil + case chargeflatfeeruninvoicedusage.FieldCreditsTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreditsTotal(v) + return nil + case chargeflatfeeruninvoicedusage.FieldTotal: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTotal(v) + return nil + case chargeflatfeeruninvoicedusage.FieldRunID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRunID(v) + return nil + } + return fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) 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 *ChargeFlatFeeRunInvoicedUsageMutation) 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 *ChargeFlatFeeRunInvoicedUsageMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID) { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID) + } + if m.FieldCleared(chargeflatfeeruninvoicedusage.FieldDeletedAt) { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldDeletedAt) + } + if m.FieldCleared(chargeflatfeeruninvoicedusage.FieldAnnotations) { + fields = append(fields, chargeflatfeeruninvoicedusage.FieldAnnotations) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) 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 *ChargeFlatFeeRunInvoicedUsageMutation) ClearField(name string) error { + switch name { + case chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID: + m.ClearLedgerTransactionGroupID() + return nil + case chargeflatfeeruninvoicedusage.FieldDeletedAt: + m.ClearDeletedAt() + return nil + case chargeflatfeeruninvoicedusage.FieldAnnotations: + m.ClearAnnotations() + return nil + } + return fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) ResetField(name string) error { + switch name { + case chargeflatfeeruninvoicedusage.FieldServicePeriodFrom: + m.ResetServicePeriodFrom() + return nil + case chargeflatfeeruninvoicedusage.FieldServicePeriodTo: + m.ResetServicePeriodTo() + return nil + case chargeflatfeeruninvoicedusage.FieldLedgerTransactionGroupID: + m.ResetLedgerTransactionGroupID() + return nil + case chargeflatfeeruninvoicedusage.FieldNamespace: + m.ResetNamespace() + return nil + case chargeflatfeeruninvoicedusage.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case chargeflatfeeruninvoicedusage.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case chargeflatfeeruninvoicedusage.FieldDeletedAt: + m.ResetDeletedAt() + return nil + case chargeflatfeeruninvoicedusage.FieldAnnotations: + m.ResetAnnotations() + return nil + case chargeflatfeeruninvoicedusage.FieldAmount: + m.ResetAmount() + return nil + case chargeflatfeeruninvoicedusage.FieldTaxesTotal: + m.ResetTaxesTotal() + return nil + case chargeflatfeeruninvoicedusage.FieldTaxesInclusiveTotal: + m.ResetTaxesInclusiveTotal() + return nil + case chargeflatfeeruninvoicedusage.FieldTaxesExclusiveTotal: + m.ResetTaxesExclusiveTotal() + return nil + case chargeflatfeeruninvoicedusage.FieldChargesTotal: + m.ResetChargesTotal() + return nil + case chargeflatfeeruninvoicedusage.FieldDiscountsTotal: + m.ResetDiscountsTotal() + return nil + case chargeflatfeeruninvoicedusage.FieldCreditsTotal: + m.ResetCreditsTotal() + return nil + case chargeflatfeeruninvoicedusage.FieldTotal: + m.ResetTotal() + return nil + case chargeflatfeeruninvoicedusage.FieldRunID: + m.ResetRunID() + return nil + } + return fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.run != nil { + edges = append(edges, chargeflatfeeruninvoicedusage.EdgeRun) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) AddedIDs(name string) []ent.Value { + switch name { + case chargeflatfeeruninvoicedusage.EdgeRun: + if id := m.run; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedrun { + edges = append(edges, chargeflatfeeruninvoicedusage.EdgeRun) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ChargeFlatFeeRunInvoicedUsageMutation) EdgeCleared(name string) bool { + switch name { + case chargeflatfeeruninvoicedusage.EdgeRun: + return m.clearedrun + } + 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 *ChargeFlatFeeRunInvoicedUsageMutation) ClearEdge(name string) error { + switch name { + case chargeflatfeeruninvoicedusage.EdgeRun: + m.ClearRun() + return nil + } + return fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage 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 *ChargeFlatFeeRunInvoicedUsageMutation) ResetEdge(name string) error { + switch name { + case chargeflatfeeruninvoicedusage.EdgeRun: + m.ResetRun() + return nil + } + return fmt.Errorf("unknown ChargeFlatFeeRunInvoicedUsage edge %s", name) +} + +// ChargeFlatFeeRunPaymentMutation represents an operation that mutates the ChargeFlatFeeRunPayment nodes in the graph. +type ChargeFlatFeeRunPaymentMutation struct { + config + op Op + typ string + id *string + invoice_id *string + service_period_from *time.Time + service_period_to *time.Time + status *payment.Status + amount *alpacadecimal.Decimal + authorized_transaction_group_id *string + authorized_at *time.Time + settled_transaction_group_id *string + settled_at *time.Time + namespace *string + created_at *time.Time + updated_at *time.Time + deleted_at *time.Time + annotations *models.Annotations + clearedFields map[string]struct{} + billing_invoice_line *string + clearedbilling_invoice_line bool + run *string + clearedrun bool + done bool + oldValue func(context.Context) (*ChargeFlatFeeRunPayment, error) + predicates []predicate.ChargeFlatFeeRunPayment +} + +var _ ent.Mutation = (*ChargeFlatFeeRunPaymentMutation)(nil) + +// chargeflatfeerunpaymentOption allows management of the mutation configuration using functional options. +type chargeflatfeerunpaymentOption func(*ChargeFlatFeeRunPaymentMutation) + +// newChargeFlatFeeRunPaymentMutation creates new mutation for the ChargeFlatFeeRunPayment entity. +func newChargeFlatFeeRunPaymentMutation(c config, op Op, opts ...chargeflatfeerunpaymentOption) *ChargeFlatFeeRunPaymentMutation { + m := &ChargeFlatFeeRunPaymentMutation{ + config: c, + op: op, + typ: TypeChargeFlatFeeRunPayment, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withChargeFlatFeeRunPaymentID sets the ID field of the mutation. +func withChargeFlatFeeRunPaymentID(id string) chargeflatfeerunpaymentOption { + return func(m *ChargeFlatFeeRunPaymentMutation) { + var ( + err error + once sync.Once + value *ChargeFlatFeeRunPayment + ) + m.oldValue = func(ctx context.Context) (*ChargeFlatFeeRunPayment, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().ChargeFlatFeeRunPayment.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withChargeFlatFeeRunPayment sets the old ChargeFlatFeeRunPayment of the mutation. +func withChargeFlatFeeRunPayment(node *ChargeFlatFeeRunPayment) chargeflatfeerunpaymentOption { + return func(m *ChargeFlatFeeRunPaymentMutation) { + m.oldValue = func(context.Context) (*ChargeFlatFeeRunPayment, 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 ChargeFlatFeeRunPaymentMutation) 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 ChargeFlatFeeRunPaymentMutation) 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 ChargeFlatFeeRunPayment entities. +func (m *ChargeFlatFeeRunPaymentMutation) 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 *ChargeFlatFeeRunPaymentMutation) 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 *ChargeFlatFeeRunPaymentMutation) 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().ChargeFlatFeeRunPayment.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetLineID sets the "line_id" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetLineID(s string) { + m.billing_invoice_line = &s +} + +// LineID returns the value of the "line_id" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) LineID() (r string, exists bool) { + v := m.billing_invoice_line + if v == nil { + return + } + return *v, true +} + +// OldLineID returns the old "line_id" field's value of the ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) OldLineID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLineID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLineID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLineID: %w", err) + } + return oldValue.LineID, nil +} + +// ResetLineID resets all changes to the "line_id" field. +func (m *ChargeFlatFeeRunPaymentMutation) ResetLineID() { + m.billing_invoice_line = nil +} + +// SetInvoiceID sets the "invoice_id" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetInvoiceID(s string) { + m.invoice_id = &s +} + +// InvoiceID returns the value of the "invoice_id" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) InvoiceID() (r string, exists bool) { + v := m.invoice_id + if v == nil { + return + } + return *v, true +} + +// OldInvoiceID returns the old "invoice_id" field's value of the ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) 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 *ChargeFlatFeeRunPaymentMutation) ResetInvoiceID() { + m.invoice_id = nil +} + +// SetServicePeriodFrom sets the "service_period_from" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetServicePeriodFrom(t time.Time) { + m.service_period_from = &t +} + +// ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) ServicePeriodFrom() (r time.Time, exists bool) { + v := m.service_period_from + if v == nil { + return + } + return *v, true +} + +// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldServicePeriodFrom requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldServicePeriodFrom: %w", err) + } + return oldValue.ServicePeriodFrom, nil +} + +// ResetServicePeriodFrom resets all changes to the "service_period_from" field. +func (m *ChargeFlatFeeRunPaymentMutation) ResetServicePeriodFrom() { + m.service_period_from = nil +} + +// SetServicePeriodTo sets the "service_period_to" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetServicePeriodTo(t time.Time) { + m.service_period_to = &t +} + +// ServicePeriodTo returns the value of the "service_period_to" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) ServicePeriodTo() (r time.Time, exists bool) { + v := m.service_period_to + if v == nil { + return + } + return *v, true +} + +// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldServicePeriodTo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldServicePeriodTo: %w", err) + } + return oldValue.ServicePeriodTo, nil +} + +// ResetServicePeriodTo resets all changes to the "service_period_to" field. +func (m *ChargeFlatFeeRunPaymentMutation) ResetServicePeriodTo() { + m.service_period_to = nil +} + +// SetStatus sets the "status" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetStatus(pa payment.Status) { + m.status = &pa +} + +// Status returns the value of the "status" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) Status() (r payment.Status, exists bool) { + v := m.status + if v == nil { + return + } + return *v, true +} + +// OldStatus returns the old "status" field's value of the ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) OldStatus(ctx context.Context) (v payment.Status, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil +} + +// ResetStatus resets all changes to the "status" field. +func (m *ChargeFlatFeeRunPaymentMutation) ResetStatus() { + m.status = nil +} + +// SetAmount sets the "amount" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetAmount(a alpacadecimal.Decimal) { + m.amount = &a +} + +// Amount returns the value of the "amount" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) Amount() (r alpacadecimal.Decimal, exists bool) { + v := m.amount + if v == nil { + return + } + return *v, true +} + +// OldAmount returns the old "amount" field's value of the ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) OldAmount(ctx context.Context) (v alpacadecimal.Decimal, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAmount is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAmount requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAmount: %w", err) + } + return oldValue.Amount, nil +} + +// ResetAmount resets all changes to the "amount" field. +func (m *ChargeFlatFeeRunPaymentMutation) ResetAmount() { + m.amount = nil +} + +// SetAuthorizedTransactionGroupID sets the "authorized_transaction_group_id" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetAuthorizedTransactionGroupID(s string) { + m.authorized_transaction_group_id = &s +} + +// AuthorizedTransactionGroupID returns the value of the "authorized_transaction_group_id" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) AuthorizedTransactionGroupID() (r string, exists bool) { + v := m.authorized_transaction_group_id + if v == nil { + return + } + return *v, true +} + +// OldAuthorizedTransactionGroupID returns the old "authorized_transaction_group_id" field's value of the ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) OldAuthorizedTransactionGroupID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAuthorizedTransactionGroupID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAuthorizedTransactionGroupID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAuthorizedTransactionGroupID: %w", err) + } + return oldValue.AuthorizedTransactionGroupID, nil +} + +// ClearAuthorizedTransactionGroupID clears the value of the "authorized_transaction_group_id" field. +func (m *ChargeFlatFeeRunPaymentMutation) ClearAuthorizedTransactionGroupID() { + m.authorized_transaction_group_id = nil + m.clearedFields[chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID] = struct{}{} +} + +// AuthorizedTransactionGroupIDCleared returns if the "authorized_transaction_group_id" field was cleared in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) AuthorizedTransactionGroupIDCleared() bool { + _, ok := m.clearedFields[chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID] + return ok +} + +// ResetAuthorizedTransactionGroupID resets all changes to the "authorized_transaction_group_id" field. +func (m *ChargeFlatFeeRunPaymentMutation) ResetAuthorizedTransactionGroupID() { + m.authorized_transaction_group_id = nil + delete(m.clearedFields, chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID) +} + +// SetAuthorizedAt sets the "authorized_at" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetAuthorizedAt(t time.Time) { + m.authorized_at = &t +} + +// AuthorizedAt returns the value of the "authorized_at" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) AuthorizedAt() (r time.Time, exists bool) { + v := m.authorized_at + if v == nil { + return + } + return *v, true +} + +// OldAuthorizedAt returns the old "authorized_at" field's value of the ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) OldAuthorizedAt(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAuthorizedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAuthorizedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAuthorizedAt: %w", err) + } + return oldValue.AuthorizedAt, nil +} + +// ClearAuthorizedAt clears the value of the "authorized_at" field. +func (m *ChargeFlatFeeRunPaymentMutation) ClearAuthorizedAt() { + m.authorized_at = nil + m.clearedFields[chargeflatfeerunpayment.FieldAuthorizedAt] = struct{}{} +} + +// AuthorizedAtCleared returns if the "authorized_at" field was cleared in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) AuthorizedAtCleared() bool { + _, ok := m.clearedFields[chargeflatfeerunpayment.FieldAuthorizedAt] + return ok +} + +// ResetAuthorizedAt resets all changes to the "authorized_at" field. +func (m *ChargeFlatFeeRunPaymentMutation) ResetAuthorizedAt() { + m.authorized_at = nil + delete(m.clearedFields, chargeflatfeerunpayment.FieldAuthorizedAt) +} + +// SetSettledTransactionGroupID sets the "settled_transaction_group_id" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetSettledTransactionGroupID(s string) { + m.settled_transaction_group_id = &s +} + +// SettledTransactionGroupID returns the value of the "settled_transaction_group_id" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) SettledTransactionGroupID() (r string, exists bool) { + v := m.settled_transaction_group_id + if v == nil { + return + } + return *v, true +} + +// OldSettledTransactionGroupID returns the old "settled_transaction_group_id" field's value of the ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) OldSettledTransactionGroupID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSettledTransactionGroupID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSettledTransactionGroupID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSettledTransactionGroupID: %w", err) + } + return oldValue.SettledTransactionGroupID, nil +} + +// ClearSettledTransactionGroupID clears the value of the "settled_transaction_group_id" field. +func (m *ChargeFlatFeeRunPaymentMutation) ClearSettledTransactionGroupID() { + m.settled_transaction_group_id = nil + m.clearedFields[chargeflatfeerunpayment.FieldSettledTransactionGroupID] = struct{}{} +} + +// SettledTransactionGroupIDCleared returns if the "settled_transaction_group_id" field was cleared in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) SettledTransactionGroupIDCleared() bool { + _, ok := m.clearedFields[chargeflatfeerunpayment.FieldSettledTransactionGroupID] + return ok +} + +// ResetSettledTransactionGroupID resets all changes to the "settled_transaction_group_id" field. +func (m *ChargeFlatFeeRunPaymentMutation) ResetSettledTransactionGroupID() { + m.settled_transaction_group_id = nil + delete(m.clearedFields, chargeflatfeerunpayment.FieldSettledTransactionGroupID) +} + +// SetSettledAt sets the "settled_at" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetSettledAt(t time.Time) { + m.settled_at = &t +} + +// SettledAt returns the value of the "settled_at" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) SettledAt() (r time.Time, exists bool) { + v := m.settled_at + if v == nil { + return + } + return *v, true +} + +// OldSettledAt returns the old "settled_at" field's value of the ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) OldSettledAt(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSettledAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSettledAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSettledAt: %w", err) + } + return oldValue.SettledAt, nil +} + +// ClearSettledAt clears the value of the "settled_at" field. +func (m *ChargeFlatFeeRunPaymentMutation) ClearSettledAt() { + m.settled_at = nil + m.clearedFields[chargeflatfeerunpayment.FieldSettledAt] = struct{}{} +} + +// SettledAtCleared returns if the "settled_at" field was cleared in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) SettledAtCleared() bool { + _, ok := m.clearedFields[chargeflatfeerunpayment.FieldSettledAt] + return ok +} + +// ResetSettledAt resets all changes to the "settled_at" field. +func (m *ChargeFlatFeeRunPaymentMutation) ResetSettledAt() { + m.settled_at = nil + delete(m.clearedFields, chargeflatfeerunpayment.FieldSettledAt) +} + +// SetNamespace sets the "namespace" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetNamespace(s string) { + m.namespace = &s +} + +// Namespace returns the value of the "namespace" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) 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 ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) 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 *ChargeFlatFeeRunPaymentMutation) ResetNamespace() { + m.namespace = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) 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 ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) 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 *ChargeFlatFeeRunPaymentMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) 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 ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) 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 *ChargeFlatFeeRunPaymentMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// SetDeletedAt sets the "deleted_at" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetDeletedAt(t time.Time) { + m.deleted_at = &t +} + +// DeletedAt returns the value of the "deleted_at" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) 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 ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) 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 *ChargeFlatFeeRunPaymentMutation) ClearDeletedAt() { + m.deleted_at = nil + m.clearedFields[chargeflatfeerunpayment.FieldDeletedAt] = struct{}{} +} + +// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargeflatfeerunpayment.FieldDeletedAt] + return ok +} + +// ResetDeletedAt resets all changes to the "deleted_at" field. +func (m *ChargeFlatFeeRunPaymentMutation) ResetDeletedAt() { + m.deleted_at = nil + delete(m.clearedFields, chargeflatfeerunpayment.FieldDeletedAt) +} + +// SetAnnotations sets the "annotations" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetAnnotations(value models.Annotations) { + m.annotations = &value +} + +// Annotations returns the value of the "annotations" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) 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 ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) 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 *ChargeFlatFeeRunPaymentMutation) ClearAnnotations() { + m.annotations = nil + m.clearedFields[chargeflatfeerunpayment.FieldAnnotations] = struct{}{} +} + +// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) AnnotationsCleared() bool { + _, ok := m.clearedFields[chargeflatfeerunpayment.FieldAnnotations] + return ok +} + +// ResetAnnotations resets all changes to the "annotations" field. +func (m *ChargeFlatFeeRunPaymentMutation) ResetAnnotations() { + m.annotations = nil + delete(m.clearedFields, chargeflatfeerunpayment.FieldAnnotations) +} + +// SetRunID sets the "run_id" field. +func (m *ChargeFlatFeeRunPaymentMutation) SetRunID(s string) { + m.run = &s +} + +// RunID returns the value of the "run_id" field in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) RunID() (r string, exists bool) { + v := m.run + if v == nil { + return + } + return *v, true +} + +// OldRunID returns the old "run_id" field's value of the ChargeFlatFeeRunPayment entity. +// If the ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) OldRunID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRunID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRunID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRunID: %w", err) + } + return oldValue.RunID, nil +} + +// ResetRunID resets all changes to the "run_id" field. +func (m *ChargeFlatFeeRunPaymentMutation) ResetRunID() { + m.run = nil +} + +// SetBillingInvoiceLineID sets the "billing_invoice_line" edge to the BillingInvoiceLine entity by id. +func (m *ChargeFlatFeeRunPaymentMutation) SetBillingInvoiceLineID(id string) { + m.billing_invoice_line = &id +} + +// ClearBillingInvoiceLine clears the "billing_invoice_line" edge to the BillingInvoiceLine entity. +func (m *ChargeFlatFeeRunPaymentMutation) ClearBillingInvoiceLine() { + m.clearedbilling_invoice_line = true + m.clearedFields[chargeflatfeerunpayment.FieldLineID] = struct{}{} +} + +// BillingInvoiceLineCleared reports if the "billing_invoice_line" edge to the BillingInvoiceLine entity was cleared. +func (m *ChargeFlatFeeRunPaymentMutation) BillingInvoiceLineCleared() bool { + return m.clearedbilling_invoice_line +} + +// BillingInvoiceLineID returns the "billing_invoice_line" edge ID in the mutation. +func (m *ChargeFlatFeeRunPaymentMutation) BillingInvoiceLineID() (id string, exists bool) { + if m.billing_invoice_line != nil { + return *m.billing_invoice_line, true + } + return +} + +// BillingInvoiceLineIDs returns the "billing_invoice_line" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// BillingInvoiceLineID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeRunPaymentMutation) BillingInvoiceLineIDs() (ids []string) { + if id := m.billing_invoice_line; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetBillingInvoiceLine resets all changes to the "billing_invoice_line" edge. +func (m *ChargeFlatFeeRunPaymentMutation) ResetBillingInvoiceLine() { + m.billing_invoice_line = nil + m.clearedbilling_invoice_line = false +} + +// ClearRun clears the "run" edge to the ChargeFlatFeeRun entity. +func (m *ChargeFlatFeeRunPaymentMutation) ClearRun() { + m.clearedrun = true + m.clearedFields[chargeflatfeerunpayment.FieldRunID] = struct{}{} +} + +// RunCleared reports if the "run" edge to the ChargeFlatFeeRun entity was cleared. +func (m *ChargeFlatFeeRunPaymentMutation) RunCleared() bool { + return m.clearedrun +} + +// RunIDs returns the "run" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// RunID instead. It exists only for internal usage by the builders. +func (m *ChargeFlatFeeRunPaymentMutation) RunIDs() (ids []string) { + if id := m.run; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetRun resets all changes to the "run" edge. +func (m *ChargeFlatFeeRunPaymentMutation) ResetRun() { + m.run = nil + m.clearedrun = false +} + +// Where appends a list predicates to the ChargeFlatFeeRunPaymentMutation builder. +func (m *ChargeFlatFeeRunPaymentMutation) Where(ps ...predicate.ChargeFlatFeeRunPayment) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the ChargeFlatFeeRunPaymentMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ChargeFlatFeeRunPaymentMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeFlatFeeRunPayment, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *ChargeFlatFeeRunPaymentMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *ChargeFlatFeeRunPaymentMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (ChargeFlatFeeRunPayment). +func (m *ChargeFlatFeeRunPaymentMutation) 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 *ChargeFlatFeeRunPaymentMutation) Fields() []string { + fields := make([]string, 0, 16) + if m.billing_invoice_line != nil { + fields = append(fields, chargeflatfeerunpayment.FieldLineID) + } + if m.invoice_id != nil { + fields = append(fields, chargeflatfeerunpayment.FieldInvoiceID) + } + if m.service_period_from != nil { + fields = append(fields, chargeflatfeerunpayment.FieldServicePeriodFrom) + } + if m.service_period_to != nil { + fields = append(fields, chargeflatfeerunpayment.FieldServicePeriodTo) + } + if m.status != nil { + fields = append(fields, chargeflatfeerunpayment.FieldStatus) + } + if m.amount != nil { + fields = append(fields, chargeflatfeerunpayment.FieldAmount) + } + if m.authorized_transaction_group_id != nil { + fields = append(fields, chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID) + } + if m.authorized_at != nil { + fields = append(fields, chargeflatfeerunpayment.FieldAuthorizedAt) + } + if m.settled_transaction_group_id != nil { + fields = append(fields, chargeflatfeerunpayment.FieldSettledTransactionGroupID) + } + if m.settled_at != nil { + fields = append(fields, chargeflatfeerunpayment.FieldSettledAt) + } + if m.namespace != nil { + fields = append(fields, chargeflatfeerunpayment.FieldNamespace) + } + if m.created_at != nil { + fields = append(fields, chargeflatfeerunpayment.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, chargeflatfeerunpayment.FieldUpdatedAt) + } + if m.deleted_at != nil { + fields = append(fields, chargeflatfeerunpayment.FieldDeletedAt) + } + if m.annotations != nil { + fields = append(fields, chargeflatfeerunpayment.FieldAnnotations) + } + if m.run != nil { + fields = append(fields, chargeflatfeerunpayment.FieldRunID) + } + 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 *ChargeFlatFeeRunPaymentMutation) Field(name string) (ent.Value, bool) { + switch name { + case chargeflatfeerunpayment.FieldLineID: + return m.LineID() + case chargeflatfeerunpayment.FieldInvoiceID: + return m.InvoiceID() + case chargeflatfeerunpayment.FieldServicePeriodFrom: + return m.ServicePeriodFrom() + case chargeflatfeerunpayment.FieldServicePeriodTo: + return m.ServicePeriodTo() + case chargeflatfeerunpayment.FieldStatus: + return m.Status() + case chargeflatfeerunpayment.FieldAmount: + return m.Amount() + case chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID: + return m.AuthorizedTransactionGroupID() + case chargeflatfeerunpayment.FieldAuthorizedAt: + return m.AuthorizedAt() + case chargeflatfeerunpayment.FieldSettledTransactionGroupID: + return m.SettledTransactionGroupID() + case chargeflatfeerunpayment.FieldSettledAt: + return m.SettledAt() + case chargeflatfeerunpayment.FieldNamespace: + return m.Namespace() + case chargeflatfeerunpayment.FieldCreatedAt: + return m.CreatedAt() + case chargeflatfeerunpayment.FieldUpdatedAt: + return m.UpdatedAt() + case chargeflatfeerunpayment.FieldDeletedAt: + return m.DeletedAt() + case chargeflatfeerunpayment.FieldAnnotations: + return m.Annotations() + case chargeflatfeerunpayment.FieldRunID: + return m.RunID() + } + 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 *ChargeFlatFeeRunPaymentMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case chargeflatfeerunpayment.FieldLineID: + return m.OldLineID(ctx) + case chargeflatfeerunpayment.FieldInvoiceID: + return m.OldInvoiceID(ctx) + case chargeflatfeerunpayment.FieldServicePeriodFrom: + return m.OldServicePeriodFrom(ctx) + case chargeflatfeerunpayment.FieldServicePeriodTo: + return m.OldServicePeriodTo(ctx) + case chargeflatfeerunpayment.FieldStatus: + return m.OldStatus(ctx) + case chargeflatfeerunpayment.FieldAmount: + return m.OldAmount(ctx) + case chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID: + return m.OldAuthorizedTransactionGroupID(ctx) + case chargeflatfeerunpayment.FieldAuthorizedAt: + return m.OldAuthorizedAt(ctx) + case chargeflatfeerunpayment.FieldSettledTransactionGroupID: + return m.OldSettledTransactionGroupID(ctx) + case chargeflatfeerunpayment.FieldSettledAt: + return m.OldSettledAt(ctx) + case chargeflatfeerunpayment.FieldNamespace: + return m.OldNamespace(ctx) + case chargeflatfeerunpayment.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case chargeflatfeerunpayment.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case chargeflatfeerunpayment.FieldDeletedAt: + return m.OldDeletedAt(ctx) + case chargeflatfeerunpayment.FieldAnnotations: + return m.OldAnnotations(ctx) + case chargeflatfeerunpayment.FieldRunID: + return m.OldRunID(ctx) + } + return nil, fmt.Errorf("unknown ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) SetField(name string, value ent.Value) error { + switch name { + case chargeflatfeerunpayment.FieldLineID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLineID(v) + return nil + case chargeflatfeerunpayment.FieldInvoiceID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetInvoiceID(v) + return nil + case chargeflatfeerunpayment.FieldServicePeriodFrom: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServicePeriodFrom(v) + return nil + case chargeflatfeerunpayment.FieldServicePeriodTo: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServicePeriodTo(v) + return nil + case chargeflatfeerunpayment.FieldStatus: + v, ok := value.(payment.Status) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + case chargeflatfeerunpayment.FieldAmount: + v, ok := value.(alpacadecimal.Decimal) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAmount(v) + return nil + case chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAuthorizedTransactionGroupID(v) + return nil + case chargeflatfeerunpayment.FieldAuthorizedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAuthorizedAt(v) + return nil + case chargeflatfeerunpayment.FieldSettledTransactionGroupID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSettledTransactionGroupID(v) + return nil + case chargeflatfeerunpayment.FieldSettledAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSettledAt(v) + return nil + case chargeflatfeerunpayment.FieldNamespace: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNamespace(v) + return nil + case chargeflatfeerunpayment.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 chargeflatfeerunpayment.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 chargeflatfeerunpayment.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 chargeflatfeerunpayment.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 chargeflatfeerunpayment.FieldRunID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRunID(v) + return nil + } + return fmt.Errorf("unknown ChargeFlatFeeRunPayment field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) 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 *ChargeFlatFeeRunPaymentMutation) 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 *ChargeFlatFeeRunPaymentMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown ChargeFlatFeeRunPayment numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ChargeFlatFeeRunPaymentMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID) { + fields = append(fields, chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID) + } + if m.FieldCleared(chargeflatfeerunpayment.FieldAuthorizedAt) { + fields = append(fields, chargeflatfeerunpayment.FieldAuthorizedAt) + } + if m.FieldCleared(chargeflatfeerunpayment.FieldSettledTransactionGroupID) { + fields = append(fields, chargeflatfeerunpayment.FieldSettledTransactionGroupID) + } + if m.FieldCleared(chargeflatfeerunpayment.FieldSettledAt) { + fields = append(fields, chargeflatfeerunpayment.FieldSettledAt) + } + if m.FieldCleared(chargeflatfeerunpayment.FieldDeletedAt) { + fields = append(fields, chargeflatfeerunpayment.FieldDeletedAt) + } + if m.FieldCleared(chargeflatfeerunpayment.FieldAnnotations) { + fields = append(fields, chargeflatfeerunpayment.FieldAnnotations) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) 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 *ChargeFlatFeeRunPaymentMutation) ClearField(name string) error { + switch name { + case chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID: + m.ClearAuthorizedTransactionGroupID() + return nil + case chargeflatfeerunpayment.FieldAuthorizedAt: + m.ClearAuthorizedAt() + return nil + case chargeflatfeerunpayment.FieldSettledTransactionGroupID: + m.ClearSettledTransactionGroupID() + return nil + case chargeflatfeerunpayment.FieldSettledAt: + m.ClearSettledAt() + return nil + case chargeflatfeerunpayment.FieldDeletedAt: + m.ClearDeletedAt() + return nil + case chargeflatfeerunpayment.FieldAnnotations: + m.ClearAnnotations() + return nil + } + return fmt.Errorf("unknown ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) ResetField(name string) error { + switch name { + case chargeflatfeerunpayment.FieldLineID: + m.ResetLineID() + return nil + case chargeflatfeerunpayment.FieldInvoiceID: + m.ResetInvoiceID() + return nil + case chargeflatfeerunpayment.FieldServicePeriodFrom: + m.ResetServicePeriodFrom() + return nil + case chargeflatfeerunpayment.FieldServicePeriodTo: + m.ResetServicePeriodTo() + return nil + case chargeflatfeerunpayment.FieldStatus: + m.ResetStatus() + return nil + case chargeflatfeerunpayment.FieldAmount: + m.ResetAmount() + return nil + case chargeflatfeerunpayment.FieldAuthorizedTransactionGroupID: + m.ResetAuthorizedTransactionGroupID() + return nil + case chargeflatfeerunpayment.FieldAuthorizedAt: + m.ResetAuthorizedAt() + return nil + case chargeflatfeerunpayment.FieldSettledTransactionGroupID: + m.ResetSettledTransactionGroupID() + return nil + case chargeflatfeerunpayment.FieldSettledAt: + m.ResetSettledAt() + return nil + case chargeflatfeerunpayment.FieldNamespace: + m.ResetNamespace() + return nil + case chargeflatfeerunpayment.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case chargeflatfeerunpayment.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case chargeflatfeerunpayment.FieldDeletedAt: + m.ResetDeletedAt() + return nil + case chargeflatfeerunpayment.FieldAnnotations: + m.ResetAnnotations() + return nil + case chargeflatfeerunpayment.FieldRunID: + m.ResetRunID() + return nil + } + return fmt.Errorf("unknown ChargeFlatFeeRunPayment field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) AddedEdges() []string { + edges := make([]string, 0, 2) + if m.billing_invoice_line != nil { + edges = append(edges, chargeflatfeerunpayment.EdgeBillingInvoiceLine) + } + if m.run != nil { + edges = append(edges, chargeflatfeerunpayment.EdgeRun) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) AddedIDs(name string) []ent.Value { + switch name { + case chargeflatfeerunpayment.EdgeBillingInvoiceLine: + if id := m.billing_invoice_line; id != nil { + return []ent.Value{*id} + } + case chargeflatfeerunpayment.EdgeRun: + if id := m.run; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.clearedbilling_invoice_line { + edges = append(edges, chargeflatfeerunpayment.EdgeBillingInvoiceLine) + } + if m.clearedrun { + edges = append(edges, chargeflatfeerunpayment.EdgeRun) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ChargeFlatFeeRunPaymentMutation) EdgeCleared(name string) bool { + switch name { + case chargeflatfeerunpayment.EdgeBillingInvoiceLine: + return m.clearedbilling_invoice_line + case chargeflatfeerunpayment.EdgeRun: + return m.clearedrun + } + 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 *ChargeFlatFeeRunPaymentMutation) ClearEdge(name string) error { + switch name { + case chargeflatfeerunpayment.EdgeBillingInvoiceLine: + m.ClearBillingInvoiceLine() + return nil + case chargeflatfeerunpayment.EdgeRun: + m.ClearRun() + return nil + } + return fmt.Errorf("unknown ChargeFlatFeeRunPayment 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 *ChargeFlatFeeRunPaymentMutation) ResetEdge(name string) error { + switch name { + case chargeflatfeerunpayment.EdgeBillingInvoiceLine: + m.ResetBillingInvoiceLine() + return nil + case chargeflatfeerunpayment.EdgeRun: + m.ResetRun() + return nil + } + return fmt.Errorf("unknown ChargeFlatFeeRunPayment edge %s", name) +} + +// ChargeUsageBasedMutation represents an operation that mutates the ChargeUsageBased nodes in the graph. +type ChargeUsageBasedMutation struct { + config + op Op + typ string + id *string + service_period_from *time.Time + service_period_to *time.Time + billing_period_from *time.Time + billing_period_to *time.Time + full_service_period_from *time.Time + full_service_period_to *time.Time + status *meta.ChargeStatus + unique_reference_id *string + fiat_currency_code *currencyx.Code + managed_by *billing.InvoiceLineManagedBy + advance_after *time.Time + tax_behavior *productcatalog.TaxBehavior + 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 + invoice_at *time.Time + settlement_mode *productcatalog.SettlementMode + intent_deleted_at *time.Time + discounts **billing.Discounts + feature_key *string + rating_engine *usagebased.RatingEngine + price **productcatalog.Price + unit_config **productcatalog.UnitConfig + status_detailed *usagebased.Status + clearedFields map[string]struct{} + runs map[string]struct{} + removedruns map[string]struct{} + clearedruns bool + detailed_lines map[string]struct{} + removeddetailed_lines map[string]struct{} + cleareddetailed_lines bool + current_run *string + clearedcurrent_run bool + cost_basis *string + clearedcost_basis bool + charge *string + clearedcharge bool + intent_override *string + clearedintent_override bool + subscription *string + clearedsubscription bool + subscription_phase *string + clearedsubscription_phase bool + subscription_item *string + clearedsubscription_item bool + customer *string + clearedcustomer bool + feature *string + clearedfeature bool + tax_code *string + clearedtax_code bool + custom_currency *string + clearedcustom_currency bool + done bool + oldValue func(context.Context) (*ChargeUsageBased, error) + predicates []predicate.ChargeUsageBased +} + +var _ ent.Mutation = (*ChargeUsageBasedMutation)(nil) + +// chargeusagebasedOption allows management of the mutation configuration using functional options. +type chargeusagebasedOption func(*ChargeUsageBasedMutation) + +// newChargeUsageBasedMutation creates new mutation for the ChargeUsageBased entity. +func newChargeUsageBasedMutation(c config, op Op, opts ...chargeusagebasedOption) *ChargeUsageBasedMutation { + m := &ChargeUsageBasedMutation{ + config: c, + op: op, + typ: TypeChargeUsageBased, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withChargeUsageBasedID sets the ID field of the mutation. +func withChargeUsageBasedID(id string) chargeusagebasedOption { + return func(m *ChargeUsageBasedMutation) { + var ( + err error + once sync.Once + value *ChargeUsageBased + ) + m.oldValue = func(ctx context.Context) (*ChargeUsageBased, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().ChargeUsageBased.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withChargeUsageBased sets the old ChargeUsageBased of the mutation. +func withChargeUsageBased(node *ChargeUsageBased) chargeusagebasedOption { + return func(m *ChargeUsageBasedMutation) { + m.oldValue = func(context.Context) (*ChargeUsageBased, 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 ChargeUsageBasedMutation) 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 ChargeUsageBasedMutation) 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 ChargeUsageBased entities. +func (m *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) 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().ChargeUsageBased.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetCustomerID sets the "customer_id" field. +func (m *ChargeUsageBasedMutation) SetCustomerID(s string) { + m.customer = &s +} + +// CustomerID returns the value of the "customer_id" field in the mutation. +func (m *ChargeUsageBasedMutation) CustomerID() (r string, exists bool) { + v := m.customer + if v == nil { + return + } + return *v, true +} + +// OldCustomerID returns the old "customer_id" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldCustomerID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCustomerID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCustomerID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCustomerID: %w", err) + } + return oldValue.CustomerID, nil +} + +// ResetCustomerID resets all changes to the "customer_id" field. +func (m *ChargeUsageBasedMutation) ResetCustomerID() { + m.customer = nil +} + +// SetServicePeriodFrom sets the "service_period_from" field. +func (m *ChargeUsageBasedMutation) SetServicePeriodFrom(t time.Time) { + m.service_period_from = &t +} + +// ServicePeriodFrom returns the value of the "service_period_from" field in the mutation. +func (m *ChargeUsageBasedMutation) ServicePeriodFrom() (r time.Time, exists bool) { + v := m.service_period_from + if v == nil { + return + } + return *v, true +} + +// OldServicePeriodFrom returns the old "service_period_from" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldServicePeriodFrom(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldServicePeriodFrom is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldServicePeriodFrom requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldServicePeriodFrom: %w", err) + } + return oldValue.ServicePeriodFrom, nil +} + +// ResetServicePeriodFrom resets all changes to the "service_period_from" field. +func (m *ChargeUsageBasedMutation) ResetServicePeriodFrom() { + m.service_period_from = nil +} + +// SetServicePeriodTo sets the "service_period_to" field. +func (m *ChargeUsageBasedMutation) SetServicePeriodTo(t time.Time) { + m.service_period_to = &t +} + +// ServicePeriodTo returns the value of the "service_period_to" field in the mutation. +func (m *ChargeUsageBasedMutation) ServicePeriodTo() (r time.Time, exists bool) { + v := m.service_period_to + if v == nil { + return + } + return *v, true +} + +// OldServicePeriodTo returns the old "service_period_to" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldServicePeriodTo(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldServicePeriodTo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldServicePeriodTo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldServicePeriodTo: %w", err) + } + return oldValue.ServicePeriodTo, nil +} + +// ResetServicePeriodTo resets all changes to the "service_period_to" field. +func (m *ChargeUsageBasedMutation) ResetServicePeriodTo() { + m.service_period_to = nil +} + +// SetBillingPeriodFrom sets the "billing_period_from" field. +func (m *ChargeUsageBasedMutation) SetBillingPeriodFrom(t time.Time) { + m.billing_period_from = &t +} + +// BillingPeriodFrom returns the value of the "billing_period_from" field in the mutation. +func (m *ChargeUsageBasedMutation) BillingPeriodFrom() (r time.Time, exists bool) { + v := m.billing_period_from + if v == nil { + return + } + return *v, true +} + +// OldBillingPeriodFrom returns the old "billing_period_from" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldBillingPeriodFrom(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBillingPeriodFrom is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBillingPeriodFrom requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBillingPeriodFrom: %w", err) + } + return oldValue.BillingPeriodFrom, nil +} + +// ResetBillingPeriodFrom resets all changes to the "billing_period_from" field. +func (m *ChargeUsageBasedMutation) ResetBillingPeriodFrom() { + m.billing_period_from = nil +} + +// SetBillingPeriodTo sets the "billing_period_to" field. +func (m *ChargeUsageBasedMutation) SetBillingPeriodTo(t time.Time) { + m.billing_period_to = &t +} + +// BillingPeriodTo returns the value of the "billing_period_to" field in the mutation. +func (m *ChargeUsageBasedMutation) BillingPeriodTo() (r time.Time, exists bool) { + v := m.billing_period_to + if v == nil { + return + } + return *v, true +} + +// OldBillingPeriodTo returns the old "billing_period_to" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldBillingPeriodTo(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBillingPeriodTo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBillingPeriodTo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBillingPeriodTo: %w", err) + } + return oldValue.BillingPeriodTo, nil +} + +// ResetBillingPeriodTo resets all changes to the "billing_period_to" field. +func (m *ChargeUsageBasedMutation) ResetBillingPeriodTo() { + m.billing_period_to = nil +} + +// SetFullServicePeriodFrom sets the "full_service_period_from" field. +func (m *ChargeUsageBasedMutation) SetFullServicePeriodFrom(t time.Time) { + m.full_service_period_from = &t +} + +// FullServicePeriodFrom returns the value of the "full_service_period_from" field in the mutation. +func (m *ChargeUsageBasedMutation) FullServicePeriodFrom() (r time.Time, exists bool) { + v := m.full_service_period_from + if v == nil { + return + } + return *v, true +} + +// OldFullServicePeriodFrom returns the old "full_service_period_from" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldFullServicePeriodFrom(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFullServicePeriodFrom is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFullServicePeriodFrom requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFullServicePeriodFrom: %w", err) + } + return oldValue.FullServicePeriodFrom, nil +} + +// ResetFullServicePeriodFrom resets all changes to the "full_service_period_from" field. +func (m *ChargeUsageBasedMutation) ResetFullServicePeriodFrom() { + m.full_service_period_from = nil +} + +// SetFullServicePeriodTo sets the "full_service_period_to" field. +func (m *ChargeUsageBasedMutation) SetFullServicePeriodTo(t time.Time) { + m.full_service_period_to = &t +} + +// FullServicePeriodTo returns the value of the "full_service_period_to" field in the mutation. +func (m *ChargeUsageBasedMutation) FullServicePeriodTo() (r time.Time, exists bool) { + v := m.full_service_period_to + if v == nil { + return + } + return *v, true +} + +// OldFullServicePeriodTo returns the old "full_service_period_to" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldFullServicePeriodTo(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFullServicePeriodTo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFullServicePeriodTo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFullServicePeriodTo: %w", err) + } + return oldValue.FullServicePeriodTo, nil +} + +// ResetFullServicePeriodTo resets all changes to the "full_service_period_to" field. +func (m *ChargeUsageBasedMutation) ResetFullServicePeriodTo() { + m.full_service_period_to = nil +} + +// SetStatus sets the "status" field. +func (m *ChargeUsageBasedMutation) SetStatus(ms meta.ChargeStatus) { + m.status = &ms +} + +// Status returns the value of the "status" field in the mutation. +func (m *ChargeUsageBasedMutation) Status() (r meta.ChargeStatus, exists bool) { + v := m.status + if v == nil { + return + } + return *v, true +} + +// OldStatus returns the old "status" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldStatus(ctx context.Context) (v meta.ChargeStatus, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil +} + +// ResetStatus resets all changes to the "status" field. +func (m *ChargeUsageBasedMutation) ResetStatus() { + m.status = nil +} + +// SetUniqueReferenceID sets the "unique_reference_id" field. +func (m *ChargeUsageBasedMutation) SetUniqueReferenceID(s string) { + m.unique_reference_id = &s +} + +// UniqueReferenceID returns the value of the "unique_reference_id" field in the mutation. +func (m *ChargeUsageBasedMutation) UniqueReferenceID() (r string, exists bool) { + v := m.unique_reference_id + if v == nil { + return + } + return *v, true +} + +// OldUniqueReferenceID returns the old "unique_reference_id" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldUniqueReferenceID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUniqueReferenceID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUniqueReferenceID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUniqueReferenceID: %w", err) + } + return oldValue.UniqueReferenceID, nil +} + +// ClearUniqueReferenceID clears the value of the "unique_reference_id" field. +func (m *ChargeUsageBasedMutation) ClearUniqueReferenceID() { + m.unique_reference_id = nil + m.clearedFields[chargeusagebased.FieldUniqueReferenceID] = struct{}{} +} + +// UniqueReferenceIDCleared returns if the "unique_reference_id" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) UniqueReferenceIDCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldUniqueReferenceID] + return ok +} + +// ResetUniqueReferenceID resets all changes to the "unique_reference_id" field. +func (m *ChargeUsageBasedMutation) ResetUniqueReferenceID() { + m.unique_reference_id = nil + delete(m.clearedFields, chargeusagebased.FieldUniqueReferenceID) +} + +// SetFiatCurrencyCode sets the "fiat_currency_code" field. +func (m *ChargeUsageBasedMutation) SetFiatCurrencyCode(c currencyx.Code) { + m.fiat_currency_code = &c +} + +// FiatCurrencyCode returns the value of the "fiat_currency_code" field in the mutation. +func (m *ChargeUsageBasedMutation) FiatCurrencyCode() (r currencyx.Code, exists bool) { + v := m.fiat_currency_code + if v == nil { + return + } + return *v, true +} + +// OldFiatCurrencyCode returns the old "fiat_currency_code" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldFiatCurrencyCode(ctx context.Context) (v *currencyx.Code, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFiatCurrencyCode is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFiatCurrencyCode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFiatCurrencyCode: %w", err) + } + return oldValue.FiatCurrencyCode, nil +} + +// ClearFiatCurrencyCode clears the value of the "fiat_currency_code" field. +func (m *ChargeUsageBasedMutation) ClearFiatCurrencyCode() { + m.fiat_currency_code = nil + m.clearedFields[chargeusagebased.FieldFiatCurrencyCode] = struct{}{} +} + +// FiatCurrencyCodeCleared returns if the "fiat_currency_code" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) FiatCurrencyCodeCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldFiatCurrencyCode] + return ok +} + +// ResetFiatCurrencyCode resets all changes to the "fiat_currency_code" field. +func (m *ChargeUsageBasedMutation) ResetFiatCurrencyCode() { + m.fiat_currency_code = nil + delete(m.clearedFields, chargeusagebased.FieldFiatCurrencyCode) +} + +// SetCustomCurrencyID sets the "custom_currency_id" field. +func (m *ChargeUsageBasedMutation) SetCustomCurrencyID(s string) { + m.custom_currency = &s +} + +// CustomCurrencyID returns the value of the "custom_currency_id" field in the mutation. +func (m *ChargeUsageBasedMutation) CustomCurrencyID() (r string, exists bool) { + v := m.custom_currency + if v == nil { + return + } + return *v, true +} + +// OldCustomCurrencyID returns the old "custom_currency_id" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldCustomCurrencyID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCustomCurrencyID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCustomCurrencyID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCustomCurrencyID: %w", err) + } + return oldValue.CustomCurrencyID, nil +} + +// ClearCustomCurrencyID clears the value of the "custom_currency_id" field. +func (m *ChargeUsageBasedMutation) ClearCustomCurrencyID() { + m.custom_currency = nil + m.clearedFields[chargeusagebased.FieldCustomCurrencyID] = struct{}{} +} + +// CustomCurrencyIDCleared returns if the "custom_currency_id" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) CustomCurrencyIDCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldCustomCurrencyID] + return ok +} + +// ResetCustomCurrencyID resets all changes to the "custom_currency_id" field. +func (m *ChargeUsageBasedMutation) ResetCustomCurrencyID() { + m.custom_currency = nil + delete(m.clearedFields, chargeusagebased.FieldCustomCurrencyID) +} + +// SetManagedBy sets the "managed_by" field. +func (m *ChargeUsageBasedMutation) SetManagedBy(blmb billing.InvoiceLineManagedBy) { + m.managed_by = &blmb +} + +// ManagedBy returns the value of the "managed_by" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ResetManagedBy() { + m.managed_by = nil +} + +// SetSubscriptionID sets the "subscription_id" field. +func (m *ChargeUsageBasedMutation) SetSubscriptionID(s string) { + m.subscription = &s +} + +// SubscriptionID returns the value of the "subscription_id" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ClearSubscriptionID() { + m.subscription = nil + m.clearedFields[chargeusagebased.FieldSubscriptionID] = struct{}{} +} + +// SubscriptionIDCleared returns if the "subscription_id" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) SubscriptionIDCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldSubscriptionID] + return ok +} + +// ResetSubscriptionID resets all changes to the "subscription_id" field. +func (m *ChargeUsageBasedMutation) ResetSubscriptionID() { + m.subscription = nil + delete(m.clearedFields, chargeusagebased.FieldSubscriptionID) +} + +// SetSubscriptionPhaseID sets the "subscription_phase_id" field. +func (m *ChargeUsageBasedMutation) SetSubscriptionPhaseID(s string) { + m.subscription_phase = &s +} + +// SubscriptionPhaseID returns the value of the "subscription_phase_id" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ClearSubscriptionPhaseID() { + m.subscription_phase = nil + m.clearedFields[chargeusagebased.FieldSubscriptionPhaseID] = struct{}{} +} + +// SubscriptionPhaseIDCleared returns if the "subscription_phase_id" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) SubscriptionPhaseIDCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldSubscriptionPhaseID] + return ok +} + +// ResetSubscriptionPhaseID resets all changes to the "subscription_phase_id" field. +func (m *ChargeUsageBasedMutation) ResetSubscriptionPhaseID() { + m.subscription_phase = nil + delete(m.clearedFields, chargeusagebased.FieldSubscriptionPhaseID) +} + +// SetSubscriptionItemID sets the "subscription_item_id" field. +func (m *ChargeUsageBasedMutation) SetSubscriptionItemID(s string) { + m.subscription_item = &s +} + +// SubscriptionItemID returns the value of the "subscription_item_id" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ClearSubscriptionItemID() { + m.subscription_item = nil + m.clearedFields[chargeusagebased.FieldSubscriptionItemID] = struct{}{} +} + +// SubscriptionItemIDCleared returns if the "subscription_item_id" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) SubscriptionItemIDCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldSubscriptionItemID] + return ok +} + +// ResetSubscriptionItemID resets all changes to the "subscription_item_id" field. +func (m *ChargeUsageBasedMutation) ResetSubscriptionItemID() { + m.subscription_item = nil + delete(m.clearedFields, chargeusagebased.FieldSubscriptionItemID) +} + +// SetAdvanceAfter sets the "advance_after" field. +func (m *ChargeUsageBasedMutation) SetAdvanceAfter(t time.Time) { + m.advance_after = &t +} + +// AdvanceAfter returns the value of the "advance_after" field in the mutation. +func (m *ChargeUsageBasedMutation) AdvanceAfter() (r time.Time, exists bool) { + v := m.advance_after + if v == nil { + return + } + return *v, true +} + +// OldAdvanceAfter returns the old "advance_after" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldAdvanceAfter(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAdvanceAfter is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAdvanceAfter requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAdvanceAfter: %w", err) + } + return oldValue.AdvanceAfter, nil +} + +// ClearAdvanceAfter clears the value of the "advance_after" field. +func (m *ChargeUsageBasedMutation) ClearAdvanceAfter() { + m.advance_after = nil + m.clearedFields[chargeusagebased.FieldAdvanceAfter] = struct{}{} +} + +// AdvanceAfterCleared returns if the "advance_after" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) AdvanceAfterCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldAdvanceAfter] + return ok +} + +// ResetAdvanceAfter resets all changes to the "advance_after" field. +func (m *ChargeUsageBasedMutation) ResetAdvanceAfter() { + m.advance_after = nil + delete(m.clearedFields, chargeusagebased.FieldAdvanceAfter) +} + +// SetTaxCodeID sets the "tax_code_id" field. +func (m *ChargeUsageBasedMutation) SetTaxCodeID(s string) { + m.tax_code = &s +} + +// TaxCodeID returns the value of the "tax_code_id" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 +} + +// ResetTaxCodeID resets all changes to the "tax_code_id" field. +func (m *ChargeUsageBasedMutation) ResetTaxCodeID() { + m.tax_code = nil +} + +// SetTaxBehavior sets the "tax_behavior" field. +func (m *ChargeUsageBasedMutation) SetTaxBehavior(pb productcatalog.TaxBehavior) { + m.tax_behavior = &pb +} + +// TaxBehavior returns the value of the "tax_behavior" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ClearTaxBehavior() { + m.tax_behavior = nil + m.clearedFields[chargeusagebased.FieldTaxBehavior] = struct{}{} +} + +// TaxBehaviorCleared returns if the "tax_behavior" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) TaxBehaviorCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldTaxBehavior] + return ok +} + +// ResetTaxBehavior resets all changes to the "tax_behavior" field. +func (m *ChargeUsageBasedMutation) ResetTaxBehavior() { + m.tax_behavior = nil + delete(m.clearedFields, chargeusagebased.FieldTaxBehavior) +} + +// SetAnnotations sets the "annotations" field. +func (m *ChargeUsageBasedMutation) SetAnnotations(value models.Annotations) { + m.annotations = &value +} + +// Annotations returns the value of the "annotations" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ClearAnnotations() { + m.annotations = nil + m.clearedFields[chargeusagebased.FieldAnnotations] = struct{}{} +} + +// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) AnnotationsCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldAnnotations] + return ok +} + +// ResetAnnotations resets all changes to the "annotations" field. +func (m *ChargeUsageBasedMutation) ResetAnnotations() { + m.annotations = nil + delete(m.clearedFields, chargeusagebased.FieldAnnotations) +} + +// SetNamespace sets the "namespace" field. +func (m *ChargeUsageBasedMutation) SetNamespace(s string) { + m.namespace = &s +} + +// Namespace returns the value of the "namespace" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ResetNamespace() { + m.namespace = nil +} + +// SetMetadata sets the "metadata" field. +func (m *ChargeUsageBasedMutation) SetMetadata(value map[string]string) { + m.metadata = &value +} + +// Metadata returns the value of the "metadata" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ClearMetadata() { + m.metadata = nil + m.clearedFields[chargeusagebased.FieldMetadata] = struct{}{} +} + +// MetadataCleared returns if the "metadata" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) MetadataCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldMetadata] + return ok +} + +// ResetMetadata resets all changes to the "metadata" field. +func (m *ChargeUsageBasedMutation) ResetMetadata() { + m.metadata = nil + delete(m.clearedFields, chargeusagebased.FieldMetadata) +} + +// SetCreatedAt sets the "created_at" field. +func (m *ChargeUsageBasedMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *ChargeUsageBasedMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// SetDeletedAt sets the "deleted_at" field. +func (m *ChargeUsageBasedMutation) SetDeletedAt(t time.Time) { + m.deleted_at = &t +} + +// DeletedAt returns the value of the "deleted_at" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ClearDeletedAt() { + m.deleted_at = nil + m.clearedFields[chargeusagebased.FieldDeletedAt] = struct{}{} +} + +// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldDeletedAt] + return ok +} + +// ResetDeletedAt resets all changes to the "deleted_at" field. +func (m *ChargeUsageBasedMutation) ResetDeletedAt() { + m.deleted_at = nil + delete(m.clearedFields, chargeusagebased.FieldDeletedAt) +} + +// SetName sets the "name" field. +func (m *ChargeUsageBasedMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ResetName() { + m.name = nil +} + +// SetDescription sets the "description" field. +func (m *ChargeUsageBasedMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ClearDescription() { + m.description = nil + m.clearedFields[chargeusagebased.FieldDescription] = struct{}{} +} + +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldDescription] + return ok +} + +// ResetDescription resets all changes to the "description" field. +func (m *ChargeUsageBasedMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, chargeusagebased.FieldDescription) +} + +// SetInvoiceAt sets the "invoice_at" field. +func (m *ChargeUsageBasedMutation) SetInvoiceAt(t time.Time) { + m.invoice_at = &t +} + +// InvoiceAt returns the value of the "invoice_at" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ResetInvoiceAt() { + m.invoice_at = nil +} + +// SetSettlementMode sets the "settlement_mode" field. +func (m *ChargeUsageBasedMutation) SetSettlementMode(pm productcatalog.SettlementMode) { + m.settlement_mode = &pm +} + +// SettlementMode returns the value of the "settlement_mode" field in the mutation. +func (m *ChargeUsageBasedMutation) SettlementMode() (r productcatalog.SettlementMode, exists bool) { + v := m.settlement_mode + if v == nil { + return + } + return *v, true +} + +// OldSettlementMode returns the old "settlement_mode" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldSettlementMode(ctx context.Context) (v productcatalog.SettlementMode, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSettlementMode is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSettlementMode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSettlementMode: %w", err) + } + return oldValue.SettlementMode, nil +} + +// ResetSettlementMode resets all changes to the "settlement_mode" field. +func (m *ChargeUsageBasedMutation) ResetSettlementMode() { + m.settlement_mode = nil +} + +// SetIntentDeletedAt sets the "intent_deleted_at" field. +func (m *ChargeUsageBasedMutation) SetIntentDeletedAt(t time.Time) { + m.intent_deleted_at = &t +} + +// IntentDeletedAt returns the value of the "intent_deleted_at" field in the mutation. +func (m *ChargeUsageBasedMutation) IntentDeletedAt() (r time.Time, exists bool) { + v := m.intent_deleted_at + if v == nil { + return + } + return *v, true +} + +// OldIntentDeletedAt returns the old "intent_deleted_at" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldIntentDeletedAt(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIntentDeletedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIntentDeletedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIntentDeletedAt: %w", err) + } + return oldValue.IntentDeletedAt, nil +} + +// ClearIntentDeletedAt clears the value of the "intent_deleted_at" field. +func (m *ChargeUsageBasedMutation) ClearIntentDeletedAt() { + m.intent_deleted_at = nil + m.clearedFields[chargeusagebased.FieldIntentDeletedAt] = struct{}{} +} + +// IntentDeletedAtCleared returns if the "intent_deleted_at" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) IntentDeletedAtCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldIntentDeletedAt] + return ok +} + +// ResetIntentDeletedAt resets all changes to the "intent_deleted_at" field. +func (m *ChargeUsageBasedMutation) ResetIntentDeletedAt() { + m.intent_deleted_at = nil + delete(m.clearedFields, chargeusagebased.FieldIntentDeletedAt) +} + +// SetDiscounts sets the "discounts" field. +func (m *ChargeUsageBasedMutation) SetDiscounts(b *billing.Discounts) { + m.discounts = &b +} + +// Discounts returns the value of the "discounts" field in the mutation. +func (m *ChargeUsageBasedMutation) Discounts() (r *billing.Discounts, exists bool) { + v := m.discounts + if v == nil { + return + } + return *v, true +} + +// OldDiscounts returns the old "discounts" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldDiscounts(ctx context.Context) (v *billing.Discounts, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDiscounts is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDiscounts requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDiscounts: %w", err) + } + return oldValue.Discounts, nil +} + +// ClearDiscounts clears the value of the "discounts" field. +func (m *ChargeUsageBasedMutation) ClearDiscounts() { + m.discounts = nil + m.clearedFields[chargeusagebased.FieldDiscounts] = struct{}{} +} + +// DiscountsCleared returns if the "discounts" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) DiscountsCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldDiscounts] + return ok +} + +// ResetDiscounts resets all changes to the "discounts" field. +func (m *ChargeUsageBasedMutation) ResetDiscounts() { + m.discounts = nil + delete(m.clearedFields, chargeusagebased.FieldDiscounts) +} + +// SetFeatureKey sets the "feature_key" field. +func (m *ChargeUsageBasedMutation) SetFeatureKey(s string) { + m.feature_key = &s +} + +// FeatureKey returns the value of the "feature_key" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 +} + +// ResetFeatureKey resets all changes to the "feature_key" field. +func (m *ChargeUsageBasedMutation) ResetFeatureKey() { + m.feature_key = nil +} + +// SetFeatureID sets the "feature_id" field. +func (m *ChargeUsageBasedMutation) SetFeatureID(s string) { + m.feature = &s +} + +// FeatureID returns the value of the "feature_id" field in the mutation. +func (m *ChargeUsageBasedMutation) FeatureID() (r string, exists bool) { + v := m.feature + if v == nil { + return + } + return *v, true +} + +// OldFeatureID returns the old "feature_id" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldFeatureID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFeatureID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFeatureID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFeatureID: %w", err) + } + return oldValue.FeatureID, nil +} + +// ResetFeatureID resets all changes to the "feature_id" field. +func (m *ChargeUsageBasedMutation) ResetFeatureID() { + m.feature = nil +} + +// SetRatingEngine sets the "rating_engine" field. +func (m *ChargeUsageBasedMutation) SetRatingEngine(ue usagebased.RatingEngine) { + m.rating_engine = &ue +} + +// RatingEngine returns the value of the "rating_engine" field in the mutation. +func (m *ChargeUsageBasedMutation) RatingEngine() (r usagebased.RatingEngine, exists bool) { + v := m.rating_engine + if v == nil { + return + } + return *v, true +} + +// OldRatingEngine returns the old "rating_engine" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldRatingEngine(ctx context.Context) (v usagebased.RatingEngine, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRatingEngine is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRatingEngine requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRatingEngine: %w", err) + } + return oldValue.RatingEngine, nil +} + +// ResetRatingEngine resets all changes to the "rating_engine" field. +func (m *ChargeUsageBasedMutation) ResetRatingEngine() { + m.rating_engine = nil +} + +// SetPrice sets the "price" field. +func (m *ChargeUsageBasedMutation) SetPrice(pr *productcatalog.Price) { + m.price = &pr +} + +// Price returns the value of the "price" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ResetPrice() { + m.price = nil +} + +// SetUnitConfig sets the "unit_config" field. +func (m *ChargeUsageBasedMutation) SetUnitConfig(pc *productcatalog.UnitConfig) { + m.unit_config = &pc +} + +// UnitConfig returns the value of the "unit_config" field in the mutation. +func (m *ChargeUsageBasedMutation) 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 ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ClearUnitConfig() { + m.unit_config = nil + m.clearedFields[chargeusagebased.FieldUnitConfig] = struct{}{} +} + +// UnitConfigCleared returns if the "unit_config" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) UnitConfigCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldUnitConfig] + return ok +} + +// ResetUnitConfig resets all changes to the "unit_config" field. +func (m *ChargeUsageBasedMutation) ResetUnitConfig() { + m.unit_config = nil + delete(m.clearedFields, chargeusagebased.FieldUnitConfig) +} + +// SetCurrentRealizationRunID sets the "current_realization_run_id" field. +func (m *ChargeUsageBasedMutation) SetCurrentRealizationRunID(s string) { + m.current_run = &s +} + +// CurrentRealizationRunID returns the value of the "current_realization_run_id" field in the mutation. +func (m *ChargeUsageBasedMutation) CurrentRealizationRunID() (r string, exists bool) { + v := m.current_run + if v == nil { + return + } + return *v, true +} + +// OldCurrentRealizationRunID returns the old "current_realization_run_id" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldCurrentRealizationRunID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCurrentRealizationRunID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCurrentRealizationRunID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCurrentRealizationRunID: %w", err) + } + return oldValue.CurrentRealizationRunID, nil +} + +// ClearCurrentRealizationRunID clears the value of the "current_realization_run_id" field. +func (m *ChargeUsageBasedMutation) ClearCurrentRealizationRunID() { + m.current_run = nil + m.clearedFields[chargeusagebased.FieldCurrentRealizationRunID] = struct{}{} +} + +// CurrentRealizationRunIDCleared returns if the "current_realization_run_id" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) CurrentRealizationRunIDCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldCurrentRealizationRunID] + return ok +} + +// ResetCurrentRealizationRunID resets all changes to the "current_realization_run_id" field. +func (m *ChargeUsageBasedMutation) ResetCurrentRealizationRunID() { + m.current_run = nil + delete(m.clearedFields, chargeusagebased.FieldCurrentRealizationRunID) +} + +// SetCostBasisID sets the "cost_basis_id" field. +func (m *ChargeUsageBasedMutation) SetCostBasisID(s string) { + m.cost_basis = &s +} + +// CostBasisID returns the value of the "cost_basis_id" field in the mutation. +func (m *ChargeUsageBasedMutation) CostBasisID() (r string, exists bool) { + v := m.cost_basis + if v == nil { + return + } + return *v, true +} + +// OldCostBasisID returns the old "cost_basis_id" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldCostBasisID(ctx context.Context) (v *string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCostBasisID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCostBasisID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCostBasisID: %w", err) + } + return oldValue.CostBasisID, nil +} + +// ClearCostBasisID clears the value of the "cost_basis_id" field. +func (m *ChargeUsageBasedMutation) ClearCostBasisID() { + m.cost_basis = nil + m.clearedFields[chargeusagebased.FieldCostBasisID] = struct{}{} +} + +// CostBasisIDCleared returns if the "cost_basis_id" field was cleared in this mutation. +func (m *ChargeUsageBasedMutation) CostBasisIDCleared() bool { + _, ok := m.clearedFields[chargeusagebased.FieldCostBasisID] + return ok +} + +// ResetCostBasisID resets all changes to the "cost_basis_id" field. +func (m *ChargeUsageBasedMutation) ResetCostBasisID() { + m.cost_basis = nil + delete(m.clearedFields, chargeusagebased.FieldCostBasisID) +} + +// SetStatusDetailed sets the "status_detailed" field. +func (m *ChargeUsageBasedMutation) SetStatusDetailed(u usagebased.Status) { + m.status_detailed = &u +} + +// StatusDetailed returns the value of the "status_detailed" field in the mutation. +func (m *ChargeUsageBasedMutation) StatusDetailed() (r usagebased.Status, exists bool) { + v := m.status_detailed + if v == nil { + return + } + return *v, true +} + +// OldStatusDetailed returns the old "status_detailed" field's value of the ChargeUsageBased entity. +// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldStatusDetailed(ctx context.Context) (v usagebased.Status, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatusDetailed is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatusDetailed requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatusDetailed: %w", err) + } + return oldValue.StatusDetailed, nil +} + +// ResetStatusDetailed resets all changes to the "status_detailed" field. +func (m *ChargeUsageBasedMutation) ResetStatusDetailed() { + m.status_detailed = nil +} + +// AddRunIDs adds the "runs" edge to the ChargeUsageBasedRuns entity by ids. +func (m *ChargeUsageBasedMutation) AddRunIDs(ids ...string) { + if m.runs == nil { + m.runs = make(map[string]struct{}) + } + for i := range ids { + m.runs[ids[i]] = struct{}{} + } +} + +// ClearRuns clears the "runs" edge to the ChargeUsageBasedRuns entity. +func (m *ChargeUsageBasedMutation) ClearRuns() { + m.clearedruns = true +} + +// RunsCleared reports if the "runs" edge to the ChargeUsageBasedRuns entity was cleared. +func (m *ChargeUsageBasedMutation) RunsCleared() bool { + return m.clearedruns +} + +// RemoveRunIDs removes the "runs" edge to the ChargeUsageBasedRuns entity by IDs. +func (m *ChargeUsageBasedMutation) RemoveRunIDs(ids ...string) { + if m.removedruns == nil { + m.removedruns = make(map[string]struct{}) + } + for i := range ids { + delete(m.runs, ids[i]) + m.removedruns[ids[i]] = struct{}{} + } +} + +// RemovedRuns returns the removed IDs of the "runs" edge to the ChargeUsageBasedRuns entity. +func (m *ChargeUsageBasedMutation) RemovedRunsIDs() (ids []string) { + for id := range m.removedruns { + ids = append(ids, id) + } + return +} + +// RunsIDs returns the "runs" edge IDs in the mutation. +func (m *ChargeUsageBasedMutation) RunsIDs() (ids []string) { + for id := range m.runs { + ids = append(ids, id) + } + return +} + +// ResetRuns resets all changes to the "runs" edge. +func (m *ChargeUsageBasedMutation) ResetRuns() { + m.runs = nil + m.clearedruns = false + m.removedruns = nil +} + +// AddDetailedLineIDs adds the "detailed_lines" edge to the ChargeUsageBasedRunDetailedLine entity by ids. +func (m *ChargeUsageBasedMutation) AddDetailedLineIDs(ids ...string) { + if m.detailed_lines == nil { + m.detailed_lines = make(map[string]struct{}) + } + for i := range ids { + m.detailed_lines[ids[i]] = struct{}{} + } +} + +// ClearDetailedLines clears the "detailed_lines" edge to the ChargeUsageBasedRunDetailedLine entity. +func (m *ChargeUsageBasedMutation) ClearDetailedLines() { + m.cleareddetailed_lines = true +} + +// DetailedLinesCleared reports if the "detailed_lines" edge to the ChargeUsageBasedRunDetailedLine entity was cleared. +func (m *ChargeUsageBasedMutation) DetailedLinesCleared() bool { + return m.cleareddetailed_lines +} + +// RemoveDetailedLineIDs removes the "detailed_lines" edge to the ChargeUsageBasedRunDetailedLine entity by IDs. +func (m *ChargeUsageBasedMutation) RemoveDetailedLineIDs(ids ...string) { + if m.removeddetailed_lines == nil { + m.removeddetailed_lines = make(map[string]struct{}) + } + for i := range ids { + delete(m.detailed_lines, ids[i]) + m.removeddetailed_lines[ids[i]] = struct{}{} + } +} + +// RemovedDetailedLines returns the removed IDs of the "detailed_lines" edge to the ChargeUsageBasedRunDetailedLine entity. +func (m *ChargeUsageBasedMutation) RemovedDetailedLinesIDs() (ids []string) { + for id := range m.removeddetailed_lines { + ids = append(ids, id) + } + return +} + +// DetailedLinesIDs returns the "detailed_lines" edge IDs in the mutation. +func (m *ChargeUsageBasedMutation) DetailedLinesIDs() (ids []string) { + for id := range m.detailed_lines { + ids = append(ids, id) + } + return +} + +// ResetDetailedLines resets all changes to the "detailed_lines" edge. +func (m *ChargeUsageBasedMutation) ResetDetailedLines() { + m.detailed_lines = nil + m.cleareddetailed_lines = false + m.removeddetailed_lines = nil +} + +// SetCurrentRunID sets the "current_run" edge to the ChargeUsageBasedRuns entity by id. +func (m *ChargeUsageBasedMutation) SetCurrentRunID(id string) { + m.current_run = &id +} + +// ClearCurrentRun clears the "current_run" edge to the ChargeUsageBasedRuns entity. +func (m *ChargeUsageBasedMutation) ClearCurrentRun() { + m.clearedcurrent_run = true + m.clearedFields[chargeusagebased.FieldCurrentRealizationRunID] = struct{}{} +} + +// CurrentRunCleared reports if the "current_run" edge to the ChargeUsageBasedRuns entity was cleared. +func (m *ChargeUsageBasedMutation) CurrentRunCleared() bool { + return m.CurrentRealizationRunIDCleared() || m.clearedcurrent_run +} + +// CurrentRunID returns the "current_run" edge ID in the mutation. +func (m *ChargeUsageBasedMutation) CurrentRunID() (id string, exists bool) { + if m.current_run != nil { + return *m.current_run, true + } + return +} + +// CurrentRunIDs returns the "current_run" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CurrentRunID instead. It exists only for internal usage by the builders. +func (m *ChargeUsageBasedMutation) CurrentRunIDs() (ids []string) { + if id := m.current_run; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetCurrentRun resets all changes to the "current_run" edge. +func (m *ChargeUsageBasedMutation) ResetCurrentRun() { + m.current_run = nil + m.clearedcurrent_run = false +} + +// ClearCostBasis clears the "cost_basis" edge to the ChargeUsageBasedCostBasis entity. +func (m *ChargeUsageBasedMutation) ClearCostBasis() { + m.clearedcost_basis = true + m.clearedFields[chargeusagebased.FieldCostBasisID] = struct{}{} +} + +// CostBasisCleared reports if the "cost_basis" edge to the ChargeUsageBasedCostBasis entity was cleared. +func (m *ChargeUsageBasedMutation) CostBasisCleared() bool { + return m.CostBasisIDCleared() || m.clearedcost_basis +} + +// CostBasisIDs returns the "cost_basis" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CostBasisID instead. It exists only for internal usage by the builders. +func (m *ChargeUsageBasedMutation) CostBasisIDs() (ids []string) { + if id := m.cost_basis; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetCostBasis resets all changes to the "cost_basis" edge. +func (m *ChargeUsageBasedMutation) ResetCostBasis() { + m.cost_basis = nil + m.clearedcost_basis = false +} + +// SetChargeID sets the "charge" edge to the Charge entity by id. +func (m *ChargeUsageBasedMutation) SetChargeID(id string) { + m.charge = &id +} + +// ClearCharge clears the "charge" edge to the Charge entity. +func (m *ChargeUsageBasedMutation) ClearCharge() { + m.clearedcharge = true +} + +// ChargeCleared reports if the "charge" edge to the Charge entity was cleared. +func (m *ChargeUsageBasedMutation) ChargeCleared() bool { + return m.clearedcharge +} + +// ChargeID returns the "charge" edge ID in the mutation. +func (m *ChargeUsageBasedMutation) ChargeID() (id string, exists bool) { + if m.charge != nil { + return *m.charge, true + } + return +} + +// 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 *ChargeUsageBasedMutation) ChargeIDs() (ids []string) { + if id := m.charge; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetCharge resets all changes to the "charge" edge. +func (m *ChargeUsageBasedMutation) ResetCharge() { + m.charge = nil + m.clearedcharge = false +} + +// SetIntentOverrideID sets the "intent_override" edge to the ChargeUsageBasedOverride entity by id. +func (m *ChargeUsageBasedMutation) SetIntentOverrideID(id string) { + m.intent_override = &id +} + +// ClearIntentOverride clears the "intent_override" edge to the ChargeUsageBasedOverride entity. +func (m *ChargeUsageBasedMutation) ClearIntentOverride() { + m.clearedintent_override = true +} + +// IntentOverrideCleared reports if the "intent_override" edge to the ChargeUsageBasedOverride entity was cleared. +func (m *ChargeUsageBasedMutation) IntentOverrideCleared() bool { + return m.clearedintent_override +} + +// IntentOverrideID returns the "intent_override" edge ID in the mutation. +func (m *ChargeUsageBasedMutation) IntentOverrideID() (id string, exists bool) { + if m.intent_override != nil { + return *m.intent_override, true + } + return +} + +// IntentOverrideIDs returns the "intent_override" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// IntentOverrideID instead. It exists only for internal usage by the builders. +func (m *ChargeUsageBasedMutation) IntentOverrideIDs() (ids []string) { + if id := m.intent_override; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetIntentOverride resets all changes to the "intent_override" edge. +func (m *ChargeUsageBasedMutation) ResetIntentOverride() { + m.intent_override = nil + m.clearedintent_override = false +} + +// ClearSubscription clears the "subscription" edge to the Subscription entity. +func (m *ChargeUsageBasedMutation) ClearSubscription() { + m.clearedsubscription = true + m.clearedFields[chargeusagebased.FieldSubscriptionID] = struct{}{} +} + +// SubscriptionCleared reports if the "subscription" edge to the Subscription entity was cleared. +func (m *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) SubscriptionIDs() (ids []string) { + if id := m.subscription; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetSubscription resets all changes to the "subscription" edge. +func (m *ChargeUsageBasedMutation) ResetSubscription() { + m.subscription = nil + m.clearedsubscription = false +} + +// ClearSubscriptionPhase clears the "subscription_phase" edge to the SubscriptionPhase entity. +func (m *ChargeUsageBasedMutation) ClearSubscriptionPhase() { + m.clearedsubscription_phase = true + m.clearedFields[chargeusagebased.FieldSubscriptionPhaseID] = struct{}{} +} + +// SubscriptionPhaseCleared reports if the "subscription_phase" edge to the SubscriptionPhase entity was cleared. +func (m *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ResetSubscriptionPhase() { + m.subscription_phase = nil + m.clearedsubscription_phase = false +} + +// ClearSubscriptionItem clears the "subscription_item" edge to the SubscriptionItem entity. +func (m *ChargeUsageBasedMutation) ClearSubscriptionItem() { + m.clearedsubscription_item = true + m.clearedFields[chargeusagebased.FieldSubscriptionItemID] = struct{}{} +} + +// SubscriptionItemCleared reports if the "subscription_item" edge to the SubscriptionItem entity was cleared. +func (m *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ResetSubscriptionItem() { + m.subscription_item = nil + m.clearedsubscription_item = false +} + +// ClearCustomer clears the "customer" edge to the Customer entity. +func (m *ChargeUsageBasedMutation) ClearCustomer() { + m.clearedcustomer = true + m.clearedFields[chargeusagebased.FieldCustomerID] = struct{}{} +} + +// CustomerCleared reports if the "customer" edge to the Customer entity was cleared. +func (m *ChargeUsageBasedMutation) CustomerCleared() bool { + return m.clearedcustomer +} + +// CustomerIDs returns the "customer" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CustomerID instead. It exists only for internal usage by the builders. +func (m *ChargeUsageBasedMutation) CustomerIDs() (ids []string) { + if id := m.customer; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetCustomer resets all changes to the "customer" edge. +func (m *ChargeUsageBasedMutation) ResetCustomer() { + m.customer = nil + m.clearedcustomer = false +} + +// ClearFeature clears the "feature" edge to the Feature entity. +func (m *ChargeUsageBasedMutation) ClearFeature() { + m.clearedfeature = true + m.clearedFields[chargeusagebased.FieldFeatureID] = struct{}{} +} + +// FeatureCleared reports if the "feature" edge to the Feature entity was cleared. +func (m *ChargeUsageBasedMutation) FeatureCleared() bool { + return m.clearedfeature +} + +// FeatureIDs returns the "feature" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// FeatureID instead. It exists only for internal usage by the builders. +func (m *ChargeUsageBasedMutation) FeatureIDs() (ids []string) { + if id := m.feature; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetFeature resets all changes to the "feature" edge. +func (m *ChargeUsageBasedMutation) ResetFeature() { + m.feature = nil + m.clearedfeature = false +} + +// ClearTaxCode clears the "tax_code" edge to the TaxCode entity. +func (m *ChargeUsageBasedMutation) ClearTaxCode() { + m.clearedtax_code = true + m.clearedFields[chargeusagebased.FieldTaxCodeID] = struct{}{} +} + +// TaxCodeCleared reports if the "tax_code" edge to the TaxCode entity was cleared. +func (m *ChargeUsageBasedMutation) TaxCodeCleared() bool { + return 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 *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) ResetTaxCode() { + m.tax_code = nil + m.clearedtax_code = false +} + +// ClearCustomCurrency clears the "custom_currency" edge to the CustomCurrency entity. +func (m *ChargeUsageBasedMutation) ClearCustomCurrency() { + m.clearedcustom_currency = true + m.clearedFields[chargeusagebased.FieldCustomCurrencyID] = struct{}{} +} + +// CustomCurrencyCleared reports if the "custom_currency" edge to the CustomCurrency entity was cleared. +func (m *ChargeUsageBasedMutation) CustomCurrencyCleared() bool { + return m.CustomCurrencyIDCleared() || m.clearedcustom_currency +} + +// CustomCurrencyIDs returns the "custom_currency" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// CustomCurrencyID instead. It exists only for internal usage by the builders. +func (m *ChargeUsageBasedMutation) CustomCurrencyIDs() (ids []string) { + if id := m.custom_currency; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetCustomCurrency resets all changes to the "custom_currency" edge. +func (m *ChargeUsageBasedMutation) ResetCustomCurrency() { + m.custom_currency = nil + m.clearedcustom_currency = false +} + +// Where appends a list predicates to the ChargeUsageBasedMutation builder. +func (m *ChargeUsageBasedMutation) Where(ps ...predicate.ChargeUsageBased) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the ChargeUsageBasedMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ChargeUsageBasedMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeUsageBased, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *ChargeUsageBasedMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *ChargeUsageBasedMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (ChargeUsageBased). +func (m *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) Fields() []string { + fields := make([]string, 0, 38) + if m.customer != nil { + fields = append(fields, chargeusagebased.FieldCustomerID) + } + if m.service_period_from != nil { + fields = append(fields, chargeusagebased.FieldServicePeriodFrom) + } + if m.service_period_to != nil { + fields = append(fields, chargeusagebased.FieldServicePeriodTo) + } + if m.billing_period_from != nil { + fields = append(fields, chargeusagebased.FieldBillingPeriodFrom) + } + if m.billing_period_to != nil { + fields = append(fields, chargeusagebased.FieldBillingPeriodTo) + } + if m.full_service_period_from != nil { + fields = append(fields, chargeusagebased.FieldFullServicePeriodFrom) + } + if m.full_service_period_to != nil { + fields = append(fields, chargeusagebased.FieldFullServicePeriodTo) + } + if m.status != nil { + fields = append(fields, chargeusagebased.FieldStatus) + } + if m.unique_reference_id != nil { + fields = append(fields, chargeusagebased.FieldUniqueReferenceID) + } + if m.fiat_currency_code != nil { + fields = append(fields, chargeusagebased.FieldFiatCurrencyCode) + } + if m.custom_currency != nil { + fields = append(fields, chargeusagebased.FieldCustomCurrencyID) + } + if m.managed_by != nil { + fields = append(fields, chargeusagebased.FieldManagedBy) + } + if m.subscription != nil { + fields = append(fields, chargeusagebased.FieldSubscriptionID) + } + if m.subscription_phase != nil { + fields = append(fields, chargeusagebased.FieldSubscriptionPhaseID) + } + if m.subscription_item != nil { + fields = append(fields, chargeusagebased.FieldSubscriptionItemID) + } + if m.advance_after != nil { + fields = append(fields, chargeusagebased.FieldAdvanceAfter) + } + if m.tax_code != nil { + fields = append(fields, chargeusagebased.FieldTaxCodeID) + } + if m.tax_behavior != nil { + fields = append(fields, chargeusagebased.FieldTaxBehavior) + } + if m.annotations != nil { + fields = append(fields, chargeusagebased.FieldAnnotations) + } + if m.namespace != nil { + fields = append(fields, chargeusagebased.FieldNamespace) + } + if m.metadata != nil { + fields = append(fields, chargeusagebased.FieldMetadata) + } + if m.created_at != nil { + fields = append(fields, chargeusagebased.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, chargeusagebased.FieldUpdatedAt) + } + if m.deleted_at != nil { + fields = append(fields, chargeusagebased.FieldDeletedAt) + } + if m.name != nil { + fields = append(fields, chargeusagebased.FieldName) + } + if m.description != nil { + fields = append(fields, chargeusagebased.FieldDescription) + } + if m.invoice_at != nil { + fields = append(fields, chargeusagebased.FieldInvoiceAt) + } + if m.settlement_mode != nil { + fields = append(fields, chargeusagebased.FieldSettlementMode) + } + if m.intent_deleted_at != nil { + fields = append(fields, chargeusagebased.FieldIntentDeletedAt) + } + if m.discounts != nil { + fields = append(fields, chargeusagebased.FieldDiscounts) + } + if m.feature_key != nil { + fields = append(fields, chargeusagebased.FieldFeatureKey) + } + if m.feature != nil { + fields = append(fields, chargeusagebased.FieldFeatureID) + } + if m.rating_engine != nil { + fields = append(fields, chargeusagebased.FieldRatingEngine) + } + if m.price != nil { + fields = append(fields, chargeusagebased.FieldPrice) + } + if m.unit_config != nil { + fields = append(fields, chargeusagebased.FieldUnitConfig) + } + if m.current_run != nil { + fields = append(fields, chargeusagebased.FieldCurrentRealizationRunID) + } + if m.cost_basis != nil { + fields = append(fields, chargeusagebased.FieldCostBasisID) + } + if m.status_detailed != nil { + fields = append(fields, chargeusagebased.FieldStatusDetailed) + } + 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 *ChargeUsageBasedMutation) Field(name string) (ent.Value, bool) { + switch name { + case chargeusagebased.FieldCustomerID: + return m.CustomerID() + case chargeusagebased.FieldServicePeriodFrom: + return m.ServicePeriodFrom() + case chargeusagebased.FieldServicePeriodTo: + return m.ServicePeriodTo() + case chargeusagebased.FieldBillingPeriodFrom: + return m.BillingPeriodFrom() + case chargeusagebased.FieldBillingPeriodTo: + return m.BillingPeriodTo() + case chargeusagebased.FieldFullServicePeriodFrom: + return m.FullServicePeriodFrom() + case chargeusagebased.FieldFullServicePeriodTo: + return m.FullServicePeriodTo() + case chargeusagebased.FieldStatus: + return m.Status() + case chargeusagebased.FieldUniqueReferenceID: + return m.UniqueReferenceID() + case chargeusagebased.FieldFiatCurrencyCode: + return m.FiatCurrencyCode() + case chargeusagebased.FieldCustomCurrencyID: + return m.CustomCurrencyID() + case chargeusagebased.FieldManagedBy: + return m.ManagedBy() + case chargeusagebased.FieldSubscriptionID: + return m.SubscriptionID() + case chargeusagebased.FieldSubscriptionPhaseID: + return m.SubscriptionPhaseID() + case chargeusagebased.FieldSubscriptionItemID: + return m.SubscriptionItemID() + case chargeusagebased.FieldAdvanceAfter: + return m.AdvanceAfter() + case chargeusagebased.FieldTaxCodeID: + return m.TaxCodeID() + case chargeusagebased.FieldTaxBehavior: + return m.TaxBehavior() + case chargeusagebased.FieldAnnotations: + return m.Annotations() + case chargeusagebased.FieldNamespace: + return m.Namespace() + case chargeusagebased.FieldMetadata: + return m.Metadata() + case chargeusagebased.FieldCreatedAt: + return m.CreatedAt() + case chargeusagebased.FieldUpdatedAt: + return m.UpdatedAt() + case chargeusagebased.FieldDeletedAt: + return m.DeletedAt() + case chargeusagebased.FieldName: + return m.Name() + case chargeusagebased.FieldDescription: + return m.Description() + case chargeusagebased.FieldInvoiceAt: + return m.InvoiceAt() + case chargeusagebased.FieldSettlementMode: + return m.SettlementMode() + case chargeusagebased.FieldIntentDeletedAt: + return m.IntentDeletedAt() + case chargeusagebased.FieldDiscounts: + return m.Discounts() + case chargeusagebased.FieldFeatureKey: + return m.FeatureKey() + case chargeusagebased.FieldFeatureID: + return m.FeatureID() + case chargeusagebased.FieldRatingEngine: + return m.RatingEngine() + case chargeusagebased.FieldPrice: + return m.Price() + case chargeusagebased.FieldUnitConfig: + return m.UnitConfig() + case chargeusagebased.FieldCurrentRealizationRunID: + return m.CurrentRealizationRunID() + case chargeusagebased.FieldCostBasisID: + return m.CostBasisID() + case chargeusagebased.FieldStatusDetailed: + return m.StatusDetailed() + } + 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 *ChargeUsageBasedMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case chargeusagebased.FieldCustomerID: + return m.OldCustomerID(ctx) + case chargeusagebased.FieldServicePeriodFrom: + return m.OldServicePeriodFrom(ctx) + case chargeusagebased.FieldServicePeriodTo: + return m.OldServicePeriodTo(ctx) + case chargeusagebased.FieldBillingPeriodFrom: + return m.OldBillingPeriodFrom(ctx) + case chargeusagebased.FieldBillingPeriodTo: + return m.OldBillingPeriodTo(ctx) + case chargeusagebased.FieldFullServicePeriodFrom: + return m.OldFullServicePeriodFrom(ctx) + case chargeusagebased.FieldFullServicePeriodTo: + return m.OldFullServicePeriodTo(ctx) + case chargeusagebased.FieldStatus: + return m.OldStatus(ctx) + case chargeusagebased.FieldUniqueReferenceID: + return m.OldUniqueReferenceID(ctx) + case chargeusagebased.FieldFiatCurrencyCode: + return m.OldFiatCurrencyCode(ctx) + case chargeusagebased.FieldCustomCurrencyID: + return m.OldCustomCurrencyID(ctx) + case chargeusagebased.FieldManagedBy: + return m.OldManagedBy(ctx) + case chargeusagebased.FieldSubscriptionID: + return m.OldSubscriptionID(ctx) + case chargeusagebased.FieldSubscriptionPhaseID: + return m.OldSubscriptionPhaseID(ctx) + case chargeusagebased.FieldSubscriptionItemID: + return m.OldSubscriptionItemID(ctx) + case chargeusagebased.FieldAdvanceAfter: + return m.OldAdvanceAfter(ctx) + case chargeusagebased.FieldTaxCodeID: + return m.OldTaxCodeID(ctx) + case chargeusagebased.FieldTaxBehavior: + return m.OldTaxBehavior(ctx) + case chargeusagebased.FieldAnnotations: + return m.OldAnnotations(ctx) + case chargeusagebased.FieldNamespace: + return m.OldNamespace(ctx) + case chargeusagebased.FieldMetadata: + return m.OldMetadata(ctx) + case chargeusagebased.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case chargeusagebased.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case chargeusagebased.FieldDeletedAt: + return m.OldDeletedAt(ctx) + case chargeusagebased.FieldName: + return m.OldName(ctx) + case chargeusagebased.FieldDescription: + return m.OldDescription(ctx) + case chargeusagebased.FieldInvoiceAt: + return m.OldInvoiceAt(ctx) + case chargeusagebased.FieldSettlementMode: + return m.OldSettlementMode(ctx) + case chargeusagebased.FieldIntentDeletedAt: + return m.OldIntentDeletedAt(ctx) + case chargeusagebased.FieldDiscounts: + return m.OldDiscounts(ctx) + case chargeusagebased.FieldFeatureKey: + return m.OldFeatureKey(ctx) + case chargeusagebased.FieldFeatureID: + return m.OldFeatureID(ctx) + case chargeusagebased.FieldRatingEngine: + return m.OldRatingEngine(ctx) + case chargeusagebased.FieldPrice: + return m.OldPrice(ctx) + case chargeusagebased.FieldUnitConfig: + return m.OldUnitConfig(ctx) + case chargeusagebased.FieldCurrentRealizationRunID: + return m.OldCurrentRealizationRunID(ctx) + case chargeusagebased.FieldCostBasisID: + return m.OldCostBasisID(ctx) + case chargeusagebased.FieldStatusDetailed: + return m.OldStatusDetailed(ctx) + } + return nil, fmt.Errorf("unknown ChargeUsageBased 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 *ChargeUsageBasedMutation) SetField(name string, value ent.Value) error { + switch name { + case chargeusagebased.FieldCustomerID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCustomerID(v) + return nil + case chargeusagebased.FieldServicePeriodFrom: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServicePeriodFrom(v) + return nil + case chargeusagebased.FieldServicePeriodTo: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServicePeriodTo(v) + return nil + case chargeusagebased.FieldBillingPeriodFrom: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBillingPeriodFrom(v) + return nil + case chargeusagebased.FieldBillingPeriodTo: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBillingPeriodTo(v) + return nil + case chargeusagebased.FieldFullServicePeriodFrom: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFullServicePeriodFrom(v) + return nil + case chargeusagebased.FieldFullServicePeriodTo: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFullServicePeriodTo(v) + return nil + case chargeusagebased.FieldStatus: + v, ok := value.(meta.ChargeStatus) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + case chargeusagebased.FieldUniqueReferenceID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUniqueReferenceID(v) + return nil + case chargeusagebased.FieldFiatCurrencyCode: + v, ok := value.(currencyx.Code) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFiatCurrencyCode(v) + return nil + case chargeusagebased.FieldCustomCurrencyID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCustomCurrencyID(v) + return nil + case chargeusagebased.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 chargeusagebased.FieldSubscriptionID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubscriptionID(v) + return nil + case chargeusagebased.FieldSubscriptionPhaseID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubscriptionPhaseID(v) + return nil + case chargeusagebased.FieldSubscriptionItemID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubscriptionItemID(v) + return nil + case chargeusagebased.FieldAdvanceAfter: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAdvanceAfter(v) + return nil + case chargeusagebased.FieldTaxCodeID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTaxCodeID(v) + return nil + case chargeusagebased.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 chargeusagebased.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 chargeusagebased.FieldNamespace: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNamespace(v) + return nil + case chargeusagebased.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 chargeusagebased.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 chargeusagebased.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 chargeusagebased.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 chargeusagebased.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case chargeusagebased.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + case chargeusagebased.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 chargeusagebased.FieldSettlementMode: + v, ok := value.(productcatalog.SettlementMode) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSettlementMode(v) + return nil + case chargeusagebased.FieldIntentDeletedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIntentDeletedAt(v) + return nil + case chargeusagebased.FieldDiscounts: + v, ok := value.(*billing.Discounts) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDiscounts(v) + return nil + case chargeusagebased.FieldFeatureKey: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFeatureKey(v) + return nil + case chargeusagebased.FieldFeatureID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFeatureID(v) + return nil + case chargeusagebased.FieldRatingEngine: + v, ok := value.(usagebased.RatingEngine) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRatingEngine(v) + return nil + case chargeusagebased.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 chargeusagebased.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 chargeusagebased.FieldCurrentRealizationRunID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCurrentRealizationRunID(v) + return nil + case chargeusagebased.FieldCostBasisID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCostBasisID(v) + return nil + case chargeusagebased.FieldStatusDetailed: + v, ok := value.(usagebased.Status) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatusDetailed(v) + return nil } - return oldValue.SubscriptionPhaseID, nil -} - -// ClearSubscriptionPhaseID clears the value of the "subscription_phase_id" field. -func (m *ChargeUsageBasedMutation) ClearSubscriptionPhaseID() { - m.subscription_phase = nil - m.clearedFields[chargeusagebased.FieldSubscriptionPhaseID] = struct{}{} -} - -// SubscriptionPhaseIDCleared returns if the "subscription_phase_id" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) SubscriptionPhaseIDCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldSubscriptionPhaseID] - return ok + return fmt.Errorf("unknown ChargeUsageBased field %s", name) } -// ResetSubscriptionPhaseID resets all changes to the "subscription_phase_id" field. -func (m *ChargeUsageBasedMutation) ResetSubscriptionPhaseID() { - m.subscription_phase = nil - delete(m.clearedFields, chargeusagebased.FieldSubscriptionPhaseID) +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ChargeUsageBasedMutation) AddedFields() []string { + return nil } -// SetSubscriptionItemID sets the "subscription_item_id" field. -func (m *ChargeUsageBasedMutation) SetSubscriptionItemID(s string) { - m.subscription_item = &s +// 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 *ChargeUsageBasedMutation) AddedField(name string) (ent.Value, bool) { + return nil, false } -// SubscriptionItemID returns the value of the "subscription_item_id" field in the mutation. -func (m *ChargeUsageBasedMutation) SubscriptionItemID() (r string, exists bool) { - v := m.subscription_item - if v == nil { - return +// 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 *ChargeUsageBasedMutation) AddField(name string, value ent.Value) error { + switch name { } - return *v, true + return fmt.Errorf("unknown ChargeUsageBased numeric field %s", name) } -// OldSubscriptionItemID returns the old "subscription_item_id" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldSubscriptionItemID(ctx context.Context) (v *string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSubscriptionItemID is only allowed on UpdateOne operations") +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ChargeUsageBasedMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(chargeusagebased.FieldUniqueReferenceID) { + fields = append(fields, chargeusagebased.FieldUniqueReferenceID) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSubscriptionItemID requires an ID field in the mutation") + if m.FieldCleared(chargeusagebased.FieldFiatCurrencyCode) { + fields = append(fields, chargeusagebased.FieldFiatCurrencyCode) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldSubscriptionItemID: %w", err) + if m.FieldCleared(chargeusagebased.FieldCustomCurrencyID) { + fields = append(fields, chargeusagebased.FieldCustomCurrencyID) } - return oldValue.SubscriptionItemID, nil -} - -// ClearSubscriptionItemID clears the value of the "subscription_item_id" field. -func (m *ChargeUsageBasedMutation) ClearSubscriptionItemID() { - m.subscription_item = nil - m.clearedFields[chargeusagebased.FieldSubscriptionItemID] = struct{}{} -} - -// SubscriptionItemIDCleared returns if the "subscription_item_id" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) SubscriptionItemIDCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldSubscriptionItemID] - return ok -} - -// ResetSubscriptionItemID resets all changes to the "subscription_item_id" field. -func (m *ChargeUsageBasedMutation) ResetSubscriptionItemID() { - m.subscription_item = nil - delete(m.clearedFields, chargeusagebased.FieldSubscriptionItemID) -} - -// SetAdvanceAfter sets the "advance_after" field. -func (m *ChargeUsageBasedMutation) SetAdvanceAfter(t time.Time) { - m.advance_after = &t -} - -// AdvanceAfter returns the value of the "advance_after" field in the mutation. -func (m *ChargeUsageBasedMutation) AdvanceAfter() (r time.Time, exists bool) { - v := m.advance_after - if v == nil { - return + if m.FieldCleared(chargeusagebased.FieldSubscriptionID) { + fields = append(fields, chargeusagebased.FieldSubscriptionID) } - return *v, true -} - -// OldAdvanceAfter returns the old "advance_after" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldAdvanceAfter(ctx context.Context) (v *time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAdvanceAfter is only allowed on UpdateOne operations") + if m.FieldCleared(chargeusagebased.FieldSubscriptionPhaseID) { + fields = append(fields, chargeusagebased.FieldSubscriptionPhaseID) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAdvanceAfter requires an ID field in the mutation") + if m.FieldCleared(chargeusagebased.FieldSubscriptionItemID) { + fields = append(fields, chargeusagebased.FieldSubscriptionItemID) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldAdvanceAfter: %w", err) + if m.FieldCleared(chargeusagebased.FieldAdvanceAfter) { + fields = append(fields, chargeusagebased.FieldAdvanceAfter) } - return oldValue.AdvanceAfter, nil -} - -// ClearAdvanceAfter clears the value of the "advance_after" field. -func (m *ChargeUsageBasedMutation) ClearAdvanceAfter() { - m.advance_after = nil - m.clearedFields[chargeusagebased.FieldAdvanceAfter] = struct{}{} -} - -// AdvanceAfterCleared returns if the "advance_after" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) AdvanceAfterCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldAdvanceAfter] - return ok -} - -// ResetAdvanceAfter resets all changes to the "advance_after" field. -func (m *ChargeUsageBasedMutation) ResetAdvanceAfter() { - m.advance_after = nil - delete(m.clearedFields, chargeusagebased.FieldAdvanceAfter) -} - -// SetTaxCodeID sets the "tax_code_id" field. -func (m *ChargeUsageBasedMutation) SetTaxCodeID(s string) { - m.tax_code = &s -} - -// TaxCodeID returns the value of the "tax_code_id" field in the mutation. -func (m *ChargeUsageBasedMutation) TaxCodeID() (r string, exists bool) { - v := m.tax_code - if v == nil { - return + if m.FieldCleared(chargeusagebased.FieldTaxBehavior) { + fields = append(fields, chargeusagebased.FieldTaxBehavior) } - return *v, true -} - -// OldTaxCodeID returns the old "tax_code_id" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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.FieldCleared(chargeusagebased.FieldAnnotations) { + fields = append(fields, chargeusagebased.FieldAnnotations) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTaxCodeID requires an ID field in the mutation") + if m.FieldCleared(chargeusagebased.FieldMetadata) { + fields = append(fields, chargeusagebased.FieldMetadata) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTaxCodeID: %w", err) + if m.FieldCleared(chargeusagebased.FieldDeletedAt) { + fields = append(fields, chargeusagebased.FieldDeletedAt) } - return oldValue.TaxCodeID, nil -} - -// ResetTaxCodeID resets all changes to the "tax_code_id" field. -func (m *ChargeUsageBasedMutation) ResetTaxCodeID() { - m.tax_code = nil -} - -// SetTaxBehavior sets the "tax_behavior" field. -func (m *ChargeUsageBasedMutation) SetTaxBehavior(pb productcatalog.TaxBehavior) { - m.tax_behavior = &pb -} - -// TaxBehavior returns the value of the "tax_behavior" field in the mutation. -func (m *ChargeUsageBasedMutation) TaxBehavior() (r productcatalog.TaxBehavior, exists bool) { - v := m.tax_behavior - if v == nil { - return + if m.FieldCleared(chargeusagebased.FieldDescription) { + fields = append(fields, chargeusagebased.FieldDescription) } - return *v, true -} - -// OldTaxBehavior returns the old "tax_behavior" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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.FieldCleared(chargeusagebased.FieldIntentDeletedAt) { + fields = append(fields, chargeusagebased.FieldIntentDeletedAt) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTaxBehavior requires an ID field in the mutation") + if m.FieldCleared(chargeusagebased.FieldDiscounts) { + fields = append(fields, chargeusagebased.FieldDiscounts) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTaxBehavior: %w", err) + if m.FieldCleared(chargeusagebased.FieldUnitConfig) { + fields = append(fields, chargeusagebased.FieldUnitConfig) } - return oldValue.TaxBehavior, nil -} - -// ClearTaxBehavior clears the value of the "tax_behavior" field. -func (m *ChargeUsageBasedMutation) ClearTaxBehavior() { - m.tax_behavior = nil - m.clearedFields[chargeusagebased.FieldTaxBehavior] = struct{}{} + if m.FieldCleared(chargeusagebased.FieldCurrentRealizationRunID) { + fields = append(fields, chargeusagebased.FieldCurrentRealizationRunID) + } + if m.FieldCleared(chargeusagebased.FieldCostBasisID) { + fields = append(fields, chargeusagebased.FieldCostBasisID) + } + return fields } -// TaxBehaviorCleared returns if the "tax_behavior" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) TaxBehaviorCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldTaxBehavior] +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ChargeUsageBasedMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] return ok } -// ResetTaxBehavior resets all changes to the "tax_behavior" field. -func (m *ChargeUsageBasedMutation) ResetTaxBehavior() { - m.tax_behavior = nil - delete(m.clearedFields, chargeusagebased.FieldTaxBehavior) -} - -// SetAnnotations sets the "annotations" field. -func (m *ChargeUsageBasedMutation) SetAnnotations(value models.Annotations) { - m.annotations = &value +// 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 *ChargeUsageBasedMutation) ClearField(name string) error { + switch name { + case chargeusagebased.FieldUniqueReferenceID: + m.ClearUniqueReferenceID() + return nil + case chargeusagebased.FieldFiatCurrencyCode: + m.ClearFiatCurrencyCode() + return nil + case chargeusagebased.FieldCustomCurrencyID: + m.ClearCustomCurrencyID() + return nil + case chargeusagebased.FieldSubscriptionID: + m.ClearSubscriptionID() + return nil + case chargeusagebased.FieldSubscriptionPhaseID: + m.ClearSubscriptionPhaseID() + return nil + case chargeusagebased.FieldSubscriptionItemID: + m.ClearSubscriptionItemID() + return nil + case chargeusagebased.FieldAdvanceAfter: + m.ClearAdvanceAfter() + return nil + case chargeusagebased.FieldTaxBehavior: + m.ClearTaxBehavior() + return nil + case chargeusagebased.FieldAnnotations: + m.ClearAnnotations() + return nil + case chargeusagebased.FieldMetadata: + m.ClearMetadata() + return nil + case chargeusagebased.FieldDeletedAt: + m.ClearDeletedAt() + return nil + case chargeusagebased.FieldDescription: + m.ClearDescription() + return nil + case chargeusagebased.FieldIntentDeletedAt: + m.ClearIntentDeletedAt() + return nil + case chargeusagebased.FieldDiscounts: + m.ClearDiscounts() + return nil + case chargeusagebased.FieldUnitConfig: + m.ClearUnitConfig() + return nil + case chargeusagebased.FieldCurrentRealizationRunID: + m.ClearCurrentRealizationRunID() + return nil + case chargeusagebased.FieldCostBasisID: + m.ClearCostBasisID() + return nil + } + return fmt.Errorf("unknown ChargeUsageBased nullable field %s", name) } -// Annotations returns the value of the "annotations" field in the mutation. -func (m *ChargeUsageBasedMutation) Annotations() (r models.Annotations, exists bool) { - v := m.annotations - if v == nil { - return +// 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 *ChargeUsageBasedMutation) ResetField(name string) error { + switch name { + case chargeusagebased.FieldCustomerID: + m.ResetCustomerID() + return nil + case chargeusagebased.FieldServicePeriodFrom: + m.ResetServicePeriodFrom() + return nil + case chargeusagebased.FieldServicePeriodTo: + m.ResetServicePeriodTo() + return nil + case chargeusagebased.FieldBillingPeriodFrom: + m.ResetBillingPeriodFrom() + return nil + case chargeusagebased.FieldBillingPeriodTo: + m.ResetBillingPeriodTo() + return nil + case chargeusagebased.FieldFullServicePeriodFrom: + m.ResetFullServicePeriodFrom() + return nil + case chargeusagebased.FieldFullServicePeriodTo: + m.ResetFullServicePeriodTo() + return nil + case chargeusagebased.FieldStatus: + m.ResetStatus() + return nil + case chargeusagebased.FieldUniqueReferenceID: + m.ResetUniqueReferenceID() + return nil + case chargeusagebased.FieldFiatCurrencyCode: + m.ResetFiatCurrencyCode() + return nil + case chargeusagebased.FieldCustomCurrencyID: + m.ResetCustomCurrencyID() + return nil + case chargeusagebased.FieldManagedBy: + m.ResetManagedBy() + return nil + case chargeusagebased.FieldSubscriptionID: + m.ResetSubscriptionID() + return nil + case chargeusagebased.FieldSubscriptionPhaseID: + m.ResetSubscriptionPhaseID() + return nil + case chargeusagebased.FieldSubscriptionItemID: + m.ResetSubscriptionItemID() + return nil + case chargeusagebased.FieldAdvanceAfter: + m.ResetAdvanceAfter() + return nil + case chargeusagebased.FieldTaxCodeID: + m.ResetTaxCodeID() + return nil + case chargeusagebased.FieldTaxBehavior: + m.ResetTaxBehavior() + return nil + case chargeusagebased.FieldAnnotations: + m.ResetAnnotations() + return nil + case chargeusagebased.FieldNamespace: + m.ResetNamespace() + return nil + case chargeusagebased.FieldMetadata: + m.ResetMetadata() + return nil + case chargeusagebased.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case chargeusagebased.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case chargeusagebased.FieldDeletedAt: + m.ResetDeletedAt() + return nil + case chargeusagebased.FieldName: + m.ResetName() + return nil + case chargeusagebased.FieldDescription: + m.ResetDescription() + return nil + case chargeusagebased.FieldInvoiceAt: + m.ResetInvoiceAt() + return nil + case chargeusagebased.FieldSettlementMode: + m.ResetSettlementMode() + return nil + case chargeusagebased.FieldIntentDeletedAt: + m.ResetIntentDeletedAt() + return nil + case chargeusagebased.FieldDiscounts: + m.ResetDiscounts() + return nil + case chargeusagebased.FieldFeatureKey: + m.ResetFeatureKey() + return nil + case chargeusagebased.FieldFeatureID: + m.ResetFeatureID() + return nil + case chargeusagebased.FieldRatingEngine: + m.ResetRatingEngine() + return nil + case chargeusagebased.FieldPrice: + m.ResetPrice() + return nil + case chargeusagebased.FieldUnitConfig: + m.ResetUnitConfig() + return nil + case chargeusagebased.FieldCurrentRealizationRunID: + m.ResetCurrentRealizationRunID() + return nil + case chargeusagebased.FieldCostBasisID: + m.ResetCostBasisID() + return nil + case chargeusagebased.FieldStatusDetailed: + m.ResetStatusDetailed() + return nil } - return *v, true + return fmt.Errorf("unknown ChargeUsageBased field %s", name) } -// OldAnnotations returns the old "annotations" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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") +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ChargeUsageBasedMutation) AddedEdges() []string { + edges := make([]string, 0, 13) + if m.runs != nil { + edges = append(edges, chargeusagebased.EdgeRuns) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAnnotations requires an ID field in the mutation") + if m.detailed_lines != nil { + edges = append(edges, chargeusagebased.EdgeDetailedLines) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldAnnotations: %w", err) + if m.current_run != nil { + edges = append(edges, chargeusagebased.EdgeCurrentRun) } - return oldValue.Annotations, nil -} - -// ClearAnnotations clears the value of the "annotations" field. -func (m *ChargeUsageBasedMutation) ClearAnnotations() { - m.annotations = nil - m.clearedFields[chargeusagebased.FieldAnnotations] = struct{}{} -} - -// AnnotationsCleared returns if the "annotations" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) AnnotationsCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldAnnotations] - return ok -} - -// ResetAnnotations resets all changes to the "annotations" field. -func (m *ChargeUsageBasedMutation) ResetAnnotations() { - m.annotations = nil - delete(m.clearedFields, chargeusagebased.FieldAnnotations) -} - -// SetNamespace sets the "namespace" field. -func (m *ChargeUsageBasedMutation) SetNamespace(s string) { - m.namespace = &s -} - -// Namespace returns the value of the "namespace" field in the mutation. -func (m *ChargeUsageBasedMutation) Namespace() (r string, exists bool) { - v := m.namespace - if v == nil { - return + if m.cost_basis != nil { + edges = append(edges, chargeusagebased.EdgeCostBasis) } - return *v, true -} - -// OldNamespace returns the old "namespace" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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.charge != nil { + edges = append(edges, chargeusagebased.EdgeCharge) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldNamespace requires an ID field in the mutation") + if m.intent_override != nil { + edges = append(edges, chargeusagebased.EdgeIntentOverride) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldNamespace: %w", err) + if m.subscription != nil { + edges = append(edges, chargeusagebased.EdgeSubscription) } - return oldValue.Namespace, nil -} - -// ResetNamespace resets all changes to the "namespace" field. -func (m *ChargeUsageBasedMutation) ResetNamespace() { - m.namespace = nil -} - -// SetMetadata sets the "metadata" field. -func (m *ChargeUsageBasedMutation) SetMetadata(value map[string]string) { - m.metadata = &value -} - -// Metadata returns the value of the "metadata" field in the mutation. -func (m *ChargeUsageBasedMutation) Metadata() (r map[string]string, exists bool) { - v := m.metadata - if v == nil { - return + if m.subscription_phase != nil { + edges = append(edges, chargeusagebased.EdgeSubscriptionPhase) + } + if m.subscription_item != nil { + edges = append(edges, chargeusagebased.EdgeSubscriptionItem) + } + if m.customer != nil { + edges = append(edges, chargeusagebased.EdgeCustomer) } - return *v, true -} - -// OldMetadata returns the old "metadata" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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.feature != nil { + edges = append(edges, chargeusagebased.EdgeFeature) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldMetadata requires an ID field in the mutation") + if m.tax_code != nil { + edges = append(edges, chargeusagebased.EdgeTaxCode) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldMetadata: %w", err) + if m.custom_currency != nil { + edges = append(edges, chargeusagebased.EdgeCustomCurrency) } - return oldValue.Metadata, nil -} - -// ClearMetadata clears the value of the "metadata" field. -func (m *ChargeUsageBasedMutation) ClearMetadata() { - m.metadata = nil - m.clearedFields[chargeusagebased.FieldMetadata] = struct{}{} -} - -// MetadataCleared returns if the "metadata" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) MetadataCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldMetadata] - return ok + return edges } -// ResetMetadata resets all changes to the "metadata" field. -func (m *ChargeUsageBasedMutation) ResetMetadata() { - m.metadata = nil - delete(m.clearedFields, chargeusagebased.FieldMetadata) +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *ChargeUsageBasedMutation) AddedIDs(name string) []ent.Value { + switch name { + case chargeusagebased.EdgeRuns: + ids := make([]ent.Value, 0, len(m.runs)) + for id := range m.runs { + ids = append(ids, id) + } + return ids + case chargeusagebased.EdgeDetailedLines: + ids := make([]ent.Value, 0, len(m.detailed_lines)) + for id := range m.detailed_lines { + ids = append(ids, id) + } + return ids + case chargeusagebased.EdgeCurrentRun: + if id := m.current_run; id != nil { + return []ent.Value{*id} + } + case chargeusagebased.EdgeCostBasis: + if id := m.cost_basis; id != nil { + return []ent.Value{*id} + } + case chargeusagebased.EdgeCharge: + if id := m.charge; id != nil { + return []ent.Value{*id} + } + case chargeusagebased.EdgeIntentOverride: + if id := m.intent_override; id != nil { + return []ent.Value{*id} + } + case chargeusagebased.EdgeSubscription: + if id := m.subscription; id != nil { + return []ent.Value{*id} + } + case chargeusagebased.EdgeSubscriptionPhase: + if id := m.subscription_phase; id != nil { + return []ent.Value{*id} + } + case chargeusagebased.EdgeSubscriptionItem: + if id := m.subscription_item; id != nil { + return []ent.Value{*id} + } + case chargeusagebased.EdgeCustomer: + if id := m.customer; id != nil { + return []ent.Value{*id} + } + case chargeusagebased.EdgeFeature: + if id := m.feature; id != nil { + return []ent.Value{*id} + } + case chargeusagebased.EdgeTaxCode: + if id := m.tax_code; id != nil { + return []ent.Value{*id} + } + case chargeusagebased.EdgeCustomCurrency: + if id := m.custom_currency; id != nil { + return []ent.Value{*id} + } + } + return nil } -// SetCreatedAt sets the "created_at" field. -func (m *ChargeUsageBasedMutation) SetCreatedAt(t time.Time) { - m.created_at = &t +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ChargeUsageBasedMutation) RemovedEdges() []string { + edges := make([]string, 0, 13) + if m.removedruns != nil { + edges = append(edges, chargeusagebased.EdgeRuns) + } + if m.removeddetailed_lines != nil { + edges = append(edges, chargeusagebased.EdgeDetailedLines) + } + return edges } -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ChargeUsageBasedMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *ChargeUsageBasedMutation) RemovedIDs(name string) []ent.Value { + switch name { + case chargeusagebased.EdgeRuns: + ids := make([]ent.Value, 0, len(m.removedruns)) + for id := range m.removedruns { + ids = append(ids, id) + } + return ids + case chargeusagebased.EdgeDetailedLines: + ids := make([]ent.Value, 0, len(m.removeddetailed_lines)) + for id := range m.removeddetailed_lines { + ids = append(ids, id) + } + return ids } - return *v, true + return nil } -// OldCreatedAt returns the old "created_at" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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") +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ChargeUsageBasedMutation) ClearedEdges() []string { + edges := make([]string, 0, 13) + if m.clearedruns { + edges = append(edges, chargeusagebased.EdgeRuns) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreatedAt requires an ID field in the mutation") + if m.cleareddetailed_lines { + edges = append(edges, chargeusagebased.EdgeDetailedLines) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + if m.clearedcurrent_run { + edges = append(edges, chargeusagebased.EdgeCurrentRun) } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *ChargeUsageBasedMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *ChargeUsageBasedMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ChargeUsageBasedMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return + if m.clearedcost_basis { + edges = append(edges, chargeusagebased.EdgeCostBasis) } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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.clearedcharge { + edges = append(edges, chargeusagebased.EdgeCharge) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + if m.clearedintent_override { + edges = append(edges, chargeusagebased.EdgeIntentOverride) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + if m.clearedsubscription { + edges = append(edges, chargeusagebased.EdgeSubscription) } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *ChargeUsageBasedMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// SetDeletedAt sets the "deleted_at" field. -func (m *ChargeUsageBasedMutation) SetDeletedAt(t time.Time) { - m.deleted_at = &t -} - -// DeletedAt returns the value of the "deleted_at" field in the mutation. -func (m *ChargeUsageBasedMutation) DeletedAt() (r time.Time, exists bool) { - v := m.deleted_at - if v == nil { - return + if m.clearedsubscription_phase { + edges = append(edges, chargeusagebased.EdgeSubscriptionPhase) } - return *v, true -} - -// OldDeletedAt returns the old "deleted_at" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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.clearedsubscription_item { + edges = append(edges, chargeusagebased.EdgeSubscriptionItem) } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDeletedAt requires an ID field in the mutation") + if m.clearedcustomer { + edges = append(edges, chargeusagebased.EdgeCustomer) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err) + if m.clearedfeature { + edges = append(edges, chargeusagebased.EdgeFeature) } - return oldValue.DeletedAt, nil -} - -// ClearDeletedAt clears the value of the "deleted_at" field. -func (m *ChargeUsageBasedMutation) ClearDeletedAt() { - m.deleted_at = nil - m.clearedFields[chargeusagebased.FieldDeletedAt] = struct{}{} -} - -// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) DeletedAtCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldDeletedAt] - return ok -} - -// ResetDeletedAt resets all changes to the "deleted_at" field. -func (m *ChargeUsageBasedMutation) ResetDeletedAt() { - m.deleted_at = nil - delete(m.clearedFields, chargeusagebased.FieldDeletedAt) + if m.clearedtax_code { + edges = append(edges, chargeusagebased.EdgeTaxCode) + } + if m.clearedcustom_currency { + edges = append(edges, chargeusagebased.EdgeCustomCurrency) + } + return edges } -// SetName sets the "name" field. -func (m *ChargeUsageBasedMutation) SetName(s string) { - m.name = &s +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *ChargeUsageBasedMutation) EdgeCleared(name string) bool { + switch name { + case chargeusagebased.EdgeRuns: + return m.clearedruns + case chargeusagebased.EdgeDetailedLines: + return m.cleareddetailed_lines + case chargeusagebased.EdgeCurrentRun: + return m.clearedcurrent_run + case chargeusagebased.EdgeCostBasis: + return m.clearedcost_basis + case chargeusagebased.EdgeCharge: + return m.clearedcharge + case chargeusagebased.EdgeIntentOverride: + return m.clearedintent_override + case chargeusagebased.EdgeSubscription: + return m.clearedsubscription + case chargeusagebased.EdgeSubscriptionPhase: + return m.clearedsubscription_phase + case chargeusagebased.EdgeSubscriptionItem: + return m.clearedsubscription_item + case chargeusagebased.EdgeCustomer: + return m.clearedcustomer + case chargeusagebased.EdgeFeature: + return m.clearedfeature + case chargeusagebased.EdgeTaxCode: + return m.clearedtax_code + case chargeusagebased.EdgeCustomCurrency: + return m.clearedcustom_currency + } + return false } -// Name returns the value of the "name" field in the mutation. -func (m *ChargeUsageBasedMutation) Name() (r string, exists bool) { - v := m.name - if v == nil { - return +// 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 *ChargeUsageBasedMutation) ClearEdge(name string) error { + switch name { + case chargeusagebased.EdgeCurrentRun: + m.ClearCurrentRun() + return nil + case chargeusagebased.EdgeCostBasis: + m.ClearCostBasis() + return nil + case chargeusagebased.EdgeCharge: + m.ClearCharge() + return nil + case chargeusagebased.EdgeIntentOverride: + m.ClearIntentOverride() + return nil + case chargeusagebased.EdgeSubscription: + m.ClearSubscription() + return nil + case chargeusagebased.EdgeSubscriptionPhase: + m.ClearSubscriptionPhase() + return nil + case chargeusagebased.EdgeSubscriptionItem: + m.ClearSubscriptionItem() + return nil + case chargeusagebased.EdgeCustomer: + m.ClearCustomer() + return nil + case chargeusagebased.EdgeFeature: + m.ClearFeature() + return nil + case chargeusagebased.EdgeTaxCode: + m.ClearTaxCode() + return nil + case chargeusagebased.EdgeCustomCurrency: + m.ClearCustomCurrency() + return nil } - return *v, true + return fmt.Errorf("unknown ChargeUsageBased unique edge %s", name) } -// OldName returns the old "name" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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) +// 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 *ChargeUsageBasedMutation) ResetEdge(name string) error { + switch name { + case chargeusagebased.EdgeRuns: + m.ResetRuns() + return nil + case chargeusagebased.EdgeDetailedLines: + m.ResetDetailedLines() + return nil + case chargeusagebased.EdgeCurrentRun: + m.ResetCurrentRun() + return nil + case chargeusagebased.EdgeCostBasis: + m.ResetCostBasis() + return nil + case chargeusagebased.EdgeCharge: + m.ResetCharge() + return nil + case chargeusagebased.EdgeIntentOverride: + m.ResetIntentOverride() + return nil + case chargeusagebased.EdgeSubscription: + m.ResetSubscription() + return nil + case chargeusagebased.EdgeSubscriptionPhase: + m.ResetSubscriptionPhase() + return nil + case chargeusagebased.EdgeSubscriptionItem: + m.ResetSubscriptionItem() + return nil + case chargeusagebased.EdgeCustomer: + m.ResetCustomer() + return nil + case chargeusagebased.EdgeFeature: + m.ResetFeature() + return nil + case chargeusagebased.EdgeTaxCode: + m.ResetTaxCode() + return nil + case chargeusagebased.EdgeCustomCurrency: + m.ResetCustomCurrency() + return nil } - return oldValue.Name, nil + return fmt.Errorf("unknown ChargeUsageBased edge %s", name) } -// ResetName resets all changes to the "name" field. -func (m *ChargeUsageBasedMutation) ResetName() { - m.name = nil +// ChargeUsageBasedCostBasisMutation represents an operation that mutates the ChargeUsageBasedCostBasis nodes in the graph. +type ChargeUsageBasedCostBasisMutation struct { + config + op Op + typ string + id *string + mode *costbasis.Mode + fiat_currency *currencyx.FiatCode + manual_rate *alpacadecimal.Decimal + resolved_cost_basis *alpacadecimal.Decimal + resolved_at *time.Time + namespace *string + created_at *time.Time + updated_at *time.Time + deleted_at *time.Time + clearedFields map[string]struct{} + currency_cost_basis *string + clearedcurrency_cost_basis bool + resolved_currency_cost_basis *string + clearedresolved_currency_cost_basis bool + custom_currency *string + clearedcustom_currency bool + done bool + oldValue func(context.Context) (*ChargeUsageBasedCostBasis, error) + predicates []predicate.ChargeUsageBasedCostBasis } -// SetDescription sets the "description" field. -func (m *ChargeUsageBasedMutation) SetDescription(s string) { - m.description = &s -} +var _ ent.Mutation = (*ChargeUsageBasedCostBasisMutation)(nil) -// Description returns the value of the "description" field in the mutation. -func (m *ChargeUsageBasedMutation) Description() (r string, exists bool) { - v := m.description - if v == nil { - return - } - return *v, true -} +// chargeusagebasedcostbasisOption allows management of the mutation configuration using functional options. +type chargeusagebasedcostbasisOption func(*ChargeUsageBasedCostBasisMutation) -// OldDescription returns the old "description" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldDescription(ctx context.Context) (v *string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDescription is only allowed on UpdateOne operations") +// newChargeUsageBasedCostBasisMutation creates new mutation for the ChargeUsageBasedCostBasis entity. +func newChargeUsageBasedCostBasisMutation(c config, op Op, opts ...chargeusagebasedcostbasisOption) *ChargeUsageBasedCostBasisMutation { + m := &ChargeUsageBasedCostBasisMutation{ + config: c, + op: op, + typ: TypeChargeUsageBasedCostBasis, + clearedFields: make(map[string]struct{}), } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDescription requires an ID field in the mutation") + for _, opt := range opts { + opt(m) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDescription: %w", err) + return m +} + +// withChargeUsageBasedCostBasisID sets the ID field of the mutation. +func withChargeUsageBasedCostBasisID(id string) chargeusagebasedcostbasisOption { + return func(m *ChargeUsageBasedCostBasisMutation) { + var ( + err error + once sync.Once + value *ChargeUsageBasedCostBasis + ) + m.oldValue = func(ctx context.Context) (*ChargeUsageBasedCostBasis, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().ChargeUsageBasedCostBasis.Get(ctx, id) + } + }) + return value, err + } + m.id = &id } - return oldValue.Description, nil } -// ClearDescription clears the value of the "description" field. -func (m *ChargeUsageBasedMutation) ClearDescription() { - m.description = nil - m.clearedFields[chargeusagebased.FieldDescription] = struct{}{} +// withChargeUsageBasedCostBasis sets the old ChargeUsageBasedCostBasis of the mutation. +func withChargeUsageBasedCostBasis(node *ChargeUsageBasedCostBasis) chargeusagebasedcostbasisOption { + return func(m *ChargeUsageBasedCostBasisMutation) { + m.oldValue = func(context.Context) (*ChargeUsageBasedCostBasis, error) { + return node, nil + } + m.id = &node.ID + } } -// DescriptionCleared returns if the "description" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) DescriptionCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldDescription] - return ok +// 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 ChargeUsageBasedCostBasisMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client } -// ResetDescription resets all changes to the "description" field. -func (m *ChargeUsageBasedMutation) ResetDescription() { - m.description = nil - delete(m.clearedFields, chargeusagebased.FieldDescription) +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m ChargeUsageBasedCostBasisMutation) 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 } -// SetInvoiceAt sets the "invoice_at" field. -func (m *ChargeUsageBasedMutation) SetInvoiceAt(t time.Time) { - m.invoice_at = &t +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of ChargeUsageBasedCostBasis entities. +func (m *ChargeUsageBasedCostBasisMutation) SetID(id string) { + m.id = &id } -// InvoiceAt returns the value of the "invoice_at" field in the mutation. -func (m *ChargeUsageBasedMutation) InvoiceAt() (r time.Time, exists bool) { - v := m.invoice_at - if v == nil { +// 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 *ChargeUsageBasedCostBasisMutation) ID() (id string, exists bool) { + if m.id == nil { return } - return *v, true + return *m.id, true } -// OldInvoiceAt returns the old "invoice_at" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) 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) +// 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 *ChargeUsageBasedCostBasisMutation) 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().ChargeUsageBasedCostBasis.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } - return oldValue.InvoiceAt, nil -} - -// ResetInvoiceAt resets all changes to the "invoice_at" field. -func (m *ChargeUsageBasedMutation) ResetInvoiceAt() { - m.invoice_at = nil } -// SetSettlementMode sets the "settlement_mode" field. -func (m *ChargeUsageBasedMutation) SetSettlementMode(pm productcatalog.SettlementMode) { - m.settlement_mode = &pm +// SetMode sets the "mode" field. +func (m *ChargeUsageBasedCostBasisMutation) SetMode(c costbasis.Mode) { + m.mode = &c } -// SettlementMode returns the value of the "settlement_mode" field in the mutation. -func (m *ChargeUsageBasedMutation) SettlementMode() (r productcatalog.SettlementMode, exists bool) { - v := m.settlement_mode +// Mode returns the value of the "mode" field in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) Mode() (r costbasis.Mode, exists bool) { + v := m.mode if v == nil { return } return *v, true } -// OldSettlementMode returns the old "settlement_mode" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldMode returns the old "mode" field's value of the ChargeUsageBasedCostBasis entity. +// If the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedMutation) OldSettlementMode(ctx context.Context) (v productcatalog.SettlementMode, err error) { +func (m *ChargeUsageBasedCostBasisMutation) OldMode(ctx context.Context) (v costbasis.Mode, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSettlementMode is only allowed on UpdateOne operations") + return v, errors.New("OldMode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSettlementMode requires an ID field in the mutation") + return v, errors.New("OldMode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldSettlementMode: %w", err) + return v, fmt.Errorf("querying old value for OldMode: %w", err) } - return oldValue.SettlementMode, nil + return oldValue.Mode, nil } -// ResetSettlementMode resets all changes to the "settlement_mode" field. -func (m *ChargeUsageBasedMutation) ResetSettlementMode() { - m.settlement_mode = nil +// ResetMode resets all changes to the "mode" field. +func (m *ChargeUsageBasedCostBasisMutation) ResetMode() { + m.mode = nil } -// SetIntentDeletedAt sets the "intent_deleted_at" field. -func (m *ChargeUsageBasedMutation) SetIntentDeletedAt(t time.Time) { - m.intent_deleted_at = &t +// SetFiatCurrency sets the "fiat_currency" field. +func (m *ChargeUsageBasedCostBasisMutation) SetFiatCurrency(cc currencyx.FiatCode) { + m.fiat_currency = &cc } -// IntentDeletedAt returns the value of the "intent_deleted_at" field in the mutation. -func (m *ChargeUsageBasedMutation) IntentDeletedAt() (r time.Time, exists bool) { - v := m.intent_deleted_at +// FiatCurrency returns the value of the "fiat_currency" field in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) FiatCurrency() (r currencyx.FiatCode, exists bool) { + v := m.fiat_currency if v == nil { return } return *v, true } -// OldIntentDeletedAt returns the old "intent_deleted_at" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldFiatCurrency returns the old "fiat_currency" field's value of the ChargeUsageBasedCostBasis entity. +// If the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedMutation) OldIntentDeletedAt(ctx context.Context) (v *time.Time, err error) { +func (m *ChargeUsageBasedCostBasisMutation) OldFiatCurrency(ctx context.Context) (v currencyx.FiatCode, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldIntentDeletedAt is only allowed on UpdateOne operations") + return v, errors.New("OldFiatCurrency is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldIntentDeletedAt requires an ID field in the mutation") + return v, errors.New("OldFiatCurrency requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldIntentDeletedAt: %w", err) + return v, fmt.Errorf("querying old value for OldFiatCurrency: %w", err) } - return oldValue.IntentDeletedAt, nil -} - -// ClearIntentDeletedAt clears the value of the "intent_deleted_at" field. -func (m *ChargeUsageBasedMutation) ClearIntentDeletedAt() { - m.intent_deleted_at = nil - m.clearedFields[chargeusagebased.FieldIntentDeletedAt] = struct{}{} -} - -// IntentDeletedAtCleared returns if the "intent_deleted_at" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) IntentDeletedAtCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldIntentDeletedAt] - return ok + return oldValue.FiatCurrency, nil } -// ResetIntentDeletedAt resets all changes to the "intent_deleted_at" field. -func (m *ChargeUsageBasedMutation) ResetIntentDeletedAt() { - m.intent_deleted_at = nil - delete(m.clearedFields, chargeusagebased.FieldIntentDeletedAt) +// ResetFiatCurrency resets all changes to the "fiat_currency" field. +func (m *ChargeUsageBasedCostBasisMutation) ResetFiatCurrency() { + m.fiat_currency = nil } -// SetDiscounts sets the "discounts" field. -func (m *ChargeUsageBasedMutation) SetDiscounts(b *billing.Discounts) { - m.discounts = &b +// SetCurrencyCostBasisID sets the "currency_cost_basis_id" field. +func (m *ChargeUsageBasedCostBasisMutation) SetCurrencyCostBasisID(s string) { + m.currency_cost_basis = &s } -// Discounts returns the value of the "discounts" field in the mutation. -func (m *ChargeUsageBasedMutation) Discounts() (r *billing.Discounts, exists bool) { - v := m.discounts +// CurrencyCostBasisID returns the value of the "currency_cost_basis_id" field in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) CurrencyCostBasisID() (r string, exists bool) { + v := m.currency_cost_basis if v == nil { return } return *v, true } -// OldDiscounts returns the old "discounts" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldCurrencyCostBasisID returns the old "currency_cost_basis_id" field's value of the ChargeUsageBasedCostBasis entity. +// If the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedMutation) OldDiscounts(ctx context.Context) (v *billing.Discounts, err error) { +func (m *ChargeUsageBasedCostBasisMutation) OldCurrencyCostBasisID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDiscounts is only allowed on UpdateOne operations") + return v, errors.New("OldCurrencyCostBasisID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDiscounts requires an ID field in the mutation") + return v, errors.New("OldCurrencyCostBasisID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldDiscounts: %w", err) + return v, fmt.Errorf("querying old value for OldCurrencyCostBasisID: %w", err) } - return oldValue.Discounts, nil + return oldValue.CurrencyCostBasisID, nil } -// ClearDiscounts clears the value of the "discounts" field. -func (m *ChargeUsageBasedMutation) ClearDiscounts() { - m.discounts = nil - m.clearedFields[chargeusagebased.FieldDiscounts] = struct{}{} +// ClearCurrencyCostBasisID clears the value of the "currency_cost_basis_id" field. +func (m *ChargeUsageBasedCostBasisMutation) ClearCurrencyCostBasisID() { + m.currency_cost_basis = nil + m.clearedFields[chargeusagebasedcostbasis.FieldCurrencyCostBasisID] = struct{}{} } -// DiscountsCleared returns if the "discounts" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) DiscountsCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldDiscounts] +// CurrencyCostBasisIDCleared returns if the "currency_cost_basis_id" field was cleared in this mutation. +func (m *ChargeUsageBasedCostBasisMutation) CurrencyCostBasisIDCleared() bool { + _, ok := m.clearedFields[chargeusagebasedcostbasis.FieldCurrencyCostBasisID] return ok } -// ResetDiscounts resets all changes to the "discounts" field. -func (m *ChargeUsageBasedMutation) ResetDiscounts() { - m.discounts = nil - delete(m.clearedFields, chargeusagebased.FieldDiscounts) +// ResetCurrencyCostBasisID resets all changes to the "currency_cost_basis_id" field. +func (m *ChargeUsageBasedCostBasisMutation) ResetCurrencyCostBasisID() { + m.currency_cost_basis = nil + delete(m.clearedFields, chargeusagebasedcostbasis.FieldCurrencyCostBasisID) } -// SetFeatureKey sets the "feature_key" field. -func (m *ChargeUsageBasedMutation) SetFeatureKey(s string) { - m.feature_key = &s +// SetResolvedCostBasisID sets the "resolved_cost_basis_id" field. +func (m *ChargeUsageBasedCostBasisMutation) SetResolvedCostBasisID(s string) { + m.resolved_currency_cost_basis = &s } -// FeatureKey returns the value of the "feature_key" field in the mutation. -func (m *ChargeUsageBasedMutation) FeatureKey() (r string, exists bool) { - v := m.feature_key +// ResolvedCostBasisID returns the value of the "resolved_cost_basis_id" field in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) ResolvedCostBasisID() (r string, exists bool) { + v := m.resolved_currency_cost_basis if v == nil { return } return *v, true } -// OldFeatureKey returns the old "feature_key" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldResolvedCostBasisID returns the old "resolved_cost_basis_id" field's value of the ChargeUsageBasedCostBasis entity. +// If the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedMutation) OldFeatureKey(ctx context.Context) (v string, err error) { +func (m *ChargeUsageBasedCostBasisMutation) OldResolvedCostBasisID(ctx context.Context) (v *string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldFeatureKey is only allowed on UpdateOne operations") + return v, errors.New("OldResolvedCostBasisID 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") + return v, errors.New("OldResolvedCostBasisID 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 v, fmt.Errorf("querying old value for OldResolvedCostBasisID: %w", err) } - return oldValue.FeatureKey, nil -} - -// ResetFeatureKey resets all changes to the "feature_key" field. -func (m *ChargeUsageBasedMutation) ResetFeatureKey() { - m.feature_key = nil + return oldValue.ResolvedCostBasisID, nil } -// SetFeatureID sets the "feature_id" field. -func (m *ChargeUsageBasedMutation) SetFeatureID(s string) { - m.feature = &s -} - -// FeatureID returns the value of the "feature_id" field in the mutation. -func (m *ChargeUsageBasedMutation) FeatureID() (r string, exists bool) { - v := m.feature - if v == nil { - return - } - return *v, true +// ClearResolvedCostBasisID clears the value of the "resolved_cost_basis_id" field. +func (m *ChargeUsageBasedCostBasisMutation) ClearResolvedCostBasisID() { + m.resolved_currency_cost_basis = nil + m.clearedFields[chargeusagebasedcostbasis.FieldResolvedCostBasisID] = struct{}{} } -// OldFeatureID returns the old "feature_id" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased 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 *ChargeUsageBasedMutation) OldFeatureID(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldFeatureID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldFeatureID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldFeatureID: %w", err) - } - return oldValue.FeatureID, nil +// ResolvedCostBasisIDCleared returns if the "resolved_cost_basis_id" field was cleared in this mutation. +func (m *ChargeUsageBasedCostBasisMutation) ResolvedCostBasisIDCleared() bool { + _, ok := m.clearedFields[chargeusagebasedcostbasis.FieldResolvedCostBasisID] + return ok } -// ResetFeatureID resets all changes to the "feature_id" field. -func (m *ChargeUsageBasedMutation) ResetFeatureID() { - m.feature = nil +// ResetResolvedCostBasisID resets all changes to the "resolved_cost_basis_id" field. +func (m *ChargeUsageBasedCostBasisMutation) ResetResolvedCostBasisID() { + m.resolved_currency_cost_basis = nil + delete(m.clearedFields, chargeusagebasedcostbasis.FieldResolvedCostBasisID) } -// SetRatingEngine sets the "rating_engine" field. -func (m *ChargeUsageBasedMutation) SetRatingEngine(ue usagebased.RatingEngine) { - m.rating_engine = &ue +// SetCurrencyID sets the "currency_id" field. +func (m *ChargeUsageBasedCostBasisMutation) SetCurrencyID(s string) { + m.custom_currency = &s } -// RatingEngine returns the value of the "rating_engine" field in the mutation. -func (m *ChargeUsageBasedMutation) RatingEngine() (r usagebased.RatingEngine, exists bool) { - v := m.rating_engine +// CurrencyID returns the value of the "currency_id" field in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) CurrencyID() (r string, exists bool) { + v := m.custom_currency if v == nil { return } return *v, true } -// OldRatingEngine returns the old "rating_engine" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldCurrencyID returns the old "currency_id" field's value of the ChargeUsageBasedCostBasis entity. +// If the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedMutation) OldRatingEngine(ctx context.Context) (v usagebased.RatingEngine, err error) { +func (m *ChargeUsageBasedCostBasisMutation) OldCurrencyID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldRatingEngine is only allowed on UpdateOne operations") + return v, errors.New("OldCurrencyID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldRatingEngine requires an ID field in the mutation") + return v, errors.New("OldCurrencyID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldRatingEngine: %w", err) + return v, fmt.Errorf("querying old value for OldCurrencyID: %w", err) } - return oldValue.RatingEngine, nil + return oldValue.CurrencyID, nil } -// ResetRatingEngine resets all changes to the "rating_engine" field. -func (m *ChargeUsageBasedMutation) ResetRatingEngine() { - m.rating_engine = nil +// ResetCurrencyID resets all changes to the "currency_id" field. +func (m *ChargeUsageBasedCostBasisMutation) ResetCurrencyID() { + m.custom_currency = nil } -// SetPrice sets the "price" field. -func (m *ChargeUsageBasedMutation) SetPrice(pr *productcatalog.Price) { - m.price = &pr +// SetManualRate sets the "manual_rate" field. +func (m *ChargeUsageBasedCostBasisMutation) SetManualRate(a alpacadecimal.Decimal) { + m.manual_rate = &a } -// Price returns the value of the "price" field in the mutation. -func (m *ChargeUsageBasedMutation) Price() (r *productcatalog.Price, exists bool) { - v := m.price +// ManualRate returns the value of the "manual_rate" field in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) ManualRate() (r alpacadecimal.Decimal, exists bool) { + v := m.manual_rate if v == nil { return } return *v, true } -// OldPrice returns the old "price" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldManualRate returns the old "manual_rate" field's value of the ChargeUsageBasedCostBasis entity. +// If the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedMutation) OldPrice(ctx context.Context) (v *productcatalog.Price, err error) { +func (m *ChargeUsageBasedCostBasisMutation) OldManualRate(ctx context.Context) (v *alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldPrice is only allowed on UpdateOne operations") + return v, errors.New("OldManualRate 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") + return v, errors.New("OldManualRate 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 v, fmt.Errorf("querying old value for OldManualRate: %w", err) } - return oldValue.Price, nil + return oldValue.ManualRate, nil } -// ResetPrice resets all changes to the "price" field. -func (m *ChargeUsageBasedMutation) ResetPrice() { - m.price = nil +// ClearManualRate clears the value of the "manual_rate" field. +func (m *ChargeUsageBasedCostBasisMutation) ClearManualRate() { + m.manual_rate = nil + m.clearedFields[chargeusagebasedcostbasis.FieldManualRate] = struct{}{} } -// SetUnitConfig sets the "unit_config" field. -func (m *ChargeUsageBasedMutation) SetUnitConfig(pc *productcatalog.UnitConfig) { - m.unit_config = &pc +// ManualRateCleared returns if the "manual_rate" field was cleared in this mutation. +func (m *ChargeUsageBasedCostBasisMutation) ManualRateCleared() bool { + _, ok := m.clearedFields[chargeusagebasedcostbasis.FieldManualRate] + return ok } -// UnitConfig returns the value of the "unit_config" field in the mutation. -func (m *ChargeUsageBasedMutation) UnitConfig() (r *productcatalog.UnitConfig, exists bool) { - v := m.unit_config +// ResetManualRate resets all changes to the "manual_rate" field. +func (m *ChargeUsageBasedCostBasisMutation) ResetManualRate() { + m.manual_rate = nil + delete(m.clearedFields, chargeusagebasedcostbasis.FieldManualRate) +} + +// SetResolvedCostBasis sets the "resolved_cost_basis" field. +func (m *ChargeUsageBasedCostBasisMutation) SetResolvedCostBasis(a alpacadecimal.Decimal) { + m.resolved_cost_basis = &a +} + +// ResolvedCostBasis returns the value of the "resolved_cost_basis" field in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) ResolvedCostBasis() (r alpacadecimal.Decimal, exists bool) { + v := m.resolved_cost_basis if v == nil { return } return *v, true } -// OldUnitConfig returns the old "unit_config" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldResolvedCostBasis returns the old "resolved_cost_basis" field's value of the ChargeUsageBasedCostBasis entity. +// If the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedMutation) OldUnitConfig(ctx context.Context) (v *productcatalog.UnitConfig, err error) { +func (m *ChargeUsageBasedCostBasisMutation) OldResolvedCostBasis(ctx context.Context) (v *alpacadecimal.Decimal, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUnitConfig is only allowed on UpdateOne operations") + return v, errors.New("OldResolvedCostBasis 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") + return v, errors.New("OldResolvedCostBasis 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 v, fmt.Errorf("querying old value for OldResolvedCostBasis: %w", err) } - return oldValue.UnitConfig, nil + return oldValue.ResolvedCostBasis, nil } -// ClearUnitConfig clears the value of the "unit_config" field. -func (m *ChargeUsageBasedMutation) ClearUnitConfig() { - m.unit_config = nil - m.clearedFields[chargeusagebased.FieldUnitConfig] = struct{}{} +// ClearResolvedCostBasis clears the value of the "resolved_cost_basis" field. +func (m *ChargeUsageBasedCostBasisMutation) ClearResolvedCostBasis() { + m.resolved_cost_basis = nil + m.clearedFields[chargeusagebasedcostbasis.FieldResolvedCostBasis] = struct{}{} } -// UnitConfigCleared returns if the "unit_config" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) UnitConfigCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldUnitConfig] +// ResolvedCostBasisCleared returns if the "resolved_cost_basis" field was cleared in this mutation. +func (m *ChargeUsageBasedCostBasisMutation) ResolvedCostBasisCleared() bool { + _, ok := m.clearedFields[chargeusagebasedcostbasis.FieldResolvedCostBasis] return ok } -// ResetUnitConfig resets all changes to the "unit_config" field. -func (m *ChargeUsageBasedMutation) ResetUnitConfig() { - m.unit_config = nil - delete(m.clearedFields, chargeusagebased.FieldUnitConfig) +// ResetResolvedCostBasis resets all changes to the "resolved_cost_basis" field. +func (m *ChargeUsageBasedCostBasisMutation) ResetResolvedCostBasis() { + m.resolved_cost_basis = nil + delete(m.clearedFields, chargeusagebasedcostbasis.FieldResolvedCostBasis) } -// SetCurrentRealizationRunID sets the "current_realization_run_id" field. -func (m *ChargeUsageBasedMutation) SetCurrentRealizationRunID(s string) { - m.current_run = &s +// SetResolvedAt sets the "resolved_at" field. +func (m *ChargeUsageBasedCostBasisMutation) SetResolvedAt(t time.Time) { + m.resolved_at = &t } -// CurrentRealizationRunID returns the value of the "current_realization_run_id" field in the mutation. -func (m *ChargeUsageBasedMutation) CurrentRealizationRunID() (r string, exists bool) { - v := m.current_run +// ResolvedAt returns the value of the "resolved_at" field in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) ResolvedAt() (r time.Time, exists bool) { + v := m.resolved_at if v == nil { return } return *v, true } -// OldCurrentRealizationRunID returns the old "current_realization_run_id" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldResolvedAt returns the old "resolved_at" field's value of the ChargeUsageBasedCostBasis entity. +// If the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedMutation) OldCurrentRealizationRunID(ctx context.Context) (v *string, err error) { +func (m *ChargeUsageBasedCostBasisMutation) OldResolvedAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCurrentRealizationRunID is only allowed on UpdateOne operations") + return v, errors.New("OldResolvedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCurrentRealizationRunID requires an ID field in the mutation") + return v, errors.New("OldResolvedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldCurrentRealizationRunID: %w", err) + return v, fmt.Errorf("querying old value for OldResolvedAt: %w", err) } - return oldValue.CurrentRealizationRunID, nil + return oldValue.ResolvedAt, nil } -// ClearCurrentRealizationRunID clears the value of the "current_realization_run_id" field. -func (m *ChargeUsageBasedMutation) ClearCurrentRealizationRunID() { - m.current_run = nil - m.clearedFields[chargeusagebased.FieldCurrentRealizationRunID] = struct{}{} +// ClearResolvedAt clears the value of the "resolved_at" field. +func (m *ChargeUsageBasedCostBasisMutation) ClearResolvedAt() { + m.resolved_at = nil + m.clearedFields[chargeusagebasedcostbasis.FieldResolvedAt] = struct{}{} } -// CurrentRealizationRunIDCleared returns if the "current_realization_run_id" field was cleared in this mutation. -func (m *ChargeUsageBasedMutation) CurrentRealizationRunIDCleared() bool { - _, ok := m.clearedFields[chargeusagebased.FieldCurrentRealizationRunID] +// ResolvedAtCleared returns if the "resolved_at" field was cleared in this mutation. +func (m *ChargeUsageBasedCostBasisMutation) ResolvedAtCleared() bool { + _, ok := m.clearedFields[chargeusagebasedcostbasis.FieldResolvedAt] return ok } -// ResetCurrentRealizationRunID resets all changes to the "current_realization_run_id" field. -func (m *ChargeUsageBasedMutation) ResetCurrentRealizationRunID() { - m.current_run = nil - delete(m.clearedFields, chargeusagebased.FieldCurrentRealizationRunID) +// ResetResolvedAt resets all changes to the "resolved_at" field. +func (m *ChargeUsageBasedCostBasisMutation) ResetResolvedAt() { + m.resolved_at = nil + delete(m.clearedFields, chargeusagebasedcostbasis.FieldResolvedAt) } -// SetStatusDetailed sets the "status_detailed" field. -func (m *ChargeUsageBasedMutation) SetStatusDetailed(u usagebased.Status) { - m.status_detailed = &u +// SetNamespace sets the "namespace" field. +func (m *ChargeUsageBasedCostBasisMutation) SetNamespace(s string) { + m.namespace = &s } -// StatusDetailed returns the value of the "status_detailed" field in the mutation. -func (m *ChargeUsageBasedMutation) StatusDetailed() (r usagebased.Status, exists bool) { - v := m.status_detailed +// Namespace returns the value of the "namespace" field in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) Namespace() (r string, exists bool) { + v := m.namespace if v == nil { return } return *v, true } -// OldStatusDetailed returns the old "status_detailed" field's value of the ChargeUsageBased entity. -// If the ChargeUsageBased object wasn't provided to the builder, the object is fetched from the database. +// OldNamespace returns the old "namespace" field's value of the ChargeUsageBasedCostBasis entity. +// If the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedMutation) OldStatusDetailed(ctx context.Context) (v usagebased.Status, err error) { +func (m *ChargeUsageBasedCostBasisMutation) OldNamespace(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldStatusDetailed is only allowed on UpdateOne operations") + return v, errors.New("OldNamespace is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldStatusDetailed requires an ID field in the mutation") + 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 OldStatusDetailed: %w", err) - } - return oldValue.StatusDetailed, nil -} - -// ResetStatusDetailed resets all changes to the "status_detailed" field. -func (m *ChargeUsageBasedMutation) ResetStatusDetailed() { - m.status_detailed = nil -} - -// AddRunIDs adds the "runs" edge to the ChargeUsageBasedRuns entity by ids. -func (m *ChargeUsageBasedMutation) AddRunIDs(ids ...string) { - if m.runs == nil { - m.runs = make(map[string]struct{}) - } - for i := range ids { - m.runs[ids[i]] = struct{}{} - } -} - -// ClearRuns clears the "runs" edge to the ChargeUsageBasedRuns entity. -func (m *ChargeUsageBasedMutation) ClearRuns() { - m.clearedruns = true -} - -// RunsCleared reports if the "runs" edge to the ChargeUsageBasedRuns entity was cleared. -func (m *ChargeUsageBasedMutation) RunsCleared() bool { - return m.clearedruns -} - -// RemoveRunIDs removes the "runs" edge to the ChargeUsageBasedRuns entity by IDs. -func (m *ChargeUsageBasedMutation) RemoveRunIDs(ids ...string) { - if m.removedruns == nil { - m.removedruns = make(map[string]struct{}) - } - for i := range ids { - delete(m.runs, ids[i]) - m.removedruns[ids[i]] = struct{}{} - } -} - -// RemovedRuns returns the removed IDs of the "runs" edge to the ChargeUsageBasedRuns entity. -func (m *ChargeUsageBasedMutation) RemovedRunsIDs() (ids []string) { - for id := range m.removedruns { - ids = append(ids, id) - } - return -} - -// RunsIDs returns the "runs" edge IDs in the mutation. -func (m *ChargeUsageBasedMutation) RunsIDs() (ids []string) { - for id := range m.runs { - ids = append(ids, id) - } - return -} - -// ResetRuns resets all changes to the "runs" edge. -func (m *ChargeUsageBasedMutation) ResetRuns() { - m.runs = nil - m.clearedruns = false - m.removedruns = nil -} - -// AddDetailedLineIDs adds the "detailed_lines" edge to the ChargeUsageBasedRunDetailedLine entity by ids. -func (m *ChargeUsageBasedMutation) AddDetailedLineIDs(ids ...string) { - if m.detailed_lines == nil { - m.detailed_lines = make(map[string]struct{}) - } - for i := range ids { - m.detailed_lines[ids[i]] = struct{}{} - } -} - -// ClearDetailedLines clears the "detailed_lines" edge to the ChargeUsageBasedRunDetailedLine entity. -func (m *ChargeUsageBasedMutation) ClearDetailedLines() { - m.cleareddetailed_lines = true -} - -// DetailedLinesCleared reports if the "detailed_lines" edge to the ChargeUsageBasedRunDetailedLine entity was cleared. -func (m *ChargeUsageBasedMutation) DetailedLinesCleared() bool { - return m.cleareddetailed_lines -} - -// RemoveDetailedLineIDs removes the "detailed_lines" edge to the ChargeUsageBasedRunDetailedLine entity by IDs. -func (m *ChargeUsageBasedMutation) RemoveDetailedLineIDs(ids ...string) { - if m.removeddetailed_lines == nil { - m.removeddetailed_lines = make(map[string]struct{}) - } - for i := range ids { - delete(m.detailed_lines, ids[i]) - m.removeddetailed_lines[ids[i]] = struct{}{} - } -} - -// RemovedDetailedLines returns the removed IDs of the "detailed_lines" edge to the ChargeUsageBasedRunDetailedLine entity. -func (m *ChargeUsageBasedMutation) RemovedDetailedLinesIDs() (ids []string) { - for id := range m.removeddetailed_lines { - ids = append(ids, id) - } - return -} - -// DetailedLinesIDs returns the "detailed_lines" edge IDs in the mutation. -func (m *ChargeUsageBasedMutation) DetailedLinesIDs() (ids []string) { - for id := range m.detailed_lines { - ids = append(ids, id) + return v, fmt.Errorf("querying old value for OldNamespace: %w", err) } - return -} - -// ResetDetailedLines resets all changes to the "detailed_lines" edge. -func (m *ChargeUsageBasedMutation) ResetDetailedLines() { - m.detailed_lines = nil - m.cleareddetailed_lines = false - m.removeddetailed_lines = nil -} - -// SetCurrentRunID sets the "current_run" edge to the ChargeUsageBasedRuns entity by id. -func (m *ChargeUsageBasedMutation) SetCurrentRunID(id string) { - m.current_run = &id + return oldValue.Namespace, nil } -// ClearCurrentRun clears the "current_run" edge to the ChargeUsageBasedRuns entity. -func (m *ChargeUsageBasedMutation) ClearCurrentRun() { - m.clearedcurrent_run = true - m.clearedFields[chargeusagebased.FieldCurrentRealizationRunID] = struct{}{} +// ResetNamespace resets all changes to the "namespace" field. +func (m *ChargeUsageBasedCostBasisMutation) ResetNamespace() { + m.namespace = nil } -// CurrentRunCleared reports if the "current_run" edge to the ChargeUsageBasedRuns entity was cleared. -func (m *ChargeUsageBasedMutation) CurrentRunCleared() bool { - return m.CurrentRealizationRunIDCleared() || m.clearedcurrent_run +// SetCreatedAt sets the "created_at" field. +func (m *ChargeUsageBasedCostBasisMutation) SetCreatedAt(t time.Time) { + m.created_at = &t } -// CurrentRunID returns the "current_run" edge ID in the mutation. -func (m *ChargeUsageBasedMutation) CurrentRunID() (id string, exists bool) { - if m.current_run != nil { - return *m.current_run, true +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return } - return + return *v, true } -// CurrentRunIDs returns the "current_run" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// CurrentRunID instead. It exists only for internal usage by the builders. -func (m *ChargeUsageBasedMutation) CurrentRunIDs() (ids []string) { - if id := m.current_run; id != nil { - ids = append(ids, *id) +// OldCreatedAt returns the old "created_at" field's value of the ChargeUsageBasedCostBasis entity. +// If the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedCostBasisMutation) 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") } - return -} - -// ResetCurrentRun resets all changes to the "current_run" edge. -func (m *ChargeUsageBasedMutation) ResetCurrentRun() { - m.current_run = nil - m.clearedcurrent_run = false -} - -// SetChargeID sets the "charge" edge to the Charge entity by id. -func (m *ChargeUsageBasedMutation) SetChargeID(id string) { - m.charge = &id -} - -// ClearCharge clears the "charge" edge to the Charge entity. -func (m *ChargeUsageBasedMutation) ClearCharge() { - m.clearedcharge = true -} - -// ChargeCleared reports if the "charge" edge to the Charge entity was cleared. -func (m *ChargeUsageBasedMutation) ChargeCleared() bool { - return m.clearedcharge -} - -// ChargeID returns the "charge" edge ID in the mutation. -func (m *ChargeUsageBasedMutation) ChargeID() (id string, exists bool) { - if m.charge != nil { - return *m.charge, true + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") } - return -} - -// 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 *ChargeUsageBasedMutation) ChargeIDs() (ids []string) { - if id := m.charge; id != nil { - ids = append(ids, *id) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } - return -} - -// ResetCharge resets all changes to the "charge" edge. -func (m *ChargeUsageBasedMutation) ResetCharge() { - m.charge = nil - m.clearedcharge = false -} - -// SetIntentOverrideID sets the "intent_override" edge to the ChargeUsageBasedOverride entity by id. -func (m *ChargeUsageBasedMutation) SetIntentOverrideID(id string) { - m.intent_override = &id + return oldValue.CreatedAt, nil } -// ClearIntentOverride clears the "intent_override" edge to the ChargeUsageBasedOverride entity. -func (m *ChargeUsageBasedMutation) ClearIntentOverride() { - m.clearedintent_override = true +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *ChargeUsageBasedCostBasisMutation) ResetCreatedAt() { + m.created_at = nil } -// IntentOverrideCleared reports if the "intent_override" edge to the ChargeUsageBasedOverride entity was cleared. -func (m *ChargeUsageBasedMutation) IntentOverrideCleared() bool { - return m.clearedintent_override +// SetUpdatedAt sets the "updated_at" field. +func (m *ChargeUsageBasedCostBasisMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t } -// IntentOverrideID returns the "intent_override" edge ID in the mutation. -func (m *ChargeUsageBasedMutation) IntentOverrideID() (id string, exists bool) { - if m.intent_override != nil { - return *m.intent_override, true +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return } - return + return *v, true } -// IntentOverrideIDs returns the "intent_override" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// IntentOverrideID instead. It exists only for internal usage by the builders. -func (m *ChargeUsageBasedMutation) IntentOverrideIDs() (ids []string) { - if id := m.intent_override; id != nil { - ids = append(ids, *id) +// OldUpdatedAt returns the old "updated_at" field's value of the ChargeUsageBasedCostBasis entity. +// If the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedCostBasisMutation) 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") } - return -} - -// ResetIntentOverride resets all changes to the "intent_override" edge. -func (m *ChargeUsageBasedMutation) ResetIntentOverride() { - m.intent_override = nil - m.clearedintent_override = false -} - -// ClearSubscription clears the "subscription" edge to the Subscription entity. -func (m *ChargeUsageBasedMutation) ClearSubscription() { - m.clearedsubscription = true - m.clearedFields[chargeusagebased.FieldSubscriptionID] = struct{}{} -} - -// SubscriptionCleared reports if the "subscription" edge to the Subscription entity was cleared. -func (m *ChargeUsageBasedMutation) 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 *ChargeUsageBasedMutation) SubscriptionIDs() (ids []string) { - if id := m.subscription; id != nil { - ids = append(ids, *id) + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") } - return -} - -// ResetSubscription resets all changes to the "subscription" edge. -func (m *ChargeUsageBasedMutation) ResetSubscription() { - m.subscription = nil - m.clearedsubscription = false + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil } -// ClearSubscriptionPhase clears the "subscription_phase" edge to the SubscriptionPhase entity. -func (m *ChargeUsageBasedMutation) ClearSubscriptionPhase() { - m.clearedsubscription_phase = true - m.clearedFields[chargeusagebased.FieldSubscriptionPhaseID] = struct{}{} +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *ChargeUsageBasedCostBasisMutation) ResetUpdatedAt() { + m.updated_at = nil } -// SubscriptionPhaseCleared reports if the "subscription_phase" edge to the SubscriptionPhase entity was cleared. -func (m *ChargeUsageBasedMutation) SubscriptionPhaseCleared() bool { - return m.SubscriptionPhaseIDCleared() || m.clearedsubscription_phase +// SetDeletedAt sets the "deleted_at" field. +func (m *ChargeUsageBasedCostBasisMutation) SetDeletedAt(t time.Time) { + m.deleted_at = &t } -// 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 *ChargeUsageBasedMutation) SubscriptionPhaseIDs() (ids []string) { - if id := m.subscription_phase; id != nil { - ids = append(ids, *id) +// DeletedAt returns the value of the "deleted_at" field in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) DeletedAt() (r time.Time, exists bool) { + v := m.deleted_at + if v == nil { + return } - return -} - -// ResetSubscriptionPhase resets all changes to the "subscription_phase" edge. -func (m *ChargeUsageBasedMutation) ResetSubscriptionPhase() { - m.subscription_phase = nil - m.clearedsubscription_phase = false + return *v, true } -// ClearSubscriptionItem clears the "subscription_item" edge to the SubscriptionItem entity. -func (m *ChargeUsageBasedMutation) ClearSubscriptionItem() { - m.clearedsubscription_item = true - m.clearedFields[chargeusagebased.FieldSubscriptionItemID] = struct{}{} +// OldDeletedAt returns the old "deleted_at" field's value of the ChargeUsageBasedCostBasis entity. +// If the ChargeUsageBasedCostBasis 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 *ChargeUsageBasedCostBasisMutation) 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 } -// SubscriptionItemCleared reports if the "subscription_item" edge to the SubscriptionItem entity was cleared. -func (m *ChargeUsageBasedMutation) SubscriptionItemCleared() bool { - return m.SubscriptionItemIDCleared() || m.clearedsubscription_item +// ClearDeletedAt clears the value of the "deleted_at" field. +func (m *ChargeUsageBasedCostBasisMutation) ClearDeletedAt() { + m.deleted_at = nil + m.clearedFields[chargeusagebasedcostbasis.FieldDeletedAt] = struct{}{} } -// 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 *ChargeUsageBasedMutation) SubscriptionItemIDs() (ids []string) { - if id := m.subscription_item; id != nil { - ids = append(ids, *id) - } - return +// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation. +func (m *ChargeUsageBasedCostBasisMutation) DeletedAtCleared() bool { + _, ok := m.clearedFields[chargeusagebasedcostbasis.FieldDeletedAt] + return ok } -// ResetSubscriptionItem resets all changes to the "subscription_item" edge. -func (m *ChargeUsageBasedMutation) ResetSubscriptionItem() { - m.subscription_item = nil - m.clearedsubscription_item = false +// ResetDeletedAt resets all changes to the "deleted_at" field. +func (m *ChargeUsageBasedCostBasisMutation) ResetDeletedAt() { + m.deleted_at = nil + delete(m.clearedFields, chargeusagebasedcostbasis.FieldDeletedAt) } -// ClearCustomer clears the "customer" edge to the Customer entity. -func (m *ChargeUsageBasedMutation) ClearCustomer() { - m.clearedcustomer = true - m.clearedFields[chargeusagebased.FieldCustomerID] = struct{}{} +// ClearCurrencyCostBasis clears the "currency_cost_basis" edge to the CurrencyCostBasis entity. +func (m *ChargeUsageBasedCostBasisMutation) ClearCurrencyCostBasis() { + m.clearedcurrency_cost_basis = true + m.clearedFields[chargeusagebasedcostbasis.FieldCurrencyCostBasisID] = struct{}{} } -// CustomerCleared reports if the "customer" edge to the Customer entity was cleared. -func (m *ChargeUsageBasedMutation) CustomerCleared() bool { - return m.clearedcustomer +// CurrencyCostBasisCleared reports if the "currency_cost_basis" edge to the CurrencyCostBasis entity was cleared. +func (m *ChargeUsageBasedCostBasisMutation) CurrencyCostBasisCleared() bool { + return m.CurrencyCostBasisIDCleared() || m.clearedcurrency_cost_basis } -// CustomerIDs returns the "customer" edge IDs in the mutation. +// CurrencyCostBasisIDs returns the "currency_cost_basis" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// CustomerID instead. It exists only for internal usage by the builders. -func (m *ChargeUsageBasedMutation) CustomerIDs() (ids []string) { - if id := m.customer; id != nil { +// CurrencyCostBasisID instead. It exists only for internal usage by the builders. +func (m *ChargeUsageBasedCostBasisMutation) CurrencyCostBasisIDs() (ids []string) { + if id := m.currency_cost_basis; id != nil { ids = append(ids, *id) } return } -// ResetCustomer resets all changes to the "customer" edge. -func (m *ChargeUsageBasedMutation) ResetCustomer() { - m.customer = nil - m.clearedcustomer = false -} - -// ClearFeature clears the "feature" edge to the Feature entity. -func (m *ChargeUsageBasedMutation) ClearFeature() { - m.clearedfeature = true - m.clearedFields[chargeusagebased.FieldFeatureID] = struct{}{} -} - -// FeatureCleared reports if the "feature" edge to the Feature entity was cleared. -func (m *ChargeUsageBasedMutation) FeatureCleared() bool { - return m.clearedfeature +// ResetCurrencyCostBasis resets all changes to the "currency_cost_basis" edge. +func (m *ChargeUsageBasedCostBasisMutation) ResetCurrencyCostBasis() { + m.currency_cost_basis = nil + m.clearedcurrency_cost_basis = false } -// FeatureIDs returns the "feature" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// FeatureID instead. It exists only for internal usage by the builders. -func (m *ChargeUsageBasedMutation) FeatureIDs() (ids []string) { - if id := m.feature; id != nil { - ids = append(ids, *id) - } - return +// SetResolvedCurrencyCostBasisID sets the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity by id. +func (m *ChargeUsageBasedCostBasisMutation) SetResolvedCurrencyCostBasisID(id string) { + m.resolved_currency_cost_basis = &id } -// ResetFeature resets all changes to the "feature" edge. -func (m *ChargeUsageBasedMutation) ResetFeature() { - m.feature = nil - m.clearedfeature = false +// ClearResolvedCurrencyCostBasis clears the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity. +func (m *ChargeUsageBasedCostBasisMutation) ClearResolvedCurrencyCostBasis() { + m.clearedresolved_currency_cost_basis = true + m.clearedFields[chargeusagebasedcostbasis.FieldResolvedCostBasisID] = struct{}{} } -// ClearTaxCode clears the "tax_code" edge to the TaxCode entity. -func (m *ChargeUsageBasedMutation) ClearTaxCode() { - m.clearedtax_code = true - m.clearedFields[chargeusagebased.FieldTaxCodeID] = struct{}{} +// ResolvedCurrencyCostBasisCleared reports if the "resolved_currency_cost_basis" edge to the CurrencyCostBasis entity was cleared. +func (m *ChargeUsageBasedCostBasisMutation) ResolvedCurrencyCostBasisCleared() bool { + return m.ResolvedCostBasisIDCleared() || m.clearedresolved_currency_cost_basis } -// TaxCodeCleared reports if the "tax_code" edge to the TaxCode entity was cleared. -func (m *ChargeUsageBasedMutation) TaxCodeCleared() bool { - return m.clearedtax_code +// ResolvedCurrencyCostBasisID returns the "resolved_currency_cost_basis" edge ID in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) ResolvedCurrencyCostBasisID() (id string, exists bool) { + if m.resolved_currency_cost_basis != nil { + return *m.resolved_currency_cost_basis, true + } + return } -// TaxCodeIDs returns the "tax_code" edge IDs in the mutation. +// ResolvedCurrencyCostBasisIDs returns the "resolved_currency_cost_basis" 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 *ChargeUsageBasedMutation) TaxCodeIDs() (ids []string) { - if id := m.tax_code; id != nil { +// ResolvedCurrencyCostBasisID instead. It exists only for internal usage by the builders. +func (m *ChargeUsageBasedCostBasisMutation) ResolvedCurrencyCostBasisIDs() (ids []string) { + if id := m.resolved_currency_cost_basis; id != nil { ids = append(ids, *id) } return } -// ResetTaxCode resets all changes to the "tax_code" edge. -func (m *ChargeUsageBasedMutation) ResetTaxCode() { - m.tax_code = nil - m.clearedtax_code = false +// ResetResolvedCurrencyCostBasis resets all changes to the "resolved_currency_cost_basis" edge. +func (m *ChargeUsageBasedCostBasisMutation) ResetResolvedCurrencyCostBasis() { + m.resolved_currency_cost_basis = nil + m.clearedresolved_currency_cost_basis = false +} + +// SetCustomCurrencyID sets the "custom_currency" edge to the CustomCurrency entity by id. +func (m *ChargeUsageBasedCostBasisMutation) SetCustomCurrencyID(id string) { + m.custom_currency = &id } // ClearCustomCurrency clears the "custom_currency" edge to the CustomCurrency entity. -func (m *ChargeUsageBasedMutation) ClearCustomCurrency() { +func (m *ChargeUsageBasedCostBasisMutation) ClearCustomCurrency() { m.clearedcustom_currency = true - m.clearedFields[chargeusagebased.FieldCustomCurrencyID] = struct{}{} + m.clearedFields[chargeusagebasedcostbasis.FieldCurrencyID] = struct{}{} } // CustomCurrencyCleared reports if the "custom_currency" edge to the CustomCurrency entity was cleared. -func (m *ChargeUsageBasedMutation) CustomCurrencyCleared() bool { - return m.CustomCurrencyIDCleared() || m.clearedcustom_currency +func (m *ChargeUsageBasedCostBasisMutation) CustomCurrencyCleared() bool { + return m.clearedcustom_currency +} + +// CustomCurrencyID returns the "custom_currency" edge ID in the mutation. +func (m *ChargeUsageBasedCostBasisMutation) CustomCurrencyID() (id string, exists bool) { + if m.custom_currency != nil { + return *m.custom_currency, true + } + return } // CustomCurrencyIDs returns the "custom_currency" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // CustomCurrencyID instead. It exists only for internal usage by the builders. -func (m *ChargeUsageBasedMutation) CustomCurrencyIDs() (ids []string) { +func (m *ChargeUsageBasedCostBasisMutation) CustomCurrencyIDs() (ids []string) { if id := m.custom_currency; id != nil { ids = append(ids, *id) } @@ -60900,20 +65574,20 @@ func (m *ChargeUsageBasedMutation) CustomCurrencyIDs() (ids []string) { } // ResetCustomCurrency resets all changes to the "custom_currency" edge. -func (m *ChargeUsageBasedMutation) ResetCustomCurrency() { +func (m *ChargeUsageBasedCostBasisMutation) ResetCustomCurrency() { m.custom_currency = nil m.clearedcustom_currency = false } -// Where appends a list predicates to the ChargeUsageBasedMutation builder. -func (m *ChargeUsageBasedMutation) Where(ps ...predicate.ChargeUsageBased) { +// Where appends a list predicates to the ChargeUsageBasedCostBasisMutation builder. +func (m *ChargeUsageBasedCostBasisMutation) Where(ps ...predicate.ChargeUsageBasedCostBasis) { m.predicates = append(m.predicates, ps...) } -// WhereP appends storage-level predicates to the ChargeUsageBasedMutation builder. Using this method, +// WhereP appends storage-level predicates to the ChargeUsageBasedCostBasisMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. -func (m *ChargeUsageBasedMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.ChargeUsageBased, len(ps)) +func (m *ChargeUsageBasedCostBasisMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ChargeUsageBasedCostBasis, len(ps)) for i := range ps { p[i] = ps[i] } @@ -60921,135 +65595,60 @@ func (m *ChargeUsageBasedMutation) WhereP(ps ...func(*sql.Selector)) { } // Op returns the operation name. -func (m *ChargeUsageBasedMutation) Op() Op { +func (m *ChargeUsageBasedCostBasisMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. -func (m *ChargeUsageBasedMutation) SetOp(op Op) { +func (m *ChargeUsageBasedCostBasisMutation) SetOp(op Op) { m.op = op } -// Type returns the node type of this mutation (ChargeUsageBased). -func (m *ChargeUsageBasedMutation) Type() string { +// Type returns the node type of this mutation (ChargeUsageBasedCostBasis). +func (m *ChargeUsageBasedCostBasisMutation) 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 *ChargeUsageBasedMutation) Fields() []string { - fields := make([]string, 0, 37) - if m.customer != nil { - fields = append(fields, chargeusagebased.FieldCustomerID) - } - if m.service_period_from != nil { - fields = append(fields, chargeusagebased.FieldServicePeriodFrom) - } - if m.service_period_to != nil { - fields = append(fields, chargeusagebased.FieldServicePeriodTo) - } - if m.billing_period_from != nil { - fields = append(fields, chargeusagebased.FieldBillingPeriodFrom) - } - if m.billing_period_to != nil { - fields = append(fields, chargeusagebased.FieldBillingPeriodTo) - } - if m.full_service_period_from != nil { - fields = append(fields, chargeusagebased.FieldFullServicePeriodFrom) - } - if m.full_service_period_to != nil { - fields = append(fields, chargeusagebased.FieldFullServicePeriodTo) +func (m *ChargeUsageBasedCostBasisMutation) Fields() []string { + fields := make([]string, 0, 12) + if m.mode != nil { + fields = append(fields, chargeusagebasedcostbasis.FieldMode) } - if m.status != nil { - fields = append(fields, chargeusagebased.FieldStatus) + if m.fiat_currency != nil { + fields = append(fields, chargeusagebasedcostbasis.FieldFiatCurrency) } - if m.unique_reference_id != nil { - fields = append(fields, chargeusagebased.FieldUniqueReferenceID) + if m.currency_cost_basis != nil { + fields = append(fields, chargeusagebasedcostbasis.FieldCurrencyCostBasisID) } - if m.fiat_currency_code != nil { - fields = append(fields, chargeusagebased.FieldFiatCurrencyCode) + if m.resolved_currency_cost_basis != nil { + fields = append(fields, chargeusagebasedcostbasis.FieldResolvedCostBasisID) } if m.custom_currency != nil { - fields = append(fields, chargeusagebased.FieldCustomCurrencyID) - } - if m.managed_by != nil { - fields = append(fields, chargeusagebased.FieldManagedBy) - } - if m.subscription != nil { - fields = append(fields, chargeusagebased.FieldSubscriptionID) - } - if m.subscription_phase != nil { - fields = append(fields, chargeusagebased.FieldSubscriptionPhaseID) + fields = append(fields, chargeusagebasedcostbasis.FieldCurrencyID) } - if m.subscription_item != nil { - fields = append(fields, chargeusagebased.FieldSubscriptionItemID) - } - if m.advance_after != nil { - fields = append(fields, chargeusagebased.FieldAdvanceAfter) - } - if m.tax_code != nil { - fields = append(fields, chargeusagebased.FieldTaxCodeID) + if m.manual_rate != nil { + fields = append(fields, chargeusagebasedcostbasis.FieldManualRate) } - if m.tax_behavior != nil { - fields = append(fields, chargeusagebased.FieldTaxBehavior) + if m.resolved_cost_basis != nil { + fields = append(fields, chargeusagebasedcostbasis.FieldResolvedCostBasis) } - if m.annotations != nil { - fields = append(fields, chargeusagebased.FieldAnnotations) + if m.resolved_at != nil { + fields = append(fields, chargeusagebasedcostbasis.FieldResolvedAt) } if m.namespace != nil { - fields = append(fields, chargeusagebased.FieldNamespace) - } - if m.metadata != nil { - fields = append(fields, chargeusagebased.FieldMetadata) + fields = append(fields, chargeusagebasedcostbasis.FieldNamespace) } if m.created_at != nil { - fields = append(fields, chargeusagebased.FieldCreatedAt) + fields = append(fields, chargeusagebasedcostbasis.FieldCreatedAt) } if m.updated_at != nil { - fields = append(fields, chargeusagebased.FieldUpdatedAt) + fields = append(fields, chargeusagebasedcostbasis.FieldUpdatedAt) } if m.deleted_at != nil { - fields = append(fields, chargeusagebased.FieldDeletedAt) - } - if m.name != nil { - fields = append(fields, chargeusagebased.FieldName) - } - if m.description != nil { - fields = append(fields, chargeusagebased.FieldDescription) - } - if m.invoice_at != nil { - fields = append(fields, chargeusagebased.FieldInvoiceAt) - } - if m.settlement_mode != nil { - fields = append(fields, chargeusagebased.FieldSettlementMode) - } - if m.intent_deleted_at != nil { - fields = append(fields, chargeusagebased.FieldIntentDeletedAt) - } - if m.discounts != nil { - fields = append(fields, chargeusagebased.FieldDiscounts) - } - if m.feature_key != nil { - fields = append(fields, chargeusagebased.FieldFeatureKey) - } - if m.feature != nil { - fields = append(fields, chargeusagebased.FieldFeatureID) - } - if m.rating_engine != nil { - fields = append(fields, chargeusagebased.FieldRatingEngine) - } - if m.price != nil { - fields = append(fields, chargeusagebased.FieldPrice) - } - if m.unit_config != nil { - fields = append(fields, chargeusagebased.FieldUnitConfig) - } - if m.current_run != nil { - fields = append(fields, chargeusagebased.FieldCurrentRealizationRunID) - } - if m.status_detailed != nil { - fields = append(fields, chargeusagebased.FieldStatusDetailed) + fields = append(fields, chargeusagebasedcostbasis.FieldDeletedAt) } return fields } @@ -61057,82 +65656,32 @@ func (m *ChargeUsageBasedMutation) Fields() []string { // 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 *ChargeUsageBasedMutation) Field(name string) (ent.Value, bool) { - switch name { - case chargeusagebased.FieldCustomerID: - return m.CustomerID() - case chargeusagebased.FieldServicePeriodFrom: - return m.ServicePeriodFrom() - case chargeusagebased.FieldServicePeriodTo: - return m.ServicePeriodTo() - case chargeusagebased.FieldBillingPeriodFrom: - return m.BillingPeriodFrom() - case chargeusagebased.FieldBillingPeriodTo: - return m.BillingPeriodTo() - case chargeusagebased.FieldFullServicePeriodFrom: - return m.FullServicePeriodFrom() - case chargeusagebased.FieldFullServicePeriodTo: - return m.FullServicePeriodTo() - case chargeusagebased.FieldStatus: - return m.Status() - case chargeusagebased.FieldUniqueReferenceID: - return m.UniqueReferenceID() - case chargeusagebased.FieldFiatCurrencyCode: - return m.FiatCurrencyCode() - case chargeusagebased.FieldCustomCurrencyID: - return m.CustomCurrencyID() - case chargeusagebased.FieldManagedBy: - return m.ManagedBy() - case chargeusagebased.FieldSubscriptionID: - return m.SubscriptionID() - case chargeusagebased.FieldSubscriptionPhaseID: - return m.SubscriptionPhaseID() - case chargeusagebased.FieldSubscriptionItemID: - return m.SubscriptionItemID() - case chargeusagebased.FieldAdvanceAfter: - return m.AdvanceAfter() - case chargeusagebased.FieldTaxCodeID: - return m.TaxCodeID() - case chargeusagebased.FieldTaxBehavior: - return m.TaxBehavior() - case chargeusagebased.FieldAnnotations: - return m.Annotations() - case chargeusagebased.FieldNamespace: +func (m *ChargeUsageBasedCostBasisMutation) Field(name string) (ent.Value, bool) { + switch name { + case chargeusagebasedcostbasis.FieldMode: + return m.Mode() + case chargeusagebasedcostbasis.FieldFiatCurrency: + return m.FiatCurrency() + case chargeusagebasedcostbasis.FieldCurrencyCostBasisID: + return m.CurrencyCostBasisID() + case chargeusagebasedcostbasis.FieldResolvedCostBasisID: + return m.ResolvedCostBasisID() + case chargeusagebasedcostbasis.FieldCurrencyID: + return m.CurrencyID() + case chargeusagebasedcostbasis.FieldManualRate: + return m.ManualRate() + case chargeusagebasedcostbasis.FieldResolvedCostBasis: + return m.ResolvedCostBasis() + case chargeusagebasedcostbasis.FieldResolvedAt: + return m.ResolvedAt() + case chargeusagebasedcostbasis.FieldNamespace: return m.Namespace() - case chargeusagebased.FieldMetadata: - return m.Metadata() - case chargeusagebased.FieldCreatedAt: + case chargeusagebasedcostbasis.FieldCreatedAt: return m.CreatedAt() - case chargeusagebased.FieldUpdatedAt: + case chargeusagebasedcostbasis.FieldUpdatedAt: return m.UpdatedAt() - case chargeusagebased.FieldDeletedAt: + case chargeusagebasedcostbasis.FieldDeletedAt: return m.DeletedAt() - case chargeusagebased.FieldName: - return m.Name() - case chargeusagebased.FieldDescription: - return m.Description() - case chargeusagebased.FieldInvoiceAt: - return m.InvoiceAt() - case chargeusagebased.FieldSettlementMode: - return m.SettlementMode() - case chargeusagebased.FieldIntentDeletedAt: - return m.IntentDeletedAt() - case chargeusagebased.FieldDiscounts: - return m.Discounts() - case chargeusagebased.FieldFeatureKey: - return m.FeatureKey() - case chargeusagebased.FieldFeatureID: - return m.FeatureID() - case chargeusagebased.FieldRatingEngine: - return m.RatingEngine() - case chargeusagebased.FieldPrice: - return m.Price() - case chargeusagebased.FieldUnitConfig: - return m.UnitConfig() - case chargeusagebased.FieldCurrentRealizationRunID: - return m.CurrentRealizationRunID() - case chargeusagebased.FieldStatusDetailed: - return m.StatusDetailed() } return nil, false } @@ -61140,708 +65689,281 @@ func (m *ChargeUsageBasedMutation) Field(name string) (ent.Value, bool) { // 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 *ChargeUsageBasedMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case chargeusagebased.FieldCustomerID: - return m.OldCustomerID(ctx) - case chargeusagebased.FieldServicePeriodFrom: - return m.OldServicePeriodFrom(ctx) - case chargeusagebased.FieldServicePeriodTo: - return m.OldServicePeriodTo(ctx) - case chargeusagebased.FieldBillingPeriodFrom: - return m.OldBillingPeriodFrom(ctx) - case chargeusagebased.FieldBillingPeriodTo: - return m.OldBillingPeriodTo(ctx) - case chargeusagebased.FieldFullServicePeriodFrom: - return m.OldFullServicePeriodFrom(ctx) - case chargeusagebased.FieldFullServicePeriodTo: - return m.OldFullServicePeriodTo(ctx) - case chargeusagebased.FieldStatus: - return m.OldStatus(ctx) - case chargeusagebased.FieldUniqueReferenceID: - return m.OldUniqueReferenceID(ctx) - case chargeusagebased.FieldFiatCurrencyCode: - return m.OldFiatCurrencyCode(ctx) - case chargeusagebased.FieldCustomCurrencyID: - return m.OldCustomCurrencyID(ctx) - case chargeusagebased.FieldManagedBy: - return m.OldManagedBy(ctx) - case chargeusagebased.FieldSubscriptionID: - return m.OldSubscriptionID(ctx) - case chargeusagebased.FieldSubscriptionPhaseID: - return m.OldSubscriptionPhaseID(ctx) - case chargeusagebased.FieldSubscriptionItemID: - return m.OldSubscriptionItemID(ctx) - case chargeusagebased.FieldAdvanceAfter: - return m.OldAdvanceAfter(ctx) - case chargeusagebased.FieldTaxCodeID: - return m.OldTaxCodeID(ctx) - case chargeusagebased.FieldTaxBehavior: - return m.OldTaxBehavior(ctx) - case chargeusagebased.FieldAnnotations: - return m.OldAnnotations(ctx) - case chargeusagebased.FieldNamespace: +func (m *ChargeUsageBasedCostBasisMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case chargeusagebasedcostbasis.FieldMode: + return m.OldMode(ctx) + case chargeusagebasedcostbasis.FieldFiatCurrency: + return m.OldFiatCurrency(ctx) + case chargeusagebasedcostbasis.FieldCurrencyCostBasisID: + return m.OldCurrencyCostBasisID(ctx) + case chargeusagebasedcostbasis.FieldResolvedCostBasisID: + return m.OldResolvedCostBasisID(ctx) + case chargeusagebasedcostbasis.FieldCurrencyID: + return m.OldCurrencyID(ctx) + case chargeusagebasedcostbasis.FieldManualRate: + return m.OldManualRate(ctx) + case chargeusagebasedcostbasis.FieldResolvedCostBasis: + return m.OldResolvedCostBasis(ctx) + case chargeusagebasedcostbasis.FieldResolvedAt: + return m.OldResolvedAt(ctx) + case chargeusagebasedcostbasis.FieldNamespace: return m.OldNamespace(ctx) - case chargeusagebased.FieldMetadata: - return m.OldMetadata(ctx) - case chargeusagebased.FieldCreatedAt: + case chargeusagebasedcostbasis.FieldCreatedAt: return m.OldCreatedAt(ctx) - case chargeusagebased.FieldUpdatedAt: + case chargeusagebasedcostbasis.FieldUpdatedAt: return m.OldUpdatedAt(ctx) - case chargeusagebased.FieldDeletedAt: + case chargeusagebasedcostbasis.FieldDeletedAt: return m.OldDeletedAt(ctx) - case chargeusagebased.FieldName: - return m.OldName(ctx) - case chargeusagebased.FieldDescription: - return m.OldDescription(ctx) - case chargeusagebased.FieldInvoiceAt: - return m.OldInvoiceAt(ctx) - case chargeusagebased.FieldSettlementMode: - return m.OldSettlementMode(ctx) - case chargeusagebased.FieldIntentDeletedAt: - return m.OldIntentDeletedAt(ctx) - case chargeusagebased.FieldDiscounts: - return m.OldDiscounts(ctx) - case chargeusagebased.FieldFeatureKey: - return m.OldFeatureKey(ctx) - case chargeusagebased.FieldFeatureID: - return m.OldFeatureID(ctx) - case chargeusagebased.FieldRatingEngine: - return m.OldRatingEngine(ctx) - case chargeusagebased.FieldPrice: - return m.OldPrice(ctx) - case chargeusagebased.FieldUnitConfig: - return m.OldUnitConfig(ctx) - case chargeusagebased.FieldCurrentRealizationRunID: - return m.OldCurrentRealizationRunID(ctx) - case chargeusagebased.FieldStatusDetailed: - return m.OldStatusDetailed(ctx) } - return nil, fmt.Errorf("unknown ChargeUsageBased field %s", name) + return nil, fmt.Errorf("unknown ChargeUsageBasedCostBasis 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 *ChargeUsageBasedMutation) SetField(name string, value ent.Value) error { - switch name { - case chargeusagebased.FieldCustomerID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCustomerID(v) - return nil - case chargeusagebased.FieldServicePeriodFrom: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetServicePeriodFrom(v) - return nil - case chargeusagebased.FieldServicePeriodTo: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetServicePeriodTo(v) - return nil - case chargeusagebased.FieldBillingPeriodFrom: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetBillingPeriodFrom(v) - return nil - case chargeusagebased.FieldBillingPeriodTo: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetBillingPeriodTo(v) - return nil - case chargeusagebased.FieldFullServicePeriodFrom: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetFullServicePeriodFrom(v) - return nil - case chargeusagebased.FieldFullServicePeriodTo: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetFullServicePeriodTo(v) - return nil - case chargeusagebased.FieldStatus: - v, ok := value.(meta.ChargeStatus) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetStatus(v) - return nil - case chargeusagebased.FieldUniqueReferenceID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUniqueReferenceID(v) - return nil - case chargeusagebased.FieldFiatCurrencyCode: - v, ok := value.(currencyx.Code) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetFiatCurrencyCode(v) - return nil - case chargeusagebased.FieldCustomCurrencyID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCustomCurrencyID(v) - return nil - case chargeusagebased.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 chargeusagebased.FieldSubscriptionID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetSubscriptionID(v) - return nil - case chargeusagebased.FieldSubscriptionPhaseID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetSubscriptionPhaseID(v) - return nil - case chargeusagebased.FieldSubscriptionItemID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetSubscriptionItemID(v) - return nil - case chargeusagebased.FieldAdvanceAfter: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetAdvanceAfter(v) - return nil - case chargeusagebased.FieldTaxCodeID: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetTaxCodeID(v) - return nil - case chargeusagebased.FieldTaxBehavior: - v, ok := value.(productcatalog.TaxBehavior) +func (m *ChargeUsageBasedCostBasisMutation) SetField(name string, value ent.Value) error { + switch name { + case chargeusagebasedcostbasis.FieldMode: + v, ok := value.(costbasis.Mode) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetTaxBehavior(v) + m.SetMode(v) return nil - case chargeusagebased.FieldAnnotations: - v, ok := value.(models.Annotations) + case chargeusagebasedcostbasis.FieldFiatCurrency: + v, ok := value.(currencyx.FiatCode) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetAnnotations(v) + m.SetFiatCurrency(v) return nil - case chargeusagebased.FieldNamespace: + case chargeusagebasedcostbasis.FieldCurrencyCostBasisID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetNamespace(v) - return nil - case chargeusagebased.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 chargeusagebased.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 chargeusagebased.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 chargeusagebased.FieldDeletedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDeletedAt(v) + m.SetCurrencyCostBasisID(v) return nil - case chargeusagebased.FieldName: + case chargeusagebasedcostbasis.FieldResolvedCostBasisID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetName(v) + m.SetResolvedCostBasisID(v) return nil - case chargeusagebased.FieldDescription: + case chargeusagebasedcostbasis.FieldCurrencyID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDescription(v) + m.SetCurrencyID(v) return nil - case chargeusagebased.FieldInvoiceAt: - v, ok := value.(time.Time) + case chargeusagebasedcostbasis.FieldManualRate: + v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetInvoiceAt(v) + m.SetManualRate(v) return nil - case chargeusagebased.FieldSettlementMode: - v, ok := value.(productcatalog.SettlementMode) + case chargeusagebasedcostbasis.FieldResolvedCostBasis: + v, ok := value.(alpacadecimal.Decimal) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetSettlementMode(v) + m.SetResolvedCostBasis(v) return nil - case chargeusagebased.FieldIntentDeletedAt: + case chargeusagebasedcostbasis.FieldResolvedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetIntentDeletedAt(v) - return nil - case chargeusagebased.FieldDiscounts: - v, ok := value.(*billing.Discounts) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDiscounts(v) - return nil - case chargeusagebased.FieldFeatureKey: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetFeatureKey(v) + m.SetResolvedAt(v) return nil - case chargeusagebased.FieldFeatureID: + case chargeusagebasedcostbasis.FieldNamespace: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetFeatureID(v) - return nil - case chargeusagebased.FieldRatingEngine: - v, ok := value.(usagebased.RatingEngine) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetRatingEngine(v) - return nil - case chargeusagebased.FieldPrice: - v, ok := value.(*productcatalog.Price) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetPrice(v) + m.SetNamespace(v) return nil - case chargeusagebased.FieldUnitConfig: - v, ok := value.(*productcatalog.UnitConfig) + case chargeusagebasedcostbasis.FieldCreatedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetUnitConfig(v) + m.SetCreatedAt(v) return nil - case chargeusagebased.FieldCurrentRealizationRunID: - v, ok := value.(string) + case chargeusagebasedcostbasis.FieldUpdatedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCurrentRealizationRunID(v) + m.SetUpdatedAt(v) return nil - case chargeusagebased.FieldStatusDetailed: - v, ok := value.(usagebased.Status) + case chargeusagebasedcostbasis.FieldDeletedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetStatusDetailed(v) + m.SetDeletedAt(v) return nil } - return fmt.Errorf("unknown ChargeUsageBased field %s", name) + return fmt.Errorf("unknown ChargeUsageBasedCostBasis field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *ChargeUsageBasedMutation) AddedFields() []string { +func (m *ChargeUsageBasedCostBasisMutation) 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 *ChargeUsageBasedMutation) AddedField(name string) (ent.Value, bool) { +func (m *ChargeUsageBasedCostBasisMutation) 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 *ChargeUsageBasedMutation) AddField(name string, value ent.Value) error { +func (m *ChargeUsageBasedCostBasisMutation) AddField(name string, value ent.Value) error { switch name { } - return fmt.Errorf("unknown ChargeUsageBased numeric field %s", name) + return fmt.Errorf("unknown ChargeUsageBasedCostBasis numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *ChargeUsageBasedMutation) ClearedFields() []string { +func (m *ChargeUsageBasedCostBasisMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(chargeusagebased.FieldUniqueReferenceID) { - fields = append(fields, chargeusagebased.FieldUniqueReferenceID) - } - if m.FieldCleared(chargeusagebased.FieldFiatCurrencyCode) { - fields = append(fields, chargeusagebased.FieldFiatCurrencyCode) - } - if m.FieldCleared(chargeusagebased.FieldCustomCurrencyID) { - fields = append(fields, chargeusagebased.FieldCustomCurrencyID) - } - if m.FieldCleared(chargeusagebased.FieldSubscriptionID) { - fields = append(fields, chargeusagebased.FieldSubscriptionID) - } - if m.FieldCleared(chargeusagebased.FieldSubscriptionPhaseID) { - fields = append(fields, chargeusagebased.FieldSubscriptionPhaseID) - } - if m.FieldCleared(chargeusagebased.FieldSubscriptionItemID) { - fields = append(fields, chargeusagebased.FieldSubscriptionItemID) - } - if m.FieldCleared(chargeusagebased.FieldAdvanceAfter) { - fields = append(fields, chargeusagebased.FieldAdvanceAfter) - } - if m.FieldCleared(chargeusagebased.FieldTaxBehavior) { - fields = append(fields, chargeusagebased.FieldTaxBehavior) - } - if m.FieldCleared(chargeusagebased.FieldAnnotations) { - fields = append(fields, chargeusagebased.FieldAnnotations) + if m.FieldCleared(chargeusagebasedcostbasis.FieldCurrencyCostBasisID) { + fields = append(fields, chargeusagebasedcostbasis.FieldCurrencyCostBasisID) } - if m.FieldCleared(chargeusagebased.FieldMetadata) { - fields = append(fields, chargeusagebased.FieldMetadata) - } - if m.FieldCleared(chargeusagebased.FieldDeletedAt) { - fields = append(fields, chargeusagebased.FieldDeletedAt) - } - if m.FieldCleared(chargeusagebased.FieldDescription) { - fields = append(fields, chargeusagebased.FieldDescription) + if m.FieldCleared(chargeusagebasedcostbasis.FieldResolvedCostBasisID) { + fields = append(fields, chargeusagebasedcostbasis.FieldResolvedCostBasisID) } - if m.FieldCleared(chargeusagebased.FieldIntentDeletedAt) { - fields = append(fields, chargeusagebased.FieldIntentDeletedAt) + if m.FieldCleared(chargeusagebasedcostbasis.FieldManualRate) { + fields = append(fields, chargeusagebasedcostbasis.FieldManualRate) } - if m.FieldCleared(chargeusagebased.FieldDiscounts) { - fields = append(fields, chargeusagebased.FieldDiscounts) + if m.FieldCleared(chargeusagebasedcostbasis.FieldResolvedCostBasis) { + fields = append(fields, chargeusagebasedcostbasis.FieldResolvedCostBasis) } - if m.FieldCleared(chargeusagebased.FieldUnitConfig) { - fields = append(fields, chargeusagebased.FieldUnitConfig) + if m.FieldCleared(chargeusagebasedcostbasis.FieldResolvedAt) { + fields = append(fields, chargeusagebasedcostbasis.FieldResolvedAt) } - if m.FieldCleared(chargeusagebased.FieldCurrentRealizationRunID) { - fields = append(fields, chargeusagebased.FieldCurrentRealizationRunID) + if m.FieldCleared(chargeusagebasedcostbasis.FieldDeletedAt) { + fields = append(fields, chargeusagebasedcostbasis.FieldDeletedAt) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *ChargeUsageBasedMutation) FieldCleared(name string) bool { +func (m *ChargeUsageBasedCostBasisMutation) 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 *ChargeUsageBasedMutation) ClearField(name string) error { +func (m *ChargeUsageBasedCostBasisMutation) ClearField(name string) error { switch name { - case chargeusagebased.FieldUniqueReferenceID: - m.ClearUniqueReferenceID() - return nil - case chargeusagebased.FieldFiatCurrencyCode: - m.ClearFiatCurrencyCode() - return nil - case chargeusagebased.FieldCustomCurrencyID: - m.ClearCustomCurrencyID() - return nil - case chargeusagebased.FieldSubscriptionID: - m.ClearSubscriptionID() - return nil - case chargeusagebased.FieldSubscriptionPhaseID: - m.ClearSubscriptionPhaseID() + case chargeusagebasedcostbasis.FieldCurrencyCostBasisID: + m.ClearCurrencyCostBasisID() return nil - case chargeusagebased.FieldSubscriptionItemID: - m.ClearSubscriptionItemID() - return nil - case chargeusagebased.FieldAdvanceAfter: - m.ClearAdvanceAfter() + case chargeusagebasedcostbasis.FieldResolvedCostBasisID: + m.ClearResolvedCostBasisID() return nil - case chargeusagebased.FieldTaxBehavior: - m.ClearTaxBehavior() + case chargeusagebasedcostbasis.FieldManualRate: + m.ClearManualRate() return nil - case chargeusagebased.FieldAnnotations: - m.ClearAnnotations() + case chargeusagebasedcostbasis.FieldResolvedCostBasis: + m.ClearResolvedCostBasis() return nil - case chargeusagebased.FieldMetadata: - m.ClearMetadata() + case chargeusagebasedcostbasis.FieldResolvedAt: + m.ClearResolvedAt() return nil - case chargeusagebased.FieldDeletedAt: + case chargeusagebasedcostbasis.FieldDeletedAt: m.ClearDeletedAt() return nil - case chargeusagebased.FieldDescription: - m.ClearDescription() - return nil - case chargeusagebased.FieldIntentDeletedAt: - m.ClearIntentDeletedAt() - return nil - case chargeusagebased.FieldDiscounts: - m.ClearDiscounts() - return nil - case chargeusagebased.FieldUnitConfig: - m.ClearUnitConfig() - return nil - case chargeusagebased.FieldCurrentRealizationRunID: - m.ClearCurrentRealizationRunID() - return nil } - return fmt.Errorf("unknown ChargeUsageBased nullable field %s", name) + return fmt.Errorf("unknown ChargeUsageBasedCostBasis 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 *ChargeUsageBasedMutation) ResetField(name string) error { +func (m *ChargeUsageBasedCostBasisMutation) ResetField(name string) error { switch name { - case chargeusagebased.FieldCustomerID: - m.ResetCustomerID() - return nil - case chargeusagebased.FieldServicePeriodFrom: - m.ResetServicePeriodFrom() - return nil - case chargeusagebased.FieldServicePeriodTo: - m.ResetServicePeriodTo() - return nil - case chargeusagebased.FieldBillingPeriodFrom: - m.ResetBillingPeriodFrom() - return nil - case chargeusagebased.FieldBillingPeriodTo: - m.ResetBillingPeriodTo() - return nil - case chargeusagebased.FieldFullServicePeriodFrom: - m.ResetFullServicePeriodFrom() - return nil - case chargeusagebased.FieldFullServicePeriodTo: - m.ResetFullServicePeriodTo() - return nil - case chargeusagebased.FieldStatus: - m.ResetStatus() - return nil - case chargeusagebased.FieldUniqueReferenceID: - m.ResetUniqueReferenceID() - return nil - case chargeusagebased.FieldFiatCurrencyCode: - m.ResetFiatCurrencyCode() - return nil - case chargeusagebased.FieldCustomCurrencyID: - m.ResetCustomCurrencyID() - return nil - case chargeusagebased.FieldManagedBy: - m.ResetManagedBy() + case chargeusagebasedcostbasis.FieldMode: + m.ResetMode() return nil - case chargeusagebased.FieldSubscriptionID: - m.ResetSubscriptionID() + case chargeusagebasedcostbasis.FieldFiatCurrency: + m.ResetFiatCurrency() return nil - case chargeusagebased.FieldSubscriptionPhaseID: - m.ResetSubscriptionPhaseID() + case chargeusagebasedcostbasis.FieldCurrencyCostBasisID: + m.ResetCurrencyCostBasisID() return nil - case chargeusagebased.FieldSubscriptionItemID: - m.ResetSubscriptionItemID() + case chargeusagebasedcostbasis.FieldResolvedCostBasisID: + m.ResetResolvedCostBasisID() return nil - case chargeusagebased.FieldAdvanceAfter: - m.ResetAdvanceAfter() + case chargeusagebasedcostbasis.FieldCurrencyID: + m.ResetCurrencyID() return nil - case chargeusagebased.FieldTaxCodeID: - m.ResetTaxCodeID() + case chargeusagebasedcostbasis.FieldManualRate: + m.ResetManualRate() return nil - case chargeusagebased.FieldTaxBehavior: - m.ResetTaxBehavior() + case chargeusagebasedcostbasis.FieldResolvedCostBasis: + m.ResetResolvedCostBasis() return nil - case chargeusagebased.FieldAnnotations: - m.ResetAnnotations() + case chargeusagebasedcostbasis.FieldResolvedAt: + m.ResetResolvedAt() return nil - case chargeusagebased.FieldNamespace: + case chargeusagebasedcostbasis.FieldNamespace: m.ResetNamespace() return nil - case chargeusagebased.FieldMetadata: - m.ResetMetadata() - return nil - case chargeusagebased.FieldCreatedAt: + case chargeusagebasedcostbasis.FieldCreatedAt: m.ResetCreatedAt() return nil - case chargeusagebased.FieldUpdatedAt: + case chargeusagebasedcostbasis.FieldUpdatedAt: m.ResetUpdatedAt() return nil - case chargeusagebased.FieldDeletedAt: + case chargeusagebasedcostbasis.FieldDeletedAt: m.ResetDeletedAt() return nil - case chargeusagebased.FieldName: - m.ResetName() - return nil - case chargeusagebased.FieldDescription: - m.ResetDescription() - return nil - case chargeusagebased.FieldInvoiceAt: - m.ResetInvoiceAt() - return nil - case chargeusagebased.FieldSettlementMode: - m.ResetSettlementMode() - return nil - case chargeusagebased.FieldIntentDeletedAt: - m.ResetIntentDeletedAt() - return nil - case chargeusagebased.FieldDiscounts: - m.ResetDiscounts() - return nil - case chargeusagebased.FieldFeatureKey: - m.ResetFeatureKey() - return nil - case chargeusagebased.FieldFeatureID: - m.ResetFeatureID() - return nil - case chargeusagebased.FieldRatingEngine: - m.ResetRatingEngine() - return nil - case chargeusagebased.FieldPrice: - m.ResetPrice() - return nil - case chargeusagebased.FieldUnitConfig: - m.ResetUnitConfig() - return nil - case chargeusagebased.FieldCurrentRealizationRunID: - m.ResetCurrentRealizationRunID() - return nil - case chargeusagebased.FieldStatusDetailed: - m.ResetStatusDetailed() - return nil } - return fmt.Errorf("unknown ChargeUsageBased field %s", name) + return fmt.Errorf("unknown ChargeUsageBasedCostBasis field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *ChargeUsageBasedMutation) AddedEdges() []string { - edges := make([]string, 0, 12) - if m.runs != nil { - edges = append(edges, chargeusagebased.EdgeRuns) - } - if m.detailed_lines != nil { - edges = append(edges, chargeusagebased.EdgeDetailedLines) - } - if m.current_run != nil { - edges = append(edges, chargeusagebased.EdgeCurrentRun) - } - if m.charge != nil { - edges = append(edges, chargeusagebased.EdgeCharge) - } - if m.intent_override != nil { - edges = append(edges, chargeusagebased.EdgeIntentOverride) - } - if m.subscription != nil { - edges = append(edges, chargeusagebased.EdgeSubscription) - } - if m.subscription_phase != nil { - edges = append(edges, chargeusagebased.EdgeSubscriptionPhase) - } - if m.subscription_item != nil { - edges = append(edges, chargeusagebased.EdgeSubscriptionItem) - } - if m.customer != nil { - edges = append(edges, chargeusagebased.EdgeCustomer) - } - if m.feature != nil { - edges = append(edges, chargeusagebased.EdgeFeature) +func (m *ChargeUsageBasedCostBasisMutation) AddedEdges() []string { + edges := make([]string, 0, 3) + if m.currency_cost_basis != nil { + edges = append(edges, chargeusagebasedcostbasis.EdgeCurrencyCostBasis) } - if m.tax_code != nil { - edges = append(edges, chargeusagebased.EdgeTaxCode) + if m.resolved_currency_cost_basis != nil { + edges = append(edges, chargeusagebasedcostbasis.EdgeResolvedCurrencyCostBasis) } if m.custom_currency != nil { - edges = append(edges, chargeusagebased.EdgeCustomCurrency) + edges = append(edges, chargeusagebasedcostbasis.EdgeCustomCurrency) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *ChargeUsageBasedMutation) AddedIDs(name string) []ent.Value { +func (m *ChargeUsageBasedCostBasisMutation) AddedIDs(name string) []ent.Value { switch name { - case chargeusagebased.EdgeRuns: - ids := make([]ent.Value, 0, len(m.runs)) - for id := range m.runs { - ids = append(ids, id) - } - return ids - case chargeusagebased.EdgeDetailedLines: - ids := make([]ent.Value, 0, len(m.detailed_lines)) - for id := range m.detailed_lines { - ids = append(ids, id) - } - return ids - case chargeusagebased.EdgeCurrentRun: - if id := m.current_run; id != nil { - return []ent.Value{*id} - } - case chargeusagebased.EdgeCharge: - if id := m.charge; id != nil { - return []ent.Value{*id} - } - case chargeusagebased.EdgeIntentOverride: - if id := m.intent_override; id != nil { - return []ent.Value{*id} - } - case chargeusagebased.EdgeSubscription: - if id := m.subscription; id != nil { - return []ent.Value{*id} - } - case chargeusagebased.EdgeSubscriptionPhase: - if id := m.subscription_phase; id != nil { + case chargeusagebasedcostbasis.EdgeCurrencyCostBasis: + if id := m.currency_cost_basis; id != nil { return []ent.Value{*id} } - case chargeusagebased.EdgeSubscriptionItem: - if id := m.subscription_item; id != nil { - return []ent.Value{*id} - } - case chargeusagebased.EdgeCustomer: - if id := m.customer; id != nil { - return []ent.Value{*id} - } - case chargeusagebased.EdgeFeature: - if id := m.feature; id != nil { - return []ent.Value{*id} - } - case chargeusagebased.EdgeTaxCode: - if id := m.tax_code; id != nil { + case chargeusagebasedcostbasis.EdgeResolvedCurrencyCostBasis: + if id := m.resolved_currency_cost_basis; id != nil { return []ent.Value{*id} } - case chargeusagebased.EdgeCustomCurrency: + case chargeusagebasedcostbasis.EdgeCustomCurrency: if id := m.custom_currency; id != nil { return []ent.Value{*id} } @@ -61850,106 +65972,41 @@ func (m *ChargeUsageBasedMutation) AddedIDs(name string) []ent.Value { } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *ChargeUsageBasedMutation) RemovedEdges() []string { - edges := make([]string, 0, 12) - if m.removedruns != nil { - edges = append(edges, chargeusagebased.EdgeRuns) - } - if m.removeddetailed_lines != nil { - edges = append(edges, chargeusagebased.EdgeDetailedLines) - } +func (m *ChargeUsageBasedCostBasisMutation) RemovedEdges() []string { + edges := make([]string, 0, 3) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *ChargeUsageBasedMutation) RemovedIDs(name string) []ent.Value { - switch name { - case chargeusagebased.EdgeRuns: - ids := make([]ent.Value, 0, len(m.removedruns)) - for id := range m.removedruns { - ids = append(ids, id) - } - return ids - case chargeusagebased.EdgeDetailedLines: - ids := make([]ent.Value, 0, len(m.removeddetailed_lines)) - for id := range m.removeddetailed_lines { - ids = append(ids, id) - } - return ids - } +func (m *ChargeUsageBasedCostBasisMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ChargeUsageBasedMutation) ClearedEdges() []string { - edges := make([]string, 0, 12) - if m.clearedruns { - edges = append(edges, chargeusagebased.EdgeRuns) - } - if m.cleareddetailed_lines { - edges = append(edges, chargeusagebased.EdgeDetailedLines) - } - if m.clearedcurrent_run { - edges = append(edges, chargeusagebased.EdgeCurrentRun) - } - if m.clearedcharge { - edges = append(edges, chargeusagebased.EdgeCharge) - } - if m.clearedintent_override { - edges = append(edges, chargeusagebased.EdgeIntentOverride) - } - if m.clearedsubscription { - edges = append(edges, chargeusagebased.EdgeSubscription) - } - if m.clearedsubscription_phase { - edges = append(edges, chargeusagebased.EdgeSubscriptionPhase) - } - if m.clearedsubscription_item { - edges = append(edges, chargeusagebased.EdgeSubscriptionItem) - } - if m.clearedcustomer { - edges = append(edges, chargeusagebased.EdgeCustomer) - } - if m.clearedfeature { - edges = append(edges, chargeusagebased.EdgeFeature) +func (m *ChargeUsageBasedCostBasisMutation) ClearedEdges() []string { + edges := make([]string, 0, 3) + if m.clearedcurrency_cost_basis { + edges = append(edges, chargeusagebasedcostbasis.EdgeCurrencyCostBasis) } - if m.clearedtax_code { - edges = append(edges, chargeusagebased.EdgeTaxCode) + if m.clearedresolved_currency_cost_basis { + edges = append(edges, chargeusagebasedcostbasis.EdgeResolvedCurrencyCostBasis) } if m.clearedcustom_currency { - edges = append(edges, chargeusagebased.EdgeCustomCurrency) + edges = append(edges, chargeusagebasedcostbasis.EdgeCustomCurrency) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *ChargeUsageBasedMutation) EdgeCleared(name string) bool { +func (m *ChargeUsageBasedCostBasisMutation) EdgeCleared(name string) bool { switch name { - case chargeusagebased.EdgeRuns: - return m.clearedruns - case chargeusagebased.EdgeDetailedLines: - return m.cleareddetailed_lines - case chargeusagebased.EdgeCurrentRun: - return m.clearedcurrent_run - case chargeusagebased.EdgeCharge: - return m.clearedcharge - case chargeusagebased.EdgeIntentOverride: - return m.clearedintent_override - case chargeusagebased.EdgeSubscription: - return m.clearedsubscription - case chargeusagebased.EdgeSubscriptionPhase: - return m.clearedsubscription_phase - case chargeusagebased.EdgeSubscriptionItem: - return m.clearedsubscription_item - case chargeusagebased.EdgeCustomer: - return m.clearedcustomer - case chargeusagebased.EdgeFeature: - return m.clearedfeature - case chargeusagebased.EdgeTaxCode: - return m.clearedtax_code - case chargeusagebased.EdgeCustomCurrency: + case chargeusagebasedcostbasis.EdgeCurrencyCostBasis: + return m.clearedcurrency_cost_basis + case chargeusagebasedcostbasis.EdgeResolvedCurrencyCostBasis: + return m.clearedresolved_currency_cost_basis + case chargeusagebasedcostbasis.EdgeCustomCurrency: return m.clearedcustom_currency } return false @@ -61957,84 +66014,36 @@ func (m *ChargeUsageBasedMutation) EdgeCleared(name string) bool { // 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 *ChargeUsageBasedMutation) ClearEdge(name string) error { +func (m *ChargeUsageBasedCostBasisMutation) ClearEdge(name string) error { switch name { - case chargeusagebased.EdgeCurrentRun: - m.ClearCurrentRun() - return nil - case chargeusagebased.EdgeCharge: - m.ClearCharge() - return nil - case chargeusagebased.EdgeIntentOverride: - m.ClearIntentOverride() - return nil - case chargeusagebased.EdgeSubscription: - m.ClearSubscription() - return nil - case chargeusagebased.EdgeSubscriptionPhase: - m.ClearSubscriptionPhase() - return nil - case chargeusagebased.EdgeSubscriptionItem: - m.ClearSubscriptionItem() - return nil - case chargeusagebased.EdgeCustomer: - m.ClearCustomer() - return nil - case chargeusagebased.EdgeFeature: - m.ClearFeature() + case chargeusagebasedcostbasis.EdgeCurrencyCostBasis: + m.ClearCurrencyCostBasis() return nil - case chargeusagebased.EdgeTaxCode: - m.ClearTaxCode() + case chargeusagebasedcostbasis.EdgeResolvedCurrencyCostBasis: + m.ClearResolvedCurrencyCostBasis() return nil - case chargeusagebased.EdgeCustomCurrency: + case chargeusagebasedcostbasis.EdgeCustomCurrency: m.ClearCustomCurrency() return nil } - return fmt.Errorf("unknown ChargeUsageBased unique edge %s", name) + return fmt.Errorf("unknown ChargeUsageBasedCostBasis 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 *ChargeUsageBasedMutation) ResetEdge(name string) error { +func (m *ChargeUsageBasedCostBasisMutation) ResetEdge(name string) error { switch name { - case chargeusagebased.EdgeRuns: - m.ResetRuns() - return nil - case chargeusagebased.EdgeDetailedLines: - m.ResetDetailedLines() - return nil - case chargeusagebased.EdgeCurrentRun: - m.ResetCurrentRun() - return nil - case chargeusagebased.EdgeCharge: - m.ResetCharge() - return nil - case chargeusagebased.EdgeIntentOverride: - m.ResetIntentOverride() - return nil - case chargeusagebased.EdgeSubscription: - m.ResetSubscription() + case chargeusagebasedcostbasis.EdgeCurrencyCostBasis: + m.ResetCurrencyCostBasis() return nil - case chargeusagebased.EdgeSubscriptionPhase: - m.ResetSubscriptionPhase() - return nil - case chargeusagebased.EdgeSubscriptionItem: - m.ResetSubscriptionItem() - return nil - case chargeusagebased.EdgeCustomer: - m.ResetCustomer() + case chargeusagebasedcostbasis.EdgeResolvedCurrencyCostBasis: + m.ResetResolvedCurrencyCostBasis() return nil - case chargeusagebased.EdgeFeature: - m.ResetFeature() - return nil - case chargeusagebased.EdgeTaxCode: - m.ResetTaxCode() - return nil - case chargeusagebased.EdgeCustomCurrency: + case chargeusagebasedcostbasis.EdgeCustomCurrency: m.ResetCustomCurrency() return nil } - return fmt.Errorf("unknown ChargeUsageBased edge %s", name) + return fmt.Errorf("unknown ChargeUsageBasedCostBasis edge %s", name) } // ChargeUsageBasedOverrideMutation represents an operation that mutates the ChargeUsageBasedOverride nodes in the graph. diff --git a/openmeter/ent/db/paginate.go b/openmeter/ent/db/paginate.go index 3ad0f3fd89..58ddb85bb3 100644 --- a/openmeter/ent/db/paginate.go +++ b/openmeter/ent/db/paginate.go @@ -1633,6 +1633,64 @@ func (_m *ChargeCreditPurchaseQuery) Paginate(ctx context.Context, page paginati // type check var _ pagination.Paginator[*ChargeCreditPurchase] = (*ChargeCreditPurchaseQuery)(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 *ChargeCreditPurchaseCostBasisQuery) Paginate(ctx context.Context, page pagination.Page) (pagination.Result[*ChargeCreditPurchaseCostBasis], 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[*ChargeCreditPurchaseCostBasis]{ + 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([]*ChargeCreditPurchaseCostBasis, 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[*ChargeCreditPurchaseCostBasis] = (*ChargeCreditPurchaseCostBasisQuery)(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 *ChargeCreditPurchaseCreditGrantQuery) Paginate(ctx context.Context, page pagination.Page) (pagination.Result[*ChargeCreditPurchaseCreditGrant], error) { @@ -1865,6 +1923,64 @@ func (_m *ChargeFlatFeeQuery) Paginate(ctx context.Context, page pagination.Page // type check var _ pagination.Paginator[*ChargeFlatFee] = (*ChargeFlatFeeQuery)(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 *ChargeFlatFeeCostBasisQuery) Paginate(ctx context.Context, page pagination.Page) (pagination.Result[*ChargeFlatFeeCostBasis], 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[*ChargeFlatFeeCostBasis]{ + 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([]*ChargeFlatFeeCostBasis, 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[*ChargeFlatFeeCostBasis] = (*ChargeFlatFeeCostBasisQuery)(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 *ChargeFlatFeeOverrideQuery) Paginate(ctx context.Context, page pagination.Page) (pagination.Result[*ChargeFlatFeeOverride], error) { @@ -2271,6 +2387,64 @@ func (_m *ChargeUsageBasedQuery) Paginate(ctx context.Context, page pagination.P // type check var _ pagination.Paginator[*ChargeUsageBased] = (*ChargeUsageBasedQuery)(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 *ChargeUsageBasedCostBasisQuery) Paginate(ctx context.Context, page pagination.Page) (pagination.Result[*ChargeUsageBasedCostBasis], 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[*ChargeUsageBasedCostBasis]{ + 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([]*ChargeUsageBasedCostBasis, 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[*ChargeUsageBasedCostBasis] = (*ChargeUsageBasedCostBasisQuery)(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 *ChargeUsageBasedOverrideQuery) Paginate(ctx context.Context, page pagination.Page) (pagination.Result[*ChargeUsageBasedOverride], error) { diff --git a/openmeter/ent/db/predicate/predicate.go b/openmeter/ent/db/predicate/predicate.go index 0b3d65d810..f2bdf30a4b 100644 --- a/openmeter/ent/db/predicate/predicate.go +++ b/openmeter/ent/db/predicate/predicate.go @@ -200,6 +200,9 @@ func ChargeCreditPurchaseOrErr(p ChargeCreditPurchase, err error) ChargeCreditPu } } +// ChargeCreditPurchaseCostBasis is the predicate function for chargecreditpurchasecostbasis builders. +type ChargeCreditPurchaseCostBasis func(*sql.Selector) + // ChargeCreditPurchaseCreditGrant is the predicate function for chargecreditpurchasecreditgrant builders. type ChargeCreditPurchaseCreditGrant func(*sql.Selector) @@ -223,6 +226,9 @@ func ChargeFlatFeeOrErr(p ChargeFlatFee, err error) ChargeFlatFee { } } +// ChargeFlatFeeCostBasis is the predicate function for chargeflatfeecostbasis builders. +type ChargeFlatFeeCostBasis func(*sql.Selector) + // ChargeFlatFeeOverride is the predicate function for chargeflatfeeoverride builders. type ChargeFlatFeeOverride func(*sql.Selector) @@ -266,6 +272,9 @@ func ChargeUsageBasedOrErr(p ChargeUsageBased, err error) ChargeUsageBased { } } +// ChargeUsageBasedCostBasis is the predicate function for chargeusagebasedcostbasis builders. +type ChargeUsageBasedCostBasis func(*sql.Selector) + // ChargeUsageBasedOverride is the predicate function for chargeusagebasedoverride builders. type ChargeUsageBasedOverride func(*sql.Selector) diff --git a/openmeter/ent/db/runtime.go b/openmeter/ent/db/runtime.go index d5eee985f0..b27a6a88de 100644 --- a/openmeter/ent/db/runtime.go +++ b/openmeter/ent/db/runtime.go @@ -37,10 +37,12 @@ import ( "github.com/openmeterio/openmeter/openmeter/ent/db/billingworkflowconfig" "github.com/openmeterio/openmeter/openmeter/ent/db/charge" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchase" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchasecreditgrant" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseexternalpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargecreditpurchaseinvoicedpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfee" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeecostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeerun" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeeruncreditallocations" @@ -49,6 +51,7 @@ import ( "github.com/openmeterio/openmeter/openmeter/ent/db/chargeflatfeerunpayment" "github.com/openmeterio/openmeter/openmeter/ent/db/chargessearchv1" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebased" + "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedcostbasis" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedoverride" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedruncreditallocations" "github.com/openmeterio/openmeter/openmeter/ent/db/chargeusagebasedrundetailedline" @@ -1021,6 +1024,37 @@ func init() { chargecreditpurchaseDescID := chargecreditpurchaseMixinFields0[19].Descriptor() // chargecreditpurchase.DefaultID holds the default value on creation for the id field. chargecreditpurchase.DefaultID = chargecreditpurchaseDescID.Default.(func() string) + chargecreditpurchasecostbasisMixin := schema.ChargeCreditPurchaseCostBasis{}.Mixin() + chargecreditpurchasecostbasisMixinFields0 := chargecreditpurchasecostbasisMixin[0].Fields() + _ = chargecreditpurchasecostbasisMixinFields0 + chargecreditpurchasecostbasisFields := schema.ChargeCreditPurchaseCostBasis{}.Fields() + _ = chargecreditpurchasecostbasisFields + // chargecreditpurchasecostbasisDescFiatCurrency is the schema descriptor for fiat_currency field. + chargecreditpurchasecostbasisDescFiatCurrency := chargecreditpurchasecostbasisMixinFields0[1].Descriptor() + // chargecreditpurchasecostbasis.FiatCurrencyValidator is a validator for the "fiat_currency" field. It is called by the builders before save. + chargecreditpurchasecostbasis.FiatCurrencyValidator = chargecreditpurchasecostbasisDescFiatCurrency.Validators[0].(func(string) error) + // chargecreditpurchasecostbasisDescCurrencyID is the schema descriptor for currency_id field. + chargecreditpurchasecostbasisDescCurrencyID := chargecreditpurchasecostbasisMixinFields0[4].Descriptor() + // chargecreditpurchasecostbasis.CurrencyIDValidator is a validator for the "currency_id" field. It is called by the builders before save. + chargecreditpurchasecostbasis.CurrencyIDValidator = chargecreditpurchasecostbasisDescCurrencyID.Validators[0].(func(string) error) + // chargecreditpurchasecostbasisDescNamespace is the schema descriptor for namespace field. + chargecreditpurchasecostbasisDescNamespace := chargecreditpurchasecostbasisMixinFields0[8].Descriptor() + // chargecreditpurchasecostbasis.NamespaceValidator is a validator for the "namespace" field. It is called by the builders before save. + chargecreditpurchasecostbasis.NamespaceValidator = chargecreditpurchasecostbasisDescNamespace.Validators[0].(func(string) error) + // chargecreditpurchasecostbasisDescCreatedAt is the schema descriptor for created_at field. + chargecreditpurchasecostbasisDescCreatedAt := chargecreditpurchasecostbasisMixinFields0[10].Descriptor() + // chargecreditpurchasecostbasis.DefaultCreatedAt holds the default value on creation for the created_at field. + chargecreditpurchasecostbasis.DefaultCreatedAt = chargecreditpurchasecostbasisDescCreatedAt.Default.(func() time.Time) + // chargecreditpurchasecostbasisDescUpdatedAt is the schema descriptor for updated_at field. + chargecreditpurchasecostbasisDescUpdatedAt := chargecreditpurchasecostbasisMixinFields0[11].Descriptor() + // chargecreditpurchasecostbasis.DefaultUpdatedAt holds the default value on creation for the updated_at field. + chargecreditpurchasecostbasis.DefaultUpdatedAt = chargecreditpurchasecostbasisDescUpdatedAt.Default.(func() time.Time) + // chargecreditpurchasecostbasis.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + chargecreditpurchasecostbasis.UpdateDefaultUpdatedAt = chargecreditpurchasecostbasisDescUpdatedAt.UpdateDefault.(func() time.Time) + // chargecreditpurchasecostbasisDescID is the schema descriptor for id field. + chargecreditpurchasecostbasisDescID := chargecreditpurchasecostbasisMixinFields0[9].Descriptor() + // chargecreditpurchasecostbasis.DefaultID holds the default value on creation for the id field. + chargecreditpurchasecostbasis.DefaultID = chargecreditpurchasecostbasisDescID.Default.(func() string) chargecreditpurchasecreditgrantMixin := schema.ChargeCreditPurchaseCreditGrant{}.Mixin() chargecreditpurchasecreditgrantMixinFields0 := chargecreditpurchasecreditgrantMixin[0].Fields() _ = chargecreditpurchasecreditgrantMixinFields0 @@ -1164,6 +1198,37 @@ func init() { chargeflatfeeDescID := chargeflatfeeMixinFields0[19].Descriptor() // chargeflatfee.DefaultID holds the default value on creation for the id field. chargeflatfee.DefaultID = chargeflatfeeDescID.Default.(func() string) + chargeflatfeecostbasisMixin := schema.ChargeFlatFeeCostBasis{}.Mixin() + chargeflatfeecostbasisMixinFields0 := chargeflatfeecostbasisMixin[0].Fields() + _ = chargeflatfeecostbasisMixinFields0 + chargeflatfeecostbasisFields := schema.ChargeFlatFeeCostBasis{}.Fields() + _ = chargeflatfeecostbasisFields + // chargeflatfeecostbasisDescFiatCurrency is the schema descriptor for fiat_currency field. + chargeflatfeecostbasisDescFiatCurrency := chargeflatfeecostbasisMixinFields0[1].Descriptor() + // chargeflatfeecostbasis.FiatCurrencyValidator is a validator for the "fiat_currency" field. It is called by the builders before save. + chargeflatfeecostbasis.FiatCurrencyValidator = chargeflatfeecostbasisDescFiatCurrency.Validators[0].(func(string) error) + // chargeflatfeecostbasisDescCurrencyID is the schema descriptor for currency_id field. + chargeflatfeecostbasisDescCurrencyID := chargeflatfeecostbasisMixinFields0[4].Descriptor() + // chargeflatfeecostbasis.CurrencyIDValidator is a validator for the "currency_id" field. It is called by the builders before save. + chargeflatfeecostbasis.CurrencyIDValidator = chargeflatfeecostbasisDescCurrencyID.Validators[0].(func(string) error) + // chargeflatfeecostbasisDescNamespace is the schema descriptor for namespace field. + chargeflatfeecostbasisDescNamespace := chargeflatfeecostbasisMixinFields0[8].Descriptor() + // chargeflatfeecostbasis.NamespaceValidator is a validator for the "namespace" field. It is called by the builders before save. + chargeflatfeecostbasis.NamespaceValidator = chargeflatfeecostbasisDescNamespace.Validators[0].(func(string) error) + // chargeflatfeecostbasisDescCreatedAt is the schema descriptor for created_at field. + chargeflatfeecostbasisDescCreatedAt := chargeflatfeecostbasisMixinFields0[10].Descriptor() + // chargeflatfeecostbasis.DefaultCreatedAt holds the default value on creation for the created_at field. + chargeflatfeecostbasis.DefaultCreatedAt = chargeflatfeecostbasisDescCreatedAt.Default.(func() time.Time) + // chargeflatfeecostbasisDescUpdatedAt is the schema descriptor for updated_at field. + chargeflatfeecostbasisDescUpdatedAt := chargeflatfeecostbasisMixinFields0[11].Descriptor() + // chargeflatfeecostbasis.DefaultUpdatedAt holds the default value on creation for the updated_at field. + chargeflatfeecostbasis.DefaultUpdatedAt = chargeflatfeecostbasisDescUpdatedAt.Default.(func() time.Time) + // chargeflatfeecostbasis.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + chargeflatfeecostbasis.UpdateDefaultUpdatedAt = chargeflatfeecostbasisDescUpdatedAt.UpdateDefault.(func() time.Time) + // chargeflatfeecostbasisDescID is the schema descriptor for id field. + chargeflatfeecostbasisDescID := chargeflatfeecostbasisMixinFields0[9].Descriptor() + // chargeflatfeecostbasis.DefaultID holds the default value on creation for the id field. + chargeflatfeecostbasis.DefaultID = chargeflatfeecostbasisDescID.Default.(func() string) chargeflatfeeoverrideMixin := schema.ChargeFlatFeeOverride{}.Mixin() chargeflatfeeoverrideMixinFields0 := chargeflatfeeoverrideMixin[0].Fields() _ = chargeflatfeeoverrideMixinFields0 @@ -1418,6 +1483,37 @@ func init() { chargeusagebasedDescID := chargeusagebasedMixinFields0[19].Descriptor() // chargeusagebased.DefaultID holds the default value on creation for the id field. chargeusagebased.DefaultID = chargeusagebasedDescID.Default.(func() string) + chargeusagebasedcostbasisMixin := schema.ChargeUsageBasedCostBasis{}.Mixin() + chargeusagebasedcostbasisMixinFields0 := chargeusagebasedcostbasisMixin[0].Fields() + _ = chargeusagebasedcostbasisMixinFields0 + chargeusagebasedcostbasisFields := schema.ChargeUsageBasedCostBasis{}.Fields() + _ = chargeusagebasedcostbasisFields + // chargeusagebasedcostbasisDescFiatCurrency is the schema descriptor for fiat_currency field. + chargeusagebasedcostbasisDescFiatCurrency := chargeusagebasedcostbasisMixinFields0[1].Descriptor() + // chargeusagebasedcostbasis.FiatCurrencyValidator is a validator for the "fiat_currency" field. It is called by the builders before save. + chargeusagebasedcostbasis.FiatCurrencyValidator = chargeusagebasedcostbasisDescFiatCurrency.Validators[0].(func(string) error) + // chargeusagebasedcostbasisDescCurrencyID is the schema descriptor for currency_id field. + chargeusagebasedcostbasisDescCurrencyID := chargeusagebasedcostbasisMixinFields0[4].Descriptor() + // chargeusagebasedcostbasis.CurrencyIDValidator is a validator for the "currency_id" field. It is called by the builders before save. + chargeusagebasedcostbasis.CurrencyIDValidator = chargeusagebasedcostbasisDescCurrencyID.Validators[0].(func(string) error) + // chargeusagebasedcostbasisDescNamespace is the schema descriptor for namespace field. + chargeusagebasedcostbasisDescNamespace := chargeusagebasedcostbasisMixinFields0[8].Descriptor() + // chargeusagebasedcostbasis.NamespaceValidator is a validator for the "namespace" field. It is called by the builders before save. + chargeusagebasedcostbasis.NamespaceValidator = chargeusagebasedcostbasisDescNamespace.Validators[0].(func(string) error) + // chargeusagebasedcostbasisDescCreatedAt is the schema descriptor for created_at field. + chargeusagebasedcostbasisDescCreatedAt := chargeusagebasedcostbasisMixinFields0[10].Descriptor() + // chargeusagebasedcostbasis.DefaultCreatedAt holds the default value on creation for the created_at field. + chargeusagebasedcostbasis.DefaultCreatedAt = chargeusagebasedcostbasisDescCreatedAt.Default.(func() time.Time) + // chargeusagebasedcostbasisDescUpdatedAt is the schema descriptor for updated_at field. + chargeusagebasedcostbasisDescUpdatedAt := chargeusagebasedcostbasisMixinFields0[11].Descriptor() + // chargeusagebasedcostbasis.DefaultUpdatedAt holds the default value on creation for the updated_at field. + chargeusagebasedcostbasis.DefaultUpdatedAt = chargeusagebasedcostbasisDescUpdatedAt.Default.(func() time.Time) + // chargeusagebasedcostbasis.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + chargeusagebasedcostbasis.UpdateDefaultUpdatedAt = chargeusagebasedcostbasisDescUpdatedAt.UpdateDefault.(func() time.Time) + // chargeusagebasedcostbasisDescID is the schema descriptor for id field. + chargeusagebasedcostbasisDescID := chargeusagebasedcostbasisMixinFields0[9].Descriptor() + // chargeusagebasedcostbasis.DefaultID holds the default value on creation for the id field. + chargeusagebasedcostbasis.DefaultID = chargeusagebasedcostbasisDescID.Default.(func() string) chargeusagebasedoverrideMixin := schema.ChargeUsageBasedOverride{}.Mixin() chargeusagebasedoverrideMixinFields0 := chargeusagebasedoverrideMixin[0].Fields() _ = chargeusagebasedoverrideMixinFields0 diff --git a/openmeter/ent/db/setorclear.go b/openmeter/ent/db/setorclear.go index d76b4f75a4..95606f57cc 100644 --- a/openmeter/ent/db/setorclear.go +++ b/openmeter/ent/db/setorclear.go @@ -2553,6 +2553,76 @@ func (u *ChargeCreditPurchaseUpdateOne) SetOrClearVoidedAt(value *time.Time) *Ch return u.SetVoidedAt(*value) } +func (u *ChargeCreditPurchaseCostBasisUpdate) SetOrClearCurrencyCostBasisID(value *string) *ChargeCreditPurchaseCostBasisUpdate { + if value == nil { + return u.ClearCurrencyCostBasisID() + } + return u.SetCurrencyCostBasisID(*value) +} + +func (u *ChargeCreditPurchaseCostBasisUpdateOne) SetOrClearCurrencyCostBasisID(value *string) *ChargeCreditPurchaseCostBasisUpdateOne { + if value == nil { + return u.ClearCurrencyCostBasisID() + } + return u.SetCurrencyCostBasisID(*value) +} + +func (u *ChargeCreditPurchaseCostBasisUpdate) SetOrClearResolvedCostBasisID(value *string) *ChargeCreditPurchaseCostBasisUpdate { + if value == nil { + return u.ClearResolvedCostBasisID() + } + return u.SetResolvedCostBasisID(*value) +} + +func (u *ChargeCreditPurchaseCostBasisUpdateOne) SetOrClearResolvedCostBasisID(value *string) *ChargeCreditPurchaseCostBasisUpdateOne { + if value == nil { + return u.ClearResolvedCostBasisID() + } + return u.SetResolvedCostBasisID(*value) +} + +func (u *ChargeCreditPurchaseCostBasisUpdate) SetOrClearResolvedCostBasis(value *alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisUpdate { + if value == nil { + return u.ClearResolvedCostBasis() + } + return u.SetResolvedCostBasis(*value) +} + +func (u *ChargeCreditPurchaseCostBasisUpdateOne) SetOrClearResolvedCostBasis(value *alpacadecimal.Decimal) *ChargeCreditPurchaseCostBasisUpdateOne { + if value == nil { + return u.ClearResolvedCostBasis() + } + return u.SetResolvedCostBasis(*value) +} + +func (u *ChargeCreditPurchaseCostBasisUpdate) SetOrClearResolvedAt(value *time.Time) *ChargeCreditPurchaseCostBasisUpdate { + if value == nil { + return u.ClearResolvedAt() + } + return u.SetResolvedAt(*value) +} + +func (u *ChargeCreditPurchaseCostBasisUpdateOne) SetOrClearResolvedAt(value *time.Time) *ChargeCreditPurchaseCostBasisUpdateOne { + if value == nil { + return u.ClearResolvedAt() + } + return u.SetResolvedAt(*value) +} + +func (u *ChargeCreditPurchaseCostBasisUpdate) SetOrClearDeletedAt(value *time.Time) *ChargeCreditPurchaseCostBasisUpdate { + if value == nil { + return u.ClearDeletedAt() + } + return u.SetDeletedAt(*value) +} + +func (u *ChargeCreditPurchaseCostBasisUpdateOne) SetOrClearDeletedAt(value *time.Time) *ChargeCreditPurchaseCostBasisUpdateOne { + if value == nil { + return u.ClearDeletedAt() + } + return u.SetDeletedAt(*value) +} + func (u *ChargeCreditPurchaseCreditGrantUpdate) SetOrClearDeletedAt(value *time.Time) *ChargeCreditPurchaseCreditGrantUpdate { if value == nil { return u.ClearDeletedAt() @@ -2875,6 +2945,76 @@ func (u *ChargeFlatFeeUpdateOne) SetOrClearCurrentRealizationRunID(value *string return u.SetCurrentRealizationRunID(*value) } +func (u *ChargeFlatFeeCostBasisUpdate) SetOrClearCurrencyCostBasisID(value *string) *ChargeFlatFeeCostBasisUpdate { + if value == nil { + return u.ClearCurrencyCostBasisID() + } + return u.SetCurrencyCostBasisID(*value) +} + +func (u *ChargeFlatFeeCostBasisUpdateOne) SetOrClearCurrencyCostBasisID(value *string) *ChargeFlatFeeCostBasisUpdateOne { + if value == nil { + return u.ClearCurrencyCostBasisID() + } + return u.SetCurrencyCostBasisID(*value) +} + +func (u *ChargeFlatFeeCostBasisUpdate) SetOrClearResolvedCostBasisID(value *string) *ChargeFlatFeeCostBasisUpdate { + if value == nil { + return u.ClearResolvedCostBasisID() + } + return u.SetResolvedCostBasisID(*value) +} + +func (u *ChargeFlatFeeCostBasisUpdateOne) SetOrClearResolvedCostBasisID(value *string) *ChargeFlatFeeCostBasisUpdateOne { + if value == nil { + return u.ClearResolvedCostBasisID() + } + return u.SetResolvedCostBasisID(*value) +} + +func (u *ChargeFlatFeeCostBasisUpdate) SetOrClearResolvedCostBasis(value *alpacadecimal.Decimal) *ChargeFlatFeeCostBasisUpdate { + if value == nil { + return u.ClearResolvedCostBasis() + } + return u.SetResolvedCostBasis(*value) +} + +func (u *ChargeFlatFeeCostBasisUpdateOne) SetOrClearResolvedCostBasis(value *alpacadecimal.Decimal) *ChargeFlatFeeCostBasisUpdateOne { + if value == nil { + return u.ClearResolvedCostBasis() + } + return u.SetResolvedCostBasis(*value) +} + +func (u *ChargeFlatFeeCostBasisUpdate) SetOrClearResolvedAt(value *time.Time) *ChargeFlatFeeCostBasisUpdate { + if value == nil { + return u.ClearResolvedAt() + } + return u.SetResolvedAt(*value) +} + +func (u *ChargeFlatFeeCostBasisUpdateOne) SetOrClearResolvedAt(value *time.Time) *ChargeFlatFeeCostBasisUpdateOne { + if value == nil { + return u.ClearResolvedAt() + } + return u.SetResolvedAt(*value) +} + +func (u *ChargeFlatFeeCostBasisUpdate) SetOrClearDeletedAt(value *time.Time) *ChargeFlatFeeCostBasisUpdate { + if value == nil { + return u.ClearDeletedAt() + } + return u.SetDeletedAt(*value) +} + +func (u *ChargeFlatFeeCostBasisUpdateOne) SetOrClearDeletedAt(value *time.Time) *ChargeFlatFeeCostBasisUpdateOne { + if value == nil { + return u.ClearDeletedAt() + } + return u.SetDeletedAt(*value) +} + func (u *ChargeFlatFeeOverrideUpdate) SetOrClearDescription(value *string) *ChargeFlatFeeOverrideUpdate { if value == nil { return u.ClearDescription() @@ -3449,6 +3589,76 @@ func (u *ChargeUsageBasedUpdateOne) SetOrClearCurrentRealizationRunID(value *str return u.SetCurrentRealizationRunID(*value) } +func (u *ChargeUsageBasedCostBasisUpdate) SetOrClearCurrencyCostBasisID(value *string) *ChargeUsageBasedCostBasisUpdate { + if value == nil { + return u.ClearCurrencyCostBasisID() + } + return u.SetCurrencyCostBasisID(*value) +} + +func (u *ChargeUsageBasedCostBasisUpdateOne) SetOrClearCurrencyCostBasisID(value *string) *ChargeUsageBasedCostBasisUpdateOne { + if value == nil { + return u.ClearCurrencyCostBasisID() + } + return u.SetCurrencyCostBasisID(*value) +} + +func (u *ChargeUsageBasedCostBasisUpdate) SetOrClearResolvedCostBasisID(value *string) *ChargeUsageBasedCostBasisUpdate { + if value == nil { + return u.ClearResolvedCostBasisID() + } + return u.SetResolvedCostBasisID(*value) +} + +func (u *ChargeUsageBasedCostBasisUpdateOne) SetOrClearResolvedCostBasisID(value *string) *ChargeUsageBasedCostBasisUpdateOne { + if value == nil { + return u.ClearResolvedCostBasisID() + } + return u.SetResolvedCostBasisID(*value) +} + +func (u *ChargeUsageBasedCostBasisUpdate) SetOrClearResolvedCostBasis(value *alpacadecimal.Decimal) *ChargeUsageBasedCostBasisUpdate { + if value == nil { + return u.ClearResolvedCostBasis() + } + return u.SetResolvedCostBasis(*value) +} + +func (u *ChargeUsageBasedCostBasisUpdateOne) SetOrClearResolvedCostBasis(value *alpacadecimal.Decimal) *ChargeUsageBasedCostBasisUpdateOne { + if value == nil { + return u.ClearResolvedCostBasis() + } + return u.SetResolvedCostBasis(*value) +} + +func (u *ChargeUsageBasedCostBasisUpdate) SetOrClearResolvedAt(value *time.Time) *ChargeUsageBasedCostBasisUpdate { + if value == nil { + return u.ClearResolvedAt() + } + return u.SetResolvedAt(*value) +} + +func (u *ChargeUsageBasedCostBasisUpdateOne) SetOrClearResolvedAt(value *time.Time) *ChargeUsageBasedCostBasisUpdateOne { + if value == nil { + return u.ClearResolvedAt() + } + return u.SetResolvedAt(*value) +} + +func (u *ChargeUsageBasedCostBasisUpdate) SetOrClearDeletedAt(value *time.Time) *ChargeUsageBasedCostBasisUpdate { + if value == nil { + return u.ClearDeletedAt() + } + return u.SetDeletedAt(*value) +} + +func (u *ChargeUsageBasedCostBasisUpdateOne) SetOrClearDeletedAt(value *time.Time) *ChargeUsageBasedCostBasisUpdateOne { + if value == nil { + return u.ClearDeletedAt() + } + return u.SetDeletedAt(*value) +} + func (u *ChargeUsageBasedOverrideUpdate) SetOrClearDescription(value *string) *ChargeUsageBasedOverrideUpdate { if value == nil { return u.ClearDescription() diff --git a/openmeter/ent/db/tx.go b/openmeter/ent/db/tx.go index 91b3b1a346..188c70f0fb 100644 --- a/openmeter/ent/db/tx.go +++ b/openmeter/ent/db/tx.go @@ -70,6 +70,8 @@ type Tx struct { Charge *ChargeClient // ChargeCreditPurchase is the client for interacting with the ChargeCreditPurchase builders. ChargeCreditPurchase *ChargeCreditPurchaseClient + // ChargeCreditPurchaseCostBasis is the client for interacting with the ChargeCreditPurchaseCostBasis builders. + ChargeCreditPurchaseCostBasis *ChargeCreditPurchaseCostBasisClient // ChargeCreditPurchaseCreditGrant is the client for interacting with the ChargeCreditPurchaseCreditGrant builders. ChargeCreditPurchaseCreditGrant *ChargeCreditPurchaseCreditGrantClient // ChargeCreditPurchaseExternalPayment is the client for interacting with the ChargeCreditPurchaseExternalPayment builders. @@ -78,6 +80,8 @@ type Tx struct { ChargeCreditPurchaseInvoicedPayment *ChargeCreditPurchaseInvoicedPaymentClient // ChargeFlatFee is the client for interacting with the ChargeFlatFee builders. ChargeFlatFee *ChargeFlatFeeClient + // ChargeFlatFeeCostBasis is the client for interacting with the ChargeFlatFeeCostBasis builders. + ChargeFlatFeeCostBasis *ChargeFlatFeeCostBasisClient // ChargeFlatFeeOverride is the client for interacting with the ChargeFlatFeeOverride builders. ChargeFlatFeeOverride *ChargeFlatFeeOverrideClient // ChargeFlatFeeRun is the client for interacting with the ChargeFlatFeeRun builders. @@ -92,6 +96,8 @@ type Tx struct { ChargeFlatFeeRunPayment *ChargeFlatFeeRunPaymentClient // ChargeUsageBased is the client for interacting with the ChargeUsageBased builders. ChargeUsageBased *ChargeUsageBasedClient + // ChargeUsageBasedCostBasis is the client for interacting with the ChargeUsageBasedCostBasis builders. + ChargeUsageBasedCostBasis *ChargeUsageBasedCostBasisClient // ChargeUsageBasedOverride is the client for interacting with the ChargeUsageBasedOverride builders. ChargeUsageBasedOverride *ChargeUsageBasedOverrideClient // ChargeUsageBasedRunCreditAllocations is the client for interacting with the ChargeUsageBasedRunCreditAllocations builders. @@ -341,10 +347,12 @@ func (tx *Tx) init() { tx.BillingWorkflowConfig = NewBillingWorkflowConfigClient(tx.config) tx.Charge = NewChargeClient(tx.config) tx.ChargeCreditPurchase = NewChargeCreditPurchaseClient(tx.config) + tx.ChargeCreditPurchaseCostBasis = NewChargeCreditPurchaseCostBasisClient(tx.config) tx.ChargeCreditPurchaseCreditGrant = NewChargeCreditPurchaseCreditGrantClient(tx.config) tx.ChargeCreditPurchaseExternalPayment = NewChargeCreditPurchaseExternalPaymentClient(tx.config) tx.ChargeCreditPurchaseInvoicedPayment = NewChargeCreditPurchaseInvoicedPaymentClient(tx.config) tx.ChargeFlatFee = NewChargeFlatFeeClient(tx.config) + tx.ChargeFlatFeeCostBasis = NewChargeFlatFeeCostBasisClient(tx.config) tx.ChargeFlatFeeOverride = NewChargeFlatFeeOverrideClient(tx.config) tx.ChargeFlatFeeRun = NewChargeFlatFeeRunClient(tx.config) tx.ChargeFlatFeeRunCreditAllocations = NewChargeFlatFeeRunCreditAllocationsClient(tx.config) @@ -352,6 +360,7 @@ func (tx *Tx) init() { tx.ChargeFlatFeeRunInvoicedUsage = NewChargeFlatFeeRunInvoicedUsageClient(tx.config) tx.ChargeFlatFeeRunPayment = NewChargeFlatFeeRunPaymentClient(tx.config) tx.ChargeUsageBased = NewChargeUsageBasedClient(tx.config) + tx.ChargeUsageBasedCostBasis = NewChargeUsageBasedCostBasisClient(tx.config) tx.ChargeUsageBasedOverride = NewChargeUsageBasedOverrideClient(tx.config) tx.ChargeUsageBasedRunCreditAllocations = NewChargeUsageBasedRunCreditAllocationsClient(tx.config) tx.ChargeUsageBasedRunDetailedLine = NewChargeUsageBasedRunDetailedLineClient(tx.config) diff --git a/openmeter/ent/schema/charges.go b/openmeter/ent/schema/charges.go index e3e3ec9b8c..95f72d6ded 100644 --- a/openmeter/ent/schema/charges.go +++ b/openmeter/ent/schema/charges.go @@ -10,9 +10,11 @@ import ( "entgo.io/ent/schema/field" "entgo.io/ent/schema/index" "entgo.io/ent/schema/mixin" + "github.com/alpacahq/alpacadecimal" "github.com/openmeterio/openmeter/openmeter/billing" "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" + "github.com/openmeterio/openmeter/openmeter/billing/charges/models/costbasis" "github.com/openmeterio/openmeter/openmeter/productcatalog" "github.com/openmeterio/openmeter/pkg/clock" "github.com/openmeterio/openmeter/pkg/currencyx" @@ -298,3 +300,133 @@ func (chargesMetaMixin) Annotations() []schema.Annotation { }), } } + +type ChargeCostBasisMixin = entutils.RecursiveMixin[chargeCostBasisMixin] + +type chargeCostBasisMixin struct { + mixin.Schema +} + +func (chargeCostBasisMixin) Mixin() []ent.Mixin { + return []ent.Mixin{ + entutils.NamespaceMixin{}, + entutils.IDMixin{}, + entutils.TimeMixin{}, + } +} + +func (chargeCostBasisMixin) Fields() []ent.Field { + return []ent.Field{ + field.Enum("mode"). + GoType(costbasis.Mode("")). + Immutable(), + field.String("fiat_currency"). + GoType(currencyx.FiatCode("")). + NotEmpty(). + Immutable(). + SchemaType(map[string]string{ + dialect.Postgres: "varchar(3)", + }), + field.String("currency_cost_basis_id"). + Optional(). + Nillable(). + SchemaType(map[string]string{ + dialect.Postgres: "char(26)", + }), + field.String("resolved_cost_basis_id"). + Optional(). + Nillable(). + SchemaType(map[string]string{ + dialect.Postgres: "char(26)", + }), + field.String("currency_id"). + NotEmpty(). + Immutable(). + SchemaType(map[string]string{ + dialect.Postgres: "char(26)", + }), + field.Other("manual_rate", alpacadecimal.Decimal{}). + Optional(). + Nillable(). + Immutable(). + SchemaType(map[string]string{ + dialect.Postgres: "numeric", + }), + field.Other("resolved_cost_basis", alpacadecimal.Decimal{}). + Optional(). + Nillable(). + SchemaType(map[string]string{ + dialect.Postgres: "numeric", + }), + field.Time("resolved_at"). + Optional(). + Nillable(), + } +} + +func chargeCostBasisCurrencyEdges(symbolPrefix string) []ent.Edge { + return []ent.Edge{ + edge.To("currency_cost_basis", CurrencyCostBasis.Type). + Field("currency_cost_basis_id"). + Unique(). + StorageKey(edge.Symbol(symbolPrefix + "_currency_cost_basis_fk")). + Annotations(entsql.OnDelete(entsql.Restrict)), + edge.To("resolved_currency_cost_basis", CurrencyCostBasis.Type). + Field("resolved_cost_basis_id"). + Unique(). + StorageKey(edge.Symbol(symbolPrefix + "_resolved_cost_basis_fk")). + Annotations(entsql.OnDelete(entsql.Restrict)), + edge.To("custom_currency", CustomCurrency.Type). + Field("currency_id"). + Unique(). + Required(). + Immutable(). + StorageKey(edge.Symbol(symbolPrefix + "_currency_fk")). + Annotations(entsql.OnDelete(entsql.Restrict)), + } +} + +func (chargeCostBasisMixin) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("currency_cost_basis_id"), + index.Fields("resolved_cost_basis_id"), + index.Fields("currency_id"), + } +} + +func (chargeCostBasisMixin) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Checks(map[string]string{ + "fiat_currency_not_empty": `fiat_currency <> ''`, + "resolved_cost_basis_positive": `resolved_cost_basis IS NULL OR resolved_cost_basis > 0`, + "state": ` + ( + mode = 'dynamic' + AND currency_cost_basis_id IS NULL + AND manual_rate IS NULL + AND ( + (resolved_cost_basis_id IS NULL AND resolved_cost_basis IS NULL AND resolved_at IS NULL) + OR (resolved_cost_basis_id IS NOT NULL AND resolved_cost_basis IS NOT NULL AND resolved_at IS NOT NULL) + ) + ) + OR ( + mode = 'pinned' + AND currency_cost_basis_id IS NOT NULL + AND resolved_cost_basis_id IS NOT NULL + AND resolved_cost_basis_id = currency_cost_basis_id + AND manual_rate IS NULL + AND resolved_cost_basis IS NOT NULL + AND resolved_at IS NOT NULL + ) + OR ( + mode = 'manual' + AND currency_cost_basis_id IS NULL + AND resolved_cost_basis_id IS NULL + AND manual_rate > 0 + AND resolved_cost_basis IS NOT NULL + AND resolved_at IS NOT NULL + ) + `, + }), + } +} diff --git a/openmeter/ent/schema/chargescreditpurchase.go b/openmeter/ent/schema/chargescreditpurchase.go index b790e7fcb5..7c36f6b960 100644 --- a/openmeter/ent/schema/chargescreditpurchase.go +++ b/openmeter/ent/schema/chargescreditpurchase.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" @@ -71,6 +72,14 @@ func (ChargeCreditPurchase) Fields() []ent.Field { field.Time("voided_at"). Optional(). Nillable(), + + field.String("cost_basis_id"). + SchemaType(map[string]string{ + dialect.Postgres: "char(26)", + }). + Optional(). + Nillable(). + Immutable(), } } @@ -85,6 +94,12 @@ func (ChargeCreditPurchase) Edges() []ent.Edge { edge.To("credit_grant", ChargeCreditPurchaseCreditGrant.Type). Unique(). Annotations(entsql.OnDelete(entsql.Cascade)), + edge.To("cost_basis", ChargeCreditPurchaseCostBasis.Type). + Field("cost_basis_id"). + StorageKey(edge.Symbol("charge_credit_purchase_cost_basis_charge_fk")). + Unique(). + Immutable(). + Annotations(entsql.OnDelete(entsql.Cascade)), edge.To("charge", Charge.Type). Unique(). Immutable(). @@ -141,6 +156,26 @@ func (ChargeCreditPurchase) Indexes() []ent.Index { } } +type ChargeCreditPurchaseCostBasis struct { + ent.Schema +} + +func (ChargeCreditPurchaseCostBasis) Mixin() []ent.Mixin { + return []ent.Mixin{ + ChargeCostBasisMixin{}, + } +} + +func (ChargeCreditPurchaseCostBasis) Edges() []ent.Edge { + return chargeCostBasisCurrencyEdges("charge_credit_purchase_cost_basis") +} + +func (ChargeCreditPurchaseCostBasis) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "charge_credit_purchase_cost_bases"}, + } +} + type ChargeCreditPurchaseCreditGrant struct { ent.Schema } diff --git a/openmeter/ent/schema/chargesflatfee.go b/openmeter/ent/schema/chargesflatfee.go index 92ca961470..4e299e332b 100644 --- a/openmeter/ent/schema/chargesflatfee.go +++ b/openmeter/ent/schema/chargesflatfee.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" @@ -89,6 +90,14 @@ func (ChargeFlatFee) Fields() []ent.Field { Optional(). Nillable(), + field.String("cost_basis_id"). + SchemaType(map[string]string{ + dialect.Postgres: "char(26)", + }). + Optional(). + Nillable(). + Immutable(), + field.Enum("status_detailed"). GoType(flatfee.Status("")), } @@ -101,6 +110,12 @@ func (ChargeFlatFee) Edges() []ent.Edge { edge.To("current_run", ChargeFlatFeeRun.Type). Field("current_realization_run_id"). Unique(), + edge.To("cost_basis", ChargeFlatFeeCostBasis.Type). + Field("cost_basis_id"). + StorageKey(edge.Symbol("charge_flat_fee_cost_basis_charge_fk")). + Unique(). + Immutable(). + Annotations(entsql.OnDelete(entsql.Cascade)), edge.To("charge", Charge.Type). Unique(). Immutable(). @@ -156,6 +171,26 @@ func (ChargeFlatFee) Indexes() []ent.Index { } } +type ChargeFlatFeeCostBasis struct { + ent.Schema +} + +func (ChargeFlatFeeCostBasis) Mixin() []ent.Mixin { + return []ent.Mixin{ + ChargeCostBasisMixin{}, + } +} + +func (ChargeFlatFeeCostBasis) Edges() []ent.Edge { + return chargeCostBasisCurrencyEdges("charge_flat_fee_cost_basis") +} + +func (ChargeFlatFeeCostBasis) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "charge_flat_fee_cost_bases"}, + } +} + type ChargeFlatFeeOverride struct { ent.Schema } diff --git a/openmeter/ent/schema/chargesusagebased.go b/openmeter/ent/schema/chargesusagebased.go index 3b223cffb0..9c47a5b914 100644 --- a/openmeter/ent/schema/chargesusagebased.go +++ b/openmeter/ent/schema/chargesusagebased.go @@ -93,6 +93,14 @@ func (ChargeUsageBased) Fields() []ent.Field { Optional(). Nillable(), + field.String("cost_basis_id"). + SchemaType(map[string]string{ + dialect.Postgres: "char(26)", + }). + Optional(). + Nillable(). + Immutable(), + field.Enum("status_detailed"). GoType(usagebased.Status("")), } @@ -107,6 +115,12 @@ func (ChargeUsageBased) Edges() []ent.Edge { edge.To("current_run", ChargeUsageBasedRuns.Type). Field("current_realization_run_id"). Unique(), + edge.To("cost_basis", ChargeUsageBasedCostBasis.Type). + Field("cost_basis_id"). + StorageKey(edge.Symbol("charge_usage_based_cost_basis_charge_fk")). + Unique(). + Immutable(). + Annotations(entsql.OnDelete(entsql.Cascade)), edge.To("charge", Charge.Type). Unique(). Immutable(). @@ -169,6 +183,26 @@ func (ChargeUsageBased) Annotations() []schema.Annotation { } } +type ChargeUsageBasedCostBasis struct { + ent.Schema +} + +func (ChargeUsageBasedCostBasis) Mixin() []ent.Mixin { + return []ent.Mixin{ + ChargeCostBasisMixin{}, + } +} + +func (ChargeUsageBasedCostBasis) Edges() []ent.Edge { + return chargeCostBasisCurrencyEdges("charge_usage_based_cost_basis") +} + +func (ChargeUsageBasedCostBasis) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "charge_usage_based_cost_bases"}, + } +} + type ChargeUsageBasedOverride struct { ent.Schema } diff --git a/openmeter/ledger/customerbalance/testenv_test.go b/openmeter/ledger/customerbalance/testenv_test.go index 06c2ec4d83..fc87fef7b0 100644 --- a/openmeter/ledger/customerbalance/testenv_test.go +++ b/openmeter/ledger/customerbalance/testenv_test.go @@ -29,6 +29,8 @@ import ( usagebasedadapter "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased/adapter" usagebasedservice "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased/service" billingratingservice "github.com/openmeterio/openmeter/openmeter/billing/rating/service" + currencyadapter "github.com/openmeterio/openmeter/openmeter/currencies/adapter" + currencyservice "github.com/openmeterio/openmeter/openmeter/currencies/service" currenciestestutils "github.com/openmeterio/openmeter/openmeter/currencies/testutils/currency" "github.com/openmeterio/openmeter/openmeter/customer" enttx "github.com/openmeterio/openmeter/openmeter/ent/tx" @@ -239,6 +241,14 @@ func newTestEnv(t *testing.T) *testEnv { }) require.NoError(t, err) + currencyAdapter, err := currencyadapter.New(currencyadapter.Config{ + Client: base.DB, + }) + require.NoError(t, err) + + currencyService, err := currencyservice.New(currencyAdapter) + require.NoError(t, err) + flatFeeService, err := flatfeeservice.New(flatfeeservice.Config{ Adapter: flatFeeAdapter, Handler: ledgerchargeadapter.NewFlatFeeHandler( @@ -254,6 +264,7 @@ func newTestEnv(t *testing.T) *testEnv { MetaAdapter: metaAdapter, Locker: locker, RatingService: billingratingservice.New(billingratingservice.Config{UnitConfigEnabled: true}), + Currencies: currencyService, }) require.NoError(t, err) @@ -275,6 +286,7 @@ func newTestEnv(t *testing.T) *testEnv { CustomerOverrideService: billingService, FeatureService: featureService, RatingService: billingratingservice.New(billingratingservice.Config{UnitConfigEnabled: true}), + Currencies: currencyService, StreamingConnector: streaming, }) require.NoError(t, err) diff --git a/openmeter/server/server_test.go b/openmeter/server/server_test.go index 8ac02a1686..cc8b64caaa 100644 --- a/openmeter/server/server_test.go +++ b/openmeter/server/server_test.go @@ -2132,6 +2132,10 @@ func (n NoopCurrencyService) GetCostBasis(ctx context.Context, params currencies return currencies.CostBasis{}, nil } +func (n NoopCurrencyService) GetCostBasisAt(ctx context.Context, params currencies.GetCostBasisAtInput) (currencies.CostBasis, error) { + return currencies.CostBasis{}, nil +} + func (n NoopCurrencyService) ListCostBases(ctx context.Context, params currencies.ListCostBasesInput) (pagination.Result[currencies.CostBasis], error) { return pagination.Result[currencies.CostBasis]{}, nil } diff --git a/pkg/currencyx/code.go b/pkg/currencyx/code.go index da261a08bb..82538cef09 100644 --- a/pkg/currencyx/code.go +++ b/pkg/currencyx/code.go @@ -110,3 +110,27 @@ func validateCustomCurrencyCode(code Code) error { return errors.Join(errs...) } + +var ( + _ fmt.Stringer = (*FiatCode)(nil) + _ models.Validator = (*FiatCode)(nil) + _ models.Equaler[FiatCode] = (*FiatCode)(nil) +) + +type FiatCode currency.Code + +func (c FiatCode) Validate() error { + return validateFiatCurrencyCode(Code(c)) +} + +func (c FiatCode) String() string { + return string(c) +} + +func (c FiatCode) Equal(other FiatCode) bool { + return c == other +} + +func (c FiatCode) AsFiatCurrency() (*FiatCurrency, error) { + return NewFiatCurrency(string(c)) +} diff --git a/pkg/currencyx/currency.go b/pkg/currencyx/currency.go index fc7b6158c9..5dded4f47b 100644 --- a/pkg/currencyx/currency.go +++ b/pkg/currencyx/currency.go @@ -194,7 +194,11 @@ func (f *FiatCurrency) Validate() error { return models.NewNillableGenericValidationError(errors.Join(errs...)) } -func newFiatCurrency(code string) (Currency, error) { +func (f *FiatCurrency) GetFiatCode() FiatCode { + return FiatCode(f.def.ISOCode) +} + +func NewFiatCurrency[T ~string](code T) (*FiatCurrency, error) { if err := validateFiatCurrencyCode(Code(code)); err != nil { return nil, err } @@ -362,7 +366,7 @@ func (b *CurrencyBuilder) WithThousandsSeparator(thousandsSeparator string) *Cur func (b *CurrencyBuilder) Build() (Currency, error) { switch b.t { case CurrencyTypeFiat: - return newFiatCurrency(b.d.Code.String()) + return NewFiatCurrency(b.d.Code.String()) case CurrencyTypeCustom: return newCustomCurrency(¤cy.Def{ ISOCode: currency.Code(b.d.Code.String()), diff --git a/tools/migrate/migrations/20260722145858_add_charge_cost_basis.down.sql b/tools/migrate/migrations/20260722145858_add_charge_cost_basis.down.sql new file mode 100644 index 0000000000..7b1e34a4f6 --- /dev/null +++ b/tools/migrate/migrations/20260722145858_add_charge_cost_basis.down.sql @@ -0,0 +1,42 @@ +-- reverse: modify "charge_usage_based" table +ALTER TABLE "charge_usage_based" DROP CONSTRAINT "charge_usage_based_cost_basis_charge_fk", DROP COLUMN "cost_basis_id"; +-- reverse: create index "chargeusagebasedcostbasis_resolved_cost_basis_id" to table: "charge_usage_based_cost_bases" +DROP INDEX "chargeusagebasedcostbasis_resolved_cost_basis_id"; +-- reverse: create index "chargeusagebasedcostbasis_namespace" to table: "charge_usage_based_cost_bases" +DROP INDEX "chargeusagebasedcostbasis_namespace"; +-- reverse: create index "chargeusagebasedcostbasis_id" to table: "charge_usage_based_cost_bases" +DROP INDEX "chargeusagebasedcostbasis_id"; +-- reverse: create index "chargeusagebasedcostbasis_currency_id" to table: "charge_usage_based_cost_bases" +DROP INDEX "chargeusagebasedcostbasis_currency_id"; +-- reverse: create index "chargeusagebasedcostbasis_currency_cost_basis_id" to table: "charge_usage_based_cost_bases" +DROP INDEX "chargeusagebasedcostbasis_currency_cost_basis_id"; +-- reverse: create "charge_usage_based_cost_bases" table +DROP TABLE "charge_usage_based_cost_bases"; +-- reverse: modify "charge_flat_fees" table +ALTER TABLE "charge_flat_fees" DROP CONSTRAINT "charge_flat_fee_cost_basis_charge_fk", DROP COLUMN "cost_basis_id"; +-- reverse: create index "chargeflatfeecostbasis_resolved_cost_basis_id" to table: "charge_flat_fee_cost_bases" +DROP INDEX "chargeflatfeecostbasis_resolved_cost_basis_id"; +-- reverse: create index "chargeflatfeecostbasis_namespace" to table: "charge_flat_fee_cost_bases" +DROP INDEX "chargeflatfeecostbasis_namespace"; +-- reverse: create index "chargeflatfeecostbasis_id" to table: "charge_flat_fee_cost_bases" +DROP INDEX "chargeflatfeecostbasis_id"; +-- reverse: create index "chargeflatfeecostbasis_currency_id" to table: "charge_flat_fee_cost_bases" +DROP INDEX "chargeflatfeecostbasis_currency_id"; +-- reverse: create index "chargeflatfeecostbasis_currency_cost_basis_id" to table: "charge_flat_fee_cost_bases" +DROP INDEX "chargeflatfeecostbasis_currency_cost_basis_id"; +-- reverse: create "charge_flat_fee_cost_bases" table +DROP TABLE "charge_flat_fee_cost_bases"; +-- reverse: modify "charge_credit_purchases" table +ALTER TABLE "charge_credit_purchases" DROP CONSTRAINT "charge_credit_purchase_cost_basis_charge_fk", DROP COLUMN "cost_basis_id"; +-- reverse: create index "chargecreditpurchasecostbasis_resolved_cost_basis_id" to table: "charge_credit_purchase_cost_bases" +DROP INDEX "chargecreditpurchasecostbasis_resolved_cost_basis_id"; +-- reverse: create index "chargecreditpurchasecostbasis_namespace" to table: "charge_credit_purchase_cost_bases" +DROP INDEX "chargecreditpurchasecostbasis_namespace"; +-- reverse: create index "chargecreditpurchasecostbasis_id" to table: "charge_credit_purchase_cost_bases" +DROP INDEX "chargecreditpurchasecostbasis_id"; +-- reverse: create index "chargecreditpurchasecostbasis_currency_id" to table: "charge_credit_purchase_cost_bases" +DROP INDEX "chargecreditpurchasecostbasis_currency_id"; +-- reverse: create index "chargecreditpurchasecostbasis_currency_cost_basis_id" to table: "charge_credit_purchase_cost_bases" +DROP INDEX "chargecreditpurchasecostbasis_currency_cost_basis_id"; +-- reverse: create "charge_credit_purchase_cost_bases" table +DROP TABLE "charge_credit_purchase_cost_bases"; diff --git a/tools/migrate/migrations/20260722145858_add_charge_cost_basis.up.sql b/tools/migrate/migrations/20260722145858_add_charge_cost_basis.up.sql new file mode 100644 index 0000000000..64685ee1a3 --- /dev/null +++ b/tools/migrate/migrations/20260722145858_add_charge_cost_basis.up.sql @@ -0,0 +1,105 @@ +-- create "charge_credit_purchase_cost_bases" table +CREATE TABLE "charge_credit_purchase_cost_bases" ( + "id" character(26) NOT NULL, + "mode" character varying NOT NULL, + "fiat_currency" character varying(3) NOT NULL, + "manual_rate" numeric NULL, + "resolved_cost_basis" numeric NULL, + "resolved_at" timestamptz NULL, + "namespace" character varying NOT NULL, + "created_at" timestamptz NOT NULL, + "updated_at" timestamptz NOT NULL, + "deleted_at" timestamptz NULL, + "currency_cost_basis_id" character(26) NULL, + "resolved_cost_basis_id" character(26) NULL, + "currency_id" character(26) NOT NULL, + PRIMARY KEY ("id"), + CONSTRAINT "charge_credit_purchase_cost_basis_currency_cost_basis_fk" FOREIGN KEY ("currency_cost_basis_id") REFERENCES "currency_cost_bases" ("id") ON UPDATE NO ACTION ON DELETE RESTRICT, + CONSTRAINT "charge_credit_purchase_cost_basis_currency_fk" FOREIGN KEY ("currency_id") REFERENCES "custom_currencies" ("id") ON UPDATE NO ACTION ON DELETE RESTRICT, + CONSTRAINT "charge_credit_purchase_cost_basis_resolved_cost_basis_fk" FOREIGN KEY ("resolved_cost_basis_id") REFERENCES "currency_cost_bases" ("id") ON UPDATE NO ACTION ON DELETE RESTRICT, + CONSTRAINT "fiat_currency_not_empty" CHECK ((fiat_currency)::text <> ''::text), + CONSTRAINT "resolved_cost_basis_positive" CHECK ((resolved_cost_basis IS NULL) OR (resolved_cost_basis > (0)::numeric)), + CONSTRAINT "state" CHECK ((((mode)::text = 'dynamic'::text) AND (currency_cost_basis_id IS NULL) AND (manual_rate IS NULL) AND (((resolved_cost_basis_id IS NULL) AND (resolved_cost_basis IS NULL) AND (resolved_at IS NULL)) OR ((resolved_cost_basis_id IS NOT NULL) AND (resolved_cost_basis IS NOT NULL) AND (resolved_at IS NOT NULL)))) OR (((mode)::text = 'pinned'::text) AND (currency_cost_basis_id IS NOT NULL) AND (resolved_cost_basis_id IS NOT NULL) AND (resolved_cost_basis_id = currency_cost_basis_id) AND (manual_rate IS NULL) AND (resolved_cost_basis IS NOT NULL) AND (resolved_at IS NOT NULL)) OR (((mode)::text = 'manual'::text) AND (currency_cost_basis_id IS NULL) AND (resolved_cost_basis_id IS NULL) AND (manual_rate > (0)::numeric) AND (resolved_cost_basis IS NOT NULL) AND (resolved_at IS NOT NULL))) +); +-- create index "chargecreditpurchasecostbasis_currency_cost_basis_id" to table: "charge_credit_purchase_cost_bases" +CREATE INDEX "chargecreditpurchasecostbasis_currency_cost_basis_id" ON "charge_credit_purchase_cost_bases" ("currency_cost_basis_id"); +-- create index "chargecreditpurchasecostbasis_currency_id" to table: "charge_credit_purchase_cost_bases" +CREATE INDEX "chargecreditpurchasecostbasis_currency_id" ON "charge_credit_purchase_cost_bases" ("currency_id"); +-- create index "chargecreditpurchasecostbasis_id" to table: "charge_credit_purchase_cost_bases" +CREATE UNIQUE INDEX "chargecreditpurchasecostbasis_id" ON "charge_credit_purchase_cost_bases" ("id"); +-- create index "chargecreditpurchasecostbasis_namespace" to table: "charge_credit_purchase_cost_bases" +CREATE INDEX "chargecreditpurchasecostbasis_namespace" ON "charge_credit_purchase_cost_bases" ("namespace"); +-- create index "chargecreditpurchasecostbasis_resolved_cost_basis_id" to table: "charge_credit_purchase_cost_bases" +CREATE INDEX "chargecreditpurchasecostbasis_resolved_cost_basis_id" ON "charge_credit_purchase_cost_bases" ("resolved_cost_basis_id"); +-- modify "charge_credit_purchases" table +ALTER TABLE "charge_credit_purchases" ADD COLUMN "cost_basis_id" character(26) NULL, ADD CONSTRAINT "charge_credit_purchase_cost_basis_charge_fk" FOREIGN KEY ("cost_basis_id") REFERENCES "charge_credit_purchase_cost_bases" ("id") ON UPDATE NO ACTION ON DELETE CASCADE; +-- create "charge_flat_fee_cost_bases" table +CREATE TABLE "charge_flat_fee_cost_bases" ( + "id" character(26) NOT NULL, + "mode" character varying NOT NULL, + "fiat_currency" character varying(3) NOT NULL, + "manual_rate" numeric NULL, + "resolved_cost_basis" numeric NULL, + "resolved_at" timestamptz NULL, + "namespace" character varying NOT NULL, + "created_at" timestamptz NOT NULL, + "updated_at" timestamptz NOT NULL, + "deleted_at" timestamptz NULL, + "currency_cost_basis_id" character(26) NULL, + "resolved_cost_basis_id" character(26) NULL, + "currency_id" character(26) NOT NULL, + PRIMARY KEY ("id"), + CONSTRAINT "charge_flat_fee_cost_basis_currency_cost_basis_fk" FOREIGN KEY ("currency_cost_basis_id") REFERENCES "currency_cost_bases" ("id") ON UPDATE NO ACTION ON DELETE RESTRICT, + CONSTRAINT "charge_flat_fee_cost_basis_currency_fk" FOREIGN KEY ("currency_id") REFERENCES "custom_currencies" ("id") ON UPDATE NO ACTION ON DELETE RESTRICT, + CONSTRAINT "charge_flat_fee_cost_basis_resolved_cost_basis_fk" FOREIGN KEY ("resolved_cost_basis_id") REFERENCES "currency_cost_bases" ("id") ON UPDATE NO ACTION ON DELETE RESTRICT, + CONSTRAINT "fiat_currency_not_empty" CHECK ((fiat_currency)::text <> ''::text), + CONSTRAINT "resolved_cost_basis_positive" CHECK ((resolved_cost_basis IS NULL) OR (resolved_cost_basis > (0)::numeric)), + CONSTRAINT "state" CHECK ((((mode)::text = 'dynamic'::text) AND (currency_cost_basis_id IS NULL) AND (manual_rate IS NULL) AND (((resolved_cost_basis_id IS NULL) AND (resolved_cost_basis IS NULL) AND (resolved_at IS NULL)) OR ((resolved_cost_basis_id IS NOT NULL) AND (resolved_cost_basis IS NOT NULL) AND (resolved_at IS NOT NULL)))) OR (((mode)::text = 'pinned'::text) AND (currency_cost_basis_id IS NOT NULL) AND (resolved_cost_basis_id IS NOT NULL) AND (resolved_cost_basis_id = currency_cost_basis_id) AND (manual_rate IS NULL) AND (resolved_cost_basis IS NOT NULL) AND (resolved_at IS NOT NULL)) OR (((mode)::text = 'manual'::text) AND (currency_cost_basis_id IS NULL) AND (resolved_cost_basis_id IS NULL) AND (manual_rate > (0)::numeric) AND (resolved_cost_basis IS NOT NULL) AND (resolved_at IS NOT NULL))) +); +-- create index "chargeflatfeecostbasis_currency_cost_basis_id" to table: "charge_flat_fee_cost_bases" +CREATE INDEX "chargeflatfeecostbasis_currency_cost_basis_id" ON "charge_flat_fee_cost_bases" ("currency_cost_basis_id"); +-- create index "chargeflatfeecostbasis_currency_id" to table: "charge_flat_fee_cost_bases" +CREATE INDEX "chargeflatfeecostbasis_currency_id" ON "charge_flat_fee_cost_bases" ("currency_id"); +-- create index "chargeflatfeecostbasis_id" to table: "charge_flat_fee_cost_bases" +CREATE UNIQUE INDEX "chargeflatfeecostbasis_id" ON "charge_flat_fee_cost_bases" ("id"); +-- create index "chargeflatfeecostbasis_namespace" to table: "charge_flat_fee_cost_bases" +CREATE INDEX "chargeflatfeecostbasis_namespace" ON "charge_flat_fee_cost_bases" ("namespace"); +-- create index "chargeflatfeecostbasis_resolved_cost_basis_id" to table: "charge_flat_fee_cost_bases" +CREATE INDEX "chargeflatfeecostbasis_resolved_cost_basis_id" ON "charge_flat_fee_cost_bases" ("resolved_cost_basis_id"); +-- modify "charge_flat_fees" table +ALTER TABLE "charge_flat_fees" ADD COLUMN "cost_basis_id" character(26) NULL, ADD CONSTRAINT "charge_flat_fee_cost_basis_charge_fk" FOREIGN KEY ("cost_basis_id") REFERENCES "charge_flat_fee_cost_bases" ("id") ON UPDATE NO ACTION ON DELETE CASCADE; +-- create "charge_usage_based_cost_bases" table +CREATE TABLE "charge_usage_based_cost_bases" ( + "id" character(26) NOT NULL, + "mode" character varying NOT NULL, + "fiat_currency" character varying(3) NOT NULL, + "manual_rate" numeric NULL, + "resolved_cost_basis" numeric NULL, + "resolved_at" timestamptz NULL, + "namespace" character varying NOT NULL, + "created_at" timestamptz NOT NULL, + "updated_at" timestamptz NOT NULL, + "deleted_at" timestamptz NULL, + "currency_cost_basis_id" character(26) NULL, + "resolved_cost_basis_id" character(26) NULL, + "currency_id" character(26) NOT NULL, + PRIMARY KEY ("id"), + CONSTRAINT "charge_usage_based_cost_basis_currency_cost_basis_fk" FOREIGN KEY ("currency_cost_basis_id") REFERENCES "currency_cost_bases" ("id") ON UPDATE NO ACTION ON DELETE RESTRICT, + CONSTRAINT "charge_usage_based_cost_basis_currency_fk" FOREIGN KEY ("currency_id") REFERENCES "custom_currencies" ("id") ON UPDATE NO ACTION ON DELETE RESTRICT, + CONSTRAINT "charge_usage_based_cost_basis_resolved_cost_basis_fk" FOREIGN KEY ("resolved_cost_basis_id") REFERENCES "currency_cost_bases" ("id") ON UPDATE NO ACTION ON DELETE RESTRICT, + CONSTRAINT "fiat_currency_not_empty" CHECK ((fiat_currency)::text <> ''::text), + CONSTRAINT "resolved_cost_basis_positive" CHECK ((resolved_cost_basis IS NULL) OR (resolved_cost_basis > (0)::numeric)), + CONSTRAINT "state" CHECK ((((mode)::text = 'dynamic'::text) AND (currency_cost_basis_id IS NULL) AND (manual_rate IS NULL) AND (((resolved_cost_basis_id IS NULL) AND (resolved_cost_basis IS NULL) AND (resolved_at IS NULL)) OR ((resolved_cost_basis_id IS NOT NULL) AND (resolved_cost_basis IS NOT NULL) AND (resolved_at IS NOT NULL)))) OR (((mode)::text = 'pinned'::text) AND (currency_cost_basis_id IS NOT NULL) AND (resolved_cost_basis_id IS NOT NULL) AND (resolved_cost_basis_id = currency_cost_basis_id) AND (manual_rate IS NULL) AND (resolved_cost_basis IS NOT NULL) AND (resolved_at IS NOT NULL)) OR (((mode)::text = 'manual'::text) AND (currency_cost_basis_id IS NULL) AND (resolved_cost_basis_id IS NULL) AND (manual_rate > (0)::numeric) AND (resolved_cost_basis IS NOT NULL) AND (resolved_at IS NOT NULL))) +); +-- create index "chargeusagebasedcostbasis_currency_cost_basis_id" to table: "charge_usage_based_cost_bases" +CREATE INDEX "chargeusagebasedcostbasis_currency_cost_basis_id" ON "charge_usage_based_cost_bases" ("currency_cost_basis_id"); +-- create index "chargeusagebasedcostbasis_currency_id" to table: "charge_usage_based_cost_bases" +CREATE INDEX "chargeusagebasedcostbasis_currency_id" ON "charge_usage_based_cost_bases" ("currency_id"); +-- create index "chargeusagebasedcostbasis_id" to table: "charge_usage_based_cost_bases" +CREATE UNIQUE INDEX "chargeusagebasedcostbasis_id" ON "charge_usage_based_cost_bases" ("id"); +-- create index "chargeusagebasedcostbasis_namespace" to table: "charge_usage_based_cost_bases" +CREATE INDEX "chargeusagebasedcostbasis_namespace" ON "charge_usage_based_cost_bases" ("namespace"); +-- create index "chargeusagebasedcostbasis_resolved_cost_basis_id" to table: "charge_usage_based_cost_bases" +CREATE INDEX "chargeusagebasedcostbasis_resolved_cost_basis_id" ON "charge_usage_based_cost_bases" ("resolved_cost_basis_id"); +-- modify "charge_usage_based" table +ALTER TABLE "charge_usage_based" ADD COLUMN "cost_basis_id" character(26) NULL, ADD CONSTRAINT "charge_usage_based_cost_basis_charge_fk" FOREIGN KEY ("cost_basis_id") REFERENCES "charge_usage_based_cost_bases" ("id") ON UPDATE NO ACTION ON DELETE CASCADE; diff --git a/tools/migrate/migrations/atlas.sum b/tools/migrate/migrations/atlas.sum index d17e18fb55..f422231b3b 100644 --- a/tools/migrate/migrations/atlas.sum +++ b/tools/migrate/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:zJM4ULiLNtWs2vWL7Mg2ppmFvdYazvpeGwgnfM2t2dM= +h1:eruJ4NCdirj6K6npl5WW0YbJ6jj03gp0eldeQo2A6hQ= 20240826120919_init.up.sql h1:tc1V91/smlmaeJGQ8h+MzTEeFjjnrrFDbDAjOYJK91o= 20240903155435_entitlement-expired-index.up.sql h1:Hp8u5uckmLXc1cRvWU0AtVnnK8ShlpzZNp8pbiJLhac= 20240917172257_billing-entities.up.sql h1:Q1dAMo0Vjiit76OybClNfYPGC5nmvov2/M2W1ioi4Kw= @@ -241,3 +241,4 @@ h1:zJM4ULiLNtWs2vWL7Mg2ppmFvdYazvpeGwgnfM2t2dM= 20260717160017_custom_currencies.up.sql h1:HHScXLfjVxumxzNrw/RdxZZZMo3EnCE5Min67fEX9jo= 20260720093016_charges-custom-currencies.up.sql h1:U9K4UDDHwNCCqcAQ3n9HFTXaibsm66KPebSa/7XB2OE= 20260721140844_deprecate_detailed_line_currency.up.sql h1:wG5tChhpzGEfeXdAVvpYmLzxKnmqPcACAYvcSdH9sJ0= +20260722145858_add_charge_cost_basis.up.sql h1:fkgfCOoDlg9XsWATSRmBXUywHwTiUfq9FAmRQ0mNGHw=