| |
|
|
| package chargeusagebased |
|
|
| import ( |
| "fmt" |
| "time" |
|
|
| "entgo.io/ent/dialect/sql" |
| "entgo.io/ent/dialect/sql/sqlgraph" |
| "entgo.io/ent/schema/field" |
| "github.com/openmeterio/openmeter/openmeter/billing" |
| "github.com/openmeterio/openmeter/openmeter/billing/charges/meta" |
| "github.com/openmeterio/openmeter/openmeter/billing/charges/usagebased" |
| "github.com/openmeterio/openmeter/openmeter/productcatalog" |
| ) |
|
|
| const ( |
| |
| Label = "charge_usage_based" |
| |
| FieldID = "id" |
| |
| FieldCustomerID = "customer_id" |
| |
| FieldServicePeriodFrom = "service_period_from" |
| |
| FieldServicePeriodTo = "service_period_to" |
| |
| FieldBillingPeriodFrom = "billing_period_from" |
| |
| FieldBillingPeriodTo = "billing_period_to" |
| |
| FieldFullServicePeriodFrom = "full_service_period_from" |
| |
| FieldFullServicePeriodTo = "full_service_period_to" |
| |
| FieldStatus = "status" |
| |
| FieldUniqueReferenceID = "unique_reference_id" |
| |
| FieldCurrency = "currency" |
| |
| FieldManagedBy = "managed_by" |
| |
| FieldSubscriptionID = "subscription_id" |
| |
| FieldSubscriptionPhaseID = "subscription_phase_id" |
| |
| FieldSubscriptionItemID = "subscription_item_id" |
| |
| FieldAdvanceAfter = "advance_after" |
| |
| FieldTaxCodeID = "tax_code_id" |
| |
| FieldTaxBehavior = "tax_behavior" |
| |
| FieldAnnotations = "annotations" |
| |
| FieldNamespace = "namespace" |
| |
| FieldMetadata = "metadata" |
| |
| FieldCreatedAt = "created_at" |
| |
| FieldUpdatedAt = "updated_at" |
| |
| FieldDeletedAt = "deleted_at" |
| |
| FieldName = "name" |
| |
| FieldDescription = "description" |
| |
| FieldInvoiceAt = "invoice_at" |
| |
| FieldSettlementMode = "settlement_mode" |
| |
| FieldIntentDeletedAt = "intent_deleted_at" |
| |
| FieldDiscounts = "discounts" |
| |
| FieldFeatureKey = "feature_key" |
| |
| FieldFeatureID = "feature_id" |
| |
| FieldRatingEngine = "rating_engine" |
| |
| FieldPrice = "price" |
| |
| FieldUnitConfig = "unit_config" |
| |
| FieldCurrentRealizationRunID = "current_realization_run_id" |
| |
| FieldStatusDetailed = "status_detailed" |
| |
| EdgeRuns = "runs" |
| |
| EdgeDetailedLines = "detailed_lines" |
| |
| EdgeCurrentRun = "current_run" |
| |
| EdgeCharge = "charge" |
| |
| EdgeIntentOverride = "intent_override" |
| |
| EdgeSubscription = "subscription" |
| |
| EdgeSubscriptionPhase = "subscription_phase" |
| |
| EdgeSubscriptionItem = "subscription_item" |
| |
| EdgeCustomer = "customer" |
| |
| EdgeFeature = "feature" |
| |
| EdgeTaxCode = "tax_code" |
| |
| Table = "charge_usage_based" |
| |
| RunsTable = "charge_usage_based_runs" |
| |
| |
| RunsInverseTable = "charge_usage_based_runs" |
| |
| RunsColumn = "charge_id" |
| |
| DetailedLinesTable = "charge_usage_based_run_detailed_line" |
| |
| |
| DetailedLinesInverseTable = "charge_usage_based_run_detailed_line" |
| |
| DetailedLinesColumn = "charge_id" |
| |
| CurrentRunTable = "charge_usage_based" |
| |
| |
| CurrentRunInverseTable = "charge_usage_based_runs" |
| |
| CurrentRunColumn = "current_realization_run_id" |
| |
| ChargeTable = "charges" |
| |
| |
| ChargeInverseTable = "charges" |
| |
| ChargeColumn = "charge_usage_based_id" |
| |
| IntentOverrideTable = "charge_usage_based_overrides" |
| |
| |
| IntentOverrideInverseTable = "charge_usage_based_overrides" |
| |
| IntentOverrideColumn = "charge_id" |
| |
| SubscriptionTable = "charge_usage_based" |
| |
| |
| SubscriptionInverseTable = "subscriptions" |
| |
| SubscriptionColumn = "subscription_id" |
| |
| SubscriptionPhaseTable = "charge_usage_based" |
| |
| |
| SubscriptionPhaseInverseTable = "subscription_phases" |
| |
| SubscriptionPhaseColumn = "subscription_phase_id" |
| |
| SubscriptionItemTable = "charge_usage_based" |
| |
| |
| SubscriptionItemInverseTable = "subscription_items" |
| |
| SubscriptionItemColumn = "subscription_item_id" |
| |
| CustomerTable = "charge_usage_based" |
| |
| |
| CustomerInverseTable = "customers" |
| |
| CustomerColumn = "customer_id" |
| |
| FeatureTable = "charge_usage_based" |
| |
| |
| FeatureInverseTable = "features" |
| |
| FeatureColumn = "feature_id" |
| |
| TaxCodeTable = "charge_usage_based" |
| |
| |
| TaxCodeInverseTable = "tax_codes" |
| |
| TaxCodeColumn = "tax_code_id" |
| ) |
|
|
| |
| var Columns = []string{ |
| FieldID, |
| FieldCustomerID, |
| FieldServicePeriodFrom, |
| FieldServicePeriodTo, |
| FieldBillingPeriodFrom, |
| FieldBillingPeriodTo, |
| FieldFullServicePeriodFrom, |
| FieldFullServicePeriodTo, |
| FieldStatus, |
| FieldUniqueReferenceID, |
| FieldCurrency, |
| FieldManagedBy, |
| FieldSubscriptionID, |
| FieldSubscriptionPhaseID, |
| FieldSubscriptionItemID, |
| FieldAdvanceAfter, |
| FieldTaxCodeID, |
| FieldTaxBehavior, |
| FieldAnnotations, |
| FieldNamespace, |
| FieldMetadata, |
| FieldCreatedAt, |
| FieldUpdatedAt, |
| FieldDeletedAt, |
| FieldName, |
| FieldDescription, |
| FieldInvoiceAt, |
| FieldSettlementMode, |
| FieldIntentDeletedAt, |
| FieldDiscounts, |
| FieldFeatureKey, |
| FieldFeatureID, |
| FieldRatingEngine, |
| FieldPrice, |
| FieldUnitConfig, |
| FieldCurrentRealizationRunID, |
| FieldStatusDetailed, |
| } |
|
|
| |
| func ValidColumn(column string) bool { |
| for i := range Columns { |
| if column == Columns[i] { |
| return true |
| } |
| } |
| return false |
| } |
|
|
| var ( |
| |
| CustomerIDValidator func(string) error |
| |
| CurrencyValidator func(string) error |
| |
| TaxCodeIDValidator func(string) error |
| |
| NamespaceValidator func(string) error |
| |
| DefaultCreatedAt func() time.Time |
| |
| DefaultUpdatedAt func() time.Time |
| |
| UpdateDefaultUpdatedAt func() time.Time |
| |
| FeatureKeyValidator func(string) error |
| |
| FeatureIDValidator func(string) error |
| |
| DefaultID func() string |
| |
| ValueScanner struct { |
| Discounts field.TypeValueScanner[*billing.Discounts] |
| Price field.TypeValueScanner[*productcatalog.Price] |
| UnitConfig field.TypeValueScanner[*productcatalog.UnitConfig] |
| } |
| ) |
|
|
| |
| func StatusValidator(s meta.ChargeStatus) error { |
| switch s { |
| case "created", "active", "final", "deleted": |
| return nil |
| default: |
| return fmt.Errorf("chargeusagebased: invalid enum value for status field: %q", s) |
| } |
| } |
|
|
| |
| func ManagedByValidator(mb billing.InvoiceLineManagedBy) error { |
| switch mb { |
| case "subscription", "system", "manual": |
| return nil |
| default: |
| return fmt.Errorf("chargeusagebased: invalid enum value for managed_by field: %q", mb) |
| } |
| } |
|
|
| |
| func TaxBehaviorValidator(tb productcatalog.TaxBehavior) error { |
| switch tb { |
| case "inclusive", "exclusive": |
| return nil |
| default: |
| return fmt.Errorf("chargeusagebased: invalid enum value for tax_behavior field: %q", tb) |
| } |
| } |
|
|
| |
| func SettlementModeValidator(sm productcatalog.SettlementMode) error { |
| switch sm { |
| case "credit_then_invoice", "credit_only": |
| return nil |
| default: |
| return fmt.Errorf("chargeusagebased: invalid enum value for settlement_mode field: %q", sm) |
| } |
| } |
|
|
| |
| func RatingEngineValidator(re usagebased.RatingEngine) error { |
| switch re { |
| case "delta", "period_preserving": |
| return nil |
| default: |
| return fmt.Errorf("chargeusagebased: invalid enum value for rating_engine field: %q", re) |
| } |
| } |
|
|
| |
| func StatusDetailedValidator(sd usagebased.Status) error { |
| switch sd { |
| case "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": |
| return nil |
| default: |
| return fmt.Errorf("chargeusagebased: invalid enum value for status_detailed field: %q", sd) |
| } |
| } |
|
|
| |
| type OrderOption func(*sql.Selector) |
|
|
| |
| func ByID(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldID, opts...).ToFunc() |
| } |
|
|
| |
| func ByCustomerID(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldCustomerID, opts...).ToFunc() |
| } |
|
|
| |
| func ByServicePeriodFrom(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldServicePeriodFrom, opts...).ToFunc() |
| } |
|
|
| |
| func ByServicePeriodTo(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldServicePeriodTo, opts...).ToFunc() |
| } |
|
|
| |
| func ByBillingPeriodFrom(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldBillingPeriodFrom, opts...).ToFunc() |
| } |
|
|
| |
| func ByBillingPeriodTo(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldBillingPeriodTo, opts...).ToFunc() |
| } |
|
|
| |
| func ByFullServicePeriodFrom(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldFullServicePeriodFrom, opts...).ToFunc() |
| } |
|
|
| |
| func ByFullServicePeriodTo(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldFullServicePeriodTo, opts...).ToFunc() |
| } |
|
|
| |
| func ByStatus(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldStatus, opts...).ToFunc() |
| } |
|
|
| |
| func ByUniqueReferenceID(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldUniqueReferenceID, opts...).ToFunc() |
| } |
|
|
| |
| func ByCurrency(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldCurrency, opts...).ToFunc() |
| } |
|
|
| |
| func ByManagedBy(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldManagedBy, opts...).ToFunc() |
| } |
|
|
| |
| func BySubscriptionID(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldSubscriptionID, opts...).ToFunc() |
| } |
|
|
| |
| func BySubscriptionPhaseID(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldSubscriptionPhaseID, opts...).ToFunc() |
| } |
|
|
| |
| func BySubscriptionItemID(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldSubscriptionItemID, opts...).ToFunc() |
| } |
|
|
| |
| func ByAdvanceAfter(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldAdvanceAfter, opts...).ToFunc() |
| } |
|
|
| |
| func ByTaxCodeID(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldTaxCodeID, opts...).ToFunc() |
| } |
|
|
| |
| func ByTaxBehavior(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldTaxBehavior, opts...).ToFunc() |
| } |
|
|
| |
| func ByNamespace(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldNamespace, opts...).ToFunc() |
| } |
|
|
| |
| func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() |
| } |
|
|
| |
| func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() |
| } |
|
|
| |
| func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() |
| } |
|
|
| |
| func ByName(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldName, opts...).ToFunc() |
| } |
|
|
| |
| func ByDescription(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldDescription, opts...).ToFunc() |
| } |
|
|
| |
| func ByInvoiceAt(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldInvoiceAt, opts...).ToFunc() |
| } |
|
|
| |
| func BySettlementMode(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldSettlementMode, opts...).ToFunc() |
| } |
|
|
| |
| func ByIntentDeletedAt(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldIntentDeletedAt, opts...).ToFunc() |
| } |
|
|
| |
| func ByDiscounts(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldDiscounts, opts...).ToFunc() |
| } |
|
|
| |
| func ByFeatureKey(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldFeatureKey, opts...).ToFunc() |
| } |
|
|
| |
| func ByFeatureID(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldFeatureID, opts...).ToFunc() |
| } |
|
|
| |
| func ByRatingEngine(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldRatingEngine, opts...).ToFunc() |
| } |
|
|
| |
| func ByPrice(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldPrice, opts...).ToFunc() |
| } |
|
|
| |
| func ByUnitConfig(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldUnitConfig, opts...).ToFunc() |
| } |
|
|
| |
| func ByCurrentRealizationRunID(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldCurrentRealizationRunID, opts...).ToFunc() |
| } |
|
|
| |
| func ByStatusDetailed(opts ...sql.OrderTermOption) OrderOption { |
| return sql.OrderByField(FieldStatusDetailed, opts...).ToFunc() |
| } |
|
|
| |
| func ByRunsCount(opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborsCount(s, newRunsStep(), opts...) |
| } |
| } |
|
|
| |
| func ByRuns(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newRunsStep(), append([]sql.OrderTerm{term}, terms...)...) |
| } |
| } |
|
|
| |
| func ByDetailedLinesCount(opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborsCount(s, newDetailedLinesStep(), opts...) |
| } |
| } |
|
|
| |
| func ByDetailedLines(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newDetailedLinesStep(), append([]sql.OrderTerm{term}, terms...)...) |
| } |
| } |
|
|
| |
| func ByCurrentRunField(field string, opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newCurrentRunStep(), sql.OrderByField(field, opts...)) |
| } |
| } |
|
|
| |
| func ByChargeField(field string, opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newChargeStep(), sql.OrderByField(field, opts...)) |
| } |
| } |
|
|
| |
| func ByIntentOverrideField(field string, opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newIntentOverrideStep(), sql.OrderByField(field, opts...)) |
| } |
| } |
|
|
| |
| func BySubscriptionField(field string, opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newSubscriptionStep(), sql.OrderByField(field, opts...)) |
| } |
| } |
|
|
| |
| func BySubscriptionPhaseField(field string, opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newSubscriptionPhaseStep(), sql.OrderByField(field, opts...)) |
| } |
| } |
|
|
| |
| func BySubscriptionItemField(field string, opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newSubscriptionItemStep(), sql.OrderByField(field, opts...)) |
| } |
| } |
|
|
| |
| func ByCustomerField(field string, opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newCustomerStep(), sql.OrderByField(field, opts...)) |
| } |
| } |
|
|
| |
| func ByFeatureField(field string, opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newFeatureStep(), sql.OrderByField(field, opts...)) |
| } |
| } |
|
|
| |
| func ByTaxCodeField(field string, opts ...sql.OrderTermOption) OrderOption { |
| return func(s *sql.Selector) { |
| sqlgraph.OrderByNeighborTerms(s, newTaxCodeStep(), sql.OrderByField(field, opts...)) |
| } |
| } |
| func newRunsStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(RunsInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.O2M, false, RunsTable, RunsColumn), |
| ) |
| } |
| func newDetailedLinesStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(DetailedLinesInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.O2M, false, DetailedLinesTable, DetailedLinesColumn), |
| ) |
| } |
| func newCurrentRunStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(CurrentRunInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.M2O, false, CurrentRunTable, CurrentRunColumn), |
| ) |
| } |
| func newChargeStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(ChargeInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.O2O, false, ChargeTable, ChargeColumn), |
| ) |
| } |
| func newIntentOverrideStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(IntentOverrideInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.O2O, false, IntentOverrideTable, IntentOverrideColumn), |
| ) |
| } |
| func newSubscriptionStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(SubscriptionInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.M2O, true, SubscriptionTable, SubscriptionColumn), |
| ) |
| } |
| func newSubscriptionPhaseStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(SubscriptionPhaseInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.M2O, true, SubscriptionPhaseTable, SubscriptionPhaseColumn), |
| ) |
| } |
| func newSubscriptionItemStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(SubscriptionItemInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.M2O, true, SubscriptionItemTable, SubscriptionItemColumn), |
| ) |
| } |
| func newCustomerStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(CustomerInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.M2O, true, CustomerTable, CustomerColumn), |
| ) |
| } |
| func newFeatureStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(FeatureInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.M2O, true, FeatureTable, FeatureColumn), |
| ) |
| } |
| func newTaxCodeStep() *sqlgraph.Step { |
| return sqlgraph.NewStep( |
| sqlgraph.From(Table, FieldID), |
| sqlgraph.To(TaxCodeInverseTable, FieldID), |
| sqlgraph.Edge(sqlgraph.M2O, true, TaxCodeTable, TaxCodeColumn), |
| ) |
| } |
|
|