// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"sync"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/Wei-Shaw/sub2api/ent/account"
	"github.com/Wei-Shaw/sub2api/ent/accountgroup"
	"github.com/Wei-Shaw/sub2api/ent/announcement"
	"github.com/Wei-Shaw/sub2api/ent/announcementread"
	"github.com/Wei-Shaw/sub2api/ent/apikey"
	"github.com/Wei-Shaw/sub2api/ent/authidentity"
	"github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
	"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
	"github.com/Wei-Shaw/sub2api/ent/group"
	"github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
	"github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
	"github.com/Wei-Shaw/sub2api/ent/paymentauditlog"
	"github.com/Wei-Shaw/sub2api/ent/paymentorder"
	"github.com/Wei-Shaw/sub2api/ent/paymentproviderinstance"
	"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
	"github.com/Wei-Shaw/sub2api/ent/predicate"
	"github.com/Wei-Shaw/sub2api/ent/promocode"
	"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
	"github.com/Wei-Shaw/sub2api/ent/proxy"
	"github.com/Wei-Shaw/sub2api/ent/redeemcode"
	"github.com/Wei-Shaw/sub2api/ent/securitysecret"
	"github.com/Wei-Shaw/sub2api/ent/setting"
	"github.com/Wei-Shaw/sub2api/ent/subscriptionplan"
	"github.com/Wei-Shaw/sub2api/ent/tlsfingerprintprofile"
	"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
	"github.com/Wei-Shaw/sub2api/ent/usagelog"
	"github.com/Wei-Shaw/sub2api/ent/user"
	"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
	"github.com/Wei-Shaw/sub2api/ent/userattributedefinition"
	"github.com/Wei-Shaw/sub2api/ent/userattributevalue"
	"github.com/Wei-Shaw/sub2api/ent/usersubscription"
	"github.com/Wei-Shaw/sub2api/internal/domain"
)

const (
	// Operation types.
	OpCreate    = ent.OpCreate
	OpDelete    = ent.OpDelete
	OpDeleteOne = ent.OpDeleteOne
	OpUpdate    = ent.OpUpdate
	OpUpdateOne = ent.OpUpdateOne

	// Node types.
	TypeAPIKey                   = "APIKey"
	TypeAccount                  = "Account"
	TypeAccountGroup             = "AccountGroup"
	TypeAnnouncement             = "Announcement"
	TypeAnnouncementRead         = "AnnouncementRead"
	TypeAuthIdentity             = "AuthIdentity"
	TypeAuthIdentityChannel      = "AuthIdentityChannel"
	TypeErrorPassthroughRule     = "ErrorPassthroughRule"
	TypeGroup                    = "Group"
	TypeIdempotencyRecord        = "IdempotencyRecord"
	TypeIdentityAdoptionDecision = "IdentityAdoptionDecision"
	TypePaymentAuditLog          = "PaymentAuditLog"
	TypePaymentOrder             = "PaymentOrder"
	TypePaymentProviderInstance  = "PaymentProviderInstance"
	TypePendingAuthSession       = "PendingAuthSession"
	TypePromoCode                = "PromoCode"
	TypePromoCodeUsage           = "PromoCodeUsage"
	TypeProxy                    = "Proxy"
	TypeRedeemCode               = "RedeemCode"
	TypeSecuritySecret           = "SecuritySecret"
	TypeSetting                  = "Setting"
	TypeSubscriptionPlan         = "SubscriptionPlan"
	TypeTLSFingerprintProfile    = "TLSFingerprintProfile"
	TypeUsageCleanupTask         = "UsageCleanupTask"
	TypeUsageLog                 = "UsageLog"
	TypeUser                     = "User"
	TypeUserAllowedGroup         = "UserAllowedGroup"
	TypeUserAttributeDefinition  = "UserAttributeDefinition"
	TypeUserAttributeValue       = "UserAttributeValue"
	TypeUserSubscription         = "UserSubscription"
)

// APIKeyMutation represents an operation that mutates the APIKey nodes in the graph.
type APIKeyMutation struct {
	config
	op                 Op
	typ                string
	id                 *int64
	created_at         *time.Time
	updated_at         *time.Time
	deleted_at         *time.Time
	key                *string
	name               *string
	status             *string
	last_used_at       *time.Time
	ip_whitelist       *[]string
	appendip_whitelist []string
	ip_blacklist       *[]string
	appendip_blacklist []string
	quota              *float64
	addquota           *float64
	quota_used         *float64
	addquota_used      *float64
	expires_at         *time.Time
	rate_limit_5h      *float64
	addrate_limit_5h   *float64
	rate_limit_1d      *float64
	addrate_limit_1d   *float64
	rate_limit_7d      *float64
	addrate_limit_7d   *float64
	usage_5h           *float64
	addusage_5h        *float64
	usage_1d           *float64
	addusage_1d        *float64
	usage_7d           *float64
	addusage_7d        *float64
	window_5h_start    *time.Time
	window_1d_start    *time.Time
	window_7d_start    *time.Time
	clearedFields      map[string]struct{}
	user               *int64
	cleareduser        bool
	group              *int64
	clearedgroup       bool
	usage_logs         map[int64]struct{}
	removedusage_logs  map[int64]struct{}
	clearedusage_logs  bool
	done               bool
	oldValue           func(context.Context) (*APIKey, error)
	predicates         []predicate.APIKey
}

var _ ent.Mutation = (*APIKeyMutation)(nil)

// apikeyOption allows management of the mutation configuration using functional options.
type apikeyOption func(*APIKeyMutation)

// newAPIKeyMutation creates new mutation for the APIKey entity.
func newAPIKeyMutation(c config, op Op, opts ...apikeyOption) *APIKeyMutation {
	m := &APIKeyMutation{
		config:        c,
		op:            op,
		typ:           TypeAPIKey,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withAPIKeyID sets the ID field of the mutation.
func withAPIKeyID(id int64) apikeyOption {
	return func(m *APIKeyMutation) {
		var (
			err   error
			once  sync.Once
			value *APIKey
		)
		m.oldValue = func(ctx context.Context) (*APIKey, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().APIKey.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withAPIKey sets the old APIKey of the mutation.
func withAPIKey(node *APIKey) apikeyOption {
	return func(m *APIKeyMutation) {
		m.oldValue = func(context.Context) (*APIKey, 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 APIKeyMutation) 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 APIKeyMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *APIKeyMutation) ID() (id int64, 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 *APIKeyMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().APIKey.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *APIKeyMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *APIKeyMutation) 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 APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) 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 *APIKeyMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *APIKeyMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *APIKeyMutation) 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 APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) 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 *APIKeyMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetDeletedAt sets the "deleted_at" field.
func (m *APIKeyMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *APIKeyMutation) 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 APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) 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 *APIKeyMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[apikey.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *APIKeyMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[apikey.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *APIKeyMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, apikey.FieldDeletedAt)
}

// SetUserID sets the "user_id" field.
func (m *APIKeyMutation) SetUserID(i int64) {
	m.user = &i
}

// UserID returns the value of the "user_id" field in the mutation.
func (m *APIKeyMutation) UserID() (r int64, exists bool) {
	v := m.user
	if v == nil {
		return
	}
	return *v, true
}

// OldUserID returns the old "user_id" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldUserID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
	}
	return oldValue.UserID, nil
}

// ResetUserID resets all changes to the "user_id" field.
func (m *APIKeyMutation) ResetUserID() {
	m.user = nil
}

// SetKey sets the "key" field.
func (m *APIKeyMutation) SetKey(s string) {
	m.key = &s
}

// Key returns the value of the "key" field in the mutation.
func (m *APIKeyMutation) Key() (r string, exists bool) {
	v := m.key
	if v == nil {
		return
	}
	return *v, true
}

// OldKey returns the old "key" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldKey(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldKey is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldKey requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldKey: %w", err)
	}
	return oldValue.Key, nil
}

// ResetKey resets all changes to the "key" field.
func (m *APIKeyMutation) ResetKey() {
	m.key = nil
}

// SetName sets the "name" field.
func (m *APIKeyMutation) SetName(s string) {
	m.name = &s
}

// Name returns the value of the "name" field in the mutation.
func (m *APIKeyMutation) 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 APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) 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 *APIKeyMutation) ResetName() {
	m.name = nil
}

// SetGroupID sets the "group_id" field.
func (m *APIKeyMutation) SetGroupID(i int64) {
	m.group = &i
}

// GroupID returns the value of the "group_id" field in the mutation.
func (m *APIKeyMutation) GroupID() (r int64, exists bool) {
	v := m.group
	if v == nil {
		return
	}
	return *v, true
}

// OldGroupID returns the old "group_id" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldGroupID(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldGroupID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldGroupID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldGroupID: %w", err)
	}
	return oldValue.GroupID, nil
}

// ClearGroupID clears the value of the "group_id" field.
func (m *APIKeyMutation) ClearGroupID() {
	m.group = nil
	m.clearedFields[apikey.FieldGroupID] = struct{}{}
}

// GroupIDCleared returns if the "group_id" field was cleared in this mutation.
func (m *APIKeyMutation) GroupIDCleared() bool {
	_, ok := m.clearedFields[apikey.FieldGroupID]
	return ok
}

// ResetGroupID resets all changes to the "group_id" field.
func (m *APIKeyMutation) ResetGroupID() {
	m.group = nil
	delete(m.clearedFields, apikey.FieldGroupID)
}

// SetStatus sets the "status" field.
func (m *APIKeyMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *APIKeyMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldStatus(ctx context.Context) (v string, 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 *APIKeyMutation) ResetStatus() {
	m.status = nil
}

// SetLastUsedAt sets the "last_used_at" field.
func (m *APIKeyMutation) SetLastUsedAt(t time.Time) {
	m.last_used_at = &t
}

// LastUsedAt returns the value of the "last_used_at" field in the mutation.
func (m *APIKeyMutation) LastUsedAt() (r time.Time, exists bool) {
	v := m.last_used_at
	if v == nil {
		return
	}
	return *v, true
}

// OldLastUsedAt returns the old "last_used_at" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldLastUsedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLastUsedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLastUsedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLastUsedAt: %w", err)
	}
	return oldValue.LastUsedAt, nil
}

// ClearLastUsedAt clears the value of the "last_used_at" field.
func (m *APIKeyMutation) ClearLastUsedAt() {
	m.last_used_at = nil
	m.clearedFields[apikey.FieldLastUsedAt] = struct{}{}
}

// LastUsedAtCleared returns if the "last_used_at" field was cleared in this mutation.
func (m *APIKeyMutation) LastUsedAtCleared() bool {
	_, ok := m.clearedFields[apikey.FieldLastUsedAt]
	return ok
}

// ResetLastUsedAt resets all changes to the "last_used_at" field.
func (m *APIKeyMutation) ResetLastUsedAt() {
	m.last_used_at = nil
	delete(m.clearedFields, apikey.FieldLastUsedAt)
}

// SetIPWhitelist sets the "ip_whitelist" field.
func (m *APIKeyMutation) SetIPWhitelist(s []string) {
	m.ip_whitelist = &s
	m.appendip_whitelist = nil
}

// IPWhitelist returns the value of the "ip_whitelist" field in the mutation.
func (m *APIKeyMutation) IPWhitelist() (r []string, exists bool) {
	v := m.ip_whitelist
	if v == nil {
		return
	}
	return *v, true
}

// OldIPWhitelist returns the old "ip_whitelist" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldIPWhitelist(ctx context.Context) (v []string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldIPWhitelist is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldIPWhitelist requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldIPWhitelist: %w", err)
	}
	return oldValue.IPWhitelist, nil
}

// AppendIPWhitelist adds s to the "ip_whitelist" field.
func (m *APIKeyMutation) AppendIPWhitelist(s []string) {
	m.appendip_whitelist = append(m.appendip_whitelist, s...)
}

// AppendedIPWhitelist returns the list of values that were appended to the "ip_whitelist" field in this mutation.
func (m *APIKeyMutation) AppendedIPWhitelist() ([]string, bool) {
	if len(m.appendip_whitelist) == 0 {
		return nil, false
	}
	return m.appendip_whitelist, true
}

// ClearIPWhitelist clears the value of the "ip_whitelist" field.
func (m *APIKeyMutation) ClearIPWhitelist() {
	m.ip_whitelist = nil
	m.appendip_whitelist = nil
	m.clearedFields[apikey.FieldIPWhitelist] = struct{}{}
}

// IPWhitelistCleared returns if the "ip_whitelist" field was cleared in this mutation.
func (m *APIKeyMutation) IPWhitelistCleared() bool {
	_, ok := m.clearedFields[apikey.FieldIPWhitelist]
	return ok
}

// ResetIPWhitelist resets all changes to the "ip_whitelist" field.
func (m *APIKeyMutation) ResetIPWhitelist() {
	m.ip_whitelist = nil
	m.appendip_whitelist = nil
	delete(m.clearedFields, apikey.FieldIPWhitelist)
}

// SetIPBlacklist sets the "ip_blacklist" field.
func (m *APIKeyMutation) SetIPBlacklist(s []string) {
	m.ip_blacklist = &s
	m.appendip_blacklist = nil
}

// IPBlacklist returns the value of the "ip_blacklist" field in the mutation.
func (m *APIKeyMutation) IPBlacklist() (r []string, exists bool) {
	v := m.ip_blacklist
	if v == nil {
		return
	}
	return *v, true
}

// OldIPBlacklist returns the old "ip_blacklist" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldIPBlacklist(ctx context.Context) (v []string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldIPBlacklist is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldIPBlacklist requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldIPBlacklist: %w", err)
	}
	return oldValue.IPBlacklist, nil
}

// AppendIPBlacklist adds s to the "ip_blacklist" field.
func (m *APIKeyMutation) AppendIPBlacklist(s []string) {
	m.appendip_blacklist = append(m.appendip_blacklist, s...)
}

// AppendedIPBlacklist returns the list of values that were appended to the "ip_blacklist" field in this mutation.
func (m *APIKeyMutation) AppendedIPBlacklist() ([]string, bool) {
	if len(m.appendip_blacklist) == 0 {
		return nil, false
	}
	return m.appendip_blacklist, true
}

// ClearIPBlacklist clears the value of the "ip_blacklist" field.
func (m *APIKeyMutation) ClearIPBlacklist() {
	m.ip_blacklist = nil
	m.appendip_blacklist = nil
	m.clearedFields[apikey.FieldIPBlacklist] = struct{}{}
}

// IPBlacklistCleared returns if the "ip_blacklist" field was cleared in this mutation.
func (m *APIKeyMutation) IPBlacklistCleared() bool {
	_, ok := m.clearedFields[apikey.FieldIPBlacklist]
	return ok
}

// ResetIPBlacklist resets all changes to the "ip_blacklist" field.
func (m *APIKeyMutation) ResetIPBlacklist() {
	m.ip_blacklist = nil
	m.appendip_blacklist = nil
	delete(m.clearedFields, apikey.FieldIPBlacklist)
}

// SetQuota sets the "quota" field.
func (m *APIKeyMutation) SetQuota(f float64) {
	m.quota = &f
	m.addquota = nil
}

// Quota returns the value of the "quota" field in the mutation.
func (m *APIKeyMutation) Quota() (r float64, exists bool) {
	v := m.quota
	if v == nil {
		return
	}
	return *v, true
}

// OldQuota returns the old "quota" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldQuota(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldQuota is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldQuota requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldQuota: %w", err)
	}
	return oldValue.Quota, nil
}

// AddQuota adds f to the "quota" field.
func (m *APIKeyMutation) AddQuota(f float64) {
	if m.addquota != nil {
		*m.addquota += f
	} else {
		m.addquota = &f
	}
}

// AddedQuota returns the value that was added to the "quota" field in this mutation.
func (m *APIKeyMutation) AddedQuota() (r float64, exists bool) {
	v := m.addquota
	if v == nil {
		return
	}
	return *v, true
}

// ResetQuota resets all changes to the "quota" field.
func (m *APIKeyMutation) ResetQuota() {
	m.quota = nil
	m.addquota = nil
}

// SetQuotaUsed sets the "quota_used" field.
func (m *APIKeyMutation) SetQuotaUsed(f float64) {
	m.quota_used = &f
	m.addquota_used = nil
}

// QuotaUsed returns the value of the "quota_used" field in the mutation.
func (m *APIKeyMutation) QuotaUsed() (r float64, exists bool) {
	v := m.quota_used
	if v == nil {
		return
	}
	return *v, true
}

// OldQuotaUsed returns the old "quota_used" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldQuotaUsed(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldQuotaUsed is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldQuotaUsed requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldQuotaUsed: %w", err)
	}
	return oldValue.QuotaUsed, nil
}

// AddQuotaUsed adds f to the "quota_used" field.
func (m *APIKeyMutation) AddQuotaUsed(f float64) {
	if m.addquota_used != nil {
		*m.addquota_used += f
	} else {
		m.addquota_used = &f
	}
}

// AddedQuotaUsed returns the value that was added to the "quota_used" field in this mutation.
func (m *APIKeyMutation) AddedQuotaUsed() (r float64, exists bool) {
	v := m.addquota_used
	if v == nil {
		return
	}
	return *v, true
}

// ResetQuotaUsed resets all changes to the "quota_used" field.
func (m *APIKeyMutation) ResetQuotaUsed() {
	m.quota_used = nil
	m.addquota_used = nil
}

// SetExpiresAt sets the "expires_at" field.
func (m *APIKeyMutation) SetExpiresAt(t time.Time) {
	m.expires_at = &t
}

// ExpiresAt returns the value of the "expires_at" field in the mutation.
func (m *APIKeyMutation) ExpiresAt() (r time.Time, exists bool) {
	v := m.expires_at
	if v == nil {
		return
	}
	return *v, true
}

// OldExpiresAt returns the old "expires_at" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldExpiresAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldExpiresAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err)
	}
	return oldValue.ExpiresAt, nil
}

// ClearExpiresAt clears the value of the "expires_at" field.
func (m *APIKeyMutation) ClearExpiresAt() {
	m.expires_at = nil
	m.clearedFields[apikey.FieldExpiresAt] = struct{}{}
}

// ExpiresAtCleared returns if the "expires_at" field was cleared in this mutation.
func (m *APIKeyMutation) ExpiresAtCleared() bool {
	_, ok := m.clearedFields[apikey.FieldExpiresAt]
	return ok
}

// ResetExpiresAt resets all changes to the "expires_at" field.
func (m *APIKeyMutation) ResetExpiresAt() {
	m.expires_at = nil
	delete(m.clearedFields, apikey.FieldExpiresAt)
}

// SetRateLimit5h sets the "rate_limit_5h" field.
func (m *APIKeyMutation) SetRateLimit5h(f float64) {
	m.rate_limit_5h = &f
	m.addrate_limit_5h = nil
}

// RateLimit5h returns the value of the "rate_limit_5h" field in the mutation.
func (m *APIKeyMutation) RateLimit5h() (r float64, exists bool) {
	v := m.rate_limit_5h
	if v == nil {
		return
	}
	return *v, true
}

// OldRateLimit5h returns the old "rate_limit_5h" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldRateLimit5h(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRateLimit5h is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRateLimit5h requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRateLimit5h: %w", err)
	}
	return oldValue.RateLimit5h, nil
}

// AddRateLimit5h adds f to the "rate_limit_5h" field.
func (m *APIKeyMutation) AddRateLimit5h(f float64) {
	if m.addrate_limit_5h != nil {
		*m.addrate_limit_5h += f
	} else {
		m.addrate_limit_5h = &f
	}
}

// AddedRateLimit5h returns the value that was added to the "rate_limit_5h" field in this mutation.
func (m *APIKeyMutation) AddedRateLimit5h() (r float64, exists bool) {
	v := m.addrate_limit_5h
	if v == nil {
		return
	}
	return *v, true
}

// ResetRateLimit5h resets all changes to the "rate_limit_5h" field.
func (m *APIKeyMutation) ResetRateLimit5h() {
	m.rate_limit_5h = nil
	m.addrate_limit_5h = nil
}

// SetRateLimit1d sets the "rate_limit_1d" field.
func (m *APIKeyMutation) SetRateLimit1d(f float64) {
	m.rate_limit_1d = &f
	m.addrate_limit_1d = nil
}

// RateLimit1d returns the value of the "rate_limit_1d" field in the mutation.
func (m *APIKeyMutation) RateLimit1d() (r float64, exists bool) {
	v := m.rate_limit_1d
	if v == nil {
		return
	}
	return *v, true
}

// OldRateLimit1d returns the old "rate_limit_1d" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldRateLimit1d(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRateLimit1d is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRateLimit1d requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRateLimit1d: %w", err)
	}
	return oldValue.RateLimit1d, nil
}

// AddRateLimit1d adds f to the "rate_limit_1d" field.
func (m *APIKeyMutation) AddRateLimit1d(f float64) {
	if m.addrate_limit_1d != nil {
		*m.addrate_limit_1d += f
	} else {
		m.addrate_limit_1d = &f
	}
}

// AddedRateLimit1d returns the value that was added to the "rate_limit_1d" field in this mutation.
func (m *APIKeyMutation) AddedRateLimit1d() (r float64, exists bool) {
	v := m.addrate_limit_1d
	if v == nil {
		return
	}
	return *v, true
}

// ResetRateLimit1d resets all changes to the "rate_limit_1d" field.
func (m *APIKeyMutation) ResetRateLimit1d() {
	m.rate_limit_1d = nil
	m.addrate_limit_1d = nil
}

// SetRateLimit7d sets the "rate_limit_7d" field.
func (m *APIKeyMutation) SetRateLimit7d(f float64) {
	m.rate_limit_7d = &f
	m.addrate_limit_7d = nil
}

// RateLimit7d returns the value of the "rate_limit_7d" field in the mutation.
func (m *APIKeyMutation) RateLimit7d() (r float64, exists bool) {
	v := m.rate_limit_7d
	if v == nil {
		return
	}
	return *v, true
}

// OldRateLimit7d returns the old "rate_limit_7d" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldRateLimit7d(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRateLimit7d is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRateLimit7d requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRateLimit7d: %w", err)
	}
	return oldValue.RateLimit7d, nil
}

// AddRateLimit7d adds f to the "rate_limit_7d" field.
func (m *APIKeyMutation) AddRateLimit7d(f float64) {
	if m.addrate_limit_7d != nil {
		*m.addrate_limit_7d += f
	} else {
		m.addrate_limit_7d = &f
	}
}

// AddedRateLimit7d returns the value that was added to the "rate_limit_7d" field in this mutation.
func (m *APIKeyMutation) AddedRateLimit7d() (r float64, exists bool) {
	v := m.addrate_limit_7d
	if v == nil {
		return
	}
	return *v, true
}

// ResetRateLimit7d resets all changes to the "rate_limit_7d" field.
func (m *APIKeyMutation) ResetRateLimit7d() {
	m.rate_limit_7d = nil
	m.addrate_limit_7d = nil
}

// SetUsage5h sets the "usage_5h" field.
func (m *APIKeyMutation) SetUsage5h(f float64) {
	m.usage_5h = &f
	m.addusage_5h = nil
}

// Usage5h returns the value of the "usage_5h" field in the mutation.
func (m *APIKeyMutation) Usage5h() (r float64, exists bool) {
	v := m.usage_5h
	if v == nil {
		return
	}
	return *v, true
}

// OldUsage5h returns the old "usage_5h" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldUsage5h(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUsage5h is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUsage5h requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUsage5h: %w", err)
	}
	return oldValue.Usage5h, nil
}

// AddUsage5h adds f to the "usage_5h" field.
func (m *APIKeyMutation) AddUsage5h(f float64) {
	if m.addusage_5h != nil {
		*m.addusage_5h += f
	} else {
		m.addusage_5h = &f
	}
}

// AddedUsage5h returns the value that was added to the "usage_5h" field in this mutation.
func (m *APIKeyMutation) AddedUsage5h() (r float64, exists bool) {
	v := m.addusage_5h
	if v == nil {
		return
	}
	return *v, true
}

// ResetUsage5h resets all changes to the "usage_5h" field.
func (m *APIKeyMutation) ResetUsage5h() {
	m.usage_5h = nil
	m.addusage_5h = nil
}

// SetUsage1d sets the "usage_1d" field.
func (m *APIKeyMutation) SetUsage1d(f float64) {
	m.usage_1d = &f
	m.addusage_1d = nil
}

// Usage1d returns the value of the "usage_1d" field in the mutation.
func (m *APIKeyMutation) Usage1d() (r float64, exists bool) {
	v := m.usage_1d
	if v == nil {
		return
	}
	return *v, true
}

// OldUsage1d returns the old "usage_1d" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldUsage1d(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUsage1d is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUsage1d requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUsage1d: %w", err)
	}
	return oldValue.Usage1d, nil
}

// AddUsage1d adds f to the "usage_1d" field.
func (m *APIKeyMutation) AddUsage1d(f float64) {
	if m.addusage_1d != nil {
		*m.addusage_1d += f
	} else {
		m.addusage_1d = &f
	}
}

// AddedUsage1d returns the value that was added to the "usage_1d" field in this mutation.
func (m *APIKeyMutation) AddedUsage1d() (r float64, exists bool) {
	v := m.addusage_1d
	if v == nil {
		return
	}
	return *v, true
}

// ResetUsage1d resets all changes to the "usage_1d" field.
func (m *APIKeyMutation) ResetUsage1d() {
	m.usage_1d = nil
	m.addusage_1d = nil
}

// SetUsage7d sets the "usage_7d" field.
func (m *APIKeyMutation) SetUsage7d(f float64) {
	m.usage_7d = &f
	m.addusage_7d = nil
}

// Usage7d returns the value of the "usage_7d" field in the mutation.
func (m *APIKeyMutation) Usage7d() (r float64, exists bool) {
	v := m.usage_7d
	if v == nil {
		return
	}
	return *v, true
}

// OldUsage7d returns the old "usage_7d" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldUsage7d(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUsage7d is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUsage7d requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUsage7d: %w", err)
	}
	return oldValue.Usage7d, nil
}

// AddUsage7d adds f to the "usage_7d" field.
func (m *APIKeyMutation) AddUsage7d(f float64) {
	if m.addusage_7d != nil {
		*m.addusage_7d += f
	} else {
		m.addusage_7d = &f
	}
}

// AddedUsage7d returns the value that was added to the "usage_7d" field in this mutation.
func (m *APIKeyMutation) AddedUsage7d() (r float64, exists bool) {
	v := m.addusage_7d
	if v == nil {
		return
	}
	return *v, true
}

// ResetUsage7d resets all changes to the "usage_7d" field.
func (m *APIKeyMutation) ResetUsage7d() {
	m.usage_7d = nil
	m.addusage_7d = nil
}

// SetWindow5hStart sets the "window_5h_start" field.
func (m *APIKeyMutation) SetWindow5hStart(t time.Time) {
	m.window_5h_start = &t
}

// Window5hStart returns the value of the "window_5h_start" field in the mutation.
func (m *APIKeyMutation) Window5hStart() (r time.Time, exists bool) {
	v := m.window_5h_start
	if v == nil {
		return
	}
	return *v, true
}

// OldWindow5hStart returns the old "window_5h_start" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldWindow5hStart(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWindow5hStart is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWindow5hStart requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWindow5hStart: %w", err)
	}
	return oldValue.Window5hStart, nil
}

// ClearWindow5hStart clears the value of the "window_5h_start" field.
func (m *APIKeyMutation) ClearWindow5hStart() {
	m.window_5h_start = nil
	m.clearedFields[apikey.FieldWindow5hStart] = struct{}{}
}

// Window5hStartCleared returns if the "window_5h_start" field was cleared in this mutation.
func (m *APIKeyMutation) Window5hStartCleared() bool {
	_, ok := m.clearedFields[apikey.FieldWindow5hStart]
	return ok
}

// ResetWindow5hStart resets all changes to the "window_5h_start" field.
func (m *APIKeyMutation) ResetWindow5hStart() {
	m.window_5h_start = nil
	delete(m.clearedFields, apikey.FieldWindow5hStart)
}

// SetWindow1dStart sets the "window_1d_start" field.
func (m *APIKeyMutation) SetWindow1dStart(t time.Time) {
	m.window_1d_start = &t
}

// Window1dStart returns the value of the "window_1d_start" field in the mutation.
func (m *APIKeyMutation) Window1dStart() (r time.Time, exists bool) {
	v := m.window_1d_start
	if v == nil {
		return
	}
	return *v, true
}

// OldWindow1dStart returns the old "window_1d_start" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldWindow1dStart(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWindow1dStart is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWindow1dStart requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWindow1dStart: %w", err)
	}
	return oldValue.Window1dStart, nil
}

// ClearWindow1dStart clears the value of the "window_1d_start" field.
func (m *APIKeyMutation) ClearWindow1dStart() {
	m.window_1d_start = nil
	m.clearedFields[apikey.FieldWindow1dStart] = struct{}{}
}

// Window1dStartCleared returns if the "window_1d_start" field was cleared in this mutation.
func (m *APIKeyMutation) Window1dStartCleared() bool {
	_, ok := m.clearedFields[apikey.FieldWindow1dStart]
	return ok
}

// ResetWindow1dStart resets all changes to the "window_1d_start" field.
func (m *APIKeyMutation) ResetWindow1dStart() {
	m.window_1d_start = nil
	delete(m.clearedFields, apikey.FieldWindow1dStart)
}

// SetWindow7dStart sets the "window_7d_start" field.
func (m *APIKeyMutation) SetWindow7dStart(t time.Time) {
	m.window_7d_start = &t
}

// Window7dStart returns the value of the "window_7d_start" field in the mutation.
func (m *APIKeyMutation) Window7dStart() (r time.Time, exists bool) {
	v := m.window_7d_start
	if v == nil {
		return
	}
	return *v, true
}

// OldWindow7dStart returns the old "window_7d_start" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldWindow7dStart(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWindow7dStart is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWindow7dStart requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWindow7dStart: %w", err)
	}
	return oldValue.Window7dStart, nil
}

// ClearWindow7dStart clears the value of the "window_7d_start" field.
func (m *APIKeyMutation) ClearWindow7dStart() {
	m.window_7d_start = nil
	m.clearedFields[apikey.FieldWindow7dStart] = struct{}{}
}

// Window7dStartCleared returns if the "window_7d_start" field was cleared in this mutation.
func (m *APIKeyMutation) Window7dStartCleared() bool {
	_, ok := m.clearedFields[apikey.FieldWindow7dStart]
	return ok
}

// ResetWindow7dStart resets all changes to the "window_7d_start" field.
func (m *APIKeyMutation) ResetWindow7dStart() {
	m.window_7d_start = nil
	delete(m.clearedFields, apikey.FieldWindow7dStart)
}

// ClearUser clears the "user" edge to the User entity.
func (m *APIKeyMutation) ClearUser() {
	m.cleareduser = true
	m.clearedFields[apikey.FieldUserID] = struct{}{}
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *APIKeyMutation) UserCleared() bool {
	return m.cleareduser
}

// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *APIKeyMutation) UserIDs() (ids []int64) {
	if id := m.user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetUser resets all changes to the "user" edge.
func (m *APIKeyMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

// ClearGroup clears the "group" edge to the Group entity.
func (m *APIKeyMutation) ClearGroup() {
	m.clearedgroup = true
	m.clearedFields[apikey.FieldGroupID] = struct{}{}
}

// GroupCleared reports if the "group" edge to the Group entity was cleared.
func (m *APIKeyMutation) GroupCleared() bool {
	return m.GroupIDCleared() || m.clearedgroup
}

// GroupIDs returns the "group" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// GroupID instead. It exists only for internal usage by the builders.
func (m *APIKeyMutation) GroupIDs() (ids []int64) {
	if id := m.group; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetGroup resets all changes to the "group" edge.
func (m *APIKeyMutation) ResetGroup() {
	m.group = nil
	m.clearedgroup = false
}

// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by ids.
func (m *APIKeyMutation) AddUsageLogIDs(ids ...int64) {
	if m.usage_logs == nil {
		m.usage_logs = make(map[int64]struct{})
	}
	for i := range ids {
		m.usage_logs[ids[i]] = struct{}{}
	}
}

// ClearUsageLogs clears the "usage_logs" edge to the UsageLog entity.
func (m *APIKeyMutation) ClearUsageLogs() {
	m.clearedusage_logs = true
}

// UsageLogsCleared reports if the "usage_logs" edge to the UsageLog entity was cleared.
func (m *APIKeyMutation) UsageLogsCleared() bool {
	return m.clearedusage_logs
}

// RemoveUsageLogIDs removes the "usage_logs" edge to the UsageLog entity by IDs.
func (m *APIKeyMutation) RemoveUsageLogIDs(ids ...int64) {
	if m.removedusage_logs == nil {
		m.removedusage_logs = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.usage_logs, ids[i])
		m.removedusage_logs[ids[i]] = struct{}{}
	}
}

// RemovedUsageLogs returns the removed IDs of the "usage_logs" edge to the UsageLog entity.
func (m *APIKeyMutation) RemovedUsageLogsIDs() (ids []int64) {
	for id := range m.removedusage_logs {
		ids = append(ids, id)
	}
	return
}

// UsageLogsIDs returns the "usage_logs" edge IDs in the mutation.
func (m *APIKeyMutation) UsageLogsIDs() (ids []int64) {
	for id := range m.usage_logs {
		ids = append(ids, id)
	}
	return
}

// ResetUsageLogs resets all changes to the "usage_logs" edge.
func (m *APIKeyMutation) ResetUsageLogs() {
	m.usage_logs = nil
	m.clearedusage_logs = false
	m.removedusage_logs = nil
}

// Where appends a list predicates to the APIKeyMutation builder.
func (m *APIKeyMutation) Where(ps ...predicate.APIKey) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the APIKeyMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *APIKeyMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.APIKey, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *APIKeyMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *APIKeyMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (APIKey).
func (m *APIKeyMutation) 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 *APIKeyMutation) Fields() []string {
	fields := make([]string, 0, 23)
	if m.created_at != nil {
		fields = append(fields, apikey.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, apikey.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, apikey.FieldDeletedAt)
	}
	if m.user != nil {
		fields = append(fields, apikey.FieldUserID)
	}
	if m.key != nil {
		fields = append(fields, apikey.FieldKey)
	}
	if m.name != nil {
		fields = append(fields, apikey.FieldName)
	}
	if m.group != nil {
		fields = append(fields, apikey.FieldGroupID)
	}
	if m.status != nil {
		fields = append(fields, apikey.FieldStatus)
	}
	if m.last_used_at != nil {
		fields = append(fields, apikey.FieldLastUsedAt)
	}
	if m.ip_whitelist != nil {
		fields = append(fields, apikey.FieldIPWhitelist)
	}
	if m.ip_blacklist != nil {
		fields = append(fields, apikey.FieldIPBlacklist)
	}
	if m.quota != nil {
		fields = append(fields, apikey.FieldQuota)
	}
	if m.quota_used != nil {
		fields = append(fields, apikey.FieldQuotaUsed)
	}
	if m.expires_at != nil {
		fields = append(fields, apikey.FieldExpiresAt)
	}
	if m.rate_limit_5h != nil {
		fields = append(fields, apikey.FieldRateLimit5h)
	}
	if m.rate_limit_1d != nil {
		fields = append(fields, apikey.FieldRateLimit1d)
	}
	if m.rate_limit_7d != nil {
		fields = append(fields, apikey.FieldRateLimit7d)
	}
	if m.usage_5h != nil {
		fields = append(fields, apikey.FieldUsage5h)
	}
	if m.usage_1d != nil {
		fields = append(fields, apikey.FieldUsage1d)
	}
	if m.usage_7d != nil {
		fields = append(fields, apikey.FieldUsage7d)
	}
	if m.window_5h_start != nil {
		fields = append(fields, apikey.FieldWindow5hStart)
	}
	if m.window_1d_start != nil {
		fields = append(fields, apikey.FieldWindow1dStart)
	}
	if m.window_7d_start != nil {
		fields = append(fields, apikey.FieldWindow7dStart)
	}
	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 *APIKeyMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case apikey.FieldCreatedAt:
		return m.CreatedAt()
	case apikey.FieldUpdatedAt:
		return m.UpdatedAt()
	case apikey.FieldDeletedAt:
		return m.DeletedAt()
	case apikey.FieldUserID:
		return m.UserID()
	case apikey.FieldKey:
		return m.Key()
	case apikey.FieldName:
		return m.Name()
	case apikey.FieldGroupID:
		return m.GroupID()
	case apikey.FieldStatus:
		return m.Status()
	case apikey.FieldLastUsedAt:
		return m.LastUsedAt()
	case apikey.FieldIPWhitelist:
		return m.IPWhitelist()
	case apikey.FieldIPBlacklist:
		return m.IPBlacklist()
	case apikey.FieldQuota:
		return m.Quota()
	case apikey.FieldQuotaUsed:
		return m.QuotaUsed()
	case apikey.FieldExpiresAt:
		return m.ExpiresAt()
	case apikey.FieldRateLimit5h:
		return m.RateLimit5h()
	case apikey.FieldRateLimit1d:
		return m.RateLimit1d()
	case apikey.FieldRateLimit7d:
		return m.RateLimit7d()
	case apikey.FieldUsage5h:
		return m.Usage5h()
	case apikey.FieldUsage1d:
		return m.Usage1d()
	case apikey.FieldUsage7d:
		return m.Usage7d()
	case apikey.FieldWindow5hStart:
		return m.Window5hStart()
	case apikey.FieldWindow1dStart:
		return m.Window1dStart()
	case apikey.FieldWindow7dStart:
		return m.Window7dStart()
	}
	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 *APIKeyMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case apikey.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case apikey.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case apikey.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case apikey.FieldUserID:
		return m.OldUserID(ctx)
	case apikey.FieldKey:
		return m.OldKey(ctx)
	case apikey.FieldName:
		return m.OldName(ctx)
	case apikey.FieldGroupID:
		return m.OldGroupID(ctx)
	case apikey.FieldStatus:
		return m.OldStatus(ctx)
	case apikey.FieldLastUsedAt:
		return m.OldLastUsedAt(ctx)
	case apikey.FieldIPWhitelist:
		return m.OldIPWhitelist(ctx)
	case apikey.FieldIPBlacklist:
		return m.OldIPBlacklist(ctx)
	case apikey.FieldQuota:
		return m.OldQuota(ctx)
	case apikey.FieldQuotaUsed:
		return m.OldQuotaUsed(ctx)
	case apikey.FieldExpiresAt:
		return m.OldExpiresAt(ctx)
	case apikey.FieldRateLimit5h:
		return m.OldRateLimit5h(ctx)
	case apikey.FieldRateLimit1d:
		return m.OldRateLimit1d(ctx)
	case apikey.FieldRateLimit7d:
		return m.OldRateLimit7d(ctx)
	case apikey.FieldUsage5h:
		return m.OldUsage5h(ctx)
	case apikey.FieldUsage1d:
		return m.OldUsage1d(ctx)
	case apikey.FieldUsage7d:
		return m.OldUsage7d(ctx)
	case apikey.FieldWindow5hStart:
		return m.OldWindow5hStart(ctx)
	case apikey.FieldWindow1dStart:
		return m.OldWindow1dStart(ctx)
	case apikey.FieldWindow7dStart:
		return m.OldWindow7dStart(ctx)
	}
	return nil, fmt.Errorf("unknown APIKey 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 *APIKeyMutation) SetField(name string, value ent.Value) error {
	switch name {
	case apikey.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 apikey.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 apikey.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 apikey.FieldUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserID(v)
		return nil
	case apikey.FieldKey:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetKey(v)
		return nil
	case apikey.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case apikey.FieldGroupID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetGroupID(v)
		return nil
	case apikey.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case apikey.FieldLastUsedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastUsedAt(v)
		return nil
	case apikey.FieldIPWhitelist:
		v, ok := value.([]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIPWhitelist(v)
		return nil
	case apikey.FieldIPBlacklist:
		v, ok := value.([]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIPBlacklist(v)
		return nil
	case apikey.FieldQuota:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetQuota(v)
		return nil
	case apikey.FieldQuotaUsed:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetQuotaUsed(v)
		return nil
	case apikey.FieldExpiresAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetExpiresAt(v)
		return nil
	case apikey.FieldRateLimit5h:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRateLimit5h(v)
		return nil
	case apikey.FieldRateLimit1d:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRateLimit1d(v)
		return nil
	case apikey.FieldRateLimit7d:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRateLimit7d(v)
		return nil
	case apikey.FieldUsage5h:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUsage5h(v)
		return nil
	case apikey.FieldUsage1d:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUsage1d(v)
		return nil
	case apikey.FieldUsage7d:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUsage7d(v)
		return nil
	case apikey.FieldWindow5hStart:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWindow5hStart(v)
		return nil
	case apikey.FieldWindow1dStart:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWindow1dStart(v)
		return nil
	case apikey.FieldWindow7dStart:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWindow7dStart(v)
		return nil
	}
	return fmt.Errorf("unknown APIKey field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *APIKeyMutation) AddedFields() []string {
	var fields []string
	if m.addquota != nil {
		fields = append(fields, apikey.FieldQuota)
	}
	if m.addquota_used != nil {
		fields = append(fields, apikey.FieldQuotaUsed)
	}
	if m.addrate_limit_5h != nil {
		fields = append(fields, apikey.FieldRateLimit5h)
	}
	if m.addrate_limit_1d != nil {
		fields = append(fields, apikey.FieldRateLimit1d)
	}
	if m.addrate_limit_7d != nil {
		fields = append(fields, apikey.FieldRateLimit7d)
	}
	if m.addusage_5h != nil {
		fields = append(fields, apikey.FieldUsage5h)
	}
	if m.addusage_1d != nil {
		fields = append(fields, apikey.FieldUsage1d)
	}
	if m.addusage_7d != nil {
		fields = append(fields, apikey.FieldUsage7d)
	}
	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 *APIKeyMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case apikey.FieldQuota:
		return m.AddedQuota()
	case apikey.FieldQuotaUsed:
		return m.AddedQuotaUsed()
	case apikey.FieldRateLimit5h:
		return m.AddedRateLimit5h()
	case apikey.FieldRateLimit1d:
		return m.AddedRateLimit1d()
	case apikey.FieldRateLimit7d:
		return m.AddedRateLimit7d()
	case apikey.FieldUsage5h:
		return m.AddedUsage5h()
	case apikey.FieldUsage1d:
		return m.AddedUsage1d()
	case apikey.FieldUsage7d:
		return m.AddedUsage7d()
	}
	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 *APIKeyMutation) AddField(name string, value ent.Value) error {
	switch name {
	case apikey.FieldQuota:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddQuota(v)
		return nil
	case apikey.FieldQuotaUsed:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddQuotaUsed(v)
		return nil
	case apikey.FieldRateLimit5h:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddRateLimit5h(v)
		return nil
	case apikey.FieldRateLimit1d:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddRateLimit1d(v)
		return nil
	case apikey.FieldRateLimit7d:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddRateLimit7d(v)
		return nil
	case apikey.FieldUsage5h:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddUsage5h(v)
		return nil
	case apikey.FieldUsage1d:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddUsage1d(v)
		return nil
	case apikey.FieldUsage7d:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddUsage7d(v)
		return nil
	}
	return fmt.Errorf("unknown APIKey numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *APIKeyMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(apikey.FieldDeletedAt) {
		fields = append(fields, apikey.FieldDeletedAt)
	}
	if m.FieldCleared(apikey.FieldGroupID) {
		fields = append(fields, apikey.FieldGroupID)
	}
	if m.FieldCleared(apikey.FieldLastUsedAt) {
		fields = append(fields, apikey.FieldLastUsedAt)
	}
	if m.FieldCleared(apikey.FieldIPWhitelist) {
		fields = append(fields, apikey.FieldIPWhitelist)
	}
	if m.FieldCleared(apikey.FieldIPBlacklist) {
		fields = append(fields, apikey.FieldIPBlacklist)
	}
	if m.FieldCleared(apikey.FieldExpiresAt) {
		fields = append(fields, apikey.FieldExpiresAt)
	}
	if m.FieldCleared(apikey.FieldWindow5hStart) {
		fields = append(fields, apikey.FieldWindow5hStart)
	}
	if m.FieldCleared(apikey.FieldWindow1dStart) {
		fields = append(fields, apikey.FieldWindow1dStart)
	}
	if m.FieldCleared(apikey.FieldWindow7dStart) {
		fields = append(fields, apikey.FieldWindow7dStart)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *APIKeyMutation) 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 *APIKeyMutation) ClearField(name string) error {
	switch name {
	case apikey.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	case apikey.FieldGroupID:
		m.ClearGroupID()
		return nil
	case apikey.FieldLastUsedAt:
		m.ClearLastUsedAt()
		return nil
	case apikey.FieldIPWhitelist:
		m.ClearIPWhitelist()
		return nil
	case apikey.FieldIPBlacklist:
		m.ClearIPBlacklist()
		return nil
	case apikey.FieldExpiresAt:
		m.ClearExpiresAt()
		return nil
	case apikey.FieldWindow5hStart:
		m.ClearWindow5hStart()
		return nil
	case apikey.FieldWindow1dStart:
		m.ClearWindow1dStart()
		return nil
	case apikey.FieldWindow7dStart:
		m.ClearWindow7dStart()
		return nil
	}
	return fmt.Errorf("unknown APIKey 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 *APIKeyMutation) ResetField(name string) error {
	switch name {
	case apikey.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case apikey.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case apikey.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case apikey.FieldUserID:
		m.ResetUserID()
		return nil
	case apikey.FieldKey:
		m.ResetKey()
		return nil
	case apikey.FieldName:
		m.ResetName()
		return nil
	case apikey.FieldGroupID:
		m.ResetGroupID()
		return nil
	case apikey.FieldStatus:
		m.ResetStatus()
		return nil
	case apikey.FieldLastUsedAt:
		m.ResetLastUsedAt()
		return nil
	case apikey.FieldIPWhitelist:
		m.ResetIPWhitelist()
		return nil
	case apikey.FieldIPBlacklist:
		m.ResetIPBlacklist()
		return nil
	case apikey.FieldQuota:
		m.ResetQuota()
		return nil
	case apikey.FieldQuotaUsed:
		m.ResetQuotaUsed()
		return nil
	case apikey.FieldExpiresAt:
		m.ResetExpiresAt()
		return nil
	case apikey.FieldRateLimit5h:
		m.ResetRateLimit5h()
		return nil
	case apikey.FieldRateLimit1d:
		m.ResetRateLimit1d()
		return nil
	case apikey.FieldRateLimit7d:
		m.ResetRateLimit7d()
		return nil
	case apikey.FieldUsage5h:
		m.ResetUsage5h()
		return nil
	case apikey.FieldUsage1d:
		m.ResetUsage1d()
		return nil
	case apikey.FieldUsage7d:
		m.ResetUsage7d()
		return nil
	case apikey.FieldWindow5hStart:
		m.ResetWindow5hStart()
		return nil
	case apikey.FieldWindow1dStart:
		m.ResetWindow1dStart()
		return nil
	case apikey.FieldWindow7dStart:
		m.ResetWindow7dStart()
		return nil
	}
	return fmt.Errorf("unknown APIKey field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *APIKeyMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.user != nil {
		edges = append(edges, apikey.EdgeUser)
	}
	if m.group != nil {
		edges = append(edges, apikey.EdgeGroup)
	}
	if m.usage_logs != nil {
		edges = append(edges, apikey.EdgeUsageLogs)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *APIKeyMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case apikey.EdgeUser:
		if id := m.user; id != nil {
			return []ent.Value{*id}
		}
	case apikey.EdgeGroup:
		if id := m.group; id != nil {
			return []ent.Value{*id}
		}
	case apikey.EdgeUsageLogs:
		ids := make([]ent.Value, 0, len(m.usage_logs))
		for id := range m.usage_logs {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *APIKeyMutation) RemovedEdges() []string {
	edges := make([]string, 0, 3)
	if m.removedusage_logs != nil {
		edges = append(edges, apikey.EdgeUsageLogs)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *APIKeyMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case apikey.EdgeUsageLogs:
		ids := make([]ent.Value, 0, len(m.removedusage_logs))
		for id := range m.removedusage_logs {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *APIKeyMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.cleareduser {
		edges = append(edges, apikey.EdgeUser)
	}
	if m.clearedgroup {
		edges = append(edges, apikey.EdgeGroup)
	}
	if m.clearedusage_logs {
		edges = append(edges, apikey.EdgeUsageLogs)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *APIKeyMutation) EdgeCleared(name string) bool {
	switch name {
	case apikey.EdgeUser:
		return m.cleareduser
	case apikey.EdgeGroup:
		return m.clearedgroup
	case apikey.EdgeUsageLogs:
		return m.clearedusage_logs
	}
	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 *APIKeyMutation) ClearEdge(name string) error {
	switch name {
	case apikey.EdgeUser:
		m.ClearUser()
		return nil
	case apikey.EdgeGroup:
		m.ClearGroup()
		return nil
	}
	return fmt.Errorf("unknown APIKey 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 *APIKeyMutation) ResetEdge(name string) error {
	switch name {
	case apikey.EdgeUser:
		m.ResetUser()
		return nil
	case apikey.EdgeGroup:
		m.ResetGroup()
		return nil
	case apikey.EdgeUsageLogs:
		m.ResetUsageLogs()
		return nil
	}
	return fmt.Errorf("unknown APIKey edge %s", name)
}

// AccountMutation represents an operation that mutates the Account nodes in the graph.
type AccountMutation struct {
	config
	op                        Op
	typ                       string
	id                        *int64
	created_at                *time.Time
	updated_at                *time.Time
	deleted_at                *time.Time
	name                      *string
	notes                     *string
	platform                  *string
	_type                     *string
	credentials               *map[string]interface{}
	extra                     *map[string]interface{}
	concurrency               *int
	addconcurrency            *int
	load_factor               *int
	addload_factor            *int
	priority                  *int
	addpriority               *int
	rate_multiplier           *float64
	addrate_multiplier        *float64
	status                    *string
	error_message             *string
	last_used_at              *time.Time
	expires_at                *time.Time
	auto_pause_on_expired     *bool
	schedulable               *bool
	rate_limited_at           *time.Time
	rate_limit_reset_at       *time.Time
	overload_until            *time.Time
	temp_unschedulable_until  *time.Time
	temp_unschedulable_reason *string
	session_window_start      *time.Time
	session_window_end        *time.Time
	session_window_status     *string
	clearedFields             map[string]struct{}
	groups                    map[int64]struct{}
	removedgroups             map[int64]struct{}
	clearedgroups             bool
	proxy                     *int64
	clearedproxy              bool
	usage_logs                map[int64]struct{}
	removedusage_logs         map[int64]struct{}
	clearedusage_logs         bool
	done                      bool
	oldValue                  func(context.Context) (*Account, error)
	predicates                []predicate.Account
}

var _ ent.Mutation = (*AccountMutation)(nil)

// accountOption allows management of the mutation configuration using functional options.
type accountOption func(*AccountMutation)

// newAccountMutation creates new mutation for the Account entity.
func newAccountMutation(c config, op Op, opts ...accountOption) *AccountMutation {
	m := &AccountMutation{
		config:        c,
		op:            op,
		typ:           TypeAccount,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withAccountID sets the ID field of the mutation.
func withAccountID(id int64) accountOption {
	return func(m *AccountMutation) {
		var (
			err   error
			once  sync.Once
			value *Account
		)
		m.oldValue = func(ctx context.Context) (*Account, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Account.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withAccount sets the old Account of the mutation.
func withAccount(node *Account) accountOption {
	return func(m *AccountMutation) {
		m.oldValue = func(context.Context) (*Account, 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 AccountMutation) 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 AccountMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *AccountMutation) ID() (id int64, 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 *AccountMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Account.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *AccountMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *AccountMutation) 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 Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) 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 *AccountMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *AccountMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *AccountMutation) 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 Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) 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 *AccountMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetDeletedAt sets the "deleted_at" field.
func (m *AccountMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *AccountMutation) 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 Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) 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 *AccountMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[account.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *AccountMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[account.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *AccountMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, account.FieldDeletedAt)
}

// SetName sets the "name" field.
func (m *AccountMutation) SetName(s string) {
	m.name = &s
}

// Name returns the value of the "name" field in the mutation.
func (m *AccountMutation) 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 Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) 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 *AccountMutation) ResetName() {
	m.name = nil
}

// SetNotes sets the "notes" field.
func (m *AccountMutation) SetNotes(s string) {
	m.notes = &s
}

// Notes returns the value of the "notes" field in the mutation.
func (m *AccountMutation) Notes() (r string, exists bool) {
	v := m.notes
	if v == nil {
		return
	}
	return *v, true
}

// OldNotes returns the old "notes" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldNotes(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldNotes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldNotes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldNotes: %w", err)
	}
	return oldValue.Notes, nil
}

// ClearNotes clears the value of the "notes" field.
func (m *AccountMutation) ClearNotes() {
	m.notes = nil
	m.clearedFields[account.FieldNotes] = struct{}{}
}

// NotesCleared returns if the "notes" field was cleared in this mutation.
func (m *AccountMutation) NotesCleared() bool {
	_, ok := m.clearedFields[account.FieldNotes]
	return ok
}

// ResetNotes resets all changes to the "notes" field.
func (m *AccountMutation) ResetNotes() {
	m.notes = nil
	delete(m.clearedFields, account.FieldNotes)
}

// SetPlatform sets the "platform" field.
func (m *AccountMutation) SetPlatform(s string) {
	m.platform = &s
}

// Platform returns the value of the "platform" field in the mutation.
func (m *AccountMutation) Platform() (r string, exists bool) {
	v := m.platform
	if v == nil {
		return
	}
	return *v, true
}

// OldPlatform returns the old "platform" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldPlatform(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPlatform is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPlatform requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPlatform: %w", err)
	}
	return oldValue.Platform, nil
}

// ResetPlatform resets all changes to the "platform" field.
func (m *AccountMutation) ResetPlatform() {
	m.platform = nil
}

// SetType sets the "type" field.
func (m *AccountMutation) SetType(s string) {
	m._type = &s
}

// GetType returns the value of the "type" field in the mutation.
func (m *AccountMutation) GetType() (r string, exists bool) {
	v := m._type
	if v == nil {
		return
	}
	return *v, true
}

// OldType returns the old "type" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldType(ctx context.Context) (v string, 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 *AccountMutation) ResetType() {
	m._type = nil
}

// SetCredentials sets the "credentials" field.
func (m *AccountMutation) SetCredentials(value map[string]interface{}) {
	m.credentials = &value
}

// Credentials returns the value of the "credentials" field in the mutation.
func (m *AccountMutation) Credentials() (r map[string]interface{}, exists bool) {
	v := m.credentials
	if v == nil {
		return
	}
	return *v, true
}

// OldCredentials returns the old "credentials" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldCredentials(ctx context.Context) (v map[string]interface{}, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCredentials is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCredentials requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCredentials: %w", err)
	}
	return oldValue.Credentials, nil
}

// ResetCredentials resets all changes to the "credentials" field.
func (m *AccountMutation) ResetCredentials() {
	m.credentials = nil
}

// SetExtra sets the "extra" field.
func (m *AccountMutation) SetExtra(value map[string]interface{}) {
	m.extra = &value
}

// Extra returns the value of the "extra" field in the mutation.
func (m *AccountMutation) Extra() (r map[string]interface{}, exists bool) {
	v := m.extra
	if v == nil {
		return
	}
	return *v, true
}

// OldExtra returns the old "extra" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldExtra(ctx context.Context) (v map[string]interface{}, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldExtra is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldExtra requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldExtra: %w", err)
	}
	return oldValue.Extra, nil
}

// ResetExtra resets all changes to the "extra" field.
func (m *AccountMutation) ResetExtra() {
	m.extra = nil
}

// SetProxyID sets the "proxy_id" field.
func (m *AccountMutation) SetProxyID(i int64) {
	m.proxy = &i
}

// ProxyID returns the value of the "proxy_id" field in the mutation.
func (m *AccountMutation) ProxyID() (r int64, exists bool) {
	v := m.proxy
	if v == nil {
		return
	}
	return *v, true
}

// OldProxyID returns the old "proxy_id" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldProxyID(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProxyID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProxyID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProxyID: %w", err)
	}
	return oldValue.ProxyID, nil
}

// ClearProxyID clears the value of the "proxy_id" field.
func (m *AccountMutation) ClearProxyID() {
	m.proxy = nil
	m.clearedFields[account.FieldProxyID] = struct{}{}
}

// ProxyIDCleared returns if the "proxy_id" field was cleared in this mutation.
func (m *AccountMutation) ProxyIDCleared() bool {
	_, ok := m.clearedFields[account.FieldProxyID]
	return ok
}

// ResetProxyID resets all changes to the "proxy_id" field.
func (m *AccountMutation) ResetProxyID() {
	m.proxy = nil
	delete(m.clearedFields, account.FieldProxyID)
}

// SetConcurrency sets the "concurrency" field.
func (m *AccountMutation) SetConcurrency(i int) {
	m.concurrency = &i
	m.addconcurrency = nil
}

// Concurrency returns the value of the "concurrency" field in the mutation.
func (m *AccountMutation) Concurrency() (r int, exists bool) {
	v := m.concurrency
	if v == nil {
		return
	}
	return *v, true
}

// OldConcurrency returns the old "concurrency" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldConcurrency(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldConcurrency is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldConcurrency requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldConcurrency: %w", err)
	}
	return oldValue.Concurrency, nil
}

// AddConcurrency adds i to the "concurrency" field.
func (m *AccountMutation) AddConcurrency(i int) {
	if m.addconcurrency != nil {
		*m.addconcurrency += i
	} else {
		m.addconcurrency = &i
	}
}

// AddedConcurrency returns the value that was added to the "concurrency" field in this mutation.
func (m *AccountMutation) AddedConcurrency() (r int, exists bool) {
	v := m.addconcurrency
	if v == nil {
		return
	}
	return *v, true
}

// ResetConcurrency resets all changes to the "concurrency" field.
func (m *AccountMutation) ResetConcurrency() {
	m.concurrency = nil
	m.addconcurrency = nil
}

// SetLoadFactor sets the "load_factor" field.
func (m *AccountMutation) SetLoadFactor(i int) {
	m.load_factor = &i
	m.addload_factor = nil
}

// LoadFactor returns the value of the "load_factor" field in the mutation.
func (m *AccountMutation) LoadFactor() (r int, exists bool) {
	v := m.load_factor
	if v == nil {
		return
	}
	return *v, true
}

// OldLoadFactor returns the old "load_factor" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldLoadFactor(ctx context.Context) (v *int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLoadFactor is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLoadFactor requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLoadFactor: %w", err)
	}
	return oldValue.LoadFactor, nil
}

// AddLoadFactor adds i to the "load_factor" field.
func (m *AccountMutation) AddLoadFactor(i int) {
	if m.addload_factor != nil {
		*m.addload_factor += i
	} else {
		m.addload_factor = &i
	}
}

// AddedLoadFactor returns the value that was added to the "load_factor" field in this mutation.
func (m *AccountMutation) AddedLoadFactor() (r int, exists bool) {
	v := m.addload_factor
	if v == nil {
		return
	}
	return *v, true
}

// ClearLoadFactor clears the value of the "load_factor" field.
func (m *AccountMutation) ClearLoadFactor() {
	m.load_factor = nil
	m.addload_factor = nil
	m.clearedFields[account.FieldLoadFactor] = struct{}{}
}

// LoadFactorCleared returns if the "load_factor" field was cleared in this mutation.
func (m *AccountMutation) LoadFactorCleared() bool {
	_, ok := m.clearedFields[account.FieldLoadFactor]
	return ok
}

// ResetLoadFactor resets all changes to the "load_factor" field.
func (m *AccountMutation) ResetLoadFactor() {
	m.load_factor = nil
	m.addload_factor = nil
	delete(m.clearedFields, account.FieldLoadFactor)
}

// SetPriority sets the "priority" field.
func (m *AccountMutation) SetPriority(i int) {
	m.priority = &i
	m.addpriority = nil
}

// Priority returns the value of the "priority" field in the mutation.
func (m *AccountMutation) Priority() (r int, exists bool) {
	v := m.priority
	if v == nil {
		return
	}
	return *v, true
}

// OldPriority returns the old "priority" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldPriority(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPriority is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPriority requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPriority: %w", err)
	}
	return oldValue.Priority, nil
}

// AddPriority adds i to the "priority" field.
func (m *AccountMutation) AddPriority(i int) {
	if m.addpriority != nil {
		*m.addpriority += i
	} else {
		m.addpriority = &i
	}
}

// AddedPriority returns the value that was added to the "priority" field in this mutation.
func (m *AccountMutation) AddedPriority() (r int, exists bool) {
	v := m.addpriority
	if v == nil {
		return
	}
	return *v, true
}

// ResetPriority resets all changes to the "priority" field.
func (m *AccountMutation) ResetPriority() {
	m.priority = nil
	m.addpriority = nil
}

// SetRateMultiplier sets the "rate_multiplier" field.
func (m *AccountMutation) SetRateMultiplier(f float64) {
	m.rate_multiplier = &f
	m.addrate_multiplier = nil
}

// RateMultiplier returns the value of the "rate_multiplier" field in the mutation.
func (m *AccountMutation) RateMultiplier() (r float64, exists bool) {
	v := m.rate_multiplier
	if v == nil {
		return
	}
	return *v, true
}

// OldRateMultiplier returns the old "rate_multiplier" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldRateMultiplier(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRateMultiplier is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRateMultiplier requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRateMultiplier: %w", err)
	}
	return oldValue.RateMultiplier, nil
}

// AddRateMultiplier adds f to the "rate_multiplier" field.
func (m *AccountMutation) AddRateMultiplier(f float64) {
	if m.addrate_multiplier != nil {
		*m.addrate_multiplier += f
	} else {
		m.addrate_multiplier = &f
	}
}

// AddedRateMultiplier returns the value that was added to the "rate_multiplier" field in this mutation.
func (m *AccountMutation) AddedRateMultiplier() (r float64, exists bool) {
	v := m.addrate_multiplier
	if v == nil {
		return
	}
	return *v, true
}

// ResetRateMultiplier resets all changes to the "rate_multiplier" field.
func (m *AccountMutation) ResetRateMultiplier() {
	m.rate_multiplier = nil
	m.addrate_multiplier = nil
}

// SetStatus sets the "status" field.
func (m *AccountMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *AccountMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldStatus(ctx context.Context) (v string, 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 *AccountMutation) ResetStatus() {
	m.status = nil
}

// SetErrorMessage sets the "error_message" field.
func (m *AccountMutation) SetErrorMessage(s string) {
	m.error_message = &s
}

// ErrorMessage returns the value of the "error_message" field in the mutation.
func (m *AccountMutation) ErrorMessage() (r string, exists bool) {
	v := m.error_message
	if v == nil {
		return
	}
	return *v, true
}

// OldErrorMessage returns the old "error_message" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldErrorMessage(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldErrorMessage is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldErrorMessage requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldErrorMessage: %w", err)
	}
	return oldValue.ErrorMessage, nil
}

// ClearErrorMessage clears the value of the "error_message" field.
func (m *AccountMutation) ClearErrorMessage() {
	m.error_message = nil
	m.clearedFields[account.FieldErrorMessage] = struct{}{}
}

// ErrorMessageCleared returns if the "error_message" field was cleared in this mutation.
func (m *AccountMutation) ErrorMessageCleared() bool {
	_, ok := m.clearedFields[account.FieldErrorMessage]
	return ok
}

// ResetErrorMessage resets all changes to the "error_message" field.
func (m *AccountMutation) ResetErrorMessage() {
	m.error_message = nil
	delete(m.clearedFields, account.FieldErrorMessage)
}

// SetLastUsedAt sets the "last_used_at" field.
func (m *AccountMutation) SetLastUsedAt(t time.Time) {
	m.last_used_at = &t
}

// LastUsedAt returns the value of the "last_used_at" field in the mutation.
func (m *AccountMutation) LastUsedAt() (r time.Time, exists bool) {
	v := m.last_used_at
	if v == nil {
		return
	}
	return *v, true
}

// OldLastUsedAt returns the old "last_used_at" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldLastUsedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLastUsedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLastUsedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLastUsedAt: %w", err)
	}
	return oldValue.LastUsedAt, nil
}

// ClearLastUsedAt clears the value of the "last_used_at" field.
func (m *AccountMutation) ClearLastUsedAt() {
	m.last_used_at = nil
	m.clearedFields[account.FieldLastUsedAt] = struct{}{}
}

// LastUsedAtCleared returns if the "last_used_at" field was cleared in this mutation.
func (m *AccountMutation) LastUsedAtCleared() bool {
	_, ok := m.clearedFields[account.FieldLastUsedAt]
	return ok
}

// ResetLastUsedAt resets all changes to the "last_used_at" field.
func (m *AccountMutation) ResetLastUsedAt() {
	m.last_used_at = nil
	delete(m.clearedFields, account.FieldLastUsedAt)
}

// SetExpiresAt sets the "expires_at" field.
func (m *AccountMutation) SetExpiresAt(t time.Time) {
	m.expires_at = &t
}

// ExpiresAt returns the value of the "expires_at" field in the mutation.
func (m *AccountMutation) ExpiresAt() (r time.Time, exists bool) {
	v := m.expires_at
	if v == nil {
		return
	}
	return *v, true
}

// OldExpiresAt returns the old "expires_at" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldExpiresAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldExpiresAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err)
	}
	return oldValue.ExpiresAt, nil
}

// ClearExpiresAt clears the value of the "expires_at" field.
func (m *AccountMutation) ClearExpiresAt() {
	m.expires_at = nil
	m.clearedFields[account.FieldExpiresAt] = struct{}{}
}

// ExpiresAtCleared returns if the "expires_at" field was cleared in this mutation.
func (m *AccountMutation) ExpiresAtCleared() bool {
	_, ok := m.clearedFields[account.FieldExpiresAt]
	return ok
}

// ResetExpiresAt resets all changes to the "expires_at" field.
func (m *AccountMutation) ResetExpiresAt() {
	m.expires_at = nil
	delete(m.clearedFields, account.FieldExpiresAt)
}

// SetAutoPauseOnExpired sets the "auto_pause_on_expired" field.
func (m *AccountMutation) SetAutoPauseOnExpired(b bool) {
	m.auto_pause_on_expired = &b
}

// AutoPauseOnExpired returns the value of the "auto_pause_on_expired" field in the mutation.
func (m *AccountMutation) AutoPauseOnExpired() (r bool, exists bool) {
	v := m.auto_pause_on_expired
	if v == nil {
		return
	}
	return *v, true
}

// OldAutoPauseOnExpired returns the old "auto_pause_on_expired" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldAutoPauseOnExpired(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAutoPauseOnExpired is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAutoPauseOnExpired requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAutoPauseOnExpired: %w", err)
	}
	return oldValue.AutoPauseOnExpired, nil
}

// ResetAutoPauseOnExpired resets all changes to the "auto_pause_on_expired" field.
func (m *AccountMutation) ResetAutoPauseOnExpired() {
	m.auto_pause_on_expired = nil
}

// SetSchedulable sets the "schedulable" field.
func (m *AccountMutation) SetSchedulable(b bool) {
	m.schedulable = &b
}

// Schedulable returns the value of the "schedulable" field in the mutation.
func (m *AccountMutation) Schedulable() (r bool, exists bool) {
	v := m.schedulable
	if v == nil {
		return
	}
	return *v, true
}

// OldSchedulable returns the old "schedulable" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldSchedulable(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSchedulable is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSchedulable requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSchedulable: %w", err)
	}
	return oldValue.Schedulable, nil
}

// ResetSchedulable resets all changes to the "schedulable" field.
func (m *AccountMutation) ResetSchedulable() {
	m.schedulable = nil
}

// SetRateLimitedAt sets the "rate_limited_at" field.
func (m *AccountMutation) SetRateLimitedAt(t time.Time) {
	m.rate_limited_at = &t
}

// RateLimitedAt returns the value of the "rate_limited_at" field in the mutation.
func (m *AccountMutation) RateLimitedAt() (r time.Time, exists bool) {
	v := m.rate_limited_at
	if v == nil {
		return
	}
	return *v, true
}

// OldRateLimitedAt returns the old "rate_limited_at" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldRateLimitedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRateLimitedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRateLimitedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRateLimitedAt: %w", err)
	}
	return oldValue.RateLimitedAt, nil
}

// ClearRateLimitedAt clears the value of the "rate_limited_at" field.
func (m *AccountMutation) ClearRateLimitedAt() {
	m.rate_limited_at = nil
	m.clearedFields[account.FieldRateLimitedAt] = struct{}{}
}

// RateLimitedAtCleared returns if the "rate_limited_at" field was cleared in this mutation.
func (m *AccountMutation) RateLimitedAtCleared() bool {
	_, ok := m.clearedFields[account.FieldRateLimitedAt]
	return ok
}

// ResetRateLimitedAt resets all changes to the "rate_limited_at" field.
func (m *AccountMutation) ResetRateLimitedAt() {
	m.rate_limited_at = nil
	delete(m.clearedFields, account.FieldRateLimitedAt)
}

// SetRateLimitResetAt sets the "rate_limit_reset_at" field.
func (m *AccountMutation) SetRateLimitResetAt(t time.Time) {
	m.rate_limit_reset_at = &t
}

// RateLimitResetAt returns the value of the "rate_limit_reset_at" field in the mutation.
func (m *AccountMutation) RateLimitResetAt() (r time.Time, exists bool) {
	v := m.rate_limit_reset_at
	if v == nil {
		return
	}
	return *v, true
}

// OldRateLimitResetAt returns the old "rate_limit_reset_at" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldRateLimitResetAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRateLimitResetAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRateLimitResetAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRateLimitResetAt: %w", err)
	}
	return oldValue.RateLimitResetAt, nil
}

// ClearRateLimitResetAt clears the value of the "rate_limit_reset_at" field.
func (m *AccountMutation) ClearRateLimitResetAt() {
	m.rate_limit_reset_at = nil
	m.clearedFields[account.FieldRateLimitResetAt] = struct{}{}
}

// RateLimitResetAtCleared returns if the "rate_limit_reset_at" field was cleared in this mutation.
func (m *AccountMutation) RateLimitResetAtCleared() bool {
	_, ok := m.clearedFields[account.FieldRateLimitResetAt]
	return ok
}

// ResetRateLimitResetAt resets all changes to the "rate_limit_reset_at" field.
func (m *AccountMutation) ResetRateLimitResetAt() {
	m.rate_limit_reset_at = nil
	delete(m.clearedFields, account.FieldRateLimitResetAt)
}

// SetOverloadUntil sets the "overload_until" field.
func (m *AccountMutation) SetOverloadUntil(t time.Time) {
	m.overload_until = &t
}

// OverloadUntil returns the value of the "overload_until" field in the mutation.
func (m *AccountMutation) OverloadUntil() (r time.Time, exists bool) {
	v := m.overload_until
	if v == nil {
		return
	}
	return *v, true
}

// OldOverloadUntil returns the old "overload_until" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldOverloadUntil(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldOverloadUntil is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldOverloadUntil requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldOverloadUntil: %w", err)
	}
	return oldValue.OverloadUntil, nil
}

// ClearOverloadUntil clears the value of the "overload_until" field.
func (m *AccountMutation) ClearOverloadUntil() {
	m.overload_until = nil
	m.clearedFields[account.FieldOverloadUntil] = struct{}{}
}

// OverloadUntilCleared returns if the "overload_until" field was cleared in this mutation.
func (m *AccountMutation) OverloadUntilCleared() bool {
	_, ok := m.clearedFields[account.FieldOverloadUntil]
	return ok
}

// ResetOverloadUntil resets all changes to the "overload_until" field.
func (m *AccountMutation) ResetOverloadUntil() {
	m.overload_until = nil
	delete(m.clearedFields, account.FieldOverloadUntil)
}

// SetTempUnschedulableUntil sets the "temp_unschedulable_until" field.
func (m *AccountMutation) SetTempUnschedulableUntil(t time.Time) {
	m.temp_unschedulable_until = &t
}

// TempUnschedulableUntil returns the value of the "temp_unschedulable_until" field in the mutation.
func (m *AccountMutation) TempUnschedulableUntil() (r time.Time, exists bool) {
	v := m.temp_unschedulable_until
	if v == nil {
		return
	}
	return *v, true
}

// OldTempUnschedulableUntil returns the old "temp_unschedulable_until" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldTempUnschedulableUntil(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTempUnschedulableUntil is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTempUnschedulableUntil requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTempUnschedulableUntil: %w", err)
	}
	return oldValue.TempUnschedulableUntil, nil
}

// ClearTempUnschedulableUntil clears the value of the "temp_unschedulable_until" field.
func (m *AccountMutation) ClearTempUnschedulableUntil() {
	m.temp_unschedulable_until = nil
	m.clearedFields[account.FieldTempUnschedulableUntil] = struct{}{}
}

// TempUnschedulableUntilCleared returns if the "temp_unschedulable_until" field was cleared in this mutation.
func (m *AccountMutation) TempUnschedulableUntilCleared() bool {
	_, ok := m.clearedFields[account.FieldTempUnschedulableUntil]
	return ok
}

// ResetTempUnschedulableUntil resets all changes to the "temp_unschedulable_until" field.
func (m *AccountMutation) ResetTempUnschedulableUntil() {
	m.temp_unschedulable_until = nil
	delete(m.clearedFields, account.FieldTempUnschedulableUntil)
}

// SetTempUnschedulableReason sets the "temp_unschedulable_reason" field.
func (m *AccountMutation) SetTempUnschedulableReason(s string) {
	m.temp_unschedulable_reason = &s
}

// TempUnschedulableReason returns the value of the "temp_unschedulable_reason" field in the mutation.
func (m *AccountMutation) TempUnschedulableReason() (r string, exists bool) {
	v := m.temp_unschedulable_reason
	if v == nil {
		return
	}
	return *v, true
}

// OldTempUnschedulableReason returns the old "temp_unschedulable_reason" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldTempUnschedulableReason(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTempUnschedulableReason is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTempUnschedulableReason requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTempUnschedulableReason: %w", err)
	}
	return oldValue.TempUnschedulableReason, nil
}

// ClearTempUnschedulableReason clears the value of the "temp_unschedulable_reason" field.
func (m *AccountMutation) ClearTempUnschedulableReason() {
	m.temp_unschedulable_reason = nil
	m.clearedFields[account.FieldTempUnschedulableReason] = struct{}{}
}

// TempUnschedulableReasonCleared returns if the "temp_unschedulable_reason" field was cleared in this mutation.
func (m *AccountMutation) TempUnschedulableReasonCleared() bool {
	_, ok := m.clearedFields[account.FieldTempUnschedulableReason]
	return ok
}

// ResetTempUnschedulableReason resets all changes to the "temp_unschedulable_reason" field.
func (m *AccountMutation) ResetTempUnschedulableReason() {
	m.temp_unschedulable_reason = nil
	delete(m.clearedFields, account.FieldTempUnschedulableReason)
}

// SetSessionWindowStart sets the "session_window_start" field.
func (m *AccountMutation) SetSessionWindowStart(t time.Time) {
	m.session_window_start = &t
}

// SessionWindowStart returns the value of the "session_window_start" field in the mutation.
func (m *AccountMutation) SessionWindowStart() (r time.Time, exists bool) {
	v := m.session_window_start
	if v == nil {
		return
	}
	return *v, true
}

// OldSessionWindowStart returns the old "session_window_start" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldSessionWindowStart(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSessionWindowStart is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSessionWindowStart requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSessionWindowStart: %w", err)
	}
	return oldValue.SessionWindowStart, nil
}

// ClearSessionWindowStart clears the value of the "session_window_start" field.
func (m *AccountMutation) ClearSessionWindowStart() {
	m.session_window_start = nil
	m.clearedFields[account.FieldSessionWindowStart] = struct{}{}
}

// SessionWindowStartCleared returns if the "session_window_start" field was cleared in this mutation.
func (m *AccountMutation) SessionWindowStartCleared() bool {
	_, ok := m.clearedFields[account.FieldSessionWindowStart]
	return ok
}

// ResetSessionWindowStart resets all changes to the "session_window_start" field.
func (m *AccountMutation) ResetSessionWindowStart() {
	m.session_window_start = nil
	delete(m.clearedFields, account.FieldSessionWindowStart)
}

// SetSessionWindowEnd sets the "session_window_end" field.
func (m *AccountMutation) SetSessionWindowEnd(t time.Time) {
	m.session_window_end = &t
}

// SessionWindowEnd returns the value of the "session_window_end" field in the mutation.
func (m *AccountMutation) SessionWindowEnd() (r time.Time, exists bool) {
	v := m.session_window_end
	if v == nil {
		return
	}
	return *v, true
}

// OldSessionWindowEnd returns the old "session_window_end" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldSessionWindowEnd(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSessionWindowEnd is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSessionWindowEnd requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSessionWindowEnd: %w", err)
	}
	return oldValue.SessionWindowEnd, nil
}

// ClearSessionWindowEnd clears the value of the "session_window_end" field.
func (m *AccountMutation) ClearSessionWindowEnd() {
	m.session_window_end = nil
	m.clearedFields[account.FieldSessionWindowEnd] = struct{}{}
}

// SessionWindowEndCleared returns if the "session_window_end" field was cleared in this mutation.
func (m *AccountMutation) SessionWindowEndCleared() bool {
	_, ok := m.clearedFields[account.FieldSessionWindowEnd]
	return ok
}

// ResetSessionWindowEnd resets all changes to the "session_window_end" field.
func (m *AccountMutation) ResetSessionWindowEnd() {
	m.session_window_end = nil
	delete(m.clearedFields, account.FieldSessionWindowEnd)
}

// SetSessionWindowStatus sets the "session_window_status" field.
func (m *AccountMutation) SetSessionWindowStatus(s string) {
	m.session_window_status = &s
}

// SessionWindowStatus returns the value of the "session_window_status" field in the mutation.
func (m *AccountMutation) SessionWindowStatus() (r string, exists bool) {
	v := m.session_window_status
	if v == nil {
		return
	}
	return *v, true
}

// OldSessionWindowStatus returns the old "session_window_status" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldSessionWindowStatus(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSessionWindowStatus is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSessionWindowStatus requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSessionWindowStatus: %w", err)
	}
	return oldValue.SessionWindowStatus, nil
}

// ClearSessionWindowStatus clears the value of the "session_window_status" field.
func (m *AccountMutation) ClearSessionWindowStatus() {
	m.session_window_status = nil
	m.clearedFields[account.FieldSessionWindowStatus] = struct{}{}
}

// SessionWindowStatusCleared returns if the "session_window_status" field was cleared in this mutation.
func (m *AccountMutation) SessionWindowStatusCleared() bool {
	_, ok := m.clearedFields[account.FieldSessionWindowStatus]
	return ok
}

// ResetSessionWindowStatus resets all changes to the "session_window_status" field.
func (m *AccountMutation) ResetSessionWindowStatus() {
	m.session_window_status = nil
	delete(m.clearedFields, account.FieldSessionWindowStatus)
}

// AddGroupIDs adds the "groups" edge to the Group entity by ids.
func (m *AccountMutation) AddGroupIDs(ids ...int64) {
	if m.groups == nil {
		m.groups = make(map[int64]struct{})
	}
	for i := range ids {
		m.groups[ids[i]] = struct{}{}
	}
}

// ClearGroups clears the "groups" edge to the Group entity.
func (m *AccountMutation) ClearGroups() {
	m.clearedgroups = true
}

// GroupsCleared reports if the "groups" edge to the Group entity was cleared.
func (m *AccountMutation) GroupsCleared() bool {
	return m.clearedgroups
}

// RemoveGroupIDs removes the "groups" edge to the Group entity by IDs.
func (m *AccountMutation) RemoveGroupIDs(ids ...int64) {
	if m.removedgroups == nil {
		m.removedgroups = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.groups, ids[i])
		m.removedgroups[ids[i]] = struct{}{}
	}
}

// RemovedGroups returns the removed IDs of the "groups" edge to the Group entity.
func (m *AccountMutation) RemovedGroupsIDs() (ids []int64) {
	for id := range m.removedgroups {
		ids = append(ids, id)
	}
	return
}

// GroupsIDs returns the "groups" edge IDs in the mutation.
func (m *AccountMutation) GroupsIDs() (ids []int64) {
	for id := range m.groups {
		ids = append(ids, id)
	}
	return
}

// ResetGroups resets all changes to the "groups" edge.
func (m *AccountMutation) ResetGroups() {
	m.groups = nil
	m.clearedgroups = false
	m.removedgroups = nil
}

// ClearProxy clears the "proxy" edge to the Proxy entity.
func (m *AccountMutation) ClearProxy() {
	m.clearedproxy = true
	m.clearedFields[account.FieldProxyID] = struct{}{}
}

// ProxyCleared reports if the "proxy" edge to the Proxy entity was cleared.
func (m *AccountMutation) ProxyCleared() bool {
	return m.ProxyIDCleared() || m.clearedproxy
}

// ProxyIDs returns the "proxy" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// ProxyID instead. It exists only for internal usage by the builders.
func (m *AccountMutation) ProxyIDs() (ids []int64) {
	if id := m.proxy; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetProxy resets all changes to the "proxy" edge.
func (m *AccountMutation) ResetProxy() {
	m.proxy = nil
	m.clearedproxy = false
}

// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by ids.
func (m *AccountMutation) AddUsageLogIDs(ids ...int64) {
	if m.usage_logs == nil {
		m.usage_logs = make(map[int64]struct{})
	}
	for i := range ids {
		m.usage_logs[ids[i]] = struct{}{}
	}
}

// ClearUsageLogs clears the "usage_logs" edge to the UsageLog entity.
func (m *AccountMutation) ClearUsageLogs() {
	m.clearedusage_logs = true
}

// UsageLogsCleared reports if the "usage_logs" edge to the UsageLog entity was cleared.
func (m *AccountMutation) UsageLogsCleared() bool {
	return m.clearedusage_logs
}

// RemoveUsageLogIDs removes the "usage_logs" edge to the UsageLog entity by IDs.
func (m *AccountMutation) RemoveUsageLogIDs(ids ...int64) {
	if m.removedusage_logs == nil {
		m.removedusage_logs = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.usage_logs, ids[i])
		m.removedusage_logs[ids[i]] = struct{}{}
	}
}

// RemovedUsageLogs returns the removed IDs of the "usage_logs" edge to the UsageLog entity.
func (m *AccountMutation) RemovedUsageLogsIDs() (ids []int64) {
	for id := range m.removedusage_logs {
		ids = append(ids, id)
	}
	return
}

// UsageLogsIDs returns the "usage_logs" edge IDs in the mutation.
func (m *AccountMutation) UsageLogsIDs() (ids []int64) {
	for id := range m.usage_logs {
		ids = append(ids, id)
	}
	return
}

// ResetUsageLogs resets all changes to the "usage_logs" edge.
func (m *AccountMutation) ResetUsageLogs() {
	m.usage_logs = nil
	m.clearedusage_logs = false
	m.removedusage_logs = nil
}

// Where appends a list predicates to the AccountMutation builder.
func (m *AccountMutation) Where(ps ...predicate.Account) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the AccountMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *AccountMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.Account, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *AccountMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *AccountMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (Account).
func (m *AccountMutation) 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 *AccountMutation) Fields() []string {
	fields := make([]string, 0, 28)
	if m.created_at != nil {
		fields = append(fields, account.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, account.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, account.FieldDeletedAt)
	}
	if m.name != nil {
		fields = append(fields, account.FieldName)
	}
	if m.notes != nil {
		fields = append(fields, account.FieldNotes)
	}
	if m.platform != nil {
		fields = append(fields, account.FieldPlatform)
	}
	if m._type != nil {
		fields = append(fields, account.FieldType)
	}
	if m.credentials != nil {
		fields = append(fields, account.FieldCredentials)
	}
	if m.extra != nil {
		fields = append(fields, account.FieldExtra)
	}
	if m.proxy != nil {
		fields = append(fields, account.FieldProxyID)
	}
	if m.concurrency != nil {
		fields = append(fields, account.FieldConcurrency)
	}
	if m.load_factor != nil {
		fields = append(fields, account.FieldLoadFactor)
	}
	if m.priority != nil {
		fields = append(fields, account.FieldPriority)
	}
	if m.rate_multiplier != nil {
		fields = append(fields, account.FieldRateMultiplier)
	}
	if m.status != nil {
		fields = append(fields, account.FieldStatus)
	}
	if m.error_message != nil {
		fields = append(fields, account.FieldErrorMessage)
	}
	if m.last_used_at != nil {
		fields = append(fields, account.FieldLastUsedAt)
	}
	if m.expires_at != nil {
		fields = append(fields, account.FieldExpiresAt)
	}
	if m.auto_pause_on_expired != nil {
		fields = append(fields, account.FieldAutoPauseOnExpired)
	}
	if m.schedulable != nil {
		fields = append(fields, account.FieldSchedulable)
	}
	if m.rate_limited_at != nil {
		fields = append(fields, account.FieldRateLimitedAt)
	}
	if m.rate_limit_reset_at != nil {
		fields = append(fields, account.FieldRateLimitResetAt)
	}
	if m.overload_until != nil {
		fields = append(fields, account.FieldOverloadUntil)
	}
	if m.temp_unschedulable_until != nil {
		fields = append(fields, account.FieldTempUnschedulableUntil)
	}
	if m.temp_unschedulable_reason != nil {
		fields = append(fields, account.FieldTempUnschedulableReason)
	}
	if m.session_window_start != nil {
		fields = append(fields, account.FieldSessionWindowStart)
	}
	if m.session_window_end != nil {
		fields = append(fields, account.FieldSessionWindowEnd)
	}
	if m.session_window_status != nil {
		fields = append(fields, account.FieldSessionWindowStatus)
	}
	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 *AccountMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case account.FieldCreatedAt:
		return m.CreatedAt()
	case account.FieldUpdatedAt:
		return m.UpdatedAt()
	case account.FieldDeletedAt:
		return m.DeletedAt()
	case account.FieldName:
		return m.Name()
	case account.FieldNotes:
		return m.Notes()
	case account.FieldPlatform:
		return m.Platform()
	case account.FieldType:
		return m.GetType()
	case account.FieldCredentials:
		return m.Credentials()
	case account.FieldExtra:
		return m.Extra()
	case account.FieldProxyID:
		return m.ProxyID()
	case account.FieldConcurrency:
		return m.Concurrency()
	case account.FieldLoadFactor:
		return m.LoadFactor()
	case account.FieldPriority:
		return m.Priority()
	case account.FieldRateMultiplier:
		return m.RateMultiplier()
	case account.FieldStatus:
		return m.Status()
	case account.FieldErrorMessage:
		return m.ErrorMessage()
	case account.FieldLastUsedAt:
		return m.LastUsedAt()
	case account.FieldExpiresAt:
		return m.ExpiresAt()
	case account.FieldAutoPauseOnExpired:
		return m.AutoPauseOnExpired()
	case account.FieldSchedulable:
		return m.Schedulable()
	case account.FieldRateLimitedAt:
		return m.RateLimitedAt()
	case account.FieldRateLimitResetAt:
		return m.RateLimitResetAt()
	case account.FieldOverloadUntil:
		return m.OverloadUntil()
	case account.FieldTempUnschedulableUntil:
		return m.TempUnschedulableUntil()
	case account.FieldTempUnschedulableReason:
		return m.TempUnschedulableReason()
	case account.FieldSessionWindowStart:
		return m.SessionWindowStart()
	case account.FieldSessionWindowEnd:
		return m.SessionWindowEnd()
	case account.FieldSessionWindowStatus:
		return m.SessionWindowStatus()
	}
	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 *AccountMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case account.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case account.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case account.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case account.FieldName:
		return m.OldName(ctx)
	case account.FieldNotes:
		return m.OldNotes(ctx)
	case account.FieldPlatform:
		return m.OldPlatform(ctx)
	case account.FieldType:
		return m.OldType(ctx)
	case account.FieldCredentials:
		return m.OldCredentials(ctx)
	case account.FieldExtra:
		return m.OldExtra(ctx)
	case account.FieldProxyID:
		return m.OldProxyID(ctx)
	case account.FieldConcurrency:
		return m.OldConcurrency(ctx)
	case account.FieldLoadFactor:
		return m.OldLoadFactor(ctx)
	case account.FieldPriority:
		return m.OldPriority(ctx)
	case account.FieldRateMultiplier:
		return m.OldRateMultiplier(ctx)
	case account.FieldStatus:
		return m.OldStatus(ctx)
	case account.FieldErrorMessage:
		return m.OldErrorMessage(ctx)
	case account.FieldLastUsedAt:
		return m.OldLastUsedAt(ctx)
	case account.FieldExpiresAt:
		return m.OldExpiresAt(ctx)
	case account.FieldAutoPauseOnExpired:
		return m.OldAutoPauseOnExpired(ctx)
	case account.FieldSchedulable:
		return m.OldSchedulable(ctx)
	case account.FieldRateLimitedAt:
		return m.OldRateLimitedAt(ctx)
	case account.FieldRateLimitResetAt:
		return m.OldRateLimitResetAt(ctx)
	case account.FieldOverloadUntil:
		return m.OldOverloadUntil(ctx)
	case account.FieldTempUnschedulableUntil:
		return m.OldTempUnschedulableUntil(ctx)
	case account.FieldTempUnschedulableReason:
		return m.OldTempUnschedulableReason(ctx)
	case account.FieldSessionWindowStart:
		return m.OldSessionWindowStart(ctx)
	case account.FieldSessionWindowEnd:
		return m.OldSessionWindowEnd(ctx)
	case account.FieldSessionWindowStatus:
		return m.OldSessionWindowStatus(ctx)
	}
	return nil, fmt.Errorf("unknown Account 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 *AccountMutation) SetField(name string, value ent.Value) error {
	switch name {
	case account.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 account.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 account.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 account.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case account.FieldNotes:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNotes(v)
		return nil
	case account.FieldPlatform:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPlatform(v)
		return nil
	case account.FieldType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetType(v)
		return nil
	case account.FieldCredentials:
		v, ok := value.(map[string]interface{})
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCredentials(v)
		return nil
	case account.FieldExtra:
		v, ok := value.(map[string]interface{})
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetExtra(v)
		return nil
	case account.FieldProxyID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProxyID(v)
		return nil
	case account.FieldConcurrency:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetConcurrency(v)
		return nil
	case account.FieldLoadFactor:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLoadFactor(v)
		return nil
	case account.FieldPriority:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPriority(v)
		return nil
	case account.FieldRateMultiplier:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRateMultiplier(v)
		return nil
	case account.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case account.FieldErrorMessage:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetErrorMessage(v)
		return nil
	case account.FieldLastUsedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastUsedAt(v)
		return nil
	case account.FieldExpiresAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetExpiresAt(v)
		return nil
	case account.FieldAutoPauseOnExpired:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAutoPauseOnExpired(v)
		return nil
	case account.FieldSchedulable:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSchedulable(v)
		return nil
	case account.FieldRateLimitedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRateLimitedAt(v)
		return nil
	case account.FieldRateLimitResetAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRateLimitResetAt(v)
		return nil
	case account.FieldOverloadUntil:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOverloadUntil(v)
		return nil
	case account.FieldTempUnschedulableUntil:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTempUnschedulableUntil(v)
		return nil
	case account.FieldTempUnschedulableReason:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTempUnschedulableReason(v)
		return nil
	case account.FieldSessionWindowStart:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSessionWindowStart(v)
		return nil
	case account.FieldSessionWindowEnd:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSessionWindowEnd(v)
		return nil
	case account.FieldSessionWindowStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSessionWindowStatus(v)
		return nil
	}
	return fmt.Errorf("unknown Account field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *AccountMutation) AddedFields() []string {
	var fields []string
	if m.addconcurrency != nil {
		fields = append(fields, account.FieldConcurrency)
	}
	if m.addload_factor != nil {
		fields = append(fields, account.FieldLoadFactor)
	}
	if m.addpriority != nil {
		fields = append(fields, account.FieldPriority)
	}
	if m.addrate_multiplier != nil {
		fields = append(fields, account.FieldRateMultiplier)
	}
	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 *AccountMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case account.FieldConcurrency:
		return m.AddedConcurrency()
	case account.FieldLoadFactor:
		return m.AddedLoadFactor()
	case account.FieldPriority:
		return m.AddedPriority()
	case account.FieldRateMultiplier:
		return m.AddedRateMultiplier()
	}
	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 *AccountMutation) AddField(name string, value ent.Value) error {
	switch name {
	case account.FieldConcurrency:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddConcurrency(v)
		return nil
	case account.FieldLoadFactor:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddLoadFactor(v)
		return nil
	case account.FieldPriority:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPriority(v)
		return nil
	case account.FieldRateMultiplier:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddRateMultiplier(v)
		return nil
	}
	return fmt.Errorf("unknown Account numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *AccountMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(account.FieldDeletedAt) {
		fields = append(fields, account.FieldDeletedAt)
	}
	if m.FieldCleared(account.FieldNotes) {
		fields = append(fields, account.FieldNotes)
	}
	if m.FieldCleared(account.FieldProxyID) {
		fields = append(fields, account.FieldProxyID)
	}
	if m.FieldCleared(account.FieldLoadFactor) {
		fields = append(fields, account.FieldLoadFactor)
	}
	if m.FieldCleared(account.FieldErrorMessage) {
		fields = append(fields, account.FieldErrorMessage)
	}
	if m.FieldCleared(account.FieldLastUsedAt) {
		fields = append(fields, account.FieldLastUsedAt)
	}
	if m.FieldCleared(account.FieldExpiresAt) {
		fields = append(fields, account.FieldExpiresAt)
	}
	if m.FieldCleared(account.FieldRateLimitedAt) {
		fields = append(fields, account.FieldRateLimitedAt)
	}
	if m.FieldCleared(account.FieldRateLimitResetAt) {
		fields = append(fields, account.FieldRateLimitResetAt)
	}
	if m.FieldCleared(account.FieldOverloadUntil) {
		fields = append(fields, account.FieldOverloadUntil)
	}
	if m.FieldCleared(account.FieldTempUnschedulableUntil) {
		fields = append(fields, account.FieldTempUnschedulableUntil)
	}
	if m.FieldCleared(account.FieldTempUnschedulableReason) {
		fields = append(fields, account.FieldTempUnschedulableReason)
	}
	if m.FieldCleared(account.FieldSessionWindowStart) {
		fields = append(fields, account.FieldSessionWindowStart)
	}
	if m.FieldCleared(account.FieldSessionWindowEnd) {
		fields = append(fields, account.FieldSessionWindowEnd)
	}
	if m.FieldCleared(account.FieldSessionWindowStatus) {
		fields = append(fields, account.FieldSessionWindowStatus)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *AccountMutation) 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 *AccountMutation) ClearField(name string) error {
	switch name {
	case account.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	case account.FieldNotes:
		m.ClearNotes()
		return nil
	case account.FieldProxyID:
		m.ClearProxyID()
		return nil
	case account.FieldLoadFactor:
		m.ClearLoadFactor()
		return nil
	case account.FieldErrorMessage:
		m.ClearErrorMessage()
		return nil
	case account.FieldLastUsedAt:
		m.ClearLastUsedAt()
		return nil
	case account.FieldExpiresAt:
		m.ClearExpiresAt()
		return nil
	case account.FieldRateLimitedAt:
		m.ClearRateLimitedAt()
		return nil
	case account.FieldRateLimitResetAt:
		m.ClearRateLimitResetAt()
		return nil
	case account.FieldOverloadUntil:
		m.ClearOverloadUntil()
		return nil
	case account.FieldTempUnschedulableUntil:
		m.ClearTempUnschedulableUntil()
		return nil
	case account.FieldTempUnschedulableReason:
		m.ClearTempUnschedulableReason()
		return nil
	case account.FieldSessionWindowStart:
		m.ClearSessionWindowStart()
		return nil
	case account.FieldSessionWindowEnd:
		m.ClearSessionWindowEnd()
		return nil
	case account.FieldSessionWindowStatus:
		m.ClearSessionWindowStatus()
		return nil
	}
	return fmt.Errorf("unknown Account 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 *AccountMutation) ResetField(name string) error {
	switch name {
	case account.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case account.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case account.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case account.FieldName:
		m.ResetName()
		return nil
	case account.FieldNotes:
		m.ResetNotes()
		return nil
	case account.FieldPlatform:
		m.ResetPlatform()
		return nil
	case account.FieldType:
		m.ResetType()
		return nil
	case account.FieldCredentials:
		m.ResetCredentials()
		return nil
	case account.FieldExtra:
		m.ResetExtra()
		return nil
	case account.FieldProxyID:
		m.ResetProxyID()
		return nil
	case account.FieldConcurrency:
		m.ResetConcurrency()
		return nil
	case account.FieldLoadFactor:
		m.ResetLoadFactor()
		return nil
	case account.FieldPriority:
		m.ResetPriority()
		return nil
	case account.FieldRateMultiplier:
		m.ResetRateMultiplier()
		return nil
	case account.FieldStatus:
		m.ResetStatus()
		return nil
	case account.FieldErrorMessage:
		m.ResetErrorMessage()
		return nil
	case account.FieldLastUsedAt:
		m.ResetLastUsedAt()
		return nil
	case account.FieldExpiresAt:
		m.ResetExpiresAt()
		return nil
	case account.FieldAutoPauseOnExpired:
		m.ResetAutoPauseOnExpired()
		return nil
	case account.FieldSchedulable:
		m.ResetSchedulable()
		return nil
	case account.FieldRateLimitedAt:
		m.ResetRateLimitedAt()
		return nil
	case account.FieldRateLimitResetAt:
		m.ResetRateLimitResetAt()
		return nil
	case account.FieldOverloadUntil:
		m.ResetOverloadUntil()
		return nil
	case account.FieldTempUnschedulableUntil:
		m.ResetTempUnschedulableUntil()
		return nil
	case account.FieldTempUnschedulableReason:
		m.ResetTempUnschedulableReason()
		return nil
	case account.FieldSessionWindowStart:
		m.ResetSessionWindowStart()
		return nil
	case account.FieldSessionWindowEnd:
		m.ResetSessionWindowEnd()
		return nil
	case account.FieldSessionWindowStatus:
		m.ResetSessionWindowStatus()
		return nil
	}
	return fmt.Errorf("unknown Account field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *AccountMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.groups != nil {
		edges = append(edges, account.EdgeGroups)
	}
	if m.proxy != nil {
		edges = append(edges, account.EdgeProxy)
	}
	if m.usage_logs != nil {
		edges = append(edges, account.EdgeUsageLogs)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *AccountMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case account.EdgeGroups:
		ids := make([]ent.Value, 0, len(m.groups))
		for id := range m.groups {
			ids = append(ids, id)
		}
		return ids
	case account.EdgeProxy:
		if id := m.proxy; id != nil {
			return []ent.Value{*id}
		}
	case account.EdgeUsageLogs:
		ids := make([]ent.Value, 0, len(m.usage_logs))
		for id := range m.usage_logs {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *AccountMutation) RemovedEdges() []string {
	edges := make([]string, 0, 3)
	if m.removedgroups != nil {
		edges = append(edges, account.EdgeGroups)
	}
	if m.removedusage_logs != nil {
		edges = append(edges, account.EdgeUsageLogs)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *AccountMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case account.EdgeGroups:
		ids := make([]ent.Value, 0, len(m.removedgroups))
		for id := range m.removedgroups {
			ids = append(ids, id)
		}
		return ids
	case account.EdgeUsageLogs:
		ids := make([]ent.Value, 0, len(m.removedusage_logs))
		for id := range m.removedusage_logs {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *AccountMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.clearedgroups {
		edges = append(edges, account.EdgeGroups)
	}
	if m.clearedproxy {
		edges = append(edges, account.EdgeProxy)
	}
	if m.clearedusage_logs {
		edges = append(edges, account.EdgeUsageLogs)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *AccountMutation) EdgeCleared(name string) bool {
	switch name {
	case account.EdgeGroups:
		return m.clearedgroups
	case account.EdgeProxy:
		return m.clearedproxy
	case account.EdgeUsageLogs:
		return m.clearedusage_logs
	}
	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 *AccountMutation) ClearEdge(name string) error {
	switch name {
	case account.EdgeProxy:
		m.ClearProxy()
		return nil
	}
	return fmt.Errorf("unknown Account 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 *AccountMutation) ResetEdge(name string) error {
	switch name {
	case account.EdgeGroups:
		m.ResetGroups()
		return nil
	case account.EdgeProxy:
		m.ResetProxy()
		return nil
	case account.EdgeUsageLogs:
		m.ResetUsageLogs()
		return nil
	}
	return fmt.Errorf("unknown Account edge %s", name)
}

// AccountGroupMutation represents an operation that mutates the AccountGroup nodes in the graph.
type AccountGroupMutation struct {
	config
	op             Op
	typ            string
	priority       *int
	addpriority    *int
	created_at     *time.Time
	clearedFields  map[string]struct{}
	account        *int64
	clearedaccount bool
	group          *int64
	clearedgroup   bool
	done           bool
	oldValue       func(context.Context) (*AccountGroup, error)
	predicates     []predicate.AccountGroup
}

var _ ent.Mutation = (*AccountGroupMutation)(nil)

// accountgroupOption allows management of the mutation configuration using functional options.
type accountgroupOption func(*AccountGroupMutation)

// newAccountGroupMutation creates new mutation for the AccountGroup entity.
func newAccountGroupMutation(c config, op Op, opts ...accountgroupOption) *AccountGroupMutation {
	m := &AccountGroupMutation{
		config:        c,
		op:            op,
		typ:           TypeAccountGroup,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// 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 AccountGroupMutation) 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 AccountGroupMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetAccountID sets the "account_id" field.
func (m *AccountGroupMutation) SetAccountID(i int64) {
	m.account = &i
}

// AccountID returns the value of the "account_id" field in the mutation.
func (m *AccountGroupMutation) AccountID() (r int64, exists bool) {
	v := m.account
	if v == nil {
		return
	}
	return *v, true
}

// ResetAccountID resets all changes to the "account_id" field.
func (m *AccountGroupMutation) ResetAccountID() {
	m.account = nil
}

// SetGroupID sets the "group_id" field.
func (m *AccountGroupMutation) SetGroupID(i int64) {
	m.group = &i
}

// GroupID returns the value of the "group_id" field in the mutation.
func (m *AccountGroupMutation) GroupID() (r int64, exists bool) {
	v := m.group
	if v == nil {
		return
	}
	return *v, true
}

// ResetGroupID resets all changes to the "group_id" field.
func (m *AccountGroupMutation) ResetGroupID() {
	m.group = nil
}

// SetPriority sets the "priority" field.
func (m *AccountGroupMutation) SetPriority(i int) {
	m.priority = &i
	m.addpriority = nil
}

// Priority returns the value of the "priority" field in the mutation.
func (m *AccountGroupMutation) Priority() (r int, exists bool) {
	v := m.priority
	if v == nil {
		return
	}
	return *v, true
}

// AddPriority adds i to the "priority" field.
func (m *AccountGroupMutation) AddPriority(i int) {
	if m.addpriority != nil {
		*m.addpriority += i
	} else {
		m.addpriority = &i
	}
}

// AddedPriority returns the value that was added to the "priority" field in this mutation.
func (m *AccountGroupMutation) AddedPriority() (r int, exists bool) {
	v := m.addpriority
	if v == nil {
		return
	}
	return *v, true
}

// ResetPriority resets all changes to the "priority" field.
func (m *AccountGroupMutation) ResetPriority() {
	m.priority = nil
	m.addpriority = nil
}

// SetCreatedAt sets the "created_at" field.
func (m *AccountGroupMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *AccountGroupMutation) CreatedAt() (r time.Time, exists bool) {
	v := m.created_at
	if v == nil {
		return
	}
	return *v, true
}

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *AccountGroupMutation) ResetCreatedAt() {
	m.created_at = nil
}

// ClearAccount clears the "account" edge to the Account entity.
func (m *AccountGroupMutation) ClearAccount() {
	m.clearedaccount = true
	m.clearedFields[accountgroup.FieldAccountID] = struct{}{}
}

// AccountCleared reports if the "account" edge to the Account entity was cleared.
func (m *AccountGroupMutation) AccountCleared() bool {
	return m.clearedaccount
}

// AccountIDs returns the "account" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// AccountID instead. It exists only for internal usage by the builders.
func (m *AccountGroupMutation) AccountIDs() (ids []int64) {
	if id := m.account; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetAccount resets all changes to the "account" edge.
func (m *AccountGroupMutation) ResetAccount() {
	m.account = nil
	m.clearedaccount = false
}

// ClearGroup clears the "group" edge to the Group entity.
func (m *AccountGroupMutation) ClearGroup() {
	m.clearedgroup = true
	m.clearedFields[accountgroup.FieldGroupID] = struct{}{}
}

// GroupCleared reports if the "group" edge to the Group entity was cleared.
func (m *AccountGroupMutation) GroupCleared() bool {
	return m.clearedgroup
}

// GroupIDs returns the "group" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// GroupID instead. It exists only for internal usage by the builders.
func (m *AccountGroupMutation) GroupIDs() (ids []int64) {
	if id := m.group; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetGroup resets all changes to the "group" edge.
func (m *AccountGroupMutation) ResetGroup() {
	m.group = nil
	m.clearedgroup = false
}

// Where appends a list predicates to the AccountGroupMutation builder.
func (m *AccountGroupMutation) Where(ps ...predicate.AccountGroup) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the AccountGroupMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *AccountGroupMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.AccountGroup, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *AccountGroupMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *AccountGroupMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (AccountGroup).
func (m *AccountGroupMutation) 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 *AccountGroupMutation) Fields() []string {
	fields := make([]string, 0, 4)
	if m.account != nil {
		fields = append(fields, accountgroup.FieldAccountID)
	}
	if m.group != nil {
		fields = append(fields, accountgroup.FieldGroupID)
	}
	if m.priority != nil {
		fields = append(fields, accountgroup.FieldPriority)
	}
	if m.created_at != nil {
		fields = append(fields, accountgroup.FieldCreatedAt)
	}
	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 *AccountGroupMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case accountgroup.FieldAccountID:
		return m.AccountID()
	case accountgroup.FieldGroupID:
		return m.GroupID()
	case accountgroup.FieldPriority:
		return m.Priority()
	case accountgroup.FieldCreatedAt:
		return m.CreatedAt()
	}
	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 *AccountGroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	return nil, errors.New("edge schema AccountGroup does not support getting old values")
}

// 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 *AccountGroupMutation) SetField(name string, value ent.Value) error {
	switch name {
	case accountgroup.FieldAccountID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAccountID(v)
		return nil
	case accountgroup.FieldGroupID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetGroupID(v)
		return nil
	case accountgroup.FieldPriority:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPriority(v)
		return nil
	case accountgroup.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown AccountGroup field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *AccountGroupMutation) AddedFields() []string {
	var fields []string
	if m.addpriority != nil {
		fields = append(fields, accountgroup.FieldPriority)
	}
	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 *AccountGroupMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case accountgroup.FieldPriority:
		return m.AddedPriority()
	}
	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 *AccountGroupMutation) AddField(name string, value ent.Value) error {
	switch name {
	case accountgroup.FieldPriority:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPriority(v)
		return nil
	}
	return fmt.Errorf("unknown AccountGroup numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *AccountGroupMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *AccountGroupMutation) 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 *AccountGroupMutation) ClearField(name string) error {
	return fmt.Errorf("unknown AccountGroup 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 *AccountGroupMutation) ResetField(name string) error {
	switch name {
	case accountgroup.FieldAccountID:
		m.ResetAccountID()
		return nil
	case accountgroup.FieldGroupID:
		m.ResetGroupID()
		return nil
	case accountgroup.FieldPriority:
		m.ResetPriority()
		return nil
	case accountgroup.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown AccountGroup field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *AccountGroupMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.account != nil {
		edges = append(edges, accountgroup.EdgeAccount)
	}
	if m.group != nil {
		edges = append(edges, accountgroup.EdgeGroup)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *AccountGroupMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case accountgroup.EdgeAccount:
		if id := m.account; id != nil {
			return []ent.Value{*id}
		}
	case accountgroup.EdgeGroup:
		if id := m.group; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *AccountGroupMutation) 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 *AccountGroupMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *AccountGroupMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedaccount {
		edges = append(edges, accountgroup.EdgeAccount)
	}
	if m.clearedgroup {
		edges = append(edges, accountgroup.EdgeGroup)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *AccountGroupMutation) EdgeCleared(name string) bool {
	switch name {
	case accountgroup.EdgeAccount:
		return m.clearedaccount
	case accountgroup.EdgeGroup:
		return m.clearedgroup
	}
	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 *AccountGroupMutation) ClearEdge(name string) error {
	switch name {
	case accountgroup.EdgeAccount:
		m.ClearAccount()
		return nil
	case accountgroup.EdgeGroup:
		m.ClearGroup()
		return nil
	}
	return fmt.Errorf("unknown AccountGroup 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 *AccountGroupMutation) ResetEdge(name string) error {
	switch name {
	case accountgroup.EdgeAccount:
		m.ResetAccount()
		return nil
	case accountgroup.EdgeGroup:
		m.ResetGroup()
		return nil
	}
	return fmt.Errorf("unknown AccountGroup edge %s", name)
}

// AnnouncementMutation represents an operation that mutates the Announcement nodes in the graph.
type AnnouncementMutation struct {
	config
	op            Op
	typ           string
	id            *int64
	title         *string
	content       *string
	status        *string
	notify_mode   *string
	targeting     *domain.AnnouncementTargeting
	starts_at     *time.Time
	ends_at       *time.Time
	created_by    *int64
	addcreated_by *int64
	updated_by    *int64
	addupdated_by *int64
	created_at    *time.Time
	updated_at    *time.Time
	clearedFields map[string]struct{}
	reads         map[int64]struct{}
	removedreads  map[int64]struct{}
	clearedreads  bool
	done          bool
	oldValue      func(context.Context) (*Announcement, error)
	predicates    []predicate.Announcement
}

var _ ent.Mutation = (*AnnouncementMutation)(nil)

// announcementOption allows management of the mutation configuration using functional options.
type announcementOption func(*AnnouncementMutation)

// newAnnouncementMutation creates new mutation for the Announcement entity.
func newAnnouncementMutation(c config, op Op, opts ...announcementOption) *AnnouncementMutation {
	m := &AnnouncementMutation{
		config:        c,
		op:            op,
		typ:           TypeAnnouncement,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withAnnouncementID sets the ID field of the mutation.
func withAnnouncementID(id int64) announcementOption {
	return func(m *AnnouncementMutation) {
		var (
			err   error
			once  sync.Once
			value *Announcement
		)
		m.oldValue = func(ctx context.Context) (*Announcement, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Announcement.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withAnnouncement sets the old Announcement of the mutation.
func withAnnouncement(node *Announcement) announcementOption {
	return func(m *AnnouncementMutation) {
		m.oldValue = func(context.Context) (*Announcement, 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 AnnouncementMutation) 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 AnnouncementMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *AnnouncementMutation) ID() (id int64, 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 *AnnouncementMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Announcement.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetTitle sets the "title" field.
func (m *AnnouncementMutation) SetTitle(s string) {
	m.title = &s
}

// Title returns the value of the "title" field in the mutation.
func (m *AnnouncementMutation) Title() (r string, exists bool) {
	v := m.title
	if v == nil {
		return
	}
	return *v, true
}

// OldTitle returns the old "title" field's value of the Announcement entity.
// If the Announcement object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementMutation) OldTitle(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTitle is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTitle requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTitle: %w", err)
	}
	return oldValue.Title, nil
}

// ResetTitle resets all changes to the "title" field.
func (m *AnnouncementMutation) ResetTitle() {
	m.title = nil
}

// SetContent sets the "content" field.
func (m *AnnouncementMutation) SetContent(s string) {
	m.content = &s
}

// Content returns the value of the "content" field in the mutation.
func (m *AnnouncementMutation) Content() (r string, exists bool) {
	v := m.content
	if v == nil {
		return
	}
	return *v, true
}

// OldContent returns the old "content" field's value of the Announcement entity.
// If the Announcement object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementMutation) OldContent(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldContent is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldContent requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldContent: %w", err)
	}
	return oldValue.Content, nil
}

// ResetContent resets all changes to the "content" field.
func (m *AnnouncementMutation) ResetContent() {
	m.content = nil
}

// SetStatus sets the "status" field.
func (m *AnnouncementMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *AnnouncementMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the Announcement entity.
// If the Announcement object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementMutation) OldStatus(ctx context.Context) (v string, 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 *AnnouncementMutation) ResetStatus() {
	m.status = nil
}

// SetNotifyMode sets the "notify_mode" field.
func (m *AnnouncementMutation) SetNotifyMode(s string) {
	m.notify_mode = &s
}

// NotifyMode returns the value of the "notify_mode" field in the mutation.
func (m *AnnouncementMutation) NotifyMode() (r string, exists bool) {
	v := m.notify_mode
	if v == nil {
		return
	}
	return *v, true
}

// OldNotifyMode returns the old "notify_mode" field's value of the Announcement entity.
// If the Announcement object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementMutation) OldNotifyMode(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldNotifyMode is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldNotifyMode requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldNotifyMode: %w", err)
	}
	return oldValue.NotifyMode, nil
}

// ResetNotifyMode resets all changes to the "notify_mode" field.
func (m *AnnouncementMutation) ResetNotifyMode() {
	m.notify_mode = nil
}

// SetTargeting sets the "targeting" field.
func (m *AnnouncementMutation) SetTargeting(dt domain.AnnouncementTargeting) {
	m.targeting = &dt
}

// Targeting returns the value of the "targeting" field in the mutation.
func (m *AnnouncementMutation) Targeting() (r domain.AnnouncementTargeting, exists bool) {
	v := m.targeting
	if v == nil {
		return
	}
	return *v, true
}

// OldTargeting returns the old "targeting" field's value of the Announcement entity.
// If the Announcement object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementMutation) OldTargeting(ctx context.Context) (v domain.AnnouncementTargeting, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTargeting is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTargeting requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTargeting: %w", err)
	}
	return oldValue.Targeting, nil
}

// ClearTargeting clears the value of the "targeting" field.
func (m *AnnouncementMutation) ClearTargeting() {
	m.targeting = nil
	m.clearedFields[announcement.FieldTargeting] = struct{}{}
}

// TargetingCleared returns if the "targeting" field was cleared in this mutation.
func (m *AnnouncementMutation) TargetingCleared() bool {
	_, ok := m.clearedFields[announcement.FieldTargeting]
	return ok
}

// ResetTargeting resets all changes to the "targeting" field.
func (m *AnnouncementMutation) ResetTargeting() {
	m.targeting = nil
	delete(m.clearedFields, announcement.FieldTargeting)
}

// SetStartsAt sets the "starts_at" field.
func (m *AnnouncementMutation) SetStartsAt(t time.Time) {
	m.starts_at = &t
}

// StartsAt returns the value of the "starts_at" field in the mutation.
func (m *AnnouncementMutation) StartsAt() (r time.Time, exists bool) {
	v := m.starts_at
	if v == nil {
		return
	}
	return *v, true
}

// OldStartsAt returns the old "starts_at" field's value of the Announcement entity.
// If the Announcement object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementMutation) OldStartsAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldStartsAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldStartsAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldStartsAt: %w", err)
	}
	return oldValue.StartsAt, nil
}

// ClearStartsAt clears the value of the "starts_at" field.
func (m *AnnouncementMutation) ClearStartsAt() {
	m.starts_at = nil
	m.clearedFields[announcement.FieldStartsAt] = struct{}{}
}

// StartsAtCleared returns if the "starts_at" field was cleared in this mutation.
func (m *AnnouncementMutation) StartsAtCleared() bool {
	_, ok := m.clearedFields[announcement.FieldStartsAt]
	return ok
}

// ResetStartsAt resets all changes to the "starts_at" field.
func (m *AnnouncementMutation) ResetStartsAt() {
	m.starts_at = nil
	delete(m.clearedFields, announcement.FieldStartsAt)
}

// SetEndsAt sets the "ends_at" field.
func (m *AnnouncementMutation) SetEndsAt(t time.Time) {
	m.ends_at = &t
}

// EndsAt returns the value of the "ends_at" field in the mutation.
func (m *AnnouncementMutation) EndsAt() (r time.Time, exists bool) {
	v := m.ends_at
	if v == nil {
		return
	}
	return *v, true
}

// OldEndsAt returns the old "ends_at" field's value of the Announcement entity.
// If the Announcement object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementMutation) OldEndsAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldEndsAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldEndsAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldEndsAt: %w", err)
	}
	return oldValue.EndsAt, nil
}

// ClearEndsAt clears the value of the "ends_at" field.
func (m *AnnouncementMutation) ClearEndsAt() {
	m.ends_at = nil
	m.clearedFields[announcement.FieldEndsAt] = struct{}{}
}

// EndsAtCleared returns if the "ends_at" field was cleared in this mutation.
func (m *AnnouncementMutation) EndsAtCleared() bool {
	_, ok := m.clearedFields[announcement.FieldEndsAt]
	return ok
}

// ResetEndsAt resets all changes to the "ends_at" field.
func (m *AnnouncementMutation) ResetEndsAt() {
	m.ends_at = nil
	delete(m.clearedFields, announcement.FieldEndsAt)
}

// SetCreatedBy sets the "created_by" field.
func (m *AnnouncementMutation) SetCreatedBy(i int64) {
	m.created_by = &i
	m.addcreated_by = nil
}

// CreatedBy returns the value of the "created_by" field in the mutation.
func (m *AnnouncementMutation) CreatedBy() (r int64, exists bool) {
	v := m.created_by
	if v == nil {
		return
	}
	return *v, true
}

// OldCreatedBy returns the old "created_by" field's value of the Announcement entity.
// If the Announcement object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementMutation) OldCreatedBy(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCreatedBy is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCreatedBy requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCreatedBy: %w", err)
	}
	return oldValue.CreatedBy, nil
}

// AddCreatedBy adds i to the "created_by" field.
func (m *AnnouncementMutation) AddCreatedBy(i int64) {
	if m.addcreated_by != nil {
		*m.addcreated_by += i
	} else {
		m.addcreated_by = &i
	}
}

// AddedCreatedBy returns the value that was added to the "created_by" field in this mutation.
func (m *AnnouncementMutation) AddedCreatedBy() (r int64, exists bool) {
	v := m.addcreated_by
	if v == nil {
		return
	}
	return *v, true
}

// ClearCreatedBy clears the value of the "created_by" field.
func (m *AnnouncementMutation) ClearCreatedBy() {
	m.created_by = nil
	m.addcreated_by = nil
	m.clearedFields[announcement.FieldCreatedBy] = struct{}{}
}

// CreatedByCleared returns if the "created_by" field was cleared in this mutation.
func (m *AnnouncementMutation) CreatedByCleared() bool {
	_, ok := m.clearedFields[announcement.FieldCreatedBy]
	return ok
}

// ResetCreatedBy resets all changes to the "created_by" field.
func (m *AnnouncementMutation) ResetCreatedBy() {
	m.created_by = nil
	m.addcreated_by = nil
	delete(m.clearedFields, announcement.FieldCreatedBy)
}

// SetUpdatedBy sets the "updated_by" field.
func (m *AnnouncementMutation) SetUpdatedBy(i int64) {
	m.updated_by = &i
	m.addupdated_by = nil
}

// UpdatedBy returns the value of the "updated_by" field in the mutation.
func (m *AnnouncementMutation) UpdatedBy() (r int64, exists bool) {
	v := m.updated_by
	if v == nil {
		return
	}
	return *v, true
}

// OldUpdatedBy returns the old "updated_by" field's value of the Announcement entity.
// If the Announcement object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementMutation) OldUpdatedBy(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUpdatedBy is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUpdatedBy requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUpdatedBy: %w", err)
	}
	return oldValue.UpdatedBy, nil
}

// AddUpdatedBy adds i to the "updated_by" field.
func (m *AnnouncementMutation) AddUpdatedBy(i int64) {
	if m.addupdated_by != nil {
		*m.addupdated_by += i
	} else {
		m.addupdated_by = &i
	}
}

// AddedUpdatedBy returns the value that was added to the "updated_by" field in this mutation.
func (m *AnnouncementMutation) AddedUpdatedBy() (r int64, exists bool) {
	v := m.addupdated_by
	if v == nil {
		return
	}
	return *v, true
}

// ClearUpdatedBy clears the value of the "updated_by" field.
func (m *AnnouncementMutation) ClearUpdatedBy() {
	m.updated_by = nil
	m.addupdated_by = nil
	m.clearedFields[announcement.FieldUpdatedBy] = struct{}{}
}

// UpdatedByCleared returns if the "updated_by" field was cleared in this mutation.
func (m *AnnouncementMutation) UpdatedByCleared() bool {
	_, ok := m.clearedFields[announcement.FieldUpdatedBy]
	return ok
}

// ResetUpdatedBy resets all changes to the "updated_by" field.
func (m *AnnouncementMutation) ResetUpdatedBy() {
	m.updated_by = nil
	m.addupdated_by = nil
	delete(m.clearedFields, announcement.FieldUpdatedBy)
}

// SetCreatedAt sets the "created_at" field.
func (m *AnnouncementMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *AnnouncementMutation) 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 Announcement entity.
// If the Announcement object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementMutation) 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 *AnnouncementMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *AnnouncementMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *AnnouncementMutation) 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 Announcement entity.
// If the Announcement object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementMutation) 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 *AnnouncementMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// AddReadIDs adds the "reads" edge to the AnnouncementRead entity by ids.
func (m *AnnouncementMutation) AddReadIDs(ids ...int64) {
	if m.reads == nil {
		m.reads = make(map[int64]struct{})
	}
	for i := range ids {
		m.reads[ids[i]] = struct{}{}
	}
}

// ClearReads clears the "reads" edge to the AnnouncementRead entity.
func (m *AnnouncementMutation) ClearReads() {
	m.clearedreads = true
}

// ReadsCleared reports if the "reads" edge to the AnnouncementRead entity was cleared.
func (m *AnnouncementMutation) ReadsCleared() bool {
	return m.clearedreads
}

// RemoveReadIDs removes the "reads" edge to the AnnouncementRead entity by IDs.
func (m *AnnouncementMutation) RemoveReadIDs(ids ...int64) {
	if m.removedreads == nil {
		m.removedreads = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.reads, ids[i])
		m.removedreads[ids[i]] = struct{}{}
	}
}

// RemovedReads returns the removed IDs of the "reads" edge to the AnnouncementRead entity.
func (m *AnnouncementMutation) RemovedReadsIDs() (ids []int64) {
	for id := range m.removedreads {
		ids = append(ids, id)
	}
	return
}

// ReadsIDs returns the "reads" edge IDs in the mutation.
func (m *AnnouncementMutation) ReadsIDs() (ids []int64) {
	for id := range m.reads {
		ids = append(ids, id)
	}
	return
}

// ResetReads resets all changes to the "reads" edge.
func (m *AnnouncementMutation) ResetReads() {
	m.reads = nil
	m.clearedreads = false
	m.removedreads = nil
}

// Where appends a list predicates to the AnnouncementMutation builder.
func (m *AnnouncementMutation) Where(ps ...predicate.Announcement) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the AnnouncementMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *AnnouncementMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.Announcement, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *AnnouncementMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *AnnouncementMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (Announcement).
func (m *AnnouncementMutation) 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 *AnnouncementMutation) Fields() []string {
	fields := make([]string, 0, 11)
	if m.title != nil {
		fields = append(fields, announcement.FieldTitle)
	}
	if m.content != nil {
		fields = append(fields, announcement.FieldContent)
	}
	if m.status != nil {
		fields = append(fields, announcement.FieldStatus)
	}
	if m.notify_mode != nil {
		fields = append(fields, announcement.FieldNotifyMode)
	}
	if m.targeting != nil {
		fields = append(fields, announcement.FieldTargeting)
	}
	if m.starts_at != nil {
		fields = append(fields, announcement.FieldStartsAt)
	}
	if m.ends_at != nil {
		fields = append(fields, announcement.FieldEndsAt)
	}
	if m.created_by != nil {
		fields = append(fields, announcement.FieldCreatedBy)
	}
	if m.updated_by != nil {
		fields = append(fields, announcement.FieldUpdatedBy)
	}
	if m.created_at != nil {
		fields = append(fields, announcement.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, announcement.FieldUpdatedAt)
	}
	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 *AnnouncementMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case announcement.FieldTitle:
		return m.Title()
	case announcement.FieldContent:
		return m.Content()
	case announcement.FieldStatus:
		return m.Status()
	case announcement.FieldNotifyMode:
		return m.NotifyMode()
	case announcement.FieldTargeting:
		return m.Targeting()
	case announcement.FieldStartsAt:
		return m.StartsAt()
	case announcement.FieldEndsAt:
		return m.EndsAt()
	case announcement.FieldCreatedBy:
		return m.CreatedBy()
	case announcement.FieldUpdatedBy:
		return m.UpdatedBy()
	case announcement.FieldCreatedAt:
		return m.CreatedAt()
	case announcement.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	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 *AnnouncementMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case announcement.FieldTitle:
		return m.OldTitle(ctx)
	case announcement.FieldContent:
		return m.OldContent(ctx)
	case announcement.FieldStatus:
		return m.OldStatus(ctx)
	case announcement.FieldNotifyMode:
		return m.OldNotifyMode(ctx)
	case announcement.FieldTargeting:
		return m.OldTargeting(ctx)
	case announcement.FieldStartsAt:
		return m.OldStartsAt(ctx)
	case announcement.FieldEndsAt:
		return m.OldEndsAt(ctx)
	case announcement.FieldCreatedBy:
		return m.OldCreatedBy(ctx)
	case announcement.FieldUpdatedBy:
		return m.OldUpdatedBy(ctx)
	case announcement.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case announcement.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Announcement 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 *AnnouncementMutation) SetField(name string, value ent.Value) error {
	switch name {
	case announcement.FieldTitle:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTitle(v)
		return nil
	case announcement.FieldContent:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetContent(v)
		return nil
	case announcement.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case announcement.FieldNotifyMode:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNotifyMode(v)
		return nil
	case announcement.FieldTargeting:
		v, ok := value.(domain.AnnouncementTargeting)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTargeting(v)
		return nil
	case announcement.FieldStartsAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStartsAt(v)
		return nil
	case announcement.FieldEndsAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEndsAt(v)
		return nil
	case announcement.FieldCreatedBy:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedBy(v)
		return nil
	case announcement.FieldUpdatedBy:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedBy(v)
		return nil
	case announcement.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 announcement.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Announcement field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *AnnouncementMutation) AddedFields() []string {
	var fields []string
	if m.addcreated_by != nil {
		fields = append(fields, announcement.FieldCreatedBy)
	}
	if m.addupdated_by != nil {
		fields = append(fields, announcement.FieldUpdatedBy)
	}
	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 *AnnouncementMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case announcement.FieldCreatedBy:
		return m.AddedCreatedBy()
	case announcement.FieldUpdatedBy:
		return m.AddedUpdatedBy()
	}
	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 *AnnouncementMutation) AddField(name string, value ent.Value) error {
	switch name {
	case announcement.FieldCreatedBy:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCreatedBy(v)
		return nil
	case announcement.FieldUpdatedBy:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddUpdatedBy(v)
		return nil
	}
	return fmt.Errorf("unknown Announcement numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *AnnouncementMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(announcement.FieldTargeting) {
		fields = append(fields, announcement.FieldTargeting)
	}
	if m.FieldCleared(announcement.FieldStartsAt) {
		fields = append(fields, announcement.FieldStartsAt)
	}
	if m.FieldCleared(announcement.FieldEndsAt) {
		fields = append(fields, announcement.FieldEndsAt)
	}
	if m.FieldCleared(announcement.FieldCreatedBy) {
		fields = append(fields, announcement.FieldCreatedBy)
	}
	if m.FieldCleared(announcement.FieldUpdatedBy) {
		fields = append(fields, announcement.FieldUpdatedBy)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *AnnouncementMutation) 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 *AnnouncementMutation) ClearField(name string) error {
	switch name {
	case announcement.FieldTargeting:
		m.ClearTargeting()
		return nil
	case announcement.FieldStartsAt:
		m.ClearStartsAt()
		return nil
	case announcement.FieldEndsAt:
		m.ClearEndsAt()
		return nil
	case announcement.FieldCreatedBy:
		m.ClearCreatedBy()
		return nil
	case announcement.FieldUpdatedBy:
		m.ClearUpdatedBy()
		return nil
	}
	return fmt.Errorf("unknown Announcement 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 *AnnouncementMutation) ResetField(name string) error {
	switch name {
	case announcement.FieldTitle:
		m.ResetTitle()
		return nil
	case announcement.FieldContent:
		m.ResetContent()
		return nil
	case announcement.FieldStatus:
		m.ResetStatus()
		return nil
	case announcement.FieldNotifyMode:
		m.ResetNotifyMode()
		return nil
	case announcement.FieldTargeting:
		m.ResetTargeting()
		return nil
	case announcement.FieldStartsAt:
		m.ResetStartsAt()
		return nil
	case announcement.FieldEndsAt:
		m.ResetEndsAt()
		return nil
	case announcement.FieldCreatedBy:
		m.ResetCreatedBy()
		return nil
	case announcement.FieldUpdatedBy:
		m.ResetUpdatedBy()
		return nil
	case announcement.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case announcement.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown Announcement field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *AnnouncementMutation) AddedEdges() []string {
	edges := make([]string, 0, 1)
	if m.reads != nil {
		edges = append(edges, announcement.EdgeReads)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *AnnouncementMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case announcement.EdgeReads:
		ids := make([]ent.Value, 0, len(m.reads))
		for id := range m.reads {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *AnnouncementMutation) RemovedEdges() []string {
	edges := make([]string, 0, 1)
	if m.removedreads != nil {
		edges = append(edges, announcement.EdgeReads)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *AnnouncementMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case announcement.EdgeReads:
		ids := make([]ent.Value, 0, len(m.removedreads))
		for id := range m.removedreads {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *AnnouncementMutation) ClearedEdges() []string {
	edges := make([]string, 0, 1)
	if m.clearedreads {
		edges = append(edges, announcement.EdgeReads)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *AnnouncementMutation) EdgeCleared(name string) bool {
	switch name {
	case announcement.EdgeReads:
		return m.clearedreads
	}
	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 *AnnouncementMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown Announcement 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 *AnnouncementMutation) ResetEdge(name string) error {
	switch name {
	case announcement.EdgeReads:
		m.ResetReads()
		return nil
	}
	return fmt.Errorf("unknown Announcement edge %s", name)
}

// AnnouncementReadMutation represents an operation that mutates the AnnouncementRead nodes in the graph.
type AnnouncementReadMutation struct {
	config
	op                  Op
	typ                 string
	id                  *int64
	read_at             *time.Time
	created_at          *time.Time
	clearedFields       map[string]struct{}
	announcement        *int64
	clearedannouncement bool
	user                *int64
	cleareduser         bool
	done                bool
	oldValue            func(context.Context) (*AnnouncementRead, error)
	predicates          []predicate.AnnouncementRead
}

var _ ent.Mutation = (*AnnouncementReadMutation)(nil)

// announcementreadOption allows management of the mutation configuration using functional options.
type announcementreadOption func(*AnnouncementReadMutation)

// newAnnouncementReadMutation creates new mutation for the AnnouncementRead entity.
func newAnnouncementReadMutation(c config, op Op, opts ...announcementreadOption) *AnnouncementReadMutation {
	m := &AnnouncementReadMutation{
		config:        c,
		op:            op,
		typ:           TypeAnnouncementRead,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withAnnouncementReadID sets the ID field of the mutation.
func withAnnouncementReadID(id int64) announcementreadOption {
	return func(m *AnnouncementReadMutation) {
		var (
			err   error
			once  sync.Once
			value *AnnouncementRead
		)
		m.oldValue = func(ctx context.Context) (*AnnouncementRead, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().AnnouncementRead.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withAnnouncementRead sets the old AnnouncementRead of the mutation.
func withAnnouncementRead(node *AnnouncementRead) announcementreadOption {
	return func(m *AnnouncementReadMutation) {
		m.oldValue = func(context.Context) (*AnnouncementRead, 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 AnnouncementReadMutation) 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 AnnouncementReadMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *AnnouncementReadMutation) ID() (id int64, 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 *AnnouncementReadMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().AnnouncementRead.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetAnnouncementID sets the "announcement_id" field.
func (m *AnnouncementReadMutation) SetAnnouncementID(i int64) {
	m.announcement = &i
}

// AnnouncementID returns the value of the "announcement_id" field in the mutation.
func (m *AnnouncementReadMutation) AnnouncementID() (r int64, exists bool) {
	v := m.announcement
	if v == nil {
		return
	}
	return *v, true
}

// OldAnnouncementID returns the old "announcement_id" field's value of the AnnouncementRead entity.
// If the AnnouncementRead object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementReadMutation) OldAnnouncementID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAnnouncementID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAnnouncementID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAnnouncementID: %w", err)
	}
	return oldValue.AnnouncementID, nil
}

// ResetAnnouncementID resets all changes to the "announcement_id" field.
func (m *AnnouncementReadMutation) ResetAnnouncementID() {
	m.announcement = nil
}

// SetUserID sets the "user_id" field.
func (m *AnnouncementReadMutation) SetUserID(i int64) {
	m.user = &i
}

// UserID returns the value of the "user_id" field in the mutation.
func (m *AnnouncementReadMutation) UserID() (r int64, exists bool) {
	v := m.user
	if v == nil {
		return
	}
	return *v, true
}

// OldUserID returns the old "user_id" field's value of the AnnouncementRead entity.
// If the AnnouncementRead object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementReadMutation) OldUserID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
	}
	return oldValue.UserID, nil
}

// ResetUserID resets all changes to the "user_id" field.
func (m *AnnouncementReadMutation) ResetUserID() {
	m.user = nil
}

// SetReadAt sets the "read_at" field.
func (m *AnnouncementReadMutation) SetReadAt(t time.Time) {
	m.read_at = &t
}

// ReadAt returns the value of the "read_at" field in the mutation.
func (m *AnnouncementReadMutation) ReadAt() (r time.Time, exists bool) {
	v := m.read_at
	if v == nil {
		return
	}
	return *v, true
}

// OldReadAt returns the old "read_at" field's value of the AnnouncementRead entity.
// If the AnnouncementRead object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementReadMutation) OldReadAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldReadAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldReadAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldReadAt: %w", err)
	}
	return oldValue.ReadAt, nil
}

// ResetReadAt resets all changes to the "read_at" field.
func (m *AnnouncementReadMutation) ResetReadAt() {
	m.read_at = nil
}

// SetCreatedAt sets the "created_at" field.
func (m *AnnouncementReadMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *AnnouncementReadMutation) 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 AnnouncementRead entity.
// If the AnnouncementRead object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AnnouncementReadMutation) 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 *AnnouncementReadMutation) ResetCreatedAt() {
	m.created_at = nil
}

// ClearAnnouncement clears the "announcement" edge to the Announcement entity.
func (m *AnnouncementReadMutation) ClearAnnouncement() {
	m.clearedannouncement = true
	m.clearedFields[announcementread.FieldAnnouncementID] = struct{}{}
}

// AnnouncementCleared reports if the "announcement" edge to the Announcement entity was cleared.
func (m *AnnouncementReadMutation) AnnouncementCleared() bool {
	return m.clearedannouncement
}

// AnnouncementIDs returns the "announcement" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// AnnouncementID instead. It exists only for internal usage by the builders.
func (m *AnnouncementReadMutation) AnnouncementIDs() (ids []int64) {
	if id := m.announcement; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetAnnouncement resets all changes to the "announcement" edge.
func (m *AnnouncementReadMutation) ResetAnnouncement() {
	m.announcement = nil
	m.clearedannouncement = false
}

// ClearUser clears the "user" edge to the User entity.
func (m *AnnouncementReadMutation) ClearUser() {
	m.cleareduser = true
	m.clearedFields[announcementread.FieldUserID] = struct{}{}
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *AnnouncementReadMutation) UserCleared() bool {
	return m.cleareduser
}

// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *AnnouncementReadMutation) UserIDs() (ids []int64) {
	if id := m.user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetUser resets all changes to the "user" edge.
func (m *AnnouncementReadMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

// Where appends a list predicates to the AnnouncementReadMutation builder.
func (m *AnnouncementReadMutation) Where(ps ...predicate.AnnouncementRead) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the AnnouncementReadMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *AnnouncementReadMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.AnnouncementRead, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *AnnouncementReadMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *AnnouncementReadMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (AnnouncementRead).
func (m *AnnouncementReadMutation) 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 *AnnouncementReadMutation) Fields() []string {
	fields := make([]string, 0, 4)
	if m.announcement != nil {
		fields = append(fields, announcementread.FieldAnnouncementID)
	}
	if m.user != nil {
		fields = append(fields, announcementread.FieldUserID)
	}
	if m.read_at != nil {
		fields = append(fields, announcementread.FieldReadAt)
	}
	if m.created_at != nil {
		fields = append(fields, announcementread.FieldCreatedAt)
	}
	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 *AnnouncementReadMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case announcementread.FieldAnnouncementID:
		return m.AnnouncementID()
	case announcementread.FieldUserID:
		return m.UserID()
	case announcementread.FieldReadAt:
		return m.ReadAt()
	case announcementread.FieldCreatedAt:
		return m.CreatedAt()
	}
	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 *AnnouncementReadMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case announcementread.FieldAnnouncementID:
		return m.OldAnnouncementID(ctx)
	case announcementread.FieldUserID:
		return m.OldUserID(ctx)
	case announcementread.FieldReadAt:
		return m.OldReadAt(ctx)
	case announcementread.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown AnnouncementRead 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 *AnnouncementReadMutation) SetField(name string, value ent.Value) error {
	switch name {
	case announcementread.FieldAnnouncementID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAnnouncementID(v)
		return nil
	case announcementread.FieldUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserID(v)
		return nil
	case announcementread.FieldReadAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetReadAt(v)
		return nil
	case announcementread.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown AnnouncementRead field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *AnnouncementReadMutation) AddedFields() []string {
	var fields []string
	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 *AnnouncementReadMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	}
	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 *AnnouncementReadMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown AnnouncementRead numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *AnnouncementReadMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *AnnouncementReadMutation) 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 *AnnouncementReadMutation) ClearField(name string) error {
	return fmt.Errorf("unknown AnnouncementRead 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 *AnnouncementReadMutation) ResetField(name string) error {
	switch name {
	case announcementread.FieldAnnouncementID:
		m.ResetAnnouncementID()
		return nil
	case announcementread.FieldUserID:
		m.ResetUserID()
		return nil
	case announcementread.FieldReadAt:
		m.ResetReadAt()
		return nil
	case announcementread.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown AnnouncementRead field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *AnnouncementReadMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.announcement != nil {
		edges = append(edges, announcementread.EdgeAnnouncement)
	}
	if m.user != nil {
		edges = append(edges, announcementread.EdgeUser)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *AnnouncementReadMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case announcementread.EdgeAnnouncement:
		if id := m.announcement; id != nil {
			return []ent.Value{*id}
		}
	case announcementread.EdgeUser:
		if id := m.user; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *AnnouncementReadMutation) 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 *AnnouncementReadMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *AnnouncementReadMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedannouncement {
		edges = append(edges, announcementread.EdgeAnnouncement)
	}
	if m.cleareduser {
		edges = append(edges, announcementread.EdgeUser)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *AnnouncementReadMutation) EdgeCleared(name string) bool {
	switch name {
	case announcementread.EdgeAnnouncement:
		return m.clearedannouncement
	case announcementread.EdgeUser:
		return m.cleareduser
	}
	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 *AnnouncementReadMutation) ClearEdge(name string) error {
	switch name {
	case announcementread.EdgeAnnouncement:
		m.ClearAnnouncement()
		return nil
	case announcementread.EdgeUser:
		m.ClearUser()
		return nil
	}
	return fmt.Errorf("unknown AnnouncementRead 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 *AnnouncementReadMutation) ResetEdge(name string) error {
	switch name {
	case announcementread.EdgeAnnouncement:
		m.ResetAnnouncement()
		return nil
	case announcementread.EdgeUser:
		m.ResetUser()
		return nil
	}
	return fmt.Errorf("unknown AnnouncementRead edge %s", name)
}

// AuthIdentityMutation represents an operation that mutates the AuthIdentity nodes in the graph.
type AuthIdentityMutation struct {
	config
	op                        Op
	typ                       string
	id                        *int64
	created_at                *time.Time
	updated_at                *time.Time
	provider_type             *string
	provider_key              *string
	provider_subject          *string
	verified_at               *time.Time
	issuer                    *string
	metadata                  *map[string]interface{}
	clearedFields             map[string]struct{}
	user                      *int64
	cleareduser               bool
	channels                  map[int64]struct{}
	removedchannels           map[int64]struct{}
	clearedchannels           bool
	adoption_decisions        map[int64]struct{}
	removedadoption_decisions map[int64]struct{}
	clearedadoption_decisions bool
	done                      bool
	oldValue                  func(context.Context) (*AuthIdentity, error)
	predicates                []predicate.AuthIdentity
}

var _ ent.Mutation = (*AuthIdentityMutation)(nil)

// authidentityOption allows management of the mutation configuration using functional options.
type authidentityOption func(*AuthIdentityMutation)

// newAuthIdentityMutation creates new mutation for the AuthIdentity entity.
func newAuthIdentityMutation(c config, op Op, opts ...authidentityOption) *AuthIdentityMutation {
	m := &AuthIdentityMutation{
		config:        c,
		op:            op,
		typ:           TypeAuthIdentity,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withAuthIdentityID sets the ID field of the mutation.
func withAuthIdentityID(id int64) authidentityOption {
	return func(m *AuthIdentityMutation) {
		var (
			err   error
			once  sync.Once
			value *AuthIdentity
		)
		m.oldValue = func(ctx context.Context) (*AuthIdentity, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().AuthIdentity.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withAuthIdentity sets the old AuthIdentity of the mutation.
func withAuthIdentity(node *AuthIdentity) authidentityOption {
	return func(m *AuthIdentityMutation) {
		m.oldValue = func(context.Context) (*AuthIdentity, 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 AuthIdentityMutation) 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 AuthIdentityMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *AuthIdentityMutation) ID() (id int64, 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 *AuthIdentityMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().AuthIdentity.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *AuthIdentityMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *AuthIdentityMutation) 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 AuthIdentity entity.
// If the AuthIdentity object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityMutation) 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 *AuthIdentityMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *AuthIdentityMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *AuthIdentityMutation) 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 AuthIdentity entity.
// If the AuthIdentity object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityMutation) 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 *AuthIdentityMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetUserID sets the "user_id" field.
func (m *AuthIdentityMutation) SetUserID(i int64) {
	m.user = &i
}

// UserID returns the value of the "user_id" field in the mutation.
func (m *AuthIdentityMutation) UserID() (r int64, exists bool) {
	v := m.user
	if v == nil {
		return
	}
	return *v, true
}

// OldUserID returns the old "user_id" field's value of the AuthIdentity entity.
// If the AuthIdentity object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityMutation) OldUserID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
	}
	return oldValue.UserID, nil
}

// ResetUserID resets all changes to the "user_id" field.
func (m *AuthIdentityMutation) ResetUserID() {
	m.user = nil
}

// SetProviderType sets the "provider_type" field.
func (m *AuthIdentityMutation) SetProviderType(s string) {
	m.provider_type = &s
}

// ProviderType returns the value of the "provider_type" field in the mutation.
func (m *AuthIdentityMutation) ProviderType() (r string, exists bool) {
	v := m.provider_type
	if v == nil {
		return
	}
	return *v, true
}

// OldProviderType returns the old "provider_type" field's value of the AuthIdentity entity.
// If the AuthIdentity object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityMutation) OldProviderType(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProviderType is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProviderType requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProviderType: %w", err)
	}
	return oldValue.ProviderType, nil
}

// ResetProviderType resets all changes to the "provider_type" field.
func (m *AuthIdentityMutation) ResetProviderType() {
	m.provider_type = nil
}

// SetProviderKey sets the "provider_key" field.
func (m *AuthIdentityMutation) SetProviderKey(s string) {
	m.provider_key = &s
}

// ProviderKey returns the value of the "provider_key" field in the mutation.
func (m *AuthIdentityMutation) ProviderKey() (r string, exists bool) {
	v := m.provider_key
	if v == nil {
		return
	}
	return *v, true
}

// OldProviderKey returns the old "provider_key" field's value of the AuthIdentity entity.
// If the AuthIdentity object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityMutation) OldProviderKey(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProviderKey is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProviderKey requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProviderKey: %w", err)
	}
	return oldValue.ProviderKey, nil
}

// ResetProviderKey resets all changes to the "provider_key" field.
func (m *AuthIdentityMutation) ResetProviderKey() {
	m.provider_key = nil
}

// SetProviderSubject sets the "provider_subject" field.
func (m *AuthIdentityMutation) SetProviderSubject(s string) {
	m.provider_subject = &s
}

// ProviderSubject returns the value of the "provider_subject" field in the mutation.
func (m *AuthIdentityMutation) ProviderSubject() (r string, exists bool) {
	v := m.provider_subject
	if v == nil {
		return
	}
	return *v, true
}

// OldProviderSubject returns the old "provider_subject" field's value of the AuthIdentity entity.
// If the AuthIdentity object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityMutation) OldProviderSubject(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProviderSubject is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProviderSubject requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProviderSubject: %w", err)
	}
	return oldValue.ProviderSubject, nil
}

// ResetProviderSubject resets all changes to the "provider_subject" field.
func (m *AuthIdentityMutation) ResetProviderSubject() {
	m.provider_subject = nil
}

// SetVerifiedAt sets the "verified_at" field.
func (m *AuthIdentityMutation) SetVerifiedAt(t time.Time) {
	m.verified_at = &t
}

// VerifiedAt returns the value of the "verified_at" field in the mutation.
func (m *AuthIdentityMutation) VerifiedAt() (r time.Time, exists bool) {
	v := m.verified_at
	if v == nil {
		return
	}
	return *v, true
}

// OldVerifiedAt returns the old "verified_at" field's value of the AuthIdentity entity.
// If the AuthIdentity object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityMutation) OldVerifiedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldVerifiedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldVerifiedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldVerifiedAt: %w", err)
	}
	return oldValue.VerifiedAt, nil
}

// ClearVerifiedAt clears the value of the "verified_at" field.
func (m *AuthIdentityMutation) ClearVerifiedAt() {
	m.verified_at = nil
	m.clearedFields[authidentity.FieldVerifiedAt] = struct{}{}
}

// VerifiedAtCleared returns if the "verified_at" field was cleared in this mutation.
func (m *AuthIdentityMutation) VerifiedAtCleared() bool {
	_, ok := m.clearedFields[authidentity.FieldVerifiedAt]
	return ok
}

// ResetVerifiedAt resets all changes to the "verified_at" field.
func (m *AuthIdentityMutation) ResetVerifiedAt() {
	m.verified_at = nil
	delete(m.clearedFields, authidentity.FieldVerifiedAt)
}

// SetIssuer sets the "issuer" field.
func (m *AuthIdentityMutation) SetIssuer(s string) {
	m.issuer = &s
}

// Issuer returns the value of the "issuer" field in the mutation.
func (m *AuthIdentityMutation) Issuer() (r string, exists bool) {
	v := m.issuer
	if v == nil {
		return
	}
	return *v, true
}

// OldIssuer returns the old "issuer" field's value of the AuthIdentity entity.
// If the AuthIdentity object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityMutation) OldIssuer(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldIssuer is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldIssuer requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldIssuer: %w", err)
	}
	return oldValue.Issuer, nil
}

// ClearIssuer clears the value of the "issuer" field.
func (m *AuthIdentityMutation) ClearIssuer() {
	m.issuer = nil
	m.clearedFields[authidentity.FieldIssuer] = struct{}{}
}

// IssuerCleared returns if the "issuer" field was cleared in this mutation.
func (m *AuthIdentityMutation) IssuerCleared() bool {
	_, ok := m.clearedFields[authidentity.FieldIssuer]
	return ok
}

// ResetIssuer resets all changes to the "issuer" field.
func (m *AuthIdentityMutation) ResetIssuer() {
	m.issuer = nil
	delete(m.clearedFields, authidentity.FieldIssuer)
}

// SetMetadata sets the "metadata" field.
func (m *AuthIdentityMutation) SetMetadata(value map[string]interface{}) {
	m.metadata = &value
}

// Metadata returns the value of the "metadata" field in the mutation.
func (m *AuthIdentityMutation) Metadata() (r map[string]interface{}, exists bool) {
	v := m.metadata
	if v == nil {
		return
	}
	return *v, true
}

// OldMetadata returns the old "metadata" field's value of the AuthIdentity entity.
// If the AuthIdentity object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityMutation) OldMetadata(ctx context.Context) (v map[string]interface{}, 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
}

// ResetMetadata resets all changes to the "metadata" field.
func (m *AuthIdentityMutation) ResetMetadata() {
	m.metadata = nil
}

// ClearUser clears the "user" edge to the User entity.
func (m *AuthIdentityMutation) ClearUser() {
	m.cleareduser = true
	m.clearedFields[authidentity.FieldUserID] = struct{}{}
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *AuthIdentityMutation) UserCleared() bool {
	return m.cleareduser
}

// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *AuthIdentityMutation) UserIDs() (ids []int64) {
	if id := m.user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetUser resets all changes to the "user" edge.
func (m *AuthIdentityMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

// AddChannelIDs adds the "channels" edge to the AuthIdentityChannel entity by ids.
func (m *AuthIdentityMutation) AddChannelIDs(ids ...int64) {
	if m.channels == nil {
		m.channels = make(map[int64]struct{})
	}
	for i := range ids {
		m.channels[ids[i]] = struct{}{}
	}
}

// ClearChannels clears the "channels" edge to the AuthIdentityChannel entity.
func (m *AuthIdentityMutation) ClearChannels() {
	m.clearedchannels = true
}

// ChannelsCleared reports if the "channels" edge to the AuthIdentityChannel entity was cleared.
func (m *AuthIdentityMutation) ChannelsCleared() bool {
	return m.clearedchannels
}

// RemoveChannelIDs removes the "channels" edge to the AuthIdentityChannel entity by IDs.
func (m *AuthIdentityMutation) RemoveChannelIDs(ids ...int64) {
	if m.removedchannels == nil {
		m.removedchannels = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.channels, ids[i])
		m.removedchannels[ids[i]] = struct{}{}
	}
}

// RemovedChannels returns the removed IDs of the "channels" edge to the AuthIdentityChannel entity.
func (m *AuthIdentityMutation) RemovedChannelsIDs() (ids []int64) {
	for id := range m.removedchannels {
		ids = append(ids, id)
	}
	return
}

// ChannelsIDs returns the "channels" edge IDs in the mutation.
func (m *AuthIdentityMutation) ChannelsIDs() (ids []int64) {
	for id := range m.channels {
		ids = append(ids, id)
	}
	return
}

// ResetChannels resets all changes to the "channels" edge.
func (m *AuthIdentityMutation) ResetChannels() {
	m.channels = nil
	m.clearedchannels = false
	m.removedchannels = nil
}

// AddAdoptionDecisionIDs adds the "adoption_decisions" edge to the IdentityAdoptionDecision entity by ids.
func (m *AuthIdentityMutation) AddAdoptionDecisionIDs(ids ...int64) {
	if m.adoption_decisions == nil {
		m.adoption_decisions = make(map[int64]struct{})
	}
	for i := range ids {
		m.adoption_decisions[ids[i]] = struct{}{}
	}
}

// ClearAdoptionDecisions clears the "adoption_decisions" edge to the IdentityAdoptionDecision entity.
func (m *AuthIdentityMutation) ClearAdoptionDecisions() {
	m.clearedadoption_decisions = true
}

// AdoptionDecisionsCleared reports if the "adoption_decisions" edge to the IdentityAdoptionDecision entity was cleared.
func (m *AuthIdentityMutation) AdoptionDecisionsCleared() bool {
	return m.clearedadoption_decisions
}

// RemoveAdoptionDecisionIDs removes the "adoption_decisions" edge to the IdentityAdoptionDecision entity by IDs.
func (m *AuthIdentityMutation) RemoveAdoptionDecisionIDs(ids ...int64) {
	if m.removedadoption_decisions == nil {
		m.removedadoption_decisions = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.adoption_decisions, ids[i])
		m.removedadoption_decisions[ids[i]] = struct{}{}
	}
}

// RemovedAdoptionDecisions returns the removed IDs of the "adoption_decisions" edge to the IdentityAdoptionDecision entity.
func (m *AuthIdentityMutation) RemovedAdoptionDecisionsIDs() (ids []int64) {
	for id := range m.removedadoption_decisions {
		ids = append(ids, id)
	}
	return
}

// AdoptionDecisionsIDs returns the "adoption_decisions" edge IDs in the mutation.
func (m *AuthIdentityMutation) AdoptionDecisionsIDs() (ids []int64) {
	for id := range m.adoption_decisions {
		ids = append(ids, id)
	}
	return
}

// ResetAdoptionDecisions resets all changes to the "adoption_decisions" edge.
func (m *AuthIdentityMutation) ResetAdoptionDecisions() {
	m.adoption_decisions = nil
	m.clearedadoption_decisions = false
	m.removedadoption_decisions = nil
}

// Where appends a list predicates to the AuthIdentityMutation builder.
func (m *AuthIdentityMutation) Where(ps ...predicate.AuthIdentity) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the AuthIdentityMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *AuthIdentityMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.AuthIdentity, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *AuthIdentityMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *AuthIdentityMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (AuthIdentity).
func (m *AuthIdentityMutation) 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 *AuthIdentityMutation) Fields() []string {
	fields := make([]string, 0, 9)
	if m.created_at != nil {
		fields = append(fields, authidentity.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, authidentity.FieldUpdatedAt)
	}
	if m.user != nil {
		fields = append(fields, authidentity.FieldUserID)
	}
	if m.provider_type != nil {
		fields = append(fields, authidentity.FieldProviderType)
	}
	if m.provider_key != nil {
		fields = append(fields, authidentity.FieldProviderKey)
	}
	if m.provider_subject != nil {
		fields = append(fields, authidentity.FieldProviderSubject)
	}
	if m.verified_at != nil {
		fields = append(fields, authidentity.FieldVerifiedAt)
	}
	if m.issuer != nil {
		fields = append(fields, authidentity.FieldIssuer)
	}
	if m.metadata != nil {
		fields = append(fields, authidentity.FieldMetadata)
	}
	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 *AuthIdentityMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case authidentity.FieldCreatedAt:
		return m.CreatedAt()
	case authidentity.FieldUpdatedAt:
		return m.UpdatedAt()
	case authidentity.FieldUserID:
		return m.UserID()
	case authidentity.FieldProviderType:
		return m.ProviderType()
	case authidentity.FieldProviderKey:
		return m.ProviderKey()
	case authidentity.FieldProviderSubject:
		return m.ProviderSubject()
	case authidentity.FieldVerifiedAt:
		return m.VerifiedAt()
	case authidentity.FieldIssuer:
		return m.Issuer()
	case authidentity.FieldMetadata:
		return m.Metadata()
	}
	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 *AuthIdentityMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case authidentity.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case authidentity.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case authidentity.FieldUserID:
		return m.OldUserID(ctx)
	case authidentity.FieldProviderType:
		return m.OldProviderType(ctx)
	case authidentity.FieldProviderKey:
		return m.OldProviderKey(ctx)
	case authidentity.FieldProviderSubject:
		return m.OldProviderSubject(ctx)
	case authidentity.FieldVerifiedAt:
		return m.OldVerifiedAt(ctx)
	case authidentity.FieldIssuer:
		return m.OldIssuer(ctx)
	case authidentity.FieldMetadata:
		return m.OldMetadata(ctx)
	}
	return nil, fmt.Errorf("unknown AuthIdentity 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 *AuthIdentityMutation) SetField(name string, value ent.Value) error {
	switch name {
	case authidentity.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 authidentity.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 authidentity.FieldUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserID(v)
		return nil
	case authidentity.FieldProviderType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProviderType(v)
		return nil
	case authidentity.FieldProviderKey:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProviderKey(v)
		return nil
	case authidentity.FieldProviderSubject:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProviderSubject(v)
		return nil
	case authidentity.FieldVerifiedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetVerifiedAt(v)
		return nil
	case authidentity.FieldIssuer:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIssuer(v)
		return nil
	case authidentity.FieldMetadata:
		v, ok := value.(map[string]interface{})
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMetadata(v)
		return nil
	}
	return fmt.Errorf("unknown AuthIdentity field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *AuthIdentityMutation) AddedFields() []string {
	var fields []string
	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 *AuthIdentityMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	}
	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 *AuthIdentityMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown AuthIdentity numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *AuthIdentityMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(authidentity.FieldVerifiedAt) {
		fields = append(fields, authidentity.FieldVerifiedAt)
	}
	if m.FieldCleared(authidentity.FieldIssuer) {
		fields = append(fields, authidentity.FieldIssuer)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *AuthIdentityMutation) 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 *AuthIdentityMutation) ClearField(name string) error {
	switch name {
	case authidentity.FieldVerifiedAt:
		m.ClearVerifiedAt()
		return nil
	case authidentity.FieldIssuer:
		m.ClearIssuer()
		return nil
	}
	return fmt.Errorf("unknown AuthIdentity 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 *AuthIdentityMutation) ResetField(name string) error {
	switch name {
	case authidentity.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case authidentity.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case authidentity.FieldUserID:
		m.ResetUserID()
		return nil
	case authidentity.FieldProviderType:
		m.ResetProviderType()
		return nil
	case authidentity.FieldProviderKey:
		m.ResetProviderKey()
		return nil
	case authidentity.FieldProviderSubject:
		m.ResetProviderSubject()
		return nil
	case authidentity.FieldVerifiedAt:
		m.ResetVerifiedAt()
		return nil
	case authidentity.FieldIssuer:
		m.ResetIssuer()
		return nil
	case authidentity.FieldMetadata:
		m.ResetMetadata()
		return nil
	}
	return fmt.Errorf("unknown AuthIdentity field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *AuthIdentityMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.user != nil {
		edges = append(edges, authidentity.EdgeUser)
	}
	if m.channels != nil {
		edges = append(edges, authidentity.EdgeChannels)
	}
	if m.adoption_decisions != nil {
		edges = append(edges, authidentity.EdgeAdoptionDecisions)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *AuthIdentityMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case authidentity.EdgeUser:
		if id := m.user; id != nil {
			return []ent.Value{*id}
		}
	case authidentity.EdgeChannels:
		ids := make([]ent.Value, 0, len(m.channels))
		for id := range m.channels {
			ids = append(ids, id)
		}
		return ids
	case authidentity.EdgeAdoptionDecisions:
		ids := make([]ent.Value, 0, len(m.adoption_decisions))
		for id := range m.adoption_decisions {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *AuthIdentityMutation) RemovedEdges() []string {
	edges := make([]string, 0, 3)
	if m.removedchannels != nil {
		edges = append(edges, authidentity.EdgeChannels)
	}
	if m.removedadoption_decisions != nil {
		edges = append(edges, authidentity.EdgeAdoptionDecisions)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *AuthIdentityMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case authidentity.EdgeChannels:
		ids := make([]ent.Value, 0, len(m.removedchannels))
		for id := range m.removedchannels {
			ids = append(ids, id)
		}
		return ids
	case authidentity.EdgeAdoptionDecisions:
		ids := make([]ent.Value, 0, len(m.removedadoption_decisions))
		for id := range m.removedadoption_decisions {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *AuthIdentityMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.cleareduser {
		edges = append(edges, authidentity.EdgeUser)
	}
	if m.clearedchannels {
		edges = append(edges, authidentity.EdgeChannels)
	}
	if m.clearedadoption_decisions {
		edges = append(edges, authidentity.EdgeAdoptionDecisions)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *AuthIdentityMutation) EdgeCleared(name string) bool {
	switch name {
	case authidentity.EdgeUser:
		return m.cleareduser
	case authidentity.EdgeChannels:
		return m.clearedchannels
	case authidentity.EdgeAdoptionDecisions:
		return m.clearedadoption_decisions
	}
	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 *AuthIdentityMutation) ClearEdge(name string) error {
	switch name {
	case authidentity.EdgeUser:
		m.ClearUser()
		return nil
	}
	return fmt.Errorf("unknown AuthIdentity 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 *AuthIdentityMutation) ResetEdge(name string) error {
	switch name {
	case authidentity.EdgeUser:
		m.ResetUser()
		return nil
	case authidentity.EdgeChannels:
		m.ResetChannels()
		return nil
	case authidentity.EdgeAdoptionDecisions:
		m.ResetAdoptionDecisions()
		return nil
	}
	return fmt.Errorf("unknown AuthIdentity edge %s", name)
}

// AuthIdentityChannelMutation represents an operation that mutates the AuthIdentityChannel nodes in the graph.
type AuthIdentityChannelMutation struct {
	config
	op              Op
	typ             string
	id              *int64
	created_at      *time.Time
	updated_at      *time.Time
	provider_type   *string
	provider_key    *string
	channel         *string
	channel_app_id  *string
	channel_subject *string
	metadata        *map[string]interface{}
	clearedFields   map[string]struct{}
	identity        *int64
	clearedidentity bool
	done            bool
	oldValue        func(context.Context) (*AuthIdentityChannel, error)
	predicates      []predicate.AuthIdentityChannel
}

var _ ent.Mutation = (*AuthIdentityChannelMutation)(nil)

// authidentitychannelOption allows management of the mutation configuration using functional options.
type authidentitychannelOption func(*AuthIdentityChannelMutation)

// newAuthIdentityChannelMutation creates new mutation for the AuthIdentityChannel entity.
func newAuthIdentityChannelMutation(c config, op Op, opts ...authidentitychannelOption) *AuthIdentityChannelMutation {
	m := &AuthIdentityChannelMutation{
		config:        c,
		op:            op,
		typ:           TypeAuthIdentityChannel,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withAuthIdentityChannelID sets the ID field of the mutation.
func withAuthIdentityChannelID(id int64) authidentitychannelOption {
	return func(m *AuthIdentityChannelMutation) {
		var (
			err   error
			once  sync.Once
			value *AuthIdentityChannel
		)
		m.oldValue = func(ctx context.Context) (*AuthIdentityChannel, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().AuthIdentityChannel.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withAuthIdentityChannel sets the old AuthIdentityChannel of the mutation.
func withAuthIdentityChannel(node *AuthIdentityChannel) authidentitychannelOption {
	return func(m *AuthIdentityChannelMutation) {
		m.oldValue = func(context.Context) (*AuthIdentityChannel, 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 AuthIdentityChannelMutation) 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 AuthIdentityChannelMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *AuthIdentityChannelMutation) ID() (id int64, 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 *AuthIdentityChannelMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().AuthIdentityChannel.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *AuthIdentityChannelMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *AuthIdentityChannelMutation) 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 AuthIdentityChannel entity.
// If the AuthIdentityChannel object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityChannelMutation) 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 *AuthIdentityChannelMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *AuthIdentityChannelMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *AuthIdentityChannelMutation) 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 AuthIdentityChannel entity.
// If the AuthIdentityChannel object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityChannelMutation) 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 *AuthIdentityChannelMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetIdentityID sets the "identity_id" field.
func (m *AuthIdentityChannelMutation) SetIdentityID(i int64) {
	m.identity = &i
}

// IdentityID returns the value of the "identity_id" field in the mutation.
func (m *AuthIdentityChannelMutation) IdentityID() (r int64, exists bool) {
	v := m.identity
	if v == nil {
		return
	}
	return *v, true
}

// OldIdentityID returns the old "identity_id" field's value of the AuthIdentityChannel entity.
// If the AuthIdentityChannel object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityChannelMutation) OldIdentityID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldIdentityID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldIdentityID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldIdentityID: %w", err)
	}
	return oldValue.IdentityID, nil
}

// ResetIdentityID resets all changes to the "identity_id" field.
func (m *AuthIdentityChannelMutation) ResetIdentityID() {
	m.identity = nil
}

// SetProviderType sets the "provider_type" field.
func (m *AuthIdentityChannelMutation) SetProviderType(s string) {
	m.provider_type = &s
}

// ProviderType returns the value of the "provider_type" field in the mutation.
func (m *AuthIdentityChannelMutation) ProviderType() (r string, exists bool) {
	v := m.provider_type
	if v == nil {
		return
	}
	return *v, true
}

// OldProviderType returns the old "provider_type" field's value of the AuthIdentityChannel entity.
// If the AuthIdentityChannel object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityChannelMutation) OldProviderType(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProviderType is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProviderType requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProviderType: %w", err)
	}
	return oldValue.ProviderType, nil
}

// ResetProviderType resets all changes to the "provider_type" field.
func (m *AuthIdentityChannelMutation) ResetProviderType() {
	m.provider_type = nil
}

// SetProviderKey sets the "provider_key" field.
func (m *AuthIdentityChannelMutation) SetProviderKey(s string) {
	m.provider_key = &s
}

// ProviderKey returns the value of the "provider_key" field in the mutation.
func (m *AuthIdentityChannelMutation) ProviderKey() (r string, exists bool) {
	v := m.provider_key
	if v == nil {
		return
	}
	return *v, true
}

// OldProviderKey returns the old "provider_key" field's value of the AuthIdentityChannel entity.
// If the AuthIdentityChannel object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityChannelMutation) OldProviderKey(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProviderKey is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProviderKey requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProviderKey: %w", err)
	}
	return oldValue.ProviderKey, nil
}

// ResetProviderKey resets all changes to the "provider_key" field.
func (m *AuthIdentityChannelMutation) ResetProviderKey() {
	m.provider_key = nil
}

// SetChannel sets the "channel" field.
func (m *AuthIdentityChannelMutation) SetChannel(s string) {
	m.channel = &s
}

// Channel returns the value of the "channel" field in the mutation.
func (m *AuthIdentityChannelMutation) Channel() (r string, exists bool) {
	v := m.channel
	if v == nil {
		return
	}
	return *v, true
}

// OldChannel returns the old "channel" field's value of the AuthIdentityChannel entity.
// If the AuthIdentityChannel object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityChannelMutation) OldChannel(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldChannel is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldChannel requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldChannel: %w", err)
	}
	return oldValue.Channel, nil
}

// ResetChannel resets all changes to the "channel" field.
func (m *AuthIdentityChannelMutation) ResetChannel() {
	m.channel = nil
}

// SetChannelAppID sets the "channel_app_id" field.
func (m *AuthIdentityChannelMutation) SetChannelAppID(s string) {
	m.channel_app_id = &s
}

// ChannelAppID returns the value of the "channel_app_id" field in the mutation.
func (m *AuthIdentityChannelMutation) ChannelAppID() (r string, exists bool) {
	v := m.channel_app_id
	if v == nil {
		return
	}
	return *v, true
}

// OldChannelAppID returns the old "channel_app_id" field's value of the AuthIdentityChannel entity.
// If the AuthIdentityChannel object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityChannelMutation) OldChannelAppID(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldChannelAppID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldChannelAppID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldChannelAppID: %w", err)
	}
	return oldValue.ChannelAppID, nil
}

// ResetChannelAppID resets all changes to the "channel_app_id" field.
func (m *AuthIdentityChannelMutation) ResetChannelAppID() {
	m.channel_app_id = nil
}

// SetChannelSubject sets the "channel_subject" field.
func (m *AuthIdentityChannelMutation) SetChannelSubject(s string) {
	m.channel_subject = &s
}

// ChannelSubject returns the value of the "channel_subject" field in the mutation.
func (m *AuthIdentityChannelMutation) ChannelSubject() (r string, exists bool) {
	v := m.channel_subject
	if v == nil {
		return
	}
	return *v, true
}

// OldChannelSubject returns the old "channel_subject" field's value of the AuthIdentityChannel entity.
// If the AuthIdentityChannel object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityChannelMutation) OldChannelSubject(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldChannelSubject is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldChannelSubject requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldChannelSubject: %w", err)
	}
	return oldValue.ChannelSubject, nil
}

// ResetChannelSubject resets all changes to the "channel_subject" field.
func (m *AuthIdentityChannelMutation) ResetChannelSubject() {
	m.channel_subject = nil
}

// SetMetadata sets the "metadata" field.
func (m *AuthIdentityChannelMutation) SetMetadata(value map[string]interface{}) {
	m.metadata = &value
}

// Metadata returns the value of the "metadata" field in the mutation.
func (m *AuthIdentityChannelMutation) Metadata() (r map[string]interface{}, exists bool) {
	v := m.metadata
	if v == nil {
		return
	}
	return *v, true
}

// OldMetadata returns the old "metadata" field's value of the AuthIdentityChannel entity.
// If the AuthIdentityChannel object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AuthIdentityChannelMutation) OldMetadata(ctx context.Context) (v map[string]interface{}, 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
}

// ResetMetadata resets all changes to the "metadata" field.
func (m *AuthIdentityChannelMutation) ResetMetadata() {
	m.metadata = nil
}

// ClearIdentity clears the "identity" edge to the AuthIdentity entity.
func (m *AuthIdentityChannelMutation) ClearIdentity() {
	m.clearedidentity = true
	m.clearedFields[authidentitychannel.FieldIdentityID] = struct{}{}
}

// IdentityCleared reports if the "identity" edge to the AuthIdentity entity was cleared.
func (m *AuthIdentityChannelMutation) IdentityCleared() bool {
	return m.clearedidentity
}

// IdentityIDs returns the "identity" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// IdentityID instead. It exists only for internal usage by the builders.
func (m *AuthIdentityChannelMutation) IdentityIDs() (ids []int64) {
	if id := m.identity; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetIdentity resets all changes to the "identity" edge.
func (m *AuthIdentityChannelMutation) ResetIdentity() {
	m.identity = nil
	m.clearedidentity = false
}

// Where appends a list predicates to the AuthIdentityChannelMutation builder.
func (m *AuthIdentityChannelMutation) Where(ps ...predicate.AuthIdentityChannel) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the AuthIdentityChannelMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *AuthIdentityChannelMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.AuthIdentityChannel, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *AuthIdentityChannelMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *AuthIdentityChannelMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (AuthIdentityChannel).
func (m *AuthIdentityChannelMutation) 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 *AuthIdentityChannelMutation) Fields() []string {
	fields := make([]string, 0, 9)
	if m.created_at != nil {
		fields = append(fields, authidentitychannel.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, authidentitychannel.FieldUpdatedAt)
	}
	if m.identity != nil {
		fields = append(fields, authidentitychannel.FieldIdentityID)
	}
	if m.provider_type != nil {
		fields = append(fields, authidentitychannel.FieldProviderType)
	}
	if m.provider_key != nil {
		fields = append(fields, authidentitychannel.FieldProviderKey)
	}
	if m.channel != nil {
		fields = append(fields, authidentitychannel.FieldChannel)
	}
	if m.channel_app_id != nil {
		fields = append(fields, authidentitychannel.FieldChannelAppID)
	}
	if m.channel_subject != nil {
		fields = append(fields, authidentitychannel.FieldChannelSubject)
	}
	if m.metadata != nil {
		fields = append(fields, authidentitychannel.FieldMetadata)
	}
	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 *AuthIdentityChannelMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case authidentitychannel.FieldCreatedAt:
		return m.CreatedAt()
	case authidentitychannel.FieldUpdatedAt:
		return m.UpdatedAt()
	case authidentitychannel.FieldIdentityID:
		return m.IdentityID()
	case authidentitychannel.FieldProviderType:
		return m.ProviderType()
	case authidentitychannel.FieldProviderKey:
		return m.ProviderKey()
	case authidentitychannel.FieldChannel:
		return m.Channel()
	case authidentitychannel.FieldChannelAppID:
		return m.ChannelAppID()
	case authidentitychannel.FieldChannelSubject:
		return m.ChannelSubject()
	case authidentitychannel.FieldMetadata:
		return m.Metadata()
	}
	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 *AuthIdentityChannelMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case authidentitychannel.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case authidentitychannel.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case authidentitychannel.FieldIdentityID:
		return m.OldIdentityID(ctx)
	case authidentitychannel.FieldProviderType:
		return m.OldProviderType(ctx)
	case authidentitychannel.FieldProviderKey:
		return m.OldProviderKey(ctx)
	case authidentitychannel.FieldChannel:
		return m.OldChannel(ctx)
	case authidentitychannel.FieldChannelAppID:
		return m.OldChannelAppID(ctx)
	case authidentitychannel.FieldChannelSubject:
		return m.OldChannelSubject(ctx)
	case authidentitychannel.FieldMetadata:
		return m.OldMetadata(ctx)
	}
	return nil, fmt.Errorf("unknown AuthIdentityChannel 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 *AuthIdentityChannelMutation) SetField(name string, value ent.Value) error {
	switch name {
	case authidentitychannel.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 authidentitychannel.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 authidentitychannel.FieldIdentityID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIdentityID(v)
		return nil
	case authidentitychannel.FieldProviderType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProviderType(v)
		return nil
	case authidentitychannel.FieldProviderKey:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProviderKey(v)
		return nil
	case authidentitychannel.FieldChannel:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetChannel(v)
		return nil
	case authidentitychannel.FieldChannelAppID:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetChannelAppID(v)
		return nil
	case authidentitychannel.FieldChannelSubject:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetChannelSubject(v)
		return nil
	case authidentitychannel.FieldMetadata:
		v, ok := value.(map[string]interface{})
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMetadata(v)
		return nil
	}
	return fmt.Errorf("unknown AuthIdentityChannel field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *AuthIdentityChannelMutation) AddedFields() []string {
	var fields []string
	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 *AuthIdentityChannelMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	}
	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 *AuthIdentityChannelMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown AuthIdentityChannel numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *AuthIdentityChannelMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *AuthIdentityChannelMutation) 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 *AuthIdentityChannelMutation) ClearField(name string) error {
	return fmt.Errorf("unknown AuthIdentityChannel 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 *AuthIdentityChannelMutation) ResetField(name string) error {
	switch name {
	case authidentitychannel.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case authidentitychannel.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case authidentitychannel.FieldIdentityID:
		m.ResetIdentityID()
		return nil
	case authidentitychannel.FieldProviderType:
		m.ResetProviderType()
		return nil
	case authidentitychannel.FieldProviderKey:
		m.ResetProviderKey()
		return nil
	case authidentitychannel.FieldChannel:
		m.ResetChannel()
		return nil
	case authidentitychannel.FieldChannelAppID:
		m.ResetChannelAppID()
		return nil
	case authidentitychannel.FieldChannelSubject:
		m.ResetChannelSubject()
		return nil
	case authidentitychannel.FieldMetadata:
		m.ResetMetadata()
		return nil
	}
	return fmt.Errorf("unknown AuthIdentityChannel field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *AuthIdentityChannelMutation) AddedEdges() []string {
	edges := make([]string, 0, 1)
	if m.identity != nil {
		edges = append(edges, authidentitychannel.EdgeIdentity)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *AuthIdentityChannelMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case authidentitychannel.EdgeIdentity:
		if id := m.identity; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *AuthIdentityChannelMutation) 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 *AuthIdentityChannelMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *AuthIdentityChannelMutation) ClearedEdges() []string {
	edges := make([]string, 0, 1)
	if m.clearedidentity {
		edges = append(edges, authidentitychannel.EdgeIdentity)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *AuthIdentityChannelMutation) EdgeCleared(name string) bool {
	switch name {
	case authidentitychannel.EdgeIdentity:
		return m.clearedidentity
	}
	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 *AuthIdentityChannelMutation) ClearEdge(name string) error {
	switch name {
	case authidentitychannel.EdgeIdentity:
		m.ClearIdentity()
		return nil
	}
	return fmt.Errorf("unknown AuthIdentityChannel 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 *AuthIdentityChannelMutation) ResetEdge(name string) error {
	switch name {
	case authidentitychannel.EdgeIdentity:
		m.ResetIdentity()
		return nil
	}
	return fmt.Errorf("unknown AuthIdentityChannel edge %s", name)
}

// ErrorPassthroughRuleMutation represents an operation that mutates the ErrorPassthroughRule nodes in the graph.
type ErrorPassthroughRuleMutation struct {
	config
	op                Op
	typ               string
	id                *int64
	created_at        *time.Time
	updated_at        *time.Time
	name              *string
	enabled           *bool
	priority          *int
	addpriority       *int
	error_codes       *[]int
	appenderror_codes []int
	keywords          *[]string
	appendkeywords    []string
	match_mode        *string
	platforms         *[]string
	appendplatforms   []string
	passthrough_code  *bool
	response_code     *int
	addresponse_code  *int
	passthrough_body  *bool
	custom_message    *string
	skip_monitoring   *bool
	description       *string
	clearedFields     map[string]struct{}
	done              bool
	oldValue          func(context.Context) (*ErrorPassthroughRule, error)
	predicates        []predicate.ErrorPassthroughRule
}

var _ ent.Mutation = (*ErrorPassthroughRuleMutation)(nil)

// errorpassthroughruleOption allows management of the mutation configuration using functional options.
type errorpassthroughruleOption func(*ErrorPassthroughRuleMutation)

// newErrorPassthroughRuleMutation creates new mutation for the ErrorPassthroughRule entity.
func newErrorPassthroughRuleMutation(c config, op Op, opts ...errorpassthroughruleOption) *ErrorPassthroughRuleMutation {
	m := &ErrorPassthroughRuleMutation{
		config:        c,
		op:            op,
		typ:           TypeErrorPassthroughRule,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withErrorPassthroughRuleID sets the ID field of the mutation.
func withErrorPassthroughRuleID(id int64) errorpassthroughruleOption {
	return func(m *ErrorPassthroughRuleMutation) {
		var (
			err   error
			once  sync.Once
			value *ErrorPassthroughRule
		)
		m.oldValue = func(ctx context.Context) (*ErrorPassthroughRule, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().ErrorPassthroughRule.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withErrorPassthroughRule sets the old ErrorPassthroughRule of the mutation.
func withErrorPassthroughRule(node *ErrorPassthroughRule) errorpassthroughruleOption {
	return func(m *ErrorPassthroughRuleMutation) {
		m.oldValue = func(context.Context) (*ErrorPassthroughRule, 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 ErrorPassthroughRuleMutation) 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 ErrorPassthroughRuleMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *ErrorPassthroughRuleMutation) ID() (id int64, 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 *ErrorPassthroughRuleMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().ErrorPassthroughRule.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *ErrorPassthroughRuleMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *ErrorPassthroughRuleMutation) 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 ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) 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 *ErrorPassthroughRuleMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *ErrorPassthroughRuleMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *ErrorPassthroughRuleMutation) 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 ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) 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 *ErrorPassthroughRuleMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetName sets the "name" field.
func (m *ErrorPassthroughRuleMutation) SetName(s string) {
	m.name = &s
}

// Name returns the value of the "name" field in the mutation.
func (m *ErrorPassthroughRuleMutation) 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 ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) 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 *ErrorPassthroughRuleMutation) ResetName() {
	m.name = nil
}

// SetEnabled sets the "enabled" field.
func (m *ErrorPassthroughRuleMutation) SetEnabled(b bool) {
	m.enabled = &b
}

// Enabled returns the value of the "enabled" field in the mutation.
func (m *ErrorPassthroughRuleMutation) Enabled() (r bool, exists bool) {
	v := m.enabled
	if v == nil {
		return
	}
	return *v, true
}

// OldEnabled returns the old "enabled" field's value of the ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) OldEnabled(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldEnabled is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldEnabled requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldEnabled: %w", err)
	}
	return oldValue.Enabled, nil
}

// ResetEnabled resets all changes to the "enabled" field.
func (m *ErrorPassthroughRuleMutation) ResetEnabled() {
	m.enabled = nil
}

// SetPriority sets the "priority" field.
func (m *ErrorPassthroughRuleMutation) SetPriority(i int) {
	m.priority = &i
	m.addpriority = nil
}

// Priority returns the value of the "priority" field in the mutation.
func (m *ErrorPassthroughRuleMutation) Priority() (r int, exists bool) {
	v := m.priority
	if v == nil {
		return
	}
	return *v, true
}

// OldPriority returns the old "priority" field's value of the ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) OldPriority(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPriority is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPriority requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPriority: %w", err)
	}
	return oldValue.Priority, nil
}

// AddPriority adds i to the "priority" field.
func (m *ErrorPassthroughRuleMutation) AddPriority(i int) {
	if m.addpriority != nil {
		*m.addpriority += i
	} else {
		m.addpriority = &i
	}
}

// AddedPriority returns the value that was added to the "priority" field in this mutation.
func (m *ErrorPassthroughRuleMutation) AddedPriority() (r int, exists bool) {
	v := m.addpriority
	if v == nil {
		return
	}
	return *v, true
}

// ResetPriority resets all changes to the "priority" field.
func (m *ErrorPassthroughRuleMutation) ResetPriority() {
	m.priority = nil
	m.addpriority = nil
}

// SetErrorCodes sets the "error_codes" field.
func (m *ErrorPassthroughRuleMutation) SetErrorCodes(i []int) {
	m.error_codes = &i
	m.appenderror_codes = nil
}

// ErrorCodes returns the value of the "error_codes" field in the mutation.
func (m *ErrorPassthroughRuleMutation) ErrorCodes() (r []int, exists bool) {
	v := m.error_codes
	if v == nil {
		return
	}
	return *v, true
}

// OldErrorCodes returns the old "error_codes" field's value of the ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) OldErrorCodes(ctx context.Context) (v []int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldErrorCodes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldErrorCodes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldErrorCodes: %w", err)
	}
	return oldValue.ErrorCodes, nil
}

// AppendErrorCodes adds i to the "error_codes" field.
func (m *ErrorPassthroughRuleMutation) AppendErrorCodes(i []int) {
	m.appenderror_codes = append(m.appenderror_codes, i...)
}

// AppendedErrorCodes returns the list of values that were appended to the "error_codes" field in this mutation.
func (m *ErrorPassthroughRuleMutation) AppendedErrorCodes() ([]int, bool) {
	if len(m.appenderror_codes) == 0 {
		return nil, false
	}
	return m.appenderror_codes, true
}

// ClearErrorCodes clears the value of the "error_codes" field.
func (m *ErrorPassthroughRuleMutation) ClearErrorCodes() {
	m.error_codes = nil
	m.appenderror_codes = nil
	m.clearedFields[errorpassthroughrule.FieldErrorCodes] = struct{}{}
}

// ErrorCodesCleared returns if the "error_codes" field was cleared in this mutation.
func (m *ErrorPassthroughRuleMutation) ErrorCodesCleared() bool {
	_, ok := m.clearedFields[errorpassthroughrule.FieldErrorCodes]
	return ok
}

// ResetErrorCodes resets all changes to the "error_codes" field.
func (m *ErrorPassthroughRuleMutation) ResetErrorCodes() {
	m.error_codes = nil
	m.appenderror_codes = nil
	delete(m.clearedFields, errorpassthroughrule.FieldErrorCodes)
}

// SetKeywords sets the "keywords" field.
func (m *ErrorPassthroughRuleMutation) SetKeywords(s []string) {
	m.keywords = &s
	m.appendkeywords = nil
}

// Keywords returns the value of the "keywords" field in the mutation.
func (m *ErrorPassthroughRuleMutation) Keywords() (r []string, exists bool) {
	v := m.keywords
	if v == nil {
		return
	}
	return *v, true
}

// OldKeywords returns the old "keywords" field's value of the ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) OldKeywords(ctx context.Context) (v []string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldKeywords is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldKeywords requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldKeywords: %w", err)
	}
	return oldValue.Keywords, nil
}

// AppendKeywords adds s to the "keywords" field.
func (m *ErrorPassthroughRuleMutation) AppendKeywords(s []string) {
	m.appendkeywords = append(m.appendkeywords, s...)
}

// AppendedKeywords returns the list of values that were appended to the "keywords" field in this mutation.
func (m *ErrorPassthroughRuleMutation) AppendedKeywords() ([]string, bool) {
	if len(m.appendkeywords) == 0 {
		return nil, false
	}
	return m.appendkeywords, true
}

// ClearKeywords clears the value of the "keywords" field.
func (m *ErrorPassthroughRuleMutation) ClearKeywords() {
	m.keywords = nil
	m.appendkeywords = nil
	m.clearedFields[errorpassthroughrule.FieldKeywords] = struct{}{}
}

// KeywordsCleared returns if the "keywords" field was cleared in this mutation.
func (m *ErrorPassthroughRuleMutation) KeywordsCleared() bool {
	_, ok := m.clearedFields[errorpassthroughrule.FieldKeywords]
	return ok
}

// ResetKeywords resets all changes to the "keywords" field.
func (m *ErrorPassthroughRuleMutation) ResetKeywords() {
	m.keywords = nil
	m.appendkeywords = nil
	delete(m.clearedFields, errorpassthroughrule.FieldKeywords)
}

// SetMatchMode sets the "match_mode" field.
func (m *ErrorPassthroughRuleMutation) SetMatchMode(s string) {
	m.match_mode = &s
}

// MatchMode returns the value of the "match_mode" field in the mutation.
func (m *ErrorPassthroughRuleMutation) MatchMode() (r string, exists bool) {
	v := m.match_mode
	if v == nil {
		return
	}
	return *v, true
}

// OldMatchMode returns the old "match_mode" field's value of the ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) OldMatchMode(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldMatchMode is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldMatchMode requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldMatchMode: %w", err)
	}
	return oldValue.MatchMode, nil
}

// ResetMatchMode resets all changes to the "match_mode" field.
func (m *ErrorPassthroughRuleMutation) ResetMatchMode() {
	m.match_mode = nil
}

// SetPlatforms sets the "platforms" field.
func (m *ErrorPassthroughRuleMutation) SetPlatforms(s []string) {
	m.platforms = &s
	m.appendplatforms = nil
}

// Platforms returns the value of the "platforms" field in the mutation.
func (m *ErrorPassthroughRuleMutation) Platforms() (r []string, exists bool) {
	v := m.platforms
	if v == nil {
		return
	}
	return *v, true
}

// OldPlatforms returns the old "platforms" field's value of the ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) OldPlatforms(ctx context.Context) (v []string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPlatforms is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPlatforms requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPlatforms: %w", err)
	}
	return oldValue.Platforms, nil
}

// AppendPlatforms adds s to the "platforms" field.
func (m *ErrorPassthroughRuleMutation) AppendPlatforms(s []string) {
	m.appendplatforms = append(m.appendplatforms, s...)
}

// AppendedPlatforms returns the list of values that were appended to the "platforms" field in this mutation.
func (m *ErrorPassthroughRuleMutation) AppendedPlatforms() ([]string, bool) {
	if len(m.appendplatforms) == 0 {
		return nil, false
	}
	return m.appendplatforms, true
}

// ClearPlatforms clears the value of the "platforms" field.
func (m *ErrorPassthroughRuleMutation) ClearPlatforms() {
	m.platforms = nil
	m.appendplatforms = nil
	m.clearedFields[errorpassthroughrule.FieldPlatforms] = struct{}{}
}

// PlatformsCleared returns if the "platforms" field was cleared in this mutation.
func (m *ErrorPassthroughRuleMutation) PlatformsCleared() bool {
	_, ok := m.clearedFields[errorpassthroughrule.FieldPlatforms]
	return ok
}

// ResetPlatforms resets all changes to the "platforms" field.
func (m *ErrorPassthroughRuleMutation) ResetPlatforms() {
	m.platforms = nil
	m.appendplatforms = nil
	delete(m.clearedFields, errorpassthroughrule.FieldPlatforms)
}

// SetPassthroughCode sets the "passthrough_code" field.
func (m *ErrorPassthroughRuleMutation) SetPassthroughCode(b bool) {
	m.passthrough_code = &b
}

// PassthroughCode returns the value of the "passthrough_code" field in the mutation.
func (m *ErrorPassthroughRuleMutation) PassthroughCode() (r bool, exists bool) {
	v := m.passthrough_code
	if v == nil {
		return
	}
	return *v, true
}

// OldPassthroughCode returns the old "passthrough_code" field's value of the ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) OldPassthroughCode(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPassthroughCode is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPassthroughCode requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPassthroughCode: %w", err)
	}
	return oldValue.PassthroughCode, nil
}

// ResetPassthroughCode resets all changes to the "passthrough_code" field.
func (m *ErrorPassthroughRuleMutation) ResetPassthroughCode() {
	m.passthrough_code = nil
}

// SetResponseCode sets the "response_code" field.
func (m *ErrorPassthroughRuleMutation) SetResponseCode(i int) {
	m.response_code = &i
	m.addresponse_code = nil
}

// ResponseCode returns the value of the "response_code" field in the mutation.
func (m *ErrorPassthroughRuleMutation) ResponseCode() (r int, exists bool) {
	v := m.response_code
	if v == nil {
		return
	}
	return *v, true
}

// OldResponseCode returns the old "response_code" field's value of the ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) OldResponseCode(ctx context.Context) (v *int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldResponseCode is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldResponseCode requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldResponseCode: %w", err)
	}
	return oldValue.ResponseCode, nil
}

// AddResponseCode adds i to the "response_code" field.
func (m *ErrorPassthroughRuleMutation) AddResponseCode(i int) {
	if m.addresponse_code != nil {
		*m.addresponse_code += i
	} else {
		m.addresponse_code = &i
	}
}

// AddedResponseCode returns the value that was added to the "response_code" field in this mutation.
func (m *ErrorPassthroughRuleMutation) AddedResponseCode() (r int, exists bool) {
	v := m.addresponse_code
	if v == nil {
		return
	}
	return *v, true
}

// ClearResponseCode clears the value of the "response_code" field.
func (m *ErrorPassthroughRuleMutation) ClearResponseCode() {
	m.response_code = nil
	m.addresponse_code = nil
	m.clearedFields[errorpassthroughrule.FieldResponseCode] = struct{}{}
}

// ResponseCodeCleared returns if the "response_code" field was cleared in this mutation.
func (m *ErrorPassthroughRuleMutation) ResponseCodeCleared() bool {
	_, ok := m.clearedFields[errorpassthroughrule.FieldResponseCode]
	return ok
}

// ResetResponseCode resets all changes to the "response_code" field.
func (m *ErrorPassthroughRuleMutation) ResetResponseCode() {
	m.response_code = nil
	m.addresponse_code = nil
	delete(m.clearedFields, errorpassthroughrule.FieldResponseCode)
}

// SetPassthroughBody sets the "passthrough_body" field.
func (m *ErrorPassthroughRuleMutation) SetPassthroughBody(b bool) {
	m.passthrough_body = &b
}

// PassthroughBody returns the value of the "passthrough_body" field in the mutation.
func (m *ErrorPassthroughRuleMutation) PassthroughBody() (r bool, exists bool) {
	v := m.passthrough_body
	if v == nil {
		return
	}
	return *v, true
}

// OldPassthroughBody returns the old "passthrough_body" field's value of the ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) OldPassthroughBody(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPassthroughBody is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPassthroughBody requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPassthroughBody: %w", err)
	}
	return oldValue.PassthroughBody, nil
}

// ResetPassthroughBody resets all changes to the "passthrough_body" field.
func (m *ErrorPassthroughRuleMutation) ResetPassthroughBody() {
	m.passthrough_body = nil
}

// SetCustomMessage sets the "custom_message" field.
func (m *ErrorPassthroughRuleMutation) SetCustomMessage(s string) {
	m.custom_message = &s
}

// CustomMessage returns the value of the "custom_message" field in the mutation.
func (m *ErrorPassthroughRuleMutation) CustomMessage() (r string, exists bool) {
	v := m.custom_message
	if v == nil {
		return
	}
	return *v, true
}

// OldCustomMessage returns the old "custom_message" field's value of the ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) OldCustomMessage(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCustomMessage is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCustomMessage requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCustomMessage: %w", err)
	}
	return oldValue.CustomMessage, nil
}

// ClearCustomMessage clears the value of the "custom_message" field.
func (m *ErrorPassthroughRuleMutation) ClearCustomMessage() {
	m.custom_message = nil
	m.clearedFields[errorpassthroughrule.FieldCustomMessage] = struct{}{}
}

// CustomMessageCleared returns if the "custom_message" field was cleared in this mutation.
func (m *ErrorPassthroughRuleMutation) CustomMessageCleared() bool {
	_, ok := m.clearedFields[errorpassthroughrule.FieldCustomMessage]
	return ok
}

// ResetCustomMessage resets all changes to the "custom_message" field.
func (m *ErrorPassthroughRuleMutation) ResetCustomMessage() {
	m.custom_message = nil
	delete(m.clearedFields, errorpassthroughrule.FieldCustomMessage)
}

// SetSkipMonitoring sets the "skip_monitoring" field.
func (m *ErrorPassthroughRuleMutation) SetSkipMonitoring(b bool) {
	m.skip_monitoring = &b
}

// SkipMonitoring returns the value of the "skip_monitoring" field in the mutation.
func (m *ErrorPassthroughRuleMutation) SkipMonitoring() (r bool, exists bool) {
	v := m.skip_monitoring
	if v == nil {
		return
	}
	return *v, true
}

// OldSkipMonitoring returns the old "skip_monitoring" field's value of the ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) OldSkipMonitoring(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSkipMonitoring is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSkipMonitoring requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSkipMonitoring: %w", err)
	}
	return oldValue.SkipMonitoring, nil
}

// ResetSkipMonitoring resets all changes to the "skip_monitoring" field.
func (m *ErrorPassthroughRuleMutation) ResetSkipMonitoring() {
	m.skip_monitoring = nil
}

// SetDescription sets the "description" field.
func (m *ErrorPassthroughRuleMutation) SetDescription(s string) {
	m.description = &s
}

// Description returns the value of the "description" field in the mutation.
func (m *ErrorPassthroughRuleMutation) 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 ErrorPassthroughRule entity.
// If the ErrorPassthroughRule object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ErrorPassthroughRuleMutation) 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 *ErrorPassthroughRuleMutation) ClearDescription() {
	m.description = nil
	m.clearedFields[errorpassthroughrule.FieldDescription] = struct{}{}
}

// DescriptionCleared returns if the "description" field was cleared in this mutation.
func (m *ErrorPassthroughRuleMutation) DescriptionCleared() bool {
	_, ok := m.clearedFields[errorpassthroughrule.FieldDescription]
	return ok
}

// ResetDescription resets all changes to the "description" field.
func (m *ErrorPassthroughRuleMutation) ResetDescription() {
	m.description = nil
	delete(m.clearedFields, errorpassthroughrule.FieldDescription)
}

// Where appends a list predicates to the ErrorPassthroughRuleMutation builder.
func (m *ErrorPassthroughRuleMutation) Where(ps ...predicate.ErrorPassthroughRule) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the ErrorPassthroughRuleMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *ErrorPassthroughRuleMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.ErrorPassthroughRule, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *ErrorPassthroughRuleMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *ErrorPassthroughRuleMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (ErrorPassthroughRule).
func (m *ErrorPassthroughRuleMutation) 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 *ErrorPassthroughRuleMutation) Fields() []string {
	fields := make([]string, 0, 15)
	if m.created_at != nil {
		fields = append(fields, errorpassthroughrule.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, errorpassthroughrule.FieldUpdatedAt)
	}
	if m.name != nil {
		fields = append(fields, errorpassthroughrule.FieldName)
	}
	if m.enabled != nil {
		fields = append(fields, errorpassthroughrule.FieldEnabled)
	}
	if m.priority != nil {
		fields = append(fields, errorpassthroughrule.FieldPriority)
	}
	if m.error_codes != nil {
		fields = append(fields, errorpassthroughrule.FieldErrorCodes)
	}
	if m.keywords != nil {
		fields = append(fields, errorpassthroughrule.FieldKeywords)
	}
	if m.match_mode != nil {
		fields = append(fields, errorpassthroughrule.FieldMatchMode)
	}
	if m.platforms != nil {
		fields = append(fields, errorpassthroughrule.FieldPlatforms)
	}
	if m.passthrough_code != nil {
		fields = append(fields, errorpassthroughrule.FieldPassthroughCode)
	}
	if m.response_code != nil {
		fields = append(fields, errorpassthroughrule.FieldResponseCode)
	}
	if m.passthrough_body != nil {
		fields = append(fields, errorpassthroughrule.FieldPassthroughBody)
	}
	if m.custom_message != nil {
		fields = append(fields, errorpassthroughrule.FieldCustomMessage)
	}
	if m.skip_monitoring != nil {
		fields = append(fields, errorpassthroughrule.FieldSkipMonitoring)
	}
	if m.description != nil {
		fields = append(fields, errorpassthroughrule.FieldDescription)
	}
	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 *ErrorPassthroughRuleMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case errorpassthroughrule.FieldCreatedAt:
		return m.CreatedAt()
	case errorpassthroughrule.FieldUpdatedAt:
		return m.UpdatedAt()
	case errorpassthroughrule.FieldName:
		return m.Name()
	case errorpassthroughrule.FieldEnabled:
		return m.Enabled()
	case errorpassthroughrule.FieldPriority:
		return m.Priority()
	case errorpassthroughrule.FieldErrorCodes:
		return m.ErrorCodes()
	case errorpassthroughrule.FieldKeywords:
		return m.Keywords()
	case errorpassthroughrule.FieldMatchMode:
		return m.MatchMode()
	case errorpassthroughrule.FieldPlatforms:
		return m.Platforms()
	case errorpassthroughrule.FieldPassthroughCode:
		return m.PassthroughCode()
	case errorpassthroughrule.FieldResponseCode:
		return m.ResponseCode()
	case errorpassthroughrule.FieldPassthroughBody:
		return m.PassthroughBody()
	case errorpassthroughrule.FieldCustomMessage:
		return m.CustomMessage()
	case errorpassthroughrule.FieldSkipMonitoring:
		return m.SkipMonitoring()
	case errorpassthroughrule.FieldDescription:
		return m.Description()
	}
	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 *ErrorPassthroughRuleMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case errorpassthroughrule.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case errorpassthroughrule.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case errorpassthroughrule.FieldName:
		return m.OldName(ctx)
	case errorpassthroughrule.FieldEnabled:
		return m.OldEnabled(ctx)
	case errorpassthroughrule.FieldPriority:
		return m.OldPriority(ctx)
	case errorpassthroughrule.FieldErrorCodes:
		return m.OldErrorCodes(ctx)
	case errorpassthroughrule.FieldKeywords:
		return m.OldKeywords(ctx)
	case errorpassthroughrule.FieldMatchMode:
		return m.OldMatchMode(ctx)
	case errorpassthroughrule.FieldPlatforms:
		return m.OldPlatforms(ctx)
	case errorpassthroughrule.FieldPassthroughCode:
		return m.OldPassthroughCode(ctx)
	case errorpassthroughrule.FieldResponseCode:
		return m.OldResponseCode(ctx)
	case errorpassthroughrule.FieldPassthroughBody:
		return m.OldPassthroughBody(ctx)
	case errorpassthroughrule.FieldCustomMessage:
		return m.OldCustomMessage(ctx)
	case errorpassthroughrule.FieldSkipMonitoring:
		return m.OldSkipMonitoring(ctx)
	case errorpassthroughrule.FieldDescription:
		return m.OldDescription(ctx)
	}
	return nil, fmt.Errorf("unknown ErrorPassthroughRule 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 *ErrorPassthroughRuleMutation) SetField(name string, value ent.Value) error {
	switch name {
	case errorpassthroughrule.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 errorpassthroughrule.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 errorpassthroughrule.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case errorpassthroughrule.FieldEnabled:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEnabled(v)
		return nil
	case errorpassthroughrule.FieldPriority:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPriority(v)
		return nil
	case errorpassthroughrule.FieldErrorCodes:
		v, ok := value.([]int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetErrorCodes(v)
		return nil
	case errorpassthroughrule.FieldKeywords:
		v, ok := value.([]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetKeywords(v)
		return nil
	case errorpassthroughrule.FieldMatchMode:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMatchMode(v)
		return nil
	case errorpassthroughrule.FieldPlatforms:
		v, ok := value.([]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPlatforms(v)
		return nil
	case errorpassthroughrule.FieldPassthroughCode:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPassthroughCode(v)
		return nil
	case errorpassthroughrule.FieldResponseCode:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetResponseCode(v)
		return nil
	case errorpassthroughrule.FieldPassthroughBody:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPassthroughBody(v)
		return nil
	case errorpassthroughrule.FieldCustomMessage:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCustomMessage(v)
		return nil
	case errorpassthroughrule.FieldSkipMonitoring:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSkipMonitoring(v)
		return nil
	case errorpassthroughrule.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	}
	return fmt.Errorf("unknown ErrorPassthroughRule field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *ErrorPassthroughRuleMutation) AddedFields() []string {
	var fields []string
	if m.addpriority != nil {
		fields = append(fields, errorpassthroughrule.FieldPriority)
	}
	if m.addresponse_code != nil {
		fields = append(fields, errorpassthroughrule.FieldResponseCode)
	}
	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 *ErrorPassthroughRuleMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case errorpassthroughrule.FieldPriority:
		return m.AddedPriority()
	case errorpassthroughrule.FieldResponseCode:
		return m.AddedResponseCode()
	}
	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 *ErrorPassthroughRuleMutation) AddField(name string, value ent.Value) error {
	switch name {
	case errorpassthroughrule.FieldPriority:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPriority(v)
		return nil
	case errorpassthroughrule.FieldResponseCode:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddResponseCode(v)
		return nil
	}
	return fmt.Errorf("unknown ErrorPassthroughRule numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *ErrorPassthroughRuleMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(errorpassthroughrule.FieldErrorCodes) {
		fields = append(fields, errorpassthroughrule.FieldErrorCodes)
	}
	if m.FieldCleared(errorpassthroughrule.FieldKeywords) {
		fields = append(fields, errorpassthroughrule.FieldKeywords)
	}
	if m.FieldCleared(errorpassthroughrule.FieldPlatforms) {
		fields = append(fields, errorpassthroughrule.FieldPlatforms)
	}
	if m.FieldCleared(errorpassthroughrule.FieldResponseCode) {
		fields = append(fields, errorpassthroughrule.FieldResponseCode)
	}
	if m.FieldCleared(errorpassthroughrule.FieldCustomMessage) {
		fields = append(fields, errorpassthroughrule.FieldCustomMessage)
	}
	if m.FieldCleared(errorpassthroughrule.FieldDescription) {
		fields = append(fields, errorpassthroughrule.FieldDescription)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ErrorPassthroughRuleMutation) 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 *ErrorPassthroughRuleMutation) ClearField(name string) error {
	switch name {
	case errorpassthroughrule.FieldErrorCodes:
		m.ClearErrorCodes()
		return nil
	case errorpassthroughrule.FieldKeywords:
		m.ClearKeywords()
		return nil
	case errorpassthroughrule.FieldPlatforms:
		m.ClearPlatforms()
		return nil
	case errorpassthroughrule.FieldResponseCode:
		m.ClearResponseCode()
		return nil
	case errorpassthroughrule.FieldCustomMessage:
		m.ClearCustomMessage()
		return nil
	case errorpassthroughrule.FieldDescription:
		m.ClearDescription()
		return nil
	}
	return fmt.Errorf("unknown ErrorPassthroughRule 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 *ErrorPassthroughRuleMutation) ResetField(name string) error {
	switch name {
	case errorpassthroughrule.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case errorpassthroughrule.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case errorpassthroughrule.FieldName:
		m.ResetName()
		return nil
	case errorpassthroughrule.FieldEnabled:
		m.ResetEnabled()
		return nil
	case errorpassthroughrule.FieldPriority:
		m.ResetPriority()
		return nil
	case errorpassthroughrule.FieldErrorCodes:
		m.ResetErrorCodes()
		return nil
	case errorpassthroughrule.FieldKeywords:
		m.ResetKeywords()
		return nil
	case errorpassthroughrule.FieldMatchMode:
		m.ResetMatchMode()
		return nil
	case errorpassthroughrule.FieldPlatforms:
		m.ResetPlatforms()
		return nil
	case errorpassthroughrule.FieldPassthroughCode:
		m.ResetPassthroughCode()
		return nil
	case errorpassthroughrule.FieldResponseCode:
		m.ResetResponseCode()
		return nil
	case errorpassthroughrule.FieldPassthroughBody:
		m.ResetPassthroughBody()
		return nil
	case errorpassthroughrule.FieldCustomMessage:
		m.ResetCustomMessage()
		return nil
	case errorpassthroughrule.FieldSkipMonitoring:
		m.ResetSkipMonitoring()
		return nil
	case errorpassthroughrule.FieldDescription:
		m.ResetDescription()
		return nil
	}
	return fmt.Errorf("unknown ErrorPassthroughRule field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *ErrorPassthroughRuleMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *ErrorPassthroughRuleMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *ErrorPassthroughRuleMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *ErrorPassthroughRuleMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *ErrorPassthroughRuleMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ErrorPassthroughRuleMutation) EdgeCleared(name string) bool {
	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 *ErrorPassthroughRuleMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown ErrorPassthroughRule 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 *ErrorPassthroughRuleMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown ErrorPassthroughRule edge %s", name)
}

// GroupMutation represents an operation that mutates the Group nodes in the graph.
type GroupMutation struct {
	config
	op                                      Op
	typ                                     string
	id                                      *int64
	created_at                              *time.Time
	updated_at                              *time.Time
	deleted_at                              *time.Time
	name                                    *string
	description                             *string
	rate_multiplier                         *float64
	addrate_multiplier                      *float64
	is_exclusive                            *bool
	status                                  *string
	platform                                *string
	subscription_type                       *string
	daily_limit_usd                         *float64
	adddaily_limit_usd                      *float64
	weekly_limit_usd                        *float64
	addweekly_limit_usd                     *float64
	monthly_limit_usd                       *float64
	addmonthly_limit_usd                    *float64
	default_validity_days                   *int
	adddefault_validity_days                *int
	image_price_1k                          *float64
	addimage_price_1k                       *float64
	image_price_2k                          *float64
	addimage_price_2k                       *float64
	image_price_4k                          *float64
	addimage_price_4k                       *float64
	claude_code_only                        *bool
	fallback_group_id                       *int64
	addfallback_group_id                    *int64
	fallback_group_id_on_invalid_request    *int64
	addfallback_group_id_on_invalid_request *int64
	model_routing                           *map[string][]int64
	model_routing_enabled                   *bool
	mcp_xml_inject                          *bool
	supported_model_scopes                  *[]string
	appendsupported_model_scopes            []string
	sort_order                              *int
	addsort_order                           *int
	allow_messages_dispatch                 *bool
	require_oauth_only                      *bool
	require_privacy_set                     *bool
	default_mapped_model                    *string
	messages_dispatch_model_config          *domain.OpenAIMessagesDispatchModelConfig
	clearedFields                           map[string]struct{}
	api_keys                                map[int64]struct{}
	removedapi_keys                         map[int64]struct{}
	clearedapi_keys                         bool
	redeem_codes                            map[int64]struct{}
	removedredeem_codes                     map[int64]struct{}
	clearedredeem_codes                     bool
	subscriptions                           map[int64]struct{}
	removedsubscriptions                    map[int64]struct{}
	clearedsubscriptions                    bool
	usage_logs                              map[int64]struct{}
	removedusage_logs                       map[int64]struct{}
	clearedusage_logs                       bool
	accounts                                map[int64]struct{}
	removedaccounts                         map[int64]struct{}
	clearedaccounts                         bool
	allowed_users                           map[int64]struct{}
	removedallowed_users                    map[int64]struct{}
	clearedallowed_users                    bool
	done                                    bool
	oldValue                                func(context.Context) (*Group, error)
	predicates                              []predicate.Group
}

var _ ent.Mutation = (*GroupMutation)(nil)

// groupOption allows management of the mutation configuration using functional options.
type groupOption func(*GroupMutation)

// newGroupMutation creates new mutation for the Group entity.
func newGroupMutation(c config, op Op, opts ...groupOption) *GroupMutation {
	m := &GroupMutation{
		config:        c,
		op:            op,
		typ:           TypeGroup,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withGroupID sets the ID field of the mutation.
func withGroupID(id int64) groupOption {
	return func(m *GroupMutation) {
		var (
			err   error
			once  sync.Once
			value *Group
		)
		m.oldValue = func(ctx context.Context) (*Group, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Group.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withGroup sets the old Group of the mutation.
func withGroup(node *Group) groupOption {
	return func(m *GroupMutation) {
		m.oldValue = func(context.Context) (*Group, 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 GroupMutation) 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 GroupMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *GroupMutation) ID() (id int64, 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 *GroupMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Group.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *GroupMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *GroupMutation) 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 Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) 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 *GroupMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *GroupMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *GroupMutation) 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 Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) 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 *GroupMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetDeletedAt sets the "deleted_at" field.
func (m *GroupMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *GroupMutation) 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 Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) 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 *GroupMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[group.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *GroupMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[group.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *GroupMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, group.FieldDeletedAt)
}

// SetName sets the "name" field.
func (m *GroupMutation) SetName(s string) {
	m.name = &s
}

// Name returns the value of the "name" field in the mutation.
func (m *GroupMutation) 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 Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) 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 *GroupMutation) ResetName() {
	m.name = nil
}

// SetDescription sets the "description" field.
func (m *GroupMutation) SetDescription(s string) {
	m.description = &s
}

// Description returns the value of the "description" field in the mutation.
func (m *GroupMutation) 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 Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) 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 *GroupMutation) ClearDescription() {
	m.description = nil
	m.clearedFields[group.FieldDescription] = struct{}{}
}

// DescriptionCleared returns if the "description" field was cleared in this mutation.
func (m *GroupMutation) DescriptionCleared() bool {
	_, ok := m.clearedFields[group.FieldDescription]
	return ok
}

// ResetDescription resets all changes to the "description" field.
func (m *GroupMutation) ResetDescription() {
	m.description = nil
	delete(m.clearedFields, group.FieldDescription)
}

// SetRateMultiplier sets the "rate_multiplier" field.
func (m *GroupMutation) SetRateMultiplier(f float64) {
	m.rate_multiplier = &f
	m.addrate_multiplier = nil
}

// RateMultiplier returns the value of the "rate_multiplier" field in the mutation.
func (m *GroupMutation) RateMultiplier() (r float64, exists bool) {
	v := m.rate_multiplier
	if v == nil {
		return
	}
	return *v, true
}

// OldRateMultiplier returns the old "rate_multiplier" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldRateMultiplier(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRateMultiplier is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRateMultiplier requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRateMultiplier: %w", err)
	}
	return oldValue.RateMultiplier, nil
}

// AddRateMultiplier adds f to the "rate_multiplier" field.
func (m *GroupMutation) AddRateMultiplier(f float64) {
	if m.addrate_multiplier != nil {
		*m.addrate_multiplier += f
	} else {
		m.addrate_multiplier = &f
	}
}

// AddedRateMultiplier returns the value that was added to the "rate_multiplier" field in this mutation.
func (m *GroupMutation) AddedRateMultiplier() (r float64, exists bool) {
	v := m.addrate_multiplier
	if v == nil {
		return
	}
	return *v, true
}

// ResetRateMultiplier resets all changes to the "rate_multiplier" field.
func (m *GroupMutation) ResetRateMultiplier() {
	m.rate_multiplier = nil
	m.addrate_multiplier = nil
}

// SetIsExclusive sets the "is_exclusive" field.
func (m *GroupMutation) SetIsExclusive(b bool) {
	m.is_exclusive = &b
}

// IsExclusive returns the value of the "is_exclusive" field in the mutation.
func (m *GroupMutation) IsExclusive() (r bool, exists bool) {
	v := m.is_exclusive
	if v == nil {
		return
	}
	return *v, true
}

// OldIsExclusive returns the old "is_exclusive" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldIsExclusive(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldIsExclusive is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldIsExclusive requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldIsExclusive: %w", err)
	}
	return oldValue.IsExclusive, nil
}

// ResetIsExclusive resets all changes to the "is_exclusive" field.
func (m *GroupMutation) ResetIsExclusive() {
	m.is_exclusive = nil
}

// SetStatus sets the "status" field.
func (m *GroupMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *GroupMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldStatus(ctx context.Context) (v string, 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 *GroupMutation) ResetStatus() {
	m.status = nil
}

// SetPlatform sets the "platform" field.
func (m *GroupMutation) SetPlatform(s string) {
	m.platform = &s
}

// Platform returns the value of the "platform" field in the mutation.
func (m *GroupMutation) Platform() (r string, exists bool) {
	v := m.platform
	if v == nil {
		return
	}
	return *v, true
}

// OldPlatform returns the old "platform" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldPlatform(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPlatform is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPlatform requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPlatform: %w", err)
	}
	return oldValue.Platform, nil
}

// ResetPlatform resets all changes to the "platform" field.
func (m *GroupMutation) ResetPlatform() {
	m.platform = nil
}

// SetSubscriptionType sets the "subscription_type" field.
func (m *GroupMutation) SetSubscriptionType(s string) {
	m.subscription_type = &s
}

// SubscriptionType returns the value of the "subscription_type" field in the mutation.
func (m *GroupMutation) SubscriptionType() (r string, exists bool) {
	v := m.subscription_type
	if v == nil {
		return
	}
	return *v, true
}

// OldSubscriptionType returns the old "subscription_type" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldSubscriptionType(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSubscriptionType is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSubscriptionType requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSubscriptionType: %w", err)
	}
	return oldValue.SubscriptionType, nil
}

// ResetSubscriptionType resets all changes to the "subscription_type" field.
func (m *GroupMutation) ResetSubscriptionType() {
	m.subscription_type = nil
}

// SetDailyLimitUsd sets the "daily_limit_usd" field.
func (m *GroupMutation) SetDailyLimitUsd(f float64) {
	m.daily_limit_usd = &f
	m.adddaily_limit_usd = nil
}

// DailyLimitUsd returns the value of the "daily_limit_usd" field in the mutation.
func (m *GroupMutation) DailyLimitUsd() (r float64, exists bool) {
	v := m.daily_limit_usd
	if v == nil {
		return
	}
	return *v, true
}

// OldDailyLimitUsd returns the old "daily_limit_usd" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldDailyLimitUsd(ctx context.Context) (v *float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDailyLimitUsd is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDailyLimitUsd requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDailyLimitUsd: %w", err)
	}
	return oldValue.DailyLimitUsd, nil
}

// AddDailyLimitUsd adds f to the "daily_limit_usd" field.
func (m *GroupMutation) AddDailyLimitUsd(f float64) {
	if m.adddaily_limit_usd != nil {
		*m.adddaily_limit_usd += f
	} else {
		m.adddaily_limit_usd = &f
	}
}

// AddedDailyLimitUsd returns the value that was added to the "daily_limit_usd" field in this mutation.
func (m *GroupMutation) AddedDailyLimitUsd() (r float64, exists bool) {
	v := m.adddaily_limit_usd
	if v == nil {
		return
	}
	return *v, true
}

// ClearDailyLimitUsd clears the value of the "daily_limit_usd" field.
func (m *GroupMutation) ClearDailyLimitUsd() {
	m.daily_limit_usd = nil
	m.adddaily_limit_usd = nil
	m.clearedFields[group.FieldDailyLimitUsd] = struct{}{}
}

// DailyLimitUsdCleared returns if the "daily_limit_usd" field was cleared in this mutation.
func (m *GroupMutation) DailyLimitUsdCleared() bool {
	_, ok := m.clearedFields[group.FieldDailyLimitUsd]
	return ok
}

// ResetDailyLimitUsd resets all changes to the "daily_limit_usd" field.
func (m *GroupMutation) ResetDailyLimitUsd() {
	m.daily_limit_usd = nil
	m.adddaily_limit_usd = nil
	delete(m.clearedFields, group.FieldDailyLimitUsd)
}

// SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
func (m *GroupMutation) SetWeeklyLimitUsd(f float64) {
	m.weekly_limit_usd = &f
	m.addweekly_limit_usd = nil
}

// WeeklyLimitUsd returns the value of the "weekly_limit_usd" field in the mutation.
func (m *GroupMutation) WeeklyLimitUsd() (r float64, exists bool) {
	v := m.weekly_limit_usd
	if v == nil {
		return
	}
	return *v, true
}

// OldWeeklyLimitUsd returns the old "weekly_limit_usd" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldWeeklyLimitUsd(ctx context.Context) (v *float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWeeklyLimitUsd is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWeeklyLimitUsd requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWeeklyLimitUsd: %w", err)
	}
	return oldValue.WeeklyLimitUsd, nil
}

// AddWeeklyLimitUsd adds f to the "weekly_limit_usd" field.
func (m *GroupMutation) AddWeeklyLimitUsd(f float64) {
	if m.addweekly_limit_usd != nil {
		*m.addweekly_limit_usd += f
	} else {
		m.addweekly_limit_usd = &f
	}
}

// AddedWeeklyLimitUsd returns the value that was added to the "weekly_limit_usd" field in this mutation.
func (m *GroupMutation) AddedWeeklyLimitUsd() (r float64, exists bool) {
	v := m.addweekly_limit_usd
	if v == nil {
		return
	}
	return *v, true
}

// ClearWeeklyLimitUsd clears the value of the "weekly_limit_usd" field.
func (m *GroupMutation) ClearWeeklyLimitUsd() {
	m.weekly_limit_usd = nil
	m.addweekly_limit_usd = nil
	m.clearedFields[group.FieldWeeklyLimitUsd] = struct{}{}
}

// WeeklyLimitUsdCleared returns if the "weekly_limit_usd" field was cleared in this mutation.
func (m *GroupMutation) WeeklyLimitUsdCleared() bool {
	_, ok := m.clearedFields[group.FieldWeeklyLimitUsd]
	return ok
}

// ResetWeeklyLimitUsd resets all changes to the "weekly_limit_usd" field.
func (m *GroupMutation) ResetWeeklyLimitUsd() {
	m.weekly_limit_usd = nil
	m.addweekly_limit_usd = nil
	delete(m.clearedFields, group.FieldWeeklyLimitUsd)
}

// SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
func (m *GroupMutation) SetMonthlyLimitUsd(f float64) {
	m.monthly_limit_usd = &f
	m.addmonthly_limit_usd = nil
}

// MonthlyLimitUsd returns the value of the "monthly_limit_usd" field in the mutation.
func (m *GroupMutation) MonthlyLimitUsd() (r float64, exists bool) {
	v := m.monthly_limit_usd
	if v == nil {
		return
	}
	return *v, true
}

// OldMonthlyLimitUsd returns the old "monthly_limit_usd" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldMonthlyLimitUsd(ctx context.Context) (v *float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldMonthlyLimitUsd is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldMonthlyLimitUsd requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldMonthlyLimitUsd: %w", err)
	}
	return oldValue.MonthlyLimitUsd, nil
}

// AddMonthlyLimitUsd adds f to the "monthly_limit_usd" field.
func (m *GroupMutation) AddMonthlyLimitUsd(f float64) {
	if m.addmonthly_limit_usd != nil {
		*m.addmonthly_limit_usd += f
	} else {
		m.addmonthly_limit_usd = &f
	}
}

// AddedMonthlyLimitUsd returns the value that was added to the "monthly_limit_usd" field in this mutation.
func (m *GroupMutation) AddedMonthlyLimitUsd() (r float64, exists bool) {
	v := m.addmonthly_limit_usd
	if v == nil {
		return
	}
	return *v, true
}

// ClearMonthlyLimitUsd clears the value of the "monthly_limit_usd" field.
func (m *GroupMutation) ClearMonthlyLimitUsd() {
	m.monthly_limit_usd = nil
	m.addmonthly_limit_usd = nil
	m.clearedFields[group.FieldMonthlyLimitUsd] = struct{}{}
}

// MonthlyLimitUsdCleared returns if the "monthly_limit_usd" field was cleared in this mutation.
func (m *GroupMutation) MonthlyLimitUsdCleared() bool {
	_, ok := m.clearedFields[group.FieldMonthlyLimitUsd]
	return ok
}

// ResetMonthlyLimitUsd resets all changes to the "monthly_limit_usd" field.
func (m *GroupMutation) ResetMonthlyLimitUsd() {
	m.monthly_limit_usd = nil
	m.addmonthly_limit_usd = nil
	delete(m.clearedFields, group.FieldMonthlyLimitUsd)
}

// SetDefaultValidityDays sets the "default_validity_days" field.
func (m *GroupMutation) SetDefaultValidityDays(i int) {
	m.default_validity_days = &i
	m.adddefault_validity_days = nil
}

// DefaultValidityDays returns the value of the "default_validity_days" field in the mutation.
func (m *GroupMutation) DefaultValidityDays() (r int, exists bool) {
	v := m.default_validity_days
	if v == nil {
		return
	}
	return *v, true
}

// OldDefaultValidityDays returns the old "default_validity_days" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldDefaultValidityDays(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDefaultValidityDays is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDefaultValidityDays requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDefaultValidityDays: %w", err)
	}
	return oldValue.DefaultValidityDays, nil
}

// AddDefaultValidityDays adds i to the "default_validity_days" field.
func (m *GroupMutation) AddDefaultValidityDays(i int) {
	if m.adddefault_validity_days != nil {
		*m.adddefault_validity_days += i
	} else {
		m.adddefault_validity_days = &i
	}
}

// AddedDefaultValidityDays returns the value that was added to the "default_validity_days" field in this mutation.
func (m *GroupMutation) AddedDefaultValidityDays() (r int, exists bool) {
	v := m.adddefault_validity_days
	if v == nil {
		return
	}
	return *v, true
}

// ResetDefaultValidityDays resets all changes to the "default_validity_days" field.
func (m *GroupMutation) ResetDefaultValidityDays() {
	m.default_validity_days = nil
	m.adddefault_validity_days = nil
}

// SetImagePrice1k sets the "image_price_1k" field.
func (m *GroupMutation) SetImagePrice1k(f float64) {
	m.image_price_1k = &f
	m.addimage_price_1k = nil
}

// ImagePrice1k returns the value of the "image_price_1k" field in the mutation.
func (m *GroupMutation) ImagePrice1k() (r float64, exists bool) {
	v := m.image_price_1k
	if v == nil {
		return
	}
	return *v, true
}

// OldImagePrice1k returns the old "image_price_1k" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldImagePrice1k(ctx context.Context) (v *float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldImagePrice1k is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldImagePrice1k requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldImagePrice1k: %w", err)
	}
	return oldValue.ImagePrice1k, nil
}

// AddImagePrice1k adds f to the "image_price_1k" field.
func (m *GroupMutation) AddImagePrice1k(f float64) {
	if m.addimage_price_1k != nil {
		*m.addimage_price_1k += f
	} else {
		m.addimage_price_1k = &f
	}
}

// AddedImagePrice1k returns the value that was added to the "image_price_1k" field in this mutation.
func (m *GroupMutation) AddedImagePrice1k() (r float64, exists bool) {
	v := m.addimage_price_1k
	if v == nil {
		return
	}
	return *v, true
}

// ClearImagePrice1k clears the value of the "image_price_1k" field.
func (m *GroupMutation) ClearImagePrice1k() {
	m.image_price_1k = nil
	m.addimage_price_1k = nil
	m.clearedFields[group.FieldImagePrice1k] = struct{}{}
}

// ImagePrice1kCleared returns if the "image_price_1k" field was cleared in this mutation.
func (m *GroupMutation) ImagePrice1kCleared() bool {
	_, ok := m.clearedFields[group.FieldImagePrice1k]
	return ok
}

// ResetImagePrice1k resets all changes to the "image_price_1k" field.
func (m *GroupMutation) ResetImagePrice1k() {
	m.image_price_1k = nil
	m.addimage_price_1k = nil
	delete(m.clearedFields, group.FieldImagePrice1k)
}

// SetImagePrice2k sets the "image_price_2k" field.
func (m *GroupMutation) SetImagePrice2k(f float64) {
	m.image_price_2k = &f
	m.addimage_price_2k = nil
}

// ImagePrice2k returns the value of the "image_price_2k" field in the mutation.
func (m *GroupMutation) ImagePrice2k() (r float64, exists bool) {
	v := m.image_price_2k
	if v == nil {
		return
	}
	return *v, true
}

// OldImagePrice2k returns the old "image_price_2k" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldImagePrice2k(ctx context.Context) (v *float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldImagePrice2k is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldImagePrice2k requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldImagePrice2k: %w", err)
	}
	return oldValue.ImagePrice2k, nil
}

// AddImagePrice2k adds f to the "image_price_2k" field.
func (m *GroupMutation) AddImagePrice2k(f float64) {
	if m.addimage_price_2k != nil {
		*m.addimage_price_2k += f
	} else {
		m.addimage_price_2k = &f
	}
}

// AddedImagePrice2k returns the value that was added to the "image_price_2k" field in this mutation.
func (m *GroupMutation) AddedImagePrice2k() (r float64, exists bool) {
	v := m.addimage_price_2k
	if v == nil {
		return
	}
	return *v, true
}

// ClearImagePrice2k clears the value of the "image_price_2k" field.
func (m *GroupMutation) ClearImagePrice2k() {
	m.image_price_2k = nil
	m.addimage_price_2k = nil
	m.clearedFields[group.FieldImagePrice2k] = struct{}{}
}

// ImagePrice2kCleared returns if the "image_price_2k" field was cleared in this mutation.
func (m *GroupMutation) ImagePrice2kCleared() bool {
	_, ok := m.clearedFields[group.FieldImagePrice2k]
	return ok
}

// ResetImagePrice2k resets all changes to the "image_price_2k" field.
func (m *GroupMutation) ResetImagePrice2k() {
	m.image_price_2k = nil
	m.addimage_price_2k = nil
	delete(m.clearedFields, group.FieldImagePrice2k)
}

// SetImagePrice4k sets the "image_price_4k" field.
func (m *GroupMutation) SetImagePrice4k(f float64) {
	m.image_price_4k = &f
	m.addimage_price_4k = nil
}

// ImagePrice4k returns the value of the "image_price_4k" field in the mutation.
func (m *GroupMutation) ImagePrice4k() (r float64, exists bool) {
	v := m.image_price_4k
	if v == nil {
		return
	}
	return *v, true
}

// OldImagePrice4k returns the old "image_price_4k" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldImagePrice4k(ctx context.Context) (v *float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldImagePrice4k is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldImagePrice4k requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldImagePrice4k: %w", err)
	}
	return oldValue.ImagePrice4k, nil
}

// AddImagePrice4k adds f to the "image_price_4k" field.
func (m *GroupMutation) AddImagePrice4k(f float64) {
	if m.addimage_price_4k != nil {
		*m.addimage_price_4k += f
	} else {
		m.addimage_price_4k = &f
	}
}

// AddedImagePrice4k returns the value that was added to the "image_price_4k" field in this mutation.
func (m *GroupMutation) AddedImagePrice4k() (r float64, exists bool) {
	v := m.addimage_price_4k
	if v == nil {
		return
	}
	return *v, true
}

// ClearImagePrice4k clears the value of the "image_price_4k" field.
func (m *GroupMutation) ClearImagePrice4k() {
	m.image_price_4k = nil
	m.addimage_price_4k = nil
	m.clearedFields[group.FieldImagePrice4k] = struct{}{}
}

// ImagePrice4kCleared returns if the "image_price_4k" field was cleared in this mutation.
func (m *GroupMutation) ImagePrice4kCleared() bool {
	_, ok := m.clearedFields[group.FieldImagePrice4k]
	return ok
}

// ResetImagePrice4k resets all changes to the "image_price_4k" field.
func (m *GroupMutation) ResetImagePrice4k() {
	m.image_price_4k = nil
	m.addimage_price_4k = nil
	delete(m.clearedFields, group.FieldImagePrice4k)
}

// SetClaudeCodeOnly sets the "claude_code_only" field.
func (m *GroupMutation) SetClaudeCodeOnly(b bool) {
	m.claude_code_only = &b
}

// ClaudeCodeOnly returns the value of the "claude_code_only" field in the mutation.
func (m *GroupMutation) ClaudeCodeOnly() (r bool, exists bool) {
	v := m.claude_code_only
	if v == nil {
		return
	}
	return *v, true
}

// OldClaudeCodeOnly returns the old "claude_code_only" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldClaudeCodeOnly(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldClaudeCodeOnly is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldClaudeCodeOnly requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldClaudeCodeOnly: %w", err)
	}
	return oldValue.ClaudeCodeOnly, nil
}

// ResetClaudeCodeOnly resets all changes to the "claude_code_only" field.
func (m *GroupMutation) ResetClaudeCodeOnly() {
	m.claude_code_only = nil
}

// SetFallbackGroupID sets the "fallback_group_id" field.
func (m *GroupMutation) SetFallbackGroupID(i int64) {
	m.fallback_group_id = &i
	m.addfallback_group_id = nil
}

// FallbackGroupID returns the value of the "fallback_group_id" field in the mutation.
func (m *GroupMutation) FallbackGroupID() (r int64, exists bool) {
	v := m.fallback_group_id
	if v == nil {
		return
	}
	return *v, true
}

// OldFallbackGroupID returns the old "fallback_group_id" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldFallbackGroupID(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFallbackGroupID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFallbackGroupID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFallbackGroupID: %w", err)
	}
	return oldValue.FallbackGroupID, nil
}

// AddFallbackGroupID adds i to the "fallback_group_id" field.
func (m *GroupMutation) AddFallbackGroupID(i int64) {
	if m.addfallback_group_id != nil {
		*m.addfallback_group_id += i
	} else {
		m.addfallback_group_id = &i
	}
}

// AddedFallbackGroupID returns the value that was added to the "fallback_group_id" field in this mutation.
func (m *GroupMutation) AddedFallbackGroupID() (r int64, exists bool) {
	v := m.addfallback_group_id
	if v == nil {
		return
	}
	return *v, true
}

// ClearFallbackGroupID clears the value of the "fallback_group_id" field.
func (m *GroupMutation) ClearFallbackGroupID() {
	m.fallback_group_id = nil
	m.addfallback_group_id = nil
	m.clearedFields[group.FieldFallbackGroupID] = struct{}{}
}

// FallbackGroupIDCleared returns if the "fallback_group_id" field was cleared in this mutation.
func (m *GroupMutation) FallbackGroupIDCleared() bool {
	_, ok := m.clearedFields[group.FieldFallbackGroupID]
	return ok
}

// ResetFallbackGroupID resets all changes to the "fallback_group_id" field.
func (m *GroupMutation) ResetFallbackGroupID() {
	m.fallback_group_id = nil
	m.addfallback_group_id = nil
	delete(m.clearedFields, group.FieldFallbackGroupID)
}

// SetFallbackGroupIDOnInvalidRequest sets the "fallback_group_id_on_invalid_request" field.
func (m *GroupMutation) SetFallbackGroupIDOnInvalidRequest(i int64) {
	m.fallback_group_id_on_invalid_request = &i
	m.addfallback_group_id_on_invalid_request = nil
}

// FallbackGroupIDOnInvalidRequest returns the value of the "fallback_group_id_on_invalid_request" field in the mutation.
func (m *GroupMutation) FallbackGroupIDOnInvalidRequest() (r int64, exists bool) {
	v := m.fallback_group_id_on_invalid_request
	if v == nil {
		return
	}
	return *v, true
}

// OldFallbackGroupIDOnInvalidRequest returns the old "fallback_group_id_on_invalid_request" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldFallbackGroupIDOnInvalidRequest(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFallbackGroupIDOnInvalidRequest is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFallbackGroupIDOnInvalidRequest requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFallbackGroupIDOnInvalidRequest: %w", err)
	}
	return oldValue.FallbackGroupIDOnInvalidRequest, nil
}

// AddFallbackGroupIDOnInvalidRequest adds i to the "fallback_group_id_on_invalid_request" field.
func (m *GroupMutation) AddFallbackGroupIDOnInvalidRequest(i int64) {
	if m.addfallback_group_id_on_invalid_request != nil {
		*m.addfallback_group_id_on_invalid_request += i
	} else {
		m.addfallback_group_id_on_invalid_request = &i
	}
}

// AddedFallbackGroupIDOnInvalidRequest returns the value that was added to the "fallback_group_id_on_invalid_request" field in this mutation.
func (m *GroupMutation) AddedFallbackGroupIDOnInvalidRequest() (r int64, exists bool) {
	v := m.addfallback_group_id_on_invalid_request
	if v == nil {
		return
	}
	return *v, true
}

// ClearFallbackGroupIDOnInvalidRequest clears the value of the "fallback_group_id_on_invalid_request" field.
func (m *GroupMutation) ClearFallbackGroupIDOnInvalidRequest() {
	m.fallback_group_id_on_invalid_request = nil
	m.addfallback_group_id_on_invalid_request = nil
	m.clearedFields[group.FieldFallbackGroupIDOnInvalidRequest] = struct{}{}
}

// FallbackGroupIDOnInvalidRequestCleared returns if the "fallback_group_id_on_invalid_request" field was cleared in this mutation.
func (m *GroupMutation) FallbackGroupIDOnInvalidRequestCleared() bool {
	_, ok := m.clearedFields[group.FieldFallbackGroupIDOnInvalidRequest]
	return ok
}

// ResetFallbackGroupIDOnInvalidRequest resets all changes to the "fallback_group_id_on_invalid_request" field.
func (m *GroupMutation) ResetFallbackGroupIDOnInvalidRequest() {
	m.fallback_group_id_on_invalid_request = nil
	m.addfallback_group_id_on_invalid_request = nil
	delete(m.clearedFields, group.FieldFallbackGroupIDOnInvalidRequest)
}

// SetModelRouting sets the "model_routing" field.
func (m *GroupMutation) SetModelRouting(value map[string][]int64) {
	m.model_routing = &value
}

// ModelRouting returns the value of the "model_routing" field in the mutation.
func (m *GroupMutation) ModelRouting() (r map[string][]int64, exists bool) {
	v := m.model_routing
	if v == nil {
		return
	}
	return *v, true
}

// OldModelRouting returns the old "model_routing" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldModelRouting(ctx context.Context) (v map[string][]int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldModelRouting is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldModelRouting requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldModelRouting: %w", err)
	}
	return oldValue.ModelRouting, nil
}

// ClearModelRouting clears the value of the "model_routing" field.
func (m *GroupMutation) ClearModelRouting() {
	m.model_routing = nil
	m.clearedFields[group.FieldModelRouting] = struct{}{}
}

// ModelRoutingCleared returns if the "model_routing" field was cleared in this mutation.
func (m *GroupMutation) ModelRoutingCleared() bool {
	_, ok := m.clearedFields[group.FieldModelRouting]
	return ok
}

// ResetModelRouting resets all changes to the "model_routing" field.
func (m *GroupMutation) ResetModelRouting() {
	m.model_routing = nil
	delete(m.clearedFields, group.FieldModelRouting)
}

// SetModelRoutingEnabled sets the "model_routing_enabled" field.
func (m *GroupMutation) SetModelRoutingEnabled(b bool) {
	m.model_routing_enabled = &b
}

// ModelRoutingEnabled returns the value of the "model_routing_enabled" field in the mutation.
func (m *GroupMutation) ModelRoutingEnabled() (r bool, exists bool) {
	v := m.model_routing_enabled
	if v == nil {
		return
	}
	return *v, true
}

// OldModelRoutingEnabled returns the old "model_routing_enabled" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldModelRoutingEnabled(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldModelRoutingEnabled is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldModelRoutingEnabled requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldModelRoutingEnabled: %w", err)
	}
	return oldValue.ModelRoutingEnabled, nil
}

// ResetModelRoutingEnabled resets all changes to the "model_routing_enabled" field.
func (m *GroupMutation) ResetModelRoutingEnabled() {
	m.model_routing_enabled = nil
}

// SetMcpXMLInject sets the "mcp_xml_inject" field.
func (m *GroupMutation) SetMcpXMLInject(b bool) {
	m.mcp_xml_inject = &b
}

// McpXMLInject returns the value of the "mcp_xml_inject" field in the mutation.
func (m *GroupMutation) McpXMLInject() (r bool, exists bool) {
	v := m.mcp_xml_inject
	if v == nil {
		return
	}
	return *v, true
}

// OldMcpXMLInject returns the old "mcp_xml_inject" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldMcpXMLInject(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldMcpXMLInject is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldMcpXMLInject requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldMcpXMLInject: %w", err)
	}
	return oldValue.McpXMLInject, nil
}

// ResetMcpXMLInject resets all changes to the "mcp_xml_inject" field.
func (m *GroupMutation) ResetMcpXMLInject() {
	m.mcp_xml_inject = nil
}

// SetSupportedModelScopes sets the "supported_model_scopes" field.
func (m *GroupMutation) SetSupportedModelScopes(s []string) {
	m.supported_model_scopes = &s
	m.appendsupported_model_scopes = nil
}

// SupportedModelScopes returns the value of the "supported_model_scopes" field in the mutation.
func (m *GroupMutation) SupportedModelScopes() (r []string, exists bool) {
	v := m.supported_model_scopes
	if v == nil {
		return
	}
	return *v, true
}

// OldSupportedModelScopes returns the old "supported_model_scopes" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldSupportedModelScopes(ctx context.Context) (v []string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSupportedModelScopes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSupportedModelScopes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSupportedModelScopes: %w", err)
	}
	return oldValue.SupportedModelScopes, nil
}

// AppendSupportedModelScopes adds s to the "supported_model_scopes" field.
func (m *GroupMutation) AppendSupportedModelScopes(s []string) {
	m.appendsupported_model_scopes = append(m.appendsupported_model_scopes, s...)
}

// AppendedSupportedModelScopes returns the list of values that were appended to the "supported_model_scopes" field in this mutation.
func (m *GroupMutation) AppendedSupportedModelScopes() ([]string, bool) {
	if len(m.appendsupported_model_scopes) == 0 {
		return nil, false
	}
	return m.appendsupported_model_scopes, true
}

// ResetSupportedModelScopes resets all changes to the "supported_model_scopes" field.
func (m *GroupMutation) ResetSupportedModelScopes() {
	m.supported_model_scopes = nil
	m.appendsupported_model_scopes = nil
}

// SetSortOrder sets the "sort_order" field.
func (m *GroupMutation) SetSortOrder(i int) {
	m.sort_order = &i
	m.addsort_order = nil
}

// SortOrder returns the value of the "sort_order" field in the mutation.
func (m *GroupMutation) SortOrder() (r int, exists bool) {
	v := m.sort_order
	if v == nil {
		return
	}
	return *v, true
}

// OldSortOrder returns the old "sort_order" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldSortOrder(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSortOrder is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSortOrder requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSortOrder: %w", err)
	}
	return oldValue.SortOrder, nil
}

// AddSortOrder adds i to the "sort_order" field.
func (m *GroupMutation) AddSortOrder(i int) {
	if m.addsort_order != nil {
		*m.addsort_order += i
	} else {
		m.addsort_order = &i
	}
}

// AddedSortOrder returns the value that was added to the "sort_order" field in this mutation.
func (m *GroupMutation) AddedSortOrder() (r int, exists bool) {
	v := m.addsort_order
	if v == nil {
		return
	}
	return *v, true
}

// ResetSortOrder resets all changes to the "sort_order" field.
func (m *GroupMutation) ResetSortOrder() {
	m.sort_order = nil
	m.addsort_order = nil
}

// SetAllowMessagesDispatch sets the "allow_messages_dispatch" field.
func (m *GroupMutation) SetAllowMessagesDispatch(b bool) {
	m.allow_messages_dispatch = &b
}

// AllowMessagesDispatch returns the value of the "allow_messages_dispatch" field in the mutation.
func (m *GroupMutation) AllowMessagesDispatch() (r bool, exists bool) {
	v := m.allow_messages_dispatch
	if v == nil {
		return
	}
	return *v, true
}

// OldAllowMessagesDispatch returns the old "allow_messages_dispatch" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldAllowMessagesDispatch(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAllowMessagesDispatch is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAllowMessagesDispatch requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAllowMessagesDispatch: %w", err)
	}
	return oldValue.AllowMessagesDispatch, nil
}

// ResetAllowMessagesDispatch resets all changes to the "allow_messages_dispatch" field.
func (m *GroupMutation) ResetAllowMessagesDispatch() {
	m.allow_messages_dispatch = nil
}

// SetRequireOauthOnly sets the "require_oauth_only" field.
func (m *GroupMutation) SetRequireOauthOnly(b bool) {
	m.require_oauth_only = &b
}

// RequireOauthOnly returns the value of the "require_oauth_only" field in the mutation.
func (m *GroupMutation) RequireOauthOnly() (r bool, exists bool) {
	v := m.require_oauth_only
	if v == nil {
		return
	}
	return *v, true
}

// OldRequireOauthOnly returns the old "require_oauth_only" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldRequireOauthOnly(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRequireOauthOnly is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRequireOauthOnly requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRequireOauthOnly: %w", err)
	}
	return oldValue.RequireOauthOnly, nil
}

// ResetRequireOauthOnly resets all changes to the "require_oauth_only" field.
func (m *GroupMutation) ResetRequireOauthOnly() {
	m.require_oauth_only = nil
}

// SetRequirePrivacySet sets the "require_privacy_set" field.
func (m *GroupMutation) SetRequirePrivacySet(b bool) {
	m.require_privacy_set = &b
}

// RequirePrivacySet returns the value of the "require_privacy_set" field in the mutation.
func (m *GroupMutation) RequirePrivacySet() (r bool, exists bool) {
	v := m.require_privacy_set
	if v == nil {
		return
	}
	return *v, true
}

// OldRequirePrivacySet returns the old "require_privacy_set" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldRequirePrivacySet(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRequirePrivacySet is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRequirePrivacySet requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRequirePrivacySet: %w", err)
	}
	return oldValue.RequirePrivacySet, nil
}

// ResetRequirePrivacySet resets all changes to the "require_privacy_set" field.
func (m *GroupMutation) ResetRequirePrivacySet() {
	m.require_privacy_set = nil
}

// SetDefaultMappedModel sets the "default_mapped_model" field.
func (m *GroupMutation) SetDefaultMappedModel(s string) {
	m.default_mapped_model = &s
}

// DefaultMappedModel returns the value of the "default_mapped_model" field in the mutation.
func (m *GroupMutation) DefaultMappedModel() (r string, exists bool) {
	v := m.default_mapped_model
	if v == nil {
		return
	}
	return *v, true
}

// OldDefaultMappedModel returns the old "default_mapped_model" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldDefaultMappedModel(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDefaultMappedModel is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDefaultMappedModel requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDefaultMappedModel: %w", err)
	}
	return oldValue.DefaultMappedModel, nil
}

// ResetDefaultMappedModel resets all changes to the "default_mapped_model" field.
func (m *GroupMutation) ResetDefaultMappedModel() {
	m.default_mapped_model = nil
}

// SetMessagesDispatchModelConfig sets the "messages_dispatch_model_config" field.
func (m *GroupMutation) SetMessagesDispatchModelConfig(damdmc domain.OpenAIMessagesDispatchModelConfig) {
	m.messages_dispatch_model_config = &damdmc
}

// MessagesDispatchModelConfig returns the value of the "messages_dispatch_model_config" field in the mutation.
func (m *GroupMutation) MessagesDispatchModelConfig() (r domain.OpenAIMessagesDispatchModelConfig, exists bool) {
	v := m.messages_dispatch_model_config
	if v == nil {
		return
	}
	return *v, true
}

// OldMessagesDispatchModelConfig returns the old "messages_dispatch_model_config" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldMessagesDispatchModelConfig(ctx context.Context) (v domain.OpenAIMessagesDispatchModelConfig, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldMessagesDispatchModelConfig is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldMessagesDispatchModelConfig requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldMessagesDispatchModelConfig: %w", err)
	}
	return oldValue.MessagesDispatchModelConfig, nil
}

// ResetMessagesDispatchModelConfig resets all changes to the "messages_dispatch_model_config" field.
func (m *GroupMutation) ResetMessagesDispatchModelConfig() {
	m.messages_dispatch_model_config = nil
}

// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by ids.
func (m *GroupMutation) AddAPIKeyIDs(ids ...int64) {
	if m.api_keys == nil {
		m.api_keys = make(map[int64]struct{})
	}
	for i := range ids {
		m.api_keys[ids[i]] = struct{}{}
	}
}

// ClearAPIKeys clears the "api_keys" edge to the APIKey entity.
func (m *GroupMutation) ClearAPIKeys() {
	m.clearedapi_keys = true
}

// APIKeysCleared reports if the "api_keys" edge to the APIKey entity was cleared.
func (m *GroupMutation) APIKeysCleared() bool {
	return m.clearedapi_keys
}

// RemoveAPIKeyIDs removes the "api_keys" edge to the APIKey entity by IDs.
func (m *GroupMutation) RemoveAPIKeyIDs(ids ...int64) {
	if m.removedapi_keys == nil {
		m.removedapi_keys = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.api_keys, ids[i])
		m.removedapi_keys[ids[i]] = struct{}{}
	}
}

// RemovedAPIKeys returns the removed IDs of the "api_keys" edge to the APIKey entity.
func (m *GroupMutation) RemovedAPIKeysIDs() (ids []int64) {
	for id := range m.removedapi_keys {
		ids = append(ids, id)
	}
	return
}

// APIKeysIDs returns the "api_keys" edge IDs in the mutation.
func (m *GroupMutation) APIKeysIDs() (ids []int64) {
	for id := range m.api_keys {
		ids = append(ids, id)
	}
	return
}

// ResetAPIKeys resets all changes to the "api_keys" edge.
func (m *GroupMutation) ResetAPIKeys() {
	m.api_keys = nil
	m.clearedapi_keys = false
	m.removedapi_keys = nil
}

// AddRedeemCodeIDs adds the "redeem_codes" edge to the RedeemCode entity by ids.
func (m *GroupMutation) AddRedeemCodeIDs(ids ...int64) {
	if m.redeem_codes == nil {
		m.redeem_codes = make(map[int64]struct{})
	}
	for i := range ids {
		m.redeem_codes[ids[i]] = struct{}{}
	}
}

// ClearRedeemCodes clears the "redeem_codes" edge to the RedeemCode entity.
func (m *GroupMutation) ClearRedeemCodes() {
	m.clearedredeem_codes = true
}

// RedeemCodesCleared reports if the "redeem_codes" edge to the RedeemCode entity was cleared.
func (m *GroupMutation) RedeemCodesCleared() bool {
	return m.clearedredeem_codes
}

// RemoveRedeemCodeIDs removes the "redeem_codes" edge to the RedeemCode entity by IDs.
func (m *GroupMutation) RemoveRedeemCodeIDs(ids ...int64) {
	if m.removedredeem_codes == nil {
		m.removedredeem_codes = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.redeem_codes, ids[i])
		m.removedredeem_codes[ids[i]] = struct{}{}
	}
}

// RemovedRedeemCodes returns the removed IDs of the "redeem_codes" edge to the RedeemCode entity.
func (m *GroupMutation) RemovedRedeemCodesIDs() (ids []int64) {
	for id := range m.removedredeem_codes {
		ids = append(ids, id)
	}
	return
}

// RedeemCodesIDs returns the "redeem_codes" edge IDs in the mutation.
func (m *GroupMutation) RedeemCodesIDs() (ids []int64) {
	for id := range m.redeem_codes {
		ids = append(ids, id)
	}
	return
}

// ResetRedeemCodes resets all changes to the "redeem_codes" edge.
func (m *GroupMutation) ResetRedeemCodes() {
	m.redeem_codes = nil
	m.clearedredeem_codes = false
	m.removedredeem_codes = nil
}

// AddSubscriptionIDs adds the "subscriptions" edge to the UserSubscription entity by ids.
func (m *GroupMutation) AddSubscriptionIDs(ids ...int64) {
	if m.subscriptions == nil {
		m.subscriptions = make(map[int64]struct{})
	}
	for i := range ids {
		m.subscriptions[ids[i]] = struct{}{}
	}
}

// ClearSubscriptions clears the "subscriptions" edge to the UserSubscription entity.
func (m *GroupMutation) ClearSubscriptions() {
	m.clearedsubscriptions = true
}

// SubscriptionsCleared reports if the "subscriptions" edge to the UserSubscription entity was cleared.
func (m *GroupMutation) SubscriptionsCleared() bool {
	return m.clearedsubscriptions
}

// RemoveSubscriptionIDs removes the "subscriptions" edge to the UserSubscription entity by IDs.
func (m *GroupMutation) RemoveSubscriptionIDs(ids ...int64) {
	if m.removedsubscriptions == nil {
		m.removedsubscriptions = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.subscriptions, ids[i])
		m.removedsubscriptions[ids[i]] = struct{}{}
	}
}

// RemovedSubscriptions returns the removed IDs of the "subscriptions" edge to the UserSubscription entity.
func (m *GroupMutation) RemovedSubscriptionsIDs() (ids []int64) {
	for id := range m.removedsubscriptions {
		ids = append(ids, id)
	}
	return
}

// SubscriptionsIDs returns the "subscriptions" edge IDs in the mutation.
func (m *GroupMutation) SubscriptionsIDs() (ids []int64) {
	for id := range m.subscriptions {
		ids = append(ids, id)
	}
	return
}

// ResetSubscriptions resets all changes to the "subscriptions" edge.
func (m *GroupMutation) ResetSubscriptions() {
	m.subscriptions = nil
	m.clearedsubscriptions = false
	m.removedsubscriptions = nil
}

// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by ids.
func (m *GroupMutation) AddUsageLogIDs(ids ...int64) {
	if m.usage_logs == nil {
		m.usage_logs = make(map[int64]struct{})
	}
	for i := range ids {
		m.usage_logs[ids[i]] = struct{}{}
	}
}

// ClearUsageLogs clears the "usage_logs" edge to the UsageLog entity.
func (m *GroupMutation) ClearUsageLogs() {
	m.clearedusage_logs = true
}

// UsageLogsCleared reports if the "usage_logs" edge to the UsageLog entity was cleared.
func (m *GroupMutation) UsageLogsCleared() bool {
	return m.clearedusage_logs
}

// RemoveUsageLogIDs removes the "usage_logs" edge to the UsageLog entity by IDs.
func (m *GroupMutation) RemoveUsageLogIDs(ids ...int64) {
	if m.removedusage_logs == nil {
		m.removedusage_logs = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.usage_logs, ids[i])
		m.removedusage_logs[ids[i]] = struct{}{}
	}
}

// RemovedUsageLogs returns the removed IDs of the "usage_logs" edge to the UsageLog entity.
func (m *GroupMutation) RemovedUsageLogsIDs() (ids []int64) {
	for id := range m.removedusage_logs {
		ids = append(ids, id)
	}
	return
}

// UsageLogsIDs returns the "usage_logs" edge IDs in the mutation.
func (m *GroupMutation) UsageLogsIDs() (ids []int64) {
	for id := range m.usage_logs {
		ids = append(ids, id)
	}
	return
}

// ResetUsageLogs resets all changes to the "usage_logs" edge.
func (m *GroupMutation) ResetUsageLogs() {
	m.usage_logs = nil
	m.clearedusage_logs = false
	m.removedusage_logs = nil
}

// AddAccountIDs adds the "accounts" edge to the Account entity by ids.
func (m *GroupMutation) AddAccountIDs(ids ...int64) {
	if m.accounts == nil {
		m.accounts = make(map[int64]struct{})
	}
	for i := range ids {
		m.accounts[ids[i]] = struct{}{}
	}
}

// ClearAccounts clears the "accounts" edge to the Account entity.
func (m *GroupMutation) ClearAccounts() {
	m.clearedaccounts = true
}

// AccountsCleared reports if the "accounts" edge to the Account entity was cleared.
func (m *GroupMutation) AccountsCleared() bool {
	return m.clearedaccounts
}

// RemoveAccountIDs removes the "accounts" edge to the Account entity by IDs.
func (m *GroupMutation) RemoveAccountIDs(ids ...int64) {
	if m.removedaccounts == nil {
		m.removedaccounts = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.accounts, ids[i])
		m.removedaccounts[ids[i]] = struct{}{}
	}
}

// RemovedAccounts returns the removed IDs of the "accounts" edge to the Account entity.
func (m *GroupMutation) RemovedAccountsIDs() (ids []int64) {
	for id := range m.removedaccounts {
		ids = append(ids, id)
	}
	return
}

// AccountsIDs returns the "accounts" edge IDs in the mutation.
func (m *GroupMutation) AccountsIDs() (ids []int64) {
	for id := range m.accounts {
		ids = append(ids, id)
	}
	return
}

// ResetAccounts resets all changes to the "accounts" edge.
func (m *GroupMutation) ResetAccounts() {
	m.accounts = nil
	m.clearedaccounts = false
	m.removedaccounts = nil
}

// AddAllowedUserIDs adds the "allowed_users" edge to the User entity by ids.
func (m *GroupMutation) AddAllowedUserIDs(ids ...int64) {
	if m.allowed_users == nil {
		m.allowed_users = make(map[int64]struct{})
	}
	for i := range ids {
		m.allowed_users[ids[i]] = struct{}{}
	}
}

// ClearAllowedUsers clears the "allowed_users" edge to the User entity.
func (m *GroupMutation) ClearAllowedUsers() {
	m.clearedallowed_users = true
}

// AllowedUsersCleared reports if the "allowed_users" edge to the User entity was cleared.
func (m *GroupMutation) AllowedUsersCleared() bool {
	return m.clearedallowed_users
}

// RemoveAllowedUserIDs removes the "allowed_users" edge to the User entity by IDs.
func (m *GroupMutation) RemoveAllowedUserIDs(ids ...int64) {
	if m.removedallowed_users == nil {
		m.removedallowed_users = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.allowed_users, ids[i])
		m.removedallowed_users[ids[i]] = struct{}{}
	}
}

// RemovedAllowedUsers returns the removed IDs of the "allowed_users" edge to the User entity.
func (m *GroupMutation) RemovedAllowedUsersIDs() (ids []int64) {
	for id := range m.removedallowed_users {
		ids = append(ids, id)
	}
	return
}

// AllowedUsersIDs returns the "allowed_users" edge IDs in the mutation.
func (m *GroupMutation) AllowedUsersIDs() (ids []int64) {
	for id := range m.allowed_users {
		ids = append(ids, id)
	}
	return
}

// ResetAllowedUsers resets all changes to the "allowed_users" edge.
func (m *GroupMutation) ResetAllowedUsers() {
	m.allowed_users = nil
	m.clearedallowed_users = false
	m.removedallowed_users = nil
}

// Where appends a list predicates to the GroupMutation builder.
func (m *GroupMutation) Where(ps ...predicate.Group) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the GroupMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *GroupMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.Group, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *GroupMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *GroupMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (Group).
func (m *GroupMutation) 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 *GroupMutation) Fields() []string {
	fields := make([]string, 0, 30)
	if m.created_at != nil {
		fields = append(fields, group.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, group.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, group.FieldDeletedAt)
	}
	if m.name != nil {
		fields = append(fields, group.FieldName)
	}
	if m.description != nil {
		fields = append(fields, group.FieldDescription)
	}
	if m.rate_multiplier != nil {
		fields = append(fields, group.FieldRateMultiplier)
	}
	if m.is_exclusive != nil {
		fields = append(fields, group.FieldIsExclusive)
	}
	if m.status != nil {
		fields = append(fields, group.FieldStatus)
	}
	if m.platform != nil {
		fields = append(fields, group.FieldPlatform)
	}
	if m.subscription_type != nil {
		fields = append(fields, group.FieldSubscriptionType)
	}
	if m.daily_limit_usd != nil {
		fields = append(fields, group.FieldDailyLimitUsd)
	}
	if m.weekly_limit_usd != nil {
		fields = append(fields, group.FieldWeeklyLimitUsd)
	}
	if m.monthly_limit_usd != nil {
		fields = append(fields, group.FieldMonthlyLimitUsd)
	}
	if m.default_validity_days != nil {
		fields = append(fields, group.FieldDefaultValidityDays)
	}
	if m.image_price_1k != nil {
		fields = append(fields, group.FieldImagePrice1k)
	}
	if m.image_price_2k != nil {
		fields = append(fields, group.FieldImagePrice2k)
	}
	if m.image_price_4k != nil {
		fields = append(fields, group.FieldImagePrice4k)
	}
	if m.claude_code_only != nil {
		fields = append(fields, group.FieldClaudeCodeOnly)
	}
	if m.fallback_group_id != nil {
		fields = append(fields, group.FieldFallbackGroupID)
	}
	if m.fallback_group_id_on_invalid_request != nil {
		fields = append(fields, group.FieldFallbackGroupIDOnInvalidRequest)
	}
	if m.model_routing != nil {
		fields = append(fields, group.FieldModelRouting)
	}
	if m.model_routing_enabled != nil {
		fields = append(fields, group.FieldModelRoutingEnabled)
	}
	if m.mcp_xml_inject != nil {
		fields = append(fields, group.FieldMcpXMLInject)
	}
	if m.supported_model_scopes != nil {
		fields = append(fields, group.FieldSupportedModelScopes)
	}
	if m.sort_order != nil {
		fields = append(fields, group.FieldSortOrder)
	}
	if m.allow_messages_dispatch != nil {
		fields = append(fields, group.FieldAllowMessagesDispatch)
	}
	if m.require_oauth_only != nil {
		fields = append(fields, group.FieldRequireOauthOnly)
	}
	if m.require_privacy_set != nil {
		fields = append(fields, group.FieldRequirePrivacySet)
	}
	if m.default_mapped_model != nil {
		fields = append(fields, group.FieldDefaultMappedModel)
	}
	if m.messages_dispatch_model_config != nil {
		fields = append(fields, group.FieldMessagesDispatchModelConfig)
	}
	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 *GroupMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case group.FieldCreatedAt:
		return m.CreatedAt()
	case group.FieldUpdatedAt:
		return m.UpdatedAt()
	case group.FieldDeletedAt:
		return m.DeletedAt()
	case group.FieldName:
		return m.Name()
	case group.FieldDescription:
		return m.Description()
	case group.FieldRateMultiplier:
		return m.RateMultiplier()
	case group.FieldIsExclusive:
		return m.IsExclusive()
	case group.FieldStatus:
		return m.Status()
	case group.FieldPlatform:
		return m.Platform()
	case group.FieldSubscriptionType:
		return m.SubscriptionType()
	case group.FieldDailyLimitUsd:
		return m.DailyLimitUsd()
	case group.FieldWeeklyLimitUsd:
		return m.WeeklyLimitUsd()
	case group.FieldMonthlyLimitUsd:
		return m.MonthlyLimitUsd()
	case group.FieldDefaultValidityDays:
		return m.DefaultValidityDays()
	case group.FieldImagePrice1k:
		return m.ImagePrice1k()
	case group.FieldImagePrice2k:
		return m.ImagePrice2k()
	case group.FieldImagePrice4k:
		return m.ImagePrice4k()
	case group.FieldClaudeCodeOnly:
		return m.ClaudeCodeOnly()
	case group.FieldFallbackGroupID:
		return m.FallbackGroupID()
	case group.FieldFallbackGroupIDOnInvalidRequest:
		return m.FallbackGroupIDOnInvalidRequest()
	case group.FieldModelRouting:
		return m.ModelRouting()
	case group.FieldModelRoutingEnabled:
		return m.ModelRoutingEnabled()
	case group.FieldMcpXMLInject:
		return m.McpXMLInject()
	case group.FieldSupportedModelScopes:
		return m.SupportedModelScopes()
	case group.FieldSortOrder:
		return m.SortOrder()
	case group.FieldAllowMessagesDispatch:
		return m.AllowMessagesDispatch()
	case group.FieldRequireOauthOnly:
		return m.RequireOauthOnly()
	case group.FieldRequirePrivacySet:
		return m.RequirePrivacySet()
	case group.FieldDefaultMappedModel:
		return m.DefaultMappedModel()
	case group.FieldMessagesDispatchModelConfig:
		return m.MessagesDispatchModelConfig()
	}
	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 *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case group.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case group.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case group.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case group.FieldName:
		return m.OldName(ctx)
	case group.FieldDescription:
		return m.OldDescription(ctx)
	case group.FieldRateMultiplier:
		return m.OldRateMultiplier(ctx)
	case group.FieldIsExclusive:
		return m.OldIsExclusive(ctx)
	case group.FieldStatus:
		return m.OldStatus(ctx)
	case group.FieldPlatform:
		return m.OldPlatform(ctx)
	case group.FieldSubscriptionType:
		return m.OldSubscriptionType(ctx)
	case group.FieldDailyLimitUsd:
		return m.OldDailyLimitUsd(ctx)
	case group.FieldWeeklyLimitUsd:
		return m.OldWeeklyLimitUsd(ctx)
	case group.FieldMonthlyLimitUsd:
		return m.OldMonthlyLimitUsd(ctx)
	case group.FieldDefaultValidityDays:
		return m.OldDefaultValidityDays(ctx)
	case group.FieldImagePrice1k:
		return m.OldImagePrice1k(ctx)
	case group.FieldImagePrice2k:
		return m.OldImagePrice2k(ctx)
	case group.FieldImagePrice4k:
		return m.OldImagePrice4k(ctx)
	case group.FieldClaudeCodeOnly:
		return m.OldClaudeCodeOnly(ctx)
	case group.FieldFallbackGroupID:
		return m.OldFallbackGroupID(ctx)
	case group.FieldFallbackGroupIDOnInvalidRequest:
		return m.OldFallbackGroupIDOnInvalidRequest(ctx)
	case group.FieldModelRouting:
		return m.OldModelRouting(ctx)
	case group.FieldModelRoutingEnabled:
		return m.OldModelRoutingEnabled(ctx)
	case group.FieldMcpXMLInject:
		return m.OldMcpXMLInject(ctx)
	case group.FieldSupportedModelScopes:
		return m.OldSupportedModelScopes(ctx)
	case group.FieldSortOrder:
		return m.OldSortOrder(ctx)
	case group.FieldAllowMessagesDispatch:
		return m.OldAllowMessagesDispatch(ctx)
	case group.FieldRequireOauthOnly:
		return m.OldRequireOauthOnly(ctx)
	case group.FieldRequirePrivacySet:
		return m.OldRequirePrivacySet(ctx)
	case group.FieldDefaultMappedModel:
		return m.OldDefaultMappedModel(ctx)
	case group.FieldMessagesDispatchModelConfig:
		return m.OldMessagesDispatchModelConfig(ctx)
	}
	return nil, fmt.Errorf("unknown Group 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 *GroupMutation) SetField(name string, value ent.Value) error {
	switch name {
	case group.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 group.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 group.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 group.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case group.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case group.FieldRateMultiplier:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRateMultiplier(v)
		return nil
	case group.FieldIsExclusive:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIsExclusive(v)
		return nil
	case group.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case group.FieldPlatform:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPlatform(v)
		return nil
	case group.FieldSubscriptionType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSubscriptionType(v)
		return nil
	case group.FieldDailyLimitUsd:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDailyLimitUsd(v)
		return nil
	case group.FieldWeeklyLimitUsd:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWeeklyLimitUsd(v)
		return nil
	case group.FieldMonthlyLimitUsd:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMonthlyLimitUsd(v)
		return nil
	case group.FieldDefaultValidityDays:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDefaultValidityDays(v)
		return nil
	case group.FieldImagePrice1k:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetImagePrice1k(v)
		return nil
	case group.FieldImagePrice2k:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetImagePrice2k(v)
		return nil
	case group.FieldImagePrice4k:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetImagePrice4k(v)
		return nil
	case group.FieldClaudeCodeOnly:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetClaudeCodeOnly(v)
		return nil
	case group.FieldFallbackGroupID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFallbackGroupID(v)
		return nil
	case group.FieldFallbackGroupIDOnInvalidRequest:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFallbackGroupIDOnInvalidRequest(v)
		return nil
	case group.FieldModelRouting:
		v, ok := value.(map[string][]int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetModelRouting(v)
		return nil
	case group.FieldModelRoutingEnabled:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetModelRoutingEnabled(v)
		return nil
	case group.FieldMcpXMLInject:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMcpXMLInject(v)
		return nil
	case group.FieldSupportedModelScopes:
		v, ok := value.([]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSupportedModelScopes(v)
		return nil
	case group.FieldSortOrder:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSortOrder(v)
		return nil
	case group.FieldAllowMessagesDispatch:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAllowMessagesDispatch(v)
		return nil
	case group.FieldRequireOauthOnly:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRequireOauthOnly(v)
		return nil
	case group.FieldRequirePrivacySet:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRequirePrivacySet(v)
		return nil
	case group.FieldDefaultMappedModel:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDefaultMappedModel(v)
		return nil
	case group.FieldMessagesDispatchModelConfig:
		v, ok := value.(domain.OpenAIMessagesDispatchModelConfig)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMessagesDispatchModelConfig(v)
		return nil
	}
	return fmt.Errorf("unknown Group field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *GroupMutation) AddedFields() []string {
	var fields []string
	if m.addrate_multiplier != nil {
		fields = append(fields, group.FieldRateMultiplier)
	}
	if m.adddaily_limit_usd != nil {
		fields = append(fields, group.FieldDailyLimitUsd)
	}
	if m.addweekly_limit_usd != nil {
		fields = append(fields, group.FieldWeeklyLimitUsd)
	}
	if m.addmonthly_limit_usd != nil {
		fields = append(fields, group.FieldMonthlyLimitUsd)
	}
	if m.adddefault_validity_days != nil {
		fields = append(fields, group.FieldDefaultValidityDays)
	}
	if m.addimage_price_1k != nil {
		fields = append(fields, group.FieldImagePrice1k)
	}
	if m.addimage_price_2k != nil {
		fields = append(fields, group.FieldImagePrice2k)
	}
	if m.addimage_price_4k != nil {
		fields = append(fields, group.FieldImagePrice4k)
	}
	if m.addfallback_group_id != nil {
		fields = append(fields, group.FieldFallbackGroupID)
	}
	if m.addfallback_group_id_on_invalid_request != nil {
		fields = append(fields, group.FieldFallbackGroupIDOnInvalidRequest)
	}
	if m.addsort_order != nil {
		fields = append(fields, group.FieldSortOrder)
	}
	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 *GroupMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case group.FieldRateMultiplier:
		return m.AddedRateMultiplier()
	case group.FieldDailyLimitUsd:
		return m.AddedDailyLimitUsd()
	case group.FieldWeeklyLimitUsd:
		return m.AddedWeeklyLimitUsd()
	case group.FieldMonthlyLimitUsd:
		return m.AddedMonthlyLimitUsd()
	case group.FieldDefaultValidityDays:
		return m.AddedDefaultValidityDays()
	case group.FieldImagePrice1k:
		return m.AddedImagePrice1k()
	case group.FieldImagePrice2k:
		return m.AddedImagePrice2k()
	case group.FieldImagePrice4k:
		return m.AddedImagePrice4k()
	case group.FieldFallbackGroupID:
		return m.AddedFallbackGroupID()
	case group.FieldFallbackGroupIDOnInvalidRequest:
		return m.AddedFallbackGroupIDOnInvalidRequest()
	case group.FieldSortOrder:
		return m.AddedSortOrder()
	}
	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 *GroupMutation) AddField(name string, value ent.Value) error {
	switch name {
	case group.FieldRateMultiplier:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddRateMultiplier(v)
		return nil
	case group.FieldDailyLimitUsd:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddDailyLimitUsd(v)
		return nil
	case group.FieldWeeklyLimitUsd:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddWeeklyLimitUsd(v)
		return nil
	case group.FieldMonthlyLimitUsd:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddMonthlyLimitUsd(v)
		return nil
	case group.FieldDefaultValidityDays:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddDefaultValidityDays(v)
		return nil
	case group.FieldImagePrice1k:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddImagePrice1k(v)
		return nil
	case group.FieldImagePrice2k:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddImagePrice2k(v)
		return nil
	case group.FieldImagePrice4k:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddImagePrice4k(v)
		return nil
	case group.FieldFallbackGroupID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddFallbackGroupID(v)
		return nil
	case group.FieldFallbackGroupIDOnInvalidRequest:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddFallbackGroupIDOnInvalidRequest(v)
		return nil
	case group.FieldSortOrder:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddSortOrder(v)
		return nil
	}
	return fmt.Errorf("unknown Group numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *GroupMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(group.FieldDeletedAt) {
		fields = append(fields, group.FieldDeletedAt)
	}
	if m.FieldCleared(group.FieldDescription) {
		fields = append(fields, group.FieldDescription)
	}
	if m.FieldCleared(group.FieldDailyLimitUsd) {
		fields = append(fields, group.FieldDailyLimitUsd)
	}
	if m.FieldCleared(group.FieldWeeklyLimitUsd) {
		fields = append(fields, group.FieldWeeklyLimitUsd)
	}
	if m.FieldCleared(group.FieldMonthlyLimitUsd) {
		fields = append(fields, group.FieldMonthlyLimitUsd)
	}
	if m.FieldCleared(group.FieldImagePrice1k) {
		fields = append(fields, group.FieldImagePrice1k)
	}
	if m.FieldCleared(group.FieldImagePrice2k) {
		fields = append(fields, group.FieldImagePrice2k)
	}
	if m.FieldCleared(group.FieldImagePrice4k) {
		fields = append(fields, group.FieldImagePrice4k)
	}
	if m.FieldCleared(group.FieldFallbackGroupID) {
		fields = append(fields, group.FieldFallbackGroupID)
	}
	if m.FieldCleared(group.FieldFallbackGroupIDOnInvalidRequest) {
		fields = append(fields, group.FieldFallbackGroupIDOnInvalidRequest)
	}
	if m.FieldCleared(group.FieldModelRouting) {
		fields = append(fields, group.FieldModelRouting)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *GroupMutation) 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 *GroupMutation) ClearField(name string) error {
	switch name {
	case group.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	case group.FieldDescription:
		m.ClearDescription()
		return nil
	case group.FieldDailyLimitUsd:
		m.ClearDailyLimitUsd()
		return nil
	case group.FieldWeeklyLimitUsd:
		m.ClearWeeklyLimitUsd()
		return nil
	case group.FieldMonthlyLimitUsd:
		m.ClearMonthlyLimitUsd()
		return nil
	case group.FieldImagePrice1k:
		m.ClearImagePrice1k()
		return nil
	case group.FieldImagePrice2k:
		m.ClearImagePrice2k()
		return nil
	case group.FieldImagePrice4k:
		m.ClearImagePrice4k()
		return nil
	case group.FieldFallbackGroupID:
		m.ClearFallbackGroupID()
		return nil
	case group.FieldFallbackGroupIDOnInvalidRequest:
		m.ClearFallbackGroupIDOnInvalidRequest()
		return nil
	case group.FieldModelRouting:
		m.ClearModelRouting()
		return nil
	}
	return fmt.Errorf("unknown Group 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 *GroupMutation) ResetField(name string) error {
	switch name {
	case group.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case group.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case group.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case group.FieldName:
		m.ResetName()
		return nil
	case group.FieldDescription:
		m.ResetDescription()
		return nil
	case group.FieldRateMultiplier:
		m.ResetRateMultiplier()
		return nil
	case group.FieldIsExclusive:
		m.ResetIsExclusive()
		return nil
	case group.FieldStatus:
		m.ResetStatus()
		return nil
	case group.FieldPlatform:
		m.ResetPlatform()
		return nil
	case group.FieldSubscriptionType:
		m.ResetSubscriptionType()
		return nil
	case group.FieldDailyLimitUsd:
		m.ResetDailyLimitUsd()
		return nil
	case group.FieldWeeklyLimitUsd:
		m.ResetWeeklyLimitUsd()
		return nil
	case group.FieldMonthlyLimitUsd:
		m.ResetMonthlyLimitUsd()
		return nil
	case group.FieldDefaultValidityDays:
		m.ResetDefaultValidityDays()
		return nil
	case group.FieldImagePrice1k:
		m.ResetImagePrice1k()
		return nil
	case group.FieldImagePrice2k:
		m.ResetImagePrice2k()
		return nil
	case group.FieldImagePrice4k:
		m.ResetImagePrice4k()
		return nil
	case group.FieldClaudeCodeOnly:
		m.ResetClaudeCodeOnly()
		return nil
	case group.FieldFallbackGroupID:
		m.ResetFallbackGroupID()
		return nil
	case group.FieldFallbackGroupIDOnInvalidRequest:
		m.ResetFallbackGroupIDOnInvalidRequest()
		return nil
	case group.FieldModelRouting:
		m.ResetModelRouting()
		return nil
	case group.FieldModelRoutingEnabled:
		m.ResetModelRoutingEnabled()
		return nil
	case group.FieldMcpXMLInject:
		m.ResetMcpXMLInject()
		return nil
	case group.FieldSupportedModelScopes:
		m.ResetSupportedModelScopes()
		return nil
	case group.FieldSortOrder:
		m.ResetSortOrder()
		return nil
	case group.FieldAllowMessagesDispatch:
		m.ResetAllowMessagesDispatch()
		return nil
	case group.FieldRequireOauthOnly:
		m.ResetRequireOauthOnly()
		return nil
	case group.FieldRequirePrivacySet:
		m.ResetRequirePrivacySet()
		return nil
	case group.FieldDefaultMappedModel:
		m.ResetDefaultMappedModel()
		return nil
	case group.FieldMessagesDispatchModelConfig:
		m.ResetMessagesDispatchModelConfig()
		return nil
	}
	return fmt.Errorf("unknown Group field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *GroupMutation) AddedEdges() []string {
	edges := make([]string, 0, 6)
	if m.api_keys != nil {
		edges = append(edges, group.EdgeAPIKeys)
	}
	if m.redeem_codes != nil {
		edges = append(edges, group.EdgeRedeemCodes)
	}
	if m.subscriptions != nil {
		edges = append(edges, group.EdgeSubscriptions)
	}
	if m.usage_logs != nil {
		edges = append(edges, group.EdgeUsageLogs)
	}
	if m.accounts != nil {
		edges = append(edges, group.EdgeAccounts)
	}
	if m.allowed_users != nil {
		edges = append(edges, group.EdgeAllowedUsers)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *GroupMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case group.EdgeAPIKeys:
		ids := make([]ent.Value, 0, len(m.api_keys))
		for id := range m.api_keys {
			ids = append(ids, id)
		}
		return ids
	case group.EdgeRedeemCodes:
		ids := make([]ent.Value, 0, len(m.redeem_codes))
		for id := range m.redeem_codes {
			ids = append(ids, id)
		}
		return ids
	case group.EdgeSubscriptions:
		ids := make([]ent.Value, 0, len(m.subscriptions))
		for id := range m.subscriptions {
			ids = append(ids, id)
		}
		return ids
	case group.EdgeUsageLogs:
		ids := make([]ent.Value, 0, len(m.usage_logs))
		for id := range m.usage_logs {
			ids = append(ids, id)
		}
		return ids
	case group.EdgeAccounts:
		ids := make([]ent.Value, 0, len(m.accounts))
		for id := range m.accounts {
			ids = append(ids, id)
		}
		return ids
	case group.EdgeAllowedUsers:
		ids := make([]ent.Value, 0, len(m.allowed_users))
		for id := range m.allowed_users {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *GroupMutation) RemovedEdges() []string {
	edges := make([]string, 0, 6)
	if m.removedapi_keys != nil {
		edges = append(edges, group.EdgeAPIKeys)
	}
	if m.removedredeem_codes != nil {
		edges = append(edges, group.EdgeRedeemCodes)
	}
	if m.removedsubscriptions != nil {
		edges = append(edges, group.EdgeSubscriptions)
	}
	if m.removedusage_logs != nil {
		edges = append(edges, group.EdgeUsageLogs)
	}
	if m.removedaccounts != nil {
		edges = append(edges, group.EdgeAccounts)
	}
	if m.removedallowed_users != nil {
		edges = append(edges, group.EdgeAllowedUsers)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *GroupMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case group.EdgeAPIKeys:
		ids := make([]ent.Value, 0, len(m.removedapi_keys))
		for id := range m.removedapi_keys {
			ids = append(ids, id)
		}
		return ids
	case group.EdgeRedeemCodes:
		ids := make([]ent.Value, 0, len(m.removedredeem_codes))
		for id := range m.removedredeem_codes {
			ids = append(ids, id)
		}
		return ids
	case group.EdgeSubscriptions:
		ids := make([]ent.Value, 0, len(m.removedsubscriptions))
		for id := range m.removedsubscriptions {
			ids = append(ids, id)
		}
		return ids
	case group.EdgeUsageLogs:
		ids := make([]ent.Value, 0, len(m.removedusage_logs))
		for id := range m.removedusage_logs {
			ids = append(ids, id)
		}
		return ids
	case group.EdgeAccounts:
		ids := make([]ent.Value, 0, len(m.removedaccounts))
		for id := range m.removedaccounts {
			ids = append(ids, id)
		}
		return ids
	case group.EdgeAllowedUsers:
		ids := make([]ent.Value, 0, len(m.removedallowed_users))
		for id := range m.removedallowed_users {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *GroupMutation) ClearedEdges() []string {
	edges := make([]string, 0, 6)
	if m.clearedapi_keys {
		edges = append(edges, group.EdgeAPIKeys)
	}
	if m.clearedredeem_codes {
		edges = append(edges, group.EdgeRedeemCodes)
	}
	if m.clearedsubscriptions {
		edges = append(edges, group.EdgeSubscriptions)
	}
	if m.clearedusage_logs {
		edges = append(edges, group.EdgeUsageLogs)
	}
	if m.clearedaccounts {
		edges = append(edges, group.EdgeAccounts)
	}
	if m.clearedallowed_users {
		edges = append(edges, group.EdgeAllowedUsers)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *GroupMutation) EdgeCleared(name string) bool {
	switch name {
	case group.EdgeAPIKeys:
		return m.clearedapi_keys
	case group.EdgeRedeemCodes:
		return m.clearedredeem_codes
	case group.EdgeSubscriptions:
		return m.clearedsubscriptions
	case group.EdgeUsageLogs:
		return m.clearedusage_logs
	case group.EdgeAccounts:
		return m.clearedaccounts
	case group.EdgeAllowedUsers:
		return m.clearedallowed_users
	}
	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 *GroupMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown Group 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 *GroupMutation) ResetEdge(name string) error {
	switch name {
	case group.EdgeAPIKeys:
		m.ResetAPIKeys()
		return nil
	case group.EdgeRedeemCodes:
		m.ResetRedeemCodes()
		return nil
	case group.EdgeSubscriptions:
		m.ResetSubscriptions()
		return nil
	case group.EdgeUsageLogs:
		m.ResetUsageLogs()
		return nil
	case group.EdgeAccounts:
		m.ResetAccounts()
		return nil
	case group.EdgeAllowedUsers:
		m.ResetAllowedUsers()
		return nil
	}
	return fmt.Errorf("unknown Group edge %s", name)
}

// IdempotencyRecordMutation represents an operation that mutates the IdempotencyRecord nodes in the graph.
type IdempotencyRecordMutation struct {
	config
	op                   Op
	typ                  string
	id                   *int64
	created_at           *time.Time
	updated_at           *time.Time
	scope                *string
	idempotency_key_hash *string
	request_fingerprint  *string
	status               *string
	response_status      *int
	addresponse_status   *int
	response_body        *string
	error_reason         *string
	locked_until         *time.Time
	expires_at           *time.Time
	clearedFields        map[string]struct{}
	done                 bool
	oldValue             func(context.Context) (*IdempotencyRecord, error)
	predicates           []predicate.IdempotencyRecord
}

var _ ent.Mutation = (*IdempotencyRecordMutation)(nil)

// idempotencyrecordOption allows management of the mutation configuration using functional options.
type idempotencyrecordOption func(*IdempotencyRecordMutation)

// newIdempotencyRecordMutation creates new mutation for the IdempotencyRecord entity.
func newIdempotencyRecordMutation(c config, op Op, opts ...idempotencyrecordOption) *IdempotencyRecordMutation {
	m := &IdempotencyRecordMutation{
		config:        c,
		op:            op,
		typ:           TypeIdempotencyRecord,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withIdempotencyRecordID sets the ID field of the mutation.
func withIdempotencyRecordID(id int64) idempotencyrecordOption {
	return func(m *IdempotencyRecordMutation) {
		var (
			err   error
			once  sync.Once
			value *IdempotencyRecord
		)
		m.oldValue = func(ctx context.Context) (*IdempotencyRecord, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().IdempotencyRecord.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withIdempotencyRecord sets the old IdempotencyRecord of the mutation.
func withIdempotencyRecord(node *IdempotencyRecord) idempotencyrecordOption {
	return func(m *IdempotencyRecordMutation) {
		m.oldValue = func(context.Context) (*IdempotencyRecord, 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 IdempotencyRecordMutation) 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 IdempotencyRecordMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *IdempotencyRecordMutation) ID() (id int64, 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 *IdempotencyRecordMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().IdempotencyRecord.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *IdempotencyRecordMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *IdempotencyRecordMutation) 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 IdempotencyRecord entity.
// If the IdempotencyRecord object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdempotencyRecordMutation) 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 *IdempotencyRecordMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *IdempotencyRecordMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *IdempotencyRecordMutation) 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 IdempotencyRecord entity.
// If the IdempotencyRecord object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdempotencyRecordMutation) 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 *IdempotencyRecordMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetScope sets the "scope" field.
func (m *IdempotencyRecordMutation) SetScope(s string) {
	m.scope = &s
}

// Scope returns the value of the "scope" field in the mutation.
func (m *IdempotencyRecordMutation) Scope() (r string, exists bool) {
	v := m.scope
	if v == nil {
		return
	}
	return *v, true
}

// OldScope returns the old "scope" field's value of the IdempotencyRecord entity.
// If the IdempotencyRecord object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdempotencyRecordMutation) OldScope(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldScope is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldScope requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldScope: %w", err)
	}
	return oldValue.Scope, nil
}

// ResetScope resets all changes to the "scope" field.
func (m *IdempotencyRecordMutation) ResetScope() {
	m.scope = nil
}

// SetIdempotencyKeyHash sets the "idempotency_key_hash" field.
func (m *IdempotencyRecordMutation) SetIdempotencyKeyHash(s string) {
	m.idempotency_key_hash = &s
}

// IdempotencyKeyHash returns the value of the "idempotency_key_hash" field in the mutation.
func (m *IdempotencyRecordMutation) IdempotencyKeyHash() (r string, exists bool) {
	v := m.idempotency_key_hash
	if v == nil {
		return
	}
	return *v, true
}

// OldIdempotencyKeyHash returns the old "idempotency_key_hash" field's value of the IdempotencyRecord entity.
// If the IdempotencyRecord object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdempotencyRecordMutation) OldIdempotencyKeyHash(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldIdempotencyKeyHash is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldIdempotencyKeyHash requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldIdempotencyKeyHash: %w", err)
	}
	return oldValue.IdempotencyKeyHash, nil
}

// ResetIdempotencyKeyHash resets all changes to the "idempotency_key_hash" field.
func (m *IdempotencyRecordMutation) ResetIdempotencyKeyHash() {
	m.idempotency_key_hash = nil
}

// SetRequestFingerprint sets the "request_fingerprint" field.
func (m *IdempotencyRecordMutation) SetRequestFingerprint(s string) {
	m.request_fingerprint = &s
}

// RequestFingerprint returns the value of the "request_fingerprint" field in the mutation.
func (m *IdempotencyRecordMutation) RequestFingerprint() (r string, exists bool) {
	v := m.request_fingerprint
	if v == nil {
		return
	}
	return *v, true
}

// OldRequestFingerprint returns the old "request_fingerprint" field's value of the IdempotencyRecord entity.
// If the IdempotencyRecord object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdempotencyRecordMutation) OldRequestFingerprint(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRequestFingerprint is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRequestFingerprint requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRequestFingerprint: %w", err)
	}
	return oldValue.RequestFingerprint, nil
}

// ResetRequestFingerprint resets all changes to the "request_fingerprint" field.
func (m *IdempotencyRecordMutation) ResetRequestFingerprint() {
	m.request_fingerprint = nil
}

// SetStatus sets the "status" field.
func (m *IdempotencyRecordMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *IdempotencyRecordMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the IdempotencyRecord entity.
// If the IdempotencyRecord object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdempotencyRecordMutation) OldStatus(ctx context.Context) (v string, 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 *IdempotencyRecordMutation) ResetStatus() {
	m.status = nil
}

// SetResponseStatus sets the "response_status" field.
func (m *IdempotencyRecordMutation) SetResponseStatus(i int) {
	m.response_status = &i
	m.addresponse_status = nil
}

// ResponseStatus returns the value of the "response_status" field in the mutation.
func (m *IdempotencyRecordMutation) ResponseStatus() (r int, exists bool) {
	v := m.response_status
	if v == nil {
		return
	}
	return *v, true
}

// OldResponseStatus returns the old "response_status" field's value of the IdempotencyRecord entity.
// If the IdempotencyRecord object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdempotencyRecordMutation) OldResponseStatus(ctx context.Context) (v *int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldResponseStatus is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldResponseStatus requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldResponseStatus: %w", err)
	}
	return oldValue.ResponseStatus, nil
}

// AddResponseStatus adds i to the "response_status" field.
func (m *IdempotencyRecordMutation) AddResponseStatus(i int) {
	if m.addresponse_status != nil {
		*m.addresponse_status += i
	} else {
		m.addresponse_status = &i
	}
}

// AddedResponseStatus returns the value that was added to the "response_status" field in this mutation.
func (m *IdempotencyRecordMutation) AddedResponseStatus() (r int, exists bool) {
	v := m.addresponse_status
	if v == nil {
		return
	}
	return *v, true
}

// ClearResponseStatus clears the value of the "response_status" field.
func (m *IdempotencyRecordMutation) ClearResponseStatus() {
	m.response_status = nil
	m.addresponse_status = nil
	m.clearedFields[idempotencyrecord.FieldResponseStatus] = struct{}{}
}

// ResponseStatusCleared returns if the "response_status" field was cleared in this mutation.
func (m *IdempotencyRecordMutation) ResponseStatusCleared() bool {
	_, ok := m.clearedFields[idempotencyrecord.FieldResponseStatus]
	return ok
}

// ResetResponseStatus resets all changes to the "response_status" field.
func (m *IdempotencyRecordMutation) ResetResponseStatus() {
	m.response_status = nil
	m.addresponse_status = nil
	delete(m.clearedFields, idempotencyrecord.FieldResponseStatus)
}

// SetResponseBody sets the "response_body" field.
func (m *IdempotencyRecordMutation) SetResponseBody(s string) {
	m.response_body = &s
}

// ResponseBody returns the value of the "response_body" field in the mutation.
func (m *IdempotencyRecordMutation) ResponseBody() (r string, exists bool) {
	v := m.response_body
	if v == nil {
		return
	}
	return *v, true
}

// OldResponseBody returns the old "response_body" field's value of the IdempotencyRecord entity.
// If the IdempotencyRecord object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdempotencyRecordMutation) OldResponseBody(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldResponseBody is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldResponseBody requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldResponseBody: %w", err)
	}
	return oldValue.ResponseBody, nil
}

// ClearResponseBody clears the value of the "response_body" field.
func (m *IdempotencyRecordMutation) ClearResponseBody() {
	m.response_body = nil
	m.clearedFields[idempotencyrecord.FieldResponseBody] = struct{}{}
}

// ResponseBodyCleared returns if the "response_body" field was cleared in this mutation.
func (m *IdempotencyRecordMutation) ResponseBodyCleared() bool {
	_, ok := m.clearedFields[idempotencyrecord.FieldResponseBody]
	return ok
}

// ResetResponseBody resets all changes to the "response_body" field.
func (m *IdempotencyRecordMutation) ResetResponseBody() {
	m.response_body = nil
	delete(m.clearedFields, idempotencyrecord.FieldResponseBody)
}

// SetErrorReason sets the "error_reason" field.
func (m *IdempotencyRecordMutation) SetErrorReason(s string) {
	m.error_reason = &s
}

// ErrorReason returns the value of the "error_reason" field in the mutation.
func (m *IdempotencyRecordMutation) ErrorReason() (r string, exists bool) {
	v := m.error_reason
	if v == nil {
		return
	}
	return *v, true
}

// OldErrorReason returns the old "error_reason" field's value of the IdempotencyRecord entity.
// If the IdempotencyRecord object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdempotencyRecordMutation) OldErrorReason(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldErrorReason is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldErrorReason requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldErrorReason: %w", err)
	}
	return oldValue.ErrorReason, nil
}

// ClearErrorReason clears the value of the "error_reason" field.
func (m *IdempotencyRecordMutation) ClearErrorReason() {
	m.error_reason = nil
	m.clearedFields[idempotencyrecord.FieldErrorReason] = struct{}{}
}

// ErrorReasonCleared returns if the "error_reason" field was cleared in this mutation.
func (m *IdempotencyRecordMutation) ErrorReasonCleared() bool {
	_, ok := m.clearedFields[idempotencyrecord.FieldErrorReason]
	return ok
}

// ResetErrorReason resets all changes to the "error_reason" field.
func (m *IdempotencyRecordMutation) ResetErrorReason() {
	m.error_reason = nil
	delete(m.clearedFields, idempotencyrecord.FieldErrorReason)
}

// SetLockedUntil sets the "locked_until" field.
func (m *IdempotencyRecordMutation) SetLockedUntil(t time.Time) {
	m.locked_until = &t
}

// LockedUntil returns the value of the "locked_until" field in the mutation.
func (m *IdempotencyRecordMutation) LockedUntil() (r time.Time, exists bool) {
	v := m.locked_until
	if v == nil {
		return
	}
	return *v, true
}

// OldLockedUntil returns the old "locked_until" field's value of the IdempotencyRecord entity.
// If the IdempotencyRecord object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdempotencyRecordMutation) OldLockedUntil(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLockedUntil is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLockedUntil requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLockedUntil: %w", err)
	}
	return oldValue.LockedUntil, nil
}

// ClearLockedUntil clears the value of the "locked_until" field.
func (m *IdempotencyRecordMutation) ClearLockedUntil() {
	m.locked_until = nil
	m.clearedFields[idempotencyrecord.FieldLockedUntil] = struct{}{}
}

// LockedUntilCleared returns if the "locked_until" field was cleared in this mutation.
func (m *IdempotencyRecordMutation) LockedUntilCleared() bool {
	_, ok := m.clearedFields[idempotencyrecord.FieldLockedUntil]
	return ok
}

// ResetLockedUntil resets all changes to the "locked_until" field.
func (m *IdempotencyRecordMutation) ResetLockedUntil() {
	m.locked_until = nil
	delete(m.clearedFields, idempotencyrecord.FieldLockedUntil)
}

// SetExpiresAt sets the "expires_at" field.
func (m *IdempotencyRecordMutation) SetExpiresAt(t time.Time) {
	m.expires_at = &t
}

// ExpiresAt returns the value of the "expires_at" field in the mutation.
func (m *IdempotencyRecordMutation) ExpiresAt() (r time.Time, exists bool) {
	v := m.expires_at
	if v == nil {
		return
	}
	return *v, true
}

// OldExpiresAt returns the old "expires_at" field's value of the IdempotencyRecord entity.
// If the IdempotencyRecord object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdempotencyRecordMutation) OldExpiresAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldExpiresAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err)
	}
	return oldValue.ExpiresAt, nil
}

// ResetExpiresAt resets all changes to the "expires_at" field.
func (m *IdempotencyRecordMutation) ResetExpiresAt() {
	m.expires_at = nil
}

// Where appends a list predicates to the IdempotencyRecordMutation builder.
func (m *IdempotencyRecordMutation) Where(ps ...predicate.IdempotencyRecord) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the IdempotencyRecordMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *IdempotencyRecordMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.IdempotencyRecord, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *IdempotencyRecordMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *IdempotencyRecordMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (IdempotencyRecord).
func (m *IdempotencyRecordMutation) 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 *IdempotencyRecordMutation) Fields() []string {
	fields := make([]string, 0, 11)
	if m.created_at != nil {
		fields = append(fields, idempotencyrecord.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, idempotencyrecord.FieldUpdatedAt)
	}
	if m.scope != nil {
		fields = append(fields, idempotencyrecord.FieldScope)
	}
	if m.idempotency_key_hash != nil {
		fields = append(fields, idempotencyrecord.FieldIdempotencyKeyHash)
	}
	if m.request_fingerprint != nil {
		fields = append(fields, idempotencyrecord.FieldRequestFingerprint)
	}
	if m.status != nil {
		fields = append(fields, idempotencyrecord.FieldStatus)
	}
	if m.response_status != nil {
		fields = append(fields, idempotencyrecord.FieldResponseStatus)
	}
	if m.response_body != nil {
		fields = append(fields, idempotencyrecord.FieldResponseBody)
	}
	if m.error_reason != nil {
		fields = append(fields, idempotencyrecord.FieldErrorReason)
	}
	if m.locked_until != nil {
		fields = append(fields, idempotencyrecord.FieldLockedUntil)
	}
	if m.expires_at != nil {
		fields = append(fields, idempotencyrecord.FieldExpiresAt)
	}
	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 *IdempotencyRecordMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case idempotencyrecord.FieldCreatedAt:
		return m.CreatedAt()
	case idempotencyrecord.FieldUpdatedAt:
		return m.UpdatedAt()
	case idempotencyrecord.FieldScope:
		return m.Scope()
	case idempotencyrecord.FieldIdempotencyKeyHash:
		return m.IdempotencyKeyHash()
	case idempotencyrecord.FieldRequestFingerprint:
		return m.RequestFingerprint()
	case idempotencyrecord.FieldStatus:
		return m.Status()
	case idempotencyrecord.FieldResponseStatus:
		return m.ResponseStatus()
	case idempotencyrecord.FieldResponseBody:
		return m.ResponseBody()
	case idempotencyrecord.FieldErrorReason:
		return m.ErrorReason()
	case idempotencyrecord.FieldLockedUntil:
		return m.LockedUntil()
	case idempotencyrecord.FieldExpiresAt:
		return m.ExpiresAt()
	}
	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 *IdempotencyRecordMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case idempotencyrecord.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case idempotencyrecord.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case idempotencyrecord.FieldScope:
		return m.OldScope(ctx)
	case idempotencyrecord.FieldIdempotencyKeyHash:
		return m.OldIdempotencyKeyHash(ctx)
	case idempotencyrecord.FieldRequestFingerprint:
		return m.OldRequestFingerprint(ctx)
	case idempotencyrecord.FieldStatus:
		return m.OldStatus(ctx)
	case idempotencyrecord.FieldResponseStatus:
		return m.OldResponseStatus(ctx)
	case idempotencyrecord.FieldResponseBody:
		return m.OldResponseBody(ctx)
	case idempotencyrecord.FieldErrorReason:
		return m.OldErrorReason(ctx)
	case idempotencyrecord.FieldLockedUntil:
		return m.OldLockedUntil(ctx)
	case idempotencyrecord.FieldExpiresAt:
		return m.OldExpiresAt(ctx)
	}
	return nil, fmt.Errorf("unknown IdempotencyRecord 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 *IdempotencyRecordMutation) SetField(name string, value ent.Value) error {
	switch name {
	case idempotencyrecord.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 idempotencyrecord.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 idempotencyrecord.FieldScope:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetScope(v)
		return nil
	case idempotencyrecord.FieldIdempotencyKeyHash:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIdempotencyKeyHash(v)
		return nil
	case idempotencyrecord.FieldRequestFingerprint:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRequestFingerprint(v)
		return nil
	case idempotencyrecord.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case idempotencyrecord.FieldResponseStatus:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetResponseStatus(v)
		return nil
	case idempotencyrecord.FieldResponseBody:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetResponseBody(v)
		return nil
	case idempotencyrecord.FieldErrorReason:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetErrorReason(v)
		return nil
	case idempotencyrecord.FieldLockedUntil:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLockedUntil(v)
		return nil
	case idempotencyrecord.FieldExpiresAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetExpiresAt(v)
		return nil
	}
	return fmt.Errorf("unknown IdempotencyRecord field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *IdempotencyRecordMutation) AddedFields() []string {
	var fields []string
	if m.addresponse_status != nil {
		fields = append(fields, idempotencyrecord.FieldResponseStatus)
	}
	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 *IdempotencyRecordMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case idempotencyrecord.FieldResponseStatus:
		return m.AddedResponseStatus()
	}
	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 *IdempotencyRecordMutation) AddField(name string, value ent.Value) error {
	switch name {
	case idempotencyrecord.FieldResponseStatus:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddResponseStatus(v)
		return nil
	}
	return fmt.Errorf("unknown IdempotencyRecord numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *IdempotencyRecordMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(idempotencyrecord.FieldResponseStatus) {
		fields = append(fields, idempotencyrecord.FieldResponseStatus)
	}
	if m.FieldCleared(idempotencyrecord.FieldResponseBody) {
		fields = append(fields, idempotencyrecord.FieldResponseBody)
	}
	if m.FieldCleared(idempotencyrecord.FieldErrorReason) {
		fields = append(fields, idempotencyrecord.FieldErrorReason)
	}
	if m.FieldCleared(idempotencyrecord.FieldLockedUntil) {
		fields = append(fields, idempotencyrecord.FieldLockedUntil)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *IdempotencyRecordMutation) 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 *IdempotencyRecordMutation) ClearField(name string) error {
	switch name {
	case idempotencyrecord.FieldResponseStatus:
		m.ClearResponseStatus()
		return nil
	case idempotencyrecord.FieldResponseBody:
		m.ClearResponseBody()
		return nil
	case idempotencyrecord.FieldErrorReason:
		m.ClearErrorReason()
		return nil
	case idempotencyrecord.FieldLockedUntil:
		m.ClearLockedUntil()
		return nil
	}
	return fmt.Errorf("unknown IdempotencyRecord 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 *IdempotencyRecordMutation) ResetField(name string) error {
	switch name {
	case idempotencyrecord.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case idempotencyrecord.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case idempotencyrecord.FieldScope:
		m.ResetScope()
		return nil
	case idempotencyrecord.FieldIdempotencyKeyHash:
		m.ResetIdempotencyKeyHash()
		return nil
	case idempotencyrecord.FieldRequestFingerprint:
		m.ResetRequestFingerprint()
		return nil
	case idempotencyrecord.FieldStatus:
		m.ResetStatus()
		return nil
	case idempotencyrecord.FieldResponseStatus:
		m.ResetResponseStatus()
		return nil
	case idempotencyrecord.FieldResponseBody:
		m.ResetResponseBody()
		return nil
	case idempotencyrecord.FieldErrorReason:
		m.ResetErrorReason()
		return nil
	case idempotencyrecord.FieldLockedUntil:
		m.ResetLockedUntil()
		return nil
	case idempotencyrecord.FieldExpiresAt:
		m.ResetExpiresAt()
		return nil
	}
	return fmt.Errorf("unknown IdempotencyRecord field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *IdempotencyRecordMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *IdempotencyRecordMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *IdempotencyRecordMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *IdempotencyRecordMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *IdempotencyRecordMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *IdempotencyRecordMutation) EdgeCleared(name string) bool {
	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 *IdempotencyRecordMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown IdempotencyRecord 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 *IdempotencyRecordMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown IdempotencyRecord edge %s", name)
}

// IdentityAdoptionDecisionMutation represents an operation that mutates the IdentityAdoptionDecision nodes in the graph.
type IdentityAdoptionDecisionMutation struct {
	config
	op                          Op
	typ                         string
	id                          *int64
	created_at                  *time.Time
	updated_at                  *time.Time
	adopt_display_name          *bool
	adopt_avatar                *bool
	decided_at                  *time.Time
	clearedFields               map[string]struct{}
	pending_auth_session        *int64
	clearedpending_auth_session bool
	identity                    *int64
	clearedidentity             bool
	done                        bool
	oldValue                    func(context.Context) (*IdentityAdoptionDecision, error)
	predicates                  []predicate.IdentityAdoptionDecision
}

var _ ent.Mutation = (*IdentityAdoptionDecisionMutation)(nil)

// identityadoptiondecisionOption allows management of the mutation configuration using functional options.
type identityadoptiondecisionOption func(*IdentityAdoptionDecisionMutation)

// newIdentityAdoptionDecisionMutation creates new mutation for the IdentityAdoptionDecision entity.
func newIdentityAdoptionDecisionMutation(c config, op Op, opts ...identityadoptiondecisionOption) *IdentityAdoptionDecisionMutation {
	m := &IdentityAdoptionDecisionMutation{
		config:        c,
		op:            op,
		typ:           TypeIdentityAdoptionDecision,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withIdentityAdoptionDecisionID sets the ID field of the mutation.
func withIdentityAdoptionDecisionID(id int64) identityadoptiondecisionOption {
	return func(m *IdentityAdoptionDecisionMutation) {
		var (
			err   error
			once  sync.Once
			value *IdentityAdoptionDecision
		)
		m.oldValue = func(ctx context.Context) (*IdentityAdoptionDecision, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().IdentityAdoptionDecision.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withIdentityAdoptionDecision sets the old IdentityAdoptionDecision of the mutation.
func withIdentityAdoptionDecision(node *IdentityAdoptionDecision) identityadoptiondecisionOption {
	return func(m *IdentityAdoptionDecisionMutation) {
		m.oldValue = func(context.Context) (*IdentityAdoptionDecision, 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 IdentityAdoptionDecisionMutation) 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 IdentityAdoptionDecisionMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *IdentityAdoptionDecisionMutation) ID() (id int64, 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 *IdentityAdoptionDecisionMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().IdentityAdoptionDecision.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *IdentityAdoptionDecisionMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *IdentityAdoptionDecisionMutation) 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 IdentityAdoptionDecision entity.
// If the IdentityAdoptionDecision object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdentityAdoptionDecisionMutation) 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 *IdentityAdoptionDecisionMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *IdentityAdoptionDecisionMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *IdentityAdoptionDecisionMutation) 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 IdentityAdoptionDecision entity.
// If the IdentityAdoptionDecision object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdentityAdoptionDecisionMutation) 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 *IdentityAdoptionDecisionMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetPendingAuthSessionID sets the "pending_auth_session_id" field.
func (m *IdentityAdoptionDecisionMutation) SetPendingAuthSessionID(i int64) {
	m.pending_auth_session = &i
}

// PendingAuthSessionID returns the value of the "pending_auth_session_id" field in the mutation.
func (m *IdentityAdoptionDecisionMutation) PendingAuthSessionID() (r int64, exists bool) {
	v := m.pending_auth_session
	if v == nil {
		return
	}
	return *v, true
}

// OldPendingAuthSessionID returns the old "pending_auth_session_id" field's value of the IdentityAdoptionDecision entity.
// If the IdentityAdoptionDecision object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdentityAdoptionDecisionMutation) OldPendingAuthSessionID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPendingAuthSessionID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPendingAuthSessionID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPendingAuthSessionID: %w", err)
	}
	return oldValue.PendingAuthSessionID, nil
}

// ResetPendingAuthSessionID resets all changes to the "pending_auth_session_id" field.
func (m *IdentityAdoptionDecisionMutation) ResetPendingAuthSessionID() {
	m.pending_auth_session = nil
}

// SetIdentityID sets the "identity_id" field.
func (m *IdentityAdoptionDecisionMutation) SetIdentityID(i int64) {
	m.identity = &i
}

// IdentityID returns the value of the "identity_id" field in the mutation.
func (m *IdentityAdoptionDecisionMutation) IdentityID() (r int64, exists bool) {
	v := m.identity
	if v == nil {
		return
	}
	return *v, true
}

// OldIdentityID returns the old "identity_id" field's value of the IdentityAdoptionDecision entity.
// If the IdentityAdoptionDecision object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdentityAdoptionDecisionMutation) OldIdentityID(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldIdentityID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldIdentityID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldIdentityID: %w", err)
	}
	return oldValue.IdentityID, nil
}

// ClearIdentityID clears the value of the "identity_id" field.
func (m *IdentityAdoptionDecisionMutation) ClearIdentityID() {
	m.identity = nil
	m.clearedFields[identityadoptiondecision.FieldIdentityID] = struct{}{}
}

// IdentityIDCleared returns if the "identity_id" field was cleared in this mutation.
func (m *IdentityAdoptionDecisionMutation) IdentityIDCleared() bool {
	_, ok := m.clearedFields[identityadoptiondecision.FieldIdentityID]
	return ok
}

// ResetIdentityID resets all changes to the "identity_id" field.
func (m *IdentityAdoptionDecisionMutation) ResetIdentityID() {
	m.identity = nil
	delete(m.clearedFields, identityadoptiondecision.FieldIdentityID)
}

// SetAdoptDisplayName sets the "adopt_display_name" field.
func (m *IdentityAdoptionDecisionMutation) SetAdoptDisplayName(b bool) {
	m.adopt_display_name = &b
}

// AdoptDisplayName returns the value of the "adopt_display_name" field in the mutation.
func (m *IdentityAdoptionDecisionMutation) AdoptDisplayName() (r bool, exists bool) {
	v := m.adopt_display_name
	if v == nil {
		return
	}
	return *v, true
}

// OldAdoptDisplayName returns the old "adopt_display_name" field's value of the IdentityAdoptionDecision entity.
// If the IdentityAdoptionDecision object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdentityAdoptionDecisionMutation) OldAdoptDisplayName(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAdoptDisplayName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAdoptDisplayName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAdoptDisplayName: %w", err)
	}
	return oldValue.AdoptDisplayName, nil
}

// ResetAdoptDisplayName resets all changes to the "adopt_display_name" field.
func (m *IdentityAdoptionDecisionMutation) ResetAdoptDisplayName() {
	m.adopt_display_name = nil
}

// SetAdoptAvatar sets the "adopt_avatar" field.
func (m *IdentityAdoptionDecisionMutation) SetAdoptAvatar(b bool) {
	m.adopt_avatar = &b
}

// AdoptAvatar returns the value of the "adopt_avatar" field in the mutation.
func (m *IdentityAdoptionDecisionMutation) AdoptAvatar() (r bool, exists bool) {
	v := m.adopt_avatar
	if v == nil {
		return
	}
	return *v, true
}

// OldAdoptAvatar returns the old "adopt_avatar" field's value of the IdentityAdoptionDecision entity.
// If the IdentityAdoptionDecision object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdentityAdoptionDecisionMutation) OldAdoptAvatar(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAdoptAvatar is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAdoptAvatar requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAdoptAvatar: %w", err)
	}
	return oldValue.AdoptAvatar, nil
}

// ResetAdoptAvatar resets all changes to the "adopt_avatar" field.
func (m *IdentityAdoptionDecisionMutation) ResetAdoptAvatar() {
	m.adopt_avatar = nil
}

// SetDecidedAt sets the "decided_at" field.
func (m *IdentityAdoptionDecisionMutation) SetDecidedAt(t time.Time) {
	m.decided_at = &t
}

// DecidedAt returns the value of the "decided_at" field in the mutation.
func (m *IdentityAdoptionDecisionMutation) DecidedAt() (r time.Time, exists bool) {
	v := m.decided_at
	if v == nil {
		return
	}
	return *v, true
}

// OldDecidedAt returns the old "decided_at" field's value of the IdentityAdoptionDecision entity.
// If the IdentityAdoptionDecision object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *IdentityAdoptionDecisionMutation) OldDecidedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDecidedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDecidedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDecidedAt: %w", err)
	}
	return oldValue.DecidedAt, nil
}

// ResetDecidedAt resets all changes to the "decided_at" field.
func (m *IdentityAdoptionDecisionMutation) ResetDecidedAt() {
	m.decided_at = nil
}

// ClearPendingAuthSession clears the "pending_auth_session" edge to the PendingAuthSession entity.
func (m *IdentityAdoptionDecisionMutation) ClearPendingAuthSession() {
	m.clearedpending_auth_session = true
	m.clearedFields[identityadoptiondecision.FieldPendingAuthSessionID] = struct{}{}
}

// PendingAuthSessionCleared reports if the "pending_auth_session" edge to the PendingAuthSession entity was cleared.
func (m *IdentityAdoptionDecisionMutation) PendingAuthSessionCleared() bool {
	return m.clearedpending_auth_session
}

// PendingAuthSessionIDs returns the "pending_auth_session" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// PendingAuthSessionID instead. It exists only for internal usage by the builders.
func (m *IdentityAdoptionDecisionMutation) PendingAuthSessionIDs() (ids []int64) {
	if id := m.pending_auth_session; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetPendingAuthSession resets all changes to the "pending_auth_session" edge.
func (m *IdentityAdoptionDecisionMutation) ResetPendingAuthSession() {
	m.pending_auth_session = nil
	m.clearedpending_auth_session = false
}

// ClearIdentity clears the "identity" edge to the AuthIdentity entity.
func (m *IdentityAdoptionDecisionMutation) ClearIdentity() {
	m.clearedidentity = true
	m.clearedFields[identityadoptiondecision.FieldIdentityID] = struct{}{}
}

// IdentityCleared reports if the "identity" edge to the AuthIdentity entity was cleared.
func (m *IdentityAdoptionDecisionMutation) IdentityCleared() bool {
	return m.IdentityIDCleared() || m.clearedidentity
}

// IdentityIDs returns the "identity" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// IdentityID instead. It exists only for internal usage by the builders.
func (m *IdentityAdoptionDecisionMutation) IdentityIDs() (ids []int64) {
	if id := m.identity; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetIdentity resets all changes to the "identity" edge.
func (m *IdentityAdoptionDecisionMutation) ResetIdentity() {
	m.identity = nil
	m.clearedidentity = false
}

// Where appends a list predicates to the IdentityAdoptionDecisionMutation builder.
func (m *IdentityAdoptionDecisionMutation) Where(ps ...predicate.IdentityAdoptionDecision) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the IdentityAdoptionDecisionMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *IdentityAdoptionDecisionMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.IdentityAdoptionDecision, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *IdentityAdoptionDecisionMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *IdentityAdoptionDecisionMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (IdentityAdoptionDecision).
func (m *IdentityAdoptionDecisionMutation) 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 *IdentityAdoptionDecisionMutation) Fields() []string {
	fields := make([]string, 0, 7)
	if m.created_at != nil {
		fields = append(fields, identityadoptiondecision.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, identityadoptiondecision.FieldUpdatedAt)
	}
	if m.pending_auth_session != nil {
		fields = append(fields, identityadoptiondecision.FieldPendingAuthSessionID)
	}
	if m.identity != nil {
		fields = append(fields, identityadoptiondecision.FieldIdentityID)
	}
	if m.adopt_display_name != nil {
		fields = append(fields, identityadoptiondecision.FieldAdoptDisplayName)
	}
	if m.adopt_avatar != nil {
		fields = append(fields, identityadoptiondecision.FieldAdoptAvatar)
	}
	if m.decided_at != nil {
		fields = append(fields, identityadoptiondecision.FieldDecidedAt)
	}
	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 *IdentityAdoptionDecisionMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case identityadoptiondecision.FieldCreatedAt:
		return m.CreatedAt()
	case identityadoptiondecision.FieldUpdatedAt:
		return m.UpdatedAt()
	case identityadoptiondecision.FieldPendingAuthSessionID:
		return m.PendingAuthSessionID()
	case identityadoptiondecision.FieldIdentityID:
		return m.IdentityID()
	case identityadoptiondecision.FieldAdoptDisplayName:
		return m.AdoptDisplayName()
	case identityadoptiondecision.FieldAdoptAvatar:
		return m.AdoptAvatar()
	case identityadoptiondecision.FieldDecidedAt:
		return m.DecidedAt()
	}
	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 *IdentityAdoptionDecisionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case identityadoptiondecision.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case identityadoptiondecision.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case identityadoptiondecision.FieldPendingAuthSessionID:
		return m.OldPendingAuthSessionID(ctx)
	case identityadoptiondecision.FieldIdentityID:
		return m.OldIdentityID(ctx)
	case identityadoptiondecision.FieldAdoptDisplayName:
		return m.OldAdoptDisplayName(ctx)
	case identityadoptiondecision.FieldAdoptAvatar:
		return m.OldAdoptAvatar(ctx)
	case identityadoptiondecision.FieldDecidedAt:
		return m.OldDecidedAt(ctx)
	}
	return nil, fmt.Errorf("unknown IdentityAdoptionDecision 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 *IdentityAdoptionDecisionMutation) SetField(name string, value ent.Value) error {
	switch name {
	case identityadoptiondecision.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 identityadoptiondecision.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 identityadoptiondecision.FieldPendingAuthSessionID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPendingAuthSessionID(v)
		return nil
	case identityadoptiondecision.FieldIdentityID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIdentityID(v)
		return nil
	case identityadoptiondecision.FieldAdoptDisplayName:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAdoptDisplayName(v)
		return nil
	case identityadoptiondecision.FieldAdoptAvatar:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAdoptAvatar(v)
		return nil
	case identityadoptiondecision.FieldDecidedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDecidedAt(v)
		return nil
	}
	return fmt.Errorf("unknown IdentityAdoptionDecision field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *IdentityAdoptionDecisionMutation) AddedFields() []string {
	var fields []string
	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 *IdentityAdoptionDecisionMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	}
	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 *IdentityAdoptionDecisionMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown IdentityAdoptionDecision numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *IdentityAdoptionDecisionMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(identityadoptiondecision.FieldIdentityID) {
		fields = append(fields, identityadoptiondecision.FieldIdentityID)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *IdentityAdoptionDecisionMutation) 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 *IdentityAdoptionDecisionMutation) ClearField(name string) error {
	switch name {
	case identityadoptiondecision.FieldIdentityID:
		m.ClearIdentityID()
		return nil
	}
	return fmt.Errorf("unknown IdentityAdoptionDecision 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 *IdentityAdoptionDecisionMutation) ResetField(name string) error {
	switch name {
	case identityadoptiondecision.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case identityadoptiondecision.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case identityadoptiondecision.FieldPendingAuthSessionID:
		m.ResetPendingAuthSessionID()
		return nil
	case identityadoptiondecision.FieldIdentityID:
		m.ResetIdentityID()
		return nil
	case identityadoptiondecision.FieldAdoptDisplayName:
		m.ResetAdoptDisplayName()
		return nil
	case identityadoptiondecision.FieldAdoptAvatar:
		m.ResetAdoptAvatar()
		return nil
	case identityadoptiondecision.FieldDecidedAt:
		m.ResetDecidedAt()
		return nil
	}
	return fmt.Errorf("unknown IdentityAdoptionDecision field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *IdentityAdoptionDecisionMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.pending_auth_session != nil {
		edges = append(edges, identityadoptiondecision.EdgePendingAuthSession)
	}
	if m.identity != nil {
		edges = append(edges, identityadoptiondecision.EdgeIdentity)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *IdentityAdoptionDecisionMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case identityadoptiondecision.EdgePendingAuthSession:
		if id := m.pending_auth_session; id != nil {
			return []ent.Value{*id}
		}
	case identityadoptiondecision.EdgeIdentity:
		if id := m.identity; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *IdentityAdoptionDecisionMutation) 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 *IdentityAdoptionDecisionMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *IdentityAdoptionDecisionMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedpending_auth_session {
		edges = append(edges, identityadoptiondecision.EdgePendingAuthSession)
	}
	if m.clearedidentity {
		edges = append(edges, identityadoptiondecision.EdgeIdentity)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *IdentityAdoptionDecisionMutation) EdgeCleared(name string) bool {
	switch name {
	case identityadoptiondecision.EdgePendingAuthSession:
		return m.clearedpending_auth_session
	case identityadoptiondecision.EdgeIdentity:
		return m.clearedidentity
	}
	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 *IdentityAdoptionDecisionMutation) ClearEdge(name string) error {
	switch name {
	case identityadoptiondecision.EdgePendingAuthSession:
		m.ClearPendingAuthSession()
		return nil
	case identityadoptiondecision.EdgeIdentity:
		m.ClearIdentity()
		return nil
	}
	return fmt.Errorf("unknown IdentityAdoptionDecision 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 *IdentityAdoptionDecisionMutation) ResetEdge(name string) error {
	switch name {
	case identityadoptiondecision.EdgePendingAuthSession:
		m.ResetPendingAuthSession()
		return nil
	case identityadoptiondecision.EdgeIdentity:
		m.ResetIdentity()
		return nil
	}
	return fmt.Errorf("unknown IdentityAdoptionDecision edge %s", name)
}

// PaymentAuditLogMutation represents an operation that mutates the PaymentAuditLog nodes in the graph.
type PaymentAuditLogMutation struct {
	config
	op            Op
	typ           string
	id            *int64
	order_id      *string
	action        *string
	detail        *string
	operator      *string
	created_at    *time.Time
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*PaymentAuditLog, error)
	predicates    []predicate.PaymentAuditLog
}

var _ ent.Mutation = (*PaymentAuditLogMutation)(nil)

// paymentauditlogOption allows management of the mutation configuration using functional options.
type paymentauditlogOption func(*PaymentAuditLogMutation)

// newPaymentAuditLogMutation creates new mutation for the PaymentAuditLog entity.
func newPaymentAuditLogMutation(c config, op Op, opts ...paymentauditlogOption) *PaymentAuditLogMutation {
	m := &PaymentAuditLogMutation{
		config:        c,
		op:            op,
		typ:           TypePaymentAuditLog,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withPaymentAuditLogID sets the ID field of the mutation.
func withPaymentAuditLogID(id int64) paymentauditlogOption {
	return func(m *PaymentAuditLogMutation) {
		var (
			err   error
			once  sync.Once
			value *PaymentAuditLog
		)
		m.oldValue = func(ctx context.Context) (*PaymentAuditLog, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().PaymentAuditLog.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withPaymentAuditLog sets the old PaymentAuditLog of the mutation.
func withPaymentAuditLog(node *PaymentAuditLog) paymentauditlogOption {
	return func(m *PaymentAuditLogMutation) {
		m.oldValue = func(context.Context) (*PaymentAuditLog, 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 PaymentAuditLogMutation) 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 PaymentAuditLogMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *PaymentAuditLogMutation) ID() (id int64, 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 *PaymentAuditLogMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().PaymentAuditLog.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetOrderID sets the "order_id" field.
func (m *PaymentAuditLogMutation) SetOrderID(s string) {
	m.order_id = &s
}

// OrderID returns the value of the "order_id" field in the mutation.
func (m *PaymentAuditLogMutation) OrderID() (r string, exists bool) {
	v := m.order_id
	if v == nil {
		return
	}
	return *v, true
}

// OldOrderID returns the old "order_id" field's value of the PaymentAuditLog entity.
// If the PaymentAuditLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentAuditLogMutation) OldOrderID(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldOrderID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldOrderID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldOrderID: %w", err)
	}
	return oldValue.OrderID, nil
}

// ResetOrderID resets all changes to the "order_id" field.
func (m *PaymentAuditLogMutation) ResetOrderID() {
	m.order_id = nil
}

// SetAction sets the "action" field.
func (m *PaymentAuditLogMutation) SetAction(s string) {
	m.action = &s
}

// Action returns the value of the "action" field in the mutation.
func (m *PaymentAuditLogMutation) Action() (r string, exists bool) {
	v := m.action
	if v == nil {
		return
	}
	return *v, true
}

// OldAction returns the old "action" field's value of the PaymentAuditLog entity.
// If the PaymentAuditLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentAuditLogMutation) OldAction(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAction is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAction requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAction: %w", err)
	}
	return oldValue.Action, nil
}

// ResetAction resets all changes to the "action" field.
func (m *PaymentAuditLogMutation) ResetAction() {
	m.action = nil
}

// SetDetail sets the "detail" field.
func (m *PaymentAuditLogMutation) SetDetail(s string) {
	m.detail = &s
}

// Detail returns the value of the "detail" field in the mutation.
func (m *PaymentAuditLogMutation) Detail() (r string, exists bool) {
	v := m.detail
	if v == nil {
		return
	}
	return *v, true
}

// OldDetail returns the old "detail" field's value of the PaymentAuditLog entity.
// If the PaymentAuditLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentAuditLogMutation) OldDetail(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDetail is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDetail requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDetail: %w", err)
	}
	return oldValue.Detail, nil
}

// ResetDetail resets all changes to the "detail" field.
func (m *PaymentAuditLogMutation) ResetDetail() {
	m.detail = nil
}

// SetOperator sets the "operator" field.
func (m *PaymentAuditLogMutation) SetOperator(s string) {
	m.operator = &s
}

// Operator returns the value of the "operator" field in the mutation.
func (m *PaymentAuditLogMutation) Operator() (r string, exists bool) {
	v := m.operator
	if v == nil {
		return
	}
	return *v, true
}

// OldOperator returns the old "operator" field's value of the PaymentAuditLog entity.
// If the PaymentAuditLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentAuditLogMutation) OldOperator(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldOperator is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldOperator requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldOperator: %w", err)
	}
	return oldValue.Operator, nil
}

// ResetOperator resets all changes to the "operator" field.
func (m *PaymentAuditLogMutation) ResetOperator() {
	m.operator = nil
}

// SetCreatedAt sets the "created_at" field.
func (m *PaymentAuditLogMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *PaymentAuditLogMutation) 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 PaymentAuditLog entity.
// If the PaymentAuditLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentAuditLogMutation) 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 *PaymentAuditLogMutation) ResetCreatedAt() {
	m.created_at = nil
}

// Where appends a list predicates to the PaymentAuditLogMutation builder.
func (m *PaymentAuditLogMutation) Where(ps ...predicate.PaymentAuditLog) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the PaymentAuditLogMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PaymentAuditLogMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.PaymentAuditLog, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *PaymentAuditLogMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *PaymentAuditLogMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (PaymentAuditLog).
func (m *PaymentAuditLogMutation) 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 *PaymentAuditLogMutation) Fields() []string {
	fields := make([]string, 0, 5)
	if m.order_id != nil {
		fields = append(fields, paymentauditlog.FieldOrderID)
	}
	if m.action != nil {
		fields = append(fields, paymentauditlog.FieldAction)
	}
	if m.detail != nil {
		fields = append(fields, paymentauditlog.FieldDetail)
	}
	if m.operator != nil {
		fields = append(fields, paymentauditlog.FieldOperator)
	}
	if m.created_at != nil {
		fields = append(fields, paymentauditlog.FieldCreatedAt)
	}
	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 *PaymentAuditLogMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case paymentauditlog.FieldOrderID:
		return m.OrderID()
	case paymentauditlog.FieldAction:
		return m.Action()
	case paymentauditlog.FieldDetail:
		return m.Detail()
	case paymentauditlog.FieldOperator:
		return m.Operator()
	case paymentauditlog.FieldCreatedAt:
		return m.CreatedAt()
	}
	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 *PaymentAuditLogMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case paymentauditlog.FieldOrderID:
		return m.OldOrderID(ctx)
	case paymentauditlog.FieldAction:
		return m.OldAction(ctx)
	case paymentauditlog.FieldDetail:
		return m.OldDetail(ctx)
	case paymentauditlog.FieldOperator:
		return m.OldOperator(ctx)
	case paymentauditlog.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown PaymentAuditLog 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 *PaymentAuditLogMutation) SetField(name string, value ent.Value) error {
	switch name {
	case paymentauditlog.FieldOrderID:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOrderID(v)
		return nil
	case paymentauditlog.FieldAction:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAction(v)
		return nil
	case paymentauditlog.FieldDetail:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDetail(v)
		return nil
	case paymentauditlog.FieldOperator:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOperator(v)
		return nil
	case paymentauditlog.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown PaymentAuditLog field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PaymentAuditLogMutation) 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 *PaymentAuditLogMutation) 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 *PaymentAuditLogMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown PaymentAuditLog numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PaymentAuditLogMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PaymentAuditLogMutation) 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 *PaymentAuditLogMutation) ClearField(name string) error {
	return fmt.Errorf("unknown PaymentAuditLog 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 *PaymentAuditLogMutation) ResetField(name string) error {
	switch name {
	case paymentauditlog.FieldOrderID:
		m.ResetOrderID()
		return nil
	case paymentauditlog.FieldAction:
		m.ResetAction()
		return nil
	case paymentauditlog.FieldDetail:
		m.ResetDetail()
		return nil
	case paymentauditlog.FieldOperator:
		m.ResetOperator()
		return nil
	case paymentauditlog.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown PaymentAuditLog field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PaymentAuditLogMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PaymentAuditLogMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PaymentAuditLogMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *PaymentAuditLogMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PaymentAuditLogMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PaymentAuditLogMutation) EdgeCleared(name string) bool {
	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 *PaymentAuditLogMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown PaymentAuditLog 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 *PaymentAuditLogMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown PaymentAuditLog edge %s", name)
}

// PaymentOrderMutation represents an operation that mutates the PaymentOrder nodes in the graph.
type PaymentOrderMutation struct {
	config
	op                       Op
	typ                      string
	id                       *int64
	user_email               *string
	user_name                *string
	user_notes               *string
	amount                   *float64
	addamount                *float64
	pay_amount               *float64
	addpay_amount            *float64
	fee_rate                 *float64
	addfee_rate              *float64
	recharge_code            *string
	out_trade_no             *string
	payment_type             *string
	payment_trade_no         *string
	pay_url                  *string
	qr_code                  *string
	qr_code_img              *string
	order_type               *string
	plan_id                  *int64
	addplan_id               *int64
	subscription_group_id    *int64
	addsubscription_group_id *int64
	subscription_days        *int
	addsubscription_days     *int
	provider_instance_id     *string
	provider_key             *string
	status                   *string
	refund_amount            *float64
	addrefund_amount         *float64
	refund_reason            *string
	refund_at                *time.Time
	force_refund             *bool
	refund_requested_at      *time.Time
	refund_request_reason    *string
	refund_requested_by      *string
	expires_at               *time.Time
	paid_at                  *time.Time
	completed_at             *time.Time
	failed_at                *time.Time
	failed_reason            *string
	client_ip                *string
	src_host                 *string
	src_url                  *string
	created_at               *time.Time
	updated_at               *time.Time
	clearedFields            map[string]struct{}
	user                     *int64
	cleareduser              bool
	done                     bool
	oldValue                 func(context.Context) (*PaymentOrder, error)
	predicates               []predicate.PaymentOrder
}

var _ ent.Mutation = (*PaymentOrderMutation)(nil)

// paymentorderOption allows management of the mutation configuration using functional options.
type paymentorderOption func(*PaymentOrderMutation)

// newPaymentOrderMutation creates new mutation for the PaymentOrder entity.
func newPaymentOrderMutation(c config, op Op, opts ...paymentorderOption) *PaymentOrderMutation {
	m := &PaymentOrderMutation{
		config:        c,
		op:            op,
		typ:           TypePaymentOrder,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withPaymentOrderID sets the ID field of the mutation.
func withPaymentOrderID(id int64) paymentorderOption {
	return func(m *PaymentOrderMutation) {
		var (
			err   error
			once  sync.Once
			value *PaymentOrder
		)
		m.oldValue = func(ctx context.Context) (*PaymentOrder, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().PaymentOrder.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withPaymentOrder sets the old PaymentOrder of the mutation.
func withPaymentOrder(node *PaymentOrder) paymentorderOption {
	return func(m *PaymentOrderMutation) {
		m.oldValue = func(context.Context) (*PaymentOrder, 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 PaymentOrderMutation) 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 PaymentOrderMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *PaymentOrderMutation) ID() (id int64, 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 *PaymentOrderMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().PaymentOrder.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetUserID sets the "user_id" field.
func (m *PaymentOrderMutation) SetUserID(i int64) {
	m.user = &i
}

// UserID returns the value of the "user_id" field in the mutation.
func (m *PaymentOrderMutation) UserID() (r int64, exists bool) {
	v := m.user
	if v == nil {
		return
	}
	return *v, true
}

// OldUserID returns the old "user_id" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldUserID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
	}
	return oldValue.UserID, nil
}

// ResetUserID resets all changes to the "user_id" field.
func (m *PaymentOrderMutation) ResetUserID() {
	m.user = nil
}

// SetUserEmail sets the "user_email" field.
func (m *PaymentOrderMutation) SetUserEmail(s string) {
	m.user_email = &s
}

// UserEmail returns the value of the "user_email" field in the mutation.
func (m *PaymentOrderMutation) UserEmail() (r string, exists bool) {
	v := m.user_email
	if v == nil {
		return
	}
	return *v, true
}

// OldUserEmail returns the old "user_email" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldUserEmail(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserEmail is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserEmail requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserEmail: %w", err)
	}
	return oldValue.UserEmail, nil
}

// ResetUserEmail resets all changes to the "user_email" field.
func (m *PaymentOrderMutation) ResetUserEmail() {
	m.user_email = nil
}

// SetUserName sets the "user_name" field.
func (m *PaymentOrderMutation) SetUserName(s string) {
	m.user_name = &s
}

// UserName returns the value of the "user_name" field in the mutation.
func (m *PaymentOrderMutation) UserName() (r string, exists bool) {
	v := m.user_name
	if v == nil {
		return
	}
	return *v, true
}

// OldUserName returns the old "user_name" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldUserName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserName: %w", err)
	}
	return oldValue.UserName, nil
}

// ResetUserName resets all changes to the "user_name" field.
func (m *PaymentOrderMutation) ResetUserName() {
	m.user_name = nil
}

// SetUserNotes sets the "user_notes" field.
func (m *PaymentOrderMutation) SetUserNotes(s string) {
	m.user_notes = &s
}

// UserNotes returns the value of the "user_notes" field in the mutation.
func (m *PaymentOrderMutation) UserNotes() (r string, exists bool) {
	v := m.user_notes
	if v == nil {
		return
	}
	return *v, true
}

// OldUserNotes returns the old "user_notes" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldUserNotes(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserNotes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserNotes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserNotes: %w", err)
	}
	return oldValue.UserNotes, nil
}

// ClearUserNotes clears the value of the "user_notes" field.
func (m *PaymentOrderMutation) ClearUserNotes() {
	m.user_notes = nil
	m.clearedFields[paymentorder.FieldUserNotes] = struct{}{}
}

// UserNotesCleared returns if the "user_notes" field was cleared in this mutation.
func (m *PaymentOrderMutation) UserNotesCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldUserNotes]
	return ok
}

// ResetUserNotes resets all changes to the "user_notes" field.
func (m *PaymentOrderMutation) ResetUserNotes() {
	m.user_notes = nil
	delete(m.clearedFields, paymentorder.FieldUserNotes)
}

// SetAmount sets the "amount" field.
func (m *PaymentOrderMutation) SetAmount(f float64) {
	m.amount = &f
	m.addamount = nil
}

// Amount returns the value of the "amount" field in the mutation.
func (m *PaymentOrderMutation) Amount() (r float64, exists bool) {
	v := m.amount
	if v == nil {
		return
	}
	return *v, true
}

// OldAmount returns the old "amount" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldAmount(ctx context.Context) (v float64, 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
}

// AddAmount adds f to the "amount" field.
func (m *PaymentOrderMutation) AddAmount(f float64) {
	if m.addamount != nil {
		*m.addamount += f
	} else {
		m.addamount = &f
	}
}

// AddedAmount returns the value that was added to the "amount" field in this mutation.
func (m *PaymentOrderMutation) AddedAmount() (r float64, exists bool) {
	v := m.addamount
	if v == nil {
		return
	}
	return *v, true
}

// ResetAmount resets all changes to the "amount" field.
func (m *PaymentOrderMutation) ResetAmount() {
	m.amount = nil
	m.addamount = nil
}

// SetPayAmount sets the "pay_amount" field.
func (m *PaymentOrderMutation) SetPayAmount(f float64) {
	m.pay_amount = &f
	m.addpay_amount = nil
}

// PayAmount returns the value of the "pay_amount" field in the mutation.
func (m *PaymentOrderMutation) PayAmount() (r float64, exists bool) {
	v := m.pay_amount
	if v == nil {
		return
	}
	return *v, true
}

// OldPayAmount returns the old "pay_amount" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldPayAmount(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPayAmount is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPayAmount requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPayAmount: %w", err)
	}
	return oldValue.PayAmount, nil
}

// AddPayAmount adds f to the "pay_amount" field.
func (m *PaymentOrderMutation) AddPayAmount(f float64) {
	if m.addpay_amount != nil {
		*m.addpay_amount += f
	} else {
		m.addpay_amount = &f
	}
}

// AddedPayAmount returns the value that was added to the "pay_amount" field in this mutation.
func (m *PaymentOrderMutation) AddedPayAmount() (r float64, exists bool) {
	v := m.addpay_amount
	if v == nil {
		return
	}
	return *v, true
}

// ResetPayAmount resets all changes to the "pay_amount" field.
func (m *PaymentOrderMutation) ResetPayAmount() {
	m.pay_amount = nil
	m.addpay_amount = nil
}

// SetFeeRate sets the "fee_rate" field.
func (m *PaymentOrderMutation) SetFeeRate(f float64) {
	m.fee_rate = &f
	m.addfee_rate = nil
}

// FeeRate returns the value of the "fee_rate" field in the mutation.
func (m *PaymentOrderMutation) FeeRate() (r float64, exists bool) {
	v := m.fee_rate
	if v == nil {
		return
	}
	return *v, true
}

// OldFeeRate returns the old "fee_rate" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldFeeRate(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFeeRate is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFeeRate requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFeeRate: %w", err)
	}
	return oldValue.FeeRate, nil
}

// AddFeeRate adds f to the "fee_rate" field.
func (m *PaymentOrderMutation) AddFeeRate(f float64) {
	if m.addfee_rate != nil {
		*m.addfee_rate += f
	} else {
		m.addfee_rate = &f
	}
}

// AddedFeeRate returns the value that was added to the "fee_rate" field in this mutation.
func (m *PaymentOrderMutation) AddedFeeRate() (r float64, exists bool) {
	v := m.addfee_rate
	if v == nil {
		return
	}
	return *v, true
}

// ResetFeeRate resets all changes to the "fee_rate" field.
func (m *PaymentOrderMutation) ResetFeeRate() {
	m.fee_rate = nil
	m.addfee_rate = nil
}

// SetRechargeCode sets the "recharge_code" field.
func (m *PaymentOrderMutation) SetRechargeCode(s string) {
	m.recharge_code = &s
}

// RechargeCode returns the value of the "recharge_code" field in the mutation.
func (m *PaymentOrderMutation) RechargeCode() (r string, exists bool) {
	v := m.recharge_code
	if v == nil {
		return
	}
	return *v, true
}

// OldRechargeCode returns the old "recharge_code" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldRechargeCode(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRechargeCode is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRechargeCode requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRechargeCode: %w", err)
	}
	return oldValue.RechargeCode, nil
}

// ResetRechargeCode resets all changes to the "recharge_code" field.
func (m *PaymentOrderMutation) ResetRechargeCode() {
	m.recharge_code = nil
}

// SetOutTradeNo sets the "out_trade_no" field.
func (m *PaymentOrderMutation) SetOutTradeNo(s string) {
	m.out_trade_no = &s
}

// OutTradeNo returns the value of the "out_trade_no" field in the mutation.
func (m *PaymentOrderMutation) OutTradeNo() (r string, exists bool) {
	v := m.out_trade_no
	if v == nil {
		return
	}
	return *v, true
}

// OldOutTradeNo returns the old "out_trade_no" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldOutTradeNo(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldOutTradeNo is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldOutTradeNo requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldOutTradeNo: %w", err)
	}
	return oldValue.OutTradeNo, nil
}

// ResetOutTradeNo resets all changes to the "out_trade_no" field.
func (m *PaymentOrderMutation) ResetOutTradeNo() {
	m.out_trade_no = nil
}

// SetPaymentType sets the "payment_type" field.
func (m *PaymentOrderMutation) SetPaymentType(s string) {
	m.payment_type = &s
}

// PaymentType returns the value of the "payment_type" field in the mutation.
func (m *PaymentOrderMutation) PaymentType() (r string, exists bool) {
	v := m.payment_type
	if v == nil {
		return
	}
	return *v, true
}

// OldPaymentType returns the old "payment_type" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldPaymentType(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPaymentType is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPaymentType requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPaymentType: %w", err)
	}
	return oldValue.PaymentType, nil
}

// ResetPaymentType resets all changes to the "payment_type" field.
func (m *PaymentOrderMutation) ResetPaymentType() {
	m.payment_type = nil
}

// SetPaymentTradeNo sets the "payment_trade_no" field.
func (m *PaymentOrderMutation) SetPaymentTradeNo(s string) {
	m.payment_trade_no = &s
}

// PaymentTradeNo returns the value of the "payment_trade_no" field in the mutation.
func (m *PaymentOrderMutation) PaymentTradeNo() (r string, exists bool) {
	v := m.payment_trade_no
	if v == nil {
		return
	}
	return *v, true
}

// OldPaymentTradeNo returns the old "payment_trade_no" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldPaymentTradeNo(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPaymentTradeNo is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPaymentTradeNo requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPaymentTradeNo: %w", err)
	}
	return oldValue.PaymentTradeNo, nil
}

// ResetPaymentTradeNo resets all changes to the "payment_trade_no" field.
func (m *PaymentOrderMutation) ResetPaymentTradeNo() {
	m.payment_trade_no = nil
}

// SetPayURL sets the "pay_url" field.
func (m *PaymentOrderMutation) SetPayURL(s string) {
	m.pay_url = &s
}

// PayURL returns the value of the "pay_url" field in the mutation.
func (m *PaymentOrderMutation) PayURL() (r string, exists bool) {
	v := m.pay_url
	if v == nil {
		return
	}
	return *v, true
}

// OldPayURL returns the old "pay_url" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldPayURL(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPayURL is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPayURL requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPayURL: %w", err)
	}
	return oldValue.PayURL, nil
}

// ClearPayURL clears the value of the "pay_url" field.
func (m *PaymentOrderMutation) ClearPayURL() {
	m.pay_url = nil
	m.clearedFields[paymentorder.FieldPayURL] = struct{}{}
}

// PayURLCleared returns if the "pay_url" field was cleared in this mutation.
func (m *PaymentOrderMutation) PayURLCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldPayURL]
	return ok
}

// ResetPayURL resets all changes to the "pay_url" field.
func (m *PaymentOrderMutation) ResetPayURL() {
	m.pay_url = nil
	delete(m.clearedFields, paymentorder.FieldPayURL)
}

// SetQrCode sets the "qr_code" field.
func (m *PaymentOrderMutation) SetQrCode(s string) {
	m.qr_code = &s
}

// QrCode returns the value of the "qr_code" field in the mutation.
func (m *PaymentOrderMutation) QrCode() (r string, exists bool) {
	v := m.qr_code
	if v == nil {
		return
	}
	return *v, true
}

// OldQrCode returns the old "qr_code" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldQrCode(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldQrCode is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldQrCode requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldQrCode: %w", err)
	}
	return oldValue.QrCode, nil
}

// ClearQrCode clears the value of the "qr_code" field.
func (m *PaymentOrderMutation) ClearQrCode() {
	m.qr_code = nil
	m.clearedFields[paymentorder.FieldQrCode] = struct{}{}
}

// QrCodeCleared returns if the "qr_code" field was cleared in this mutation.
func (m *PaymentOrderMutation) QrCodeCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldQrCode]
	return ok
}

// ResetQrCode resets all changes to the "qr_code" field.
func (m *PaymentOrderMutation) ResetQrCode() {
	m.qr_code = nil
	delete(m.clearedFields, paymentorder.FieldQrCode)
}

// SetQrCodeImg sets the "qr_code_img" field.
func (m *PaymentOrderMutation) SetQrCodeImg(s string) {
	m.qr_code_img = &s
}

// QrCodeImg returns the value of the "qr_code_img" field in the mutation.
func (m *PaymentOrderMutation) QrCodeImg() (r string, exists bool) {
	v := m.qr_code_img
	if v == nil {
		return
	}
	return *v, true
}

// OldQrCodeImg returns the old "qr_code_img" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldQrCodeImg(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldQrCodeImg is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldQrCodeImg requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldQrCodeImg: %w", err)
	}
	return oldValue.QrCodeImg, nil
}

// ClearQrCodeImg clears the value of the "qr_code_img" field.
func (m *PaymentOrderMutation) ClearQrCodeImg() {
	m.qr_code_img = nil
	m.clearedFields[paymentorder.FieldQrCodeImg] = struct{}{}
}

// QrCodeImgCleared returns if the "qr_code_img" field was cleared in this mutation.
func (m *PaymentOrderMutation) QrCodeImgCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldQrCodeImg]
	return ok
}

// ResetQrCodeImg resets all changes to the "qr_code_img" field.
func (m *PaymentOrderMutation) ResetQrCodeImg() {
	m.qr_code_img = nil
	delete(m.clearedFields, paymentorder.FieldQrCodeImg)
}

// SetOrderType sets the "order_type" field.
func (m *PaymentOrderMutation) SetOrderType(s string) {
	m.order_type = &s
}

// OrderType returns the value of the "order_type" field in the mutation.
func (m *PaymentOrderMutation) OrderType() (r string, exists bool) {
	v := m.order_type
	if v == nil {
		return
	}
	return *v, true
}

// OldOrderType returns the old "order_type" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldOrderType(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldOrderType is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldOrderType requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldOrderType: %w", err)
	}
	return oldValue.OrderType, nil
}

// ResetOrderType resets all changes to the "order_type" field.
func (m *PaymentOrderMutation) ResetOrderType() {
	m.order_type = nil
}

// SetPlanID sets the "plan_id" field.
func (m *PaymentOrderMutation) SetPlanID(i int64) {
	m.plan_id = &i
	m.addplan_id = nil
}

// PlanID returns the value of the "plan_id" field in the mutation.
func (m *PaymentOrderMutation) PlanID() (r int64, exists bool) {
	v := m.plan_id
	if v == nil {
		return
	}
	return *v, true
}

// OldPlanID returns the old "plan_id" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldPlanID(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPlanID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPlanID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPlanID: %w", err)
	}
	return oldValue.PlanID, nil
}

// AddPlanID adds i to the "plan_id" field.
func (m *PaymentOrderMutation) AddPlanID(i int64) {
	if m.addplan_id != nil {
		*m.addplan_id += i
	} else {
		m.addplan_id = &i
	}
}

// AddedPlanID returns the value that was added to the "plan_id" field in this mutation.
func (m *PaymentOrderMutation) AddedPlanID() (r int64, exists bool) {
	v := m.addplan_id
	if v == nil {
		return
	}
	return *v, true
}

// ClearPlanID clears the value of the "plan_id" field.
func (m *PaymentOrderMutation) ClearPlanID() {
	m.plan_id = nil
	m.addplan_id = nil
	m.clearedFields[paymentorder.FieldPlanID] = struct{}{}
}

// PlanIDCleared returns if the "plan_id" field was cleared in this mutation.
func (m *PaymentOrderMutation) PlanIDCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldPlanID]
	return ok
}

// ResetPlanID resets all changes to the "plan_id" field.
func (m *PaymentOrderMutation) ResetPlanID() {
	m.plan_id = nil
	m.addplan_id = nil
	delete(m.clearedFields, paymentorder.FieldPlanID)
}

// SetSubscriptionGroupID sets the "subscription_group_id" field.
func (m *PaymentOrderMutation) SetSubscriptionGroupID(i int64) {
	m.subscription_group_id = &i
	m.addsubscription_group_id = nil
}

// SubscriptionGroupID returns the value of the "subscription_group_id" field in the mutation.
func (m *PaymentOrderMutation) SubscriptionGroupID() (r int64, exists bool) {
	v := m.subscription_group_id
	if v == nil {
		return
	}
	return *v, true
}

// OldSubscriptionGroupID returns the old "subscription_group_id" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldSubscriptionGroupID(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSubscriptionGroupID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSubscriptionGroupID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSubscriptionGroupID: %w", err)
	}
	return oldValue.SubscriptionGroupID, nil
}

// AddSubscriptionGroupID adds i to the "subscription_group_id" field.
func (m *PaymentOrderMutation) AddSubscriptionGroupID(i int64) {
	if m.addsubscription_group_id != nil {
		*m.addsubscription_group_id += i
	} else {
		m.addsubscription_group_id = &i
	}
}

// AddedSubscriptionGroupID returns the value that was added to the "subscription_group_id" field in this mutation.
func (m *PaymentOrderMutation) AddedSubscriptionGroupID() (r int64, exists bool) {
	v := m.addsubscription_group_id
	if v == nil {
		return
	}
	return *v, true
}

// ClearSubscriptionGroupID clears the value of the "subscription_group_id" field.
func (m *PaymentOrderMutation) ClearSubscriptionGroupID() {
	m.subscription_group_id = nil
	m.addsubscription_group_id = nil
	m.clearedFields[paymentorder.FieldSubscriptionGroupID] = struct{}{}
}

// SubscriptionGroupIDCleared returns if the "subscription_group_id" field was cleared in this mutation.
func (m *PaymentOrderMutation) SubscriptionGroupIDCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldSubscriptionGroupID]
	return ok
}

// ResetSubscriptionGroupID resets all changes to the "subscription_group_id" field.
func (m *PaymentOrderMutation) ResetSubscriptionGroupID() {
	m.subscription_group_id = nil
	m.addsubscription_group_id = nil
	delete(m.clearedFields, paymentorder.FieldSubscriptionGroupID)
}

// SetSubscriptionDays sets the "subscription_days" field.
func (m *PaymentOrderMutation) SetSubscriptionDays(i int) {
	m.subscription_days = &i
	m.addsubscription_days = nil
}

// SubscriptionDays returns the value of the "subscription_days" field in the mutation.
func (m *PaymentOrderMutation) SubscriptionDays() (r int, exists bool) {
	v := m.subscription_days
	if v == nil {
		return
	}
	return *v, true
}

// OldSubscriptionDays returns the old "subscription_days" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldSubscriptionDays(ctx context.Context) (v *int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSubscriptionDays is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSubscriptionDays requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSubscriptionDays: %w", err)
	}
	return oldValue.SubscriptionDays, nil
}

// AddSubscriptionDays adds i to the "subscription_days" field.
func (m *PaymentOrderMutation) AddSubscriptionDays(i int) {
	if m.addsubscription_days != nil {
		*m.addsubscription_days += i
	} else {
		m.addsubscription_days = &i
	}
}

// AddedSubscriptionDays returns the value that was added to the "subscription_days" field in this mutation.
func (m *PaymentOrderMutation) AddedSubscriptionDays() (r int, exists bool) {
	v := m.addsubscription_days
	if v == nil {
		return
	}
	return *v, true
}

// ClearSubscriptionDays clears the value of the "subscription_days" field.
func (m *PaymentOrderMutation) ClearSubscriptionDays() {
	m.subscription_days = nil
	m.addsubscription_days = nil
	m.clearedFields[paymentorder.FieldSubscriptionDays] = struct{}{}
}

// SubscriptionDaysCleared returns if the "subscription_days" field was cleared in this mutation.
func (m *PaymentOrderMutation) SubscriptionDaysCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldSubscriptionDays]
	return ok
}

// ResetSubscriptionDays resets all changes to the "subscription_days" field.
func (m *PaymentOrderMutation) ResetSubscriptionDays() {
	m.subscription_days = nil
	m.addsubscription_days = nil
	delete(m.clearedFields, paymentorder.FieldSubscriptionDays)
}

// SetProviderInstanceID sets the "provider_instance_id" field.
func (m *PaymentOrderMutation) SetProviderInstanceID(s string) {
	m.provider_instance_id = &s
}

// ProviderInstanceID returns the value of the "provider_instance_id" field in the mutation.
func (m *PaymentOrderMutation) ProviderInstanceID() (r string, exists bool) {
	v := m.provider_instance_id
	if v == nil {
		return
	}
	return *v, true
}

// OldProviderInstanceID returns the old "provider_instance_id" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldProviderInstanceID(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProviderInstanceID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProviderInstanceID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProviderInstanceID: %w", err)
	}
	return oldValue.ProviderInstanceID, nil
}

// ClearProviderInstanceID clears the value of the "provider_instance_id" field.
func (m *PaymentOrderMutation) ClearProviderInstanceID() {
	m.provider_instance_id = nil
	m.clearedFields[paymentorder.FieldProviderInstanceID] = struct{}{}
}

// ProviderInstanceIDCleared returns if the "provider_instance_id" field was cleared in this mutation.
func (m *PaymentOrderMutation) ProviderInstanceIDCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldProviderInstanceID]
	return ok
}

// ResetProviderInstanceID resets all changes to the "provider_instance_id" field.
func (m *PaymentOrderMutation) ResetProviderInstanceID() {
	m.provider_instance_id = nil
	delete(m.clearedFields, paymentorder.FieldProviderInstanceID)
}

// SetProviderKey sets the "provider_key" field.
func (m *PaymentOrderMutation) SetProviderKey(s string) {
	m.provider_key = &s
}

// ProviderKey returns the value of the "provider_key" field in the mutation.
func (m *PaymentOrderMutation) ProviderKey() (r string, exists bool) {
	v := m.provider_key
	if v == nil {
		return
	}
	return *v, true
}

// OldProviderKey returns the old "provider_key" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldProviderKey(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProviderKey is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProviderKey requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProviderKey: %w", err)
	}
	return oldValue.ProviderKey, nil
}

// ClearProviderKey clears the value of the "provider_key" field.
func (m *PaymentOrderMutation) ClearProviderKey() {
	m.provider_key = nil
	m.clearedFields[paymentorder.FieldProviderKey] = struct{}{}
}

// ProviderKeyCleared returns if the "provider_key" field was cleared in this mutation.
func (m *PaymentOrderMutation) ProviderKeyCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldProviderKey]
	return ok
}

// ResetProviderKey resets all changes to the "provider_key" field.
func (m *PaymentOrderMutation) ResetProviderKey() {
	m.provider_key = nil
	delete(m.clearedFields, paymentorder.FieldProviderKey)
}

// SetStatus sets the "status" field.
func (m *PaymentOrderMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *PaymentOrderMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldStatus(ctx context.Context) (v string, 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 *PaymentOrderMutation) ResetStatus() {
	m.status = nil
}

// SetRefundAmount sets the "refund_amount" field.
func (m *PaymentOrderMutation) SetRefundAmount(f float64) {
	m.refund_amount = &f
	m.addrefund_amount = nil
}

// RefundAmount returns the value of the "refund_amount" field in the mutation.
func (m *PaymentOrderMutation) RefundAmount() (r float64, exists bool) {
	v := m.refund_amount
	if v == nil {
		return
	}
	return *v, true
}

// OldRefundAmount returns the old "refund_amount" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldRefundAmount(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRefundAmount is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRefundAmount requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRefundAmount: %w", err)
	}
	return oldValue.RefundAmount, nil
}

// AddRefundAmount adds f to the "refund_amount" field.
func (m *PaymentOrderMutation) AddRefundAmount(f float64) {
	if m.addrefund_amount != nil {
		*m.addrefund_amount += f
	} else {
		m.addrefund_amount = &f
	}
}

// AddedRefundAmount returns the value that was added to the "refund_amount" field in this mutation.
func (m *PaymentOrderMutation) AddedRefundAmount() (r float64, exists bool) {
	v := m.addrefund_amount
	if v == nil {
		return
	}
	return *v, true
}

// ResetRefundAmount resets all changes to the "refund_amount" field.
func (m *PaymentOrderMutation) ResetRefundAmount() {
	m.refund_amount = nil
	m.addrefund_amount = nil
}

// SetRefundReason sets the "refund_reason" field.
func (m *PaymentOrderMutation) SetRefundReason(s string) {
	m.refund_reason = &s
}

// RefundReason returns the value of the "refund_reason" field in the mutation.
func (m *PaymentOrderMutation) RefundReason() (r string, exists bool) {
	v := m.refund_reason
	if v == nil {
		return
	}
	return *v, true
}

// OldRefundReason returns the old "refund_reason" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldRefundReason(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRefundReason is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRefundReason requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRefundReason: %w", err)
	}
	return oldValue.RefundReason, nil
}

// ClearRefundReason clears the value of the "refund_reason" field.
func (m *PaymentOrderMutation) ClearRefundReason() {
	m.refund_reason = nil
	m.clearedFields[paymentorder.FieldRefundReason] = struct{}{}
}

// RefundReasonCleared returns if the "refund_reason" field was cleared in this mutation.
func (m *PaymentOrderMutation) RefundReasonCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldRefundReason]
	return ok
}

// ResetRefundReason resets all changes to the "refund_reason" field.
func (m *PaymentOrderMutation) ResetRefundReason() {
	m.refund_reason = nil
	delete(m.clearedFields, paymentorder.FieldRefundReason)
}

// SetRefundAt sets the "refund_at" field.
func (m *PaymentOrderMutation) SetRefundAt(t time.Time) {
	m.refund_at = &t
}

// RefundAt returns the value of the "refund_at" field in the mutation.
func (m *PaymentOrderMutation) RefundAt() (r time.Time, exists bool) {
	v := m.refund_at
	if v == nil {
		return
	}
	return *v, true
}

// OldRefundAt returns the old "refund_at" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldRefundAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRefundAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRefundAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRefundAt: %w", err)
	}
	return oldValue.RefundAt, nil
}

// ClearRefundAt clears the value of the "refund_at" field.
func (m *PaymentOrderMutation) ClearRefundAt() {
	m.refund_at = nil
	m.clearedFields[paymentorder.FieldRefundAt] = struct{}{}
}

// RefundAtCleared returns if the "refund_at" field was cleared in this mutation.
func (m *PaymentOrderMutation) RefundAtCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldRefundAt]
	return ok
}

// ResetRefundAt resets all changes to the "refund_at" field.
func (m *PaymentOrderMutation) ResetRefundAt() {
	m.refund_at = nil
	delete(m.clearedFields, paymentorder.FieldRefundAt)
}

// SetForceRefund sets the "force_refund" field.
func (m *PaymentOrderMutation) SetForceRefund(b bool) {
	m.force_refund = &b
}

// ForceRefund returns the value of the "force_refund" field in the mutation.
func (m *PaymentOrderMutation) ForceRefund() (r bool, exists bool) {
	v := m.force_refund
	if v == nil {
		return
	}
	return *v, true
}

// OldForceRefund returns the old "force_refund" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldForceRefund(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldForceRefund is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldForceRefund requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldForceRefund: %w", err)
	}
	return oldValue.ForceRefund, nil
}

// ResetForceRefund resets all changes to the "force_refund" field.
func (m *PaymentOrderMutation) ResetForceRefund() {
	m.force_refund = nil
}

// SetRefundRequestedAt sets the "refund_requested_at" field.
func (m *PaymentOrderMutation) SetRefundRequestedAt(t time.Time) {
	m.refund_requested_at = &t
}

// RefundRequestedAt returns the value of the "refund_requested_at" field in the mutation.
func (m *PaymentOrderMutation) RefundRequestedAt() (r time.Time, exists bool) {
	v := m.refund_requested_at
	if v == nil {
		return
	}
	return *v, true
}

// OldRefundRequestedAt returns the old "refund_requested_at" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldRefundRequestedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRefundRequestedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRefundRequestedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRefundRequestedAt: %w", err)
	}
	return oldValue.RefundRequestedAt, nil
}

// ClearRefundRequestedAt clears the value of the "refund_requested_at" field.
func (m *PaymentOrderMutation) ClearRefundRequestedAt() {
	m.refund_requested_at = nil
	m.clearedFields[paymentorder.FieldRefundRequestedAt] = struct{}{}
}

// RefundRequestedAtCleared returns if the "refund_requested_at" field was cleared in this mutation.
func (m *PaymentOrderMutation) RefundRequestedAtCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldRefundRequestedAt]
	return ok
}

// ResetRefundRequestedAt resets all changes to the "refund_requested_at" field.
func (m *PaymentOrderMutation) ResetRefundRequestedAt() {
	m.refund_requested_at = nil
	delete(m.clearedFields, paymentorder.FieldRefundRequestedAt)
}

// SetRefundRequestReason sets the "refund_request_reason" field.
func (m *PaymentOrderMutation) SetRefundRequestReason(s string) {
	m.refund_request_reason = &s
}

// RefundRequestReason returns the value of the "refund_request_reason" field in the mutation.
func (m *PaymentOrderMutation) RefundRequestReason() (r string, exists bool) {
	v := m.refund_request_reason
	if v == nil {
		return
	}
	return *v, true
}

// OldRefundRequestReason returns the old "refund_request_reason" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldRefundRequestReason(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRefundRequestReason is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRefundRequestReason requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRefundRequestReason: %w", err)
	}
	return oldValue.RefundRequestReason, nil
}

// ClearRefundRequestReason clears the value of the "refund_request_reason" field.
func (m *PaymentOrderMutation) ClearRefundRequestReason() {
	m.refund_request_reason = nil
	m.clearedFields[paymentorder.FieldRefundRequestReason] = struct{}{}
}

// RefundRequestReasonCleared returns if the "refund_request_reason" field was cleared in this mutation.
func (m *PaymentOrderMutation) RefundRequestReasonCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldRefundRequestReason]
	return ok
}

// ResetRefundRequestReason resets all changes to the "refund_request_reason" field.
func (m *PaymentOrderMutation) ResetRefundRequestReason() {
	m.refund_request_reason = nil
	delete(m.clearedFields, paymentorder.FieldRefundRequestReason)
}

// SetRefundRequestedBy sets the "refund_requested_by" field.
func (m *PaymentOrderMutation) SetRefundRequestedBy(s string) {
	m.refund_requested_by = &s
}

// RefundRequestedBy returns the value of the "refund_requested_by" field in the mutation.
func (m *PaymentOrderMutation) RefundRequestedBy() (r string, exists bool) {
	v := m.refund_requested_by
	if v == nil {
		return
	}
	return *v, true
}

// OldRefundRequestedBy returns the old "refund_requested_by" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldRefundRequestedBy(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRefundRequestedBy is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRefundRequestedBy requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRefundRequestedBy: %w", err)
	}
	return oldValue.RefundRequestedBy, nil
}

// ClearRefundRequestedBy clears the value of the "refund_requested_by" field.
func (m *PaymentOrderMutation) ClearRefundRequestedBy() {
	m.refund_requested_by = nil
	m.clearedFields[paymentorder.FieldRefundRequestedBy] = struct{}{}
}

// RefundRequestedByCleared returns if the "refund_requested_by" field was cleared in this mutation.
func (m *PaymentOrderMutation) RefundRequestedByCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldRefundRequestedBy]
	return ok
}

// ResetRefundRequestedBy resets all changes to the "refund_requested_by" field.
func (m *PaymentOrderMutation) ResetRefundRequestedBy() {
	m.refund_requested_by = nil
	delete(m.clearedFields, paymentorder.FieldRefundRequestedBy)
}

// SetExpiresAt sets the "expires_at" field.
func (m *PaymentOrderMutation) SetExpiresAt(t time.Time) {
	m.expires_at = &t
}

// ExpiresAt returns the value of the "expires_at" field in the mutation.
func (m *PaymentOrderMutation) ExpiresAt() (r time.Time, exists bool) {
	v := m.expires_at
	if v == nil {
		return
	}
	return *v, true
}

// OldExpiresAt returns the old "expires_at" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldExpiresAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldExpiresAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err)
	}
	return oldValue.ExpiresAt, nil
}

// ResetExpiresAt resets all changes to the "expires_at" field.
func (m *PaymentOrderMutation) ResetExpiresAt() {
	m.expires_at = nil
}

// SetPaidAt sets the "paid_at" field.
func (m *PaymentOrderMutation) SetPaidAt(t time.Time) {
	m.paid_at = &t
}

// PaidAt returns the value of the "paid_at" field in the mutation.
func (m *PaymentOrderMutation) PaidAt() (r time.Time, exists bool) {
	v := m.paid_at
	if v == nil {
		return
	}
	return *v, true
}

// OldPaidAt returns the old "paid_at" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldPaidAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPaidAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPaidAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPaidAt: %w", err)
	}
	return oldValue.PaidAt, nil
}

// ClearPaidAt clears the value of the "paid_at" field.
func (m *PaymentOrderMutation) ClearPaidAt() {
	m.paid_at = nil
	m.clearedFields[paymentorder.FieldPaidAt] = struct{}{}
}

// PaidAtCleared returns if the "paid_at" field was cleared in this mutation.
func (m *PaymentOrderMutation) PaidAtCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldPaidAt]
	return ok
}

// ResetPaidAt resets all changes to the "paid_at" field.
func (m *PaymentOrderMutation) ResetPaidAt() {
	m.paid_at = nil
	delete(m.clearedFields, paymentorder.FieldPaidAt)
}

// SetCompletedAt sets the "completed_at" field.
func (m *PaymentOrderMutation) SetCompletedAt(t time.Time) {
	m.completed_at = &t
}

// CompletedAt returns the value of the "completed_at" field in the mutation.
func (m *PaymentOrderMutation) CompletedAt() (r time.Time, exists bool) {
	v := m.completed_at
	if v == nil {
		return
	}
	return *v, true
}

// OldCompletedAt returns the old "completed_at" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldCompletedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCompletedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCompletedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCompletedAt: %w", err)
	}
	return oldValue.CompletedAt, nil
}

// ClearCompletedAt clears the value of the "completed_at" field.
func (m *PaymentOrderMutation) ClearCompletedAt() {
	m.completed_at = nil
	m.clearedFields[paymentorder.FieldCompletedAt] = struct{}{}
}

// CompletedAtCleared returns if the "completed_at" field was cleared in this mutation.
func (m *PaymentOrderMutation) CompletedAtCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldCompletedAt]
	return ok
}

// ResetCompletedAt resets all changes to the "completed_at" field.
func (m *PaymentOrderMutation) ResetCompletedAt() {
	m.completed_at = nil
	delete(m.clearedFields, paymentorder.FieldCompletedAt)
}

// SetFailedAt sets the "failed_at" field.
func (m *PaymentOrderMutation) SetFailedAt(t time.Time) {
	m.failed_at = &t
}

// FailedAt returns the value of the "failed_at" field in the mutation.
func (m *PaymentOrderMutation) FailedAt() (r time.Time, exists bool) {
	v := m.failed_at
	if v == nil {
		return
	}
	return *v, true
}

// OldFailedAt returns the old "failed_at" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldFailedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFailedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFailedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFailedAt: %w", err)
	}
	return oldValue.FailedAt, nil
}

// ClearFailedAt clears the value of the "failed_at" field.
func (m *PaymentOrderMutation) ClearFailedAt() {
	m.failed_at = nil
	m.clearedFields[paymentorder.FieldFailedAt] = struct{}{}
}

// FailedAtCleared returns if the "failed_at" field was cleared in this mutation.
func (m *PaymentOrderMutation) FailedAtCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldFailedAt]
	return ok
}

// ResetFailedAt resets all changes to the "failed_at" field.
func (m *PaymentOrderMutation) ResetFailedAt() {
	m.failed_at = nil
	delete(m.clearedFields, paymentorder.FieldFailedAt)
}

// SetFailedReason sets the "failed_reason" field.
func (m *PaymentOrderMutation) SetFailedReason(s string) {
	m.failed_reason = &s
}

// FailedReason returns the value of the "failed_reason" field in the mutation.
func (m *PaymentOrderMutation) FailedReason() (r string, exists bool) {
	v := m.failed_reason
	if v == nil {
		return
	}
	return *v, true
}

// OldFailedReason returns the old "failed_reason" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldFailedReason(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFailedReason is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFailedReason requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFailedReason: %w", err)
	}
	return oldValue.FailedReason, nil
}

// ClearFailedReason clears the value of the "failed_reason" field.
func (m *PaymentOrderMutation) ClearFailedReason() {
	m.failed_reason = nil
	m.clearedFields[paymentorder.FieldFailedReason] = struct{}{}
}

// FailedReasonCleared returns if the "failed_reason" field was cleared in this mutation.
func (m *PaymentOrderMutation) FailedReasonCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldFailedReason]
	return ok
}

// ResetFailedReason resets all changes to the "failed_reason" field.
func (m *PaymentOrderMutation) ResetFailedReason() {
	m.failed_reason = nil
	delete(m.clearedFields, paymentorder.FieldFailedReason)
}

// SetClientIP sets the "client_ip" field.
func (m *PaymentOrderMutation) SetClientIP(s string) {
	m.client_ip = &s
}

// ClientIP returns the value of the "client_ip" field in the mutation.
func (m *PaymentOrderMutation) ClientIP() (r string, exists bool) {
	v := m.client_ip
	if v == nil {
		return
	}
	return *v, true
}

// OldClientIP returns the old "client_ip" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldClientIP(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldClientIP is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldClientIP requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldClientIP: %w", err)
	}
	return oldValue.ClientIP, nil
}

// ResetClientIP resets all changes to the "client_ip" field.
func (m *PaymentOrderMutation) ResetClientIP() {
	m.client_ip = nil
}

// SetSrcHost sets the "src_host" field.
func (m *PaymentOrderMutation) SetSrcHost(s string) {
	m.src_host = &s
}

// SrcHost returns the value of the "src_host" field in the mutation.
func (m *PaymentOrderMutation) SrcHost() (r string, exists bool) {
	v := m.src_host
	if v == nil {
		return
	}
	return *v, true
}

// OldSrcHost returns the old "src_host" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldSrcHost(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSrcHost is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSrcHost requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSrcHost: %w", err)
	}
	return oldValue.SrcHost, nil
}

// ResetSrcHost resets all changes to the "src_host" field.
func (m *PaymentOrderMutation) ResetSrcHost() {
	m.src_host = nil
}

// SetSrcURL sets the "src_url" field.
func (m *PaymentOrderMutation) SetSrcURL(s string) {
	m.src_url = &s
}

// SrcURL returns the value of the "src_url" field in the mutation.
func (m *PaymentOrderMutation) SrcURL() (r string, exists bool) {
	v := m.src_url
	if v == nil {
		return
	}
	return *v, true
}

// OldSrcURL returns the old "src_url" field's value of the PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) OldSrcURL(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSrcURL is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSrcURL requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSrcURL: %w", err)
	}
	return oldValue.SrcURL, nil
}

// ClearSrcURL clears the value of the "src_url" field.
func (m *PaymentOrderMutation) ClearSrcURL() {
	m.src_url = nil
	m.clearedFields[paymentorder.FieldSrcURL] = struct{}{}
}

// SrcURLCleared returns if the "src_url" field was cleared in this mutation.
func (m *PaymentOrderMutation) SrcURLCleared() bool {
	_, ok := m.clearedFields[paymentorder.FieldSrcURL]
	return ok
}

// ResetSrcURL resets all changes to the "src_url" field.
func (m *PaymentOrderMutation) ResetSrcURL() {
	m.src_url = nil
	delete(m.clearedFields, paymentorder.FieldSrcURL)
}

// SetCreatedAt sets the "created_at" field.
func (m *PaymentOrderMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *PaymentOrderMutation) 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 PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) 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 *PaymentOrderMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *PaymentOrderMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *PaymentOrderMutation) 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 PaymentOrder entity.
// If the PaymentOrder object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentOrderMutation) 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 *PaymentOrderMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// ClearUser clears the "user" edge to the User entity.
func (m *PaymentOrderMutation) ClearUser() {
	m.cleareduser = true
	m.clearedFields[paymentorder.FieldUserID] = struct{}{}
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *PaymentOrderMutation) UserCleared() bool {
	return m.cleareduser
}

// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *PaymentOrderMutation) UserIDs() (ids []int64) {
	if id := m.user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetUser resets all changes to the "user" edge.
func (m *PaymentOrderMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

// Where appends a list predicates to the PaymentOrderMutation builder.
func (m *PaymentOrderMutation) Where(ps ...predicate.PaymentOrder) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the PaymentOrderMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PaymentOrderMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.PaymentOrder, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *PaymentOrderMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *PaymentOrderMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (PaymentOrder).
func (m *PaymentOrderMutation) 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 *PaymentOrderMutation) Fields() []string {
	fields := make([]string, 0, 38)
	if m.user != nil {
		fields = append(fields, paymentorder.FieldUserID)
	}
	if m.user_email != nil {
		fields = append(fields, paymentorder.FieldUserEmail)
	}
	if m.user_name != nil {
		fields = append(fields, paymentorder.FieldUserName)
	}
	if m.user_notes != nil {
		fields = append(fields, paymentorder.FieldUserNotes)
	}
	if m.amount != nil {
		fields = append(fields, paymentorder.FieldAmount)
	}
	if m.pay_amount != nil {
		fields = append(fields, paymentorder.FieldPayAmount)
	}
	if m.fee_rate != nil {
		fields = append(fields, paymentorder.FieldFeeRate)
	}
	if m.recharge_code != nil {
		fields = append(fields, paymentorder.FieldRechargeCode)
	}
	if m.out_trade_no != nil {
		fields = append(fields, paymentorder.FieldOutTradeNo)
	}
	if m.payment_type != nil {
		fields = append(fields, paymentorder.FieldPaymentType)
	}
	if m.payment_trade_no != nil {
		fields = append(fields, paymentorder.FieldPaymentTradeNo)
	}
	if m.pay_url != nil {
		fields = append(fields, paymentorder.FieldPayURL)
	}
	if m.qr_code != nil {
		fields = append(fields, paymentorder.FieldQrCode)
	}
	if m.qr_code_img != nil {
		fields = append(fields, paymentorder.FieldQrCodeImg)
	}
	if m.order_type != nil {
		fields = append(fields, paymentorder.FieldOrderType)
	}
	if m.plan_id != nil {
		fields = append(fields, paymentorder.FieldPlanID)
	}
	if m.subscription_group_id != nil {
		fields = append(fields, paymentorder.FieldSubscriptionGroupID)
	}
	if m.subscription_days != nil {
		fields = append(fields, paymentorder.FieldSubscriptionDays)
	}
	if m.provider_instance_id != nil {
		fields = append(fields, paymentorder.FieldProviderInstanceID)
	}
	if m.provider_key != nil {
		fields = append(fields, paymentorder.FieldProviderKey)
	}
	if m.status != nil {
		fields = append(fields, paymentorder.FieldStatus)
	}
	if m.refund_amount != nil {
		fields = append(fields, paymentorder.FieldRefundAmount)
	}
	if m.refund_reason != nil {
		fields = append(fields, paymentorder.FieldRefundReason)
	}
	if m.refund_at != nil {
		fields = append(fields, paymentorder.FieldRefundAt)
	}
	if m.force_refund != nil {
		fields = append(fields, paymentorder.FieldForceRefund)
	}
	if m.refund_requested_at != nil {
		fields = append(fields, paymentorder.FieldRefundRequestedAt)
	}
	if m.refund_request_reason != nil {
		fields = append(fields, paymentorder.FieldRefundRequestReason)
	}
	if m.refund_requested_by != nil {
		fields = append(fields, paymentorder.FieldRefundRequestedBy)
	}
	if m.expires_at != nil {
		fields = append(fields, paymentorder.FieldExpiresAt)
	}
	if m.paid_at != nil {
		fields = append(fields, paymentorder.FieldPaidAt)
	}
	if m.completed_at != nil {
		fields = append(fields, paymentorder.FieldCompletedAt)
	}
	if m.failed_at != nil {
		fields = append(fields, paymentorder.FieldFailedAt)
	}
	if m.failed_reason != nil {
		fields = append(fields, paymentorder.FieldFailedReason)
	}
	if m.client_ip != nil {
		fields = append(fields, paymentorder.FieldClientIP)
	}
	if m.src_host != nil {
		fields = append(fields, paymentorder.FieldSrcHost)
	}
	if m.src_url != nil {
		fields = append(fields, paymentorder.FieldSrcURL)
	}
	if m.created_at != nil {
		fields = append(fields, paymentorder.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, paymentorder.FieldUpdatedAt)
	}
	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 *PaymentOrderMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case paymentorder.FieldUserID:
		return m.UserID()
	case paymentorder.FieldUserEmail:
		return m.UserEmail()
	case paymentorder.FieldUserName:
		return m.UserName()
	case paymentorder.FieldUserNotes:
		return m.UserNotes()
	case paymentorder.FieldAmount:
		return m.Amount()
	case paymentorder.FieldPayAmount:
		return m.PayAmount()
	case paymentorder.FieldFeeRate:
		return m.FeeRate()
	case paymentorder.FieldRechargeCode:
		return m.RechargeCode()
	case paymentorder.FieldOutTradeNo:
		return m.OutTradeNo()
	case paymentorder.FieldPaymentType:
		return m.PaymentType()
	case paymentorder.FieldPaymentTradeNo:
		return m.PaymentTradeNo()
	case paymentorder.FieldPayURL:
		return m.PayURL()
	case paymentorder.FieldQrCode:
		return m.QrCode()
	case paymentorder.FieldQrCodeImg:
		return m.QrCodeImg()
	case paymentorder.FieldOrderType:
		return m.OrderType()
	case paymentorder.FieldPlanID:
		return m.PlanID()
	case paymentorder.FieldSubscriptionGroupID:
		return m.SubscriptionGroupID()
	case paymentorder.FieldSubscriptionDays:
		return m.SubscriptionDays()
	case paymentorder.FieldProviderInstanceID:
		return m.ProviderInstanceID()
	case paymentorder.FieldProviderKey:
		return m.ProviderKey()
	case paymentorder.FieldStatus:
		return m.Status()
	case paymentorder.FieldRefundAmount:
		return m.RefundAmount()
	case paymentorder.FieldRefundReason:
		return m.RefundReason()
	case paymentorder.FieldRefundAt:
		return m.RefundAt()
	case paymentorder.FieldForceRefund:
		return m.ForceRefund()
	case paymentorder.FieldRefundRequestedAt:
		return m.RefundRequestedAt()
	case paymentorder.FieldRefundRequestReason:
		return m.RefundRequestReason()
	case paymentorder.FieldRefundRequestedBy:
		return m.RefundRequestedBy()
	case paymentorder.FieldExpiresAt:
		return m.ExpiresAt()
	case paymentorder.FieldPaidAt:
		return m.PaidAt()
	case paymentorder.FieldCompletedAt:
		return m.CompletedAt()
	case paymentorder.FieldFailedAt:
		return m.FailedAt()
	case paymentorder.FieldFailedReason:
		return m.FailedReason()
	case paymentorder.FieldClientIP:
		return m.ClientIP()
	case paymentorder.FieldSrcHost:
		return m.SrcHost()
	case paymentorder.FieldSrcURL:
		return m.SrcURL()
	case paymentorder.FieldCreatedAt:
		return m.CreatedAt()
	case paymentorder.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	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 *PaymentOrderMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case paymentorder.FieldUserID:
		return m.OldUserID(ctx)
	case paymentorder.FieldUserEmail:
		return m.OldUserEmail(ctx)
	case paymentorder.FieldUserName:
		return m.OldUserName(ctx)
	case paymentorder.FieldUserNotes:
		return m.OldUserNotes(ctx)
	case paymentorder.FieldAmount:
		return m.OldAmount(ctx)
	case paymentorder.FieldPayAmount:
		return m.OldPayAmount(ctx)
	case paymentorder.FieldFeeRate:
		return m.OldFeeRate(ctx)
	case paymentorder.FieldRechargeCode:
		return m.OldRechargeCode(ctx)
	case paymentorder.FieldOutTradeNo:
		return m.OldOutTradeNo(ctx)
	case paymentorder.FieldPaymentType:
		return m.OldPaymentType(ctx)
	case paymentorder.FieldPaymentTradeNo:
		return m.OldPaymentTradeNo(ctx)
	case paymentorder.FieldPayURL:
		return m.OldPayURL(ctx)
	case paymentorder.FieldQrCode:
		return m.OldQrCode(ctx)
	case paymentorder.FieldQrCodeImg:
		return m.OldQrCodeImg(ctx)
	case paymentorder.FieldOrderType:
		return m.OldOrderType(ctx)
	case paymentorder.FieldPlanID:
		return m.OldPlanID(ctx)
	case paymentorder.FieldSubscriptionGroupID:
		return m.OldSubscriptionGroupID(ctx)
	case paymentorder.FieldSubscriptionDays:
		return m.OldSubscriptionDays(ctx)
	case paymentorder.FieldProviderInstanceID:
		return m.OldProviderInstanceID(ctx)
	case paymentorder.FieldProviderKey:
		return m.OldProviderKey(ctx)
	case paymentorder.FieldStatus:
		return m.OldStatus(ctx)
	case paymentorder.FieldRefundAmount:
		return m.OldRefundAmount(ctx)
	case paymentorder.FieldRefundReason:
		return m.OldRefundReason(ctx)
	case paymentorder.FieldRefundAt:
		return m.OldRefundAt(ctx)
	case paymentorder.FieldForceRefund:
		return m.OldForceRefund(ctx)
	case paymentorder.FieldRefundRequestedAt:
		return m.OldRefundRequestedAt(ctx)
	case paymentorder.FieldRefundRequestReason:
		return m.OldRefundRequestReason(ctx)
	case paymentorder.FieldRefundRequestedBy:
		return m.OldRefundRequestedBy(ctx)
	case paymentorder.FieldExpiresAt:
		return m.OldExpiresAt(ctx)
	case paymentorder.FieldPaidAt:
		return m.OldPaidAt(ctx)
	case paymentorder.FieldCompletedAt:
		return m.OldCompletedAt(ctx)
	case paymentorder.FieldFailedAt:
		return m.OldFailedAt(ctx)
	case paymentorder.FieldFailedReason:
		return m.OldFailedReason(ctx)
	case paymentorder.FieldClientIP:
		return m.OldClientIP(ctx)
	case paymentorder.FieldSrcHost:
		return m.OldSrcHost(ctx)
	case paymentorder.FieldSrcURL:
		return m.OldSrcURL(ctx)
	case paymentorder.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case paymentorder.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown PaymentOrder 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 *PaymentOrderMutation) SetField(name string, value ent.Value) error {
	switch name {
	case paymentorder.FieldUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserID(v)
		return nil
	case paymentorder.FieldUserEmail:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserEmail(v)
		return nil
	case paymentorder.FieldUserName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserName(v)
		return nil
	case paymentorder.FieldUserNotes:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserNotes(v)
		return nil
	case paymentorder.FieldAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAmount(v)
		return nil
	case paymentorder.FieldPayAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPayAmount(v)
		return nil
	case paymentorder.FieldFeeRate:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFeeRate(v)
		return nil
	case paymentorder.FieldRechargeCode:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRechargeCode(v)
		return nil
	case paymentorder.FieldOutTradeNo:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOutTradeNo(v)
		return nil
	case paymentorder.FieldPaymentType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPaymentType(v)
		return nil
	case paymentorder.FieldPaymentTradeNo:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPaymentTradeNo(v)
		return nil
	case paymentorder.FieldPayURL:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPayURL(v)
		return nil
	case paymentorder.FieldQrCode:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetQrCode(v)
		return nil
	case paymentorder.FieldQrCodeImg:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetQrCodeImg(v)
		return nil
	case paymentorder.FieldOrderType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOrderType(v)
		return nil
	case paymentorder.FieldPlanID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPlanID(v)
		return nil
	case paymentorder.FieldSubscriptionGroupID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSubscriptionGroupID(v)
		return nil
	case paymentorder.FieldSubscriptionDays:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSubscriptionDays(v)
		return nil
	case paymentorder.FieldProviderInstanceID:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProviderInstanceID(v)
		return nil
	case paymentorder.FieldProviderKey:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProviderKey(v)
		return nil
	case paymentorder.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case paymentorder.FieldRefundAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRefundAmount(v)
		return nil
	case paymentorder.FieldRefundReason:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRefundReason(v)
		return nil
	case paymentorder.FieldRefundAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRefundAt(v)
		return nil
	case paymentorder.FieldForceRefund:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetForceRefund(v)
		return nil
	case paymentorder.FieldRefundRequestedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRefundRequestedAt(v)
		return nil
	case paymentorder.FieldRefundRequestReason:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRefundRequestReason(v)
		return nil
	case paymentorder.FieldRefundRequestedBy:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRefundRequestedBy(v)
		return nil
	case paymentorder.FieldExpiresAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetExpiresAt(v)
		return nil
	case paymentorder.FieldPaidAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPaidAt(v)
		return nil
	case paymentorder.FieldCompletedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCompletedAt(v)
		return nil
	case paymentorder.FieldFailedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFailedAt(v)
		return nil
	case paymentorder.FieldFailedReason:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFailedReason(v)
		return nil
	case paymentorder.FieldClientIP:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetClientIP(v)
		return nil
	case paymentorder.FieldSrcHost:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSrcHost(v)
		return nil
	case paymentorder.FieldSrcURL:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSrcURL(v)
		return nil
	case paymentorder.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 paymentorder.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown PaymentOrder field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PaymentOrderMutation) AddedFields() []string {
	var fields []string
	if m.addamount != nil {
		fields = append(fields, paymentorder.FieldAmount)
	}
	if m.addpay_amount != nil {
		fields = append(fields, paymentorder.FieldPayAmount)
	}
	if m.addfee_rate != nil {
		fields = append(fields, paymentorder.FieldFeeRate)
	}
	if m.addplan_id != nil {
		fields = append(fields, paymentorder.FieldPlanID)
	}
	if m.addsubscription_group_id != nil {
		fields = append(fields, paymentorder.FieldSubscriptionGroupID)
	}
	if m.addsubscription_days != nil {
		fields = append(fields, paymentorder.FieldSubscriptionDays)
	}
	if m.addrefund_amount != nil {
		fields = append(fields, paymentorder.FieldRefundAmount)
	}
	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 *PaymentOrderMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case paymentorder.FieldAmount:
		return m.AddedAmount()
	case paymentorder.FieldPayAmount:
		return m.AddedPayAmount()
	case paymentorder.FieldFeeRate:
		return m.AddedFeeRate()
	case paymentorder.FieldPlanID:
		return m.AddedPlanID()
	case paymentorder.FieldSubscriptionGroupID:
		return m.AddedSubscriptionGroupID()
	case paymentorder.FieldSubscriptionDays:
		return m.AddedSubscriptionDays()
	case paymentorder.FieldRefundAmount:
		return m.AddedRefundAmount()
	}
	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 *PaymentOrderMutation) AddField(name string, value ent.Value) error {
	switch name {
	case paymentorder.FieldAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddAmount(v)
		return nil
	case paymentorder.FieldPayAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPayAmount(v)
		return nil
	case paymentorder.FieldFeeRate:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddFeeRate(v)
		return nil
	case paymentorder.FieldPlanID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPlanID(v)
		return nil
	case paymentorder.FieldSubscriptionGroupID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddSubscriptionGroupID(v)
		return nil
	case paymentorder.FieldSubscriptionDays:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddSubscriptionDays(v)
		return nil
	case paymentorder.FieldRefundAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddRefundAmount(v)
		return nil
	}
	return fmt.Errorf("unknown PaymentOrder numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PaymentOrderMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(paymentorder.FieldUserNotes) {
		fields = append(fields, paymentorder.FieldUserNotes)
	}
	if m.FieldCleared(paymentorder.FieldPayURL) {
		fields = append(fields, paymentorder.FieldPayURL)
	}
	if m.FieldCleared(paymentorder.FieldQrCode) {
		fields = append(fields, paymentorder.FieldQrCode)
	}
	if m.FieldCleared(paymentorder.FieldQrCodeImg) {
		fields = append(fields, paymentorder.FieldQrCodeImg)
	}
	if m.FieldCleared(paymentorder.FieldPlanID) {
		fields = append(fields, paymentorder.FieldPlanID)
	}
	if m.FieldCleared(paymentorder.FieldSubscriptionGroupID) {
		fields = append(fields, paymentorder.FieldSubscriptionGroupID)
	}
	if m.FieldCleared(paymentorder.FieldSubscriptionDays) {
		fields = append(fields, paymentorder.FieldSubscriptionDays)
	}
	if m.FieldCleared(paymentorder.FieldProviderInstanceID) {
		fields = append(fields, paymentorder.FieldProviderInstanceID)
	}
	if m.FieldCleared(paymentorder.FieldProviderKey) {
		fields = append(fields, paymentorder.FieldProviderKey)
	}
	if m.FieldCleared(paymentorder.FieldRefundReason) {
		fields = append(fields, paymentorder.FieldRefundReason)
	}
	if m.FieldCleared(paymentorder.FieldRefundAt) {
		fields = append(fields, paymentorder.FieldRefundAt)
	}
	if m.FieldCleared(paymentorder.FieldRefundRequestedAt) {
		fields = append(fields, paymentorder.FieldRefundRequestedAt)
	}
	if m.FieldCleared(paymentorder.FieldRefundRequestReason) {
		fields = append(fields, paymentorder.FieldRefundRequestReason)
	}
	if m.FieldCleared(paymentorder.FieldRefundRequestedBy) {
		fields = append(fields, paymentorder.FieldRefundRequestedBy)
	}
	if m.FieldCleared(paymentorder.FieldPaidAt) {
		fields = append(fields, paymentorder.FieldPaidAt)
	}
	if m.FieldCleared(paymentorder.FieldCompletedAt) {
		fields = append(fields, paymentorder.FieldCompletedAt)
	}
	if m.FieldCleared(paymentorder.FieldFailedAt) {
		fields = append(fields, paymentorder.FieldFailedAt)
	}
	if m.FieldCleared(paymentorder.FieldFailedReason) {
		fields = append(fields, paymentorder.FieldFailedReason)
	}
	if m.FieldCleared(paymentorder.FieldSrcURL) {
		fields = append(fields, paymentorder.FieldSrcURL)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PaymentOrderMutation) 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 *PaymentOrderMutation) ClearField(name string) error {
	switch name {
	case paymentorder.FieldUserNotes:
		m.ClearUserNotes()
		return nil
	case paymentorder.FieldPayURL:
		m.ClearPayURL()
		return nil
	case paymentorder.FieldQrCode:
		m.ClearQrCode()
		return nil
	case paymentorder.FieldQrCodeImg:
		m.ClearQrCodeImg()
		return nil
	case paymentorder.FieldPlanID:
		m.ClearPlanID()
		return nil
	case paymentorder.FieldSubscriptionGroupID:
		m.ClearSubscriptionGroupID()
		return nil
	case paymentorder.FieldSubscriptionDays:
		m.ClearSubscriptionDays()
		return nil
	case paymentorder.FieldProviderInstanceID:
		m.ClearProviderInstanceID()
		return nil
	case paymentorder.FieldProviderKey:
		m.ClearProviderKey()
		return nil
	case paymentorder.FieldRefundReason:
		m.ClearRefundReason()
		return nil
	case paymentorder.FieldRefundAt:
		m.ClearRefundAt()
		return nil
	case paymentorder.FieldRefundRequestedAt:
		m.ClearRefundRequestedAt()
		return nil
	case paymentorder.FieldRefundRequestReason:
		m.ClearRefundRequestReason()
		return nil
	case paymentorder.FieldRefundRequestedBy:
		m.ClearRefundRequestedBy()
		return nil
	case paymentorder.FieldPaidAt:
		m.ClearPaidAt()
		return nil
	case paymentorder.FieldCompletedAt:
		m.ClearCompletedAt()
		return nil
	case paymentorder.FieldFailedAt:
		m.ClearFailedAt()
		return nil
	case paymentorder.FieldFailedReason:
		m.ClearFailedReason()
		return nil
	case paymentorder.FieldSrcURL:
		m.ClearSrcURL()
		return nil
	}
	return fmt.Errorf("unknown PaymentOrder 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 *PaymentOrderMutation) ResetField(name string) error {
	switch name {
	case paymentorder.FieldUserID:
		m.ResetUserID()
		return nil
	case paymentorder.FieldUserEmail:
		m.ResetUserEmail()
		return nil
	case paymentorder.FieldUserName:
		m.ResetUserName()
		return nil
	case paymentorder.FieldUserNotes:
		m.ResetUserNotes()
		return nil
	case paymentorder.FieldAmount:
		m.ResetAmount()
		return nil
	case paymentorder.FieldPayAmount:
		m.ResetPayAmount()
		return nil
	case paymentorder.FieldFeeRate:
		m.ResetFeeRate()
		return nil
	case paymentorder.FieldRechargeCode:
		m.ResetRechargeCode()
		return nil
	case paymentorder.FieldOutTradeNo:
		m.ResetOutTradeNo()
		return nil
	case paymentorder.FieldPaymentType:
		m.ResetPaymentType()
		return nil
	case paymentorder.FieldPaymentTradeNo:
		m.ResetPaymentTradeNo()
		return nil
	case paymentorder.FieldPayURL:
		m.ResetPayURL()
		return nil
	case paymentorder.FieldQrCode:
		m.ResetQrCode()
		return nil
	case paymentorder.FieldQrCodeImg:
		m.ResetQrCodeImg()
		return nil
	case paymentorder.FieldOrderType:
		m.ResetOrderType()
		return nil
	case paymentorder.FieldPlanID:
		m.ResetPlanID()
		return nil
	case paymentorder.FieldSubscriptionGroupID:
		m.ResetSubscriptionGroupID()
		return nil
	case paymentorder.FieldSubscriptionDays:
		m.ResetSubscriptionDays()
		return nil
	case paymentorder.FieldProviderInstanceID:
		m.ResetProviderInstanceID()
		return nil
	case paymentorder.FieldProviderKey:
		m.ResetProviderKey()
		return nil
	case paymentorder.FieldStatus:
		m.ResetStatus()
		return nil
	case paymentorder.FieldRefundAmount:
		m.ResetRefundAmount()
		return nil
	case paymentorder.FieldRefundReason:
		m.ResetRefundReason()
		return nil
	case paymentorder.FieldRefundAt:
		m.ResetRefundAt()
		return nil
	case paymentorder.FieldForceRefund:
		m.ResetForceRefund()
		return nil
	case paymentorder.FieldRefundRequestedAt:
		m.ResetRefundRequestedAt()
		return nil
	case paymentorder.FieldRefundRequestReason:
		m.ResetRefundRequestReason()
		return nil
	case paymentorder.FieldRefundRequestedBy:
		m.ResetRefundRequestedBy()
		return nil
	case paymentorder.FieldExpiresAt:
		m.ResetExpiresAt()
		return nil
	case paymentorder.FieldPaidAt:
		m.ResetPaidAt()
		return nil
	case paymentorder.FieldCompletedAt:
		m.ResetCompletedAt()
		return nil
	case paymentorder.FieldFailedAt:
		m.ResetFailedAt()
		return nil
	case paymentorder.FieldFailedReason:
		m.ResetFailedReason()
		return nil
	case paymentorder.FieldClientIP:
		m.ResetClientIP()
		return nil
	case paymentorder.FieldSrcHost:
		m.ResetSrcHost()
		return nil
	case paymentorder.FieldSrcURL:
		m.ResetSrcURL()
		return nil
	case paymentorder.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case paymentorder.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown PaymentOrder field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PaymentOrderMutation) AddedEdges() []string {
	edges := make([]string, 0, 1)
	if m.user != nil {
		edges = append(edges, paymentorder.EdgeUser)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PaymentOrderMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case paymentorder.EdgeUser:
		if id := m.user; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PaymentOrderMutation) 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 *PaymentOrderMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PaymentOrderMutation) ClearedEdges() []string {
	edges := make([]string, 0, 1)
	if m.cleareduser {
		edges = append(edges, paymentorder.EdgeUser)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PaymentOrderMutation) EdgeCleared(name string) bool {
	switch name {
	case paymentorder.EdgeUser:
		return m.cleareduser
	}
	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 *PaymentOrderMutation) ClearEdge(name string) error {
	switch name {
	case paymentorder.EdgeUser:
		m.ClearUser()
		return nil
	}
	return fmt.Errorf("unknown PaymentOrder 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 *PaymentOrderMutation) ResetEdge(name string) error {
	switch name {
	case paymentorder.EdgeUser:
		m.ResetUser()
		return nil
	}
	return fmt.Errorf("unknown PaymentOrder edge %s", name)
}

// PaymentProviderInstanceMutation represents an operation that mutates the PaymentProviderInstance nodes in the graph.
type PaymentProviderInstanceMutation struct {
	config
	op                Op
	typ               string
	id                *int64
	provider_key      *string
	name              *string
	_config           *string
	supported_types   *string
	enabled           *bool
	payment_mode      *string
	sort_order        *int
	addsort_order     *int
	limits            *string
	refund_enabled    *bool
	allow_user_refund *bool
	created_at        *time.Time
	updated_at        *time.Time
	clearedFields     map[string]struct{}
	done              bool
	oldValue          func(context.Context) (*PaymentProviderInstance, error)
	predicates        []predicate.PaymentProviderInstance
}

var _ ent.Mutation = (*PaymentProviderInstanceMutation)(nil)

// paymentproviderinstanceOption allows management of the mutation configuration using functional options.
type paymentproviderinstanceOption func(*PaymentProviderInstanceMutation)

// newPaymentProviderInstanceMutation creates new mutation for the PaymentProviderInstance entity.
func newPaymentProviderInstanceMutation(c config, op Op, opts ...paymentproviderinstanceOption) *PaymentProviderInstanceMutation {
	m := &PaymentProviderInstanceMutation{
		config:        c,
		op:            op,
		typ:           TypePaymentProviderInstance,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withPaymentProviderInstanceID sets the ID field of the mutation.
func withPaymentProviderInstanceID(id int64) paymentproviderinstanceOption {
	return func(m *PaymentProviderInstanceMutation) {
		var (
			err   error
			once  sync.Once
			value *PaymentProviderInstance
		)
		m.oldValue = func(ctx context.Context) (*PaymentProviderInstance, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().PaymentProviderInstance.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withPaymentProviderInstance sets the old PaymentProviderInstance of the mutation.
func withPaymentProviderInstance(node *PaymentProviderInstance) paymentproviderinstanceOption {
	return func(m *PaymentProviderInstanceMutation) {
		m.oldValue = func(context.Context) (*PaymentProviderInstance, 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 PaymentProviderInstanceMutation) 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 PaymentProviderInstanceMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *PaymentProviderInstanceMutation) ID() (id int64, 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 *PaymentProviderInstanceMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().PaymentProviderInstance.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetProviderKey sets the "provider_key" field.
func (m *PaymentProviderInstanceMutation) SetProviderKey(s string) {
	m.provider_key = &s
}

// ProviderKey returns the value of the "provider_key" field in the mutation.
func (m *PaymentProviderInstanceMutation) ProviderKey() (r string, exists bool) {
	v := m.provider_key
	if v == nil {
		return
	}
	return *v, true
}

// OldProviderKey returns the old "provider_key" field's value of the PaymentProviderInstance entity.
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentProviderInstanceMutation) OldProviderKey(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProviderKey is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProviderKey requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProviderKey: %w", err)
	}
	return oldValue.ProviderKey, nil
}

// ResetProviderKey resets all changes to the "provider_key" field.
func (m *PaymentProviderInstanceMutation) ResetProviderKey() {
	m.provider_key = nil
}

// SetName sets the "name" field.
func (m *PaymentProviderInstanceMutation) SetName(s string) {
	m.name = &s
}

// Name returns the value of the "name" field in the mutation.
func (m *PaymentProviderInstanceMutation) 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 PaymentProviderInstance entity.
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentProviderInstanceMutation) 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 *PaymentProviderInstanceMutation) ResetName() {
	m.name = nil
}

// SetConfig sets the "config" field.
func (m *PaymentProviderInstanceMutation) SetConfig(s string) {
	m._config = &s
}

// Config returns the value of the "config" field in the mutation.
func (m *PaymentProviderInstanceMutation) Config() (r string, exists bool) {
	v := m._config
	if v == nil {
		return
	}
	return *v, true
}

// OldConfig returns the old "config" field's value of the PaymentProviderInstance entity.
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentProviderInstanceMutation) OldConfig(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldConfig is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldConfig requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldConfig: %w", err)
	}
	return oldValue.Config, nil
}

// ResetConfig resets all changes to the "config" field.
func (m *PaymentProviderInstanceMutation) ResetConfig() {
	m._config = nil
}

// SetSupportedTypes sets the "supported_types" field.
func (m *PaymentProviderInstanceMutation) SetSupportedTypes(s string) {
	m.supported_types = &s
}

// SupportedTypes returns the value of the "supported_types" field in the mutation.
func (m *PaymentProviderInstanceMutation) SupportedTypes() (r string, exists bool) {
	v := m.supported_types
	if v == nil {
		return
	}
	return *v, true
}

// OldSupportedTypes returns the old "supported_types" field's value of the PaymentProviderInstance entity.
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentProviderInstanceMutation) OldSupportedTypes(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSupportedTypes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSupportedTypes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSupportedTypes: %w", err)
	}
	return oldValue.SupportedTypes, nil
}

// ResetSupportedTypes resets all changes to the "supported_types" field.
func (m *PaymentProviderInstanceMutation) ResetSupportedTypes() {
	m.supported_types = nil
}

// SetEnabled sets the "enabled" field.
func (m *PaymentProviderInstanceMutation) SetEnabled(b bool) {
	m.enabled = &b
}

// Enabled returns the value of the "enabled" field in the mutation.
func (m *PaymentProviderInstanceMutation) Enabled() (r bool, exists bool) {
	v := m.enabled
	if v == nil {
		return
	}
	return *v, true
}

// OldEnabled returns the old "enabled" field's value of the PaymentProviderInstance entity.
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentProviderInstanceMutation) OldEnabled(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldEnabled is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldEnabled requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldEnabled: %w", err)
	}
	return oldValue.Enabled, nil
}

// ResetEnabled resets all changes to the "enabled" field.
func (m *PaymentProviderInstanceMutation) ResetEnabled() {
	m.enabled = nil
}

// SetPaymentMode sets the "payment_mode" field.
func (m *PaymentProviderInstanceMutation) SetPaymentMode(s string) {
	m.payment_mode = &s
}

// PaymentMode returns the value of the "payment_mode" field in the mutation.
func (m *PaymentProviderInstanceMutation) PaymentMode() (r string, exists bool) {
	v := m.payment_mode
	if v == nil {
		return
	}
	return *v, true
}

// OldPaymentMode returns the old "payment_mode" field's value of the PaymentProviderInstance entity.
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentProviderInstanceMutation) OldPaymentMode(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPaymentMode is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPaymentMode requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPaymentMode: %w", err)
	}
	return oldValue.PaymentMode, nil
}

// ResetPaymentMode resets all changes to the "payment_mode" field.
func (m *PaymentProviderInstanceMutation) ResetPaymentMode() {
	m.payment_mode = nil
}

// SetSortOrder sets the "sort_order" field.
func (m *PaymentProviderInstanceMutation) SetSortOrder(i int) {
	m.sort_order = &i
	m.addsort_order = nil
}

// SortOrder returns the value of the "sort_order" field in the mutation.
func (m *PaymentProviderInstanceMutation) SortOrder() (r int, exists bool) {
	v := m.sort_order
	if v == nil {
		return
	}
	return *v, true
}

// OldSortOrder returns the old "sort_order" field's value of the PaymentProviderInstance entity.
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentProviderInstanceMutation) OldSortOrder(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSortOrder is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSortOrder requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSortOrder: %w", err)
	}
	return oldValue.SortOrder, nil
}

// AddSortOrder adds i to the "sort_order" field.
func (m *PaymentProviderInstanceMutation) AddSortOrder(i int) {
	if m.addsort_order != nil {
		*m.addsort_order += i
	} else {
		m.addsort_order = &i
	}
}

// AddedSortOrder returns the value that was added to the "sort_order" field in this mutation.
func (m *PaymentProviderInstanceMutation) AddedSortOrder() (r int, exists bool) {
	v := m.addsort_order
	if v == nil {
		return
	}
	return *v, true
}

// ResetSortOrder resets all changes to the "sort_order" field.
func (m *PaymentProviderInstanceMutation) ResetSortOrder() {
	m.sort_order = nil
	m.addsort_order = nil
}

// SetLimits sets the "limits" field.
func (m *PaymentProviderInstanceMutation) SetLimits(s string) {
	m.limits = &s
}

// Limits returns the value of the "limits" field in the mutation.
func (m *PaymentProviderInstanceMutation) Limits() (r string, exists bool) {
	v := m.limits
	if v == nil {
		return
	}
	return *v, true
}

// OldLimits returns the old "limits" field's value of the PaymentProviderInstance entity.
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentProviderInstanceMutation) OldLimits(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLimits is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLimits requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLimits: %w", err)
	}
	return oldValue.Limits, nil
}

// ResetLimits resets all changes to the "limits" field.
func (m *PaymentProviderInstanceMutation) ResetLimits() {
	m.limits = nil
}

// SetRefundEnabled sets the "refund_enabled" field.
func (m *PaymentProviderInstanceMutation) SetRefundEnabled(b bool) {
	m.refund_enabled = &b
}

// RefundEnabled returns the value of the "refund_enabled" field in the mutation.
func (m *PaymentProviderInstanceMutation) RefundEnabled() (r bool, exists bool) {
	v := m.refund_enabled
	if v == nil {
		return
	}
	return *v, true
}

// OldRefundEnabled returns the old "refund_enabled" field's value of the PaymentProviderInstance entity.
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentProviderInstanceMutation) OldRefundEnabled(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRefundEnabled is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRefundEnabled requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRefundEnabled: %w", err)
	}
	return oldValue.RefundEnabled, nil
}

// ResetRefundEnabled resets all changes to the "refund_enabled" field.
func (m *PaymentProviderInstanceMutation) ResetRefundEnabled() {
	m.refund_enabled = nil
}

// SetAllowUserRefund sets the "allow_user_refund" field.
func (m *PaymentProviderInstanceMutation) SetAllowUserRefund(b bool) {
	m.allow_user_refund = &b
}

// AllowUserRefund returns the value of the "allow_user_refund" field in the mutation.
func (m *PaymentProviderInstanceMutation) AllowUserRefund() (r bool, exists bool) {
	v := m.allow_user_refund
	if v == nil {
		return
	}
	return *v, true
}

// OldAllowUserRefund returns the old "allow_user_refund" field's value of the PaymentProviderInstance entity.
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentProviderInstanceMutation) OldAllowUserRefund(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAllowUserRefund is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAllowUserRefund requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAllowUserRefund: %w", err)
	}
	return oldValue.AllowUserRefund, nil
}

// ResetAllowUserRefund resets all changes to the "allow_user_refund" field.
func (m *PaymentProviderInstanceMutation) ResetAllowUserRefund() {
	m.allow_user_refund = nil
}

// SetCreatedAt sets the "created_at" field.
func (m *PaymentProviderInstanceMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *PaymentProviderInstanceMutation) 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 PaymentProviderInstance entity.
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentProviderInstanceMutation) 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 *PaymentProviderInstanceMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *PaymentProviderInstanceMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *PaymentProviderInstanceMutation) 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 PaymentProviderInstance entity.
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PaymentProviderInstanceMutation) 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 *PaymentProviderInstanceMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// Where appends a list predicates to the PaymentProviderInstanceMutation builder.
func (m *PaymentProviderInstanceMutation) Where(ps ...predicate.PaymentProviderInstance) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the PaymentProviderInstanceMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PaymentProviderInstanceMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.PaymentProviderInstance, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *PaymentProviderInstanceMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *PaymentProviderInstanceMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (PaymentProviderInstance).
func (m *PaymentProviderInstanceMutation) 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 *PaymentProviderInstanceMutation) Fields() []string {
	fields := make([]string, 0, 12)
	if m.provider_key != nil {
		fields = append(fields, paymentproviderinstance.FieldProviderKey)
	}
	if m.name != nil {
		fields = append(fields, paymentproviderinstance.FieldName)
	}
	if m._config != nil {
		fields = append(fields, paymentproviderinstance.FieldConfig)
	}
	if m.supported_types != nil {
		fields = append(fields, paymentproviderinstance.FieldSupportedTypes)
	}
	if m.enabled != nil {
		fields = append(fields, paymentproviderinstance.FieldEnabled)
	}
	if m.payment_mode != nil {
		fields = append(fields, paymentproviderinstance.FieldPaymentMode)
	}
	if m.sort_order != nil {
		fields = append(fields, paymentproviderinstance.FieldSortOrder)
	}
	if m.limits != nil {
		fields = append(fields, paymentproviderinstance.FieldLimits)
	}
	if m.refund_enabled != nil {
		fields = append(fields, paymentproviderinstance.FieldRefundEnabled)
	}
	if m.allow_user_refund != nil {
		fields = append(fields, paymentproviderinstance.FieldAllowUserRefund)
	}
	if m.created_at != nil {
		fields = append(fields, paymentproviderinstance.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, paymentproviderinstance.FieldUpdatedAt)
	}
	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 *PaymentProviderInstanceMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case paymentproviderinstance.FieldProviderKey:
		return m.ProviderKey()
	case paymentproviderinstance.FieldName:
		return m.Name()
	case paymentproviderinstance.FieldConfig:
		return m.Config()
	case paymentproviderinstance.FieldSupportedTypes:
		return m.SupportedTypes()
	case paymentproviderinstance.FieldEnabled:
		return m.Enabled()
	case paymentproviderinstance.FieldPaymentMode:
		return m.PaymentMode()
	case paymentproviderinstance.FieldSortOrder:
		return m.SortOrder()
	case paymentproviderinstance.FieldLimits:
		return m.Limits()
	case paymentproviderinstance.FieldRefundEnabled:
		return m.RefundEnabled()
	case paymentproviderinstance.FieldAllowUserRefund:
		return m.AllowUserRefund()
	case paymentproviderinstance.FieldCreatedAt:
		return m.CreatedAt()
	case paymentproviderinstance.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	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 *PaymentProviderInstanceMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case paymentproviderinstance.FieldProviderKey:
		return m.OldProviderKey(ctx)
	case paymentproviderinstance.FieldName:
		return m.OldName(ctx)
	case paymentproviderinstance.FieldConfig:
		return m.OldConfig(ctx)
	case paymentproviderinstance.FieldSupportedTypes:
		return m.OldSupportedTypes(ctx)
	case paymentproviderinstance.FieldEnabled:
		return m.OldEnabled(ctx)
	case paymentproviderinstance.FieldPaymentMode:
		return m.OldPaymentMode(ctx)
	case paymentproviderinstance.FieldSortOrder:
		return m.OldSortOrder(ctx)
	case paymentproviderinstance.FieldLimits:
		return m.OldLimits(ctx)
	case paymentproviderinstance.FieldRefundEnabled:
		return m.OldRefundEnabled(ctx)
	case paymentproviderinstance.FieldAllowUserRefund:
		return m.OldAllowUserRefund(ctx)
	case paymentproviderinstance.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case paymentproviderinstance.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown PaymentProviderInstance 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 *PaymentProviderInstanceMutation) SetField(name string, value ent.Value) error {
	switch name {
	case paymentproviderinstance.FieldProviderKey:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProviderKey(v)
		return nil
	case paymentproviderinstance.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case paymentproviderinstance.FieldConfig:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetConfig(v)
		return nil
	case paymentproviderinstance.FieldSupportedTypes:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSupportedTypes(v)
		return nil
	case paymentproviderinstance.FieldEnabled:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEnabled(v)
		return nil
	case paymentproviderinstance.FieldPaymentMode:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPaymentMode(v)
		return nil
	case paymentproviderinstance.FieldSortOrder:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSortOrder(v)
		return nil
	case paymentproviderinstance.FieldLimits:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLimits(v)
		return nil
	case paymentproviderinstance.FieldRefundEnabled:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRefundEnabled(v)
		return nil
	case paymentproviderinstance.FieldAllowUserRefund:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAllowUserRefund(v)
		return nil
	case paymentproviderinstance.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 paymentproviderinstance.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown PaymentProviderInstance field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PaymentProviderInstanceMutation) AddedFields() []string {
	var fields []string
	if m.addsort_order != nil {
		fields = append(fields, paymentproviderinstance.FieldSortOrder)
	}
	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 *PaymentProviderInstanceMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case paymentproviderinstance.FieldSortOrder:
		return m.AddedSortOrder()
	}
	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 *PaymentProviderInstanceMutation) AddField(name string, value ent.Value) error {
	switch name {
	case paymentproviderinstance.FieldSortOrder:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddSortOrder(v)
		return nil
	}
	return fmt.Errorf("unknown PaymentProviderInstance numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PaymentProviderInstanceMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PaymentProviderInstanceMutation) 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 *PaymentProviderInstanceMutation) ClearField(name string) error {
	return fmt.Errorf("unknown PaymentProviderInstance 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 *PaymentProviderInstanceMutation) ResetField(name string) error {
	switch name {
	case paymentproviderinstance.FieldProviderKey:
		m.ResetProviderKey()
		return nil
	case paymentproviderinstance.FieldName:
		m.ResetName()
		return nil
	case paymentproviderinstance.FieldConfig:
		m.ResetConfig()
		return nil
	case paymentproviderinstance.FieldSupportedTypes:
		m.ResetSupportedTypes()
		return nil
	case paymentproviderinstance.FieldEnabled:
		m.ResetEnabled()
		return nil
	case paymentproviderinstance.FieldPaymentMode:
		m.ResetPaymentMode()
		return nil
	case paymentproviderinstance.FieldSortOrder:
		m.ResetSortOrder()
		return nil
	case paymentproviderinstance.FieldLimits:
		m.ResetLimits()
		return nil
	case paymentproviderinstance.FieldRefundEnabled:
		m.ResetRefundEnabled()
		return nil
	case paymentproviderinstance.FieldAllowUserRefund:
		m.ResetAllowUserRefund()
		return nil
	case paymentproviderinstance.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case paymentproviderinstance.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown PaymentProviderInstance field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PaymentProviderInstanceMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PaymentProviderInstanceMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PaymentProviderInstanceMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *PaymentProviderInstanceMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PaymentProviderInstanceMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PaymentProviderInstanceMutation) EdgeCleared(name string) bool {
	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 *PaymentProviderInstanceMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown PaymentProviderInstance 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 *PaymentProviderInstanceMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown PaymentProviderInstance edge %s", name)
}

// PendingAuthSessionMutation represents an operation that mutates the PendingAuthSession nodes in the graph.
type PendingAuthSessionMutation struct {
	config
	op                         Op
	typ                        string
	id                         *int64
	created_at                 *time.Time
	updated_at                 *time.Time
	session_token              *string
	intent                     *string
	provider_type              *string
	provider_key               *string
	provider_subject           *string
	redirect_to                *string
	resolved_email             *string
	registration_password_hash *string
	upstream_identity_claims   *map[string]interface{}
	local_flow_state           *map[string]interface{}
	browser_session_key        *string
	completion_code_hash       *string
	completion_code_expires_at *time.Time
	email_verified_at          *time.Time
	password_verified_at       *time.Time
	totp_verified_at           *time.Time
	expires_at                 *time.Time
	consumed_at                *time.Time
	clearedFields              map[string]struct{}
	target_user                *int64
	clearedtarget_user         bool
	adoption_decision          *int64
	clearedadoption_decision   bool
	done                       bool
	oldValue                   func(context.Context) (*PendingAuthSession, error)
	predicates                 []predicate.PendingAuthSession
}

var _ ent.Mutation = (*PendingAuthSessionMutation)(nil)

// pendingauthsessionOption allows management of the mutation configuration using functional options.
type pendingauthsessionOption func(*PendingAuthSessionMutation)

// newPendingAuthSessionMutation creates new mutation for the PendingAuthSession entity.
func newPendingAuthSessionMutation(c config, op Op, opts ...pendingauthsessionOption) *PendingAuthSessionMutation {
	m := &PendingAuthSessionMutation{
		config:        c,
		op:            op,
		typ:           TypePendingAuthSession,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withPendingAuthSessionID sets the ID field of the mutation.
func withPendingAuthSessionID(id int64) pendingauthsessionOption {
	return func(m *PendingAuthSessionMutation) {
		var (
			err   error
			once  sync.Once
			value *PendingAuthSession
		)
		m.oldValue = func(ctx context.Context) (*PendingAuthSession, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().PendingAuthSession.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withPendingAuthSession sets the old PendingAuthSession of the mutation.
func withPendingAuthSession(node *PendingAuthSession) pendingauthsessionOption {
	return func(m *PendingAuthSessionMutation) {
		m.oldValue = func(context.Context) (*PendingAuthSession, 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 PendingAuthSessionMutation) 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 PendingAuthSessionMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *PendingAuthSessionMutation) ID() (id int64, 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 *PendingAuthSessionMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().PendingAuthSession.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *PendingAuthSessionMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *PendingAuthSessionMutation) 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 PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) 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 *PendingAuthSessionMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *PendingAuthSessionMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *PendingAuthSessionMutation) 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 PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) 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 *PendingAuthSessionMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetSessionToken sets the "session_token" field.
func (m *PendingAuthSessionMutation) SetSessionToken(s string) {
	m.session_token = &s
}

// SessionToken returns the value of the "session_token" field in the mutation.
func (m *PendingAuthSessionMutation) SessionToken() (r string, exists bool) {
	v := m.session_token
	if v == nil {
		return
	}
	return *v, true
}

// OldSessionToken returns the old "session_token" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldSessionToken(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSessionToken is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSessionToken requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSessionToken: %w", err)
	}
	return oldValue.SessionToken, nil
}

// ResetSessionToken resets all changes to the "session_token" field.
func (m *PendingAuthSessionMutation) ResetSessionToken() {
	m.session_token = nil
}

// SetIntent sets the "intent" field.
func (m *PendingAuthSessionMutation) SetIntent(s string) {
	m.intent = &s
}

// Intent returns the value of the "intent" field in the mutation.
func (m *PendingAuthSessionMutation) Intent() (r string, exists bool) {
	v := m.intent
	if v == nil {
		return
	}
	return *v, true
}

// OldIntent returns the old "intent" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldIntent(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldIntent is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldIntent requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldIntent: %w", err)
	}
	return oldValue.Intent, nil
}

// ResetIntent resets all changes to the "intent" field.
func (m *PendingAuthSessionMutation) ResetIntent() {
	m.intent = nil
}

// SetProviderType sets the "provider_type" field.
func (m *PendingAuthSessionMutation) SetProviderType(s string) {
	m.provider_type = &s
}

// ProviderType returns the value of the "provider_type" field in the mutation.
func (m *PendingAuthSessionMutation) ProviderType() (r string, exists bool) {
	v := m.provider_type
	if v == nil {
		return
	}
	return *v, true
}

// OldProviderType returns the old "provider_type" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldProviderType(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProviderType is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProviderType requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProviderType: %w", err)
	}
	return oldValue.ProviderType, nil
}

// ResetProviderType resets all changes to the "provider_type" field.
func (m *PendingAuthSessionMutation) ResetProviderType() {
	m.provider_type = nil
}

// SetProviderKey sets the "provider_key" field.
func (m *PendingAuthSessionMutation) SetProviderKey(s string) {
	m.provider_key = &s
}

// ProviderKey returns the value of the "provider_key" field in the mutation.
func (m *PendingAuthSessionMutation) ProviderKey() (r string, exists bool) {
	v := m.provider_key
	if v == nil {
		return
	}
	return *v, true
}

// OldProviderKey returns the old "provider_key" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldProviderKey(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProviderKey is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProviderKey requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProviderKey: %w", err)
	}
	return oldValue.ProviderKey, nil
}

// ResetProviderKey resets all changes to the "provider_key" field.
func (m *PendingAuthSessionMutation) ResetProviderKey() {
	m.provider_key = nil
}

// SetProviderSubject sets the "provider_subject" field.
func (m *PendingAuthSessionMutation) SetProviderSubject(s string) {
	m.provider_subject = &s
}

// ProviderSubject returns the value of the "provider_subject" field in the mutation.
func (m *PendingAuthSessionMutation) ProviderSubject() (r string, exists bool) {
	v := m.provider_subject
	if v == nil {
		return
	}
	return *v, true
}

// OldProviderSubject returns the old "provider_subject" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldProviderSubject(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProviderSubject is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProviderSubject requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProviderSubject: %w", err)
	}
	return oldValue.ProviderSubject, nil
}

// ResetProviderSubject resets all changes to the "provider_subject" field.
func (m *PendingAuthSessionMutation) ResetProviderSubject() {
	m.provider_subject = nil
}

// SetTargetUserID sets the "target_user_id" field.
func (m *PendingAuthSessionMutation) SetTargetUserID(i int64) {
	m.target_user = &i
}

// TargetUserID returns the value of the "target_user_id" field in the mutation.
func (m *PendingAuthSessionMutation) TargetUserID() (r int64, exists bool) {
	v := m.target_user
	if v == nil {
		return
	}
	return *v, true
}

// OldTargetUserID returns the old "target_user_id" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldTargetUserID(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTargetUserID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTargetUserID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTargetUserID: %w", err)
	}
	return oldValue.TargetUserID, nil
}

// ClearTargetUserID clears the value of the "target_user_id" field.
func (m *PendingAuthSessionMutation) ClearTargetUserID() {
	m.target_user = nil
	m.clearedFields[pendingauthsession.FieldTargetUserID] = struct{}{}
}

// TargetUserIDCleared returns if the "target_user_id" field was cleared in this mutation.
func (m *PendingAuthSessionMutation) TargetUserIDCleared() bool {
	_, ok := m.clearedFields[pendingauthsession.FieldTargetUserID]
	return ok
}

// ResetTargetUserID resets all changes to the "target_user_id" field.
func (m *PendingAuthSessionMutation) ResetTargetUserID() {
	m.target_user = nil
	delete(m.clearedFields, pendingauthsession.FieldTargetUserID)
}

// SetRedirectTo sets the "redirect_to" field.
func (m *PendingAuthSessionMutation) SetRedirectTo(s string) {
	m.redirect_to = &s
}

// RedirectTo returns the value of the "redirect_to" field in the mutation.
func (m *PendingAuthSessionMutation) RedirectTo() (r string, exists bool) {
	v := m.redirect_to
	if v == nil {
		return
	}
	return *v, true
}

// OldRedirectTo returns the old "redirect_to" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldRedirectTo(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRedirectTo is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRedirectTo requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRedirectTo: %w", err)
	}
	return oldValue.RedirectTo, nil
}

// ResetRedirectTo resets all changes to the "redirect_to" field.
func (m *PendingAuthSessionMutation) ResetRedirectTo() {
	m.redirect_to = nil
}

// SetResolvedEmail sets the "resolved_email" field.
func (m *PendingAuthSessionMutation) SetResolvedEmail(s string) {
	m.resolved_email = &s
}

// ResolvedEmail returns the value of the "resolved_email" field in the mutation.
func (m *PendingAuthSessionMutation) ResolvedEmail() (r string, exists bool) {
	v := m.resolved_email
	if v == nil {
		return
	}
	return *v, true
}

// OldResolvedEmail returns the old "resolved_email" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldResolvedEmail(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldResolvedEmail is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldResolvedEmail requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldResolvedEmail: %w", err)
	}
	return oldValue.ResolvedEmail, nil
}

// ResetResolvedEmail resets all changes to the "resolved_email" field.
func (m *PendingAuthSessionMutation) ResetResolvedEmail() {
	m.resolved_email = nil
}

// SetRegistrationPasswordHash sets the "registration_password_hash" field.
func (m *PendingAuthSessionMutation) SetRegistrationPasswordHash(s string) {
	m.registration_password_hash = &s
}

// RegistrationPasswordHash returns the value of the "registration_password_hash" field in the mutation.
func (m *PendingAuthSessionMutation) RegistrationPasswordHash() (r string, exists bool) {
	v := m.registration_password_hash
	if v == nil {
		return
	}
	return *v, true
}

// OldRegistrationPasswordHash returns the old "registration_password_hash" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldRegistrationPasswordHash(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRegistrationPasswordHash is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRegistrationPasswordHash requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRegistrationPasswordHash: %w", err)
	}
	return oldValue.RegistrationPasswordHash, nil
}

// ResetRegistrationPasswordHash resets all changes to the "registration_password_hash" field.
func (m *PendingAuthSessionMutation) ResetRegistrationPasswordHash() {
	m.registration_password_hash = nil
}

// SetUpstreamIdentityClaims sets the "upstream_identity_claims" field.
func (m *PendingAuthSessionMutation) SetUpstreamIdentityClaims(value map[string]interface{}) {
	m.upstream_identity_claims = &value
}

// UpstreamIdentityClaims returns the value of the "upstream_identity_claims" field in the mutation.
func (m *PendingAuthSessionMutation) UpstreamIdentityClaims() (r map[string]interface{}, exists bool) {
	v := m.upstream_identity_claims
	if v == nil {
		return
	}
	return *v, true
}

// OldUpstreamIdentityClaims returns the old "upstream_identity_claims" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldUpstreamIdentityClaims(ctx context.Context) (v map[string]interface{}, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUpstreamIdentityClaims is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUpstreamIdentityClaims requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUpstreamIdentityClaims: %w", err)
	}
	return oldValue.UpstreamIdentityClaims, nil
}

// ResetUpstreamIdentityClaims resets all changes to the "upstream_identity_claims" field.
func (m *PendingAuthSessionMutation) ResetUpstreamIdentityClaims() {
	m.upstream_identity_claims = nil
}

// SetLocalFlowState sets the "local_flow_state" field.
func (m *PendingAuthSessionMutation) SetLocalFlowState(value map[string]interface{}) {
	m.local_flow_state = &value
}

// LocalFlowState returns the value of the "local_flow_state" field in the mutation.
func (m *PendingAuthSessionMutation) LocalFlowState() (r map[string]interface{}, exists bool) {
	v := m.local_flow_state
	if v == nil {
		return
	}
	return *v, true
}

// OldLocalFlowState returns the old "local_flow_state" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldLocalFlowState(ctx context.Context) (v map[string]interface{}, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLocalFlowState is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLocalFlowState requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLocalFlowState: %w", err)
	}
	return oldValue.LocalFlowState, nil
}

// ResetLocalFlowState resets all changes to the "local_flow_state" field.
func (m *PendingAuthSessionMutation) ResetLocalFlowState() {
	m.local_flow_state = nil
}

// SetBrowserSessionKey sets the "browser_session_key" field.
func (m *PendingAuthSessionMutation) SetBrowserSessionKey(s string) {
	m.browser_session_key = &s
}

// BrowserSessionKey returns the value of the "browser_session_key" field in the mutation.
func (m *PendingAuthSessionMutation) BrowserSessionKey() (r string, exists bool) {
	v := m.browser_session_key
	if v == nil {
		return
	}
	return *v, true
}

// OldBrowserSessionKey returns the old "browser_session_key" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldBrowserSessionKey(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBrowserSessionKey is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBrowserSessionKey requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBrowserSessionKey: %w", err)
	}
	return oldValue.BrowserSessionKey, nil
}

// ResetBrowserSessionKey resets all changes to the "browser_session_key" field.
func (m *PendingAuthSessionMutation) ResetBrowserSessionKey() {
	m.browser_session_key = nil
}

// SetCompletionCodeHash sets the "completion_code_hash" field.
func (m *PendingAuthSessionMutation) SetCompletionCodeHash(s string) {
	m.completion_code_hash = &s
}

// CompletionCodeHash returns the value of the "completion_code_hash" field in the mutation.
func (m *PendingAuthSessionMutation) CompletionCodeHash() (r string, exists bool) {
	v := m.completion_code_hash
	if v == nil {
		return
	}
	return *v, true
}

// OldCompletionCodeHash returns the old "completion_code_hash" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldCompletionCodeHash(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCompletionCodeHash is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCompletionCodeHash requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCompletionCodeHash: %w", err)
	}
	return oldValue.CompletionCodeHash, nil
}

// ResetCompletionCodeHash resets all changes to the "completion_code_hash" field.
func (m *PendingAuthSessionMutation) ResetCompletionCodeHash() {
	m.completion_code_hash = nil
}

// SetCompletionCodeExpiresAt sets the "completion_code_expires_at" field.
func (m *PendingAuthSessionMutation) SetCompletionCodeExpiresAt(t time.Time) {
	m.completion_code_expires_at = &t
}

// CompletionCodeExpiresAt returns the value of the "completion_code_expires_at" field in the mutation.
func (m *PendingAuthSessionMutation) CompletionCodeExpiresAt() (r time.Time, exists bool) {
	v := m.completion_code_expires_at
	if v == nil {
		return
	}
	return *v, true
}

// OldCompletionCodeExpiresAt returns the old "completion_code_expires_at" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldCompletionCodeExpiresAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCompletionCodeExpiresAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCompletionCodeExpiresAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCompletionCodeExpiresAt: %w", err)
	}
	return oldValue.CompletionCodeExpiresAt, nil
}

// ClearCompletionCodeExpiresAt clears the value of the "completion_code_expires_at" field.
func (m *PendingAuthSessionMutation) ClearCompletionCodeExpiresAt() {
	m.completion_code_expires_at = nil
	m.clearedFields[pendingauthsession.FieldCompletionCodeExpiresAt] = struct{}{}
}

// CompletionCodeExpiresAtCleared returns if the "completion_code_expires_at" field was cleared in this mutation.
func (m *PendingAuthSessionMutation) CompletionCodeExpiresAtCleared() bool {
	_, ok := m.clearedFields[pendingauthsession.FieldCompletionCodeExpiresAt]
	return ok
}

// ResetCompletionCodeExpiresAt resets all changes to the "completion_code_expires_at" field.
func (m *PendingAuthSessionMutation) ResetCompletionCodeExpiresAt() {
	m.completion_code_expires_at = nil
	delete(m.clearedFields, pendingauthsession.FieldCompletionCodeExpiresAt)
}

// SetEmailVerifiedAt sets the "email_verified_at" field.
func (m *PendingAuthSessionMutation) SetEmailVerifiedAt(t time.Time) {
	m.email_verified_at = &t
}

// EmailVerifiedAt returns the value of the "email_verified_at" field in the mutation.
func (m *PendingAuthSessionMutation) EmailVerifiedAt() (r time.Time, exists bool) {
	v := m.email_verified_at
	if v == nil {
		return
	}
	return *v, true
}

// OldEmailVerifiedAt returns the old "email_verified_at" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldEmailVerifiedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldEmailVerifiedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldEmailVerifiedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldEmailVerifiedAt: %w", err)
	}
	return oldValue.EmailVerifiedAt, nil
}

// ClearEmailVerifiedAt clears the value of the "email_verified_at" field.
func (m *PendingAuthSessionMutation) ClearEmailVerifiedAt() {
	m.email_verified_at = nil
	m.clearedFields[pendingauthsession.FieldEmailVerifiedAt] = struct{}{}
}

// EmailVerifiedAtCleared returns if the "email_verified_at" field was cleared in this mutation.
func (m *PendingAuthSessionMutation) EmailVerifiedAtCleared() bool {
	_, ok := m.clearedFields[pendingauthsession.FieldEmailVerifiedAt]
	return ok
}

// ResetEmailVerifiedAt resets all changes to the "email_verified_at" field.
func (m *PendingAuthSessionMutation) ResetEmailVerifiedAt() {
	m.email_verified_at = nil
	delete(m.clearedFields, pendingauthsession.FieldEmailVerifiedAt)
}

// SetPasswordVerifiedAt sets the "password_verified_at" field.
func (m *PendingAuthSessionMutation) SetPasswordVerifiedAt(t time.Time) {
	m.password_verified_at = &t
}

// PasswordVerifiedAt returns the value of the "password_verified_at" field in the mutation.
func (m *PendingAuthSessionMutation) PasswordVerifiedAt() (r time.Time, exists bool) {
	v := m.password_verified_at
	if v == nil {
		return
	}
	return *v, true
}

// OldPasswordVerifiedAt returns the old "password_verified_at" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldPasswordVerifiedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPasswordVerifiedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPasswordVerifiedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPasswordVerifiedAt: %w", err)
	}
	return oldValue.PasswordVerifiedAt, nil
}

// ClearPasswordVerifiedAt clears the value of the "password_verified_at" field.
func (m *PendingAuthSessionMutation) ClearPasswordVerifiedAt() {
	m.password_verified_at = nil
	m.clearedFields[pendingauthsession.FieldPasswordVerifiedAt] = struct{}{}
}

// PasswordVerifiedAtCleared returns if the "password_verified_at" field was cleared in this mutation.
func (m *PendingAuthSessionMutation) PasswordVerifiedAtCleared() bool {
	_, ok := m.clearedFields[pendingauthsession.FieldPasswordVerifiedAt]
	return ok
}

// ResetPasswordVerifiedAt resets all changes to the "password_verified_at" field.
func (m *PendingAuthSessionMutation) ResetPasswordVerifiedAt() {
	m.password_verified_at = nil
	delete(m.clearedFields, pendingauthsession.FieldPasswordVerifiedAt)
}

// SetTotpVerifiedAt sets the "totp_verified_at" field.
func (m *PendingAuthSessionMutation) SetTotpVerifiedAt(t time.Time) {
	m.totp_verified_at = &t
}

// TotpVerifiedAt returns the value of the "totp_verified_at" field in the mutation.
func (m *PendingAuthSessionMutation) TotpVerifiedAt() (r time.Time, exists bool) {
	v := m.totp_verified_at
	if v == nil {
		return
	}
	return *v, true
}

// OldTotpVerifiedAt returns the old "totp_verified_at" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldTotpVerifiedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTotpVerifiedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTotpVerifiedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTotpVerifiedAt: %w", err)
	}
	return oldValue.TotpVerifiedAt, nil
}

// ClearTotpVerifiedAt clears the value of the "totp_verified_at" field.
func (m *PendingAuthSessionMutation) ClearTotpVerifiedAt() {
	m.totp_verified_at = nil
	m.clearedFields[pendingauthsession.FieldTotpVerifiedAt] = struct{}{}
}

// TotpVerifiedAtCleared returns if the "totp_verified_at" field was cleared in this mutation.
func (m *PendingAuthSessionMutation) TotpVerifiedAtCleared() bool {
	_, ok := m.clearedFields[pendingauthsession.FieldTotpVerifiedAt]
	return ok
}

// ResetTotpVerifiedAt resets all changes to the "totp_verified_at" field.
func (m *PendingAuthSessionMutation) ResetTotpVerifiedAt() {
	m.totp_verified_at = nil
	delete(m.clearedFields, pendingauthsession.FieldTotpVerifiedAt)
}

// SetExpiresAt sets the "expires_at" field.
func (m *PendingAuthSessionMutation) SetExpiresAt(t time.Time) {
	m.expires_at = &t
}

// ExpiresAt returns the value of the "expires_at" field in the mutation.
func (m *PendingAuthSessionMutation) ExpiresAt() (r time.Time, exists bool) {
	v := m.expires_at
	if v == nil {
		return
	}
	return *v, true
}

// OldExpiresAt returns the old "expires_at" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldExpiresAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldExpiresAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err)
	}
	return oldValue.ExpiresAt, nil
}

// ResetExpiresAt resets all changes to the "expires_at" field.
func (m *PendingAuthSessionMutation) ResetExpiresAt() {
	m.expires_at = nil
}

// SetConsumedAt sets the "consumed_at" field.
func (m *PendingAuthSessionMutation) SetConsumedAt(t time.Time) {
	m.consumed_at = &t
}

// ConsumedAt returns the value of the "consumed_at" field in the mutation.
func (m *PendingAuthSessionMutation) ConsumedAt() (r time.Time, exists bool) {
	v := m.consumed_at
	if v == nil {
		return
	}
	return *v, true
}

// OldConsumedAt returns the old "consumed_at" field's value of the PendingAuthSession entity.
// If the PendingAuthSession object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PendingAuthSessionMutation) OldConsumedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldConsumedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldConsumedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldConsumedAt: %w", err)
	}
	return oldValue.ConsumedAt, nil
}

// ClearConsumedAt clears the value of the "consumed_at" field.
func (m *PendingAuthSessionMutation) ClearConsumedAt() {
	m.consumed_at = nil
	m.clearedFields[pendingauthsession.FieldConsumedAt] = struct{}{}
}

// ConsumedAtCleared returns if the "consumed_at" field was cleared in this mutation.
func (m *PendingAuthSessionMutation) ConsumedAtCleared() bool {
	_, ok := m.clearedFields[pendingauthsession.FieldConsumedAt]
	return ok
}

// ResetConsumedAt resets all changes to the "consumed_at" field.
func (m *PendingAuthSessionMutation) ResetConsumedAt() {
	m.consumed_at = nil
	delete(m.clearedFields, pendingauthsession.FieldConsumedAt)
}

// ClearTargetUser clears the "target_user" edge to the User entity.
func (m *PendingAuthSessionMutation) ClearTargetUser() {
	m.clearedtarget_user = true
	m.clearedFields[pendingauthsession.FieldTargetUserID] = struct{}{}
}

// TargetUserCleared reports if the "target_user" edge to the User entity was cleared.
func (m *PendingAuthSessionMutation) TargetUserCleared() bool {
	return m.TargetUserIDCleared() || m.clearedtarget_user
}

// TargetUserIDs returns the "target_user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// TargetUserID instead. It exists only for internal usage by the builders.
func (m *PendingAuthSessionMutation) TargetUserIDs() (ids []int64) {
	if id := m.target_user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetTargetUser resets all changes to the "target_user" edge.
func (m *PendingAuthSessionMutation) ResetTargetUser() {
	m.target_user = nil
	m.clearedtarget_user = false
}

// SetAdoptionDecisionID sets the "adoption_decision" edge to the IdentityAdoptionDecision entity by id.
func (m *PendingAuthSessionMutation) SetAdoptionDecisionID(id int64) {
	m.adoption_decision = &id
}

// ClearAdoptionDecision clears the "adoption_decision" edge to the IdentityAdoptionDecision entity.
func (m *PendingAuthSessionMutation) ClearAdoptionDecision() {
	m.clearedadoption_decision = true
}

// AdoptionDecisionCleared reports if the "adoption_decision" edge to the IdentityAdoptionDecision entity was cleared.
func (m *PendingAuthSessionMutation) AdoptionDecisionCleared() bool {
	return m.clearedadoption_decision
}

// AdoptionDecisionID returns the "adoption_decision" edge ID in the mutation.
func (m *PendingAuthSessionMutation) AdoptionDecisionID() (id int64, exists bool) {
	if m.adoption_decision != nil {
		return *m.adoption_decision, true
	}
	return
}

// AdoptionDecisionIDs returns the "adoption_decision" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// AdoptionDecisionID instead. It exists only for internal usage by the builders.
func (m *PendingAuthSessionMutation) AdoptionDecisionIDs() (ids []int64) {
	if id := m.adoption_decision; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetAdoptionDecision resets all changes to the "adoption_decision" edge.
func (m *PendingAuthSessionMutation) ResetAdoptionDecision() {
	m.adoption_decision = nil
	m.clearedadoption_decision = false
}

// Where appends a list predicates to the PendingAuthSessionMutation builder.
func (m *PendingAuthSessionMutation) Where(ps ...predicate.PendingAuthSession) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the PendingAuthSessionMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PendingAuthSessionMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.PendingAuthSession, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *PendingAuthSessionMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *PendingAuthSessionMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (PendingAuthSession).
func (m *PendingAuthSessionMutation) 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 *PendingAuthSessionMutation) Fields() []string {
	fields := make([]string, 0, 21)
	if m.created_at != nil {
		fields = append(fields, pendingauthsession.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, pendingauthsession.FieldUpdatedAt)
	}
	if m.session_token != nil {
		fields = append(fields, pendingauthsession.FieldSessionToken)
	}
	if m.intent != nil {
		fields = append(fields, pendingauthsession.FieldIntent)
	}
	if m.provider_type != nil {
		fields = append(fields, pendingauthsession.FieldProviderType)
	}
	if m.provider_key != nil {
		fields = append(fields, pendingauthsession.FieldProviderKey)
	}
	if m.provider_subject != nil {
		fields = append(fields, pendingauthsession.FieldProviderSubject)
	}
	if m.target_user != nil {
		fields = append(fields, pendingauthsession.FieldTargetUserID)
	}
	if m.redirect_to != nil {
		fields = append(fields, pendingauthsession.FieldRedirectTo)
	}
	if m.resolved_email != nil {
		fields = append(fields, pendingauthsession.FieldResolvedEmail)
	}
	if m.registration_password_hash != nil {
		fields = append(fields, pendingauthsession.FieldRegistrationPasswordHash)
	}
	if m.upstream_identity_claims != nil {
		fields = append(fields, pendingauthsession.FieldUpstreamIdentityClaims)
	}
	if m.local_flow_state != nil {
		fields = append(fields, pendingauthsession.FieldLocalFlowState)
	}
	if m.browser_session_key != nil {
		fields = append(fields, pendingauthsession.FieldBrowserSessionKey)
	}
	if m.completion_code_hash != nil {
		fields = append(fields, pendingauthsession.FieldCompletionCodeHash)
	}
	if m.completion_code_expires_at != nil {
		fields = append(fields, pendingauthsession.FieldCompletionCodeExpiresAt)
	}
	if m.email_verified_at != nil {
		fields = append(fields, pendingauthsession.FieldEmailVerifiedAt)
	}
	if m.password_verified_at != nil {
		fields = append(fields, pendingauthsession.FieldPasswordVerifiedAt)
	}
	if m.totp_verified_at != nil {
		fields = append(fields, pendingauthsession.FieldTotpVerifiedAt)
	}
	if m.expires_at != nil {
		fields = append(fields, pendingauthsession.FieldExpiresAt)
	}
	if m.consumed_at != nil {
		fields = append(fields, pendingauthsession.FieldConsumedAt)
	}
	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 *PendingAuthSessionMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case pendingauthsession.FieldCreatedAt:
		return m.CreatedAt()
	case pendingauthsession.FieldUpdatedAt:
		return m.UpdatedAt()
	case pendingauthsession.FieldSessionToken:
		return m.SessionToken()
	case pendingauthsession.FieldIntent:
		return m.Intent()
	case pendingauthsession.FieldProviderType:
		return m.ProviderType()
	case pendingauthsession.FieldProviderKey:
		return m.ProviderKey()
	case pendingauthsession.FieldProviderSubject:
		return m.ProviderSubject()
	case pendingauthsession.FieldTargetUserID:
		return m.TargetUserID()
	case pendingauthsession.FieldRedirectTo:
		return m.RedirectTo()
	case pendingauthsession.FieldResolvedEmail:
		return m.ResolvedEmail()
	case pendingauthsession.FieldRegistrationPasswordHash:
		return m.RegistrationPasswordHash()
	case pendingauthsession.FieldUpstreamIdentityClaims:
		return m.UpstreamIdentityClaims()
	case pendingauthsession.FieldLocalFlowState:
		return m.LocalFlowState()
	case pendingauthsession.FieldBrowserSessionKey:
		return m.BrowserSessionKey()
	case pendingauthsession.FieldCompletionCodeHash:
		return m.CompletionCodeHash()
	case pendingauthsession.FieldCompletionCodeExpiresAt:
		return m.CompletionCodeExpiresAt()
	case pendingauthsession.FieldEmailVerifiedAt:
		return m.EmailVerifiedAt()
	case pendingauthsession.FieldPasswordVerifiedAt:
		return m.PasswordVerifiedAt()
	case pendingauthsession.FieldTotpVerifiedAt:
		return m.TotpVerifiedAt()
	case pendingauthsession.FieldExpiresAt:
		return m.ExpiresAt()
	case pendingauthsession.FieldConsumedAt:
		return m.ConsumedAt()
	}
	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 *PendingAuthSessionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case pendingauthsession.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case pendingauthsession.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case pendingauthsession.FieldSessionToken:
		return m.OldSessionToken(ctx)
	case pendingauthsession.FieldIntent:
		return m.OldIntent(ctx)
	case pendingauthsession.FieldProviderType:
		return m.OldProviderType(ctx)
	case pendingauthsession.FieldProviderKey:
		return m.OldProviderKey(ctx)
	case pendingauthsession.FieldProviderSubject:
		return m.OldProviderSubject(ctx)
	case pendingauthsession.FieldTargetUserID:
		return m.OldTargetUserID(ctx)
	case pendingauthsession.FieldRedirectTo:
		return m.OldRedirectTo(ctx)
	case pendingauthsession.FieldResolvedEmail:
		return m.OldResolvedEmail(ctx)
	case pendingauthsession.FieldRegistrationPasswordHash:
		return m.OldRegistrationPasswordHash(ctx)
	case pendingauthsession.FieldUpstreamIdentityClaims:
		return m.OldUpstreamIdentityClaims(ctx)
	case pendingauthsession.FieldLocalFlowState:
		return m.OldLocalFlowState(ctx)
	case pendingauthsession.FieldBrowserSessionKey:
		return m.OldBrowserSessionKey(ctx)
	case pendingauthsession.FieldCompletionCodeHash:
		return m.OldCompletionCodeHash(ctx)
	case pendingauthsession.FieldCompletionCodeExpiresAt:
		return m.OldCompletionCodeExpiresAt(ctx)
	case pendingauthsession.FieldEmailVerifiedAt:
		return m.OldEmailVerifiedAt(ctx)
	case pendingauthsession.FieldPasswordVerifiedAt:
		return m.OldPasswordVerifiedAt(ctx)
	case pendingauthsession.FieldTotpVerifiedAt:
		return m.OldTotpVerifiedAt(ctx)
	case pendingauthsession.FieldExpiresAt:
		return m.OldExpiresAt(ctx)
	case pendingauthsession.FieldConsumedAt:
		return m.OldConsumedAt(ctx)
	}
	return nil, fmt.Errorf("unknown PendingAuthSession 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 *PendingAuthSessionMutation) SetField(name string, value ent.Value) error {
	switch name {
	case pendingauthsession.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 pendingauthsession.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 pendingauthsession.FieldSessionToken:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSessionToken(v)
		return nil
	case pendingauthsession.FieldIntent:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIntent(v)
		return nil
	case pendingauthsession.FieldProviderType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProviderType(v)
		return nil
	case pendingauthsession.FieldProviderKey:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProviderKey(v)
		return nil
	case pendingauthsession.FieldProviderSubject:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProviderSubject(v)
		return nil
	case pendingauthsession.FieldTargetUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTargetUserID(v)
		return nil
	case pendingauthsession.FieldRedirectTo:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRedirectTo(v)
		return nil
	case pendingauthsession.FieldResolvedEmail:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetResolvedEmail(v)
		return nil
	case pendingauthsession.FieldRegistrationPasswordHash:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRegistrationPasswordHash(v)
		return nil
	case pendingauthsession.FieldUpstreamIdentityClaims:
		v, ok := value.(map[string]interface{})
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpstreamIdentityClaims(v)
		return nil
	case pendingauthsession.FieldLocalFlowState:
		v, ok := value.(map[string]interface{})
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLocalFlowState(v)
		return nil
	case pendingauthsession.FieldBrowserSessionKey:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBrowserSessionKey(v)
		return nil
	case pendingauthsession.FieldCompletionCodeHash:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCompletionCodeHash(v)
		return nil
	case pendingauthsession.FieldCompletionCodeExpiresAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCompletionCodeExpiresAt(v)
		return nil
	case pendingauthsession.FieldEmailVerifiedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEmailVerifiedAt(v)
		return nil
	case pendingauthsession.FieldPasswordVerifiedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPasswordVerifiedAt(v)
		return nil
	case pendingauthsession.FieldTotpVerifiedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTotpVerifiedAt(v)
		return nil
	case pendingauthsession.FieldExpiresAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetExpiresAt(v)
		return nil
	case pendingauthsession.FieldConsumedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetConsumedAt(v)
		return nil
	}
	return fmt.Errorf("unknown PendingAuthSession field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PendingAuthSessionMutation) AddedFields() []string {
	var fields []string
	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 *PendingAuthSessionMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	}
	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 *PendingAuthSessionMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown PendingAuthSession numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PendingAuthSessionMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(pendingauthsession.FieldTargetUserID) {
		fields = append(fields, pendingauthsession.FieldTargetUserID)
	}
	if m.FieldCleared(pendingauthsession.FieldCompletionCodeExpiresAt) {
		fields = append(fields, pendingauthsession.FieldCompletionCodeExpiresAt)
	}
	if m.FieldCleared(pendingauthsession.FieldEmailVerifiedAt) {
		fields = append(fields, pendingauthsession.FieldEmailVerifiedAt)
	}
	if m.FieldCleared(pendingauthsession.FieldPasswordVerifiedAt) {
		fields = append(fields, pendingauthsession.FieldPasswordVerifiedAt)
	}
	if m.FieldCleared(pendingauthsession.FieldTotpVerifiedAt) {
		fields = append(fields, pendingauthsession.FieldTotpVerifiedAt)
	}
	if m.FieldCleared(pendingauthsession.FieldConsumedAt) {
		fields = append(fields, pendingauthsession.FieldConsumedAt)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PendingAuthSessionMutation) 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 *PendingAuthSessionMutation) ClearField(name string) error {
	switch name {
	case pendingauthsession.FieldTargetUserID:
		m.ClearTargetUserID()
		return nil
	case pendingauthsession.FieldCompletionCodeExpiresAt:
		m.ClearCompletionCodeExpiresAt()
		return nil
	case pendingauthsession.FieldEmailVerifiedAt:
		m.ClearEmailVerifiedAt()
		return nil
	case pendingauthsession.FieldPasswordVerifiedAt:
		m.ClearPasswordVerifiedAt()
		return nil
	case pendingauthsession.FieldTotpVerifiedAt:
		m.ClearTotpVerifiedAt()
		return nil
	case pendingauthsession.FieldConsumedAt:
		m.ClearConsumedAt()
		return nil
	}
	return fmt.Errorf("unknown PendingAuthSession 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 *PendingAuthSessionMutation) ResetField(name string) error {
	switch name {
	case pendingauthsession.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case pendingauthsession.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case pendingauthsession.FieldSessionToken:
		m.ResetSessionToken()
		return nil
	case pendingauthsession.FieldIntent:
		m.ResetIntent()
		return nil
	case pendingauthsession.FieldProviderType:
		m.ResetProviderType()
		return nil
	case pendingauthsession.FieldProviderKey:
		m.ResetProviderKey()
		return nil
	case pendingauthsession.FieldProviderSubject:
		m.ResetProviderSubject()
		return nil
	case pendingauthsession.FieldTargetUserID:
		m.ResetTargetUserID()
		return nil
	case pendingauthsession.FieldRedirectTo:
		m.ResetRedirectTo()
		return nil
	case pendingauthsession.FieldResolvedEmail:
		m.ResetResolvedEmail()
		return nil
	case pendingauthsession.FieldRegistrationPasswordHash:
		m.ResetRegistrationPasswordHash()
		return nil
	case pendingauthsession.FieldUpstreamIdentityClaims:
		m.ResetUpstreamIdentityClaims()
		return nil
	case pendingauthsession.FieldLocalFlowState:
		m.ResetLocalFlowState()
		return nil
	case pendingauthsession.FieldBrowserSessionKey:
		m.ResetBrowserSessionKey()
		return nil
	case pendingauthsession.FieldCompletionCodeHash:
		m.ResetCompletionCodeHash()
		return nil
	case pendingauthsession.FieldCompletionCodeExpiresAt:
		m.ResetCompletionCodeExpiresAt()
		return nil
	case pendingauthsession.FieldEmailVerifiedAt:
		m.ResetEmailVerifiedAt()
		return nil
	case pendingauthsession.FieldPasswordVerifiedAt:
		m.ResetPasswordVerifiedAt()
		return nil
	case pendingauthsession.FieldTotpVerifiedAt:
		m.ResetTotpVerifiedAt()
		return nil
	case pendingauthsession.FieldExpiresAt:
		m.ResetExpiresAt()
		return nil
	case pendingauthsession.FieldConsumedAt:
		m.ResetConsumedAt()
		return nil
	}
	return fmt.Errorf("unknown PendingAuthSession field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PendingAuthSessionMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.target_user != nil {
		edges = append(edges, pendingauthsession.EdgeTargetUser)
	}
	if m.adoption_decision != nil {
		edges = append(edges, pendingauthsession.EdgeAdoptionDecision)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PendingAuthSessionMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case pendingauthsession.EdgeTargetUser:
		if id := m.target_user; id != nil {
			return []ent.Value{*id}
		}
	case pendingauthsession.EdgeAdoptionDecision:
		if id := m.adoption_decision; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PendingAuthSessionMutation) 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 *PendingAuthSessionMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PendingAuthSessionMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedtarget_user {
		edges = append(edges, pendingauthsession.EdgeTargetUser)
	}
	if m.clearedadoption_decision {
		edges = append(edges, pendingauthsession.EdgeAdoptionDecision)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PendingAuthSessionMutation) EdgeCleared(name string) bool {
	switch name {
	case pendingauthsession.EdgeTargetUser:
		return m.clearedtarget_user
	case pendingauthsession.EdgeAdoptionDecision:
		return m.clearedadoption_decision
	}
	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 *PendingAuthSessionMutation) ClearEdge(name string) error {
	switch name {
	case pendingauthsession.EdgeTargetUser:
		m.ClearTargetUser()
		return nil
	case pendingauthsession.EdgeAdoptionDecision:
		m.ClearAdoptionDecision()
		return nil
	}
	return fmt.Errorf("unknown PendingAuthSession 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 *PendingAuthSessionMutation) ResetEdge(name string) error {
	switch name {
	case pendingauthsession.EdgeTargetUser:
		m.ResetTargetUser()
		return nil
	case pendingauthsession.EdgeAdoptionDecision:
		m.ResetAdoptionDecision()
		return nil
	}
	return fmt.Errorf("unknown PendingAuthSession edge %s", name)
}

// PromoCodeMutation represents an operation that mutates the PromoCode nodes in the graph.
type PromoCodeMutation struct {
	config
	op                   Op
	typ                  string
	id                   *int64
	code                 *string
	bonus_amount         *float64
	addbonus_amount      *float64
	max_uses             *int
	addmax_uses          *int
	used_count           *int
	addused_count        *int
	status               *string
	expires_at           *time.Time
	notes                *string
	created_at           *time.Time
	updated_at           *time.Time
	clearedFields        map[string]struct{}
	usage_records        map[int64]struct{}
	removedusage_records map[int64]struct{}
	clearedusage_records bool
	done                 bool
	oldValue             func(context.Context) (*PromoCode, error)
	predicates           []predicate.PromoCode
}

var _ ent.Mutation = (*PromoCodeMutation)(nil)

// promocodeOption allows management of the mutation configuration using functional options.
type promocodeOption func(*PromoCodeMutation)

// newPromoCodeMutation creates new mutation for the PromoCode entity.
func newPromoCodeMutation(c config, op Op, opts ...promocodeOption) *PromoCodeMutation {
	m := &PromoCodeMutation{
		config:        c,
		op:            op,
		typ:           TypePromoCode,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withPromoCodeID sets the ID field of the mutation.
func withPromoCodeID(id int64) promocodeOption {
	return func(m *PromoCodeMutation) {
		var (
			err   error
			once  sync.Once
			value *PromoCode
		)
		m.oldValue = func(ctx context.Context) (*PromoCode, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().PromoCode.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withPromoCode sets the old PromoCode of the mutation.
func withPromoCode(node *PromoCode) promocodeOption {
	return func(m *PromoCodeMutation) {
		m.oldValue = func(context.Context) (*PromoCode, 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 PromoCodeMutation) 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 PromoCodeMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *PromoCodeMutation) ID() (id int64, 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 *PromoCodeMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().PromoCode.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCode sets the "code" field.
func (m *PromoCodeMutation) SetCode(s string) {
	m.code = &s
}

// Code returns the value of the "code" field in the mutation.
func (m *PromoCodeMutation) Code() (r string, exists bool) {
	v := m.code
	if v == nil {
		return
	}
	return *v, true
}

// OldCode returns the old "code" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldCode(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCode is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCode requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCode: %w", err)
	}
	return oldValue.Code, nil
}

// ResetCode resets all changes to the "code" field.
func (m *PromoCodeMutation) ResetCode() {
	m.code = nil
}

// SetBonusAmount sets the "bonus_amount" field.
func (m *PromoCodeMutation) SetBonusAmount(f float64) {
	m.bonus_amount = &f
	m.addbonus_amount = nil
}

// BonusAmount returns the value of the "bonus_amount" field in the mutation.
func (m *PromoCodeMutation) BonusAmount() (r float64, exists bool) {
	v := m.bonus_amount
	if v == nil {
		return
	}
	return *v, true
}

// OldBonusAmount returns the old "bonus_amount" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldBonusAmount(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBonusAmount is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBonusAmount requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBonusAmount: %w", err)
	}
	return oldValue.BonusAmount, nil
}

// AddBonusAmount adds f to the "bonus_amount" field.
func (m *PromoCodeMutation) AddBonusAmount(f float64) {
	if m.addbonus_amount != nil {
		*m.addbonus_amount += f
	} else {
		m.addbonus_amount = &f
	}
}

// AddedBonusAmount returns the value that was added to the "bonus_amount" field in this mutation.
func (m *PromoCodeMutation) AddedBonusAmount() (r float64, exists bool) {
	v := m.addbonus_amount
	if v == nil {
		return
	}
	return *v, true
}

// ResetBonusAmount resets all changes to the "bonus_amount" field.
func (m *PromoCodeMutation) ResetBonusAmount() {
	m.bonus_amount = nil
	m.addbonus_amount = nil
}

// SetMaxUses sets the "max_uses" field.
func (m *PromoCodeMutation) SetMaxUses(i int) {
	m.max_uses = &i
	m.addmax_uses = nil
}

// MaxUses returns the value of the "max_uses" field in the mutation.
func (m *PromoCodeMutation) MaxUses() (r int, exists bool) {
	v := m.max_uses
	if v == nil {
		return
	}
	return *v, true
}

// OldMaxUses returns the old "max_uses" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldMaxUses(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldMaxUses is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldMaxUses requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldMaxUses: %w", err)
	}
	return oldValue.MaxUses, nil
}

// AddMaxUses adds i to the "max_uses" field.
func (m *PromoCodeMutation) AddMaxUses(i int) {
	if m.addmax_uses != nil {
		*m.addmax_uses += i
	} else {
		m.addmax_uses = &i
	}
}

// AddedMaxUses returns the value that was added to the "max_uses" field in this mutation.
func (m *PromoCodeMutation) AddedMaxUses() (r int, exists bool) {
	v := m.addmax_uses
	if v == nil {
		return
	}
	return *v, true
}

// ResetMaxUses resets all changes to the "max_uses" field.
func (m *PromoCodeMutation) ResetMaxUses() {
	m.max_uses = nil
	m.addmax_uses = nil
}

// SetUsedCount sets the "used_count" field.
func (m *PromoCodeMutation) SetUsedCount(i int) {
	m.used_count = &i
	m.addused_count = nil
}

// UsedCount returns the value of the "used_count" field in the mutation.
func (m *PromoCodeMutation) UsedCount() (r int, exists bool) {
	v := m.used_count
	if v == nil {
		return
	}
	return *v, true
}

// OldUsedCount returns the old "used_count" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldUsedCount(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUsedCount is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUsedCount requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUsedCount: %w", err)
	}
	return oldValue.UsedCount, nil
}

// AddUsedCount adds i to the "used_count" field.
func (m *PromoCodeMutation) AddUsedCount(i int) {
	if m.addused_count != nil {
		*m.addused_count += i
	} else {
		m.addused_count = &i
	}
}

// AddedUsedCount returns the value that was added to the "used_count" field in this mutation.
func (m *PromoCodeMutation) AddedUsedCount() (r int, exists bool) {
	v := m.addused_count
	if v == nil {
		return
	}
	return *v, true
}

// ResetUsedCount resets all changes to the "used_count" field.
func (m *PromoCodeMutation) ResetUsedCount() {
	m.used_count = nil
	m.addused_count = nil
}

// SetStatus sets the "status" field.
func (m *PromoCodeMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *PromoCodeMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldStatus(ctx context.Context) (v string, 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 *PromoCodeMutation) ResetStatus() {
	m.status = nil
}

// SetExpiresAt sets the "expires_at" field.
func (m *PromoCodeMutation) SetExpiresAt(t time.Time) {
	m.expires_at = &t
}

// ExpiresAt returns the value of the "expires_at" field in the mutation.
func (m *PromoCodeMutation) ExpiresAt() (r time.Time, exists bool) {
	v := m.expires_at
	if v == nil {
		return
	}
	return *v, true
}

// OldExpiresAt returns the old "expires_at" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldExpiresAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldExpiresAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err)
	}
	return oldValue.ExpiresAt, nil
}

// ClearExpiresAt clears the value of the "expires_at" field.
func (m *PromoCodeMutation) ClearExpiresAt() {
	m.expires_at = nil
	m.clearedFields[promocode.FieldExpiresAt] = struct{}{}
}

// ExpiresAtCleared returns if the "expires_at" field was cleared in this mutation.
func (m *PromoCodeMutation) ExpiresAtCleared() bool {
	_, ok := m.clearedFields[promocode.FieldExpiresAt]
	return ok
}

// ResetExpiresAt resets all changes to the "expires_at" field.
func (m *PromoCodeMutation) ResetExpiresAt() {
	m.expires_at = nil
	delete(m.clearedFields, promocode.FieldExpiresAt)
}

// SetNotes sets the "notes" field.
func (m *PromoCodeMutation) SetNotes(s string) {
	m.notes = &s
}

// Notes returns the value of the "notes" field in the mutation.
func (m *PromoCodeMutation) Notes() (r string, exists bool) {
	v := m.notes
	if v == nil {
		return
	}
	return *v, true
}

// OldNotes returns the old "notes" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldNotes(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldNotes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldNotes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldNotes: %w", err)
	}
	return oldValue.Notes, nil
}

// ClearNotes clears the value of the "notes" field.
func (m *PromoCodeMutation) ClearNotes() {
	m.notes = nil
	m.clearedFields[promocode.FieldNotes] = struct{}{}
}

// NotesCleared returns if the "notes" field was cleared in this mutation.
func (m *PromoCodeMutation) NotesCleared() bool {
	_, ok := m.clearedFields[promocode.FieldNotes]
	return ok
}

// ResetNotes resets all changes to the "notes" field.
func (m *PromoCodeMutation) ResetNotes() {
	m.notes = nil
	delete(m.clearedFields, promocode.FieldNotes)
}

// SetCreatedAt sets the "created_at" field.
func (m *PromoCodeMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *PromoCodeMutation) 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 PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) 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 *PromoCodeMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *PromoCodeMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *PromoCodeMutation) 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 PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) 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 *PromoCodeMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// AddUsageRecordIDs adds the "usage_records" edge to the PromoCodeUsage entity by ids.
func (m *PromoCodeMutation) AddUsageRecordIDs(ids ...int64) {
	if m.usage_records == nil {
		m.usage_records = make(map[int64]struct{})
	}
	for i := range ids {
		m.usage_records[ids[i]] = struct{}{}
	}
}

// ClearUsageRecords clears the "usage_records" edge to the PromoCodeUsage entity.
func (m *PromoCodeMutation) ClearUsageRecords() {
	m.clearedusage_records = true
}

// UsageRecordsCleared reports if the "usage_records" edge to the PromoCodeUsage entity was cleared.
func (m *PromoCodeMutation) UsageRecordsCleared() bool {
	return m.clearedusage_records
}

// RemoveUsageRecordIDs removes the "usage_records" edge to the PromoCodeUsage entity by IDs.
func (m *PromoCodeMutation) RemoveUsageRecordIDs(ids ...int64) {
	if m.removedusage_records == nil {
		m.removedusage_records = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.usage_records, ids[i])
		m.removedusage_records[ids[i]] = struct{}{}
	}
}

// RemovedUsageRecords returns the removed IDs of the "usage_records" edge to the PromoCodeUsage entity.
func (m *PromoCodeMutation) RemovedUsageRecordsIDs() (ids []int64) {
	for id := range m.removedusage_records {
		ids = append(ids, id)
	}
	return
}

// UsageRecordsIDs returns the "usage_records" edge IDs in the mutation.
func (m *PromoCodeMutation) UsageRecordsIDs() (ids []int64) {
	for id := range m.usage_records {
		ids = append(ids, id)
	}
	return
}

// ResetUsageRecords resets all changes to the "usage_records" edge.
func (m *PromoCodeMutation) ResetUsageRecords() {
	m.usage_records = nil
	m.clearedusage_records = false
	m.removedusage_records = nil
}

// Where appends a list predicates to the PromoCodeMutation builder.
func (m *PromoCodeMutation) Where(ps ...predicate.PromoCode) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the PromoCodeMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PromoCodeMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.PromoCode, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *PromoCodeMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *PromoCodeMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (PromoCode).
func (m *PromoCodeMutation) 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 *PromoCodeMutation) Fields() []string {
	fields := make([]string, 0, 9)
	if m.code != nil {
		fields = append(fields, promocode.FieldCode)
	}
	if m.bonus_amount != nil {
		fields = append(fields, promocode.FieldBonusAmount)
	}
	if m.max_uses != nil {
		fields = append(fields, promocode.FieldMaxUses)
	}
	if m.used_count != nil {
		fields = append(fields, promocode.FieldUsedCount)
	}
	if m.status != nil {
		fields = append(fields, promocode.FieldStatus)
	}
	if m.expires_at != nil {
		fields = append(fields, promocode.FieldExpiresAt)
	}
	if m.notes != nil {
		fields = append(fields, promocode.FieldNotes)
	}
	if m.created_at != nil {
		fields = append(fields, promocode.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, promocode.FieldUpdatedAt)
	}
	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 *PromoCodeMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case promocode.FieldCode:
		return m.Code()
	case promocode.FieldBonusAmount:
		return m.BonusAmount()
	case promocode.FieldMaxUses:
		return m.MaxUses()
	case promocode.FieldUsedCount:
		return m.UsedCount()
	case promocode.FieldStatus:
		return m.Status()
	case promocode.FieldExpiresAt:
		return m.ExpiresAt()
	case promocode.FieldNotes:
		return m.Notes()
	case promocode.FieldCreatedAt:
		return m.CreatedAt()
	case promocode.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	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 *PromoCodeMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case promocode.FieldCode:
		return m.OldCode(ctx)
	case promocode.FieldBonusAmount:
		return m.OldBonusAmount(ctx)
	case promocode.FieldMaxUses:
		return m.OldMaxUses(ctx)
	case promocode.FieldUsedCount:
		return m.OldUsedCount(ctx)
	case promocode.FieldStatus:
		return m.OldStatus(ctx)
	case promocode.FieldExpiresAt:
		return m.OldExpiresAt(ctx)
	case promocode.FieldNotes:
		return m.OldNotes(ctx)
	case promocode.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case promocode.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown PromoCode 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 *PromoCodeMutation) SetField(name string, value ent.Value) error {
	switch name {
	case promocode.FieldCode:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCode(v)
		return nil
	case promocode.FieldBonusAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBonusAmount(v)
		return nil
	case promocode.FieldMaxUses:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMaxUses(v)
		return nil
	case promocode.FieldUsedCount:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUsedCount(v)
		return nil
	case promocode.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case promocode.FieldExpiresAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetExpiresAt(v)
		return nil
	case promocode.FieldNotes:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNotes(v)
		return nil
	case promocode.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 promocode.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown PromoCode field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PromoCodeMutation) AddedFields() []string {
	var fields []string
	if m.addbonus_amount != nil {
		fields = append(fields, promocode.FieldBonusAmount)
	}
	if m.addmax_uses != nil {
		fields = append(fields, promocode.FieldMaxUses)
	}
	if m.addused_count != nil {
		fields = append(fields, promocode.FieldUsedCount)
	}
	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 *PromoCodeMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case promocode.FieldBonusAmount:
		return m.AddedBonusAmount()
	case promocode.FieldMaxUses:
		return m.AddedMaxUses()
	case promocode.FieldUsedCount:
		return m.AddedUsedCount()
	}
	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 *PromoCodeMutation) AddField(name string, value ent.Value) error {
	switch name {
	case promocode.FieldBonusAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddBonusAmount(v)
		return nil
	case promocode.FieldMaxUses:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddMaxUses(v)
		return nil
	case promocode.FieldUsedCount:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddUsedCount(v)
		return nil
	}
	return fmt.Errorf("unknown PromoCode numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PromoCodeMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(promocode.FieldExpiresAt) {
		fields = append(fields, promocode.FieldExpiresAt)
	}
	if m.FieldCleared(promocode.FieldNotes) {
		fields = append(fields, promocode.FieldNotes)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PromoCodeMutation) 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 *PromoCodeMutation) ClearField(name string) error {
	switch name {
	case promocode.FieldExpiresAt:
		m.ClearExpiresAt()
		return nil
	case promocode.FieldNotes:
		m.ClearNotes()
		return nil
	}
	return fmt.Errorf("unknown PromoCode 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 *PromoCodeMutation) ResetField(name string) error {
	switch name {
	case promocode.FieldCode:
		m.ResetCode()
		return nil
	case promocode.FieldBonusAmount:
		m.ResetBonusAmount()
		return nil
	case promocode.FieldMaxUses:
		m.ResetMaxUses()
		return nil
	case promocode.FieldUsedCount:
		m.ResetUsedCount()
		return nil
	case promocode.FieldStatus:
		m.ResetStatus()
		return nil
	case promocode.FieldExpiresAt:
		m.ResetExpiresAt()
		return nil
	case promocode.FieldNotes:
		m.ResetNotes()
		return nil
	case promocode.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case promocode.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown PromoCode field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PromoCodeMutation) AddedEdges() []string {
	edges := make([]string, 0, 1)
	if m.usage_records != nil {
		edges = append(edges, promocode.EdgeUsageRecords)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PromoCodeMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case promocode.EdgeUsageRecords:
		ids := make([]ent.Value, 0, len(m.usage_records))
		for id := range m.usage_records {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PromoCodeMutation) RemovedEdges() []string {
	edges := make([]string, 0, 1)
	if m.removedusage_records != nil {
		edges = append(edges, promocode.EdgeUsageRecords)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *PromoCodeMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case promocode.EdgeUsageRecords:
		ids := make([]ent.Value, 0, len(m.removedusage_records))
		for id := range m.removedusage_records {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PromoCodeMutation) ClearedEdges() []string {
	edges := make([]string, 0, 1)
	if m.clearedusage_records {
		edges = append(edges, promocode.EdgeUsageRecords)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PromoCodeMutation) EdgeCleared(name string) bool {
	switch name {
	case promocode.EdgeUsageRecords:
		return m.clearedusage_records
	}
	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 *PromoCodeMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown PromoCode 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 *PromoCodeMutation) ResetEdge(name string) error {
	switch name {
	case promocode.EdgeUsageRecords:
		m.ResetUsageRecords()
		return nil
	}
	return fmt.Errorf("unknown PromoCode edge %s", name)
}

// PromoCodeUsageMutation represents an operation that mutates the PromoCodeUsage nodes in the graph.
type PromoCodeUsageMutation struct {
	config
	op                Op
	typ               string
	id                *int64
	bonus_amount      *float64
	addbonus_amount   *float64
	used_at           *time.Time
	clearedFields     map[string]struct{}
	promo_code        *int64
	clearedpromo_code bool
	user              *int64
	cleareduser       bool
	done              bool
	oldValue          func(context.Context) (*PromoCodeUsage, error)
	predicates        []predicate.PromoCodeUsage
}

var _ ent.Mutation = (*PromoCodeUsageMutation)(nil)

// promocodeusageOption allows management of the mutation configuration using functional options.
type promocodeusageOption func(*PromoCodeUsageMutation)

// newPromoCodeUsageMutation creates new mutation for the PromoCodeUsage entity.
func newPromoCodeUsageMutation(c config, op Op, opts ...promocodeusageOption) *PromoCodeUsageMutation {
	m := &PromoCodeUsageMutation{
		config:        c,
		op:            op,
		typ:           TypePromoCodeUsage,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withPromoCodeUsageID sets the ID field of the mutation.
func withPromoCodeUsageID(id int64) promocodeusageOption {
	return func(m *PromoCodeUsageMutation) {
		var (
			err   error
			once  sync.Once
			value *PromoCodeUsage
		)
		m.oldValue = func(ctx context.Context) (*PromoCodeUsage, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().PromoCodeUsage.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withPromoCodeUsage sets the old PromoCodeUsage of the mutation.
func withPromoCodeUsage(node *PromoCodeUsage) promocodeusageOption {
	return func(m *PromoCodeUsageMutation) {
		m.oldValue = func(context.Context) (*PromoCodeUsage, 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 PromoCodeUsageMutation) 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 PromoCodeUsageMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *PromoCodeUsageMutation) ID() (id int64, 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 *PromoCodeUsageMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().PromoCodeUsage.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetPromoCodeID sets the "promo_code_id" field.
func (m *PromoCodeUsageMutation) SetPromoCodeID(i int64) {
	m.promo_code = &i
}

// PromoCodeID returns the value of the "promo_code_id" field in the mutation.
func (m *PromoCodeUsageMutation) PromoCodeID() (r int64, exists bool) {
	v := m.promo_code
	if v == nil {
		return
	}
	return *v, true
}

// OldPromoCodeID returns the old "promo_code_id" field's value of the PromoCodeUsage entity.
// If the PromoCodeUsage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeUsageMutation) OldPromoCodeID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPromoCodeID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPromoCodeID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPromoCodeID: %w", err)
	}
	return oldValue.PromoCodeID, nil
}

// ResetPromoCodeID resets all changes to the "promo_code_id" field.
func (m *PromoCodeUsageMutation) ResetPromoCodeID() {
	m.promo_code = nil
}

// SetUserID sets the "user_id" field.
func (m *PromoCodeUsageMutation) SetUserID(i int64) {
	m.user = &i
}

// UserID returns the value of the "user_id" field in the mutation.
func (m *PromoCodeUsageMutation) UserID() (r int64, exists bool) {
	v := m.user
	if v == nil {
		return
	}
	return *v, true
}

// OldUserID returns the old "user_id" field's value of the PromoCodeUsage entity.
// If the PromoCodeUsage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeUsageMutation) OldUserID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
	}
	return oldValue.UserID, nil
}

// ResetUserID resets all changes to the "user_id" field.
func (m *PromoCodeUsageMutation) ResetUserID() {
	m.user = nil
}

// SetBonusAmount sets the "bonus_amount" field.
func (m *PromoCodeUsageMutation) SetBonusAmount(f float64) {
	m.bonus_amount = &f
	m.addbonus_amount = nil
}

// BonusAmount returns the value of the "bonus_amount" field in the mutation.
func (m *PromoCodeUsageMutation) BonusAmount() (r float64, exists bool) {
	v := m.bonus_amount
	if v == nil {
		return
	}
	return *v, true
}

// OldBonusAmount returns the old "bonus_amount" field's value of the PromoCodeUsage entity.
// If the PromoCodeUsage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeUsageMutation) OldBonusAmount(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBonusAmount is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBonusAmount requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBonusAmount: %w", err)
	}
	return oldValue.BonusAmount, nil
}

// AddBonusAmount adds f to the "bonus_amount" field.
func (m *PromoCodeUsageMutation) AddBonusAmount(f float64) {
	if m.addbonus_amount != nil {
		*m.addbonus_amount += f
	} else {
		m.addbonus_amount = &f
	}
}

// AddedBonusAmount returns the value that was added to the "bonus_amount" field in this mutation.
func (m *PromoCodeUsageMutation) AddedBonusAmount() (r float64, exists bool) {
	v := m.addbonus_amount
	if v == nil {
		return
	}
	return *v, true
}

// ResetBonusAmount resets all changes to the "bonus_amount" field.
func (m *PromoCodeUsageMutation) ResetBonusAmount() {
	m.bonus_amount = nil
	m.addbonus_amount = nil
}

// SetUsedAt sets the "used_at" field.
func (m *PromoCodeUsageMutation) SetUsedAt(t time.Time) {
	m.used_at = &t
}

// UsedAt returns the value of the "used_at" field in the mutation.
func (m *PromoCodeUsageMutation) UsedAt() (r time.Time, exists bool) {
	v := m.used_at
	if v == nil {
		return
	}
	return *v, true
}

// OldUsedAt returns the old "used_at" field's value of the PromoCodeUsage entity.
// If the PromoCodeUsage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeUsageMutation) OldUsedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUsedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUsedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUsedAt: %w", err)
	}
	return oldValue.UsedAt, nil
}

// ResetUsedAt resets all changes to the "used_at" field.
func (m *PromoCodeUsageMutation) ResetUsedAt() {
	m.used_at = nil
}

// ClearPromoCode clears the "promo_code" edge to the PromoCode entity.
func (m *PromoCodeUsageMutation) ClearPromoCode() {
	m.clearedpromo_code = true
	m.clearedFields[promocodeusage.FieldPromoCodeID] = struct{}{}
}

// PromoCodeCleared reports if the "promo_code" edge to the PromoCode entity was cleared.
func (m *PromoCodeUsageMutation) PromoCodeCleared() bool {
	return m.clearedpromo_code
}

// PromoCodeIDs returns the "promo_code" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// PromoCodeID instead. It exists only for internal usage by the builders.
func (m *PromoCodeUsageMutation) PromoCodeIDs() (ids []int64) {
	if id := m.promo_code; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetPromoCode resets all changes to the "promo_code" edge.
func (m *PromoCodeUsageMutation) ResetPromoCode() {
	m.promo_code = nil
	m.clearedpromo_code = false
}

// ClearUser clears the "user" edge to the User entity.
func (m *PromoCodeUsageMutation) ClearUser() {
	m.cleareduser = true
	m.clearedFields[promocodeusage.FieldUserID] = struct{}{}
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *PromoCodeUsageMutation) UserCleared() bool {
	return m.cleareduser
}

// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *PromoCodeUsageMutation) UserIDs() (ids []int64) {
	if id := m.user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetUser resets all changes to the "user" edge.
func (m *PromoCodeUsageMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

// Where appends a list predicates to the PromoCodeUsageMutation builder.
func (m *PromoCodeUsageMutation) Where(ps ...predicate.PromoCodeUsage) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the PromoCodeUsageMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PromoCodeUsageMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.PromoCodeUsage, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *PromoCodeUsageMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *PromoCodeUsageMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (PromoCodeUsage).
func (m *PromoCodeUsageMutation) 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 *PromoCodeUsageMutation) Fields() []string {
	fields := make([]string, 0, 4)
	if m.promo_code != nil {
		fields = append(fields, promocodeusage.FieldPromoCodeID)
	}
	if m.user != nil {
		fields = append(fields, promocodeusage.FieldUserID)
	}
	if m.bonus_amount != nil {
		fields = append(fields, promocodeusage.FieldBonusAmount)
	}
	if m.used_at != nil {
		fields = append(fields, promocodeusage.FieldUsedAt)
	}
	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 *PromoCodeUsageMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case promocodeusage.FieldPromoCodeID:
		return m.PromoCodeID()
	case promocodeusage.FieldUserID:
		return m.UserID()
	case promocodeusage.FieldBonusAmount:
		return m.BonusAmount()
	case promocodeusage.FieldUsedAt:
		return m.UsedAt()
	}
	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 *PromoCodeUsageMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case promocodeusage.FieldPromoCodeID:
		return m.OldPromoCodeID(ctx)
	case promocodeusage.FieldUserID:
		return m.OldUserID(ctx)
	case promocodeusage.FieldBonusAmount:
		return m.OldBonusAmount(ctx)
	case promocodeusage.FieldUsedAt:
		return m.OldUsedAt(ctx)
	}
	return nil, fmt.Errorf("unknown PromoCodeUsage 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 *PromoCodeUsageMutation) SetField(name string, value ent.Value) error {
	switch name {
	case promocodeusage.FieldPromoCodeID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPromoCodeID(v)
		return nil
	case promocodeusage.FieldUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserID(v)
		return nil
	case promocodeusage.FieldBonusAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBonusAmount(v)
		return nil
	case promocodeusage.FieldUsedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUsedAt(v)
		return nil
	}
	return fmt.Errorf("unknown PromoCodeUsage field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PromoCodeUsageMutation) AddedFields() []string {
	var fields []string
	if m.addbonus_amount != nil {
		fields = append(fields, promocodeusage.FieldBonusAmount)
	}
	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 *PromoCodeUsageMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case promocodeusage.FieldBonusAmount:
		return m.AddedBonusAmount()
	}
	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 *PromoCodeUsageMutation) AddField(name string, value ent.Value) error {
	switch name {
	case promocodeusage.FieldBonusAmount:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddBonusAmount(v)
		return nil
	}
	return fmt.Errorf("unknown PromoCodeUsage numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PromoCodeUsageMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PromoCodeUsageMutation) 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 *PromoCodeUsageMutation) ClearField(name string) error {
	return fmt.Errorf("unknown PromoCodeUsage 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 *PromoCodeUsageMutation) ResetField(name string) error {
	switch name {
	case promocodeusage.FieldPromoCodeID:
		m.ResetPromoCodeID()
		return nil
	case promocodeusage.FieldUserID:
		m.ResetUserID()
		return nil
	case promocodeusage.FieldBonusAmount:
		m.ResetBonusAmount()
		return nil
	case promocodeusage.FieldUsedAt:
		m.ResetUsedAt()
		return nil
	}
	return fmt.Errorf("unknown PromoCodeUsage field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PromoCodeUsageMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.promo_code != nil {
		edges = append(edges, promocodeusage.EdgePromoCode)
	}
	if m.user != nil {
		edges = append(edges, promocodeusage.EdgeUser)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PromoCodeUsageMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case promocodeusage.EdgePromoCode:
		if id := m.promo_code; id != nil {
			return []ent.Value{*id}
		}
	case promocodeusage.EdgeUser:
		if id := m.user; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PromoCodeUsageMutation) 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 *PromoCodeUsageMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PromoCodeUsageMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedpromo_code {
		edges = append(edges, promocodeusage.EdgePromoCode)
	}
	if m.cleareduser {
		edges = append(edges, promocodeusage.EdgeUser)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PromoCodeUsageMutation) EdgeCleared(name string) bool {
	switch name {
	case promocodeusage.EdgePromoCode:
		return m.clearedpromo_code
	case promocodeusage.EdgeUser:
		return m.cleareduser
	}
	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 *PromoCodeUsageMutation) ClearEdge(name string) error {
	switch name {
	case promocodeusage.EdgePromoCode:
		m.ClearPromoCode()
		return nil
	case promocodeusage.EdgeUser:
		m.ClearUser()
		return nil
	}
	return fmt.Errorf("unknown PromoCodeUsage 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 *PromoCodeUsageMutation) ResetEdge(name string) error {
	switch name {
	case promocodeusage.EdgePromoCode:
		m.ResetPromoCode()
		return nil
	case promocodeusage.EdgeUser:
		m.ResetUser()
		return nil
	}
	return fmt.Errorf("unknown PromoCodeUsage edge %s", name)
}

// ProxyMutation represents an operation that mutates the Proxy nodes in the graph.
type ProxyMutation struct {
	config
	op              Op
	typ             string
	id              *int64
	created_at      *time.Time
	updated_at      *time.Time
	deleted_at      *time.Time
	name            *string
	protocol        *string
	host            *string
	port            *int
	addport         *int
	username        *string
	password        *string
	status          *string
	clearedFields   map[string]struct{}
	accounts        map[int64]struct{}
	removedaccounts map[int64]struct{}
	clearedaccounts bool
	done            bool
	oldValue        func(context.Context) (*Proxy, error)
	predicates      []predicate.Proxy
}

var _ ent.Mutation = (*ProxyMutation)(nil)

// proxyOption allows management of the mutation configuration using functional options.
type proxyOption func(*ProxyMutation)

// newProxyMutation creates new mutation for the Proxy entity.
func newProxyMutation(c config, op Op, opts ...proxyOption) *ProxyMutation {
	m := &ProxyMutation{
		config:        c,
		op:            op,
		typ:           TypeProxy,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withProxyID sets the ID field of the mutation.
func withProxyID(id int64) proxyOption {
	return func(m *ProxyMutation) {
		var (
			err   error
			once  sync.Once
			value *Proxy
		)
		m.oldValue = func(ctx context.Context) (*Proxy, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Proxy.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withProxy sets the old Proxy of the mutation.
func withProxy(node *Proxy) proxyOption {
	return func(m *ProxyMutation) {
		m.oldValue = func(context.Context) (*Proxy, 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 ProxyMutation) 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 ProxyMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *ProxyMutation) ID() (id int64, 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 *ProxyMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Proxy.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *ProxyMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *ProxyMutation) 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 Proxy entity.
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ProxyMutation) 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 *ProxyMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *ProxyMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *ProxyMutation) 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 Proxy entity.
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ProxyMutation) 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 *ProxyMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetDeletedAt sets the "deleted_at" field.
func (m *ProxyMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *ProxyMutation) 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 Proxy entity.
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ProxyMutation) 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 *ProxyMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[proxy.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *ProxyMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[proxy.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *ProxyMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, proxy.FieldDeletedAt)
}

// SetName sets the "name" field.
func (m *ProxyMutation) SetName(s string) {
	m.name = &s
}

// Name returns the value of the "name" field in the mutation.
func (m *ProxyMutation) 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 Proxy entity.
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ProxyMutation) 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 *ProxyMutation) ResetName() {
	m.name = nil
}

// SetProtocol sets the "protocol" field.
func (m *ProxyMutation) SetProtocol(s string) {
	m.protocol = &s
}

// Protocol returns the value of the "protocol" field in the mutation.
func (m *ProxyMutation) Protocol() (r string, exists bool) {
	v := m.protocol
	if v == nil {
		return
	}
	return *v, true
}

// OldProtocol returns the old "protocol" field's value of the Proxy entity.
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ProxyMutation) OldProtocol(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProtocol is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProtocol requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProtocol: %w", err)
	}
	return oldValue.Protocol, nil
}

// ResetProtocol resets all changes to the "protocol" field.
func (m *ProxyMutation) ResetProtocol() {
	m.protocol = nil
}

// SetHost sets the "host" field.
func (m *ProxyMutation) SetHost(s string) {
	m.host = &s
}

// Host returns the value of the "host" field in the mutation.
func (m *ProxyMutation) Host() (r string, exists bool) {
	v := m.host
	if v == nil {
		return
	}
	return *v, true
}

// OldHost returns the old "host" field's value of the Proxy entity.
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ProxyMutation) OldHost(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldHost is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldHost requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldHost: %w", err)
	}
	return oldValue.Host, nil
}

// ResetHost resets all changes to the "host" field.
func (m *ProxyMutation) ResetHost() {
	m.host = nil
}

// SetPort sets the "port" field.
func (m *ProxyMutation) SetPort(i int) {
	m.port = &i
	m.addport = nil
}

// Port returns the value of the "port" field in the mutation.
func (m *ProxyMutation) Port() (r int, exists bool) {
	v := m.port
	if v == nil {
		return
	}
	return *v, true
}

// OldPort returns the old "port" field's value of the Proxy entity.
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ProxyMutation) OldPort(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPort is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPort requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPort: %w", err)
	}
	return oldValue.Port, nil
}

// AddPort adds i to the "port" field.
func (m *ProxyMutation) AddPort(i int) {
	if m.addport != nil {
		*m.addport += i
	} else {
		m.addport = &i
	}
}

// AddedPort returns the value that was added to the "port" field in this mutation.
func (m *ProxyMutation) AddedPort() (r int, exists bool) {
	v := m.addport
	if v == nil {
		return
	}
	return *v, true
}

// ResetPort resets all changes to the "port" field.
func (m *ProxyMutation) ResetPort() {
	m.port = nil
	m.addport = nil
}

// SetUsername sets the "username" field.
func (m *ProxyMutation) SetUsername(s string) {
	m.username = &s
}

// Username returns the value of the "username" field in the mutation.
func (m *ProxyMutation) Username() (r string, exists bool) {
	v := m.username
	if v == nil {
		return
	}
	return *v, true
}

// OldUsername returns the old "username" field's value of the Proxy entity.
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ProxyMutation) OldUsername(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUsername is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUsername requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUsername: %w", err)
	}
	return oldValue.Username, nil
}

// ClearUsername clears the value of the "username" field.
func (m *ProxyMutation) ClearUsername() {
	m.username = nil
	m.clearedFields[proxy.FieldUsername] = struct{}{}
}

// UsernameCleared returns if the "username" field was cleared in this mutation.
func (m *ProxyMutation) UsernameCleared() bool {
	_, ok := m.clearedFields[proxy.FieldUsername]
	return ok
}

// ResetUsername resets all changes to the "username" field.
func (m *ProxyMutation) ResetUsername() {
	m.username = nil
	delete(m.clearedFields, proxy.FieldUsername)
}

// SetPassword sets the "password" field.
func (m *ProxyMutation) SetPassword(s string) {
	m.password = &s
}

// Password returns the value of the "password" field in the mutation.
func (m *ProxyMutation) Password() (r string, exists bool) {
	v := m.password
	if v == nil {
		return
	}
	return *v, true
}

// OldPassword returns the old "password" field's value of the Proxy entity.
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ProxyMutation) OldPassword(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPassword is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPassword requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPassword: %w", err)
	}
	return oldValue.Password, nil
}

// ClearPassword clears the value of the "password" field.
func (m *ProxyMutation) ClearPassword() {
	m.password = nil
	m.clearedFields[proxy.FieldPassword] = struct{}{}
}

// PasswordCleared returns if the "password" field was cleared in this mutation.
func (m *ProxyMutation) PasswordCleared() bool {
	_, ok := m.clearedFields[proxy.FieldPassword]
	return ok
}

// ResetPassword resets all changes to the "password" field.
func (m *ProxyMutation) ResetPassword() {
	m.password = nil
	delete(m.clearedFields, proxy.FieldPassword)
}

// SetStatus sets the "status" field.
func (m *ProxyMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *ProxyMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the Proxy entity.
// If the Proxy object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *ProxyMutation) OldStatus(ctx context.Context) (v string, 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 *ProxyMutation) ResetStatus() {
	m.status = nil
}

// AddAccountIDs adds the "accounts" edge to the Account entity by ids.
func (m *ProxyMutation) AddAccountIDs(ids ...int64) {
	if m.accounts == nil {
		m.accounts = make(map[int64]struct{})
	}
	for i := range ids {
		m.accounts[ids[i]] = struct{}{}
	}
}

// ClearAccounts clears the "accounts" edge to the Account entity.
func (m *ProxyMutation) ClearAccounts() {
	m.clearedaccounts = true
}

// AccountsCleared reports if the "accounts" edge to the Account entity was cleared.
func (m *ProxyMutation) AccountsCleared() bool {
	return m.clearedaccounts
}

// RemoveAccountIDs removes the "accounts" edge to the Account entity by IDs.
func (m *ProxyMutation) RemoveAccountIDs(ids ...int64) {
	if m.removedaccounts == nil {
		m.removedaccounts = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.accounts, ids[i])
		m.removedaccounts[ids[i]] = struct{}{}
	}
}

// RemovedAccounts returns the removed IDs of the "accounts" edge to the Account entity.
func (m *ProxyMutation) RemovedAccountsIDs() (ids []int64) {
	for id := range m.removedaccounts {
		ids = append(ids, id)
	}
	return
}

// AccountsIDs returns the "accounts" edge IDs in the mutation.
func (m *ProxyMutation) AccountsIDs() (ids []int64) {
	for id := range m.accounts {
		ids = append(ids, id)
	}
	return
}

// ResetAccounts resets all changes to the "accounts" edge.
func (m *ProxyMutation) ResetAccounts() {
	m.accounts = nil
	m.clearedaccounts = false
	m.removedaccounts = nil
}

// Where appends a list predicates to the ProxyMutation builder.
func (m *ProxyMutation) Where(ps ...predicate.Proxy) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the ProxyMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *ProxyMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.Proxy, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *ProxyMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *ProxyMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (Proxy).
func (m *ProxyMutation) 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 *ProxyMutation) Fields() []string {
	fields := make([]string, 0, 10)
	if m.created_at != nil {
		fields = append(fields, proxy.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, proxy.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, proxy.FieldDeletedAt)
	}
	if m.name != nil {
		fields = append(fields, proxy.FieldName)
	}
	if m.protocol != nil {
		fields = append(fields, proxy.FieldProtocol)
	}
	if m.host != nil {
		fields = append(fields, proxy.FieldHost)
	}
	if m.port != nil {
		fields = append(fields, proxy.FieldPort)
	}
	if m.username != nil {
		fields = append(fields, proxy.FieldUsername)
	}
	if m.password != nil {
		fields = append(fields, proxy.FieldPassword)
	}
	if m.status != nil {
		fields = append(fields, proxy.FieldStatus)
	}
	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 *ProxyMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case proxy.FieldCreatedAt:
		return m.CreatedAt()
	case proxy.FieldUpdatedAt:
		return m.UpdatedAt()
	case proxy.FieldDeletedAt:
		return m.DeletedAt()
	case proxy.FieldName:
		return m.Name()
	case proxy.FieldProtocol:
		return m.Protocol()
	case proxy.FieldHost:
		return m.Host()
	case proxy.FieldPort:
		return m.Port()
	case proxy.FieldUsername:
		return m.Username()
	case proxy.FieldPassword:
		return m.Password()
	case proxy.FieldStatus:
		return m.Status()
	}
	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 *ProxyMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case proxy.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case proxy.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case proxy.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case proxy.FieldName:
		return m.OldName(ctx)
	case proxy.FieldProtocol:
		return m.OldProtocol(ctx)
	case proxy.FieldHost:
		return m.OldHost(ctx)
	case proxy.FieldPort:
		return m.OldPort(ctx)
	case proxy.FieldUsername:
		return m.OldUsername(ctx)
	case proxy.FieldPassword:
		return m.OldPassword(ctx)
	case proxy.FieldStatus:
		return m.OldStatus(ctx)
	}
	return nil, fmt.Errorf("unknown Proxy 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 *ProxyMutation) SetField(name string, value ent.Value) error {
	switch name {
	case proxy.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 proxy.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 proxy.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 proxy.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case proxy.FieldProtocol:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProtocol(v)
		return nil
	case proxy.FieldHost:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetHost(v)
		return nil
	case proxy.FieldPort:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPort(v)
		return nil
	case proxy.FieldUsername:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUsername(v)
		return nil
	case proxy.FieldPassword:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPassword(v)
		return nil
	case proxy.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	}
	return fmt.Errorf("unknown Proxy field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *ProxyMutation) AddedFields() []string {
	var fields []string
	if m.addport != nil {
		fields = append(fields, proxy.FieldPort)
	}
	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 *ProxyMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case proxy.FieldPort:
		return m.AddedPort()
	}
	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 *ProxyMutation) AddField(name string, value ent.Value) error {
	switch name {
	case proxy.FieldPort:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPort(v)
		return nil
	}
	return fmt.Errorf("unknown Proxy numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *ProxyMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(proxy.FieldDeletedAt) {
		fields = append(fields, proxy.FieldDeletedAt)
	}
	if m.FieldCleared(proxy.FieldUsername) {
		fields = append(fields, proxy.FieldUsername)
	}
	if m.FieldCleared(proxy.FieldPassword) {
		fields = append(fields, proxy.FieldPassword)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ProxyMutation) 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 *ProxyMutation) ClearField(name string) error {
	switch name {
	case proxy.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	case proxy.FieldUsername:
		m.ClearUsername()
		return nil
	case proxy.FieldPassword:
		m.ClearPassword()
		return nil
	}
	return fmt.Errorf("unknown Proxy 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 *ProxyMutation) ResetField(name string) error {
	switch name {
	case proxy.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case proxy.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case proxy.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case proxy.FieldName:
		m.ResetName()
		return nil
	case proxy.FieldProtocol:
		m.ResetProtocol()
		return nil
	case proxy.FieldHost:
		m.ResetHost()
		return nil
	case proxy.FieldPort:
		m.ResetPort()
		return nil
	case proxy.FieldUsername:
		m.ResetUsername()
		return nil
	case proxy.FieldPassword:
		m.ResetPassword()
		return nil
	case proxy.FieldStatus:
		m.ResetStatus()
		return nil
	}
	return fmt.Errorf("unknown Proxy field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *ProxyMutation) AddedEdges() []string {
	edges := make([]string, 0, 1)
	if m.accounts != nil {
		edges = append(edges, proxy.EdgeAccounts)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *ProxyMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case proxy.EdgeAccounts:
		ids := make([]ent.Value, 0, len(m.accounts))
		for id := range m.accounts {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *ProxyMutation) RemovedEdges() []string {
	edges := make([]string, 0, 1)
	if m.removedaccounts != nil {
		edges = append(edges, proxy.EdgeAccounts)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *ProxyMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case proxy.EdgeAccounts:
		ids := make([]ent.Value, 0, len(m.removedaccounts))
		for id := range m.removedaccounts {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *ProxyMutation) ClearedEdges() []string {
	edges := make([]string, 0, 1)
	if m.clearedaccounts {
		edges = append(edges, proxy.EdgeAccounts)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ProxyMutation) EdgeCleared(name string) bool {
	switch name {
	case proxy.EdgeAccounts:
		return m.clearedaccounts
	}
	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 *ProxyMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown Proxy 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 *ProxyMutation) ResetEdge(name string) error {
	switch name {
	case proxy.EdgeAccounts:
		m.ResetAccounts()
		return nil
	}
	return fmt.Errorf("unknown Proxy edge %s", name)
}

// RedeemCodeMutation represents an operation that mutates the RedeemCode nodes in the graph.
type RedeemCodeMutation struct {
	config
	op               Op
	typ              string
	id               *int64
	code             *string
	_type            *string
	value            *float64
	addvalue         *float64
	status           *string
	used_at          *time.Time
	notes            *string
	created_at       *time.Time
	validity_days    *int
	addvalidity_days *int
	clearedFields    map[string]struct{}
	user             *int64
	cleareduser      bool
	group            *int64
	clearedgroup     bool
	done             bool
	oldValue         func(context.Context) (*RedeemCode, error)
	predicates       []predicate.RedeemCode
}

var _ ent.Mutation = (*RedeemCodeMutation)(nil)

// redeemcodeOption allows management of the mutation configuration using functional options.
type redeemcodeOption func(*RedeemCodeMutation)

// newRedeemCodeMutation creates new mutation for the RedeemCode entity.
func newRedeemCodeMutation(c config, op Op, opts ...redeemcodeOption) *RedeemCodeMutation {
	m := &RedeemCodeMutation{
		config:        c,
		op:            op,
		typ:           TypeRedeemCode,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withRedeemCodeID sets the ID field of the mutation.
func withRedeemCodeID(id int64) redeemcodeOption {
	return func(m *RedeemCodeMutation) {
		var (
			err   error
			once  sync.Once
			value *RedeemCode
		)
		m.oldValue = func(ctx context.Context) (*RedeemCode, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().RedeemCode.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withRedeemCode sets the old RedeemCode of the mutation.
func withRedeemCode(node *RedeemCode) redeemcodeOption {
	return func(m *RedeemCodeMutation) {
		m.oldValue = func(context.Context) (*RedeemCode, 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 RedeemCodeMutation) 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 RedeemCodeMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *RedeemCodeMutation) ID() (id int64, 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 *RedeemCodeMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().RedeemCode.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCode sets the "code" field.
func (m *RedeemCodeMutation) SetCode(s string) {
	m.code = &s
}

// Code returns the value of the "code" field in the mutation.
func (m *RedeemCodeMutation) Code() (r string, exists bool) {
	v := m.code
	if v == nil {
		return
	}
	return *v, true
}

// OldCode returns the old "code" field's value of the RedeemCode entity.
// If the RedeemCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RedeemCodeMutation) OldCode(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCode is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCode requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCode: %w", err)
	}
	return oldValue.Code, nil
}

// ResetCode resets all changes to the "code" field.
func (m *RedeemCodeMutation) ResetCode() {
	m.code = nil
}

// SetType sets the "type" field.
func (m *RedeemCodeMutation) SetType(s string) {
	m._type = &s
}

// GetType returns the value of the "type" field in the mutation.
func (m *RedeemCodeMutation) GetType() (r string, exists bool) {
	v := m._type
	if v == nil {
		return
	}
	return *v, true
}

// OldType returns the old "type" field's value of the RedeemCode entity.
// If the RedeemCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RedeemCodeMutation) OldType(ctx context.Context) (v string, 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 *RedeemCodeMutation) ResetType() {
	m._type = nil
}

// SetValue sets the "value" field.
func (m *RedeemCodeMutation) SetValue(f float64) {
	m.value = &f
	m.addvalue = nil
}

// Value returns the value of the "value" field in the mutation.
func (m *RedeemCodeMutation) Value() (r float64, exists bool) {
	v := m.value
	if v == nil {
		return
	}
	return *v, true
}

// OldValue returns the old "value" field's value of the RedeemCode entity.
// If the RedeemCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RedeemCodeMutation) OldValue(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldValue is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldValue requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldValue: %w", err)
	}
	return oldValue.Value, nil
}

// AddValue adds f to the "value" field.
func (m *RedeemCodeMutation) AddValue(f float64) {
	if m.addvalue != nil {
		*m.addvalue += f
	} else {
		m.addvalue = &f
	}
}

// AddedValue returns the value that was added to the "value" field in this mutation.
func (m *RedeemCodeMutation) AddedValue() (r float64, exists bool) {
	v := m.addvalue
	if v == nil {
		return
	}
	return *v, true
}

// ResetValue resets all changes to the "value" field.
func (m *RedeemCodeMutation) ResetValue() {
	m.value = nil
	m.addvalue = nil
}

// SetStatus sets the "status" field.
func (m *RedeemCodeMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *RedeemCodeMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the RedeemCode entity.
// If the RedeemCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RedeemCodeMutation) OldStatus(ctx context.Context) (v string, 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 *RedeemCodeMutation) ResetStatus() {
	m.status = nil
}

// SetUsedBy sets the "used_by" field.
func (m *RedeemCodeMutation) SetUsedBy(i int64) {
	m.user = &i
}

// UsedBy returns the value of the "used_by" field in the mutation.
func (m *RedeemCodeMutation) UsedBy() (r int64, exists bool) {
	v := m.user
	if v == nil {
		return
	}
	return *v, true
}

// OldUsedBy returns the old "used_by" field's value of the RedeemCode entity.
// If the RedeemCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RedeemCodeMutation) OldUsedBy(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUsedBy is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUsedBy requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUsedBy: %w", err)
	}
	return oldValue.UsedBy, nil
}

// ClearUsedBy clears the value of the "used_by" field.
func (m *RedeemCodeMutation) ClearUsedBy() {
	m.user = nil
	m.clearedFields[redeemcode.FieldUsedBy] = struct{}{}
}

// UsedByCleared returns if the "used_by" field was cleared in this mutation.
func (m *RedeemCodeMutation) UsedByCleared() bool {
	_, ok := m.clearedFields[redeemcode.FieldUsedBy]
	return ok
}

// ResetUsedBy resets all changes to the "used_by" field.
func (m *RedeemCodeMutation) ResetUsedBy() {
	m.user = nil
	delete(m.clearedFields, redeemcode.FieldUsedBy)
}

// SetUsedAt sets the "used_at" field.
func (m *RedeemCodeMutation) SetUsedAt(t time.Time) {
	m.used_at = &t
}

// UsedAt returns the value of the "used_at" field in the mutation.
func (m *RedeemCodeMutation) UsedAt() (r time.Time, exists bool) {
	v := m.used_at
	if v == nil {
		return
	}
	return *v, true
}

// OldUsedAt returns the old "used_at" field's value of the RedeemCode entity.
// If the RedeemCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RedeemCodeMutation) OldUsedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUsedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUsedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUsedAt: %w", err)
	}
	return oldValue.UsedAt, nil
}

// ClearUsedAt clears the value of the "used_at" field.
func (m *RedeemCodeMutation) ClearUsedAt() {
	m.used_at = nil
	m.clearedFields[redeemcode.FieldUsedAt] = struct{}{}
}

// UsedAtCleared returns if the "used_at" field was cleared in this mutation.
func (m *RedeemCodeMutation) UsedAtCleared() bool {
	_, ok := m.clearedFields[redeemcode.FieldUsedAt]
	return ok
}

// ResetUsedAt resets all changes to the "used_at" field.
func (m *RedeemCodeMutation) ResetUsedAt() {
	m.used_at = nil
	delete(m.clearedFields, redeemcode.FieldUsedAt)
}

// SetNotes sets the "notes" field.
func (m *RedeemCodeMutation) SetNotes(s string) {
	m.notes = &s
}

// Notes returns the value of the "notes" field in the mutation.
func (m *RedeemCodeMutation) Notes() (r string, exists bool) {
	v := m.notes
	if v == nil {
		return
	}
	return *v, true
}

// OldNotes returns the old "notes" field's value of the RedeemCode entity.
// If the RedeemCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RedeemCodeMutation) OldNotes(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldNotes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldNotes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldNotes: %w", err)
	}
	return oldValue.Notes, nil
}

// ClearNotes clears the value of the "notes" field.
func (m *RedeemCodeMutation) ClearNotes() {
	m.notes = nil
	m.clearedFields[redeemcode.FieldNotes] = struct{}{}
}

// NotesCleared returns if the "notes" field was cleared in this mutation.
func (m *RedeemCodeMutation) NotesCleared() bool {
	_, ok := m.clearedFields[redeemcode.FieldNotes]
	return ok
}

// ResetNotes resets all changes to the "notes" field.
func (m *RedeemCodeMutation) ResetNotes() {
	m.notes = nil
	delete(m.clearedFields, redeemcode.FieldNotes)
}

// SetCreatedAt sets the "created_at" field.
func (m *RedeemCodeMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *RedeemCodeMutation) 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 RedeemCode entity.
// If the RedeemCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RedeemCodeMutation) 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 *RedeemCodeMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetGroupID sets the "group_id" field.
func (m *RedeemCodeMutation) SetGroupID(i int64) {
	m.group = &i
}

// GroupID returns the value of the "group_id" field in the mutation.
func (m *RedeemCodeMutation) GroupID() (r int64, exists bool) {
	v := m.group
	if v == nil {
		return
	}
	return *v, true
}

// OldGroupID returns the old "group_id" field's value of the RedeemCode entity.
// If the RedeemCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RedeemCodeMutation) OldGroupID(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldGroupID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldGroupID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldGroupID: %w", err)
	}
	return oldValue.GroupID, nil
}

// ClearGroupID clears the value of the "group_id" field.
func (m *RedeemCodeMutation) ClearGroupID() {
	m.group = nil
	m.clearedFields[redeemcode.FieldGroupID] = struct{}{}
}

// GroupIDCleared returns if the "group_id" field was cleared in this mutation.
func (m *RedeemCodeMutation) GroupIDCleared() bool {
	_, ok := m.clearedFields[redeemcode.FieldGroupID]
	return ok
}

// ResetGroupID resets all changes to the "group_id" field.
func (m *RedeemCodeMutation) ResetGroupID() {
	m.group = nil
	delete(m.clearedFields, redeemcode.FieldGroupID)
}

// SetValidityDays sets the "validity_days" field.
func (m *RedeemCodeMutation) SetValidityDays(i int) {
	m.validity_days = &i
	m.addvalidity_days = nil
}

// ValidityDays returns the value of the "validity_days" field in the mutation.
func (m *RedeemCodeMutation) ValidityDays() (r int, exists bool) {
	v := m.validity_days
	if v == nil {
		return
	}
	return *v, true
}

// OldValidityDays returns the old "validity_days" field's value of the RedeemCode entity.
// If the RedeemCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *RedeemCodeMutation) OldValidityDays(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldValidityDays is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldValidityDays requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldValidityDays: %w", err)
	}
	return oldValue.ValidityDays, nil
}

// AddValidityDays adds i to the "validity_days" field.
func (m *RedeemCodeMutation) AddValidityDays(i int) {
	if m.addvalidity_days != nil {
		*m.addvalidity_days += i
	} else {
		m.addvalidity_days = &i
	}
}

// AddedValidityDays returns the value that was added to the "validity_days" field in this mutation.
func (m *RedeemCodeMutation) AddedValidityDays() (r int, exists bool) {
	v := m.addvalidity_days
	if v == nil {
		return
	}
	return *v, true
}

// ResetValidityDays resets all changes to the "validity_days" field.
func (m *RedeemCodeMutation) ResetValidityDays() {
	m.validity_days = nil
	m.addvalidity_days = nil
}

// SetUserID sets the "user" edge to the User entity by id.
func (m *RedeemCodeMutation) SetUserID(id int64) {
	m.user = &id
}

// ClearUser clears the "user" edge to the User entity.
func (m *RedeemCodeMutation) ClearUser() {
	m.cleareduser = true
	m.clearedFields[redeemcode.FieldUsedBy] = struct{}{}
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *RedeemCodeMutation) UserCleared() bool {
	return m.UsedByCleared() || m.cleareduser
}

// UserID returns the "user" edge ID in the mutation.
func (m *RedeemCodeMutation) UserID() (id int64, exists bool) {
	if m.user != nil {
		return *m.user, true
	}
	return
}

// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *RedeemCodeMutation) UserIDs() (ids []int64) {
	if id := m.user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetUser resets all changes to the "user" edge.
func (m *RedeemCodeMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

// ClearGroup clears the "group" edge to the Group entity.
func (m *RedeemCodeMutation) ClearGroup() {
	m.clearedgroup = true
	m.clearedFields[redeemcode.FieldGroupID] = struct{}{}
}

// GroupCleared reports if the "group" edge to the Group entity was cleared.
func (m *RedeemCodeMutation) GroupCleared() bool {
	return m.GroupIDCleared() || m.clearedgroup
}

// GroupIDs returns the "group" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// GroupID instead. It exists only for internal usage by the builders.
func (m *RedeemCodeMutation) GroupIDs() (ids []int64) {
	if id := m.group; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetGroup resets all changes to the "group" edge.
func (m *RedeemCodeMutation) ResetGroup() {
	m.group = nil
	m.clearedgroup = false
}

// Where appends a list predicates to the RedeemCodeMutation builder.
func (m *RedeemCodeMutation) Where(ps ...predicate.RedeemCode) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the RedeemCodeMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *RedeemCodeMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.RedeemCode, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *RedeemCodeMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *RedeemCodeMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (RedeemCode).
func (m *RedeemCodeMutation) 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 *RedeemCodeMutation) Fields() []string {
	fields := make([]string, 0, 10)
	if m.code != nil {
		fields = append(fields, redeemcode.FieldCode)
	}
	if m._type != nil {
		fields = append(fields, redeemcode.FieldType)
	}
	if m.value != nil {
		fields = append(fields, redeemcode.FieldValue)
	}
	if m.status != nil {
		fields = append(fields, redeemcode.FieldStatus)
	}
	if m.user != nil {
		fields = append(fields, redeemcode.FieldUsedBy)
	}
	if m.used_at != nil {
		fields = append(fields, redeemcode.FieldUsedAt)
	}
	if m.notes != nil {
		fields = append(fields, redeemcode.FieldNotes)
	}
	if m.created_at != nil {
		fields = append(fields, redeemcode.FieldCreatedAt)
	}
	if m.group != nil {
		fields = append(fields, redeemcode.FieldGroupID)
	}
	if m.validity_days != nil {
		fields = append(fields, redeemcode.FieldValidityDays)
	}
	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 *RedeemCodeMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case redeemcode.FieldCode:
		return m.Code()
	case redeemcode.FieldType:
		return m.GetType()
	case redeemcode.FieldValue:
		return m.Value()
	case redeemcode.FieldStatus:
		return m.Status()
	case redeemcode.FieldUsedBy:
		return m.UsedBy()
	case redeemcode.FieldUsedAt:
		return m.UsedAt()
	case redeemcode.FieldNotes:
		return m.Notes()
	case redeemcode.FieldCreatedAt:
		return m.CreatedAt()
	case redeemcode.FieldGroupID:
		return m.GroupID()
	case redeemcode.FieldValidityDays:
		return m.ValidityDays()
	}
	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 *RedeemCodeMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case redeemcode.FieldCode:
		return m.OldCode(ctx)
	case redeemcode.FieldType:
		return m.OldType(ctx)
	case redeemcode.FieldValue:
		return m.OldValue(ctx)
	case redeemcode.FieldStatus:
		return m.OldStatus(ctx)
	case redeemcode.FieldUsedBy:
		return m.OldUsedBy(ctx)
	case redeemcode.FieldUsedAt:
		return m.OldUsedAt(ctx)
	case redeemcode.FieldNotes:
		return m.OldNotes(ctx)
	case redeemcode.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case redeemcode.FieldGroupID:
		return m.OldGroupID(ctx)
	case redeemcode.FieldValidityDays:
		return m.OldValidityDays(ctx)
	}
	return nil, fmt.Errorf("unknown RedeemCode 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 *RedeemCodeMutation) SetField(name string, value ent.Value) error {
	switch name {
	case redeemcode.FieldCode:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCode(v)
		return nil
	case redeemcode.FieldType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetType(v)
		return nil
	case redeemcode.FieldValue:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetValue(v)
		return nil
	case redeemcode.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case redeemcode.FieldUsedBy:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUsedBy(v)
		return nil
	case redeemcode.FieldUsedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUsedAt(v)
		return nil
	case redeemcode.FieldNotes:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNotes(v)
		return nil
	case redeemcode.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 redeemcode.FieldGroupID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetGroupID(v)
		return nil
	case redeemcode.FieldValidityDays:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetValidityDays(v)
		return nil
	}
	return fmt.Errorf("unknown RedeemCode field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *RedeemCodeMutation) AddedFields() []string {
	var fields []string
	if m.addvalue != nil {
		fields = append(fields, redeemcode.FieldValue)
	}
	if m.addvalidity_days != nil {
		fields = append(fields, redeemcode.FieldValidityDays)
	}
	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 *RedeemCodeMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case redeemcode.FieldValue:
		return m.AddedValue()
	case redeemcode.FieldValidityDays:
		return m.AddedValidityDays()
	}
	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 *RedeemCodeMutation) AddField(name string, value ent.Value) error {
	switch name {
	case redeemcode.FieldValue:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddValue(v)
		return nil
	case redeemcode.FieldValidityDays:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddValidityDays(v)
		return nil
	}
	return fmt.Errorf("unknown RedeemCode numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *RedeemCodeMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(redeemcode.FieldUsedBy) {
		fields = append(fields, redeemcode.FieldUsedBy)
	}
	if m.FieldCleared(redeemcode.FieldUsedAt) {
		fields = append(fields, redeemcode.FieldUsedAt)
	}
	if m.FieldCleared(redeemcode.FieldNotes) {
		fields = append(fields, redeemcode.FieldNotes)
	}
	if m.FieldCleared(redeemcode.FieldGroupID) {
		fields = append(fields, redeemcode.FieldGroupID)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *RedeemCodeMutation) 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 *RedeemCodeMutation) ClearField(name string) error {
	switch name {
	case redeemcode.FieldUsedBy:
		m.ClearUsedBy()
		return nil
	case redeemcode.FieldUsedAt:
		m.ClearUsedAt()
		return nil
	case redeemcode.FieldNotes:
		m.ClearNotes()
		return nil
	case redeemcode.FieldGroupID:
		m.ClearGroupID()
		return nil
	}
	return fmt.Errorf("unknown RedeemCode 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 *RedeemCodeMutation) ResetField(name string) error {
	switch name {
	case redeemcode.FieldCode:
		m.ResetCode()
		return nil
	case redeemcode.FieldType:
		m.ResetType()
		return nil
	case redeemcode.FieldValue:
		m.ResetValue()
		return nil
	case redeemcode.FieldStatus:
		m.ResetStatus()
		return nil
	case redeemcode.FieldUsedBy:
		m.ResetUsedBy()
		return nil
	case redeemcode.FieldUsedAt:
		m.ResetUsedAt()
		return nil
	case redeemcode.FieldNotes:
		m.ResetNotes()
		return nil
	case redeemcode.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case redeemcode.FieldGroupID:
		m.ResetGroupID()
		return nil
	case redeemcode.FieldValidityDays:
		m.ResetValidityDays()
		return nil
	}
	return fmt.Errorf("unknown RedeemCode field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *RedeemCodeMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.user != nil {
		edges = append(edges, redeemcode.EdgeUser)
	}
	if m.group != nil {
		edges = append(edges, redeemcode.EdgeGroup)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *RedeemCodeMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case redeemcode.EdgeUser:
		if id := m.user; id != nil {
			return []ent.Value{*id}
		}
	case redeemcode.EdgeGroup:
		if id := m.group; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *RedeemCodeMutation) 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 *RedeemCodeMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *RedeemCodeMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.cleareduser {
		edges = append(edges, redeemcode.EdgeUser)
	}
	if m.clearedgroup {
		edges = append(edges, redeemcode.EdgeGroup)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *RedeemCodeMutation) EdgeCleared(name string) bool {
	switch name {
	case redeemcode.EdgeUser:
		return m.cleareduser
	case redeemcode.EdgeGroup:
		return m.clearedgroup
	}
	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 *RedeemCodeMutation) ClearEdge(name string) error {
	switch name {
	case redeemcode.EdgeUser:
		m.ClearUser()
		return nil
	case redeemcode.EdgeGroup:
		m.ClearGroup()
		return nil
	}
	return fmt.Errorf("unknown RedeemCode 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 *RedeemCodeMutation) ResetEdge(name string) error {
	switch name {
	case redeemcode.EdgeUser:
		m.ResetUser()
		return nil
	case redeemcode.EdgeGroup:
		m.ResetGroup()
		return nil
	}
	return fmt.Errorf("unknown RedeemCode edge %s", name)
}

// SecuritySecretMutation represents an operation that mutates the SecuritySecret nodes in the graph.
type SecuritySecretMutation struct {
	config
	op            Op
	typ           string
	id            *int64
	created_at    *time.Time
	updated_at    *time.Time
	key           *string
	value         *string
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*SecuritySecret, error)
	predicates    []predicate.SecuritySecret
}

var _ ent.Mutation = (*SecuritySecretMutation)(nil)

// securitysecretOption allows management of the mutation configuration using functional options.
type securitysecretOption func(*SecuritySecretMutation)

// newSecuritySecretMutation creates new mutation for the SecuritySecret entity.
func newSecuritySecretMutation(c config, op Op, opts ...securitysecretOption) *SecuritySecretMutation {
	m := &SecuritySecretMutation{
		config:        c,
		op:            op,
		typ:           TypeSecuritySecret,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withSecuritySecretID sets the ID field of the mutation.
func withSecuritySecretID(id int64) securitysecretOption {
	return func(m *SecuritySecretMutation) {
		var (
			err   error
			once  sync.Once
			value *SecuritySecret
		)
		m.oldValue = func(ctx context.Context) (*SecuritySecret, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().SecuritySecret.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withSecuritySecret sets the old SecuritySecret of the mutation.
func withSecuritySecret(node *SecuritySecret) securitysecretOption {
	return func(m *SecuritySecretMutation) {
		m.oldValue = func(context.Context) (*SecuritySecret, 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 SecuritySecretMutation) 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 SecuritySecretMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *SecuritySecretMutation) ID() (id int64, 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 *SecuritySecretMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().SecuritySecret.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *SecuritySecretMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *SecuritySecretMutation) 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 SecuritySecret entity.
// If the SecuritySecret object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SecuritySecretMutation) 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 *SecuritySecretMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *SecuritySecretMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *SecuritySecretMutation) 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 SecuritySecret entity.
// If the SecuritySecret object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SecuritySecretMutation) 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 *SecuritySecretMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetKey sets the "key" field.
func (m *SecuritySecretMutation) SetKey(s string) {
	m.key = &s
}

// Key returns the value of the "key" field in the mutation.
func (m *SecuritySecretMutation) Key() (r string, exists bool) {
	v := m.key
	if v == nil {
		return
	}
	return *v, true
}

// OldKey returns the old "key" field's value of the SecuritySecret entity.
// If the SecuritySecret object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SecuritySecretMutation) OldKey(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldKey is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldKey requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldKey: %w", err)
	}
	return oldValue.Key, nil
}

// ResetKey resets all changes to the "key" field.
func (m *SecuritySecretMutation) ResetKey() {
	m.key = nil
}

// SetValue sets the "value" field.
func (m *SecuritySecretMutation) SetValue(s string) {
	m.value = &s
}

// Value returns the value of the "value" field in the mutation.
func (m *SecuritySecretMutation) Value() (r string, exists bool) {
	v := m.value
	if v == nil {
		return
	}
	return *v, true
}

// OldValue returns the old "value" field's value of the SecuritySecret entity.
// If the SecuritySecret object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SecuritySecretMutation) OldValue(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldValue is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldValue requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldValue: %w", err)
	}
	return oldValue.Value, nil
}

// ResetValue resets all changes to the "value" field.
func (m *SecuritySecretMutation) ResetValue() {
	m.value = nil
}

// Where appends a list predicates to the SecuritySecretMutation builder.
func (m *SecuritySecretMutation) Where(ps ...predicate.SecuritySecret) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the SecuritySecretMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *SecuritySecretMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.SecuritySecret, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *SecuritySecretMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *SecuritySecretMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (SecuritySecret).
func (m *SecuritySecretMutation) 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 *SecuritySecretMutation) Fields() []string {
	fields := make([]string, 0, 4)
	if m.created_at != nil {
		fields = append(fields, securitysecret.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, securitysecret.FieldUpdatedAt)
	}
	if m.key != nil {
		fields = append(fields, securitysecret.FieldKey)
	}
	if m.value != nil {
		fields = append(fields, securitysecret.FieldValue)
	}
	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 *SecuritySecretMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case securitysecret.FieldCreatedAt:
		return m.CreatedAt()
	case securitysecret.FieldUpdatedAt:
		return m.UpdatedAt()
	case securitysecret.FieldKey:
		return m.Key()
	case securitysecret.FieldValue:
		return m.Value()
	}
	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 *SecuritySecretMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case securitysecret.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case securitysecret.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case securitysecret.FieldKey:
		return m.OldKey(ctx)
	case securitysecret.FieldValue:
		return m.OldValue(ctx)
	}
	return nil, fmt.Errorf("unknown SecuritySecret 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 *SecuritySecretMutation) SetField(name string, value ent.Value) error {
	switch name {
	case securitysecret.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 securitysecret.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 securitysecret.FieldKey:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetKey(v)
		return nil
	case securitysecret.FieldValue:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetValue(v)
		return nil
	}
	return fmt.Errorf("unknown SecuritySecret field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *SecuritySecretMutation) 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 *SecuritySecretMutation) 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 *SecuritySecretMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown SecuritySecret numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *SecuritySecretMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *SecuritySecretMutation) 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 *SecuritySecretMutation) ClearField(name string) error {
	return fmt.Errorf("unknown SecuritySecret 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 *SecuritySecretMutation) ResetField(name string) error {
	switch name {
	case securitysecret.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case securitysecret.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case securitysecret.FieldKey:
		m.ResetKey()
		return nil
	case securitysecret.FieldValue:
		m.ResetValue()
		return nil
	}
	return fmt.Errorf("unknown SecuritySecret field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SecuritySecretMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *SecuritySecretMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SecuritySecretMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *SecuritySecretMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SecuritySecretMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *SecuritySecretMutation) EdgeCleared(name string) bool {
	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 *SecuritySecretMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown SecuritySecret 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 *SecuritySecretMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown SecuritySecret edge %s", name)
}

// SettingMutation represents an operation that mutates the Setting nodes in the graph.
type SettingMutation struct {
	config
	op            Op
	typ           string
	id            *int64
	key           *string
	value         *string
	updated_at    *time.Time
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*Setting, error)
	predicates    []predicate.Setting
}

var _ ent.Mutation = (*SettingMutation)(nil)

// settingOption allows management of the mutation configuration using functional options.
type settingOption func(*SettingMutation)

// newSettingMutation creates new mutation for the Setting entity.
func newSettingMutation(c config, op Op, opts ...settingOption) *SettingMutation {
	m := &SettingMutation{
		config:        c,
		op:            op,
		typ:           TypeSetting,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withSettingID sets the ID field of the mutation.
func withSettingID(id int64) settingOption {
	return func(m *SettingMutation) {
		var (
			err   error
			once  sync.Once
			value *Setting
		)
		m.oldValue = func(ctx context.Context) (*Setting, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Setting.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withSetting sets the old Setting of the mutation.
func withSetting(node *Setting) settingOption {
	return func(m *SettingMutation) {
		m.oldValue = func(context.Context) (*Setting, 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 SettingMutation) 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 SettingMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *SettingMutation) ID() (id int64, 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 *SettingMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Setting.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetKey sets the "key" field.
func (m *SettingMutation) SetKey(s string) {
	m.key = &s
}

// Key returns the value of the "key" field in the mutation.
func (m *SettingMutation) Key() (r string, exists bool) {
	v := m.key
	if v == nil {
		return
	}
	return *v, true
}

// OldKey returns the old "key" field's value of the Setting entity.
// If the Setting object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SettingMutation) OldKey(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldKey is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldKey requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldKey: %w", err)
	}
	return oldValue.Key, nil
}

// ResetKey resets all changes to the "key" field.
func (m *SettingMutation) ResetKey() {
	m.key = nil
}

// SetValue sets the "value" field.
func (m *SettingMutation) SetValue(s string) {
	m.value = &s
}

// Value returns the value of the "value" field in the mutation.
func (m *SettingMutation) Value() (r string, exists bool) {
	v := m.value
	if v == nil {
		return
	}
	return *v, true
}

// OldValue returns the old "value" field's value of the Setting entity.
// If the Setting object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SettingMutation) OldValue(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldValue is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldValue requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldValue: %w", err)
	}
	return oldValue.Value, nil
}

// ResetValue resets all changes to the "value" field.
func (m *SettingMutation) ResetValue() {
	m.value = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *SettingMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *SettingMutation) 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 Setting entity.
// If the Setting object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SettingMutation) 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 *SettingMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// Where appends a list predicates to the SettingMutation builder.
func (m *SettingMutation) Where(ps ...predicate.Setting) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the SettingMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *SettingMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.Setting, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *SettingMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *SettingMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (Setting).
func (m *SettingMutation) 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 *SettingMutation) Fields() []string {
	fields := make([]string, 0, 3)
	if m.key != nil {
		fields = append(fields, setting.FieldKey)
	}
	if m.value != nil {
		fields = append(fields, setting.FieldValue)
	}
	if m.updated_at != nil {
		fields = append(fields, setting.FieldUpdatedAt)
	}
	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 *SettingMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case setting.FieldKey:
		return m.Key()
	case setting.FieldValue:
		return m.Value()
	case setting.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	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 *SettingMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case setting.FieldKey:
		return m.OldKey(ctx)
	case setting.FieldValue:
		return m.OldValue(ctx)
	case setting.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Setting 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 *SettingMutation) SetField(name string, value ent.Value) error {
	switch name {
	case setting.FieldKey:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetKey(v)
		return nil
	case setting.FieldValue:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetValue(v)
		return nil
	case setting.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown Setting field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *SettingMutation) 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 *SettingMutation) 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 *SettingMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown Setting numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *SettingMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *SettingMutation) 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 *SettingMutation) ClearField(name string) error {
	return fmt.Errorf("unknown Setting 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 *SettingMutation) ResetField(name string) error {
	switch name {
	case setting.FieldKey:
		m.ResetKey()
		return nil
	case setting.FieldValue:
		m.ResetValue()
		return nil
	case setting.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown Setting field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SettingMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *SettingMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SettingMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *SettingMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SettingMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *SettingMutation) EdgeCleared(name string) bool {
	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 *SettingMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown Setting 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 *SettingMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown Setting edge %s", name)
}

// SubscriptionPlanMutation represents an operation that mutates the SubscriptionPlan nodes in the graph.
type SubscriptionPlanMutation struct {
	config
	op                Op
	typ               string
	id                *int64
	group_id          *int64
	addgroup_id       *int64
	name              *string
	description       *string
	price             *float64
	addprice          *float64
	original_price    *float64
	addoriginal_price *float64
	validity_days     *int
	addvalidity_days  *int
	validity_unit     *string
	features          *string
	product_name      *string
	for_sale          *bool
	sort_order        *int
	addsort_order     *int
	created_at        *time.Time
	updated_at        *time.Time
	clearedFields     map[string]struct{}
	done              bool
	oldValue          func(context.Context) (*SubscriptionPlan, error)
	predicates        []predicate.SubscriptionPlan
}

var _ ent.Mutation = (*SubscriptionPlanMutation)(nil)

// subscriptionplanOption allows management of the mutation configuration using functional options.
type subscriptionplanOption func(*SubscriptionPlanMutation)

// newSubscriptionPlanMutation creates new mutation for the SubscriptionPlan entity.
func newSubscriptionPlanMutation(c config, op Op, opts ...subscriptionplanOption) *SubscriptionPlanMutation {
	m := &SubscriptionPlanMutation{
		config:        c,
		op:            op,
		typ:           TypeSubscriptionPlan,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withSubscriptionPlanID sets the ID field of the mutation.
func withSubscriptionPlanID(id int64) subscriptionplanOption {
	return func(m *SubscriptionPlanMutation) {
		var (
			err   error
			once  sync.Once
			value *SubscriptionPlan
		)
		m.oldValue = func(ctx context.Context) (*SubscriptionPlan, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().SubscriptionPlan.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withSubscriptionPlan sets the old SubscriptionPlan of the mutation.
func withSubscriptionPlan(node *SubscriptionPlan) subscriptionplanOption {
	return func(m *SubscriptionPlanMutation) {
		m.oldValue = func(context.Context) (*SubscriptionPlan, 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 SubscriptionPlanMutation) 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 SubscriptionPlanMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *SubscriptionPlanMutation) ID() (id int64, 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 *SubscriptionPlanMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().SubscriptionPlan.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetGroupID sets the "group_id" field.
func (m *SubscriptionPlanMutation) SetGroupID(i int64) {
	m.group_id = &i
	m.addgroup_id = nil
}

// GroupID returns the value of the "group_id" field in the mutation.
func (m *SubscriptionPlanMutation) GroupID() (r int64, exists bool) {
	v := m.group_id
	if v == nil {
		return
	}
	return *v, true
}

// OldGroupID returns the old "group_id" field's value of the SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) OldGroupID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldGroupID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldGroupID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldGroupID: %w", err)
	}
	return oldValue.GroupID, nil
}

// AddGroupID adds i to the "group_id" field.
func (m *SubscriptionPlanMutation) AddGroupID(i int64) {
	if m.addgroup_id != nil {
		*m.addgroup_id += i
	} else {
		m.addgroup_id = &i
	}
}

// AddedGroupID returns the value that was added to the "group_id" field in this mutation.
func (m *SubscriptionPlanMutation) AddedGroupID() (r int64, exists bool) {
	v := m.addgroup_id
	if v == nil {
		return
	}
	return *v, true
}

// ResetGroupID resets all changes to the "group_id" field.
func (m *SubscriptionPlanMutation) ResetGroupID() {
	m.group_id = nil
	m.addgroup_id = nil
}

// SetName sets the "name" field.
func (m *SubscriptionPlanMutation) SetName(s string) {
	m.name = &s
}

// Name returns the value of the "name" field in the mutation.
func (m *SubscriptionPlanMutation) 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 SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) 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 *SubscriptionPlanMutation) ResetName() {
	m.name = nil
}

// SetDescription sets the "description" field.
func (m *SubscriptionPlanMutation) SetDescription(s string) {
	m.description = &s
}

// Description returns the value of the "description" field in the mutation.
func (m *SubscriptionPlanMutation) 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 SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) 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
}

// ResetDescription resets all changes to the "description" field.
func (m *SubscriptionPlanMutation) ResetDescription() {
	m.description = nil
}

// SetPrice sets the "price" field.
func (m *SubscriptionPlanMutation) SetPrice(f float64) {
	m.price = &f
	m.addprice = nil
}

// Price returns the value of the "price" field in the mutation.
func (m *SubscriptionPlanMutation) Price() (r float64, exists bool) {
	v := m.price
	if v == nil {
		return
	}
	return *v, true
}

// OldPrice returns the old "price" field's value of the SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) OldPrice(ctx context.Context) (v float64, 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
}

// AddPrice adds f to the "price" field.
func (m *SubscriptionPlanMutation) AddPrice(f float64) {
	if m.addprice != nil {
		*m.addprice += f
	} else {
		m.addprice = &f
	}
}

// AddedPrice returns the value that was added to the "price" field in this mutation.
func (m *SubscriptionPlanMutation) AddedPrice() (r float64, exists bool) {
	v := m.addprice
	if v == nil {
		return
	}
	return *v, true
}

// ResetPrice resets all changes to the "price" field.
func (m *SubscriptionPlanMutation) ResetPrice() {
	m.price = nil
	m.addprice = nil
}

// SetOriginalPrice sets the "original_price" field.
func (m *SubscriptionPlanMutation) SetOriginalPrice(f float64) {
	m.original_price = &f
	m.addoriginal_price = nil
}

// OriginalPrice returns the value of the "original_price" field in the mutation.
func (m *SubscriptionPlanMutation) OriginalPrice() (r float64, exists bool) {
	v := m.original_price
	if v == nil {
		return
	}
	return *v, true
}

// OldOriginalPrice returns the old "original_price" field's value of the SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) OldOriginalPrice(ctx context.Context) (v *float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldOriginalPrice is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldOriginalPrice requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldOriginalPrice: %w", err)
	}
	return oldValue.OriginalPrice, nil
}

// AddOriginalPrice adds f to the "original_price" field.
func (m *SubscriptionPlanMutation) AddOriginalPrice(f float64) {
	if m.addoriginal_price != nil {
		*m.addoriginal_price += f
	} else {
		m.addoriginal_price = &f
	}
}

// AddedOriginalPrice returns the value that was added to the "original_price" field in this mutation.
func (m *SubscriptionPlanMutation) AddedOriginalPrice() (r float64, exists bool) {
	v := m.addoriginal_price
	if v == nil {
		return
	}
	return *v, true
}

// ClearOriginalPrice clears the value of the "original_price" field.
func (m *SubscriptionPlanMutation) ClearOriginalPrice() {
	m.original_price = nil
	m.addoriginal_price = nil
	m.clearedFields[subscriptionplan.FieldOriginalPrice] = struct{}{}
}

// OriginalPriceCleared returns if the "original_price" field was cleared in this mutation.
func (m *SubscriptionPlanMutation) OriginalPriceCleared() bool {
	_, ok := m.clearedFields[subscriptionplan.FieldOriginalPrice]
	return ok
}

// ResetOriginalPrice resets all changes to the "original_price" field.
func (m *SubscriptionPlanMutation) ResetOriginalPrice() {
	m.original_price = nil
	m.addoriginal_price = nil
	delete(m.clearedFields, subscriptionplan.FieldOriginalPrice)
}

// SetValidityDays sets the "validity_days" field.
func (m *SubscriptionPlanMutation) SetValidityDays(i int) {
	m.validity_days = &i
	m.addvalidity_days = nil
}

// ValidityDays returns the value of the "validity_days" field in the mutation.
func (m *SubscriptionPlanMutation) ValidityDays() (r int, exists bool) {
	v := m.validity_days
	if v == nil {
		return
	}
	return *v, true
}

// OldValidityDays returns the old "validity_days" field's value of the SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) OldValidityDays(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldValidityDays is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldValidityDays requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldValidityDays: %w", err)
	}
	return oldValue.ValidityDays, nil
}

// AddValidityDays adds i to the "validity_days" field.
func (m *SubscriptionPlanMutation) AddValidityDays(i int) {
	if m.addvalidity_days != nil {
		*m.addvalidity_days += i
	} else {
		m.addvalidity_days = &i
	}
}

// AddedValidityDays returns the value that was added to the "validity_days" field in this mutation.
func (m *SubscriptionPlanMutation) AddedValidityDays() (r int, exists bool) {
	v := m.addvalidity_days
	if v == nil {
		return
	}
	return *v, true
}

// ResetValidityDays resets all changes to the "validity_days" field.
func (m *SubscriptionPlanMutation) ResetValidityDays() {
	m.validity_days = nil
	m.addvalidity_days = nil
}

// SetValidityUnit sets the "validity_unit" field.
func (m *SubscriptionPlanMutation) SetValidityUnit(s string) {
	m.validity_unit = &s
}

// ValidityUnit returns the value of the "validity_unit" field in the mutation.
func (m *SubscriptionPlanMutation) ValidityUnit() (r string, exists bool) {
	v := m.validity_unit
	if v == nil {
		return
	}
	return *v, true
}

// OldValidityUnit returns the old "validity_unit" field's value of the SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) OldValidityUnit(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldValidityUnit is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldValidityUnit requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldValidityUnit: %w", err)
	}
	return oldValue.ValidityUnit, nil
}

// ResetValidityUnit resets all changes to the "validity_unit" field.
func (m *SubscriptionPlanMutation) ResetValidityUnit() {
	m.validity_unit = nil
}

// SetFeatures sets the "features" field.
func (m *SubscriptionPlanMutation) SetFeatures(s string) {
	m.features = &s
}

// Features returns the value of the "features" field in the mutation.
func (m *SubscriptionPlanMutation) Features() (r string, exists bool) {
	v := m.features
	if v == nil {
		return
	}
	return *v, true
}

// OldFeatures returns the old "features" field's value of the SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) OldFeatures(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFeatures is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFeatures requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFeatures: %w", err)
	}
	return oldValue.Features, nil
}

// ResetFeatures resets all changes to the "features" field.
func (m *SubscriptionPlanMutation) ResetFeatures() {
	m.features = nil
}

// SetProductName sets the "product_name" field.
func (m *SubscriptionPlanMutation) SetProductName(s string) {
	m.product_name = &s
}

// ProductName returns the value of the "product_name" field in the mutation.
func (m *SubscriptionPlanMutation) ProductName() (r string, exists bool) {
	v := m.product_name
	if v == nil {
		return
	}
	return *v, true
}

// OldProductName returns the old "product_name" field's value of the SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) OldProductName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldProductName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldProductName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldProductName: %w", err)
	}
	return oldValue.ProductName, nil
}

// ResetProductName resets all changes to the "product_name" field.
func (m *SubscriptionPlanMutation) ResetProductName() {
	m.product_name = nil
}

// SetForSale sets the "for_sale" field.
func (m *SubscriptionPlanMutation) SetForSale(b bool) {
	m.for_sale = &b
}

// ForSale returns the value of the "for_sale" field in the mutation.
func (m *SubscriptionPlanMutation) ForSale() (r bool, exists bool) {
	v := m.for_sale
	if v == nil {
		return
	}
	return *v, true
}

// OldForSale returns the old "for_sale" field's value of the SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) OldForSale(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldForSale is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldForSale requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldForSale: %w", err)
	}
	return oldValue.ForSale, nil
}

// ResetForSale resets all changes to the "for_sale" field.
func (m *SubscriptionPlanMutation) ResetForSale() {
	m.for_sale = nil
}

// SetSortOrder sets the "sort_order" field.
func (m *SubscriptionPlanMutation) SetSortOrder(i int) {
	m.sort_order = &i
	m.addsort_order = nil
}

// SortOrder returns the value of the "sort_order" field in the mutation.
func (m *SubscriptionPlanMutation) SortOrder() (r int, exists bool) {
	v := m.sort_order
	if v == nil {
		return
	}
	return *v, true
}

// OldSortOrder returns the old "sort_order" field's value of the SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) OldSortOrder(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSortOrder is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSortOrder requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSortOrder: %w", err)
	}
	return oldValue.SortOrder, nil
}

// AddSortOrder adds i to the "sort_order" field.
func (m *SubscriptionPlanMutation) AddSortOrder(i int) {
	if m.addsort_order != nil {
		*m.addsort_order += i
	} else {
		m.addsort_order = &i
	}
}

// AddedSortOrder returns the value that was added to the "sort_order" field in this mutation.
func (m *SubscriptionPlanMutation) AddedSortOrder() (r int, exists bool) {
	v := m.addsort_order
	if v == nil {
		return
	}
	return *v, true
}

// ResetSortOrder resets all changes to the "sort_order" field.
func (m *SubscriptionPlanMutation) ResetSortOrder() {
	m.sort_order = nil
	m.addsort_order = nil
}

// SetCreatedAt sets the "created_at" field.
func (m *SubscriptionPlanMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *SubscriptionPlanMutation) 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 SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) 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 *SubscriptionPlanMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *SubscriptionPlanMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *SubscriptionPlanMutation) 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 SubscriptionPlan entity.
// If the SubscriptionPlan object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *SubscriptionPlanMutation) 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 *SubscriptionPlanMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// Where appends a list predicates to the SubscriptionPlanMutation builder.
func (m *SubscriptionPlanMutation) Where(ps ...predicate.SubscriptionPlan) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the SubscriptionPlanMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *SubscriptionPlanMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.SubscriptionPlan, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *SubscriptionPlanMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *SubscriptionPlanMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (SubscriptionPlan).
func (m *SubscriptionPlanMutation) 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 *SubscriptionPlanMutation) Fields() []string {
	fields := make([]string, 0, 13)
	if m.group_id != nil {
		fields = append(fields, subscriptionplan.FieldGroupID)
	}
	if m.name != nil {
		fields = append(fields, subscriptionplan.FieldName)
	}
	if m.description != nil {
		fields = append(fields, subscriptionplan.FieldDescription)
	}
	if m.price != nil {
		fields = append(fields, subscriptionplan.FieldPrice)
	}
	if m.original_price != nil {
		fields = append(fields, subscriptionplan.FieldOriginalPrice)
	}
	if m.validity_days != nil {
		fields = append(fields, subscriptionplan.FieldValidityDays)
	}
	if m.validity_unit != nil {
		fields = append(fields, subscriptionplan.FieldValidityUnit)
	}
	if m.features != nil {
		fields = append(fields, subscriptionplan.FieldFeatures)
	}
	if m.product_name != nil {
		fields = append(fields, subscriptionplan.FieldProductName)
	}
	if m.for_sale != nil {
		fields = append(fields, subscriptionplan.FieldForSale)
	}
	if m.sort_order != nil {
		fields = append(fields, subscriptionplan.FieldSortOrder)
	}
	if m.created_at != nil {
		fields = append(fields, subscriptionplan.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, subscriptionplan.FieldUpdatedAt)
	}
	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 *SubscriptionPlanMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case subscriptionplan.FieldGroupID:
		return m.GroupID()
	case subscriptionplan.FieldName:
		return m.Name()
	case subscriptionplan.FieldDescription:
		return m.Description()
	case subscriptionplan.FieldPrice:
		return m.Price()
	case subscriptionplan.FieldOriginalPrice:
		return m.OriginalPrice()
	case subscriptionplan.FieldValidityDays:
		return m.ValidityDays()
	case subscriptionplan.FieldValidityUnit:
		return m.ValidityUnit()
	case subscriptionplan.FieldFeatures:
		return m.Features()
	case subscriptionplan.FieldProductName:
		return m.ProductName()
	case subscriptionplan.FieldForSale:
		return m.ForSale()
	case subscriptionplan.FieldSortOrder:
		return m.SortOrder()
	case subscriptionplan.FieldCreatedAt:
		return m.CreatedAt()
	case subscriptionplan.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	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 *SubscriptionPlanMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case subscriptionplan.FieldGroupID:
		return m.OldGroupID(ctx)
	case subscriptionplan.FieldName:
		return m.OldName(ctx)
	case subscriptionplan.FieldDescription:
		return m.OldDescription(ctx)
	case subscriptionplan.FieldPrice:
		return m.OldPrice(ctx)
	case subscriptionplan.FieldOriginalPrice:
		return m.OldOriginalPrice(ctx)
	case subscriptionplan.FieldValidityDays:
		return m.OldValidityDays(ctx)
	case subscriptionplan.FieldValidityUnit:
		return m.OldValidityUnit(ctx)
	case subscriptionplan.FieldFeatures:
		return m.OldFeatures(ctx)
	case subscriptionplan.FieldProductName:
		return m.OldProductName(ctx)
	case subscriptionplan.FieldForSale:
		return m.OldForSale(ctx)
	case subscriptionplan.FieldSortOrder:
		return m.OldSortOrder(ctx)
	case subscriptionplan.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case subscriptionplan.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown SubscriptionPlan 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 *SubscriptionPlanMutation) SetField(name string, value ent.Value) error {
	switch name {
	case subscriptionplan.FieldGroupID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetGroupID(v)
		return nil
	case subscriptionplan.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case subscriptionplan.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case subscriptionplan.FieldPrice:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPrice(v)
		return nil
	case subscriptionplan.FieldOriginalPrice:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOriginalPrice(v)
		return nil
	case subscriptionplan.FieldValidityDays:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetValidityDays(v)
		return nil
	case subscriptionplan.FieldValidityUnit:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetValidityUnit(v)
		return nil
	case subscriptionplan.FieldFeatures:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFeatures(v)
		return nil
	case subscriptionplan.FieldProductName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetProductName(v)
		return nil
	case subscriptionplan.FieldForSale:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetForSale(v)
		return nil
	case subscriptionplan.FieldSortOrder:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSortOrder(v)
		return nil
	case subscriptionplan.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 subscriptionplan.FieldUpdatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpdatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown SubscriptionPlan field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *SubscriptionPlanMutation) AddedFields() []string {
	var fields []string
	if m.addgroup_id != nil {
		fields = append(fields, subscriptionplan.FieldGroupID)
	}
	if m.addprice != nil {
		fields = append(fields, subscriptionplan.FieldPrice)
	}
	if m.addoriginal_price != nil {
		fields = append(fields, subscriptionplan.FieldOriginalPrice)
	}
	if m.addvalidity_days != nil {
		fields = append(fields, subscriptionplan.FieldValidityDays)
	}
	if m.addsort_order != nil {
		fields = append(fields, subscriptionplan.FieldSortOrder)
	}
	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 *SubscriptionPlanMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case subscriptionplan.FieldGroupID:
		return m.AddedGroupID()
	case subscriptionplan.FieldPrice:
		return m.AddedPrice()
	case subscriptionplan.FieldOriginalPrice:
		return m.AddedOriginalPrice()
	case subscriptionplan.FieldValidityDays:
		return m.AddedValidityDays()
	case subscriptionplan.FieldSortOrder:
		return m.AddedSortOrder()
	}
	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 *SubscriptionPlanMutation) AddField(name string, value ent.Value) error {
	switch name {
	case subscriptionplan.FieldGroupID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddGroupID(v)
		return nil
	case subscriptionplan.FieldPrice:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddPrice(v)
		return nil
	case subscriptionplan.FieldOriginalPrice:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddOriginalPrice(v)
		return nil
	case subscriptionplan.FieldValidityDays:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddValidityDays(v)
		return nil
	case subscriptionplan.FieldSortOrder:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddSortOrder(v)
		return nil
	}
	return fmt.Errorf("unknown SubscriptionPlan numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *SubscriptionPlanMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(subscriptionplan.FieldOriginalPrice) {
		fields = append(fields, subscriptionplan.FieldOriginalPrice)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *SubscriptionPlanMutation) 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 *SubscriptionPlanMutation) ClearField(name string) error {
	switch name {
	case subscriptionplan.FieldOriginalPrice:
		m.ClearOriginalPrice()
		return nil
	}
	return fmt.Errorf("unknown SubscriptionPlan 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 *SubscriptionPlanMutation) ResetField(name string) error {
	switch name {
	case subscriptionplan.FieldGroupID:
		m.ResetGroupID()
		return nil
	case subscriptionplan.FieldName:
		m.ResetName()
		return nil
	case subscriptionplan.FieldDescription:
		m.ResetDescription()
		return nil
	case subscriptionplan.FieldPrice:
		m.ResetPrice()
		return nil
	case subscriptionplan.FieldOriginalPrice:
		m.ResetOriginalPrice()
		return nil
	case subscriptionplan.FieldValidityDays:
		m.ResetValidityDays()
		return nil
	case subscriptionplan.FieldValidityUnit:
		m.ResetValidityUnit()
		return nil
	case subscriptionplan.FieldFeatures:
		m.ResetFeatures()
		return nil
	case subscriptionplan.FieldProductName:
		m.ResetProductName()
		return nil
	case subscriptionplan.FieldForSale:
		m.ResetForSale()
		return nil
	case subscriptionplan.FieldSortOrder:
		m.ResetSortOrder()
		return nil
	case subscriptionplan.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case subscriptionplan.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown SubscriptionPlan field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SubscriptionPlanMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *SubscriptionPlanMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SubscriptionPlanMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *SubscriptionPlanMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SubscriptionPlanMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *SubscriptionPlanMutation) EdgeCleared(name string) bool {
	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 *SubscriptionPlanMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown SubscriptionPlan 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 *SubscriptionPlanMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown SubscriptionPlan edge %s", name)
}

// TLSFingerprintProfileMutation represents an operation that mutates the TLSFingerprintProfile nodes in the graph.
type TLSFingerprintProfileMutation struct {
	config
	op                         Op
	typ                        string
	id                         *int64
	created_at                 *time.Time
	updated_at                 *time.Time
	name                       *string
	description                *string
	enable_grease              *bool
	cipher_suites              *[]uint16
	appendcipher_suites        []uint16
	curves                     *[]uint16
	appendcurves               []uint16
	point_formats              *[]uint16
	appendpoint_formats        []uint16
	signature_algorithms       *[]uint16
	appendsignature_algorithms []uint16
	alpn_protocols             *[]string
	appendalpn_protocols       []string
	supported_versions         *[]uint16
	appendsupported_versions   []uint16
	key_share_groups           *[]uint16
	appendkey_share_groups     []uint16
	psk_modes                  *[]uint16
	appendpsk_modes            []uint16
	extensions                 *[]uint16
	appendextensions           []uint16
	clearedFields              map[string]struct{}
	done                       bool
	oldValue                   func(context.Context) (*TLSFingerprintProfile, error)
	predicates                 []predicate.TLSFingerprintProfile
}

var _ ent.Mutation = (*TLSFingerprintProfileMutation)(nil)

// tlsfingerprintprofileOption allows management of the mutation configuration using functional options.
type tlsfingerprintprofileOption func(*TLSFingerprintProfileMutation)

// newTLSFingerprintProfileMutation creates new mutation for the TLSFingerprintProfile entity.
func newTLSFingerprintProfileMutation(c config, op Op, opts ...tlsfingerprintprofileOption) *TLSFingerprintProfileMutation {
	m := &TLSFingerprintProfileMutation{
		config:        c,
		op:            op,
		typ:           TypeTLSFingerprintProfile,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withTLSFingerprintProfileID sets the ID field of the mutation.
func withTLSFingerprintProfileID(id int64) tlsfingerprintprofileOption {
	return func(m *TLSFingerprintProfileMutation) {
		var (
			err   error
			once  sync.Once
			value *TLSFingerprintProfile
		)
		m.oldValue = func(ctx context.Context) (*TLSFingerprintProfile, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().TLSFingerprintProfile.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withTLSFingerprintProfile sets the old TLSFingerprintProfile of the mutation.
func withTLSFingerprintProfile(node *TLSFingerprintProfile) tlsfingerprintprofileOption {
	return func(m *TLSFingerprintProfileMutation) {
		m.oldValue = func(context.Context) (*TLSFingerprintProfile, 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 TLSFingerprintProfileMutation) 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 TLSFingerprintProfileMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *TLSFingerprintProfileMutation) ID() (id int64, 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 *TLSFingerprintProfileMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().TLSFingerprintProfile.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *TLSFingerprintProfileMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *TLSFingerprintProfileMutation) 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 TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) 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 *TLSFingerprintProfileMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *TLSFingerprintProfileMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *TLSFingerprintProfileMutation) 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 TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) 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 *TLSFingerprintProfileMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetName sets the "name" field.
func (m *TLSFingerprintProfileMutation) SetName(s string) {
	m.name = &s
}

// Name returns the value of the "name" field in the mutation.
func (m *TLSFingerprintProfileMutation) 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 TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) 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 *TLSFingerprintProfileMutation) ResetName() {
	m.name = nil
}

// SetDescription sets the "description" field.
func (m *TLSFingerprintProfileMutation) SetDescription(s string) {
	m.description = &s
}

// Description returns the value of the "description" field in the mutation.
func (m *TLSFingerprintProfileMutation) 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 TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) 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 *TLSFingerprintProfileMutation) ClearDescription() {
	m.description = nil
	m.clearedFields[tlsfingerprintprofile.FieldDescription] = struct{}{}
}

// DescriptionCleared returns if the "description" field was cleared in this mutation.
func (m *TLSFingerprintProfileMutation) DescriptionCleared() bool {
	_, ok := m.clearedFields[tlsfingerprintprofile.FieldDescription]
	return ok
}

// ResetDescription resets all changes to the "description" field.
func (m *TLSFingerprintProfileMutation) ResetDescription() {
	m.description = nil
	delete(m.clearedFields, tlsfingerprintprofile.FieldDescription)
}

// SetEnableGrease sets the "enable_grease" field.
func (m *TLSFingerprintProfileMutation) SetEnableGrease(b bool) {
	m.enable_grease = &b
}

// EnableGrease returns the value of the "enable_grease" field in the mutation.
func (m *TLSFingerprintProfileMutation) EnableGrease() (r bool, exists bool) {
	v := m.enable_grease
	if v == nil {
		return
	}
	return *v, true
}

// OldEnableGrease returns the old "enable_grease" field's value of the TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) OldEnableGrease(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldEnableGrease is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldEnableGrease requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldEnableGrease: %w", err)
	}
	return oldValue.EnableGrease, nil
}

// ResetEnableGrease resets all changes to the "enable_grease" field.
func (m *TLSFingerprintProfileMutation) ResetEnableGrease() {
	m.enable_grease = nil
}

// SetCipherSuites sets the "cipher_suites" field.
func (m *TLSFingerprintProfileMutation) SetCipherSuites(u []uint16) {
	m.cipher_suites = &u
	m.appendcipher_suites = nil
}

// CipherSuites returns the value of the "cipher_suites" field in the mutation.
func (m *TLSFingerprintProfileMutation) CipherSuites() (r []uint16, exists bool) {
	v := m.cipher_suites
	if v == nil {
		return
	}
	return *v, true
}

// OldCipherSuites returns the old "cipher_suites" field's value of the TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) OldCipherSuites(ctx context.Context) (v []uint16, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCipherSuites is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCipherSuites requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCipherSuites: %w", err)
	}
	return oldValue.CipherSuites, nil
}

// AppendCipherSuites adds u to the "cipher_suites" field.
func (m *TLSFingerprintProfileMutation) AppendCipherSuites(u []uint16) {
	m.appendcipher_suites = append(m.appendcipher_suites, u...)
}

// AppendedCipherSuites returns the list of values that were appended to the "cipher_suites" field in this mutation.
func (m *TLSFingerprintProfileMutation) AppendedCipherSuites() ([]uint16, bool) {
	if len(m.appendcipher_suites) == 0 {
		return nil, false
	}
	return m.appendcipher_suites, true
}

// ClearCipherSuites clears the value of the "cipher_suites" field.
func (m *TLSFingerprintProfileMutation) ClearCipherSuites() {
	m.cipher_suites = nil
	m.appendcipher_suites = nil
	m.clearedFields[tlsfingerprintprofile.FieldCipherSuites] = struct{}{}
}

// CipherSuitesCleared returns if the "cipher_suites" field was cleared in this mutation.
func (m *TLSFingerprintProfileMutation) CipherSuitesCleared() bool {
	_, ok := m.clearedFields[tlsfingerprintprofile.FieldCipherSuites]
	return ok
}

// ResetCipherSuites resets all changes to the "cipher_suites" field.
func (m *TLSFingerprintProfileMutation) ResetCipherSuites() {
	m.cipher_suites = nil
	m.appendcipher_suites = nil
	delete(m.clearedFields, tlsfingerprintprofile.FieldCipherSuites)
}

// SetCurves sets the "curves" field.
func (m *TLSFingerprintProfileMutation) SetCurves(u []uint16) {
	m.curves = &u
	m.appendcurves = nil
}

// Curves returns the value of the "curves" field in the mutation.
func (m *TLSFingerprintProfileMutation) Curves() (r []uint16, exists bool) {
	v := m.curves
	if v == nil {
		return
	}
	return *v, true
}

// OldCurves returns the old "curves" field's value of the TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) OldCurves(ctx context.Context) (v []uint16, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCurves is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCurves requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCurves: %w", err)
	}
	return oldValue.Curves, nil
}

// AppendCurves adds u to the "curves" field.
func (m *TLSFingerprintProfileMutation) AppendCurves(u []uint16) {
	m.appendcurves = append(m.appendcurves, u...)
}

// AppendedCurves returns the list of values that were appended to the "curves" field in this mutation.
func (m *TLSFingerprintProfileMutation) AppendedCurves() ([]uint16, bool) {
	if len(m.appendcurves) == 0 {
		return nil, false
	}
	return m.appendcurves, true
}

// ClearCurves clears the value of the "curves" field.
func (m *TLSFingerprintProfileMutation) ClearCurves() {
	m.curves = nil
	m.appendcurves = nil
	m.clearedFields[tlsfingerprintprofile.FieldCurves] = struct{}{}
}

// CurvesCleared returns if the "curves" field was cleared in this mutation.
func (m *TLSFingerprintProfileMutation) CurvesCleared() bool {
	_, ok := m.clearedFields[tlsfingerprintprofile.FieldCurves]
	return ok
}

// ResetCurves resets all changes to the "curves" field.
func (m *TLSFingerprintProfileMutation) ResetCurves() {
	m.curves = nil
	m.appendcurves = nil
	delete(m.clearedFields, tlsfingerprintprofile.FieldCurves)
}

// SetPointFormats sets the "point_formats" field.
func (m *TLSFingerprintProfileMutation) SetPointFormats(u []uint16) {
	m.point_formats = &u
	m.appendpoint_formats = nil
}

// PointFormats returns the value of the "point_formats" field in the mutation.
func (m *TLSFingerprintProfileMutation) PointFormats() (r []uint16, exists bool) {
	v := m.point_formats
	if v == nil {
		return
	}
	return *v, true
}

// OldPointFormats returns the old "point_formats" field's value of the TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) OldPointFormats(ctx context.Context) (v []uint16, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPointFormats is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPointFormats requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPointFormats: %w", err)
	}
	return oldValue.PointFormats, nil
}

// AppendPointFormats adds u to the "point_formats" field.
func (m *TLSFingerprintProfileMutation) AppendPointFormats(u []uint16) {
	m.appendpoint_formats = append(m.appendpoint_formats, u...)
}

// AppendedPointFormats returns the list of values that were appended to the "point_formats" field in this mutation.
func (m *TLSFingerprintProfileMutation) AppendedPointFormats() ([]uint16, bool) {
	if len(m.appendpoint_formats) == 0 {
		return nil, false
	}
	return m.appendpoint_formats, true
}

// ClearPointFormats clears the value of the "point_formats" field.
func (m *TLSFingerprintProfileMutation) ClearPointFormats() {
	m.point_formats = nil
	m.appendpoint_formats = nil
	m.clearedFields[tlsfingerprintprofile.FieldPointFormats] = struct{}{}
}

// PointFormatsCleared returns if the "point_formats" field was cleared in this mutation.
func (m *TLSFingerprintProfileMutation) PointFormatsCleared() bool {
	_, ok := m.clearedFields[tlsfingerprintprofile.FieldPointFormats]
	return ok
}

// ResetPointFormats resets all changes to the "point_formats" field.
func (m *TLSFingerprintProfileMutation) ResetPointFormats() {
	m.point_formats = nil
	m.appendpoint_formats = nil
	delete(m.clearedFields, tlsfingerprintprofile.FieldPointFormats)
}

// SetSignatureAlgorithms sets the "signature_algorithms" field.
func (m *TLSFingerprintProfileMutation) SetSignatureAlgorithms(u []uint16) {
	m.signature_algorithms = &u
	m.appendsignature_algorithms = nil
}

// SignatureAlgorithms returns the value of the "signature_algorithms" field in the mutation.
func (m *TLSFingerprintProfileMutation) SignatureAlgorithms() (r []uint16, exists bool) {
	v := m.signature_algorithms
	if v == nil {
		return
	}
	return *v, true
}

// OldSignatureAlgorithms returns the old "signature_algorithms" field's value of the TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) OldSignatureAlgorithms(ctx context.Context) (v []uint16, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSignatureAlgorithms is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSignatureAlgorithms requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSignatureAlgorithms: %w", err)
	}
	return oldValue.SignatureAlgorithms, nil
}

// AppendSignatureAlgorithms adds u to the "signature_algorithms" field.
func (m *TLSFingerprintProfileMutation) AppendSignatureAlgorithms(u []uint16) {
	m.appendsignature_algorithms = append(m.appendsignature_algorithms, u...)
}

// AppendedSignatureAlgorithms returns the list of values that were appended to the "signature_algorithms" field in this mutation.
func (m *TLSFingerprintProfileMutation) AppendedSignatureAlgorithms() ([]uint16, bool) {
	if len(m.appendsignature_algorithms) == 0 {
		return nil, false
	}
	return m.appendsignature_algorithms, true
}

// ClearSignatureAlgorithms clears the value of the "signature_algorithms" field.
func (m *TLSFingerprintProfileMutation) ClearSignatureAlgorithms() {
	m.signature_algorithms = nil
	m.appendsignature_algorithms = nil
	m.clearedFields[tlsfingerprintprofile.FieldSignatureAlgorithms] = struct{}{}
}

// SignatureAlgorithmsCleared returns if the "signature_algorithms" field was cleared in this mutation.
func (m *TLSFingerprintProfileMutation) SignatureAlgorithmsCleared() bool {
	_, ok := m.clearedFields[tlsfingerprintprofile.FieldSignatureAlgorithms]
	return ok
}

// ResetSignatureAlgorithms resets all changes to the "signature_algorithms" field.
func (m *TLSFingerprintProfileMutation) ResetSignatureAlgorithms() {
	m.signature_algorithms = nil
	m.appendsignature_algorithms = nil
	delete(m.clearedFields, tlsfingerprintprofile.FieldSignatureAlgorithms)
}

// SetAlpnProtocols sets the "alpn_protocols" field.
func (m *TLSFingerprintProfileMutation) SetAlpnProtocols(s []string) {
	m.alpn_protocols = &s
	m.appendalpn_protocols = nil
}

// AlpnProtocols returns the value of the "alpn_protocols" field in the mutation.
func (m *TLSFingerprintProfileMutation) AlpnProtocols() (r []string, exists bool) {
	v := m.alpn_protocols
	if v == nil {
		return
	}
	return *v, true
}

// OldAlpnProtocols returns the old "alpn_protocols" field's value of the TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) OldAlpnProtocols(ctx context.Context) (v []string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAlpnProtocols is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAlpnProtocols requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAlpnProtocols: %w", err)
	}
	return oldValue.AlpnProtocols, nil
}

// AppendAlpnProtocols adds s to the "alpn_protocols" field.
func (m *TLSFingerprintProfileMutation) AppendAlpnProtocols(s []string) {
	m.appendalpn_protocols = append(m.appendalpn_protocols, s...)
}

// AppendedAlpnProtocols returns the list of values that were appended to the "alpn_protocols" field in this mutation.
func (m *TLSFingerprintProfileMutation) AppendedAlpnProtocols() ([]string, bool) {
	if len(m.appendalpn_protocols) == 0 {
		return nil, false
	}
	return m.appendalpn_protocols, true
}

// ClearAlpnProtocols clears the value of the "alpn_protocols" field.
func (m *TLSFingerprintProfileMutation) ClearAlpnProtocols() {
	m.alpn_protocols = nil
	m.appendalpn_protocols = nil
	m.clearedFields[tlsfingerprintprofile.FieldAlpnProtocols] = struct{}{}
}

// AlpnProtocolsCleared returns if the "alpn_protocols" field was cleared in this mutation.
func (m *TLSFingerprintProfileMutation) AlpnProtocolsCleared() bool {
	_, ok := m.clearedFields[tlsfingerprintprofile.FieldAlpnProtocols]
	return ok
}

// ResetAlpnProtocols resets all changes to the "alpn_protocols" field.
func (m *TLSFingerprintProfileMutation) ResetAlpnProtocols() {
	m.alpn_protocols = nil
	m.appendalpn_protocols = nil
	delete(m.clearedFields, tlsfingerprintprofile.FieldAlpnProtocols)
}

// SetSupportedVersions sets the "supported_versions" field.
func (m *TLSFingerprintProfileMutation) SetSupportedVersions(u []uint16) {
	m.supported_versions = &u
	m.appendsupported_versions = nil
}

// SupportedVersions returns the value of the "supported_versions" field in the mutation.
func (m *TLSFingerprintProfileMutation) SupportedVersions() (r []uint16, exists bool) {
	v := m.supported_versions
	if v == nil {
		return
	}
	return *v, true
}

// OldSupportedVersions returns the old "supported_versions" field's value of the TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) OldSupportedVersions(ctx context.Context) (v []uint16, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSupportedVersions is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSupportedVersions requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSupportedVersions: %w", err)
	}
	return oldValue.SupportedVersions, nil
}

// AppendSupportedVersions adds u to the "supported_versions" field.
func (m *TLSFingerprintProfileMutation) AppendSupportedVersions(u []uint16) {
	m.appendsupported_versions = append(m.appendsupported_versions, u...)
}

// AppendedSupportedVersions returns the list of values that were appended to the "supported_versions" field in this mutation.
func (m *TLSFingerprintProfileMutation) AppendedSupportedVersions() ([]uint16, bool) {
	if len(m.appendsupported_versions) == 0 {
		return nil, false
	}
	return m.appendsupported_versions, true
}

// ClearSupportedVersions clears the value of the "supported_versions" field.
func (m *TLSFingerprintProfileMutation) ClearSupportedVersions() {
	m.supported_versions = nil
	m.appendsupported_versions = nil
	m.clearedFields[tlsfingerprintprofile.FieldSupportedVersions] = struct{}{}
}

// SupportedVersionsCleared returns if the "supported_versions" field was cleared in this mutation.
func (m *TLSFingerprintProfileMutation) SupportedVersionsCleared() bool {
	_, ok := m.clearedFields[tlsfingerprintprofile.FieldSupportedVersions]
	return ok
}

// ResetSupportedVersions resets all changes to the "supported_versions" field.
func (m *TLSFingerprintProfileMutation) ResetSupportedVersions() {
	m.supported_versions = nil
	m.appendsupported_versions = nil
	delete(m.clearedFields, tlsfingerprintprofile.FieldSupportedVersions)
}

// SetKeyShareGroups sets the "key_share_groups" field.
func (m *TLSFingerprintProfileMutation) SetKeyShareGroups(u []uint16) {
	m.key_share_groups = &u
	m.appendkey_share_groups = nil
}

// KeyShareGroups returns the value of the "key_share_groups" field in the mutation.
func (m *TLSFingerprintProfileMutation) KeyShareGroups() (r []uint16, exists bool) {
	v := m.key_share_groups
	if v == nil {
		return
	}
	return *v, true
}

// OldKeyShareGroups returns the old "key_share_groups" field's value of the TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) OldKeyShareGroups(ctx context.Context) (v []uint16, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldKeyShareGroups is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldKeyShareGroups requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldKeyShareGroups: %w", err)
	}
	return oldValue.KeyShareGroups, nil
}

// AppendKeyShareGroups adds u to the "key_share_groups" field.
func (m *TLSFingerprintProfileMutation) AppendKeyShareGroups(u []uint16) {
	m.appendkey_share_groups = append(m.appendkey_share_groups, u...)
}

// AppendedKeyShareGroups returns the list of values that were appended to the "key_share_groups" field in this mutation.
func (m *TLSFingerprintProfileMutation) AppendedKeyShareGroups() ([]uint16, bool) {
	if len(m.appendkey_share_groups) == 0 {
		return nil, false
	}
	return m.appendkey_share_groups, true
}

// ClearKeyShareGroups clears the value of the "key_share_groups" field.
func (m *TLSFingerprintProfileMutation) ClearKeyShareGroups() {
	m.key_share_groups = nil
	m.appendkey_share_groups = nil
	m.clearedFields[tlsfingerprintprofile.FieldKeyShareGroups] = struct{}{}
}

// KeyShareGroupsCleared returns if the "key_share_groups" field was cleared in this mutation.
func (m *TLSFingerprintProfileMutation) KeyShareGroupsCleared() bool {
	_, ok := m.clearedFields[tlsfingerprintprofile.FieldKeyShareGroups]
	return ok
}

// ResetKeyShareGroups resets all changes to the "key_share_groups" field.
func (m *TLSFingerprintProfileMutation) ResetKeyShareGroups() {
	m.key_share_groups = nil
	m.appendkey_share_groups = nil
	delete(m.clearedFields, tlsfingerprintprofile.FieldKeyShareGroups)
}

// SetPskModes sets the "psk_modes" field.
func (m *TLSFingerprintProfileMutation) SetPskModes(u []uint16) {
	m.psk_modes = &u
	m.appendpsk_modes = nil
}

// PskModes returns the value of the "psk_modes" field in the mutation.
func (m *TLSFingerprintProfileMutation) PskModes() (r []uint16, exists bool) {
	v := m.psk_modes
	if v == nil {
		return
	}
	return *v, true
}

// OldPskModes returns the old "psk_modes" field's value of the TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) OldPskModes(ctx context.Context) (v []uint16, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPskModes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPskModes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPskModes: %w", err)
	}
	return oldValue.PskModes, nil
}

// AppendPskModes adds u to the "psk_modes" field.
func (m *TLSFingerprintProfileMutation) AppendPskModes(u []uint16) {
	m.appendpsk_modes = append(m.appendpsk_modes, u...)
}

// AppendedPskModes returns the list of values that were appended to the "psk_modes" field in this mutation.
func (m *TLSFingerprintProfileMutation) AppendedPskModes() ([]uint16, bool) {
	if len(m.appendpsk_modes) == 0 {
		return nil, false
	}
	return m.appendpsk_modes, true
}

// ClearPskModes clears the value of the "psk_modes" field.
func (m *TLSFingerprintProfileMutation) ClearPskModes() {
	m.psk_modes = nil
	m.appendpsk_modes = nil
	m.clearedFields[tlsfingerprintprofile.FieldPskModes] = struct{}{}
}

// PskModesCleared returns if the "psk_modes" field was cleared in this mutation.
func (m *TLSFingerprintProfileMutation) PskModesCleared() bool {
	_, ok := m.clearedFields[tlsfingerprintprofile.FieldPskModes]
	return ok
}

// ResetPskModes resets all changes to the "psk_modes" field.
func (m *TLSFingerprintProfileMutation) ResetPskModes() {
	m.psk_modes = nil
	m.appendpsk_modes = nil
	delete(m.clearedFields, tlsfingerprintprofile.FieldPskModes)
}

// SetExtensions sets the "extensions" field.
func (m *TLSFingerprintProfileMutation) SetExtensions(u []uint16) {
	m.extensions = &u
	m.appendextensions = nil
}

// Extensions returns the value of the "extensions" field in the mutation.
func (m *TLSFingerprintProfileMutation) Extensions() (r []uint16, exists bool) {
	v := m.extensions
	if v == nil {
		return
	}
	return *v, true
}

// OldExtensions returns the old "extensions" field's value of the TLSFingerprintProfile entity.
// If the TLSFingerprintProfile object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TLSFingerprintProfileMutation) OldExtensions(ctx context.Context) (v []uint16, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldExtensions is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldExtensions requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldExtensions: %w", err)
	}
	return oldValue.Extensions, nil
}

// AppendExtensions adds u to the "extensions" field.
func (m *TLSFingerprintProfileMutation) AppendExtensions(u []uint16) {
	m.appendextensions = append(m.appendextensions, u...)
}

// AppendedExtensions returns the list of values that were appended to the "extensions" field in this mutation.
func (m *TLSFingerprintProfileMutation) AppendedExtensions() ([]uint16, bool) {
	if len(m.appendextensions) == 0 {
		return nil, false
	}
	return m.appendextensions, true
}

// ClearExtensions clears the value of the "extensions" field.
func (m *TLSFingerprintProfileMutation) ClearExtensions() {
	m.extensions = nil
	m.appendextensions = nil
	m.clearedFields[tlsfingerprintprofile.FieldExtensions] = struct{}{}
}

// ExtensionsCleared returns if the "extensions" field was cleared in this mutation.
func (m *TLSFingerprintProfileMutation) ExtensionsCleared() bool {
	_, ok := m.clearedFields[tlsfingerprintprofile.FieldExtensions]
	return ok
}

// ResetExtensions resets all changes to the "extensions" field.
func (m *TLSFingerprintProfileMutation) ResetExtensions() {
	m.extensions = nil
	m.appendextensions = nil
	delete(m.clearedFields, tlsfingerprintprofile.FieldExtensions)
}

// Where appends a list predicates to the TLSFingerprintProfileMutation builder.
func (m *TLSFingerprintProfileMutation) Where(ps ...predicate.TLSFingerprintProfile) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the TLSFingerprintProfileMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *TLSFingerprintProfileMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.TLSFingerprintProfile, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *TLSFingerprintProfileMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *TLSFingerprintProfileMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (TLSFingerprintProfile).
func (m *TLSFingerprintProfileMutation) 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 *TLSFingerprintProfileMutation) Fields() []string {
	fields := make([]string, 0, 14)
	if m.created_at != nil {
		fields = append(fields, tlsfingerprintprofile.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, tlsfingerprintprofile.FieldUpdatedAt)
	}
	if m.name != nil {
		fields = append(fields, tlsfingerprintprofile.FieldName)
	}
	if m.description != nil {
		fields = append(fields, tlsfingerprintprofile.FieldDescription)
	}
	if m.enable_grease != nil {
		fields = append(fields, tlsfingerprintprofile.FieldEnableGrease)
	}
	if m.cipher_suites != nil {
		fields = append(fields, tlsfingerprintprofile.FieldCipherSuites)
	}
	if m.curves != nil {
		fields = append(fields, tlsfingerprintprofile.FieldCurves)
	}
	if m.point_formats != nil {
		fields = append(fields, tlsfingerprintprofile.FieldPointFormats)
	}
	if m.signature_algorithms != nil {
		fields = append(fields, tlsfingerprintprofile.FieldSignatureAlgorithms)
	}
	if m.alpn_protocols != nil {
		fields = append(fields, tlsfingerprintprofile.FieldAlpnProtocols)
	}
	if m.supported_versions != nil {
		fields = append(fields, tlsfingerprintprofile.FieldSupportedVersions)
	}
	if m.key_share_groups != nil {
		fields = append(fields, tlsfingerprintprofile.FieldKeyShareGroups)
	}
	if m.psk_modes != nil {
		fields = append(fields, tlsfingerprintprofile.FieldPskModes)
	}
	if m.extensions != nil {
		fields = append(fields, tlsfingerprintprofile.FieldExtensions)
	}
	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 *TLSFingerprintProfileMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case tlsfingerprintprofile.FieldCreatedAt:
		return m.CreatedAt()
	case tlsfingerprintprofile.FieldUpdatedAt:
		return m.UpdatedAt()
	case tlsfingerprintprofile.FieldName:
		return m.Name()
	case tlsfingerprintprofile.FieldDescription:
		return m.Description()
	case tlsfingerprintprofile.FieldEnableGrease:
		return m.EnableGrease()
	case tlsfingerprintprofile.FieldCipherSuites:
		return m.CipherSuites()
	case tlsfingerprintprofile.FieldCurves:
		return m.Curves()
	case tlsfingerprintprofile.FieldPointFormats:
		return m.PointFormats()
	case tlsfingerprintprofile.FieldSignatureAlgorithms:
		return m.SignatureAlgorithms()
	case tlsfingerprintprofile.FieldAlpnProtocols:
		return m.AlpnProtocols()
	case tlsfingerprintprofile.FieldSupportedVersions:
		return m.SupportedVersions()
	case tlsfingerprintprofile.FieldKeyShareGroups:
		return m.KeyShareGroups()
	case tlsfingerprintprofile.FieldPskModes:
		return m.PskModes()
	case tlsfingerprintprofile.FieldExtensions:
		return m.Extensions()
	}
	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 *TLSFingerprintProfileMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case tlsfingerprintprofile.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case tlsfingerprintprofile.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case tlsfingerprintprofile.FieldName:
		return m.OldName(ctx)
	case tlsfingerprintprofile.FieldDescription:
		return m.OldDescription(ctx)
	case tlsfingerprintprofile.FieldEnableGrease:
		return m.OldEnableGrease(ctx)
	case tlsfingerprintprofile.FieldCipherSuites:
		return m.OldCipherSuites(ctx)
	case tlsfingerprintprofile.FieldCurves:
		return m.OldCurves(ctx)
	case tlsfingerprintprofile.FieldPointFormats:
		return m.OldPointFormats(ctx)
	case tlsfingerprintprofile.FieldSignatureAlgorithms:
		return m.OldSignatureAlgorithms(ctx)
	case tlsfingerprintprofile.FieldAlpnProtocols:
		return m.OldAlpnProtocols(ctx)
	case tlsfingerprintprofile.FieldSupportedVersions:
		return m.OldSupportedVersions(ctx)
	case tlsfingerprintprofile.FieldKeyShareGroups:
		return m.OldKeyShareGroups(ctx)
	case tlsfingerprintprofile.FieldPskModes:
		return m.OldPskModes(ctx)
	case tlsfingerprintprofile.FieldExtensions:
		return m.OldExtensions(ctx)
	}
	return nil, fmt.Errorf("unknown TLSFingerprintProfile 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 *TLSFingerprintProfileMutation) SetField(name string, value ent.Value) error {
	switch name {
	case tlsfingerprintprofile.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 tlsfingerprintprofile.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 tlsfingerprintprofile.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case tlsfingerprintprofile.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case tlsfingerprintprofile.FieldEnableGrease:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEnableGrease(v)
		return nil
	case tlsfingerprintprofile.FieldCipherSuites:
		v, ok := value.([]uint16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCipherSuites(v)
		return nil
	case tlsfingerprintprofile.FieldCurves:
		v, ok := value.([]uint16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCurves(v)
		return nil
	case tlsfingerprintprofile.FieldPointFormats:
		v, ok := value.([]uint16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPointFormats(v)
		return nil
	case tlsfingerprintprofile.FieldSignatureAlgorithms:
		v, ok := value.([]uint16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSignatureAlgorithms(v)
		return nil
	case tlsfingerprintprofile.FieldAlpnProtocols:
		v, ok := value.([]string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAlpnProtocols(v)
		return nil
	case tlsfingerprintprofile.FieldSupportedVersions:
		v, ok := value.([]uint16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSupportedVersions(v)
		return nil
	case tlsfingerprintprofile.FieldKeyShareGroups:
		v, ok := value.([]uint16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetKeyShareGroups(v)
		return nil
	case tlsfingerprintprofile.FieldPskModes:
		v, ok := value.([]uint16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPskModes(v)
		return nil
	case tlsfingerprintprofile.FieldExtensions:
		v, ok := value.([]uint16)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetExtensions(v)
		return nil
	}
	return fmt.Errorf("unknown TLSFingerprintProfile field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *TLSFingerprintProfileMutation) 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 *TLSFingerprintProfileMutation) 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 *TLSFingerprintProfileMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown TLSFingerprintProfile numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *TLSFingerprintProfileMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(tlsfingerprintprofile.FieldDescription) {
		fields = append(fields, tlsfingerprintprofile.FieldDescription)
	}
	if m.FieldCleared(tlsfingerprintprofile.FieldCipherSuites) {
		fields = append(fields, tlsfingerprintprofile.FieldCipherSuites)
	}
	if m.FieldCleared(tlsfingerprintprofile.FieldCurves) {
		fields = append(fields, tlsfingerprintprofile.FieldCurves)
	}
	if m.FieldCleared(tlsfingerprintprofile.FieldPointFormats) {
		fields = append(fields, tlsfingerprintprofile.FieldPointFormats)
	}
	if m.FieldCleared(tlsfingerprintprofile.FieldSignatureAlgorithms) {
		fields = append(fields, tlsfingerprintprofile.FieldSignatureAlgorithms)
	}
	if m.FieldCleared(tlsfingerprintprofile.FieldAlpnProtocols) {
		fields = append(fields, tlsfingerprintprofile.FieldAlpnProtocols)
	}
	if m.FieldCleared(tlsfingerprintprofile.FieldSupportedVersions) {
		fields = append(fields, tlsfingerprintprofile.FieldSupportedVersions)
	}
	if m.FieldCleared(tlsfingerprintprofile.FieldKeyShareGroups) {
		fields = append(fields, tlsfingerprintprofile.FieldKeyShareGroups)
	}
	if m.FieldCleared(tlsfingerprintprofile.FieldPskModes) {
		fields = append(fields, tlsfingerprintprofile.FieldPskModes)
	}
	if m.FieldCleared(tlsfingerprintprofile.FieldExtensions) {
		fields = append(fields, tlsfingerprintprofile.FieldExtensions)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *TLSFingerprintProfileMutation) 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 *TLSFingerprintProfileMutation) ClearField(name string) error {
	switch name {
	case tlsfingerprintprofile.FieldDescription:
		m.ClearDescription()
		return nil
	case tlsfingerprintprofile.FieldCipherSuites:
		m.ClearCipherSuites()
		return nil
	case tlsfingerprintprofile.FieldCurves:
		m.ClearCurves()
		return nil
	case tlsfingerprintprofile.FieldPointFormats:
		m.ClearPointFormats()
		return nil
	case tlsfingerprintprofile.FieldSignatureAlgorithms:
		m.ClearSignatureAlgorithms()
		return nil
	case tlsfingerprintprofile.FieldAlpnProtocols:
		m.ClearAlpnProtocols()
		return nil
	case tlsfingerprintprofile.FieldSupportedVersions:
		m.ClearSupportedVersions()
		return nil
	case tlsfingerprintprofile.FieldKeyShareGroups:
		m.ClearKeyShareGroups()
		return nil
	case tlsfingerprintprofile.FieldPskModes:
		m.ClearPskModes()
		return nil
	case tlsfingerprintprofile.FieldExtensions:
		m.ClearExtensions()
		return nil
	}
	return fmt.Errorf("unknown TLSFingerprintProfile 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 *TLSFingerprintProfileMutation) ResetField(name string) error {
	switch name {
	case tlsfingerprintprofile.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case tlsfingerprintprofile.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case tlsfingerprintprofile.FieldName:
		m.ResetName()
		return nil
	case tlsfingerprintprofile.FieldDescription:
		m.ResetDescription()
		return nil
	case tlsfingerprintprofile.FieldEnableGrease:
		m.ResetEnableGrease()
		return nil
	case tlsfingerprintprofile.FieldCipherSuites:
		m.ResetCipherSuites()
		return nil
	case tlsfingerprintprofile.FieldCurves:
		m.ResetCurves()
		return nil
	case tlsfingerprintprofile.FieldPointFormats:
		m.ResetPointFormats()
		return nil
	case tlsfingerprintprofile.FieldSignatureAlgorithms:
		m.ResetSignatureAlgorithms()
		return nil
	case tlsfingerprintprofile.FieldAlpnProtocols:
		m.ResetAlpnProtocols()
		return nil
	case tlsfingerprintprofile.FieldSupportedVersions:
		m.ResetSupportedVersions()
		return nil
	case tlsfingerprintprofile.FieldKeyShareGroups:
		m.ResetKeyShareGroups()
		return nil
	case tlsfingerprintprofile.FieldPskModes:
		m.ResetPskModes()
		return nil
	case tlsfingerprintprofile.FieldExtensions:
		m.ResetExtensions()
		return nil
	}
	return fmt.Errorf("unknown TLSFingerprintProfile field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *TLSFingerprintProfileMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *TLSFingerprintProfileMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *TLSFingerprintProfileMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *TLSFingerprintProfileMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *TLSFingerprintProfileMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *TLSFingerprintProfileMutation) EdgeCleared(name string) bool {
	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 *TLSFingerprintProfileMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown TLSFingerprintProfile 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 *TLSFingerprintProfileMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown TLSFingerprintProfile edge %s", name)
}

// UsageCleanupTaskMutation represents an operation that mutates the UsageCleanupTask nodes in the graph.
type UsageCleanupTaskMutation struct {
	config
	op              Op
	typ             string
	id              *int64
	created_at      *time.Time
	updated_at      *time.Time
	status          *string
	filters         *json.RawMessage
	appendfilters   json.RawMessage
	created_by      *int64
	addcreated_by   *int64
	deleted_rows    *int64
	adddeleted_rows *int64
	error_message   *string
	canceled_by     *int64
	addcanceled_by  *int64
	canceled_at     *time.Time
	started_at      *time.Time
	finished_at     *time.Time
	clearedFields   map[string]struct{}
	done            bool
	oldValue        func(context.Context) (*UsageCleanupTask, error)
	predicates      []predicate.UsageCleanupTask
}

var _ ent.Mutation = (*UsageCleanupTaskMutation)(nil)

// usagecleanuptaskOption allows management of the mutation configuration using functional options.
type usagecleanuptaskOption func(*UsageCleanupTaskMutation)

// newUsageCleanupTaskMutation creates new mutation for the UsageCleanupTask entity.
func newUsageCleanupTaskMutation(c config, op Op, opts ...usagecleanuptaskOption) *UsageCleanupTaskMutation {
	m := &UsageCleanupTaskMutation{
		config:        c,
		op:            op,
		typ:           TypeUsageCleanupTask,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withUsageCleanupTaskID sets the ID field of the mutation.
func withUsageCleanupTaskID(id int64) usagecleanuptaskOption {
	return func(m *UsageCleanupTaskMutation) {
		var (
			err   error
			once  sync.Once
			value *UsageCleanupTask
		)
		m.oldValue = func(ctx context.Context) (*UsageCleanupTask, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().UsageCleanupTask.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withUsageCleanupTask sets the old UsageCleanupTask of the mutation.
func withUsageCleanupTask(node *UsageCleanupTask) usagecleanuptaskOption {
	return func(m *UsageCleanupTaskMutation) {
		m.oldValue = func(context.Context) (*UsageCleanupTask, 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 UsageCleanupTaskMutation) 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 UsageCleanupTaskMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *UsageCleanupTaskMutation) ID() (id int64, 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 *UsageCleanupTaskMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().UsageCleanupTask.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *UsageCleanupTaskMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UsageCleanupTaskMutation) 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 UsageCleanupTask entity.
// If the UsageCleanupTask object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageCleanupTaskMutation) 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 *UsageCleanupTaskMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *UsageCleanupTaskMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *UsageCleanupTaskMutation) 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 UsageCleanupTask entity.
// If the UsageCleanupTask object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageCleanupTaskMutation) 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 *UsageCleanupTaskMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetStatus sets the "status" field.
func (m *UsageCleanupTaskMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *UsageCleanupTaskMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageCleanupTaskMutation) OldStatus(ctx context.Context) (v string, 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 *UsageCleanupTaskMutation) ResetStatus() {
	m.status = nil
}

// SetFilters sets the "filters" field.
func (m *UsageCleanupTaskMutation) SetFilters(jm json.RawMessage) {
	m.filters = &jm
	m.appendfilters = nil
}

// Filters returns the value of the "filters" field in the mutation.
func (m *UsageCleanupTaskMutation) Filters() (r json.RawMessage, exists bool) {
	v := m.filters
	if v == nil {
		return
	}
	return *v, true
}

// OldFilters returns the old "filters" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageCleanupTaskMutation) OldFilters(ctx context.Context) (v json.RawMessage, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFilters is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFilters requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFilters: %w", err)
	}
	return oldValue.Filters, nil
}

// AppendFilters adds jm to the "filters" field.
func (m *UsageCleanupTaskMutation) AppendFilters(jm json.RawMessage) {
	m.appendfilters = append(m.appendfilters, jm...)
}

// AppendedFilters returns the list of values that were appended to the "filters" field in this mutation.
func (m *UsageCleanupTaskMutation) AppendedFilters() (json.RawMessage, bool) {
	if len(m.appendfilters) == 0 {
		return nil, false
	}
	return m.appendfilters, true
}

// ResetFilters resets all changes to the "filters" field.
func (m *UsageCleanupTaskMutation) ResetFilters() {
	m.filters = nil
	m.appendfilters = nil
}

// SetCreatedBy sets the "created_by" field.
func (m *UsageCleanupTaskMutation) SetCreatedBy(i int64) {
	m.created_by = &i
	m.addcreated_by = nil
}

// CreatedBy returns the value of the "created_by" field in the mutation.
func (m *UsageCleanupTaskMutation) CreatedBy() (r int64, exists bool) {
	v := m.created_by
	if v == nil {
		return
	}
	return *v, true
}

// OldCreatedBy returns the old "created_by" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageCleanupTaskMutation) OldCreatedBy(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCreatedBy is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCreatedBy requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCreatedBy: %w", err)
	}
	return oldValue.CreatedBy, nil
}

// AddCreatedBy adds i to the "created_by" field.
func (m *UsageCleanupTaskMutation) AddCreatedBy(i int64) {
	if m.addcreated_by != nil {
		*m.addcreated_by += i
	} else {
		m.addcreated_by = &i
	}
}

// AddedCreatedBy returns the value that was added to the "created_by" field in this mutation.
func (m *UsageCleanupTaskMutation) AddedCreatedBy() (r int64, exists bool) {
	v := m.addcreated_by
	if v == nil {
		return
	}
	return *v, true
}

// ResetCreatedBy resets all changes to the "created_by" field.
func (m *UsageCleanupTaskMutation) ResetCreatedBy() {
	m.created_by = nil
	m.addcreated_by = nil
}

// SetDeletedRows sets the "deleted_rows" field.
func (m *UsageCleanupTaskMutation) SetDeletedRows(i int64) {
	m.deleted_rows = &i
	m.adddeleted_rows = nil
}

// DeletedRows returns the value of the "deleted_rows" field in the mutation.
func (m *UsageCleanupTaskMutation) DeletedRows() (r int64, exists bool) {
	v := m.deleted_rows
	if v == nil {
		return
	}
	return *v, true
}

// OldDeletedRows returns the old "deleted_rows" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageCleanupTaskMutation) OldDeletedRows(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDeletedRows is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDeletedRows requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDeletedRows: %w", err)
	}
	return oldValue.DeletedRows, nil
}

// AddDeletedRows adds i to the "deleted_rows" field.
func (m *UsageCleanupTaskMutation) AddDeletedRows(i int64) {
	if m.adddeleted_rows != nil {
		*m.adddeleted_rows += i
	} else {
		m.adddeleted_rows = &i
	}
}

// AddedDeletedRows returns the value that was added to the "deleted_rows" field in this mutation.
func (m *UsageCleanupTaskMutation) AddedDeletedRows() (r int64, exists bool) {
	v := m.adddeleted_rows
	if v == nil {
		return
	}
	return *v, true
}

// ResetDeletedRows resets all changes to the "deleted_rows" field.
func (m *UsageCleanupTaskMutation) ResetDeletedRows() {
	m.deleted_rows = nil
	m.adddeleted_rows = nil
}

// SetErrorMessage sets the "error_message" field.
func (m *UsageCleanupTaskMutation) SetErrorMessage(s string) {
	m.error_message = &s
}

// ErrorMessage returns the value of the "error_message" field in the mutation.
func (m *UsageCleanupTaskMutation) ErrorMessage() (r string, exists bool) {
	v := m.error_message
	if v == nil {
		return
	}
	return *v, true
}

// OldErrorMessage returns the old "error_message" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageCleanupTaskMutation) OldErrorMessage(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldErrorMessage is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldErrorMessage requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldErrorMessage: %w", err)
	}
	return oldValue.ErrorMessage, nil
}

// ClearErrorMessage clears the value of the "error_message" field.
func (m *UsageCleanupTaskMutation) ClearErrorMessage() {
	m.error_message = nil
	m.clearedFields[usagecleanuptask.FieldErrorMessage] = struct{}{}
}

// ErrorMessageCleared returns if the "error_message" field was cleared in this mutation.
func (m *UsageCleanupTaskMutation) ErrorMessageCleared() bool {
	_, ok := m.clearedFields[usagecleanuptask.FieldErrorMessage]
	return ok
}

// ResetErrorMessage resets all changes to the "error_message" field.
func (m *UsageCleanupTaskMutation) ResetErrorMessage() {
	m.error_message = nil
	delete(m.clearedFields, usagecleanuptask.FieldErrorMessage)
}

// SetCanceledBy sets the "canceled_by" field.
func (m *UsageCleanupTaskMutation) SetCanceledBy(i int64) {
	m.canceled_by = &i
	m.addcanceled_by = nil
}

// CanceledBy returns the value of the "canceled_by" field in the mutation.
func (m *UsageCleanupTaskMutation) CanceledBy() (r int64, exists bool) {
	v := m.canceled_by
	if v == nil {
		return
	}
	return *v, true
}

// OldCanceledBy returns the old "canceled_by" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageCleanupTaskMutation) OldCanceledBy(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCanceledBy is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCanceledBy requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCanceledBy: %w", err)
	}
	return oldValue.CanceledBy, nil
}

// AddCanceledBy adds i to the "canceled_by" field.
func (m *UsageCleanupTaskMutation) AddCanceledBy(i int64) {
	if m.addcanceled_by != nil {
		*m.addcanceled_by += i
	} else {
		m.addcanceled_by = &i
	}
}

// AddedCanceledBy returns the value that was added to the "canceled_by" field in this mutation.
func (m *UsageCleanupTaskMutation) AddedCanceledBy() (r int64, exists bool) {
	v := m.addcanceled_by
	if v == nil {
		return
	}
	return *v, true
}

// ClearCanceledBy clears the value of the "canceled_by" field.
func (m *UsageCleanupTaskMutation) ClearCanceledBy() {
	m.canceled_by = nil
	m.addcanceled_by = nil
	m.clearedFields[usagecleanuptask.FieldCanceledBy] = struct{}{}
}

// CanceledByCleared returns if the "canceled_by" field was cleared in this mutation.
func (m *UsageCleanupTaskMutation) CanceledByCleared() bool {
	_, ok := m.clearedFields[usagecleanuptask.FieldCanceledBy]
	return ok
}

// ResetCanceledBy resets all changes to the "canceled_by" field.
func (m *UsageCleanupTaskMutation) ResetCanceledBy() {
	m.canceled_by = nil
	m.addcanceled_by = nil
	delete(m.clearedFields, usagecleanuptask.FieldCanceledBy)
}

// SetCanceledAt sets the "canceled_at" field.
func (m *UsageCleanupTaskMutation) SetCanceledAt(t time.Time) {
	m.canceled_at = &t
}

// CanceledAt returns the value of the "canceled_at" field in the mutation.
func (m *UsageCleanupTaskMutation) CanceledAt() (r time.Time, exists bool) {
	v := m.canceled_at
	if v == nil {
		return
	}
	return *v, true
}

// OldCanceledAt returns the old "canceled_at" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageCleanupTaskMutation) OldCanceledAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCanceledAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCanceledAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCanceledAt: %w", err)
	}
	return oldValue.CanceledAt, nil
}

// ClearCanceledAt clears the value of the "canceled_at" field.
func (m *UsageCleanupTaskMutation) ClearCanceledAt() {
	m.canceled_at = nil
	m.clearedFields[usagecleanuptask.FieldCanceledAt] = struct{}{}
}

// CanceledAtCleared returns if the "canceled_at" field was cleared in this mutation.
func (m *UsageCleanupTaskMutation) CanceledAtCleared() bool {
	_, ok := m.clearedFields[usagecleanuptask.FieldCanceledAt]
	return ok
}

// ResetCanceledAt resets all changes to the "canceled_at" field.
func (m *UsageCleanupTaskMutation) ResetCanceledAt() {
	m.canceled_at = nil
	delete(m.clearedFields, usagecleanuptask.FieldCanceledAt)
}

// SetStartedAt sets the "started_at" field.
func (m *UsageCleanupTaskMutation) SetStartedAt(t time.Time) {
	m.started_at = &t
}

// StartedAt returns the value of the "started_at" field in the mutation.
func (m *UsageCleanupTaskMutation) StartedAt() (r time.Time, exists bool) {
	v := m.started_at
	if v == nil {
		return
	}
	return *v, true
}

// OldStartedAt returns the old "started_at" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageCleanupTaskMutation) OldStartedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldStartedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldStartedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldStartedAt: %w", err)
	}
	return oldValue.StartedAt, nil
}

// ClearStartedAt clears the value of the "started_at" field.
func (m *UsageCleanupTaskMutation) ClearStartedAt() {
	m.started_at = nil
	m.clearedFields[usagecleanuptask.FieldStartedAt] = struct{}{}
}

// StartedAtCleared returns if the "started_at" field was cleared in this mutation.
func (m *UsageCleanupTaskMutation) StartedAtCleared() bool {
	_, ok := m.clearedFields[usagecleanuptask.FieldStartedAt]
	return ok
}

// ResetStartedAt resets all changes to the "started_at" field.
func (m *UsageCleanupTaskMutation) ResetStartedAt() {
	m.started_at = nil
	delete(m.clearedFields, usagecleanuptask.FieldStartedAt)
}

// SetFinishedAt sets the "finished_at" field.
func (m *UsageCleanupTaskMutation) SetFinishedAt(t time.Time) {
	m.finished_at = &t
}

// FinishedAt returns the value of the "finished_at" field in the mutation.
func (m *UsageCleanupTaskMutation) FinishedAt() (r time.Time, exists bool) {
	v := m.finished_at
	if v == nil {
		return
	}
	return *v, true
}

// OldFinishedAt returns the old "finished_at" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageCleanupTaskMutation) OldFinishedAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFinishedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFinishedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFinishedAt: %w", err)
	}
	return oldValue.FinishedAt, nil
}

// ClearFinishedAt clears the value of the "finished_at" field.
func (m *UsageCleanupTaskMutation) ClearFinishedAt() {
	m.finished_at = nil
	m.clearedFields[usagecleanuptask.FieldFinishedAt] = struct{}{}
}

// FinishedAtCleared returns if the "finished_at" field was cleared in this mutation.
func (m *UsageCleanupTaskMutation) FinishedAtCleared() bool {
	_, ok := m.clearedFields[usagecleanuptask.FieldFinishedAt]
	return ok
}

// ResetFinishedAt resets all changes to the "finished_at" field.
func (m *UsageCleanupTaskMutation) ResetFinishedAt() {
	m.finished_at = nil
	delete(m.clearedFields, usagecleanuptask.FieldFinishedAt)
}

// Where appends a list predicates to the UsageCleanupTaskMutation builder.
func (m *UsageCleanupTaskMutation) Where(ps ...predicate.UsageCleanupTask) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the UsageCleanupTaskMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UsageCleanupTaskMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.UsageCleanupTask, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *UsageCleanupTaskMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *UsageCleanupTaskMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (UsageCleanupTask).
func (m *UsageCleanupTaskMutation) 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 *UsageCleanupTaskMutation) Fields() []string {
	fields := make([]string, 0, 11)
	if m.created_at != nil {
		fields = append(fields, usagecleanuptask.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, usagecleanuptask.FieldUpdatedAt)
	}
	if m.status != nil {
		fields = append(fields, usagecleanuptask.FieldStatus)
	}
	if m.filters != nil {
		fields = append(fields, usagecleanuptask.FieldFilters)
	}
	if m.created_by != nil {
		fields = append(fields, usagecleanuptask.FieldCreatedBy)
	}
	if m.deleted_rows != nil {
		fields = append(fields, usagecleanuptask.FieldDeletedRows)
	}
	if m.error_message != nil {
		fields = append(fields, usagecleanuptask.FieldErrorMessage)
	}
	if m.canceled_by != nil {
		fields = append(fields, usagecleanuptask.FieldCanceledBy)
	}
	if m.canceled_at != nil {
		fields = append(fields, usagecleanuptask.FieldCanceledAt)
	}
	if m.started_at != nil {
		fields = append(fields, usagecleanuptask.FieldStartedAt)
	}
	if m.finished_at != nil {
		fields = append(fields, usagecleanuptask.FieldFinishedAt)
	}
	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 *UsageCleanupTaskMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case usagecleanuptask.FieldCreatedAt:
		return m.CreatedAt()
	case usagecleanuptask.FieldUpdatedAt:
		return m.UpdatedAt()
	case usagecleanuptask.FieldStatus:
		return m.Status()
	case usagecleanuptask.FieldFilters:
		return m.Filters()
	case usagecleanuptask.FieldCreatedBy:
		return m.CreatedBy()
	case usagecleanuptask.FieldDeletedRows:
		return m.DeletedRows()
	case usagecleanuptask.FieldErrorMessage:
		return m.ErrorMessage()
	case usagecleanuptask.FieldCanceledBy:
		return m.CanceledBy()
	case usagecleanuptask.FieldCanceledAt:
		return m.CanceledAt()
	case usagecleanuptask.FieldStartedAt:
		return m.StartedAt()
	case usagecleanuptask.FieldFinishedAt:
		return m.FinishedAt()
	}
	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 *UsageCleanupTaskMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case usagecleanuptask.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case usagecleanuptask.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case usagecleanuptask.FieldStatus:
		return m.OldStatus(ctx)
	case usagecleanuptask.FieldFilters:
		return m.OldFilters(ctx)
	case usagecleanuptask.FieldCreatedBy:
		return m.OldCreatedBy(ctx)
	case usagecleanuptask.FieldDeletedRows:
		return m.OldDeletedRows(ctx)
	case usagecleanuptask.FieldErrorMessage:
		return m.OldErrorMessage(ctx)
	case usagecleanuptask.FieldCanceledBy:
		return m.OldCanceledBy(ctx)
	case usagecleanuptask.FieldCanceledAt:
		return m.OldCanceledAt(ctx)
	case usagecleanuptask.FieldStartedAt:
		return m.OldStartedAt(ctx)
	case usagecleanuptask.FieldFinishedAt:
		return m.OldFinishedAt(ctx)
	}
	return nil, fmt.Errorf("unknown UsageCleanupTask 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 *UsageCleanupTaskMutation) SetField(name string, value ent.Value) error {
	switch name {
	case usagecleanuptask.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 usagecleanuptask.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 usagecleanuptask.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case usagecleanuptask.FieldFilters:
		v, ok := value.(json.RawMessage)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFilters(v)
		return nil
	case usagecleanuptask.FieldCreatedBy:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedBy(v)
		return nil
	case usagecleanuptask.FieldDeletedRows:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDeletedRows(v)
		return nil
	case usagecleanuptask.FieldErrorMessage:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetErrorMessage(v)
		return nil
	case usagecleanuptask.FieldCanceledBy:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCanceledBy(v)
		return nil
	case usagecleanuptask.FieldCanceledAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCanceledAt(v)
		return nil
	case usagecleanuptask.FieldStartedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStartedAt(v)
		return nil
	case usagecleanuptask.FieldFinishedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFinishedAt(v)
		return nil
	}
	return fmt.Errorf("unknown UsageCleanupTask field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UsageCleanupTaskMutation) AddedFields() []string {
	var fields []string
	if m.addcreated_by != nil {
		fields = append(fields, usagecleanuptask.FieldCreatedBy)
	}
	if m.adddeleted_rows != nil {
		fields = append(fields, usagecleanuptask.FieldDeletedRows)
	}
	if m.addcanceled_by != nil {
		fields = append(fields, usagecleanuptask.FieldCanceledBy)
	}
	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 *UsageCleanupTaskMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case usagecleanuptask.FieldCreatedBy:
		return m.AddedCreatedBy()
	case usagecleanuptask.FieldDeletedRows:
		return m.AddedDeletedRows()
	case usagecleanuptask.FieldCanceledBy:
		return m.AddedCanceledBy()
	}
	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 *UsageCleanupTaskMutation) AddField(name string, value ent.Value) error {
	switch name {
	case usagecleanuptask.FieldCreatedBy:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCreatedBy(v)
		return nil
	case usagecleanuptask.FieldDeletedRows:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddDeletedRows(v)
		return nil
	case usagecleanuptask.FieldCanceledBy:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCanceledBy(v)
		return nil
	}
	return fmt.Errorf("unknown UsageCleanupTask numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UsageCleanupTaskMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(usagecleanuptask.FieldErrorMessage) {
		fields = append(fields, usagecleanuptask.FieldErrorMessage)
	}
	if m.FieldCleared(usagecleanuptask.FieldCanceledBy) {
		fields = append(fields, usagecleanuptask.FieldCanceledBy)
	}
	if m.FieldCleared(usagecleanuptask.FieldCanceledAt) {
		fields = append(fields, usagecleanuptask.FieldCanceledAt)
	}
	if m.FieldCleared(usagecleanuptask.FieldStartedAt) {
		fields = append(fields, usagecleanuptask.FieldStartedAt)
	}
	if m.FieldCleared(usagecleanuptask.FieldFinishedAt) {
		fields = append(fields, usagecleanuptask.FieldFinishedAt)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UsageCleanupTaskMutation) 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 *UsageCleanupTaskMutation) ClearField(name string) error {
	switch name {
	case usagecleanuptask.FieldErrorMessage:
		m.ClearErrorMessage()
		return nil
	case usagecleanuptask.FieldCanceledBy:
		m.ClearCanceledBy()
		return nil
	case usagecleanuptask.FieldCanceledAt:
		m.ClearCanceledAt()
		return nil
	case usagecleanuptask.FieldStartedAt:
		m.ClearStartedAt()
		return nil
	case usagecleanuptask.FieldFinishedAt:
		m.ClearFinishedAt()
		return nil
	}
	return fmt.Errorf("unknown UsageCleanupTask 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 *UsageCleanupTaskMutation) ResetField(name string) error {
	switch name {
	case usagecleanuptask.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case usagecleanuptask.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case usagecleanuptask.FieldStatus:
		m.ResetStatus()
		return nil
	case usagecleanuptask.FieldFilters:
		m.ResetFilters()
		return nil
	case usagecleanuptask.FieldCreatedBy:
		m.ResetCreatedBy()
		return nil
	case usagecleanuptask.FieldDeletedRows:
		m.ResetDeletedRows()
		return nil
	case usagecleanuptask.FieldErrorMessage:
		m.ResetErrorMessage()
		return nil
	case usagecleanuptask.FieldCanceledBy:
		m.ResetCanceledBy()
		return nil
	case usagecleanuptask.FieldCanceledAt:
		m.ResetCanceledAt()
		return nil
	case usagecleanuptask.FieldStartedAt:
		m.ResetStartedAt()
		return nil
	case usagecleanuptask.FieldFinishedAt:
		m.ResetFinishedAt()
		return nil
	}
	return fmt.Errorf("unknown UsageCleanupTask field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UsageCleanupTaskMutation) AddedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UsageCleanupTaskMutation) AddedIDs(name string) []ent.Value {
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UsageCleanupTaskMutation) RemovedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UsageCleanupTaskMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UsageCleanupTaskMutation) ClearedEdges() []string {
	edges := make([]string, 0, 0)
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UsageCleanupTaskMutation) EdgeCleared(name string) bool {
	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 *UsageCleanupTaskMutation) ClearEdge(name string) error {
	return fmt.Errorf("unknown UsageCleanupTask 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 *UsageCleanupTaskMutation) ResetEdge(name string) error {
	return fmt.Errorf("unknown UsageCleanupTask edge %s", name)
}

// UsageLogMutation represents an operation that mutates the UsageLog nodes in the graph.
type UsageLogMutation struct {
	config
	op                          Op
	typ                         string
	id                          *int64
	request_id                  *string
	model                       *string
	requested_model             *string
	upstream_model              *string
	channel_id                  *int64
	addchannel_id               *int64
	model_mapping_chain         *string
	billing_tier                *string
	billing_mode                *string
	input_tokens                *int
	addinput_tokens             *int
	output_tokens               *int
	addoutput_tokens            *int
	cache_creation_tokens       *int
	addcache_creation_tokens    *int
	cache_read_tokens           *int
	addcache_read_tokens        *int
	cache_creation_5m_tokens    *int
	addcache_creation_5m_tokens *int
	cache_creation_1h_tokens    *int
	addcache_creation_1h_tokens *int
	input_cost                  *float64
	addinput_cost               *float64
	output_cost                 *float64
	addoutput_cost              *float64
	cache_creation_cost         *float64
	addcache_creation_cost      *float64
	cache_read_cost             *float64
	addcache_read_cost          *float64
	total_cost                  *float64
	addtotal_cost               *float64
	actual_cost                 *float64
	addactual_cost              *float64
	rate_multiplier             *float64
	addrate_multiplier          *float64
	account_rate_multiplier     *float64
	addaccount_rate_multiplier  *float64
	billing_type                *int8
	addbilling_type             *int8
	stream                      *bool
	duration_ms                 *int
	addduration_ms              *int
	first_token_ms              *int
	addfirst_token_ms           *int
	user_agent                  *string
	ip_address                  *string
	image_count                 *int
	addimage_count              *int
	image_size                  *string
	cache_ttl_overridden        *bool
	created_at                  *time.Time
	clearedFields               map[string]struct{}
	user                        *int64
	cleareduser                 bool
	api_key                     *int64
	clearedapi_key              bool
	account                     *int64
	clearedaccount              bool
	group                       *int64
	clearedgroup                bool
	subscription                *int64
	clearedsubscription         bool
	done                        bool
	oldValue                    func(context.Context) (*UsageLog, error)
	predicates                  []predicate.UsageLog
}

var _ ent.Mutation = (*UsageLogMutation)(nil)

// usagelogOption allows management of the mutation configuration using functional options.
type usagelogOption func(*UsageLogMutation)

// newUsageLogMutation creates new mutation for the UsageLog entity.
func newUsageLogMutation(c config, op Op, opts ...usagelogOption) *UsageLogMutation {
	m := &UsageLogMutation{
		config:        c,
		op:            op,
		typ:           TypeUsageLog,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withUsageLogID sets the ID field of the mutation.
func withUsageLogID(id int64) usagelogOption {
	return func(m *UsageLogMutation) {
		var (
			err   error
			once  sync.Once
			value *UsageLog
		)
		m.oldValue = func(ctx context.Context) (*UsageLog, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().UsageLog.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withUsageLog sets the old UsageLog of the mutation.
func withUsageLog(node *UsageLog) usagelogOption {
	return func(m *UsageLogMutation) {
		m.oldValue = func(context.Context) (*UsageLog, 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 UsageLogMutation) 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 UsageLogMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *UsageLogMutation) ID() (id int64, 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 *UsageLogMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().UsageLog.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetUserID sets the "user_id" field.
func (m *UsageLogMutation) SetUserID(i int64) {
	m.user = &i
}

// UserID returns the value of the "user_id" field in the mutation.
func (m *UsageLogMutation) UserID() (r int64, exists bool) {
	v := m.user
	if v == nil {
		return
	}
	return *v, true
}

// OldUserID returns the old "user_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldUserID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
	}
	return oldValue.UserID, nil
}

// ResetUserID resets all changes to the "user_id" field.
func (m *UsageLogMutation) ResetUserID() {
	m.user = nil
}

// SetAPIKeyID sets the "api_key_id" field.
func (m *UsageLogMutation) SetAPIKeyID(i int64) {
	m.api_key = &i
}

// APIKeyID returns the value of the "api_key_id" field in the mutation.
func (m *UsageLogMutation) APIKeyID() (r int64, exists bool) {
	v := m.api_key
	if v == nil {
		return
	}
	return *v, true
}

// OldAPIKeyID returns the old "api_key_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldAPIKeyID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAPIKeyID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAPIKeyID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAPIKeyID: %w", err)
	}
	return oldValue.APIKeyID, nil
}

// ResetAPIKeyID resets all changes to the "api_key_id" field.
func (m *UsageLogMutation) ResetAPIKeyID() {
	m.api_key = nil
}

// SetAccountID sets the "account_id" field.
func (m *UsageLogMutation) SetAccountID(i int64) {
	m.account = &i
}

// AccountID returns the value of the "account_id" field in the mutation.
func (m *UsageLogMutation) AccountID() (r int64, exists bool) {
	v := m.account
	if v == nil {
		return
	}
	return *v, true
}

// OldAccountID returns the old "account_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldAccountID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAccountID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAccountID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAccountID: %w", err)
	}
	return oldValue.AccountID, nil
}

// ResetAccountID resets all changes to the "account_id" field.
func (m *UsageLogMutation) ResetAccountID() {
	m.account = nil
}

// SetRequestID sets the "request_id" field.
func (m *UsageLogMutation) SetRequestID(s string) {
	m.request_id = &s
}

// RequestID returns the value of the "request_id" field in the mutation.
func (m *UsageLogMutation) RequestID() (r string, exists bool) {
	v := m.request_id
	if v == nil {
		return
	}
	return *v, true
}

// OldRequestID returns the old "request_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldRequestID(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRequestID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRequestID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRequestID: %w", err)
	}
	return oldValue.RequestID, nil
}

// ResetRequestID resets all changes to the "request_id" field.
func (m *UsageLogMutation) ResetRequestID() {
	m.request_id = nil
}

// SetModel sets the "model" field.
func (m *UsageLogMutation) SetModel(s string) {
	m.model = &s
}

// Model returns the value of the "model" field in the mutation.
func (m *UsageLogMutation) Model() (r string, exists bool) {
	v := m.model
	if v == nil {
		return
	}
	return *v, true
}

// OldModel returns the old "model" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldModel(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldModel is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldModel requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldModel: %w", err)
	}
	return oldValue.Model, nil
}

// ResetModel resets all changes to the "model" field.
func (m *UsageLogMutation) ResetModel() {
	m.model = nil
}

// SetRequestedModel sets the "requested_model" field.
func (m *UsageLogMutation) SetRequestedModel(s string) {
	m.requested_model = &s
}

// RequestedModel returns the value of the "requested_model" field in the mutation.
func (m *UsageLogMutation) RequestedModel() (r string, exists bool) {
	v := m.requested_model
	if v == nil {
		return
	}
	return *v, true
}

// OldRequestedModel returns the old "requested_model" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldRequestedModel(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRequestedModel is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRequestedModel requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRequestedModel: %w", err)
	}
	return oldValue.RequestedModel, nil
}

// ClearRequestedModel clears the value of the "requested_model" field.
func (m *UsageLogMutation) ClearRequestedModel() {
	m.requested_model = nil
	m.clearedFields[usagelog.FieldRequestedModel] = struct{}{}
}

// RequestedModelCleared returns if the "requested_model" field was cleared in this mutation.
func (m *UsageLogMutation) RequestedModelCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldRequestedModel]
	return ok
}

// ResetRequestedModel resets all changes to the "requested_model" field.
func (m *UsageLogMutation) ResetRequestedModel() {
	m.requested_model = nil
	delete(m.clearedFields, usagelog.FieldRequestedModel)
}

// SetUpstreamModel sets the "upstream_model" field.
func (m *UsageLogMutation) SetUpstreamModel(s string) {
	m.upstream_model = &s
}

// UpstreamModel returns the value of the "upstream_model" field in the mutation.
func (m *UsageLogMutation) UpstreamModel() (r string, exists bool) {
	v := m.upstream_model
	if v == nil {
		return
	}
	return *v, true
}

// OldUpstreamModel returns the old "upstream_model" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldUpstreamModel(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUpstreamModel is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUpstreamModel requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUpstreamModel: %w", err)
	}
	return oldValue.UpstreamModel, nil
}

// ClearUpstreamModel clears the value of the "upstream_model" field.
func (m *UsageLogMutation) ClearUpstreamModel() {
	m.upstream_model = nil
	m.clearedFields[usagelog.FieldUpstreamModel] = struct{}{}
}

// UpstreamModelCleared returns if the "upstream_model" field was cleared in this mutation.
func (m *UsageLogMutation) UpstreamModelCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldUpstreamModel]
	return ok
}

// ResetUpstreamModel resets all changes to the "upstream_model" field.
func (m *UsageLogMutation) ResetUpstreamModel() {
	m.upstream_model = nil
	delete(m.clearedFields, usagelog.FieldUpstreamModel)
}

// SetChannelID sets the "channel_id" field.
func (m *UsageLogMutation) SetChannelID(i int64) {
	m.channel_id = &i
	m.addchannel_id = nil
}

// ChannelID returns the value of the "channel_id" field in the mutation.
func (m *UsageLogMutation) ChannelID() (r int64, exists bool) {
	v := m.channel_id
	if v == nil {
		return
	}
	return *v, true
}

// OldChannelID returns the old "channel_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldChannelID(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldChannelID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldChannelID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldChannelID: %w", err)
	}
	return oldValue.ChannelID, nil
}

// AddChannelID adds i to the "channel_id" field.
func (m *UsageLogMutation) AddChannelID(i int64) {
	if m.addchannel_id != nil {
		*m.addchannel_id += i
	} else {
		m.addchannel_id = &i
	}
}

// AddedChannelID returns the value that was added to the "channel_id" field in this mutation.
func (m *UsageLogMutation) AddedChannelID() (r int64, exists bool) {
	v := m.addchannel_id
	if v == nil {
		return
	}
	return *v, true
}

// ClearChannelID clears the value of the "channel_id" field.
func (m *UsageLogMutation) ClearChannelID() {
	m.channel_id = nil
	m.addchannel_id = nil
	m.clearedFields[usagelog.FieldChannelID] = struct{}{}
}

// ChannelIDCleared returns if the "channel_id" field was cleared in this mutation.
func (m *UsageLogMutation) ChannelIDCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldChannelID]
	return ok
}

// ResetChannelID resets all changes to the "channel_id" field.
func (m *UsageLogMutation) ResetChannelID() {
	m.channel_id = nil
	m.addchannel_id = nil
	delete(m.clearedFields, usagelog.FieldChannelID)
}

// SetModelMappingChain sets the "model_mapping_chain" field.
func (m *UsageLogMutation) SetModelMappingChain(s string) {
	m.model_mapping_chain = &s
}

// ModelMappingChain returns the value of the "model_mapping_chain" field in the mutation.
func (m *UsageLogMutation) ModelMappingChain() (r string, exists bool) {
	v := m.model_mapping_chain
	if v == nil {
		return
	}
	return *v, true
}

// OldModelMappingChain returns the old "model_mapping_chain" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldModelMappingChain(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldModelMappingChain is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldModelMappingChain requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldModelMappingChain: %w", err)
	}
	return oldValue.ModelMappingChain, nil
}

// ClearModelMappingChain clears the value of the "model_mapping_chain" field.
func (m *UsageLogMutation) ClearModelMappingChain() {
	m.model_mapping_chain = nil
	m.clearedFields[usagelog.FieldModelMappingChain] = struct{}{}
}

// ModelMappingChainCleared returns if the "model_mapping_chain" field was cleared in this mutation.
func (m *UsageLogMutation) ModelMappingChainCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldModelMappingChain]
	return ok
}

// ResetModelMappingChain resets all changes to the "model_mapping_chain" field.
func (m *UsageLogMutation) ResetModelMappingChain() {
	m.model_mapping_chain = nil
	delete(m.clearedFields, usagelog.FieldModelMappingChain)
}

// SetBillingTier sets the "billing_tier" field.
func (m *UsageLogMutation) SetBillingTier(s string) {
	m.billing_tier = &s
}

// BillingTier returns the value of the "billing_tier" field in the mutation.
func (m *UsageLogMutation) BillingTier() (r string, exists bool) {
	v := m.billing_tier
	if v == nil {
		return
	}
	return *v, true
}

// OldBillingTier returns the old "billing_tier" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldBillingTier(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBillingTier is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBillingTier requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBillingTier: %w", err)
	}
	return oldValue.BillingTier, nil
}

// ClearBillingTier clears the value of the "billing_tier" field.
func (m *UsageLogMutation) ClearBillingTier() {
	m.billing_tier = nil
	m.clearedFields[usagelog.FieldBillingTier] = struct{}{}
}

// BillingTierCleared returns if the "billing_tier" field was cleared in this mutation.
func (m *UsageLogMutation) BillingTierCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldBillingTier]
	return ok
}

// ResetBillingTier resets all changes to the "billing_tier" field.
func (m *UsageLogMutation) ResetBillingTier() {
	m.billing_tier = nil
	delete(m.clearedFields, usagelog.FieldBillingTier)
}

// SetBillingMode sets the "billing_mode" field.
func (m *UsageLogMutation) SetBillingMode(s string) {
	m.billing_mode = &s
}

// BillingMode returns the value of the "billing_mode" field in the mutation.
func (m *UsageLogMutation) BillingMode() (r string, exists bool) {
	v := m.billing_mode
	if v == nil {
		return
	}
	return *v, true
}

// OldBillingMode returns the old "billing_mode" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldBillingMode(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBillingMode is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBillingMode requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBillingMode: %w", err)
	}
	return oldValue.BillingMode, nil
}

// ClearBillingMode clears the value of the "billing_mode" field.
func (m *UsageLogMutation) ClearBillingMode() {
	m.billing_mode = nil
	m.clearedFields[usagelog.FieldBillingMode] = struct{}{}
}

// BillingModeCleared returns if the "billing_mode" field was cleared in this mutation.
func (m *UsageLogMutation) BillingModeCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldBillingMode]
	return ok
}

// ResetBillingMode resets all changes to the "billing_mode" field.
func (m *UsageLogMutation) ResetBillingMode() {
	m.billing_mode = nil
	delete(m.clearedFields, usagelog.FieldBillingMode)
}

// SetGroupID sets the "group_id" field.
func (m *UsageLogMutation) SetGroupID(i int64) {
	m.group = &i
}

// GroupID returns the value of the "group_id" field in the mutation.
func (m *UsageLogMutation) GroupID() (r int64, exists bool) {
	v := m.group
	if v == nil {
		return
	}
	return *v, true
}

// OldGroupID returns the old "group_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldGroupID(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldGroupID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldGroupID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldGroupID: %w", err)
	}
	return oldValue.GroupID, nil
}

// ClearGroupID clears the value of the "group_id" field.
func (m *UsageLogMutation) ClearGroupID() {
	m.group = nil
	m.clearedFields[usagelog.FieldGroupID] = struct{}{}
}

// GroupIDCleared returns if the "group_id" field was cleared in this mutation.
func (m *UsageLogMutation) GroupIDCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldGroupID]
	return ok
}

// ResetGroupID resets all changes to the "group_id" field.
func (m *UsageLogMutation) ResetGroupID() {
	m.group = nil
	delete(m.clearedFields, usagelog.FieldGroupID)
}

// SetSubscriptionID sets the "subscription_id" field.
func (m *UsageLogMutation) SetSubscriptionID(i int64) {
	m.subscription = &i
}

// SubscriptionID returns the value of the "subscription_id" field in the mutation.
func (m *UsageLogMutation) SubscriptionID() (r int64, exists bool) {
	v := m.subscription
	if v == nil {
		return
	}
	return *v, true
}

// OldSubscriptionID returns the old "subscription_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldSubscriptionID(ctx context.Context) (v *int64, 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 *UsageLogMutation) ClearSubscriptionID() {
	m.subscription = nil
	m.clearedFields[usagelog.FieldSubscriptionID] = struct{}{}
}

// SubscriptionIDCleared returns if the "subscription_id" field was cleared in this mutation.
func (m *UsageLogMutation) SubscriptionIDCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldSubscriptionID]
	return ok
}

// ResetSubscriptionID resets all changes to the "subscription_id" field.
func (m *UsageLogMutation) ResetSubscriptionID() {
	m.subscription = nil
	delete(m.clearedFields, usagelog.FieldSubscriptionID)
}

// SetInputTokens sets the "input_tokens" field.
func (m *UsageLogMutation) SetInputTokens(i int) {
	m.input_tokens = &i
	m.addinput_tokens = nil
}

// InputTokens returns the value of the "input_tokens" field in the mutation.
func (m *UsageLogMutation) InputTokens() (r int, exists bool) {
	v := m.input_tokens
	if v == nil {
		return
	}
	return *v, true
}

// OldInputTokens returns the old "input_tokens" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldInputTokens(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldInputTokens is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldInputTokens requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldInputTokens: %w", err)
	}
	return oldValue.InputTokens, nil
}

// AddInputTokens adds i to the "input_tokens" field.
func (m *UsageLogMutation) AddInputTokens(i int) {
	if m.addinput_tokens != nil {
		*m.addinput_tokens += i
	} else {
		m.addinput_tokens = &i
	}
}

// AddedInputTokens returns the value that was added to the "input_tokens" field in this mutation.
func (m *UsageLogMutation) AddedInputTokens() (r int, exists bool) {
	v := m.addinput_tokens
	if v == nil {
		return
	}
	return *v, true
}

// ResetInputTokens resets all changes to the "input_tokens" field.
func (m *UsageLogMutation) ResetInputTokens() {
	m.input_tokens = nil
	m.addinput_tokens = nil
}

// SetOutputTokens sets the "output_tokens" field.
func (m *UsageLogMutation) SetOutputTokens(i int) {
	m.output_tokens = &i
	m.addoutput_tokens = nil
}

// OutputTokens returns the value of the "output_tokens" field in the mutation.
func (m *UsageLogMutation) OutputTokens() (r int, exists bool) {
	v := m.output_tokens
	if v == nil {
		return
	}
	return *v, true
}

// OldOutputTokens returns the old "output_tokens" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldOutputTokens(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldOutputTokens is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldOutputTokens requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldOutputTokens: %w", err)
	}
	return oldValue.OutputTokens, nil
}

// AddOutputTokens adds i to the "output_tokens" field.
func (m *UsageLogMutation) AddOutputTokens(i int) {
	if m.addoutput_tokens != nil {
		*m.addoutput_tokens += i
	} else {
		m.addoutput_tokens = &i
	}
}

// AddedOutputTokens returns the value that was added to the "output_tokens" field in this mutation.
func (m *UsageLogMutation) AddedOutputTokens() (r int, exists bool) {
	v := m.addoutput_tokens
	if v == nil {
		return
	}
	return *v, true
}

// ResetOutputTokens resets all changes to the "output_tokens" field.
func (m *UsageLogMutation) ResetOutputTokens() {
	m.output_tokens = nil
	m.addoutput_tokens = nil
}

// SetCacheCreationTokens sets the "cache_creation_tokens" field.
func (m *UsageLogMutation) SetCacheCreationTokens(i int) {
	m.cache_creation_tokens = &i
	m.addcache_creation_tokens = nil
}

// CacheCreationTokens returns the value of the "cache_creation_tokens" field in the mutation.
func (m *UsageLogMutation) CacheCreationTokens() (r int, exists bool) {
	v := m.cache_creation_tokens
	if v == nil {
		return
	}
	return *v, true
}

// OldCacheCreationTokens returns the old "cache_creation_tokens" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheCreationTokens(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCacheCreationTokens is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCacheCreationTokens requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCacheCreationTokens: %w", err)
	}
	return oldValue.CacheCreationTokens, nil
}

// AddCacheCreationTokens adds i to the "cache_creation_tokens" field.
func (m *UsageLogMutation) AddCacheCreationTokens(i int) {
	if m.addcache_creation_tokens != nil {
		*m.addcache_creation_tokens += i
	} else {
		m.addcache_creation_tokens = &i
	}
}

// AddedCacheCreationTokens returns the value that was added to the "cache_creation_tokens" field in this mutation.
func (m *UsageLogMutation) AddedCacheCreationTokens() (r int, exists bool) {
	v := m.addcache_creation_tokens
	if v == nil {
		return
	}
	return *v, true
}

// ResetCacheCreationTokens resets all changes to the "cache_creation_tokens" field.
func (m *UsageLogMutation) ResetCacheCreationTokens() {
	m.cache_creation_tokens = nil
	m.addcache_creation_tokens = nil
}

// SetCacheReadTokens sets the "cache_read_tokens" field.
func (m *UsageLogMutation) SetCacheReadTokens(i int) {
	m.cache_read_tokens = &i
	m.addcache_read_tokens = nil
}

// CacheReadTokens returns the value of the "cache_read_tokens" field in the mutation.
func (m *UsageLogMutation) CacheReadTokens() (r int, exists bool) {
	v := m.cache_read_tokens
	if v == nil {
		return
	}
	return *v, true
}

// OldCacheReadTokens returns the old "cache_read_tokens" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheReadTokens(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCacheReadTokens is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCacheReadTokens requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCacheReadTokens: %w", err)
	}
	return oldValue.CacheReadTokens, nil
}

// AddCacheReadTokens adds i to the "cache_read_tokens" field.
func (m *UsageLogMutation) AddCacheReadTokens(i int) {
	if m.addcache_read_tokens != nil {
		*m.addcache_read_tokens += i
	} else {
		m.addcache_read_tokens = &i
	}
}

// AddedCacheReadTokens returns the value that was added to the "cache_read_tokens" field in this mutation.
func (m *UsageLogMutation) AddedCacheReadTokens() (r int, exists bool) {
	v := m.addcache_read_tokens
	if v == nil {
		return
	}
	return *v, true
}

// ResetCacheReadTokens resets all changes to the "cache_read_tokens" field.
func (m *UsageLogMutation) ResetCacheReadTokens() {
	m.cache_read_tokens = nil
	m.addcache_read_tokens = nil
}

// SetCacheCreation5mTokens sets the "cache_creation_5m_tokens" field.
func (m *UsageLogMutation) SetCacheCreation5mTokens(i int) {
	m.cache_creation_5m_tokens = &i
	m.addcache_creation_5m_tokens = nil
}

// CacheCreation5mTokens returns the value of the "cache_creation_5m_tokens" field in the mutation.
func (m *UsageLogMutation) CacheCreation5mTokens() (r int, exists bool) {
	v := m.cache_creation_5m_tokens
	if v == nil {
		return
	}
	return *v, true
}

// OldCacheCreation5mTokens returns the old "cache_creation_5m_tokens" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheCreation5mTokens(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCacheCreation5mTokens is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCacheCreation5mTokens requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCacheCreation5mTokens: %w", err)
	}
	return oldValue.CacheCreation5mTokens, nil
}

// AddCacheCreation5mTokens adds i to the "cache_creation_5m_tokens" field.
func (m *UsageLogMutation) AddCacheCreation5mTokens(i int) {
	if m.addcache_creation_5m_tokens != nil {
		*m.addcache_creation_5m_tokens += i
	} else {
		m.addcache_creation_5m_tokens = &i
	}
}

// AddedCacheCreation5mTokens returns the value that was added to the "cache_creation_5m_tokens" field in this mutation.
func (m *UsageLogMutation) AddedCacheCreation5mTokens() (r int, exists bool) {
	v := m.addcache_creation_5m_tokens
	if v == nil {
		return
	}
	return *v, true
}

// ResetCacheCreation5mTokens resets all changes to the "cache_creation_5m_tokens" field.
func (m *UsageLogMutation) ResetCacheCreation5mTokens() {
	m.cache_creation_5m_tokens = nil
	m.addcache_creation_5m_tokens = nil
}

// SetCacheCreation1hTokens sets the "cache_creation_1h_tokens" field.
func (m *UsageLogMutation) SetCacheCreation1hTokens(i int) {
	m.cache_creation_1h_tokens = &i
	m.addcache_creation_1h_tokens = nil
}

// CacheCreation1hTokens returns the value of the "cache_creation_1h_tokens" field in the mutation.
func (m *UsageLogMutation) CacheCreation1hTokens() (r int, exists bool) {
	v := m.cache_creation_1h_tokens
	if v == nil {
		return
	}
	return *v, true
}

// OldCacheCreation1hTokens returns the old "cache_creation_1h_tokens" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheCreation1hTokens(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCacheCreation1hTokens is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCacheCreation1hTokens requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCacheCreation1hTokens: %w", err)
	}
	return oldValue.CacheCreation1hTokens, nil
}

// AddCacheCreation1hTokens adds i to the "cache_creation_1h_tokens" field.
func (m *UsageLogMutation) AddCacheCreation1hTokens(i int) {
	if m.addcache_creation_1h_tokens != nil {
		*m.addcache_creation_1h_tokens += i
	} else {
		m.addcache_creation_1h_tokens = &i
	}
}

// AddedCacheCreation1hTokens returns the value that was added to the "cache_creation_1h_tokens" field in this mutation.
func (m *UsageLogMutation) AddedCacheCreation1hTokens() (r int, exists bool) {
	v := m.addcache_creation_1h_tokens
	if v == nil {
		return
	}
	return *v, true
}

// ResetCacheCreation1hTokens resets all changes to the "cache_creation_1h_tokens" field.
func (m *UsageLogMutation) ResetCacheCreation1hTokens() {
	m.cache_creation_1h_tokens = nil
	m.addcache_creation_1h_tokens = nil
}

// SetInputCost sets the "input_cost" field.
func (m *UsageLogMutation) SetInputCost(f float64) {
	m.input_cost = &f
	m.addinput_cost = nil
}

// InputCost returns the value of the "input_cost" field in the mutation.
func (m *UsageLogMutation) InputCost() (r float64, exists bool) {
	v := m.input_cost
	if v == nil {
		return
	}
	return *v, true
}

// OldInputCost returns the old "input_cost" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldInputCost(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldInputCost is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldInputCost requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldInputCost: %w", err)
	}
	return oldValue.InputCost, nil
}

// AddInputCost adds f to the "input_cost" field.
func (m *UsageLogMutation) AddInputCost(f float64) {
	if m.addinput_cost != nil {
		*m.addinput_cost += f
	} else {
		m.addinput_cost = &f
	}
}

// AddedInputCost returns the value that was added to the "input_cost" field in this mutation.
func (m *UsageLogMutation) AddedInputCost() (r float64, exists bool) {
	v := m.addinput_cost
	if v == nil {
		return
	}
	return *v, true
}

// ResetInputCost resets all changes to the "input_cost" field.
func (m *UsageLogMutation) ResetInputCost() {
	m.input_cost = nil
	m.addinput_cost = nil
}

// SetOutputCost sets the "output_cost" field.
func (m *UsageLogMutation) SetOutputCost(f float64) {
	m.output_cost = &f
	m.addoutput_cost = nil
}

// OutputCost returns the value of the "output_cost" field in the mutation.
func (m *UsageLogMutation) OutputCost() (r float64, exists bool) {
	v := m.output_cost
	if v == nil {
		return
	}
	return *v, true
}

// OldOutputCost returns the old "output_cost" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldOutputCost(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldOutputCost is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldOutputCost requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldOutputCost: %w", err)
	}
	return oldValue.OutputCost, nil
}

// AddOutputCost adds f to the "output_cost" field.
func (m *UsageLogMutation) AddOutputCost(f float64) {
	if m.addoutput_cost != nil {
		*m.addoutput_cost += f
	} else {
		m.addoutput_cost = &f
	}
}

// AddedOutputCost returns the value that was added to the "output_cost" field in this mutation.
func (m *UsageLogMutation) AddedOutputCost() (r float64, exists bool) {
	v := m.addoutput_cost
	if v == nil {
		return
	}
	return *v, true
}

// ResetOutputCost resets all changes to the "output_cost" field.
func (m *UsageLogMutation) ResetOutputCost() {
	m.output_cost = nil
	m.addoutput_cost = nil
}

// SetCacheCreationCost sets the "cache_creation_cost" field.
func (m *UsageLogMutation) SetCacheCreationCost(f float64) {
	m.cache_creation_cost = &f
	m.addcache_creation_cost = nil
}

// CacheCreationCost returns the value of the "cache_creation_cost" field in the mutation.
func (m *UsageLogMutation) CacheCreationCost() (r float64, exists bool) {
	v := m.cache_creation_cost
	if v == nil {
		return
	}
	return *v, true
}

// OldCacheCreationCost returns the old "cache_creation_cost" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheCreationCost(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCacheCreationCost is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCacheCreationCost requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCacheCreationCost: %w", err)
	}
	return oldValue.CacheCreationCost, nil
}

// AddCacheCreationCost adds f to the "cache_creation_cost" field.
func (m *UsageLogMutation) AddCacheCreationCost(f float64) {
	if m.addcache_creation_cost != nil {
		*m.addcache_creation_cost += f
	} else {
		m.addcache_creation_cost = &f
	}
}

// AddedCacheCreationCost returns the value that was added to the "cache_creation_cost" field in this mutation.
func (m *UsageLogMutation) AddedCacheCreationCost() (r float64, exists bool) {
	v := m.addcache_creation_cost
	if v == nil {
		return
	}
	return *v, true
}

// ResetCacheCreationCost resets all changes to the "cache_creation_cost" field.
func (m *UsageLogMutation) ResetCacheCreationCost() {
	m.cache_creation_cost = nil
	m.addcache_creation_cost = nil
}

// SetCacheReadCost sets the "cache_read_cost" field.
func (m *UsageLogMutation) SetCacheReadCost(f float64) {
	m.cache_read_cost = &f
	m.addcache_read_cost = nil
}

// CacheReadCost returns the value of the "cache_read_cost" field in the mutation.
func (m *UsageLogMutation) CacheReadCost() (r float64, exists bool) {
	v := m.cache_read_cost
	if v == nil {
		return
	}
	return *v, true
}

// OldCacheReadCost returns the old "cache_read_cost" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheReadCost(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCacheReadCost is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCacheReadCost requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCacheReadCost: %w", err)
	}
	return oldValue.CacheReadCost, nil
}

// AddCacheReadCost adds f to the "cache_read_cost" field.
func (m *UsageLogMutation) AddCacheReadCost(f float64) {
	if m.addcache_read_cost != nil {
		*m.addcache_read_cost += f
	} else {
		m.addcache_read_cost = &f
	}
}

// AddedCacheReadCost returns the value that was added to the "cache_read_cost" field in this mutation.
func (m *UsageLogMutation) AddedCacheReadCost() (r float64, exists bool) {
	v := m.addcache_read_cost
	if v == nil {
		return
	}
	return *v, true
}

// ResetCacheReadCost resets all changes to the "cache_read_cost" field.
func (m *UsageLogMutation) ResetCacheReadCost() {
	m.cache_read_cost = nil
	m.addcache_read_cost = nil
}

// SetTotalCost sets the "total_cost" field.
func (m *UsageLogMutation) SetTotalCost(f float64) {
	m.total_cost = &f
	m.addtotal_cost = nil
}

// TotalCost returns the value of the "total_cost" field in the mutation.
func (m *UsageLogMutation) TotalCost() (r float64, exists bool) {
	v := m.total_cost
	if v == nil {
		return
	}
	return *v, true
}

// OldTotalCost returns the old "total_cost" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldTotalCost(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTotalCost is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTotalCost requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTotalCost: %w", err)
	}
	return oldValue.TotalCost, nil
}

// AddTotalCost adds f to the "total_cost" field.
func (m *UsageLogMutation) AddTotalCost(f float64) {
	if m.addtotal_cost != nil {
		*m.addtotal_cost += f
	} else {
		m.addtotal_cost = &f
	}
}

// AddedTotalCost returns the value that was added to the "total_cost" field in this mutation.
func (m *UsageLogMutation) AddedTotalCost() (r float64, exists bool) {
	v := m.addtotal_cost
	if v == nil {
		return
	}
	return *v, true
}

// ResetTotalCost resets all changes to the "total_cost" field.
func (m *UsageLogMutation) ResetTotalCost() {
	m.total_cost = nil
	m.addtotal_cost = nil
}

// SetActualCost sets the "actual_cost" field.
func (m *UsageLogMutation) SetActualCost(f float64) {
	m.actual_cost = &f
	m.addactual_cost = nil
}

// ActualCost returns the value of the "actual_cost" field in the mutation.
func (m *UsageLogMutation) ActualCost() (r float64, exists bool) {
	v := m.actual_cost
	if v == nil {
		return
	}
	return *v, true
}

// OldActualCost returns the old "actual_cost" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldActualCost(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldActualCost is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldActualCost requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldActualCost: %w", err)
	}
	return oldValue.ActualCost, nil
}

// AddActualCost adds f to the "actual_cost" field.
func (m *UsageLogMutation) AddActualCost(f float64) {
	if m.addactual_cost != nil {
		*m.addactual_cost += f
	} else {
		m.addactual_cost = &f
	}
}

// AddedActualCost returns the value that was added to the "actual_cost" field in this mutation.
func (m *UsageLogMutation) AddedActualCost() (r float64, exists bool) {
	v := m.addactual_cost
	if v == nil {
		return
	}
	return *v, true
}

// ResetActualCost resets all changes to the "actual_cost" field.
func (m *UsageLogMutation) ResetActualCost() {
	m.actual_cost = nil
	m.addactual_cost = nil
}

// SetRateMultiplier sets the "rate_multiplier" field.
func (m *UsageLogMutation) SetRateMultiplier(f float64) {
	m.rate_multiplier = &f
	m.addrate_multiplier = nil
}

// RateMultiplier returns the value of the "rate_multiplier" field in the mutation.
func (m *UsageLogMutation) RateMultiplier() (r float64, exists bool) {
	v := m.rate_multiplier
	if v == nil {
		return
	}
	return *v, true
}

// OldRateMultiplier returns the old "rate_multiplier" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldRateMultiplier(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRateMultiplier is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRateMultiplier requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRateMultiplier: %w", err)
	}
	return oldValue.RateMultiplier, nil
}

// AddRateMultiplier adds f to the "rate_multiplier" field.
func (m *UsageLogMutation) AddRateMultiplier(f float64) {
	if m.addrate_multiplier != nil {
		*m.addrate_multiplier += f
	} else {
		m.addrate_multiplier = &f
	}
}

// AddedRateMultiplier returns the value that was added to the "rate_multiplier" field in this mutation.
func (m *UsageLogMutation) AddedRateMultiplier() (r float64, exists bool) {
	v := m.addrate_multiplier
	if v == nil {
		return
	}
	return *v, true
}

// ResetRateMultiplier resets all changes to the "rate_multiplier" field.
func (m *UsageLogMutation) ResetRateMultiplier() {
	m.rate_multiplier = nil
	m.addrate_multiplier = nil
}

// SetAccountRateMultiplier sets the "account_rate_multiplier" field.
func (m *UsageLogMutation) SetAccountRateMultiplier(f float64) {
	m.account_rate_multiplier = &f
	m.addaccount_rate_multiplier = nil
}

// AccountRateMultiplier returns the value of the "account_rate_multiplier" field in the mutation.
func (m *UsageLogMutation) AccountRateMultiplier() (r float64, exists bool) {
	v := m.account_rate_multiplier
	if v == nil {
		return
	}
	return *v, true
}

// OldAccountRateMultiplier returns the old "account_rate_multiplier" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldAccountRateMultiplier(ctx context.Context) (v *float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAccountRateMultiplier is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAccountRateMultiplier requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAccountRateMultiplier: %w", err)
	}
	return oldValue.AccountRateMultiplier, nil
}

// AddAccountRateMultiplier adds f to the "account_rate_multiplier" field.
func (m *UsageLogMutation) AddAccountRateMultiplier(f float64) {
	if m.addaccount_rate_multiplier != nil {
		*m.addaccount_rate_multiplier += f
	} else {
		m.addaccount_rate_multiplier = &f
	}
}

// AddedAccountRateMultiplier returns the value that was added to the "account_rate_multiplier" field in this mutation.
func (m *UsageLogMutation) AddedAccountRateMultiplier() (r float64, exists bool) {
	v := m.addaccount_rate_multiplier
	if v == nil {
		return
	}
	return *v, true
}

// ClearAccountRateMultiplier clears the value of the "account_rate_multiplier" field.
func (m *UsageLogMutation) ClearAccountRateMultiplier() {
	m.account_rate_multiplier = nil
	m.addaccount_rate_multiplier = nil
	m.clearedFields[usagelog.FieldAccountRateMultiplier] = struct{}{}
}

// AccountRateMultiplierCleared returns if the "account_rate_multiplier" field was cleared in this mutation.
func (m *UsageLogMutation) AccountRateMultiplierCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldAccountRateMultiplier]
	return ok
}

// ResetAccountRateMultiplier resets all changes to the "account_rate_multiplier" field.
func (m *UsageLogMutation) ResetAccountRateMultiplier() {
	m.account_rate_multiplier = nil
	m.addaccount_rate_multiplier = nil
	delete(m.clearedFields, usagelog.FieldAccountRateMultiplier)
}

// SetBillingType sets the "billing_type" field.
func (m *UsageLogMutation) SetBillingType(i int8) {
	m.billing_type = &i
	m.addbilling_type = nil
}

// BillingType returns the value of the "billing_type" field in the mutation.
func (m *UsageLogMutation) BillingType() (r int8, exists bool) {
	v := m.billing_type
	if v == nil {
		return
	}
	return *v, true
}

// OldBillingType returns the old "billing_type" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldBillingType(ctx context.Context) (v int8, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBillingType is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBillingType requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBillingType: %w", err)
	}
	return oldValue.BillingType, nil
}

// AddBillingType adds i to the "billing_type" field.
func (m *UsageLogMutation) AddBillingType(i int8) {
	if m.addbilling_type != nil {
		*m.addbilling_type += i
	} else {
		m.addbilling_type = &i
	}
}

// AddedBillingType returns the value that was added to the "billing_type" field in this mutation.
func (m *UsageLogMutation) AddedBillingType() (r int8, exists bool) {
	v := m.addbilling_type
	if v == nil {
		return
	}
	return *v, true
}

// ResetBillingType resets all changes to the "billing_type" field.
func (m *UsageLogMutation) ResetBillingType() {
	m.billing_type = nil
	m.addbilling_type = nil
}

// SetStream sets the "stream" field.
func (m *UsageLogMutation) SetStream(b bool) {
	m.stream = &b
}

// Stream returns the value of the "stream" field in the mutation.
func (m *UsageLogMutation) Stream() (r bool, exists bool) {
	v := m.stream
	if v == nil {
		return
	}
	return *v, true
}

// OldStream returns the old "stream" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldStream(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldStream is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldStream requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldStream: %w", err)
	}
	return oldValue.Stream, nil
}

// ResetStream resets all changes to the "stream" field.
func (m *UsageLogMutation) ResetStream() {
	m.stream = nil
}

// SetDurationMs sets the "duration_ms" field.
func (m *UsageLogMutation) SetDurationMs(i int) {
	m.duration_ms = &i
	m.addduration_ms = nil
}

// DurationMs returns the value of the "duration_ms" field in the mutation.
func (m *UsageLogMutation) DurationMs() (r int, exists bool) {
	v := m.duration_ms
	if v == nil {
		return
	}
	return *v, true
}

// OldDurationMs returns the old "duration_ms" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldDurationMs(ctx context.Context) (v *int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDurationMs is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDurationMs requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDurationMs: %w", err)
	}
	return oldValue.DurationMs, nil
}

// AddDurationMs adds i to the "duration_ms" field.
func (m *UsageLogMutation) AddDurationMs(i int) {
	if m.addduration_ms != nil {
		*m.addduration_ms += i
	} else {
		m.addduration_ms = &i
	}
}

// AddedDurationMs returns the value that was added to the "duration_ms" field in this mutation.
func (m *UsageLogMutation) AddedDurationMs() (r int, exists bool) {
	v := m.addduration_ms
	if v == nil {
		return
	}
	return *v, true
}

// ClearDurationMs clears the value of the "duration_ms" field.
func (m *UsageLogMutation) ClearDurationMs() {
	m.duration_ms = nil
	m.addduration_ms = nil
	m.clearedFields[usagelog.FieldDurationMs] = struct{}{}
}

// DurationMsCleared returns if the "duration_ms" field was cleared in this mutation.
func (m *UsageLogMutation) DurationMsCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldDurationMs]
	return ok
}

// ResetDurationMs resets all changes to the "duration_ms" field.
func (m *UsageLogMutation) ResetDurationMs() {
	m.duration_ms = nil
	m.addduration_ms = nil
	delete(m.clearedFields, usagelog.FieldDurationMs)
}

// SetFirstTokenMs sets the "first_token_ms" field.
func (m *UsageLogMutation) SetFirstTokenMs(i int) {
	m.first_token_ms = &i
	m.addfirst_token_ms = nil
}

// FirstTokenMs returns the value of the "first_token_ms" field in the mutation.
func (m *UsageLogMutation) FirstTokenMs() (r int, exists bool) {
	v := m.first_token_ms
	if v == nil {
		return
	}
	return *v, true
}

// OldFirstTokenMs returns the old "first_token_ms" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldFirstTokenMs(ctx context.Context) (v *int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFirstTokenMs is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFirstTokenMs requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFirstTokenMs: %w", err)
	}
	return oldValue.FirstTokenMs, nil
}

// AddFirstTokenMs adds i to the "first_token_ms" field.
func (m *UsageLogMutation) AddFirstTokenMs(i int) {
	if m.addfirst_token_ms != nil {
		*m.addfirst_token_ms += i
	} else {
		m.addfirst_token_ms = &i
	}
}

// AddedFirstTokenMs returns the value that was added to the "first_token_ms" field in this mutation.
func (m *UsageLogMutation) AddedFirstTokenMs() (r int, exists bool) {
	v := m.addfirst_token_ms
	if v == nil {
		return
	}
	return *v, true
}

// ClearFirstTokenMs clears the value of the "first_token_ms" field.
func (m *UsageLogMutation) ClearFirstTokenMs() {
	m.first_token_ms = nil
	m.addfirst_token_ms = nil
	m.clearedFields[usagelog.FieldFirstTokenMs] = struct{}{}
}

// FirstTokenMsCleared returns if the "first_token_ms" field was cleared in this mutation.
func (m *UsageLogMutation) FirstTokenMsCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldFirstTokenMs]
	return ok
}

// ResetFirstTokenMs resets all changes to the "first_token_ms" field.
func (m *UsageLogMutation) ResetFirstTokenMs() {
	m.first_token_ms = nil
	m.addfirst_token_ms = nil
	delete(m.clearedFields, usagelog.FieldFirstTokenMs)
}

// SetUserAgent sets the "user_agent" field.
func (m *UsageLogMutation) SetUserAgent(s string) {
	m.user_agent = &s
}

// UserAgent returns the value of the "user_agent" field in the mutation.
func (m *UsageLogMutation) UserAgent() (r string, exists bool) {
	v := m.user_agent
	if v == nil {
		return
	}
	return *v, true
}

// OldUserAgent returns the old "user_agent" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldUserAgent(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserAgent is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserAgent requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserAgent: %w", err)
	}
	return oldValue.UserAgent, nil
}

// ClearUserAgent clears the value of the "user_agent" field.
func (m *UsageLogMutation) ClearUserAgent() {
	m.user_agent = nil
	m.clearedFields[usagelog.FieldUserAgent] = struct{}{}
}

// UserAgentCleared returns if the "user_agent" field was cleared in this mutation.
func (m *UsageLogMutation) UserAgentCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldUserAgent]
	return ok
}

// ResetUserAgent resets all changes to the "user_agent" field.
func (m *UsageLogMutation) ResetUserAgent() {
	m.user_agent = nil
	delete(m.clearedFields, usagelog.FieldUserAgent)
}

// SetIPAddress sets the "ip_address" field.
func (m *UsageLogMutation) SetIPAddress(s string) {
	m.ip_address = &s
}

// IPAddress returns the value of the "ip_address" field in the mutation.
func (m *UsageLogMutation) IPAddress() (r string, exists bool) {
	v := m.ip_address
	if v == nil {
		return
	}
	return *v, true
}

// OldIPAddress returns the old "ip_address" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldIPAddress(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldIPAddress is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldIPAddress requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldIPAddress: %w", err)
	}
	return oldValue.IPAddress, nil
}

// ClearIPAddress clears the value of the "ip_address" field.
func (m *UsageLogMutation) ClearIPAddress() {
	m.ip_address = nil
	m.clearedFields[usagelog.FieldIPAddress] = struct{}{}
}

// IPAddressCleared returns if the "ip_address" field was cleared in this mutation.
func (m *UsageLogMutation) IPAddressCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldIPAddress]
	return ok
}

// ResetIPAddress resets all changes to the "ip_address" field.
func (m *UsageLogMutation) ResetIPAddress() {
	m.ip_address = nil
	delete(m.clearedFields, usagelog.FieldIPAddress)
}

// SetImageCount sets the "image_count" field.
func (m *UsageLogMutation) SetImageCount(i int) {
	m.image_count = &i
	m.addimage_count = nil
}

// ImageCount returns the value of the "image_count" field in the mutation.
func (m *UsageLogMutation) ImageCount() (r int, exists bool) {
	v := m.image_count
	if v == nil {
		return
	}
	return *v, true
}

// OldImageCount returns the old "image_count" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldImageCount(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldImageCount is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldImageCount requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldImageCount: %w", err)
	}
	return oldValue.ImageCount, nil
}

// AddImageCount adds i to the "image_count" field.
func (m *UsageLogMutation) AddImageCount(i int) {
	if m.addimage_count != nil {
		*m.addimage_count += i
	} else {
		m.addimage_count = &i
	}
}

// AddedImageCount returns the value that was added to the "image_count" field in this mutation.
func (m *UsageLogMutation) AddedImageCount() (r int, exists bool) {
	v := m.addimage_count
	if v == nil {
		return
	}
	return *v, true
}

// ResetImageCount resets all changes to the "image_count" field.
func (m *UsageLogMutation) ResetImageCount() {
	m.image_count = nil
	m.addimage_count = nil
}

// SetImageSize sets the "image_size" field.
func (m *UsageLogMutation) SetImageSize(s string) {
	m.image_size = &s
}

// ImageSize returns the value of the "image_size" field in the mutation.
func (m *UsageLogMutation) ImageSize() (r string, exists bool) {
	v := m.image_size
	if v == nil {
		return
	}
	return *v, true
}

// OldImageSize returns the old "image_size" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldImageSize(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldImageSize is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldImageSize requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldImageSize: %w", err)
	}
	return oldValue.ImageSize, nil
}

// ClearImageSize clears the value of the "image_size" field.
func (m *UsageLogMutation) ClearImageSize() {
	m.image_size = nil
	m.clearedFields[usagelog.FieldImageSize] = struct{}{}
}

// ImageSizeCleared returns if the "image_size" field was cleared in this mutation.
func (m *UsageLogMutation) ImageSizeCleared() bool {
	_, ok := m.clearedFields[usagelog.FieldImageSize]
	return ok
}

// ResetImageSize resets all changes to the "image_size" field.
func (m *UsageLogMutation) ResetImageSize() {
	m.image_size = nil
	delete(m.clearedFields, usagelog.FieldImageSize)
}

// SetCacheTTLOverridden sets the "cache_ttl_overridden" field.
func (m *UsageLogMutation) SetCacheTTLOverridden(b bool) {
	m.cache_ttl_overridden = &b
}

// CacheTTLOverridden returns the value of the "cache_ttl_overridden" field in the mutation.
func (m *UsageLogMutation) CacheTTLOverridden() (r bool, exists bool) {
	v := m.cache_ttl_overridden
	if v == nil {
		return
	}
	return *v, true
}

// OldCacheTTLOverridden returns the old "cache_ttl_overridden" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheTTLOverridden(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldCacheTTLOverridden is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldCacheTTLOverridden requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCacheTTLOverridden: %w", err)
	}
	return oldValue.CacheTTLOverridden, nil
}

// ResetCacheTTLOverridden resets all changes to the "cache_ttl_overridden" field.
func (m *UsageLogMutation) ResetCacheTTLOverridden() {
	m.cache_ttl_overridden = nil
}

// SetCreatedAt sets the "created_at" field.
func (m *UsageLogMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UsageLogMutation) 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 UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) 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 *UsageLogMutation) ResetCreatedAt() {
	m.created_at = nil
}

// ClearUser clears the "user" edge to the User entity.
func (m *UsageLogMutation) ClearUser() {
	m.cleareduser = true
	m.clearedFields[usagelog.FieldUserID] = struct{}{}
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *UsageLogMutation) UserCleared() bool {
	return m.cleareduser
}

// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *UsageLogMutation) UserIDs() (ids []int64) {
	if id := m.user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetUser resets all changes to the "user" edge.
func (m *UsageLogMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

// ClearAPIKey clears the "api_key" edge to the APIKey entity.
func (m *UsageLogMutation) ClearAPIKey() {
	m.clearedapi_key = true
	m.clearedFields[usagelog.FieldAPIKeyID] = struct{}{}
}

// APIKeyCleared reports if the "api_key" edge to the APIKey entity was cleared.
func (m *UsageLogMutation) APIKeyCleared() bool {
	return m.clearedapi_key
}

// APIKeyIDs returns the "api_key" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// APIKeyID instead. It exists only for internal usage by the builders.
func (m *UsageLogMutation) APIKeyIDs() (ids []int64) {
	if id := m.api_key; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetAPIKey resets all changes to the "api_key" edge.
func (m *UsageLogMutation) ResetAPIKey() {
	m.api_key = nil
	m.clearedapi_key = false
}

// ClearAccount clears the "account" edge to the Account entity.
func (m *UsageLogMutation) ClearAccount() {
	m.clearedaccount = true
	m.clearedFields[usagelog.FieldAccountID] = struct{}{}
}

// AccountCleared reports if the "account" edge to the Account entity was cleared.
func (m *UsageLogMutation) AccountCleared() bool {
	return m.clearedaccount
}

// AccountIDs returns the "account" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// AccountID instead. It exists only for internal usage by the builders.
func (m *UsageLogMutation) AccountIDs() (ids []int64) {
	if id := m.account; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetAccount resets all changes to the "account" edge.
func (m *UsageLogMutation) ResetAccount() {
	m.account = nil
	m.clearedaccount = false
}

// ClearGroup clears the "group" edge to the Group entity.
func (m *UsageLogMutation) ClearGroup() {
	m.clearedgroup = true
	m.clearedFields[usagelog.FieldGroupID] = struct{}{}
}

// GroupCleared reports if the "group" edge to the Group entity was cleared.
func (m *UsageLogMutation) GroupCleared() bool {
	return m.GroupIDCleared() || m.clearedgroup
}

// GroupIDs returns the "group" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// GroupID instead. It exists only for internal usage by the builders.
func (m *UsageLogMutation) GroupIDs() (ids []int64) {
	if id := m.group; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetGroup resets all changes to the "group" edge.
func (m *UsageLogMutation) ResetGroup() {
	m.group = nil
	m.clearedgroup = false
}

// ClearSubscription clears the "subscription" edge to the UserSubscription entity.
func (m *UsageLogMutation) ClearSubscription() {
	m.clearedsubscription = true
	m.clearedFields[usagelog.FieldSubscriptionID] = struct{}{}
}

// SubscriptionCleared reports if the "subscription" edge to the UserSubscription entity was cleared.
func (m *UsageLogMutation) 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 *UsageLogMutation) SubscriptionIDs() (ids []int64) {
	if id := m.subscription; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetSubscription resets all changes to the "subscription" edge.
func (m *UsageLogMutation) ResetSubscription() {
	m.subscription = nil
	m.clearedsubscription = false
}

// Where appends a list predicates to the UsageLogMutation builder.
func (m *UsageLogMutation) Where(ps ...predicate.UsageLog) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the UsageLogMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UsageLogMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.UsageLog, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *UsageLogMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *UsageLogMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (UsageLog).
func (m *UsageLogMutation) 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 *UsageLogMutation) Fields() []string {
	fields := make([]string, 0, 37)
	if m.user != nil {
		fields = append(fields, usagelog.FieldUserID)
	}
	if m.api_key != nil {
		fields = append(fields, usagelog.FieldAPIKeyID)
	}
	if m.account != nil {
		fields = append(fields, usagelog.FieldAccountID)
	}
	if m.request_id != nil {
		fields = append(fields, usagelog.FieldRequestID)
	}
	if m.model != nil {
		fields = append(fields, usagelog.FieldModel)
	}
	if m.requested_model != nil {
		fields = append(fields, usagelog.FieldRequestedModel)
	}
	if m.upstream_model != nil {
		fields = append(fields, usagelog.FieldUpstreamModel)
	}
	if m.channel_id != nil {
		fields = append(fields, usagelog.FieldChannelID)
	}
	if m.model_mapping_chain != nil {
		fields = append(fields, usagelog.FieldModelMappingChain)
	}
	if m.billing_tier != nil {
		fields = append(fields, usagelog.FieldBillingTier)
	}
	if m.billing_mode != nil {
		fields = append(fields, usagelog.FieldBillingMode)
	}
	if m.group != nil {
		fields = append(fields, usagelog.FieldGroupID)
	}
	if m.subscription != nil {
		fields = append(fields, usagelog.FieldSubscriptionID)
	}
	if m.input_tokens != nil {
		fields = append(fields, usagelog.FieldInputTokens)
	}
	if m.output_tokens != nil {
		fields = append(fields, usagelog.FieldOutputTokens)
	}
	if m.cache_creation_tokens != nil {
		fields = append(fields, usagelog.FieldCacheCreationTokens)
	}
	if m.cache_read_tokens != nil {
		fields = append(fields, usagelog.FieldCacheReadTokens)
	}
	if m.cache_creation_5m_tokens != nil {
		fields = append(fields, usagelog.FieldCacheCreation5mTokens)
	}
	if m.cache_creation_1h_tokens != nil {
		fields = append(fields, usagelog.FieldCacheCreation1hTokens)
	}
	if m.input_cost != nil {
		fields = append(fields, usagelog.FieldInputCost)
	}
	if m.output_cost != nil {
		fields = append(fields, usagelog.FieldOutputCost)
	}
	if m.cache_creation_cost != nil {
		fields = append(fields, usagelog.FieldCacheCreationCost)
	}
	if m.cache_read_cost != nil {
		fields = append(fields, usagelog.FieldCacheReadCost)
	}
	if m.total_cost != nil {
		fields = append(fields, usagelog.FieldTotalCost)
	}
	if m.actual_cost != nil {
		fields = append(fields, usagelog.FieldActualCost)
	}
	if m.rate_multiplier != nil {
		fields = append(fields, usagelog.FieldRateMultiplier)
	}
	if m.account_rate_multiplier != nil {
		fields = append(fields, usagelog.FieldAccountRateMultiplier)
	}
	if m.billing_type != nil {
		fields = append(fields, usagelog.FieldBillingType)
	}
	if m.stream != nil {
		fields = append(fields, usagelog.FieldStream)
	}
	if m.duration_ms != nil {
		fields = append(fields, usagelog.FieldDurationMs)
	}
	if m.first_token_ms != nil {
		fields = append(fields, usagelog.FieldFirstTokenMs)
	}
	if m.user_agent != nil {
		fields = append(fields, usagelog.FieldUserAgent)
	}
	if m.ip_address != nil {
		fields = append(fields, usagelog.FieldIPAddress)
	}
	if m.image_count != nil {
		fields = append(fields, usagelog.FieldImageCount)
	}
	if m.image_size != nil {
		fields = append(fields, usagelog.FieldImageSize)
	}
	if m.cache_ttl_overridden != nil {
		fields = append(fields, usagelog.FieldCacheTTLOverridden)
	}
	if m.created_at != nil {
		fields = append(fields, usagelog.FieldCreatedAt)
	}
	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 *UsageLogMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case usagelog.FieldUserID:
		return m.UserID()
	case usagelog.FieldAPIKeyID:
		return m.APIKeyID()
	case usagelog.FieldAccountID:
		return m.AccountID()
	case usagelog.FieldRequestID:
		return m.RequestID()
	case usagelog.FieldModel:
		return m.Model()
	case usagelog.FieldRequestedModel:
		return m.RequestedModel()
	case usagelog.FieldUpstreamModel:
		return m.UpstreamModel()
	case usagelog.FieldChannelID:
		return m.ChannelID()
	case usagelog.FieldModelMappingChain:
		return m.ModelMappingChain()
	case usagelog.FieldBillingTier:
		return m.BillingTier()
	case usagelog.FieldBillingMode:
		return m.BillingMode()
	case usagelog.FieldGroupID:
		return m.GroupID()
	case usagelog.FieldSubscriptionID:
		return m.SubscriptionID()
	case usagelog.FieldInputTokens:
		return m.InputTokens()
	case usagelog.FieldOutputTokens:
		return m.OutputTokens()
	case usagelog.FieldCacheCreationTokens:
		return m.CacheCreationTokens()
	case usagelog.FieldCacheReadTokens:
		return m.CacheReadTokens()
	case usagelog.FieldCacheCreation5mTokens:
		return m.CacheCreation5mTokens()
	case usagelog.FieldCacheCreation1hTokens:
		return m.CacheCreation1hTokens()
	case usagelog.FieldInputCost:
		return m.InputCost()
	case usagelog.FieldOutputCost:
		return m.OutputCost()
	case usagelog.FieldCacheCreationCost:
		return m.CacheCreationCost()
	case usagelog.FieldCacheReadCost:
		return m.CacheReadCost()
	case usagelog.FieldTotalCost:
		return m.TotalCost()
	case usagelog.FieldActualCost:
		return m.ActualCost()
	case usagelog.FieldRateMultiplier:
		return m.RateMultiplier()
	case usagelog.FieldAccountRateMultiplier:
		return m.AccountRateMultiplier()
	case usagelog.FieldBillingType:
		return m.BillingType()
	case usagelog.FieldStream:
		return m.Stream()
	case usagelog.FieldDurationMs:
		return m.DurationMs()
	case usagelog.FieldFirstTokenMs:
		return m.FirstTokenMs()
	case usagelog.FieldUserAgent:
		return m.UserAgent()
	case usagelog.FieldIPAddress:
		return m.IPAddress()
	case usagelog.FieldImageCount:
		return m.ImageCount()
	case usagelog.FieldImageSize:
		return m.ImageSize()
	case usagelog.FieldCacheTTLOverridden:
		return m.CacheTTLOverridden()
	case usagelog.FieldCreatedAt:
		return m.CreatedAt()
	}
	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 *UsageLogMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case usagelog.FieldUserID:
		return m.OldUserID(ctx)
	case usagelog.FieldAPIKeyID:
		return m.OldAPIKeyID(ctx)
	case usagelog.FieldAccountID:
		return m.OldAccountID(ctx)
	case usagelog.FieldRequestID:
		return m.OldRequestID(ctx)
	case usagelog.FieldModel:
		return m.OldModel(ctx)
	case usagelog.FieldRequestedModel:
		return m.OldRequestedModel(ctx)
	case usagelog.FieldUpstreamModel:
		return m.OldUpstreamModel(ctx)
	case usagelog.FieldChannelID:
		return m.OldChannelID(ctx)
	case usagelog.FieldModelMappingChain:
		return m.OldModelMappingChain(ctx)
	case usagelog.FieldBillingTier:
		return m.OldBillingTier(ctx)
	case usagelog.FieldBillingMode:
		return m.OldBillingMode(ctx)
	case usagelog.FieldGroupID:
		return m.OldGroupID(ctx)
	case usagelog.FieldSubscriptionID:
		return m.OldSubscriptionID(ctx)
	case usagelog.FieldInputTokens:
		return m.OldInputTokens(ctx)
	case usagelog.FieldOutputTokens:
		return m.OldOutputTokens(ctx)
	case usagelog.FieldCacheCreationTokens:
		return m.OldCacheCreationTokens(ctx)
	case usagelog.FieldCacheReadTokens:
		return m.OldCacheReadTokens(ctx)
	case usagelog.FieldCacheCreation5mTokens:
		return m.OldCacheCreation5mTokens(ctx)
	case usagelog.FieldCacheCreation1hTokens:
		return m.OldCacheCreation1hTokens(ctx)
	case usagelog.FieldInputCost:
		return m.OldInputCost(ctx)
	case usagelog.FieldOutputCost:
		return m.OldOutputCost(ctx)
	case usagelog.FieldCacheCreationCost:
		return m.OldCacheCreationCost(ctx)
	case usagelog.FieldCacheReadCost:
		return m.OldCacheReadCost(ctx)
	case usagelog.FieldTotalCost:
		return m.OldTotalCost(ctx)
	case usagelog.FieldActualCost:
		return m.OldActualCost(ctx)
	case usagelog.FieldRateMultiplier:
		return m.OldRateMultiplier(ctx)
	case usagelog.FieldAccountRateMultiplier:
		return m.OldAccountRateMultiplier(ctx)
	case usagelog.FieldBillingType:
		return m.OldBillingType(ctx)
	case usagelog.FieldStream:
		return m.OldStream(ctx)
	case usagelog.FieldDurationMs:
		return m.OldDurationMs(ctx)
	case usagelog.FieldFirstTokenMs:
		return m.OldFirstTokenMs(ctx)
	case usagelog.FieldUserAgent:
		return m.OldUserAgent(ctx)
	case usagelog.FieldIPAddress:
		return m.OldIPAddress(ctx)
	case usagelog.FieldImageCount:
		return m.OldImageCount(ctx)
	case usagelog.FieldImageSize:
		return m.OldImageSize(ctx)
	case usagelog.FieldCacheTTLOverridden:
		return m.OldCacheTTLOverridden(ctx)
	case usagelog.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown UsageLog 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 *UsageLogMutation) SetField(name string, value ent.Value) error {
	switch name {
	case usagelog.FieldUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserID(v)
		return nil
	case usagelog.FieldAPIKeyID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAPIKeyID(v)
		return nil
	case usagelog.FieldAccountID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAccountID(v)
		return nil
	case usagelog.FieldRequestID:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRequestID(v)
		return nil
	case usagelog.FieldModel:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetModel(v)
		return nil
	case usagelog.FieldRequestedModel:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRequestedModel(v)
		return nil
	case usagelog.FieldUpstreamModel:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUpstreamModel(v)
		return nil
	case usagelog.FieldChannelID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetChannelID(v)
		return nil
	case usagelog.FieldModelMappingChain:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetModelMappingChain(v)
		return nil
	case usagelog.FieldBillingTier:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBillingTier(v)
		return nil
	case usagelog.FieldBillingMode:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBillingMode(v)
		return nil
	case usagelog.FieldGroupID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetGroupID(v)
		return nil
	case usagelog.FieldSubscriptionID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSubscriptionID(v)
		return nil
	case usagelog.FieldInputTokens:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetInputTokens(v)
		return nil
	case usagelog.FieldOutputTokens:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOutputTokens(v)
		return nil
	case usagelog.FieldCacheCreationTokens:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCacheCreationTokens(v)
		return nil
	case usagelog.FieldCacheReadTokens:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCacheReadTokens(v)
		return nil
	case usagelog.FieldCacheCreation5mTokens:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCacheCreation5mTokens(v)
		return nil
	case usagelog.FieldCacheCreation1hTokens:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCacheCreation1hTokens(v)
		return nil
	case usagelog.FieldInputCost:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetInputCost(v)
		return nil
	case usagelog.FieldOutputCost:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOutputCost(v)
		return nil
	case usagelog.FieldCacheCreationCost:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCacheCreationCost(v)
		return nil
	case usagelog.FieldCacheReadCost:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCacheReadCost(v)
		return nil
	case usagelog.FieldTotalCost:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTotalCost(v)
		return nil
	case usagelog.FieldActualCost:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetActualCost(v)
		return nil
	case usagelog.FieldRateMultiplier:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRateMultiplier(v)
		return nil
	case usagelog.FieldAccountRateMultiplier:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAccountRateMultiplier(v)
		return nil
	case usagelog.FieldBillingType:
		v, ok := value.(int8)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBillingType(v)
		return nil
	case usagelog.FieldStream:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStream(v)
		return nil
	case usagelog.FieldDurationMs:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDurationMs(v)
		return nil
	case usagelog.FieldFirstTokenMs:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFirstTokenMs(v)
		return nil
	case usagelog.FieldUserAgent:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserAgent(v)
		return nil
	case usagelog.FieldIPAddress:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIPAddress(v)
		return nil
	case usagelog.FieldImageCount:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetImageCount(v)
		return nil
	case usagelog.FieldImageSize:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetImageSize(v)
		return nil
	case usagelog.FieldCacheTTLOverridden:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCacheTTLOverridden(v)
		return nil
	case usagelog.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown UsageLog field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UsageLogMutation) AddedFields() []string {
	var fields []string
	if m.addchannel_id != nil {
		fields = append(fields, usagelog.FieldChannelID)
	}
	if m.addinput_tokens != nil {
		fields = append(fields, usagelog.FieldInputTokens)
	}
	if m.addoutput_tokens != nil {
		fields = append(fields, usagelog.FieldOutputTokens)
	}
	if m.addcache_creation_tokens != nil {
		fields = append(fields, usagelog.FieldCacheCreationTokens)
	}
	if m.addcache_read_tokens != nil {
		fields = append(fields, usagelog.FieldCacheReadTokens)
	}
	if m.addcache_creation_5m_tokens != nil {
		fields = append(fields, usagelog.FieldCacheCreation5mTokens)
	}
	if m.addcache_creation_1h_tokens != nil {
		fields = append(fields, usagelog.FieldCacheCreation1hTokens)
	}
	if m.addinput_cost != nil {
		fields = append(fields, usagelog.FieldInputCost)
	}
	if m.addoutput_cost != nil {
		fields = append(fields, usagelog.FieldOutputCost)
	}
	if m.addcache_creation_cost != nil {
		fields = append(fields, usagelog.FieldCacheCreationCost)
	}
	if m.addcache_read_cost != nil {
		fields = append(fields, usagelog.FieldCacheReadCost)
	}
	if m.addtotal_cost != nil {
		fields = append(fields, usagelog.FieldTotalCost)
	}
	if m.addactual_cost != nil {
		fields = append(fields, usagelog.FieldActualCost)
	}
	if m.addrate_multiplier != nil {
		fields = append(fields, usagelog.FieldRateMultiplier)
	}
	if m.addaccount_rate_multiplier != nil {
		fields = append(fields, usagelog.FieldAccountRateMultiplier)
	}
	if m.addbilling_type != nil {
		fields = append(fields, usagelog.FieldBillingType)
	}
	if m.addduration_ms != nil {
		fields = append(fields, usagelog.FieldDurationMs)
	}
	if m.addfirst_token_ms != nil {
		fields = append(fields, usagelog.FieldFirstTokenMs)
	}
	if m.addimage_count != nil {
		fields = append(fields, usagelog.FieldImageCount)
	}
	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 *UsageLogMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case usagelog.FieldChannelID:
		return m.AddedChannelID()
	case usagelog.FieldInputTokens:
		return m.AddedInputTokens()
	case usagelog.FieldOutputTokens:
		return m.AddedOutputTokens()
	case usagelog.FieldCacheCreationTokens:
		return m.AddedCacheCreationTokens()
	case usagelog.FieldCacheReadTokens:
		return m.AddedCacheReadTokens()
	case usagelog.FieldCacheCreation5mTokens:
		return m.AddedCacheCreation5mTokens()
	case usagelog.FieldCacheCreation1hTokens:
		return m.AddedCacheCreation1hTokens()
	case usagelog.FieldInputCost:
		return m.AddedInputCost()
	case usagelog.FieldOutputCost:
		return m.AddedOutputCost()
	case usagelog.FieldCacheCreationCost:
		return m.AddedCacheCreationCost()
	case usagelog.FieldCacheReadCost:
		return m.AddedCacheReadCost()
	case usagelog.FieldTotalCost:
		return m.AddedTotalCost()
	case usagelog.FieldActualCost:
		return m.AddedActualCost()
	case usagelog.FieldRateMultiplier:
		return m.AddedRateMultiplier()
	case usagelog.FieldAccountRateMultiplier:
		return m.AddedAccountRateMultiplier()
	case usagelog.FieldBillingType:
		return m.AddedBillingType()
	case usagelog.FieldDurationMs:
		return m.AddedDurationMs()
	case usagelog.FieldFirstTokenMs:
		return m.AddedFirstTokenMs()
	case usagelog.FieldImageCount:
		return m.AddedImageCount()
	}
	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 *UsageLogMutation) AddField(name string, value ent.Value) error {
	switch name {
	case usagelog.FieldChannelID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddChannelID(v)
		return nil
	case usagelog.FieldInputTokens:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddInputTokens(v)
		return nil
	case usagelog.FieldOutputTokens:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddOutputTokens(v)
		return nil
	case usagelog.FieldCacheCreationTokens:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCacheCreationTokens(v)
		return nil
	case usagelog.FieldCacheReadTokens:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCacheReadTokens(v)
		return nil
	case usagelog.FieldCacheCreation5mTokens:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCacheCreation5mTokens(v)
		return nil
	case usagelog.FieldCacheCreation1hTokens:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCacheCreation1hTokens(v)
		return nil
	case usagelog.FieldInputCost:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddInputCost(v)
		return nil
	case usagelog.FieldOutputCost:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddOutputCost(v)
		return nil
	case usagelog.FieldCacheCreationCost:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCacheCreationCost(v)
		return nil
	case usagelog.FieldCacheReadCost:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddCacheReadCost(v)
		return nil
	case usagelog.FieldTotalCost:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddTotalCost(v)
		return nil
	case usagelog.FieldActualCost:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddActualCost(v)
		return nil
	case usagelog.FieldRateMultiplier:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddRateMultiplier(v)
		return nil
	case usagelog.FieldAccountRateMultiplier:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddAccountRateMultiplier(v)
		return nil
	case usagelog.FieldBillingType:
		v, ok := value.(int8)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddBillingType(v)
		return nil
	case usagelog.FieldDurationMs:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddDurationMs(v)
		return nil
	case usagelog.FieldFirstTokenMs:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddFirstTokenMs(v)
		return nil
	case usagelog.FieldImageCount:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddImageCount(v)
		return nil
	}
	return fmt.Errorf("unknown UsageLog numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UsageLogMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(usagelog.FieldRequestedModel) {
		fields = append(fields, usagelog.FieldRequestedModel)
	}
	if m.FieldCleared(usagelog.FieldUpstreamModel) {
		fields = append(fields, usagelog.FieldUpstreamModel)
	}
	if m.FieldCleared(usagelog.FieldChannelID) {
		fields = append(fields, usagelog.FieldChannelID)
	}
	if m.FieldCleared(usagelog.FieldModelMappingChain) {
		fields = append(fields, usagelog.FieldModelMappingChain)
	}
	if m.FieldCleared(usagelog.FieldBillingTier) {
		fields = append(fields, usagelog.FieldBillingTier)
	}
	if m.FieldCleared(usagelog.FieldBillingMode) {
		fields = append(fields, usagelog.FieldBillingMode)
	}
	if m.FieldCleared(usagelog.FieldGroupID) {
		fields = append(fields, usagelog.FieldGroupID)
	}
	if m.FieldCleared(usagelog.FieldSubscriptionID) {
		fields = append(fields, usagelog.FieldSubscriptionID)
	}
	if m.FieldCleared(usagelog.FieldAccountRateMultiplier) {
		fields = append(fields, usagelog.FieldAccountRateMultiplier)
	}
	if m.FieldCleared(usagelog.FieldDurationMs) {
		fields = append(fields, usagelog.FieldDurationMs)
	}
	if m.FieldCleared(usagelog.FieldFirstTokenMs) {
		fields = append(fields, usagelog.FieldFirstTokenMs)
	}
	if m.FieldCleared(usagelog.FieldUserAgent) {
		fields = append(fields, usagelog.FieldUserAgent)
	}
	if m.FieldCleared(usagelog.FieldIPAddress) {
		fields = append(fields, usagelog.FieldIPAddress)
	}
	if m.FieldCleared(usagelog.FieldImageSize) {
		fields = append(fields, usagelog.FieldImageSize)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UsageLogMutation) 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 *UsageLogMutation) ClearField(name string) error {
	switch name {
	case usagelog.FieldRequestedModel:
		m.ClearRequestedModel()
		return nil
	case usagelog.FieldUpstreamModel:
		m.ClearUpstreamModel()
		return nil
	case usagelog.FieldChannelID:
		m.ClearChannelID()
		return nil
	case usagelog.FieldModelMappingChain:
		m.ClearModelMappingChain()
		return nil
	case usagelog.FieldBillingTier:
		m.ClearBillingTier()
		return nil
	case usagelog.FieldBillingMode:
		m.ClearBillingMode()
		return nil
	case usagelog.FieldGroupID:
		m.ClearGroupID()
		return nil
	case usagelog.FieldSubscriptionID:
		m.ClearSubscriptionID()
		return nil
	case usagelog.FieldAccountRateMultiplier:
		m.ClearAccountRateMultiplier()
		return nil
	case usagelog.FieldDurationMs:
		m.ClearDurationMs()
		return nil
	case usagelog.FieldFirstTokenMs:
		m.ClearFirstTokenMs()
		return nil
	case usagelog.FieldUserAgent:
		m.ClearUserAgent()
		return nil
	case usagelog.FieldIPAddress:
		m.ClearIPAddress()
		return nil
	case usagelog.FieldImageSize:
		m.ClearImageSize()
		return nil
	}
	return fmt.Errorf("unknown UsageLog 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 *UsageLogMutation) ResetField(name string) error {
	switch name {
	case usagelog.FieldUserID:
		m.ResetUserID()
		return nil
	case usagelog.FieldAPIKeyID:
		m.ResetAPIKeyID()
		return nil
	case usagelog.FieldAccountID:
		m.ResetAccountID()
		return nil
	case usagelog.FieldRequestID:
		m.ResetRequestID()
		return nil
	case usagelog.FieldModel:
		m.ResetModel()
		return nil
	case usagelog.FieldRequestedModel:
		m.ResetRequestedModel()
		return nil
	case usagelog.FieldUpstreamModel:
		m.ResetUpstreamModel()
		return nil
	case usagelog.FieldChannelID:
		m.ResetChannelID()
		return nil
	case usagelog.FieldModelMappingChain:
		m.ResetModelMappingChain()
		return nil
	case usagelog.FieldBillingTier:
		m.ResetBillingTier()
		return nil
	case usagelog.FieldBillingMode:
		m.ResetBillingMode()
		return nil
	case usagelog.FieldGroupID:
		m.ResetGroupID()
		return nil
	case usagelog.FieldSubscriptionID:
		m.ResetSubscriptionID()
		return nil
	case usagelog.FieldInputTokens:
		m.ResetInputTokens()
		return nil
	case usagelog.FieldOutputTokens:
		m.ResetOutputTokens()
		return nil
	case usagelog.FieldCacheCreationTokens:
		m.ResetCacheCreationTokens()
		return nil
	case usagelog.FieldCacheReadTokens:
		m.ResetCacheReadTokens()
		return nil
	case usagelog.FieldCacheCreation5mTokens:
		m.ResetCacheCreation5mTokens()
		return nil
	case usagelog.FieldCacheCreation1hTokens:
		m.ResetCacheCreation1hTokens()
		return nil
	case usagelog.FieldInputCost:
		m.ResetInputCost()
		return nil
	case usagelog.FieldOutputCost:
		m.ResetOutputCost()
		return nil
	case usagelog.FieldCacheCreationCost:
		m.ResetCacheCreationCost()
		return nil
	case usagelog.FieldCacheReadCost:
		m.ResetCacheReadCost()
		return nil
	case usagelog.FieldTotalCost:
		m.ResetTotalCost()
		return nil
	case usagelog.FieldActualCost:
		m.ResetActualCost()
		return nil
	case usagelog.FieldRateMultiplier:
		m.ResetRateMultiplier()
		return nil
	case usagelog.FieldAccountRateMultiplier:
		m.ResetAccountRateMultiplier()
		return nil
	case usagelog.FieldBillingType:
		m.ResetBillingType()
		return nil
	case usagelog.FieldStream:
		m.ResetStream()
		return nil
	case usagelog.FieldDurationMs:
		m.ResetDurationMs()
		return nil
	case usagelog.FieldFirstTokenMs:
		m.ResetFirstTokenMs()
		return nil
	case usagelog.FieldUserAgent:
		m.ResetUserAgent()
		return nil
	case usagelog.FieldIPAddress:
		m.ResetIPAddress()
		return nil
	case usagelog.FieldImageCount:
		m.ResetImageCount()
		return nil
	case usagelog.FieldImageSize:
		m.ResetImageSize()
		return nil
	case usagelog.FieldCacheTTLOverridden:
		m.ResetCacheTTLOverridden()
		return nil
	case usagelog.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown UsageLog field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UsageLogMutation) AddedEdges() []string {
	edges := make([]string, 0, 5)
	if m.user != nil {
		edges = append(edges, usagelog.EdgeUser)
	}
	if m.api_key != nil {
		edges = append(edges, usagelog.EdgeAPIKey)
	}
	if m.account != nil {
		edges = append(edges, usagelog.EdgeAccount)
	}
	if m.group != nil {
		edges = append(edges, usagelog.EdgeGroup)
	}
	if m.subscription != nil {
		edges = append(edges, usagelog.EdgeSubscription)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UsageLogMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case usagelog.EdgeUser:
		if id := m.user; id != nil {
			return []ent.Value{*id}
		}
	case usagelog.EdgeAPIKey:
		if id := m.api_key; id != nil {
			return []ent.Value{*id}
		}
	case usagelog.EdgeAccount:
		if id := m.account; id != nil {
			return []ent.Value{*id}
		}
	case usagelog.EdgeGroup:
		if id := m.group; id != nil {
			return []ent.Value{*id}
		}
	case usagelog.EdgeSubscription:
		if id := m.subscription; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UsageLogMutation) RemovedEdges() []string {
	edges := make([]string, 0, 5)
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UsageLogMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UsageLogMutation) ClearedEdges() []string {
	edges := make([]string, 0, 5)
	if m.cleareduser {
		edges = append(edges, usagelog.EdgeUser)
	}
	if m.clearedapi_key {
		edges = append(edges, usagelog.EdgeAPIKey)
	}
	if m.clearedaccount {
		edges = append(edges, usagelog.EdgeAccount)
	}
	if m.clearedgroup {
		edges = append(edges, usagelog.EdgeGroup)
	}
	if m.clearedsubscription {
		edges = append(edges, usagelog.EdgeSubscription)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UsageLogMutation) EdgeCleared(name string) bool {
	switch name {
	case usagelog.EdgeUser:
		return m.cleareduser
	case usagelog.EdgeAPIKey:
		return m.clearedapi_key
	case usagelog.EdgeAccount:
		return m.clearedaccount
	case usagelog.EdgeGroup:
		return m.clearedgroup
	case usagelog.EdgeSubscription:
		return m.clearedsubscription
	}
	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 *UsageLogMutation) ClearEdge(name string) error {
	switch name {
	case usagelog.EdgeUser:
		m.ClearUser()
		return nil
	case usagelog.EdgeAPIKey:
		m.ClearAPIKey()
		return nil
	case usagelog.EdgeAccount:
		m.ClearAccount()
		return nil
	case usagelog.EdgeGroup:
		m.ClearGroup()
		return nil
	case usagelog.EdgeSubscription:
		m.ClearSubscription()
		return nil
	}
	return fmt.Errorf("unknown UsageLog 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 *UsageLogMutation) ResetEdge(name string) error {
	switch name {
	case usagelog.EdgeUser:
		m.ResetUser()
		return nil
	case usagelog.EdgeAPIKey:
		m.ResetAPIKey()
		return nil
	case usagelog.EdgeAccount:
		m.ResetAccount()
		return nil
	case usagelog.EdgeGroup:
		m.ResetGroup()
		return nil
	case usagelog.EdgeSubscription:
		m.ResetSubscription()
		return nil
	}
	return fmt.Errorf("unknown UsageLog edge %s", name)
}

// UserMutation represents an operation that mutates the User nodes in the graph.
type UserMutation struct {
	config
	op                            Op
	typ                           string
	id                            *int64
	created_at                    *time.Time
	updated_at                    *time.Time
	deleted_at                    *time.Time
	email                         *string
	password_hash                 *string
	role                          *string
	balance                       *float64
	addbalance                    *float64
	concurrency                   *int
	addconcurrency                *int
	status                        *string
	username                      *string
	notes                         *string
	totp_secret_encrypted         *string
	totp_enabled                  *bool
	totp_enabled_at               *time.Time
	signup_source                 *string
	last_login_at                 *time.Time
	last_active_at                *time.Time
	balance_notify_enabled        *bool
	balance_notify_threshold_type *string
	balance_notify_threshold      *float64
	addbalance_notify_threshold   *float64
	balance_notify_extra_emails   *string
	total_recharged               *float64
	addtotal_recharged            *float64
	clearedFields                 map[string]struct{}
	api_keys                      map[int64]struct{}
	removedapi_keys               map[int64]struct{}
	clearedapi_keys               bool
	redeem_codes                  map[int64]struct{}
	removedredeem_codes           map[int64]struct{}
	clearedredeem_codes           bool
	subscriptions                 map[int64]struct{}
	removedsubscriptions          map[int64]struct{}
	clearedsubscriptions          bool
	assigned_subscriptions        map[int64]struct{}
	removedassigned_subscriptions map[int64]struct{}
	clearedassigned_subscriptions bool
	announcement_reads            map[int64]struct{}
	removedannouncement_reads     map[int64]struct{}
	clearedannouncement_reads     bool
	allowed_groups                map[int64]struct{}
	removedallowed_groups         map[int64]struct{}
	clearedallowed_groups         bool
	usage_logs                    map[int64]struct{}
	removedusage_logs             map[int64]struct{}
	clearedusage_logs             bool
	attribute_values              map[int64]struct{}
	removedattribute_values       map[int64]struct{}
	clearedattribute_values       bool
	promo_code_usages             map[int64]struct{}
	removedpromo_code_usages      map[int64]struct{}
	clearedpromo_code_usages      bool
	payment_orders                map[int64]struct{}
	removedpayment_orders         map[int64]struct{}
	clearedpayment_orders         bool
	auth_identities               map[int64]struct{}
	removedauth_identities        map[int64]struct{}
	clearedauth_identities        bool
	pending_auth_sessions         map[int64]struct{}
	removedpending_auth_sessions  map[int64]struct{}
	clearedpending_auth_sessions  bool
	done                          bool
	oldValue                      func(context.Context) (*User, error)
	predicates                    []predicate.User
}

var _ ent.Mutation = (*UserMutation)(nil)

// userOption allows management of the mutation configuration using functional options.
type userOption func(*UserMutation)

// newUserMutation creates new mutation for the User entity.
func newUserMutation(c config, op Op, opts ...userOption) *UserMutation {
	m := &UserMutation{
		config:        c,
		op:            op,
		typ:           TypeUser,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withUserID sets the ID field of the mutation.
func withUserID(id int64) userOption {
	return func(m *UserMutation) {
		var (
			err   error
			once  sync.Once
			value *User
		)
		m.oldValue = func(ctx context.Context) (*User, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().User.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withUser sets the old User of the mutation.
func withUser(node *User) userOption {
	return func(m *UserMutation) {
		m.oldValue = func(context.Context) (*User, 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 UserMutation) 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 UserMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *UserMutation) ID() (id int64, 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 *UserMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().User.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *UserMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UserMutation) 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 User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) 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 *UserMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *UserMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *UserMutation) 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 User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) 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 *UserMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetDeletedAt sets the "deleted_at" field.
func (m *UserMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *UserMutation) 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 User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) 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 *UserMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[user.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *UserMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[user.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *UserMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, user.FieldDeletedAt)
}

// SetEmail sets the "email" field.
func (m *UserMutation) SetEmail(s string) {
	m.email = &s
}

// Email returns the value of the "email" field in the mutation.
func (m *UserMutation) Email() (r string, exists bool) {
	v := m.email
	if v == nil {
		return
	}
	return *v, true
}

// OldEmail returns the old "email" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldEmail(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldEmail is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldEmail requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldEmail: %w", err)
	}
	return oldValue.Email, nil
}

// ResetEmail resets all changes to the "email" field.
func (m *UserMutation) ResetEmail() {
	m.email = nil
}

// SetPasswordHash sets the "password_hash" field.
func (m *UserMutation) SetPasswordHash(s string) {
	m.password_hash = &s
}

// PasswordHash returns the value of the "password_hash" field in the mutation.
func (m *UserMutation) PasswordHash() (r string, exists bool) {
	v := m.password_hash
	if v == nil {
		return
	}
	return *v, true
}

// OldPasswordHash returns the old "password_hash" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldPasswordHash(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPasswordHash is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPasswordHash requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPasswordHash: %w", err)
	}
	return oldValue.PasswordHash, nil
}

// ResetPasswordHash resets all changes to the "password_hash" field.
func (m *UserMutation) ResetPasswordHash() {
	m.password_hash = nil
}

// SetRole sets the "role" field.
func (m *UserMutation) SetRole(s string) {
	m.role = &s
}

// Role returns the value of the "role" field in the mutation.
func (m *UserMutation) Role() (r string, exists bool) {
	v := m.role
	if v == nil {
		return
	}
	return *v, true
}

// OldRole returns the old "role" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldRole(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRole is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRole requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRole: %w", err)
	}
	return oldValue.Role, nil
}

// ResetRole resets all changes to the "role" field.
func (m *UserMutation) ResetRole() {
	m.role = nil
}

// SetBalance sets the "balance" field.
func (m *UserMutation) SetBalance(f float64) {
	m.balance = &f
	m.addbalance = nil
}

// Balance returns the value of the "balance" field in the mutation.
func (m *UserMutation) Balance() (r float64, exists bool) {
	v := m.balance
	if v == nil {
		return
	}
	return *v, true
}

// OldBalance returns the old "balance" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldBalance(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBalance is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBalance requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBalance: %w", err)
	}
	return oldValue.Balance, nil
}

// AddBalance adds f to the "balance" field.
func (m *UserMutation) AddBalance(f float64) {
	if m.addbalance != nil {
		*m.addbalance += f
	} else {
		m.addbalance = &f
	}
}

// AddedBalance returns the value that was added to the "balance" field in this mutation.
func (m *UserMutation) AddedBalance() (r float64, exists bool) {
	v := m.addbalance
	if v == nil {
		return
	}
	return *v, true
}

// ResetBalance resets all changes to the "balance" field.
func (m *UserMutation) ResetBalance() {
	m.balance = nil
	m.addbalance = nil
}

// SetConcurrency sets the "concurrency" field.
func (m *UserMutation) SetConcurrency(i int) {
	m.concurrency = &i
	m.addconcurrency = nil
}

// Concurrency returns the value of the "concurrency" field in the mutation.
func (m *UserMutation) Concurrency() (r int, exists bool) {
	v := m.concurrency
	if v == nil {
		return
	}
	return *v, true
}

// OldConcurrency returns the old "concurrency" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldConcurrency(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldConcurrency is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldConcurrency requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldConcurrency: %w", err)
	}
	return oldValue.Concurrency, nil
}

// AddConcurrency adds i to the "concurrency" field.
func (m *UserMutation) AddConcurrency(i int) {
	if m.addconcurrency != nil {
		*m.addconcurrency += i
	} else {
		m.addconcurrency = &i
	}
}

// AddedConcurrency returns the value that was added to the "concurrency" field in this mutation.
func (m *UserMutation) AddedConcurrency() (r int, exists bool) {
	v := m.addconcurrency
	if v == nil {
		return
	}
	return *v, true
}

// ResetConcurrency resets all changes to the "concurrency" field.
func (m *UserMutation) ResetConcurrency() {
	m.concurrency = nil
	m.addconcurrency = nil
}

// SetStatus sets the "status" field.
func (m *UserMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *UserMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldStatus(ctx context.Context) (v string, 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 *UserMutation) ResetStatus() {
	m.status = nil
}

// SetUsername sets the "username" field.
func (m *UserMutation) SetUsername(s string) {
	m.username = &s
}

// Username returns the value of the "username" field in the mutation.
func (m *UserMutation) Username() (r string, exists bool) {
	v := m.username
	if v == nil {
		return
	}
	return *v, true
}

// OldUsername returns the old "username" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldUsername(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUsername is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUsername requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUsername: %w", err)
	}
	return oldValue.Username, nil
}

// ResetUsername resets all changes to the "username" field.
func (m *UserMutation) ResetUsername() {
	m.username = nil
}

// SetNotes sets the "notes" field.
func (m *UserMutation) SetNotes(s string) {
	m.notes = &s
}

// Notes returns the value of the "notes" field in the mutation.
func (m *UserMutation) Notes() (r string, exists bool) {
	v := m.notes
	if v == nil {
		return
	}
	return *v, true
}

// OldNotes returns the old "notes" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldNotes(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldNotes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldNotes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldNotes: %w", err)
	}
	return oldValue.Notes, nil
}

// ResetNotes resets all changes to the "notes" field.
func (m *UserMutation) ResetNotes() {
	m.notes = nil
}

// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func (m *UserMutation) SetTotpSecretEncrypted(s string) {
	m.totp_secret_encrypted = &s
}

// TotpSecretEncrypted returns the value of the "totp_secret_encrypted" field in the mutation.
func (m *UserMutation) TotpSecretEncrypted() (r string, exists bool) {
	v := m.totp_secret_encrypted
	if v == nil {
		return
	}
	return *v, true
}

// OldTotpSecretEncrypted returns the old "totp_secret_encrypted" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldTotpSecretEncrypted(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTotpSecretEncrypted is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTotpSecretEncrypted requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTotpSecretEncrypted: %w", err)
	}
	return oldValue.TotpSecretEncrypted, nil
}

// ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
func (m *UserMutation) ClearTotpSecretEncrypted() {
	m.totp_secret_encrypted = nil
	m.clearedFields[user.FieldTotpSecretEncrypted] = struct{}{}
}

// TotpSecretEncryptedCleared returns if the "totp_secret_encrypted" field was cleared in this mutation.
func (m *UserMutation) TotpSecretEncryptedCleared() bool {
	_, ok := m.clearedFields[user.FieldTotpSecretEncrypted]
	return ok
}

// ResetTotpSecretEncrypted resets all changes to the "totp_secret_encrypted" field.
func (m *UserMutation) ResetTotpSecretEncrypted() {
	m.totp_secret_encrypted = nil
	delete(m.clearedFields, user.FieldTotpSecretEncrypted)
}

// SetTotpEnabled sets the "totp_enabled" field.
func (m *UserMutation) SetTotpEnabled(b bool) {
	m.totp_enabled = &b
}

// TotpEnabled returns the value of the "totp_enabled" field in the mutation.
func (m *UserMutation) TotpEnabled() (r bool, exists bool) {
	v := m.totp_enabled
	if v == nil {
		return
	}
	return *v, true
}

// OldTotpEnabled returns the old "totp_enabled" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldTotpEnabled(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTotpEnabled is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTotpEnabled requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTotpEnabled: %w", err)
	}
	return oldValue.TotpEnabled, nil
}

// ResetTotpEnabled resets all changes to the "totp_enabled" field.
func (m *UserMutation) ResetTotpEnabled() {
	m.totp_enabled = nil
}

// SetTotpEnabledAt sets the "totp_enabled_at" field.
func (m *UserMutation) SetTotpEnabledAt(t time.Time) {
	m.totp_enabled_at = &t
}

// TotpEnabledAt returns the value of the "totp_enabled_at" field in the mutation.
func (m *UserMutation) TotpEnabledAt() (r time.Time, exists bool) {
	v := m.totp_enabled_at
	if v == nil {
		return
	}
	return *v, true
}

// OldTotpEnabledAt returns the old "totp_enabled_at" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldTotpEnabledAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTotpEnabledAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTotpEnabledAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTotpEnabledAt: %w", err)
	}
	return oldValue.TotpEnabledAt, nil
}

// ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
func (m *UserMutation) ClearTotpEnabledAt() {
	m.totp_enabled_at = nil
	m.clearedFields[user.FieldTotpEnabledAt] = struct{}{}
}

// TotpEnabledAtCleared returns if the "totp_enabled_at" field was cleared in this mutation.
func (m *UserMutation) TotpEnabledAtCleared() bool {
	_, ok := m.clearedFields[user.FieldTotpEnabledAt]
	return ok
}

// ResetTotpEnabledAt resets all changes to the "totp_enabled_at" field.
func (m *UserMutation) ResetTotpEnabledAt() {
	m.totp_enabled_at = nil
	delete(m.clearedFields, user.FieldTotpEnabledAt)
}

// SetSignupSource sets the "signup_source" field.
func (m *UserMutation) SetSignupSource(s string) {
	m.signup_source = &s
}

// SignupSource returns the value of the "signup_source" field in the mutation.
func (m *UserMutation) SignupSource() (r string, exists bool) {
	v := m.signup_source
	if v == nil {
		return
	}
	return *v, true
}

// OldSignupSource returns the old "signup_source" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldSignupSource(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSignupSource is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSignupSource requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSignupSource: %w", err)
	}
	return oldValue.SignupSource, nil
}

// ResetSignupSource resets all changes to the "signup_source" field.
func (m *UserMutation) ResetSignupSource() {
	m.signup_source = nil
}

// SetLastLoginAt sets the "last_login_at" field.
func (m *UserMutation) SetLastLoginAt(t time.Time) {
	m.last_login_at = &t
}

// LastLoginAt returns the value of the "last_login_at" field in the mutation.
func (m *UserMutation) LastLoginAt() (r time.Time, exists bool) {
	v := m.last_login_at
	if v == nil {
		return
	}
	return *v, true
}

// OldLastLoginAt returns the old "last_login_at" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldLastLoginAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLastLoginAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLastLoginAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLastLoginAt: %w", err)
	}
	return oldValue.LastLoginAt, nil
}

// ClearLastLoginAt clears the value of the "last_login_at" field.
func (m *UserMutation) ClearLastLoginAt() {
	m.last_login_at = nil
	m.clearedFields[user.FieldLastLoginAt] = struct{}{}
}

// LastLoginAtCleared returns if the "last_login_at" field was cleared in this mutation.
func (m *UserMutation) LastLoginAtCleared() bool {
	_, ok := m.clearedFields[user.FieldLastLoginAt]
	return ok
}

// ResetLastLoginAt resets all changes to the "last_login_at" field.
func (m *UserMutation) ResetLastLoginAt() {
	m.last_login_at = nil
	delete(m.clearedFields, user.FieldLastLoginAt)
}

// SetLastActiveAt sets the "last_active_at" field.
func (m *UserMutation) SetLastActiveAt(t time.Time) {
	m.last_active_at = &t
}

// LastActiveAt returns the value of the "last_active_at" field in the mutation.
func (m *UserMutation) LastActiveAt() (r time.Time, exists bool) {
	v := m.last_active_at
	if v == nil {
		return
	}
	return *v, true
}

// OldLastActiveAt returns the old "last_active_at" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldLastActiveAt(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLastActiveAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLastActiveAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLastActiveAt: %w", err)
	}
	return oldValue.LastActiveAt, nil
}

// ClearLastActiveAt clears the value of the "last_active_at" field.
func (m *UserMutation) ClearLastActiveAt() {
	m.last_active_at = nil
	m.clearedFields[user.FieldLastActiveAt] = struct{}{}
}

// LastActiveAtCleared returns if the "last_active_at" field was cleared in this mutation.
func (m *UserMutation) LastActiveAtCleared() bool {
	_, ok := m.clearedFields[user.FieldLastActiveAt]
	return ok
}

// ResetLastActiveAt resets all changes to the "last_active_at" field.
func (m *UserMutation) ResetLastActiveAt() {
	m.last_active_at = nil
	delete(m.clearedFields, user.FieldLastActiveAt)
}

// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
func (m *UserMutation) SetBalanceNotifyEnabled(b bool) {
	m.balance_notify_enabled = &b
}

// BalanceNotifyEnabled returns the value of the "balance_notify_enabled" field in the mutation.
func (m *UserMutation) BalanceNotifyEnabled() (r bool, exists bool) {
	v := m.balance_notify_enabled
	if v == nil {
		return
	}
	return *v, true
}

// OldBalanceNotifyEnabled returns the old "balance_notify_enabled" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldBalanceNotifyEnabled(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBalanceNotifyEnabled is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBalanceNotifyEnabled requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBalanceNotifyEnabled: %w", err)
	}
	return oldValue.BalanceNotifyEnabled, nil
}

// ResetBalanceNotifyEnabled resets all changes to the "balance_notify_enabled" field.
func (m *UserMutation) ResetBalanceNotifyEnabled() {
	m.balance_notify_enabled = nil
}

// SetBalanceNotifyThresholdType sets the "balance_notify_threshold_type" field.
func (m *UserMutation) SetBalanceNotifyThresholdType(s string) {
	m.balance_notify_threshold_type = &s
}

// BalanceNotifyThresholdType returns the value of the "balance_notify_threshold_type" field in the mutation.
func (m *UserMutation) BalanceNotifyThresholdType() (r string, exists bool) {
	v := m.balance_notify_threshold_type
	if v == nil {
		return
	}
	return *v, true
}

// OldBalanceNotifyThresholdType returns the old "balance_notify_threshold_type" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldBalanceNotifyThresholdType(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBalanceNotifyThresholdType is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBalanceNotifyThresholdType requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBalanceNotifyThresholdType: %w", err)
	}
	return oldValue.BalanceNotifyThresholdType, nil
}

// ResetBalanceNotifyThresholdType resets all changes to the "balance_notify_threshold_type" field.
func (m *UserMutation) ResetBalanceNotifyThresholdType() {
	m.balance_notify_threshold_type = nil
}

// SetBalanceNotifyThreshold sets the "balance_notify_threshold" field.
func (m *UserMutation) SetBalanceNotifyThreshold(f float64) {
	m.balance_notify_threshold = &f
	m.addbalance_notify_threshold = nil
}

// BalanceNotifyThreshold returns the value of the "balance_notify_threshold" field in the mutation.
func (m *UserMutation) BalanceNotifyThreshold() (r float64, exists bool) {
	v := m.balance_notify_threshold
	if v == nil {
		return
	}
	return *v, true
}

// OldBalanceNotifyThreshold returns the old "balance_notify_threshold" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldBalanceNotifyThreshold(ctx context.Context) (v *float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBalanceNotifyThreshold is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBalanceNotifyThreshold requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBalanceNotifyThreshold: %w", err)
	}
	return oldValue.BalanceNotifyThreshold, nil
}

// AddBalanceNotifyThreshold adds f to the "balance_notify_threshold" field.
func (m *UserMutation) AddBalanceNotifyThreshold(f float64) {
	if m.addbalance_notify_threshold != nil {
		*m.addbalance_notify_threshold += f
	} else {
		m.addbalance_notify_threshold = &f
	}
}

// AddedBalanceNotifyThreshold returns the value that was added to the "balance_notify_threshold" field in this mutation.
func (m *UserMutation) AddedBalanceNotifyThreshold() (r float64, exists bool) {
	v := m.addbalance_notify_threshold
	if v == nil {
		return
	}
	return *v, true
}

// ClearBalanceNotifyThreshold clears the value of the "balance_notify_threshold" field.
func (m *UserMutation) ClearBalanceNotifyThreshold() {
	m.balance_notify_threshold = nil
	m.addbalance_notify_threshold = nil
	m.clearedFields[user.FieldBalanceNotifyThreshold] = struct{}{}
}

// BalanceNotifyThresholdCleared returns if the "balance_notify_threshold" field was cleared in this mutation.
func (m *UserMutation) BalanceNotifyThresholdCleared() bool {
	_, ok := m.clearedFields[user.FieldBalanceNotifyThreshold]
	return ok
}

// ResetBalanceNotifyThreshold resets all changes to the "balance_notify_threshold" field.
func (m *UserMutation) ResetBalanceNotifyThreshold() {
	m.balance_notify_threshold = nil
	m.addbalance_notify_threshold = nil
	delete(m.clearedFields, user.FieldBalanceNotifyThreshold)
}

// SetBalanceNotifyExtraEmails sets the "balance_notify_extra_emails" field.
func (m *UserMutation) SetBalanceNotifyExtraEmails(s string) {
	m.balance_notify_extra_emails = &s
}

// BalanceNotifyExtraEmails returns the value of the "balance_notify_extra_emails" field in the mutation.
func (m *UserMutation) BalanceNotifyExtraEmails() (r string, exists bool) {
	v := m.balance_notify_extra_emails
	if v == nil {
		return
	}
	return *v, true
}

// OldBalanceNotifyExtraEmails returns the old "balance_notify_extra_emails" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldBalanceNotifyExtraEmails(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldBalanceNotifyExtraEmails is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldBalanceNotifyExtraEmails requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBalanceNotifyExtraEmails: %w", err)
	}
	return oldValue.BalanceNotifyExtraEmails, nil
}

// ResetBalanceNotifyExtraEmails resets all changes to the "balance_notify_extra_emails" field.
func (m *UserMutation) ResetBalanceNotifyExtraEmails() {
	m.balance_notify_extra_emails = nil
}

// SetTotalRecharged sets the "total_recharged" field.
func (m *UserMutation) SetTotalRecharged(f float64) {
	m.total_recharged = &f
	m.addtotal_recharged = nil
}

// TotalRecharged returns the value of the "total_recharged" field in the mutation.
func (m *UserMutation) TotalRecharged() (r float64, exists bool) {
	v := m.total_recharged
	if v == nil {
		return
	}
	return *v, true
}

// OldTotalRecharged returns the old "total_recharged" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldTotalRecharged(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldTotalRecharged is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldTotalRecharged requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTotalRecharged: %w", err)
	}
	return oldValue.TotalRecharged, nil
}

// AddTotalRecharged adds f to the "total_recharged" field.
func (m *UserMutation) AddTotalRecharged(f float64) {
	if m.addtotal_recharged != nil {
		*m.addtotal_recharged += f
	} else {
		m.addtotal_recharged = &f
	}
}

// AddedTotalRecharged returns the value that was added to the "total_recharged" field in this mutation.
func (m *UserMutation) AddedTotalRecharged() (r float64, exists bool) {
	v := m.addtotal_recharged
	if v == nil {
		return
	}
	return *v, true
}

// ResetTotalRecharged resets all changes to the "total_recharged" field.
func (m *UserMutation) ResetTotalRecharged() {
	m.total_recharged = nil
	m.addtotal_recharged = nil
}

// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by ids.
func (m *UserMutation) AddAPIKeyIDs(ids ...int64) {
	if m.api_keys == nil {
		m.api_keys = make(map[int64]struct{})
	}
	for i := range ids {
		m.api_keys[ids[i]] = struct{}{}
	}
}

// ClearAPIKeys clears the "api_keys" edge to the APIKey entity.
func (m *UserMutation) ClearAPIKeys() {
	m.clearedapi_keys = true
}

// APIKeysCleared reports if the "api_keys" edge to the APIKey entity was cleared.
func (m *UserMutation) APIKeysCleared() bool {
	return m.clearedapi_keys
}

// RemoveAPIKeyIDs removes the "api_keys" edge to the APIKey entity by IDs.
func (m *UserMutation) RemoveAPIKeyIDs(ids ...int64) {
	if m.removedapi_keys == nil {
		m.removedapi_keys = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.api_keys, ids[i])
		m.removedapi_keys[ids[i]] = struct{}{}
	}
}

// RemovedAPIKeys returns the removed IDs of the "api_keys" edge to the APIKey entity.
func (m *UserMutation) RemovedAPIKeysIDs() (ids []int64) {
	for id := range m.removedapi_keys {
		ids = append(ids, id)
	}
	return
}

// APIKeysIDs returns the "api_keys" edge IDs in the mutation.
func (m *UserMutation) APIKeysIDs() (ids []int64) {
	for id := range m.api_keys {
		ids = append(ids, id)
	}
	return
}

// ResetAPIKeys resets all changes to the "api_keys" edge.
func (m *UserMutation) ResetAPIKeys() {
	m.api_keys = nil
	m.clearedapi_keys = false
	m.removedapi_keys = nil
}

// AddRedeemCodeIDs adds the "redeem_codes" edge to the RedeemCode entity by ids.
func (m *UserMutation) AddRedeemCodeIDs(ids ...int64) {
	if m.redeem_codes == nil {
		m.redeem_codes = make(map[int64]struct{})
	}
	for i := range ids {
		m.redeem_codes[ids[i]] = struct{}{}
	}
}

// ClearRedeemCodes clears the "redeem_codes" edge to the RedeemCode entity.
func (m *UserMutation) ClearRedeemCodes() {
	m.clearedredeem_codes = true
}

// RedeemCodesCleared reports if the "redeem_codes" edge to the RedeemCode entity was cleared.
func (m *UserMutation) RedeemCodesCleared() bool {
	return m.clearedredeem_codes
}

// RemoveRedeemCodeIDs removes the "redeem_codes" edge to the RedeemCode entity by IDs.
func (m *UserMutation) RemoveRedeemCodeIDs(ids ...int64) {
	if m.removedredeem_codes == nil {
		m.removedredeem_codes = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.redeem_codes, ids[i])
		m.removedredeem_codes[ids[i]] = struct{}{}
	}
}

// RemovedRedeemCodes returns the removed IDs of the "redeem_codes" edge to the RedeemCode entity.
func (m *UserMutation) RemovedRedeemCodesIDs() (ids []int64) {
	for id := range m.removedredeem_codes {
		ids = append(ids, id)
	}
	return
}

// RedeemCodesIDs returns the "redeem_codes" edge IDs in the mutation.
func (m *UserMutation) RedeemCodesIDs() (ids []int64) {
	for id := range m.redeem_codes {
		ids = append(ids, id)
	}
	return
}

// ResetRedeemCodes resets all changes to the "redeem_codes" edge.
func (m *UserMutation) ResetRedeemCodes() {
	m.redeem_codes = nil
	m.clearedredeem_codes = false
	m.removedredeem_codes = nil
}

// AddSubscriptionIDs adds the "subscriptions" edge to the UserSubscription entity by ids.
func (m *UserMutation) AddSubscriptionIDs(ids ...int64) {
	if m.subscriptions == nil {
		m.subscriptions = make(map[int64]struct{})
	}
	for i := range ids {
		m.subscriptions[ids[i]] = struct{}{}
	}
}

// ClearSubscriptions clears the "subscriptions" edge to the UserSubscription entity.
func (m *UserMutation) ClearSubscriptions() {
	m.clearedsubscriptions = true
}

// SubscriptionsCleared reports if the "subscriptions" edge to the UserSubscription entity was cleared.
func (m *UserMutation) SubscriptionsCleared() bool {
	return m.clearedsubscriptions
}

// RemoveSubscriptionIDs removes the "subscriptions" edge to the UserSubscription entity by IDs.
func (m *UserMutation) RemoveSubscriptionIDs(ids ...int64) {
	if m.removedsubscriptions == nil {
		m.removedsubscriptions = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.subscriptions, ids[i])
		m.removedsubscriptions[ids[i]] = struct{}{}
	}
}

// RemovedSubscriptions returns the removed IDs of the "subscriptions" edge to the UserSubscription entity.
func (m *UserMutation) RemovedSubscriptionsIDs() (ids []int64) {
	for id := range m.removedsubscriptions {
		ids = append(ids, id)
	}
	return
}

// SubscriptionsIDs returns the "subscriptions" edge IDs in the mutation.
func (m *UserMutation) SubscriptionsIDs() (ids []int64) {
	for id := range m.subscriptions {
		ids = append(ids, id)
	}
	return
}

// ResetSubscriptions resets all changes to the "subscriptions" edge.
func (m *UserMutation) ResetSubscriptions() {
	m.subscriptions = nil
	m.clearedsubscriptions = false
	m.removedsubscriptions = nil
}

// AddAssignedSubscriptionIDs adds the "assigned_subscriptions" edge to the UserSubscription entity by ids.
func (m *UserMutation) AddAssignedSubscriptionIDs(ids ...int64) {
	if m.assigned_subscriptions == nil {
		m.assigned_subscriptions = make(map[int64]struct{})
	}
	for i := range ids {
		m.assigned_subscriptions[ids[i]] = struct{}{}
	}
}

// ClearAssignedSubscriptions clears the "assigned_subscriptions" edge to the UserSubscription entity.
func (m *UserMutation) ClearAssignedSubscriptions() {
	m.clearedassigned_subscriptions = true
}

// AssignedSubscriptionsCleared reports if the "assigned_subscriptions" edge to the UserSubscription entity was cleared.
func (m *UserMutation) AssignedSubscriptionsCleared() bool {
	return m.clearedassigned_subscriptions
}

// RemoveAssignedSubscriptionIDs removes the "assigned_subscriptions" edge to the UserSubscription entity by IDs.
func (m *UserMutation) RemoveAssignedSubscriptionIDs(ids ...int64) {
	if m.removedassigned_subscriptions == nil {
		m.removedassigned_subscriptions = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.assigned_subscriptions, ids[i])
		m.removedassigned_subscriptions[ids[i]] = struct{}{}
	}
}

// RemovedAssignedSubscriptions returns the removed IDs of the "assigned_subscriptions" edge to the UserSubscription entity.
func (m *UserMutation) RemovedAssignedSubscriptionsIDs() (ids []int64) {
	for id := range m.removedassigned_subscriptions {
		ids = append(ids, id)
	}
	return
}

// AssignedSubscriptionsIDs returns the "assigned_subscriptions" edge IDs in the mutation.
func (m *UserMutation) AssignedSubscriptionsIDs() (ids []int64) {
	for id := range m.assigned_subscriptions {
		ids = append(ids, id)
	}
	return
}

// ResetAssignedSubscriptions resets all changes to the "assigned_subscriptions" edge.
func (m *UserMutation) ResetAssignedSubscriptions() {
	m.assigned_subscriptions = nil
	m.clearedassigned_subscriptions = false
	m.removedassigned_subscriptions = nil
}

// AddAnnouncementReadIDs adds the "announcement_reads" edge to the AnnouncementRead entity by ids.
func (m *UserMutation) AddAnnouncementReadIDs(ids ...int64) {
	if m.announcement_reads == nil {
		m.announcement_reads = make(map[int64]struct{})
	}
	for i := range ids {
		m.announcement_reads[ids[i]] = struct{}{}
	}
}

// ClearAnnouncementReads clears the "announcement_reads" edge to the AnnouncementRead entity.
func (m *UserMutation) ClearAnnouncementReads() {
	m.clearedannouncement_reads = true
}

// AnnouncementReadsCleared reports if the "announcement_reads" edge to the AnnouncementRead entity was cleared.
func (m *UserMutation) AnnouncementReadsCleared() bool {
	return m.clearedannouncement_reads
}

// RemoveAnnouncementReadIDs removes the "announcement_reads" edge to the AnnouncementRead entity by IDs.
func (m *UserMutation) RemoveAnnouncementReadIDs(ids ...int64) {
	if m.removedannouncement_reads == nil {
		m.removedannouncement_reads = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.announcement_reads, ids[i])
		m.removedannouncement_reads[ids[i]] = struct{}{}
	}
}

// RemovedAnnouncementReads returns the removed IDs of the "announcement_reads" edge to the AnnouncementRead entity.
func (m *UserMutation) RemovedAnnouncementReadsIDs() (ids []int64) {
	for id := range m.removedannouncement_reads {
		ids = append(ids, id)
	}
	return
}

// AnnouncementReadsIDs returns the "announcement_reads" edge IDs in the mutation.
func (m *UserMutation) AnnouncementReadsIDs() (ids []int64) {
	for id := range m.announcement_reads {
		ids = append(ids, id)
	}
	return
}

// ResetAnnouncementReads resets all changes to the "announcement_reads" edge.
func (m *UserMutation) ResetAnnouncementReads() {
	m.announcement_reads = nil
	m.clearedannouncement_reads = false
	m.removedannouncement_reads = nil
}

// AddAllowedGroupIDs adds the "allowed_groups" edge to the Group entity by ids.
func (m *UserMutation) AddAllowedGroupIDs(ids ...int64) {
	if m.allowed_groups == nil {
		m.allowed_groups = make(map[int64]struct{})
	}
	for i := range ids {
		m.allowed_groups[ids[i]] = struct{}{}
	}
}

// ClearAllowedGroups clears the "allowed_groups" edge to the Group entity.
func (m *UserMutation) ClearAllowedGroups() {
	m.clearedallowed_groups = true
}

// AllowedGroupsCleared reports if the "allowed_groups" edge to the Group entity was cleared.
func (m *UserMutation) AllowedGroupsCleared() bool {
	return m.clearedallowed_groups
}

// RemoveAllowedGroupIDs removes the "allowed_groups" edge to the Group entity by IDs.
func (m *UserMutation) RemoveAllowedGroupIDs(ids ...int64) {
	if m.removedallowed_groups == nil {
		m.removedallowed_groups = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.allowed_groups, ids[i])
		m.removedallowed_groups[ids[i]] = struct{}{}
	}
}

// RemovedAllowedGroups returns the removed IDs of the "allowed_groups" edge to the Group entity.
func (m *UserMutation) RemovedAllowedGroupsIDs() (ids []int64) {
	for id := range m.removedallowed_groups {
		ids = append(ids, id)
	}
	return
}

// AllowedGroupsIDs returns the "allowed_groups" edge IDs in the mutation.
func (m *UserMutation) AllowedGroupsIDs() (ids []int64) {
	for id := range m.allowed_groups {
		ids = append(ids, id)
	}
	return
}

// ResetAllowedGroups resets all changes to the "allowed_groups" edge.
func (m *UserMutation) ResetAllowedGroups() {
	m.allowed_groups = nil
	m.clearedallowed_groups = false
	m.removedallowed_groups = nil
}

// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by ids.
func (m *UserMutation) AddUsageLogIDs(ids ...int64) {
	if m.usage_logs == nil {
		m.usage_logs = make(map[int64]struct{})
	}
	for i := range ids {
		m.usage_logs[ids[i]] = struct{}{}
	}
}

// ClearUsageLogs clears the "usage_logs" edge to the UsageLog entity.
func (m *UserMutation) ClearUsageLogs() {
	m.clearedusage_logs = true
}

// UsageLogsCleared reports if the "usage_logs" edge to the UsageLog entity was cleared.
func (m *UserMutation) UsageLogsCleared() bool {
	return m.clearedusage_logs
}

// RemoveUsageLogIDs removes the "usage_logs" edge to the UsageLog entity by IDs.
func (m *UserMutation) RemoveUsageLogIDs(ids ...int64) {
	if m.removedusage_logs == nil {
		m.removedusage_logs = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.usage_logs, ids[i])
		m.removedusage_logs[ids[i]] = struct{}{}
	}
}

// RemovedUsageLogs returns the removed IDs of the "usage_logs" edge to the UsageLog entity.
func (m *UserMutation) RemovedUsageLogsIDs() (ids []int64) {
	for id := range m.removedusage_logs {
		ids = append(ids, id)
	}
	return
}

// UsageLogsIDs returns the "usage_logs" edge IDs in the mutation.
func (m *UserMutation) UsageLogsIDs() (ids []int64) {
	for id := range m.usage_logs {
		ids = append(ids, id)
	}
	return
}

// ResetUsageLogs resets all changes to the "usage_logs" edge.
func (m *UserMutation) ResetUsageLogs() {
	m.usage_logs = nil
	m.clearedusage_logs = false
	m.removedusage_logs = nil
}

// AddAttributeValueIDs adds the "attribute_values" edge to the UserAttributeValue entity by ids.
func (m *UserMutation) AddAttributeValueIDs(ids ...int64) {
	if m.attribute_values == nil {
		m.attribute_values = make(map[int64]struct{})
	}
	for i := range ids {
		m.attribute_values[ids[i]] = struct{}{}
	}
}

// ClearAttributeValues clears the "attribute_values" edge to the UserAttributeValue entity.
func (m *UserMutation) ClearAttributeValues() {
	m.clearedattribute_values = true
}

// AttributeValuesCleared reports if the "attribute_values" edge to the UserAttributeValue entity was cleared.
func (m *UserMutation) AttributeValuesCleared() bool {
	return m.clearedattribute_values
}

// RemoveAttributeValueIDs removes the "attribute_values" edge to the UserAttributeValue entity by IDs.
func (m *UserMutation) RemoveAttributeValueIDs(ids ...int64) {
	if m.removedattribute_values == nil {
		m.removedattribute_values = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.attribute_values, ids[i])
		m.removedattribute_values[ids[i]] = struct{}{}
	}
}

// RemovedAttributeValues returns the removed IDs of the "attribute_values" edge to the UserAttributeValue entity.
func (m *UserMutation) RemovedAttributeValuesIDs() (ids []int64) {
	for id := range m.removedattribute_values {
		ids = append(ids, id)
	}
	return
}

// AttributeValuesIDs returns the "attribute_values" edge IDs in the mutation.
func (m *UserMutation) AttributeValuesIDs() (ids []int64) {
	for id := range m.attribute_values {
		ids = append(ids, id)
	}
	return
}

// ResetAttributeValues resets all changes to the "attribute_values" edge.
func (m *UserMutation) ResetAttributeValues() {
	m.attribute_values = nil
	m.clearedattribute_values = false
	m.removedattribute_values = nil
}

// AddPromoCodeUsageIDs adds the "promo_code_usages" edge to the PromoCodeUsage entity by ids.
func (m *UserMutation) AddPromoCodeUsageIDs(ids ...int64) {
	if m.promo_code_usages == nil {
		m.promo_code_usages = make(map[int64]struct{})
	}
	for i := range ids {
		m.promo_code_usages[ids[i]] = struct{}{}
	}
}

// ClearPromoCodeUsages clears the "promo_code_usages" edge to the PromoCodeUsage entity.
func (m *UserMutation) ClearPromoCodeUsages() {
	m.clearedpromo_code_usages = true
}

// PromoCodeUsagesCleared reports if the "promo_code_usages" edge to the PromoCodeUsage entity was cleared.
func (m *UserMutation) PromoCodeUsagesCleared() bool {
	return m.clearedpromo_code_usages
}

// RemovePromoCodeUsageIDs removes the "promo_code_usages" edge to the PromoCodeUsage entity by IDs.
func (m *UserMutation) RemovePromoCodeUsageIDs(ids ...int64) {
	if m.removedpromo_code_usages == nil {
		m.removedpromo_code_usages = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.promo_code_usages, ids[i])
		m.removedpromo_code_usages[ids[i]] = struct{}{}
	}
}

// RemovedPromoCodeUsages returns the removed IDs of the "promo_code_usages" edge to the PromoCodeUsage entity.
func (m *UserMutation) RemovedPromoCodeUsagesIDs() (ids []int64) {
	for id := range m.removedpromo_code_usages {
		ids = append(ids, id)
	}
	return
}

// PromoCodeUsagesIDs returns the "promo_code_usages" edge IDs in the mutation.
func (m *UserMutation) PromoCodeUsagesIDs() (ids []int64) {
	for id := range m.promo_code_usages {
		ids = append(ids, id)
	}
	return
}

// ResetPromoCodeUsages resets all changes to the "promo_code_usages" edge.
func (m *UserMutation) ResetPromoCodeUsages() {
	m.promo_code_usages = nil
	m.clearedpromo_code_usages = false
	m.removedpromo_code_usages = nil
}

// AddPaymentOrderIDs adds the "payment_orders" edge to the PaymentOrder entity by ids.
func (m *UserMutation) AddPaymentOrderIDs(ids ...int64) {
	if m.payment_orders == nil {
		m.payment_orders = make(map[int64]struct{})
	}
	for i := range ids {
		m.payment_orders[ids[i]] = struct{}{}
	}
}

// ClearPaymentOrders clears the "payment_orders" edge to the PaymentOrder entity.
func (m *UserMutation) ClearPaymentOrders() {
	m.clearedpayment_orders = true
}

// PaymentOrdersCleared reports if the "payment_orders" edge to the PaymentOrder entity was cleared.
func (m *UserMutation) PaymentOrdersCleared() bool {
	return m.clearedpayment_orders
}

// RemovePaymentOrderIDs removes the "payment_orders" edge to the PaymentOrder entity by IDs.
func (m *UserMutation) RemovePaymentOrderIDs(ids ...int64) {
	if m.removedpayment_orders == nil {
		m.removedpayment_orders = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.payment_orders, ids[i])
		m.removedpayment_orders[ids[i]] = struct{}{}
	}
}

// RemovedPaymentOrders returns the removed IDs of the "payment_orders" edge to the PaymentOrder entity.
func (m *UserMutation) RemovedPaymentOrdersIDs() (ids []int64) {
	for id := range m.removedpayment_orders {
		ids = append(ids, id)
	}
	return
}

// PaymentOrdersIDs returns the "payment_orders" edge IDs in the mutation.
func (m *UserMutation) PaymentOrdersIDs() (ids []int64) {
	for id := range m.payment_orders {
		ids = append(ids, id)
	}
	return
}

// ResetPaymentOrders resets all changes to the "payment_orders" edge.
func (m *UserMutation) ResetPaymentOrders() {
	m.payment_orders = nil
	m.clearedpayment_orders = false
	m.removedpayment_orders = nil
}

// AddAuthIdentityIDs adds the "auth_identities" edge to the AuthIdentity entity by ids.
func (m *UserMutation) AddAuthIdentityIDs(ids ...int64) {
	if m.auth_identities == nil {
		m.auth_identities = make(map[int64]struct{})
	}
	for i := range ids {
		m.auth_identities[ids[i]] = struct{}{}
	}
}

// ClearAuthIdentities clears the "auth_identities" edge to the AuthIdentity entity.
func (m *UserMutation) ClearAuthIdentities() {
	m.clearedauth_identities = true
}

// AuthIdentitiesCleared reports if the "auth_identities" edge to the AuthIdentity entity was cleared.
func (m *UserMutation) AuthIdentitiesCleared() bool {
	return m.clearedauth_identities
}

// RemoveAuthIdentityIDs removes the "auth_identities" edge to the AuthIdentity entity by IDs.
func (m *UserMutation) RemoveAuthIdentityIDs(ids ...int64) {
	if m.removedauth_identities == nil {
		m.removedauth_identities = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.auth_identities, ids[i])
		m.removedauth_identities[ids[i]] = struct{}{}
	}
}

// RemovedAuthIdentities returns the removed IDs of the "auth_identities" edge to the AuthIdentity entity.
func (m *UserMutation) RemovedAuthIdentitiesIDs() (ids []int64) {
	for id := range m.removedauth_identities {
		ids = append(ids, id)
	}
	return
}

// AuthIdentitiesIDs returns the "auth_identities" edge IDs in the mutation.
func (m *UserMutation) AuthIdentitiesIDs() (ids []int64) {
	for id := range m.auth_identities {
		ids = append(ids, id)
	}
	return
}

// ResetAuthIdentities resets all changes to the "auth_identities" edge.
func (m *UserMutation) ResetAuthIdentities() {
	m.auth_identities = nil
	m.clearedauth_identities = false
	m.removedauth_identities = nil
}

// AddPendingAuthSessionIDs adds the "pending_auth_sessions" edge to the PendingAuthSession entity by ids.
func (m *UserMutation) AddPendingAuthSessionIDs(ids ...int64) {
	if m.pending_auth_sessions == nil {
		m.pending_auth_sessions = make(map[int64]struct{})
	}
	for i := range ids {
		m.pending_auth_sessions[ids[i]] = struct{}{}
	}
}

// ClearPendingAuthSessions clears the "pending_auth_sessions" edge to the PendingAuthSession entity.
func (m *UserMutation) ClearPendingAuthSessions() {
	m.clearedpending_auth_sessions = true
}

// PendingAuthSessionsCleared reports if the "pending_auth_sessions" edge to the PendingAuthSession entity was cleared.
func (m *UserMutation) PendingAuthSessionsCleared() bool {
	return m.clearedpending_auth_sessions
}

// RemovePendingAuthSessionIDs removes the "pending_auth_sessions" edge to the PendingAuthSession entity by IDs.
func (m *UserMutation) RemovePendingAuthSessionIDs(ids ...int64) {
	if m.removedpending_auth_sessions == nil {
		m.removedpending_auth_sessions = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.pending_auth_sessions, ids[i])
		m.removedpending_auth_sessions[ids[i]] = struct{}{}
	}
}

// RemovedPendingAuthSessions returns the removed IDs of the "pending_auth_sessions" edge to the PendingAuthSession entity.
func (m *UserMutation) RemovedPendingAuthSessionsIDs() (ids []int64) {
	for id := range m.removedpending_auth_sessions {
		ids = append(ids, id)
	}
	return
}

// PendingAuthSessionsIDs returns the "pending_auth_sessions" edge IDs in the mutation.
func (m *UserMutation) PendingAuthSessionsIDs() (ids []int64) {
	for id := range m.pending_auth_sessions {
		ids = append(ids, id)
	}
	return
}

// ResetPendingAuthSessions resets all changes to the "pending_auth_sessions" edge.
func (m *UserMutation) ResetPendingAuthSessions() {
	m.pending_auth_sessions = nil
	m.clearedpending_auth_sessions = false
	m.removedpending_auth_sessions = nil
}

// Where appends a list predicates to the UserMutation builder.
func (m *UserMutation) Where(ps ...predicate.User) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the UserMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.User, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *UserMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *UserMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (User).
func (m *UserMutation) 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 *UserMutation) Fields() []string {
	fields := make([]string, 0, 22)
	if m.created_at != nil {
		fields = append(fields, user.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, user.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, user.FieldDeletedAt)
	}
	if m.email != nil {
		fields = append(fields, user.FieldEmail)
	}
	if m.password_hash != nil {
		fields = append(fields, user.FieldPasswordHash)
	}
	if m.role != nil {
		fields = append(fields, user.FieldRole)
	}
	if m.balance != nil {
		fields = append(fields, user.FieldBalance)
	}
	if m.concurrency != nil {
		fields = append(fields, user.FieldConcurrency)
	}
	if m.status != nil {
		fields = append(fields, user.FieldStatus)
	}
	if m.username != nil {
		fields = append(fields, user.FieldUsername)
	}
	if m.notes != nil {
		fields = append(fields, user.FieldNotes)
	}
	if m.totp_secret_encrypted != nil {
		fields = append(fields, user.FieldTotpSecretEncrypted)
	}
	if m.totp_enabled != nil {
		fields = append(fields, user.FieldTotpEnabled)
	}
	if m.totp_enabled_at != nil {
		fields = append(fields, user.FieldTotpEnabledAt)
	}
	if m.signup_source != nil {
		fields = append(fields, user.FieldSignupSource)
	}
	if m.last_login_at != nil {
		fields = append(fields, user.FieldLastLoginAt)
	}
	if m.last_active_at != nil {
		fields = append(fields, user.FieldLastActiveAt)
	}
	if m.balance_notify_enabled != nil {
		fields = append(fields, user.FieldBalanceNotifyEnabled)
	}
	if m.balance_notify_threshold_type != nil {
		fields = append(fields, user.FieldBalanceNotifyThresholdType)
	}
	if m.balance_notify_threshold != nil {
		fields = append(fields, user.FieldBalanceNotifyThreshold)
	}
	if m.balance_notify_extra_emails != nil {
		fields = append(fields, user.FieldBalanceNotifyExtraEmails)
	}
	if m.total_recharged != nil {
		fields = append(fields, user.FieldTotalRecharged)
	}
	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 *UserMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case user.FieldCreatedAt:
		return m.CreatedAt()
	case user.FieldUpdatedAt:
		return m.UpdatedAt()
	case user.FieldDeletedAt:
		return m.DeletedAt()
	case user.FieldEmail:
		return m.Email()
	case user.FieldPasswordHash:
		return m.PasswordHash()
	case user.FieldRole:
		return m.Role()
	case user.FieldBalance:
		return m.Balance()
	case user.FieldConcurrency:
		return m.Concurrency()
	case user.FieldStatus:
		return m.Status()
	case user.FieldUsername:
		return m.Username()
	case user.FieldNotes:
		return m.Notes()
	case user.FieldTotpSecretEncrypted:
		return m.TotpSecretEncrypted()
	case user.FieldTotpEnabled:
		return m.TotpEnabled()
	case user.FieldTotpEnabledAt:
		return m.TotpEnabledAt()
	case user.FieldSignupSource:
		return m.SignupSource()
	case user.FieldLastLoginAt:
		return m.LastLoginAt()
	case user.FieldLastActiveAt:
		return m.LastActiveAt()
	case user.FieldBalanceNotifyEnabled:
		return m.BalanceNotifyEnabled()
	case user.FieldBalanceNotifyThresholdType:
		return m.BalanceNotifyThresholdType()
	case user.FieldBalanceNotifyThreshold:
		return m.BalanceNotifyThreshold()
	case user.FieldBalanceNotifyExtraEmails:
		return m.BalanceNotifyExtraEmails()
	case user.FieldTotalRecharged:
		return m.TotalRecharged()
	}
	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 *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case user.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case user.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case user.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case user.FieldEmail:
		return m.OldEmail(ctx)
	case user.FieldPasswordHash:
		return m.OldPasswordHash(ctx)
	case user.FieldRole:
		return m.OldRole(ctx)
	case user.FieldBalance:
		return m.OldBalance(ctx)
	case user.FieldConcurrency:
		return m.OldConcurrency(ctx)
	case user.FieldStatus:
		return m.OldStatus(ctx)
	case user.FieldUsername:
		return m.OldUsername(ctx)
	case user.FieldNotes:
		return m.OldNotes(ctx)
	case user.FieldTotpSecretEncrypted:
		return m.OldTotpSecretEncrypted(ctx)
	case user.FieldTotpEnabled:
		return m.OldTotpEnabled(ctx)
	case user.FieldTotpEnabledAt:
		return m.OldTotpEnabledAt(ctx)
	case user.FieldSignupSource:
		return m.OldSignupSource(ctx)
	case user.FieldLastLoginAt:
		return m.OldLastLoginAt(ctx)
	case user.FieldLastActiveAt:
		return m.OldLastActiveAt(ctx)
	case user.FieldBalanceNotifyEnabled:
		return m.OldBalanceNotifyEnabled(ctx)
	case user.FieldBalanceNotifyThresholdType:
		return m.OldBalanceNotifyThresholdType(ctx)
	case user.FieldBalanceNotifyThreshold:
		return m.OldBalanceNotifyThreshold(ctx)
	case user.FieldBalanceNotifyExtraEmails:
		return m.OldBalanceNotifyExtraEmails(ctx)
	case user.FieldTotalRecharged:
		return m.OldTotalRecharged(ctx)
	}
	return nil, fmt.Errorf("unknown User 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 *UserMutation) SetField(name string, value ent.Value) error {
	switch name {
	case user.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 user.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 user.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 user.FieldEmail:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEmail(v)
		return nil
	case user.FieldPasswordHash:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPasswordHash(v)
		return nil
	case user.FieldRole:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRole(v)
		return nil
	case user.FieldBalance:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBalance(v)
		return nil
	case user.FieldConcurrency:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetConcurrency(v)
		return nil
	case user.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case user.FieldUsername:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUsername(v)
		return nil
	case user.FieldNotes:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNotes(v)
		return nil
	case user.FieldTotpSecretEncrypted:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTotpSecretEncrypted(v)
		return nil
	case user.FieldTotpEnabled:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTotpEnabled(v)
		return nil
	case user.FieldTotpEnabledAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTotpEnabledAt(v)
		return nil
	case user.FieldSignupSource:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSignupSource(v)
		return nil
	case user.FieldLastLoginAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastLoginAt(v)
		return nil
	case user.FieldLastActiveAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastActiveAt(v)
		return nil
	case user.FieldBalanceNotifyEnabled:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBalanceNotifyEnabled(v)
		return nil
	case user.FieldBalanceNotifyThresholdType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBalanceNotifyThresholdType(v)
		return nil
	case user.FieldBalanceNotifyThreshold:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBalanceNotifyThreshold(v)
		return nil
	case user.FieldBalanceNotifyExtraEmails:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBalanceNotifyExtraEmails(v)
		return nil
	case user.FieldTotalRecharged:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTotalRecharged(v)
		return nil
	}
	return fmt.Errorf("unknown User field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserMutation) AddedFields() []string {
	var fields []string
	if m.addbalance != nil {
		fields = append(fields, user.FieldBalance)
	}
	if m.addconcurrency != nil {
		fields = append(fields, user.FieldConcurrency)
	}
	if m.addbalance_notify_threshold != nil {
		fields = append(fields, user.FieldBalanceNotifyThreshold)
	}
	if m.addtotal_recharged != nil {
		fields = append(fields, user.FieldTotalRecharged)
	}
	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 *UserMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case user.FieldBalance:
		return m.AddedBalance()
	case user.FieldConcurrency:
		return m.AddedConcurrency()
	case user.FieldBalanceNotifyThreshold:
		return m.AddedBalanceNotifyThreshold()
	case user.FieldTotalRecharged:
		return m.AddedTotalRecharged()
	}
	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 *UserMutation) AddField(name string, value ent.Value) error {
	switch name {
	case user.FieldBalance:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddBalance(v)
		return nil
	case user.FieldConcurrency:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddConcurrency(v)
		return nil
	case user.FieldBalanceNotifyThreshold:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddBalanceNotifyThreshold(v)
		return nil
	case user.FieldTotalRecharged:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddTotalRecharged(v)
		return nil
	}
	return fmt.Errorf("unknown User numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(user.FieldDeletedAt) {
		fields = append(fields, user.FieldDeletedAt)
	}
	if m.FieldCleared(user.FieldTotpSecretEncrypted) {
		fields = append(fields, user.FieldTotpSecretEncrypted)
	}
	if m.FieldCleared(user.FieldTotpEnabledAt) {
		fields = append(fields, user.FieldTotpEnabledAt)
	}
	if m.FieldCleared(user.FieldLastLoginAt) {
		fields = append(fields, user.FieldLastLoginAt)
	}
	if m.FieldCleared(user.FieldLastActiveAt) {
		fields = append(fields, user.FieldLastActiveAt)
	}
	if m.FieldCleared(user.FieldBalanceNotifyThreshold) {
		fields = append(fields, user.FieldBalanceNotifyThreshold)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserMutation) 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 *UserMutation) ClearField(name string) error {
	switch name {
	case user.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	case user.FieldTotpSecretEncrypted:
		m.ClearTotpSecretEncrypted()
		return nil
	case user.FieldTotpEnabledAt:
		m.ClearTotpEnabledAt()
		return nil
	case user.FieldLastLoginAt:
		m.ClearLastLoginAt()
		return nil
	case user.FieldLastActiveAt:
		m.ClearLastActiveAt()
		return nil
	case user.FieldBalanceNotifyThreshold:
		m.ClearBalanceNotifyThreshold()
		return nil
	}
	return fmt.Errorf("unknown User 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 *UserMutation) ResetField(name string) error {
	switch name {
	case user.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case user.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case user.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case user.FieldEmail:
		m.ResetEmail()
		return nil
	case user.FieldPasswordHash:
		m.ResetPasswordHash()
		return nil
	case user.FieldRole:
		m.ResetRole()
		return nil
	case user.FieldBalance:
		m.ResetBalance()
		return nil
	case user.FieldConcurrency:
		m.ResetConcurrency()
		return nil
	case user.FieldStatus:
		m.ResetStatus()
		return nil
	case user.FieldUsername:
		m.ResetUsername()
		return nil
	case user.FieldNotes:
		m.ResetNotes()
		return nil
	case user.FieldTotpSecretEncrypted:
		m.ResetTotpSecretEncrypted()
		return nil
	case user.FieldTotpEnabled:
		m.ResetTotpEnabled()
		return nil
	case user.FieldTotpEnabledAt:
		m.ResetTotpEnabledAt()
		return nil
	case user.FieldSignupSource:
		m.ResetSignupSource()
		return nil
	case user.FieldLastLoginAt:
		m.ResetLastLoginAt()
		return nil
	case user.FieldLastActiveAt:
		m.ResetLastActiveAt()
		return nil
	case user.FieldBalanceNotifyEnabled:
		m.ResetBalanceNotifyEnabled()
		return nil
	case user.FieldBalanceNotifyThresholdType:
		m.ResetBalanceNotifyThresholdType()
		return nil
	case user.FieldBalanceNotifyThreshold:
		m.ResetBalanceNotifyThreshold()
		return nil
	case user.FieldBalanceNotifyExtraEmails:
		m.ResetBalanceNotifyExtraEmails()
		return nil
	case user.FieldTotalRecharged:
		m.ResetTotalRecharged()
		return nil
	}
	return fmt.Errorf("unknown User field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserMutation) AddedEdges() []string {
	edges := make([]string, 0, 12)
	if m.api_keys != nil {
		edges = append(edges, user.EdgeAPIKeys)
	}
	if m.redeem_codes != nil {
		edges = append(edges, user.EdgeRedeemCodes)
	}
	if m.subscriptions != nil {
		edges = append(edges, user.EdgeSubscriptions)
	}
	if m.assigned_subscriptions != nil {
		edges = append(edges, user.EdgeAssignedSubscriptions)
	}
	if m.announcement_reads != nil {
		edges = append(edges, user.EdgeAnnouncementReads)
	}
	if m.allowed_groups != nil {
		edges = append(edges, user.EdgeAllowedGroups)
	}
	if m.usage_logs != nil {
		edges = append(edges, user.EdgeUsageLogs)
	}
	if m.attribute_values != nil {
		edges = append(edges, user.EdgeAttributeValues)
	}
	if m.promo_code_usages != nil {
		edges = append(edges, user.EdgePromoCodeUsages)
	}
	if m.payment_orders != nil {
		edges = append(edges, user.EdgePaymentOrders)
	}
	if m.auth_identities != nil {
		edges = append(edges, user.EdgeAuthIdentities)
	}
	if m.pending_auth_sessions != nil {
		edges = append(edges, user.EdgePendingAuthSessions)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case user.EdgeAPIKeys:
		ids := make([]ent.Value, 0, len(m.api_keys))
		for id := range m.api_keys {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeRedeemCodes:
		ids := make([]ent.Value, 0, len(m.redeem_codes))
		for id := range m.redeem_codes {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeSubscriptions:
		ids := make([]ent.Value, 0, len(m.subscriptions))
		for id := range m.subscriptions {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeAssignedSubscriptions:
		ids := make([]ent.Value, 0, len(m.assigned_subscriptions))
		for id := range m.assigned_subscriptions {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeAnnouncementReads:
		ids := make([]ent.Value, 0, len(m.announcement_reads))
		for id := range m.announcement_reads {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeAllowedGroups:
		ids := make([]ent.Value, 0, len(m.allowed_groups))
		for id := range m.allowed_groups {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeUsageLogs:
		ids := make([]ent.Value, 0, len(m.usage_logs))
		for id := range m.usage_logs {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeAttributeValues:
		ids := make([]ent.Value, 0, len(m.attribute_values))
		for id := range m.attribute_values {
			ids = append(ids, id)
		}
		return ids
	case user.EdgePromoCodeUsages:
		ids := make([]ent.Value, 0, len(m.promo_code_usages))
		for id := range m.promo_code_usages {
			ids = append(ids, id)
		}
		return ids
	case user.EdgePaymentOrders:
		ids := make([]ent.Value, 0, len(m.payment_orders))
		for id := range m.payment_orders {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeAuthIdentities:
		ids := make([]ent.Value, 0, len(m.auth_identities))
		for id := range m.auth_identities {
			ids = append(ids, id)
		}
		return ids
	case user.EdgePendingAuthSessions:
		ids := make([]ent.Value, 0, len(m.pending_auth_sessions))
		for id := range m.pending_auth_sessions {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMutation) RemovedEdges() []string {
	edges := make([]string, 0, 12)
	if m.removedapi_keys != nil {
		edges = append(edges, user.EdgeAPIKeys)
	}
	if m.removedredeem_codes != nil {
		edges = append(edges, user.EdgeRedeemCodes)
	}
	if m.removedsubscriptions != nil {
		edges = append(edges, user.EdgeSubscriptions)
	}
	if m.removedassigned_subscriptions != nil {
		edges = append(edges, user.EdgeAssignedSubscriptions)
	}
	if m.removedannouncement_reads != nil {
		edges = append(edges, user.EdgeAnnouncementReads)
	}
	if m.removedallowed_groups != nil {
		edges = append(edges, user.EdgeAllowedGroups)
	}
	if m.removedusage_logs != nil {
		edges = append(edges, user.EdgeUsageLogs)
	}
	if m.removedattribute_values != nil {
		edges = append(edges, user.EdgeAttributeValues)
	}
	if m.removedpromo_code_usages != nil {
		edges = append(edges, user.EdgePromoCodeUsages)
	}
	if m.removedpayment_orders != nil {
		edges = append(edges, user.EdgePaymentOrders)
	}
	if m.removedauth_identities != nil {
		edges = append(edges, user.EdgeAuthIdentities)
	}
	if m.removedpending_auth_sessions != nil {
		edges = append(edges, user.EdgePendingAuthSessions)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UserMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case user.EdgeAPIKeys:
		ids := make([]ent.Value, 0, len(m.removedapi_keys))
		for id := range m.removedapi_keys {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeRedeemCodes:
		ids := make([]ent.Value, 0, len(m.removedredeem_codes))
		for id := range m.removedredeem_codes {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeSubscriptions:
		ids := make([]ent.Value, 0, len(m.removedsubscriptions))
		for id := range m.removedsubscriptions {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeAssignedSubscriptions:
		ids := make([]ent.Value, 0, len(m.removedassigned_subscriptions))
		for id := range m.removedassigned_subscriptions {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeAnnouncementReads:
		ids := make([]ent.Value, 0, len(m.removedannouncement_reads))
		for id := range m.removedannouncement_reads {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeAllowedGroups:
		ids := make([]ent.Value, 0, len(m.removedallowed_groups))
		for id := range m.removedallowed_groups {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeUsageLogs:
		ids := make([]ent.Value, 0, len(m.removedusage_logs))
		for id := range m.removedusage_logs {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeAttributeValues:
		ids := make([]ent.Value, 0, len(m.removedattribute_values))
		for id := range m.removedattribute_values {
			ids = append(ids, id)
		}
		return ids
	case user.EdgePromoCodeUsages:
		ids := make([]ent.Value, 0, len(m.removedpromo_code_usages))
		for id := range m.removedpromo_code_usages {
			ids = append(ids, id)
		}
		return ids
	case user.EdgePaymentOrders:
		ids := make([]ent.Value, 0, len(m.removedpayment_orders))
		for id := range m.removedpayment_orders {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeAuthIdentities:
		ids := make([]ent.Value, 0, len(m.removedauth_identities))
		for id := range m.removedauth_identities {
			ids = append(ids, id)
		}
		return ids
	case user.EdgePendingAuthSessions:
		ids := make([]ent.Value, 0, len(m.removedpending_auth_sessions))
		for id := range m.removedpending_auth_sessions {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserMutation) ClearedEdges() []string {
	edges := make([]string, 0, 12)
	if m.clearedapi_keys {
		edges = append(edges, user.EdgeAPIKeys)
	}
	if m.clearedredeem_codes {
		edges = append(edges, user.EdgeRedeemCodes)
	}
	if m.clearedsubscriptions {
		edges = append(edges, user.EdgeSubscriptions)
	}
	if m.clearedassigned_subscriptions {
		edges = append(edges, user.EdgeAssignedSubscriptions)
	}
	if m.clearedannouncement_reads {
		edges = append(edges, user.EdgeAnnouncementReads)
	}
	if m.clearedallowed_groups {
		edges = append(edges, user.EdgeAllowedGroups)
	}
	if m.clearedusage_logs {
		edges = append(edges, user.EdgeUsageLogs)
	}
	if m.clearedattribute_values {
		edges = append(edges, user.EdgeAttributeValues)
	}
	if m.clearedpromo_code_usages {
		edges = append(edges, user.EdgePromoCodeUsages)
	}
	if m.clearedpayment_orders {
		edges = append(edges, user.EdgePaymentOrders)
	}
	if m.clearedauth_identities {
		edges = append(edges, user.EdgeAuthIdentities)
	}
	if m.clearedpending_auth_sessions {
		edges = append(edges, user.EdgePendingAuthSessions)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserMutation) EdgeCleared(name string) bool {
	switch name {
	case user.EdgeAPIKeys:
		return m.clearedapi_keys
	case user.EdgeRedeemCodes:
		return m.clearedredeem_codes
	case user.EdgeSubscriptions:
		return m.clearedsubscriptions
	case user.EdgeAssignedSubscriptions:
		return m.clearedassigned_subscriptions
	case user.EdgeAnnouncementReads:
		return m.clearedannouncement_reads
	case user.EdgeAllowedGroups:
		return m.clearedallowed_groups
	case user.EdgeUsageLogs:
		return m.clearedusage_logs
	case user.EdgeAttributeValues:
		return m.clearedattribute_values
	case user.EdgePromoCodeUsages:
		return m.clearedpromo_code_usages
	case user.EdgePaymentOrders:
		return m.clearedpayment_orders
	case user.EdgeAuthIdentities:
		return m.clearedauth_identities
	case user.EdgePendingAuthSessions:
		return m.clearedpending_auth_sessions
	}
	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 *UserMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown User 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 *UserMutation) ResetEdge(name string) error {
	switch name {
	case user.EdgeAPIKeys:
		m.ResetAPIKeys()
		return nil
	case user.EdgeRedeemCodes:
		m.ResetRedeemCodes()
		return nil
	case user.EdgeSubscriptions:
		m.ResetSubscriptions()
		return nil
	case user.EdgeAssignedSubscriptions:
		m.ResetAssignedSubscriptions()
		return nil
	case user.EdgeAnnouncementReads:
		m.ResetAnnouncementReads()
		return nil
	case user.EdgeAllowedGroups:
		m.ResetAllowedGroups()
		return nil
	case user.EdgeUsageLogs:
		m.ResetUsageLogs()
		return nil
	case user.EdgeAttributeValues:
		m.ResetAttributeValues()
		return nil
	case user.EdgePromoCodeUsages:
		m.ResetPromoCodeUsages()
		return nil
	case user.EdgePaymentOrders:
		m.ResetPaymentOrders()
		return nil
	case user.EdgeAuthIdentities:
		m.ResetAuthIdentities()
		return nil
	case user.EdgePendingAuthSessions:
		m.ResetPendingAuthSessions()
		return nil
	}
	return fmt.Errorf("unknown User edge %s", name)
}

// UserAllowedGroupMutation represents an operation that mutates the UserAllowedGroup nodes in the graph.
type UserAllowedGroupMutation struct {
	config
	op            Op
	typ           string
	created_at    *time.Time
	clearedFields map[string]struct{}
	user          *int64
	cleareduser   bool
	group         *int64
	clearedgroup  bool
	done          bool
	oldValue      func(context.Context) (*UserAllowedGroup, error)
	predicates    []predicate.UserAllowedGroup
}

var _ ent.Mutation = (*UserAllowedGroupMutation)(nil)

// userallowedgroupOption allows management of the mutation configuration using functional options.
type userallowedgroupOption func(*UserAllowedGroupMutation)

// newUserAllowedGroupMutation creates new mutation for the UserAllowedGroup entity.
func newUserAllowedGroupMutation(c config, op Op, opts ...userallowedgroupOption) *UserAllowedGroupMutation {
	m := &UserAllowedGroupMutation{
		config:        c,
		op:            op,
		typ:           TypeUserAllowedGroup,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// 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 UserAllowedGroupMutation) 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 UserAllowedGroupMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetUserID sets the "user_id" field.
func (m *UserAllowedGroupMutation) SetUserID(i int64) {
	m.user = &i
}

// UserID returns the value of the "user_id" field in the mutation.
func (m *UserAllowedGroupMutation) UserID() (r int64, exists bool) {
	v := m.user
	if v == nil {
		return
	}
	return *v, true
}

// ResetUserID resets all changes to the "user_id" field.
func (m *UserAllowedGroupMutation) ResetUserID() {
	m.user = nil
}

// SetGroupID sets the "group_id" field.
func (m *UserAllowedGroupMutation) SetGroupID(i int64) {
	m.group = &i
}

// GroupID returns the value of the "group_id" field in the mutation.
func (m *UserAllowedGroupMutation) GroupID() (r int64, exists bool) {
	v := m.group
	if v == nil {
		return
	}
	return *v, true
}

// ResetGroupID resets all changes to the "group_id" field.
func (m *UserAllowedGroupMutation) ResetGroupID() {
	m.group = nil
}

// SetCreatedAt sets the "created_at" field.
func (m *UserAllowedGroupMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UserAllowedGroupMutation) CreatedAt() (r time.Time, exists bool) {
	v := m.created_at
	if v == nil {
		return
	}
	return *v, true
}

// ResetCreatedAt resets all changes to the "created_at" field.
func (m *UserAllowedGroupMutation) ResetCreatedAt() {
	m.created_at = nil
}

// ClearUser clears the "user" edge to the User entity.
func (m *UserAllowedGroupMutation) ClearUser() {
	m.cleareduser = true
	m.clearedFields[userallowedgroup.FieldUserID] = struct{}{}
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *UserAllowedGroupMutation) UserCleared() bool {
	return m.cleareduser
}

// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *UserAllowedGroupMutation) UserIDs() (ids []int64) {
	if id := m.user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetUser resets all changes to the "user" edge.
func (m *UserAllowedGroupMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

// ClearGroup clears the "group" edge to the Group entity.
func (m *UserAllowedGroupMutation) ClearGroup() {
	m.clearedgroup = true
	m.clearedFields[userallowedgroup.FieldGroupID] = struct{}{}
}

// GroupCleared reports if the "group" edge to the Group entity was cleared.
func (m *UserAllowedGroupMutation) GroupCleared() bool {
	return m.clearedgroup
}

// GroupIDs returns the "group" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// GroupID instead. It exists only for internal usage by the builders.
func (m *UserAllowedGroupMutation) GroupIDs() (ids []int64) {
	if id := m.group; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetGroup resets all changes to the "group" edge.
func (m *UserAllowedGroupMutation) ResetGroup() {
	m.group = nil
	m.clearedgroup = false
}

// Where appends a list predicates to the UserAllowedGroupMutation builder.
func (m *UserAllowedGroupMutation) Where(ps ...predicate.UserAllowedGroup) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the UserAllowedGroupMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserAllowedGroupMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.UserAllowedGroup, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *UserAllowedGroupMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *UserAllowedGroupMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (UserAllowedGroup).
func (m *UserAllowedGroupMutation) 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 *UserAllowedGroupMutation) Fields() []string {
	fields := make([]string, 0, 3)
	if m.user != nil {
		fields = append(fields, userallowedgroup.FieldUserID)
	}
	if m.group != nil {
		fields = append(fields, userallowedgroup.FieldGroupID)
	}
	if m.created_at != nil {
		fields = append(fields, userallowedgroup.FieldCreatedAt)
	}
	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 *UserAllowedGroupMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case userallowedgroup.FieldUserID:
		return m.UserID()
	case userallowedgroup.FieldGroupID:
		return m.GroupID()
	case userallowedgroup.FieldCreatedAt:
		return m.CreatedAt()
	}
	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 *UserAllowedGroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	return nil, errors.New("edge schema UserAllowedGroup does not support getting old values")
}

// 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 *UserAllowedGroupMutation) SetField(name string, value ent.Value) error {
	switch name {
	case userallowedgroup.FieldUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserID(v)
		return nil
	case userallowedgroup.FieldGroupID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetGroupID(v)
		return nil
	case userallowedgroup.FieldCreatedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetCreatedAt(v)
		return nil
	}
	return fmt.Errorf("unknown UserAllowedGroup field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserAllowedGroupMutation) AddedFields() []string {
	var fields []string
	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 *UserAllowedGroupMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	}
	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 *UserAllowedGroupMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown UserAllowedGroup numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserAllowedGroupMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserAllowedGroupMutation) 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 *UserAllowedGroupMutation) ClearField(name string) error {
	return fmt.Errorf("unknown UserAllowedGroup 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 *UserAllowedGroupMutation) ResetField(name string) error {
	switch name {
	case userallowedgroup.FieldUserID:
		m.ResetUserID()
		return nil
	case userallowedgroup.FieldGroupID:
		m.ResetGroupID()
		return nil
	case userallowedgroup.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	}
	return fmt.Errorf("unknown UserAllowedGroup field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserAllowedGroupMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.user != nil {
		edges = append(edges, userallowedgroup.EdgeUser)
	}
	if m.group != nil {
		edges = append(edges, userallowedgroup.EdgeGroup)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserAllowedGroupMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case userallowedgroup.EdgeUser:
		if id := m.user; id != nil {
			return []ent.Value{*id}
		}
	case userallowedgroup.EdgeGroup:
		if id := m.group; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserAllowedGroupMutation) 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 *UserAllowedGroupMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserAllowedGroupMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.cleareduser {
		edges = append(edges, userallowedgroup.EdgeUser)
	}
	if m.clearedgroup {
		edges = append(edges, userallowedgroup.EdgeGroup)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserAllowedGroupMutation) EdgeCleared(name string) bool {
	switch name {
	case userallowedgroup.EdgeUser:
		return m.cleareduser
	case userallowedgroup.EdgeGroup:
		return m.clearedgroup
	}
	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 *UserAllowedGroupMutation) ClearEdge(name string) error {
	switch name {
	case userallowedgroup.EdgeUser:
		m.ClearUser()
		return nil
	case userallowedgroup.EdgeGroup:
		m.ClearGroup()
		return nil
	}
	return fmt.Errorf("unknown UserAllowedGroup 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 *UserAllowedGroupMutation) ResetEdge(name string) error {
	switch name {
	case userallowedgroup.EdgeUser:
		m.ResetUser()
		return nil
	case userallowedgroup.EdgeGroup:
		m.ResetGroup()
		return nil
	}
	return fmt.Errorf("unknown UserAllowedGroup edge %s", name)
}

// UserAttributeDefinitionMutation represents an operation that mutates the UserAttributeDefinition nodes in the graph.
type UserAttributeDefinitionMutation struct {
	config
	op               Op
	typ              string
	id               *int64
	created_at       *time.Time
	updated_at       *time.Time
	deleted_at       *time.Time
	key              *string
	name             *string
	description      *string
	_type            *string
	options          *[]map[string]interface{}
	appendoptions    []map[string]interface{}
	required         *bool
	validation       *map[string]interface{}
	placeholder      *string
	display_order    *int
	adddisplay_order *int
	enabled          *bool
	clearedFields    map[string]struct{}
	values           map[int64]struct{}
	removedvalues    map[int64]struct{}
	clearedvalues    bool
	done             bool
	oldValue         func(context.Context) (*UserAttributeDefinition, error)
	predicates       []predicate.UserAttributeDefinition
}

var _ ent.Mutation = (*UserAttributeDefinitionMutation)(nil)

// userattributedefinitionOption allows management of the mutation configuration using functional options.
type userattributedefinitionOption func(*UserAttributeDefinitionMutation)

// newUserAttributeDefinitionMutation creates new mutation for the UserAttributeDefinition entity.
func newUserAttributeDefinitionMutation(c config, op Op, opts ...userattributedefinitionOption) *UserAttributeDefinitionMutation {
	m := &UserAttributeDefinitionMutation{
		config:        c,
		op:            op,
		typ:           TypeUserAttributeDefinition,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withUserAttributeDefinitionID sets the ID field of the mutation.
func withUserAttributeDefinitionID(id int64) userattributedefinitionOption {
	return func(m *UserAttributeDefinitionMutation) {
		var (
			err   error
			once  sync.Once
			value *UserAttributeDefinition
		)
		m.oldValue = func(ctx context.Context) (*UserAttributeDefinition, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().UserAttributeDefinition.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withUserAttributeDefinition sets the old UserAttributeDefinition of the mutation.
func withUserAttributeDefinition(node *UserAttributeDefinition) userattributedefinitionOption {
	return func(m *UserAttributeDefinitionMutation) {
		m.oldValue = func(context.Context) (*UserAttributeDefinition, 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 UserAttributeDefinitionMutation) 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 UserAttributeDefinitionMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *UserAttributeDefinitionMutation) ID() (id int64, 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 *UserAttributeDefinitionMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().UserAttributeDefinition.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *UserAttributeDefinitionMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UserAttributeDefinitionMutation) 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 UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) 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 *UserAttributeDefinitionMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *UserAttributeDefinitionMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *UserAttributeDefinitionMutation) 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 UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) 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 *UserAttributeDefinitionMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetDeletedAt sets the "deleted_at" field.
func (m *UserAttributeDefinitionMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *UserAttributeDefinitionMutation) 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 UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) 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 *UserAttributeDefinitionMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[userattributedefinition.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *UserAttributeDefinitionMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[userattributedefinition.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *UserAttributeDefinitionMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, userattributedefinition.FieldDeletedAt)
}

// SetKey sets the "key" field.
func (m *UserAttributeDefinitionMutation) SetKey(s string) {
	m.key = &s
}

// Key returns the value of the "key" field in the mutation.
func (m *UserAttributeDefinitionMutation) Key() (r string, exists bool) {
	v := m.key
	if v == nil {
		return
	}
	return *v, true
}

// OldKey returns the old "key" field's value of the UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) OldKey(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldKey is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldKey requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldKey: %w", err)
	}
	return oldValue.Key, nil
}

// ResetKey resets all changes to the "key" field.
func (m *UserAttributeDefinitionMutation) ResetKey() {
	m.key = nil
}

// SetName sets the "name" field.
func (m *UserAttributeDefinitionMutation) SetName(s string) {
	m.name = &s
}

// Name returns the value of the "name" field in the mutation.
func (m *UserAttributeDefinitionMutation) 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 UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) 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 *UserAttributeDefinitionMutation) ResetName() {
	m.name = nil
}

// SetDescription sets the "description" field.
func (m *UserAttributeDefinitionMutation) SetDescription(s string) {
	m.description = &s
}

// Description returns the value of the "description" field in the mutation.
func (m *UserAttributeDefinitionMutation) 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 UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) 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
}

// ResetDescription resets all changes to the "description" field.
func (m *UserAttributeDefinitionMutation) ResetDescription() {
	m.description = nil
}

// SetType sets the "type" field.
func (m *UserAttributeDefinitionMutation) SetType(s string) {
	m._type = &s
}

// GetType returns the value of the "type" field in the mutation.
func (m *UserAttributeDefinitionMutation) GetType() (r string, exists bool) {
	v := m._type
	if v == nil {
		return
	}
	return *v, true
}

// OldType returns the old "type" field's value of the UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) OldType(ctx context.Context) (v string, 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 *UserAttributeDefinitionMutation) ResetType() {
	m._type = nil
}

// SetOptions sets the "options" field.
func (m *UserAttributeDefinitionMutation) SetOptions(value []map[string]interface{}) {
	m.options = &value
	m.appendoptions = nil
}

// Options returns the value of the "options" field in the mutation.
func (m *UserAttributeDefinitionMutation) Options() (r []map[string]interface{}, exists bool) {
	v := m.options
	if v == nil {
		return
	}
	return *v, true
}

// OldOptions returns the old "options" field's value of the UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) OldOptions(ctx context.Context) (v []map[string]interface{}, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldOptions is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldOptions requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldOptions: %w", err)
	}
	return oldValue.Options, nil
}

// AppendOptions adds value to the "options" field.
func (m *UserAttributeDefinitionMutation) AppendOptions(value []map[string]interface{}) {
	m.appendoptions = append(m.appendoptions, value...)
}

// AppendedOptions returns the list of values that were appended to the "options" field in this mutation.
func (m *UserAttributeDefinitionMutation) AppendedOptions() ([]map[string]interface{}, bool) {
	if len(m.appendoptions) == 0 {
		return nil, false
	}
	return m.appendoptions, true
}

// ResetOptions resets all changes to the "options" field.
func (m *UserAttributeDefinitionMutation) ResetOptions() {
	m.options = nil
	m.appendoptions = nil
}

// SetRequired sets the "required" field.
func (m *UserAttributeDefinitionMutation) SetRequired(b bool) {
	m.required = &b
}

// Required returns the value of the "required" field in the mutation.
func (m *UserAttributeDefinitionMutation) Required() (r bool, exists bool) {
	v := m.required
	if v == nil {
		return
	}
	return *v, true
}

// OldRequired returns the old "required" field's value of the UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) OldRequired(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldRequired is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldRequired requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldRequired: %w", err)
	}
	return oldValue.Required, nil
}

// ResetRequired resets all changes to the "required" field.
func (m *UserAttributeDefinitionMutation) ResetRequired() {
	m.required = nil
}

// SetValidation sets the "validation" field.
func (m *UserAttributeDefinitionMutation) SetValidation(value map[string]interface{}) {
	m.validation = &value
}

// Validation returns the value of the "validation" field in the mutation.
func (m *UserAttributeDefinitionMutation) Validation() (r map[string]interface{}, exists bool) {
	v := m.validation
	if v == nil {
		return
	}
	return *v, true
}

// OldValidation returns the old "validation" field's value of the UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) OldValidation(ctx context.Context) (v map[string]interface{}, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldValidation is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldValidation requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldValidation: %w", err)
	}
	return oldValue.Validation, nil
}

// ResetValidation resets all changes to the "validation" field.
func (m *UserAttributeDefinitionMutation) ResetValidation() {
	m.validation = nil
}

// SetPlaceholder sets the "placeholder" field.
func (m *UserAttributeDefinitionMutation) SetPlaceholder(s string) {
	m.placeholder = &s
}

// Placeholder returns the value of the "placeholder" field in the mutation.
func (m *UserAttributeDefinitionMutation) Placeholder() (r string, exists bool) {
	v := m.placeholder
	if v == nil {
		return
	}
	return *v, true
}

// OldPlaceholder returns the old "placeholder" field's value of the UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) OldPlaceholder(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldPlaceholder is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldPlaceholder requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPlaceholder: %w", err)
	}
	return oldValue.Placeholder, nil
}

// ResetPlaceholder resets all changes to the "placeholder" field.
func (m *UserAttributeDefinitionMutation) ResetPlaceholder() {
	m.placeholder = nil
}

// SetDisplayOrder sets the "display_order" field.
func (m *UserAttributeDefinitionMutation) SetDisplayOrder(i int) {
	m.display_order = &i
	m.adddisplay_order = nil
}

// DisplayOrder returns the value of the "display_order" field in the mutation.
func (m *UserAttributeDefinitionMutation) DisplayOrder() (r int, exists bool) {
	v := m.display_order
	if v == nil {
		return
	}
	return *v, true
}

// OldDisplayOrder returns the old "display_order" field's value of the UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) OldDisplayOrder(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDisplayOrder is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDisplayOrder requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDisplayOrder: %w", err)
	}
	return oldValue.DisplayOrder, nil
}

// AddDisplayOrder adds i to the "display_order" field.
func (m *UserAttributeDefinitionMutation) AddDisplayOrder(i int) {
	if m.adddisplay_order != nil {
		*m.adddisplay_order += i
	} else {
		m.adddisplay_order = &i
	}
}

// AddedDisplayOrder returns the value that was added to the "display_order" field in this mutation.
func (m *UserAttributeDefinitionMutation) AddedDisplayOrder() (r int, exists bool) {
	v := m.adddisplay_order
	if v == nil {
		return
	}
	return *v, true
}

// ResetDisplayOrder resets all changes to the "display_order" field.
func (m *UserAttributeDefinitionMutation) ResetDisplayOrder() {
	m.display_order = nil
	m.adddisplay_order = nil
}

// SetEnabled sets the "enabled" field.
func (m *UserAttributeDefinitionMutation) SetEnabled(b bool) {
	m.enabled = &b
}

// Enabled returns the value of the "enabled" field in the mutation.
func (m *UserAttributeDefinitionMutation) Enabled() (r bool, exists bool) {
	v := m.enabled
	if v == nil {
		return
	}
	return *v, true
}

// OldEnabled returns the old "enabled" field's value of the UserAttributeDefinition entity.
// If the UserAttributeDefinition object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeDefinitionMutation) OldEnabled(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldEnabled is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldEnabled requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldEnabled: %w", err)
	}
	return oldValue.Enabled, nil
}

// ResetEnabled resets all changes to the "enabled" field.
func (m *UserAttributeDefinitionMutation) ResetEnabled() {
	m.enabled = nil
}

// AddValueIDs adds the "values" edge to the UserAttributeValue entity by ids.
func (m *UserAttributeDefinitionMutation) AddValueIDs(ids ...int64) {
	if m.values == nil {
		m.values = make(map[int64]struct{})
	}
	for i := range ids {
		m.values[ids[i]] = struct{}{}
	}
}

// ClearValues clears the "values" edge to the UserAttributeValue entity.
func (m *UserAttributeDefinitionMutation) ClearValues() {
	m.clearedvalues = true
}

// ValuesCleared reports if the "values" edge to the UserAttributeValue entity was cleared.
func (m *UserAttributeDefinitionMutation) ValuesCleared() bool {
	return m.clearedvalues
}

// RemoveValueIDs removes the "values" edge to the UserAttributeValue entity by IDs.
func (m *UserAttributeDefinitionMutation) RemoveValueIDs(ids ...int64) {
	if m.removedvalues == nil {
		m.removedvalues = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.values, ids[i])
		m.removedvalues[ids[i]] = struct{}{}
	}
}

// RemovedValues returns the removed IDs of the "values" edge to the UserAttributeValue entity.
func (m *UserAttributeDefinitionMutation) RemovedValuesIDs() (ids []int64) {
	for id := range m.removedvalues {
		ids = append(ids, id)
	}
	return
}

// ValuesIDs returns the "values" edge IDs in the mutation.
func (m *UserAttributeDefinitionMutation) ValuesIDs() (ids []int64) {
	for id := range m.values {
		ids = append(ids, id)
	}
	return
}

// ResetValues resets all changes to the "values" edge.
func (m *UserAttributeDefinitionMutation) ResetValues() {
	m.values = nil
	m.clearedvalues = false
	m.removedvalues = nil
}

// Where appends a list predicates to the UserAttributeDefinitionMutation builder.
func (m *UserAttributeDefinitionMutation) Where(ps ...predicate.UserAttributeDefinition) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the UserAttributeDefinitionMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserAttributeDefinitionMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.UserAttributeDefinition, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *UserAttributeDefinitionMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *UserAttributeDefinitionMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (UserAttributeDefinition).
func (m *UserAttributeDefinitionMutation) 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 *UserAttributeDefinitionMutation) Fields() []string {
	fields := make([]string, 0, 13)
	if m.created_at != nil {
		fields = append(fields, userattributedefinition.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, userattributedefinition.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, userattributedefinition.FieldDeletedAt)
	}
	if m.key != nil {
		fields = append(fields, userattributedefinition.FieldKey)
	}
	if m.name != nil {
		fields = append(fields, userattributedefinition.FieldName)
	}
	if m.description != nil {
		fields = append(fields, userattributedefinition.FieldDescription)
	}
	if m._type != nil {
		fields = append(fields, userattributedefinition.FieldType)
	}
	if m.options != nil {
		fields = append(fields, userattributedefinition.FieldOptions)
	}
	if m.required != nil {
		fields = append(fields, userattributedefinition.FieldRequired)
	}
	if m.validation != nil {
		fields = append(fields, userattributedefinition.FieldValidation)
	}
	if m.placeholder != nil {
		fields = append(fields, userattributedefinition.FieldPlaceholder)
	}
	if m.display_order != nil {
		fields = append(fields, userattributedefinition.FieldDisplayOrder)
	}
	if m.enabled != nil {
		fields = append(fields, userattributedefinition.FieldEnabled)
	}
	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 *UserAttributeDefinitionMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case userattributedefinition.FieldCreatedAt:
		return m.CreatedAt()
	case userattributedefinition.FieldUpdatedAt:
		return m.UpdatedAt()
	case userattributedefinition.FieldDeletedAt:
		return m.DeletedAt()
	case userattributedefinition.FieldKey:
		return m.Key()
	case userattributedefinition.FieldName:
		return m.Name()
	case userattributedefinition.FieldDescription:
		return m.Description()
	case userattributedefinition.FieldType:
		return m.GetType()
	case userattributedefinition.FieldOptions:
		return m.Options()
	case userattributedefinition.FieldRequired:
		return m.Required()
	case userattributedefinition.FieldValidation:
		return m.Validation()
	case userattributedefinition.FieldPlaceholder:
		return m.Placeholder()
	case userattributedefinition.FieldDisplayOrder:
		return m.DisplayOrder()
	case userattributedefinition.FieldEnabled:
		return m.Enabled()
	}
	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 *UserAttributeDefinitionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case userattributedefinition.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case userattributedefinition.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case userattributedefinition.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case userattributedefinition.FieldKey:
		return m.OldKey(ctx)
	case userattributedefinition.FieldName:
		return m.OldName(ctx)
	case userattributedefinition.FieldDescription:
		return m.OldDescription(ctx)
	case userattributedefinition.FieldType:
		return m.OldType(ctx)
	case userattributedefinition.FieldOptions:
		return m.OldOptions(ctx)
	case userattributedefinition.FieldRequired:
		return m.OldRequired(ctx)
	case userattributedefinition.FieldValidation:
		return m.OldValidation(ctx)
	case userattributedefinition.FieldPlaceholder:
		return m.OldPlaceholder(ctx)
	case userattributedefinition.FieldDisplayOrder:
		return m.OldDisplayOrder(ctx)
	case userattributedefinition.FieldEnabled:
		return m.OldEnabled(ctx)
	}
	return nil, fmt.Errorf("unknown UserAttributeDefinition 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 *UserAttributeDefinitionMutation) SetField(name string, value ent.Value) error {
	switch name {
	case userattributedefinition.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 userattributedefinition.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 userattributedefinition.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 userattributedefinition.FieldKey:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetKey(v)
		return nil
	case userattributedefinition.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case userattributedefinition.FieldDescription:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDescription(v)
		return nil
	case userattributedefinition.FieldType:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetType(v)
		return nil
	case userattributedefinition.FieldOptions:
		v, ok := value.([]map[string]interface{})
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetOptions(v)
		return nil
	case userattributedefinition.FieldRequired:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetRequired(v)
		return nil
	case userattributedefinition.FieldValidation:
		v, ok := value.(map[string]interface{})
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetValidation(v)
		return nil
	case userattributedefinition.FieldPlaceholder:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPlaceholder(v)
		return nil
	case userattributedefinition.FieldDisplayOrder:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDisplayOrder(v)
		return nil
	case userattributedefinition.FieldEnabled:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetEnabled(v)
		return nil
	}
	return fmt.Errorf("unknown UserAttributeDefinition field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserAttributeDefinitionMutation) AddedFields() []string {
	var fields []string
	if m.adddisplay_order != nil {
		fields = append(fields, userattributedefinition.FieldDisplayOrder)
	}
	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 *UserAttributeDefinitionMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case userattributedefinition.FieldDisplayOrder:
		return m.AddedDisplayOrder()
	}
	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 *UserAttributeDefinitionMutation) AddField(name string, value ent.Value) error {
	switch name {
	case userattributedefinition.FieldDisplayOrder:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddDisplayOrder(v)
		return nil
	}
	return fmt.Errorf("unknown UserAttributeDefinition numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserAttributeDefinitionMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(userattributedefinition.FieldDeletedAt) {
		fields = append(fields, userattributedefinition.FieldDeletedAt)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserAttributeDefinitionMutation) 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 *UserAttributeDefinitionMutation) ClearField(name string) error {
	switch name {
	case userattributedefinition.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	}
	return fmt.Errorf("unknown UserAttributeDefinition 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 *UserAttributeDefinitionMutation) ResetField(name string) error {
	switch name {
	case userattributedefinition.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case userattributedefinition.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case userattributedefinition.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case userattributedefinition.FieldKey:
		m.ResetKey()
		return nil
	case userattributedefinition.FieldName:
		m.ResetName()
		return nil
	case userattributedefinition.FieldDescription:
		m.ResetDescription()
		return nil
	case userattributedefinition.FieldType:
		m.ResetType()
		return nil
	case userattributedefinition.FieldOptions:
		m.ResetOptions()
		return nil
	case userattributedefinition.FieldRequired:
		m.ResetRequired()
		return nil
	case userattributedefinition.FieldValidation:
		m.ResetValidation()
		return nil
	case userattributedefinition.FieldPlaceholder:
		m.ResetPlaceholder()
		return nil
	case userattributedefinition.FieldDisplayOrder:
		m.ResetDisplayOrder()
		return nil
	case userattributedefinition.FieldEnabled:
		m.ResetEnabled()
		return nil
	}
	return fmt.Errorf("unknown UserAttributeDefinition field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserAttributeDefinitionMutation) AddedEdges() []string {
	edges := make([]string, 0, 1)
	if m.values != nil {
		edges = append(edges, userattributedefinition.EdgeValues)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserAttributeDefinitionMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case userattributedefinition.EdgeValues:
		ids := make([]ent.Value, 0, len(m.values))
		for id := range m.values {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserAttributeDefinitionMutation) RemovedEdges() []string {
	edges := make([]string, 0, 1)
	if m.removedvalues != nil {
		edges = append(edges, userattributedefinition.EdgeValues)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UserAttributeDefinitionMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case userattributedefinition.EdgeValues:
		ids := make([]ent.Value, 0, len(m.removedvalues))
		for id := range m.removedvalues {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserAttributeDefinitionMutation) ClearedEdges() []string {
	edges := make([]string, 0, 1)
	if m.clearedvalues {
		edges = append(edges, userattributedefinition.EdgeValues)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserAttributeDefinitionMutation) EdgeCleared(name string) bool {
	switch name {
	case userattributedefinition.EdgeValues:
		return m.clearedvalues
	}
	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 *UserAttributeDefinitionMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown UserAttributeDefinition 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 *UserAttributeDefinitionMutation) ResetEdge(name string) error {
	switch name {
	case userattributedefinition.EdgeValues:
		m.ResetValues()
		return nil
	}
	return fmt.Errorf("unknown UserAttributeDefinition edge %s", name)
}

// UserAttributeValueMutation represents an operation that mutates the UserAttributeValue nodes in the graph.
type UserAttributeValueMutation struct {
	config
	op                Op
	typ               string
	id                *int64
	created_at        *time.Time
	updated_at        *time.Time
	value             *string
	clearedFields     map[string]struct{}
	user              *int64
	cleareduser       bool
	definition        *int64
	cleareddefinition bool
	done              bool
	oldValue          func(context.Context) (*UserAttributeValue, error)
	predicates        []predicate.UserAttributeValue
}

var _ ent.Mutation = (*UserAttributeValueMutation)(nil)

// userattributevalueOption allows management of the mutation configuration using functional options.
type userattributevalueOption func(*UserAttributeValueMutation)

// newUserAttributeValueMutation creates new mutation for the UserAttributeValue entity.
func newUserAttributeValueMutation(c config, op Op, opts ...userattributevalueOption) *UserAttributeValueMutation {
	m := &UserAttributeValueMutation{
		config:        c,
		op:            op,
		typ:           TypeUserAttributeValue,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withUserAttributeValueID sets the ID field of the mutation.
func withUserAttributeValueID(id int64) userattributevalueOption {
	return func(m *UserAttributeValueMutation) {
		var (
			err   error
			once  sync.Once
			value *UserAttributeValue
		)
		m.oldValue = func(ctx context.Context) (*UserAttributeValue, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().UserAttributeValue.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withUserAttributeValue sets the old UserAttributeValue of the mutation.
func withUserAttributeValue(node *UserAttributeValue) userattributevalueOption {
	return func(m *UserAttributeValueMutation) {
		m.oldValue = func(context.Context) (*UserAttributeValue, 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 UserAttributeValueMutation) 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 UserAttributeValueMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *UserAttributeValueMutation) ID() (id int64, 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 *UserAttributeValueMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().UserAttributeValue.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *UserAttributeValueMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UserAttributeValueMutation) 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 UserAttributeValue entity.
// If the UserAttributeValue object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeValueMutation) 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 *UserAttributeValueMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *UserAttributeValueMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *UserAttributeValueMutation) 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 UserAttributeValue entity.
// If the UserAttributeValue object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeValueMutation) 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 *UserAttributeValueMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetUserID sets the "user_id" field.
func (m *UserAttributeValueMutation) SetUserID(i int64) {
	m.user = &i
}

// UserID returns the value of the "user_id" field in the mutation.
func (m *UserAttributeValueMutation) UserID() (r int64, exists bool) {
	v := m.user
	if v == nil {
		return
	}
	return *v, true
}

// OldUserID returns the old "user_id" field's value of the UserAttributeValue entity.
// If the UserAttributeValue object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeValueMutation) OldUserID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
	}
	return oldValue.UserID, nil
}

// ResetUserID resets all changes to the "user_id" field.
func (m *UserAttributeValueMutation) ResetUserID() {
	m.user = nil
}

// SetAttributeID sets the "attribute_id" field.
func (m *UserAttributeValueMutation) SetAttributeID(i int64) {
	m.definition = &i
}

// AttributeID returns the value of the "attribute_id" field in the mutation.
func (m *UserAttributeValueMutation) AttributeID() (r int64, exists bool) {
	v := m.definition
	if v == nil {
		return
	}
	return *v, true
}

// OldAttributeID returns the old "attribute_id" field's value of the UserAttributeValue entity.
// If the UserAttributeValue object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeValueMutation) OldAttributeID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAttributeID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAttributeID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAttributeID: %w", err)
	}
	return oldValue.AttributeID, nil
}

// ResetAttributeID resets all changes to the "attribute_id" field.
func (m *UserAttributeValueMutation) ResetAttributeID() {
	m.definition = nil
}

// SetValue sets the "value" field.
func (m *UserAttributeValueMutation) SetValue(s string) {
	m.value = &s
}

// Value returns the value of the "value" field in the mutation.
func (m *UserAttributeValueMutation) Value() (r string, exists bool) {
	v := m.value
	if v == nil {
		return
	}
	return *v, true
}

// OldValue returns the old "value" field's value of the UserAttributeValue entity.
// If the UserAttributeValue object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserAttributeValueMutation) OldValue(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldValue is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldValue requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldValue: %w", err)
	}
	return oldValue.Value, nil
}

// ResetValue resets all changes to the "value" field.
func (m *UserAttributeValueMutation) ResetValue() {
	m.value = nil
}

// ClearUser clears the "user" edge to the User entity.
func (m *UserAttributeValueMutation) ClearUser() {
	m.cleareduser = true
	m.clearedFields[userattributevalue.FieldUserID] = struct{}{}
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *UserAttributeValueMutation) UserCleared() bool {
	return m.cleareduser
}

// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *UserAttributeValueMutation) UserIDs() (ids []int64) {
	if id := m.user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetUser resets all changes to the "user" edge.
func (m *UserAttributeValueMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

// SetDefinitionID sets the "definition" edge to the UserAttributeDefinition entity by id.
func (m *UserAttributeValueMutation) SetDefinitionID(id int64) {
	m.definition = &id
}

// ClearDefinition clears the "definition" edge to the UserAttributeDefinition entity.
func (m *UserAttributeValueMutation) ClearDefinition() {
	m.cleareddefinition = true
	m.clearedFields[userattributevalue.FieldAttributeID] = struct{}{}
}

// DefinitionCleared reports if the "definition" edge to the UserAttributeDefinition entity was cleared.
func (m *UserAttributeValueMutation) DefinitionCleared() bool {
	return m.cleareddefinition
}

// DefinitionID returns the "definition" edge ID in the mutation.
func (m *UserAttributeValueMutation) DefinitionID() (id int64, exists bool) {
	if m.definition != nil {
		return *m.definition, true
	}
	return
}

// DefinitionIDs returns the "definition" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// DefinitionID instead. It exists only for internal usage by the builders.
func (m *UserAttributeValueMutation) DefinitionIDs() (ids []int64) {
	if id := m.definition; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetDefinition resets all changes to the "definition" edge.
func (m *UserAttributeValueMutation) ResetDefinition() {
	m.definition = nil
	m.cleareddefinition = false
}

// Where appends a list predicates to the UserAttributeValueMutation builder.
func (m *UserAttributeValueMutation) Where(ps ...predicate.UserAttributeValue) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the UserAttributeValueMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserAttributeValueMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.UserAttributeValue, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *UserAttributeValueMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *UserAttributeValueMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (UserAttributeValue).
func (m *UserAttributeValueMutation) 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 *UserAttributeValueMutation) Fields() []string {
	fields := make([]string, 0, 5)
	if m.created_at != nil {
		fields = append(fields, userattributevalue.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, userattributevalue.FieldUpdatedAt)
	}
	if m.user != nil {
		fields = append(fields, userattributevalue.FieldUserID)
	}
	if m.definition != nil {
		fields = append(fields, userattributevalue.FieldAttributeID)
	}
	if m.value != nil {
		fields = append(fields, userattributevalue.FieldValue)
	}
	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 *UserAttributeValueMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case userattributevalue.FieldCreatedAt:
		return m.CreatedAt()
	case userattributevalue.FieldUpdatedAt:
		return m.UpdatedAt()
	case userattributevalue.FieldUserID:
		return m.UserID()
	case userattributevalue.FieldAttributeID:
		return m.AttributeID()
	case userattributevalue.FieldValue:
		return m.Value()
	}
	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 *UserAttributeValueMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case userattributevalue.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case userattributevalue.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case userattributevalue.FieldUserID:
		return m.OldUserID(ctx)
	case userattributevalue.FieldAttributeID:
		return m.OldAttributeID(ctx)
	case userattributevalue.FieldValue:
		return m.OldValue(ctx)
	}
	return nil, fmt.Errorf("unknown UserAttributeValue 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 *UserAttributeValueMutation) SetField(name string, value ent.Value) error {
	switch name {
	case userattributevalue.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 userattributevalue.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 userattributevalue.FieldUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserID(v)
		return nil
	case userattributevalue.FieldAttributeID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAttributeID(v)
		return nil
	case userattributevalue.FieldValue:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetValue(v)
		return nil
	}
	return fmt.Errorf("unknown UserAttributeValue field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserAttributeValueMutation) AddedFields() []string {
	var fields []string
	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 *UserAttributeValueMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	}
	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 *UserAttributeValueMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown UserAttributeValue numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserAttributeValueMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserAttributeValueMutation) 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 *UserAttributeValueMutation) ClearField(name string) error {
	return fmt.Errorf("unknown UserAttributeValue 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 *UserAttributeValueMutation) ResetField(name string) error {
	switch name {
	case userattributevalue.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case userattributevalue.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case userattributevalue.FieldUserID:
		m.ResetUserID()
		return nil
	case userattributevalue.FieldAttributeID:
		m.ResetAttributeID()
		return nil
	case userattributevalue.FieldValue:
		m.ResetValue()
		return nil
	}
	return fmt.Errorf("unknown UserAttributeValue field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserAttributeValueMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.user != nil {
		edges = append(edges, userattributevalue.EdgeUser)
	}
	if m.definition != nil {
		edges = append(edges, userattributevalue.EdgeDefinition)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserAttributeValueMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case userattributevalue.EdgeUser:
		if id := m.user; id != nil {
			return []ent.Value{*id}
		}
	case userattributevalue.EdgeDefinition:
		if id := m.definition; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserAttributeValueMutation) 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 *UserAttributeValueMutation) RemovedIDs(name string) []ent.Value {
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserAttributeValueMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.cleareduser {
		edges = append(edges, userattributevalue.EdgeUser)
	}
	if m.cleareddefinition {
		edges = append(edges, userattributevalue.EdgeDefinition)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserAttributeValueMutation) EdgeCleared(name string) bool {
	switch name {
	case userattributevalue.EdgeUser:
		return m.cleareduser
	case userattributevalue.EdgeDefinition:
		return m.cleareddefinition
	}
	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 *UserAttributeValueMutation) ClearEdge(name string) error {
	switch name {
	case userattributevalue.EdgeUser:
		m.ClearUser()
		return nil
	case userattributevalue.EdgeDefinition:
		m.ClearDefinition()
		return nil
	}
	return fmt.Errorf("unknown UserAttributeValue 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 *UserAttributeValueMutation) ResetEdge(name string) error {
	switch name {
	case userattributevalue.EdgeUser:
		m.ResetUser()
		return nil
	case userattributevalue.EdgeDefinition:
		m.ResetDefinition()
		return nil
	}
	return fmt.Errorf("unknown UserAttributeValue edge %s", name)
}

// UserSubscriptionMutation represents an operation that mutates the UserSubscription nodes in the graph.
type UserSubscriptionMutation struct {
	config
	op                      Op
	typ                     string
	id                      *int64
	created_at              *time.Time
	updated_at              *time.Time
	deleted_at              *time.Time
	starts_at               *time.Time
	expires_at              *time.Time
	status                  *string
	daily_window_start      *time.Time
	weekly_window_start     *time.Time
	monthly_window_start    *time.Time
	daily_usage_usd         *float64
	adddaily_usage_usd      *float64
	weekly_usage_usd        *float64
	addweekly_usage_usd     *float64
	monthly_usage_usd       *float64
	addmonthly_usage_usd    *float64
	assigned_at             *time.Time
	notes                   *string
	clearedFields           map[string]struct{}
	user                    *int64
	cleareduser             bool
	group                   *int64
	clearedgroup            bool
	assigned_by_user        *int64
	clearedassigned_by_user bool
	usage_logs              map[int64]struct{}
	removedusage_logs       map[int64]struct{}
	clearedusage_logs       bool
	done                    bool
	oldValue                func(context.Context) (*UserSubscription, error)
	predicates              []predicate.UserSubscription
}

var _ ent.Mutation = (*UserSubscriptionMutation)(nil)

// usersubscriptionOption allows management of the mutation configuration using functional options.
type usersubscriptionOption func(*UserSubscriptionMutation)

// newUserSubscriptionMutation creates new mutation for the UserSubscription entity.
func newUserSubscriptionMutation(c config, op Op, opts ...usersubscriptionOption) *UserSubscriptionMutation {
	m := &UserSubscriptionMutation{
		config:        c,
		op:            op,
		typ:           TypeUserSubscription,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withUserSubscriptionID sets the ID field of the mutation.
func withUserSubscriptionID(id int64) usersubscriptionOption {
	return func(m *UserSubscriptionMutation) {
		var (
			err   error
			once  sync.Once
			value *UserSubscription
		)
		m.oldValue = func(ctx context.Context) (*UserSubscription, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().UserSubscription.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withUserSubscription sets the old UserSubscription of the mutation.
func withUserSubscription(node *UserSubscription) usersubscriptionOption {
	return func(m *UserSubscriptionMutation) {
		m.oldValue = func(context.Context) (*UserSubscription, 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 UserSubscriptionMutation) 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 UserSubscriptionMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, 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 *UserSubscriptionMutation) ID() (id int64, 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 *UserSubscriptionMutation) IDs(ctx context.Context) ([]int64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().UserSubscription.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetCreatedAt sets the "created_at" field.
func (m *UserSubscriptionMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}

// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UserSubscriptionMutation) 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 UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) 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 *UserSubscriptionMutation) ResetCreatedAt() {
	m.created_at = nil
}

// SetUpdatedAt sets the "updated_at" field.
func (m *UserSubscriptionMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}

// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *UserSubscriptionMutation) 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 UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) 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 *UserSubscriptionMutation) ResetUpdatedAt() {
	m.updated_at = nil
}

// SetDeletedAt sets the "deleted_at" field.
func (m *UserSubscriptionMutation) SetDeletedAt(t time.Time) {
	m.deleted_at = &t
}

// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *UserSubscriptionMutation) 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 UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) 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 *UserSubscriptionMutation) ClearDeletedAt() {
	m.deleted_at = nil
	m.clearedFields[usersubscription.FieldDeletedAt] = struct{}{}
}

// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *UserSubscriptionMutation) DeletedAtCleared() bool {
	_, ok := m.clearedFields[usersubscription.FieldDeletedAt]
	return ok
}

// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *UserSubscriptionMutation) ResetDeletedAt() {
	m.deleted_at = nil
	delete(m.clearedFields, usersubscription.FieldDeletedAt)
}

// SetUserID sets the "user_id" field.
func (m *UserSubscriptionMutation) SetUserID(i int64) {
	m.user = &i
}

// UserID returns the value of the "user_id" field in the mutation.
func (m *UserSubscriptionMutation) UserID() (r int64, exists bool) {
	v := m.user
	if v == nil {
		return
	}
	return *v, true
}

// OldUserID returns the old "user_id" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldUserID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldUserID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
	}
	return oldValue.UserID, nil
}

// ResetUserID resets all changes to the "user_id" field.
func (m *UserSubscriptionMutation) ResetUserID() {
	m.user = nil
}

// SetGroupID sets the "group_id" field.
func (m *UserSubscriptionMutation) SetGroupID(i int64) {
	m.group = &i
}

// GroupID returns the value of the "group_id" field in the mutation.
func (m *UserSubscriptionMutation) GroupID() (r int64, exists bool) {
	v := m.group
	if v == nil {
		return
	}
	return *v, true
}

// OldGroupID returns the old "group_id" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldGroupID(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldGroupID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldGroupID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldGroupID: %w", err)
	}
	return oldValue.GroupID, nil
}

// ResetGroupID resets all changes to the "group_id" field.
func (m *UserSubscriptionMutation) ResetGroupID() {
	m.group = nil
}

// SetStartsAt sets the "starts_at" field.
func (m *UserSubscriptionMutation) SetStartsAt(t time.Time) {
	m.starts_at = &t
}

// StartsAt returns the value of the "starts_at" field in the mutation.
func (m *UserSubscriptionMutation) StartsAt() (r time.Time, exists bool) {
	v := m.starts_at
	if v == nil {
		return
	}
	return *v, true
}

// OldStartsAt returns the old "starts_at" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldStartsAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldStartsAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldStartsAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldStartsAt: %w", err)
	}
	return oldValue.StartsAt, nil
}

// ResetStartsAt resets all changes to the "starts_at" field.
func (m *UserSubscriptionMutation) ResetStartsAt() {
	m.starts_at = nil
}

// SetExpiresAt sets the "expires_at" field.
func (m *UserSubscriptionMutation) SetExpiresAt(t time.Time) {
	m.expires_at = &t
}

// ExpiresAt returns the value of the "expires_at" field in the mutation.
func (m *UserSubscriptionMutation) ExpiresAt() (r time.Time, exists bool) {
	v := m.expires_at
	if v == nil {
		return
	}
	return *v, true
}

// OldExpiresAt returns the old "expires_at" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldExpiresAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldExpiresAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err)
	}
	return oldValue.ExpiresAt, nil
}

// ResetExpiresAt resets all changes to the "expires_at" field.
func (m *UserSubscriptionMutation) ResetExpiresAt() {
	m.expires_at = nil
}

// SetStatus sets the "status" field.
func (m *UserSubscriptionMutation) SetStatus(s string) {
	m.status = &s
}

// Status returns the value of the "status" field in the mutation.
func (m *UserSubscriptionMutation) Status() (r string, exists bool) {
	v := m.status
	if v == nil {
		return
	}
	return *v, true
}

// OldStatus returns the old "status" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldStatus(ctx context.Context) (v string, 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 *UserSubscriptionMutation) ResetStatus() {
	m.status = nil
}

// SetDailyWindowStart sets the "daily_window_start" field.
func (m *UserSubscriptionMutation) SetDailyWindowStart(t time.Time) {
	m.daily_window_start = &t
}

// DailyWindowStart returns the value of the "daily_window_start" field in the mutation.
func (m *UserSubscriptionMutation) DailyWindowStart() (r time.Time, exists bool) {
	v := m.daily_window_start
	if v == nil {
		return
	}
	return *v, true
}

// OldDailyWindowStart returns the old "daily_window_start" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldDailyWindowStart(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDailyWindowStart is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDailyWindowStart requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDailyWindowStart: %w", err)
	}
	return oldValue.DailyWindowStart, nil
}

// ClearDailyWindowStart clears the value of the "daily_window_start" field.
func (m *UserSubscriptionMutation) ClearDailyWindowStart() {
	m.daily_window_start = nil
	m.clearedFields[usersubscription.FieldDailyWindowStart] = struct{}{}
}

// DailyWindowStartCleared returns if the "daily_window_start" field was cleared in this mutation.
func (m *UserSubscriptionMutation) DailyWindowStartCleared() bool {
	_, ok := m.clearedFields[usersubscription.FieldDailyWindowStart]
	return ok
}

// ResetDailyWindowStart resets all changes to the "daily_window_start" field.
func (m *UserSubscriptionMutation) ResetDailyWindowStart() {
	m.daily_window_start = nil
	delete(m.clearedFields, usersubscription.FieldDailyWindowStart)
}

// SetWeeklyWindowStart sets the "weekly_window_start" field.
func (m *UserSubscriptionMutation) SetWeeklyWindowStart(t time.Time) {
	m.weekly_window_start = &t
}

// WeeklyWindowStart returns the value of the "weekly_window_start" field in the mutation.
func (m *UserSubscriptionMutation) WeeklyWindowStart() (r time.Time, exists bool) {
	v := m.weekly_window_start
	if v == nil {
		return
	}
	return *v, true
}

// OldWeeklyWindowStart returns the old "weekly_window_start" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldWeeklyWindowStart(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWeeklyWindowStart is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWeeklyWindowStart requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWeeklyWindowStart: %w", err)
	}
	return oldValue.WeeklyWindowStart, nil
}

// ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
func (m *UserSubscriptionMutation) ClearWeeklyWindowStart() {
	m.weekly_window_start = nil
	m.clearedFields[usersubscription.FieldWeeklyWindowStart] = struct{}{}
}

// WeeklyWindowStartCleared returns if the "weekly_window_start" field was cleared in this mutation.
func (m *UserSubscriptionMutation) WeeklyWindowStartCleared() bool {
	_, ok := m.clearedFields[usersubscription.FieldWeeklyWindowStart]
	return ok
}

// ResetWeeklyWindowStart resets all changes to the "weekly_window_start" field.
func (m *UserSubscriptionMutation) ResetWeeklyWindowStart() {
	m.weekly_window_start = nil
	delete(m.clearedFields, usersubscription.FieldWeeklyWindowStart)
}

// SetMonthlyWindowStart sets the "monthly_window_start" field.
func (m *UserSubscriptionMutation) SetMonthlyWindowStart(t time.Time) {
	m.monthly_window_start = &t
}

// MonthlyWindowStart returns the value of the "monthly_window_start" field in the mutation.
func (m *UserSubscriptionMutation) MonthlyWindowStart() (r time.Time, exists bool) {
	v := m.monthly_window_start
	if v == nil {
		return
	}
	return *v, true
}

// OldMonthlyWindowStart returns the old "monthly_window_start" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldMonthlyWindowStart(ctx context.Context) (v *time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldMonthlyWindowStart is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldMonthlyWindowStart requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldMonthlyWindowStart: %w", err)
	}
	return oldValue.MonthlyWindowStart, nil
}

// ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
func (m *UserSubscriptionMutation) ClearMonthlyWindowStart() {
	m.monthly_window_start = nil
	m.clearedFields[usersubscription.FieldMonthlyWindowStart] = struct{}{}
}

// MonthlyWindowStartCleared returns if the "monthly_window_start" field was cleared in this mutation.
func (m *UserSubscriptionMutation) MonthlyWindowStartCleared() bool {
	_, ok := m.clearedFields[usersubscription.FieldMonthlyWindowStart]
	return ok
}

// ResetMonthlyWindowStart resets all changes to the "monthly_window_start" field.
func (m *UserSubscriptionMutation) ResetMonthlyWindowStart() {
	m.monthly_window_start = nil
	delete(m.clearedFields, usersubscription.FieldMonthlyWindowStart)
}

// SetDailyUsageUsd sets the "daily_usage_usd" field.
func (m *UserSubscriptionMutation) SetDailyUsageUsd(f float64) {
	m.daily_usage_usd = &f
	m.adddaily_usage_usd = nil
}

// DailyUsageUsd returns the value of the "daily_usage_usd" field in the mutation.
func (m *UserSubscriptionMutation) DailyUsageUsd() (r float64, exists bool) {
	v := m.daily_usage_usd
	if v == nil {
		return
	}
	return *v, true
}

// OldDailyUsageUsd returns the old "daily_usage_usd" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldDailyUsageUsd(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDailyUsageUsd is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDailyUsageUsd requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDailyUsageUsd: %w", err)
	}
	return oldValue.DailyUsageUsd, nil
}

// AddDailyUsageUsd adds f to the "daily_usage_usd" field.
func (m *UserSubscriptionMutation) AddDailyUsageUsd(f float64) {
	if m.adddaily_usage_usd != nil {
		*m.adddaily_usage_usd += f
	} else {
		m.adddaily_usage_usd = &f
	}
}

// AddedDailyUsageUsd returns the value that was added to the "daily_usage_usd" field in this mutation.
func (m *UserSubscriptionMutation) AddedDailyUsageUsd() (r float64, exists bool) {
	v := m.adddaily_usage_usd
	if v == nil {
		return
	}
	return *v, true
}

// ResetDailyUsageUsd resets all changes to the "daily_usage_usd" field.
func (m *UserSubscriptionMutation) ResetDailyUsageUsd() {
	m.daily_usage_usd = nil
	m.adddaily_usage_usd = nil
}

// SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
func (m *UserSubscriptionMutation) SetWeeklyUsageUsd(f float64) {
	m.weekly_usage_usd = &f
	m.addweekly_usage_usd = nil
}

// WeeklyUsageUsd returns the value of the "weekly_usage_usd" field in the mutation.
func (m *UserSubscriptionMutation) WeeklyUsageUsd() (r float64, exists bool) {
	v := m.weekly_usage_usd
	if v == nil {
		return
	}
	return *v, true
}

// OldWeeklyUsageUsd returns the old "weekly_usage_usd" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldWeeklyUsageUsd(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldWeeklyUsageUsd is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldWeeklyUsageUsd requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldWeeklyUsageUsd: %w", err)
	}
	return oldValue.WeeklyUsageUsd, nil
}

// AddWeeklyUsageUsd adds f to the "weekly_usage_usd" field.
func (m *UserSubscriptionMutation) AddWeeklyUsageUsd(f float64) {
	if m.addweekly_usage_usd != nil {
		*m.addweekly_usage_usd += f
	} else {
		m.addweekly_usage_usd = &f
	}
}

// AddedWeeklyUsageUsd returns the value that was added to the "weekly_usage_usd" field in this mutation.
func (m *UserSubscriptionMutation) AddedWeeklyUsageUsd() (r float64, exists bool) {
	v := m.addweekly_usage_usd
	if v == nil {
		return
	}
	return *v, true
}

// ResetWeeklyUsageUsd resets all changes to the "weekly_usage_usd" field.
func (m *UserSubscriptionMutation) ResetWeeklyUsageUsd() {
	m.weekly_usage_usd = nil
	m.addweekly_usage_usd = nil
}

// SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
func (m *UserSubscriptionMutation) SetMonthlyUsageUsd(f float64) {
	m.monthly_usage_usd = &f
	m.addmonthly_usage_usd = nil
}

// MonthlyUsageUsd returns the value of the "monthly_usage_usd" field in the mutation.
func (m *UserSubscriptionMutation) MonthlyUsageUsd() (r float64, exists bool) {
	v := m.monthly_usage_usd
	if v == nil {
		return
	}
	return *v, true
}

// OldMonthlyUsageUsd returns the old "monthly_usage_usd" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldMonthlyUsageUsd(ctx context.Context) (v float64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldMonthlyUsageUsd is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldMonthlyUsageUsd requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldMonthlyUsageUsd: %w", err)
	}
	return oldValue.MonthlyUsageUsd, nil
}

// AddMonthlyUsageUsd adds f to the "monthly_usage_usd" field.
func (m *UserSubscriptionMutation) AddMonthlyUsageUsd(f float64) {
	if m.addmonthly_usage_usd != nil {
		*m.addmonthly_usage_usd += f
	} else {
		m.addmonthly_usage_usd = &f
	}
}

// AddedMonthlyUsageUsd returns the value that was added to the "monthly_usage_usd" field in this mutation.
func (m *UserSubscriptionMutation) AddedMonthlyUsageUsd() (r float64, exists bool) {
	v := m.addmonthly_usage_usd
	if v == nil {
		return
	}
	return *v, true
}

// ResetMonthlyUsageUsd resets all changes to the "monthly_usage_usd" field.
func (m *UserSubscriptionMutation) ResetMonthlyUsageUsd() {
	m.monthly_usage_usd = nil
	m.addmonthly_usage_usd = nil
}

// SetAssignedBy sets the "assigned_by" field.
func (m *UserSubscriptionMutation) SetAssignedBy(i int64) {
	m.assigned_by_user = &i
}

// AssignedBy returns the value of the "assigned_by" field in the mutation.
func (m *UserSubscriptionMutation) AssignedBy() (r int64, exists bool) {
	v := m.assigned_by_user
	if v == nil {
		return
	}
	return *v, true
}

// OldAssignedBy returns the old "assigned_by" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldAssignedBy(ctx context.Context) (v *int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAssignedBy is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAssignedBy requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAssignedBy: %w", err)
	}
	return oldValue.AssignedBy, nil
}

// ClearAssignedBy clears the value of the "assigned_by" field.
func (m *UserSubscriptionMutation) ClearAssignedBy() {
	m.assigned_by_user = nil
	m.clearedFields[usersubscription.FieldAssignedBy] = struct{}{}
}

// AssignedByCleared returns if the "assigned_by" field was cleared in this mutation.
func (m *UserSubscriptionMutation) AssignedByCleared() bool {
	_, ok := m.clearedFields[usersubscription.FieldAssignedBy]
	return ok
}

// ResetAssignedBy resets all changes to the "assigned_by" field.
func (m *UserSubscriptionMutation) ResetAssignedBy() {
	m.assigned_by_user = nil
	delete(m.clearedFields, usersubscription.FieldAssignedBy)
}

// SetAssignedAt sets the "assigned_at" field.
func (m *UserSubscriptionMutation) SetAssignedAt(t time.Time) {
	m.assigned_at = &t
}

// AssignedAt returns the value of the "assigned_at" field in the mutation.
func (m *UserSubscriptionMutation) AssignedAt() (r time.Time, exists bool) {
	v := m.assigned_at
	if v == nil {
		return
	}
	return *v, true
}

// OldAssignedAt returns the old "assigned_at" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldAssignedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAssignedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAssignedAt requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAssignedAt: %w", err)
	}
	return oldValue.AssignedAt, nil
}

// ResetAssignedAt resets all changes to the "assigned_at" field.
func (m *UserSubscriptionMutation) ResetAssignedAt() {
	m.assigned_at = nil
}

// SetNotes sets the "notes" field.
func (m *UserSubscriptionMutation) SetNotes(s string) {
	m.notes = &s
}

// Notes returns the value of the "notes" field in the mutation.
func (m *UserSubscriptionMutation) Notes() (r string, exists bool) {
	v := m.notes
	if v == nil {
		return
	}
	return *v, true
}

// OldNotes returns the old "notes" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldNotes(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldNotes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldNotes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldNotes: %w", err)
	}
	return oldValue.Notes, nil
}

// ClearNotes clears the value of the "notes" field.
func (m *UserSubscriptionMutation) ClearNotes() {
	m.notes = nil
	m.clearedFields[usersubscription.FieldNotes] = struct{}{}
}

// NotesCleared returns if the "notes" field was cleared in this mutation.
func (m *UserSubscriptionMutation) NotesCleared() bool {
	_, ok := m.clearedFields[usersubscription.FieldNotes]
	return ok
}

// ResetNotes resets all changes to the "notes" field.
func (m *UserSubscriptionMutation) ResetNotes() {
	m.notes = nil
	delete(m.clearedFields, usersubscription.FieldNotes)
}

// ClearUser clears the "user" edge to the User entity.
func (m *UserSubscriptionMutation) ClearUser() {
	m.cleareduser = true
	m.clearedFields[usersubscription.FieldUserID] = struct{}{}
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *UserSubscriptionMutation) UserCleared() bool {
	return m.cleareduser
}

// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *UserSubscriptionMutation) UserIDs() (ids []int64) {
	if id := m.user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetUser resets all changes to the "user" edge.
func (m *UserSubscriptionMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

// ClearGroup clears the "group" edge to the Group entity.
func (m *UserSubscriptionMutation) ClearGroup() {
	m.clearedgroup = true
	m.clearedFields[usersubscription.FieldGroupID] = struct{}{}
}

// GroupCleared reports if the "group" edge to the Group entity was cleared.
func (m *UserSubscriptionMutation) GroupCleared() bool {
	return m.clearedgroup
}

// GroupIDs returns the "group" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// GroupID instead. It exists only for internal usage by the builders.
func (m *UserSubscriptionMutation) GroupIDs() (ids []int64) {
	if id := m.group; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetGroup resets all changes to the "group" edge.
func (m *UserSubscriptionMutation) ResetGroup() {
	m.group = nil
	m.clearedgroup = false
}

// SetAssignedByUserID sets the "assigned_by_user" edge to the User entity by id.
func (m *UserSubscriptionMutation) SetAssignedByUserID(id int64) {
	m.assigned_by_user = &id
}

// ClearAssignedByUser clears the "assigned_by_user" edge to the User entity.
func (m *UserSubscriptionMutation) ClearAssignedByUser() {
	m.clearedassigned_by_user = true
	m.clearedFields[usersubscription.FieldAssignedBy] = struct{}{}
}

// AssignedByUserCleared reports if the "assigned_by_user" edge to the User entity was cleared.
func (m *UserSubscriptionMutation) AssignedByUserCleared() bool {
	return m.AssignedByCleared() || m.clearedassigned_by_user
}

// AssignedByUserID returns the "assigned_by_user" edge ID in the mutation.
func (m *UserSubscriptionMutation) AssignedByUserID() (id int64, exists bool) {
	if m.assigned_by_user != nil {
		return *m.assigned_by_user, true
	}
	return
}

// AssignedByUserIDs returns the "assigned_by_user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// AssignedByUserID instead. It exists only for internal usage by the builders.
func (m *UserSubscriptionMutation) AssignedByUserIDs() (ids []int64) {
	if id := m.assigned_by_user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetAssignedByUser resets all changes to the "assigned_by_user" edge.
func (m *UserSubscriptionMutation) ResetAssignedByUser() {
	m.assigned_by_user = nil
	m.clearedassigned_by_user = false
}

// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by ids.
func (m *UserSubscriptionMutation) AddUsageLogIDs(ids ...int64) {
	if m.usage_logs == nil {
		m.usage_logs = make(map[int64]struct{})
	}
	for i := range ids {
		m.usage_logs[ids[i]] = struct{}{}
	}
}

// ClearUsageLogs clears the "usage_logs" edge to the UsageLog entity.
func (m *UserSubscriptionMutation) ClearUsageLogs() {
	m.clearedusage_logs = true
}

// UsageLogsCleared reports if the "usage_logs" edge to the UsageLog entity was cleared.
func (m *UserSubscriptionMutation) UsageLogsCleared() bool {
	return m.clearedusage_logs
}

// RemoveUsageLogIDs removes the "usage_logs" edge to the UsageLog entity by IDs.
func (m *UserSubscriptionMutation) RemoveUsageLogIDs(ids ...int64) {
	if m.removedusage_logs == nil {
		m.removedusage_logs = make(map[int64]struct{})
	}
	for i := range ids {
		delete(m.usage_logs, ids[i])
		m.removedusage_logs[ids[i]] = struct{}{}
	}
}

// RemovedUsageLogs returns the removed IDs of the "usage_logs" edge to the UsageLog entity.
func (m *UserSubscriptionMutation) RemovedUsageLogsIDs() (ids []int64) {
	for id := range m.removedusage_logs {
		ids = append(ids, id)
	}
	return
}

// UsageLogsIDs returns the "usage_logs" edge IDs in the mutation.
func (m *UserSubscriptionMutation) UsageLogsIDs() (ids []int64) {
	for id := range m.usage_logs {
		ids = append(ids, id)
	}
	return
}

// ResetUsageLogs resets all changes to the "usage_logs" edge.
func (m *UserSubscriptionMutation) ResetUsageLogs() {
	m.usage_logs = nil
	m.clearedusage_logs = false
	m.removedusage_logs = nil
}

// Where appends a list predicates to the UserSubscriptionMutation builder.
func (m *UserSubscriptionMutation) Where(ps ...predicate.UserSubscription) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the UserSubscriptionMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserSubscriptionMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.UserSubscription, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *UserSubscriptionMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *UserSubscriptionMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (UserSubscription).
func (m *UserSubscriptionMutation) 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 *UserSubscriptionMutation) Fields() []string {
	fields := make([]string, 0, 17)
	if m.created_at != nil {
		fields = append(fields, usersubscription.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, usersubscription.FieldUpdatedAt)
	}
	if m.deleted_at != nil {
		fields = append(fields, usersubscription.FieldDeletedAt)
	}
	if m.user != nil {
		fields = append(fields, usersubscription.FieldUserID)
	}
	if m.group != nil {
		fields = append(fields, usersubscription.FieldGroupID)
	}
	if m.starts_at != nil {
		fields = append(fields, usersubscription.FieldStartsAt)
	}
	if m.expires_at != nil {
		fields = append(fields, usersubscription.FieldExpiresAt)
	}
	if m.status != nil {
		fields = append(fields, usersubscription.FieldStatus)
	}
	if m.daily_window_start != nil {
		fields = append(fields, usersubscription.FieldDailyWindowStart)
	}
	if m.weekly_window_start != nil {
		fields = append(fields, usersubscription.FieldWeeklyWindowStart)
	}
	if m.monthly_window_start != nil {
		fields = append(fields, usersubscription.FieldMonthlyWindowStart)
	}
	if m.daily_usage_usd != nil {
		fields = append(fields, usersubscription.FieldDailyUsageUsd)
	}
	if m.weekly_usage_usd != nil {
		fields = append(fields, usersubscription.FieldWeeklyUsageUsd)
	}
	if m.monthly_usage_usd != nil {
		fields = append(fields, usersubscription.FieldMonthlyUsageUsd)
	}
	if m.assigned_by_user != nil {
		fields = append(fields, usersubscription.FieldAssignedBy)
	}
	if m.assigned_at != nil {
		fields = append(fields, usersubscription.FieldAssignedAt)
	}
	if m.notes != nil {
		fields = append(fields, usersubscription.FieldNotes)
	}
	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 *UserSubscriptionMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case usersubscription.FieldCreatedAt:
		return m.CreatedAt()
	case usersubscription.FieldUpdatedAt:
		return m.UpdatedAt()
	case usersubscription.FieldDeletedAt:
		return m.DeletedAt()
	case usersubscription.FieldUserID:
		return m.UserID()
	case usersubscription.FieldGroupID:
		return m.GroupID()
	case usersubscription.FieldStartsAt:
		return m.StartsAt()
	case usersubscription.FieldExpiresAt:
		return m.ExpiresAt()
	case usersubscription.FieldStatus:
		return m.Status()
	case usersubscription.FieldDailyWindowStart:
		return m.DailyWindowStart()
	case usersubscription.FieldWeeklyWindowStart:
		return m.WeeklyWindowStart()
	case usersubscription.FieldMonthlyWindowStart:
		return m.MonthlyWindowStart()
	case usersubscription.FieldDailyUsageUsd:
		return m.DailyUsageUsd()
	case usersubscription.FieldWeeklyUsageUsd:
		return m.WeeklyUsageUsd()
	case usersubscription.FieldMonthlyUsageUsd:
		return m.MonthlyUsageUsd()
	case usersubscription.FieldAssignedBy:
		return m.AssignedBy()
	case usersubscription.FieldAssignedAt:
		return m.AssignedAt()
	case usersubscription.FieldNotes:
		return m.Notes()
	}
	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 *UserSubscriptionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case usersubscription.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case usersubscription.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	case usersubscription.FieldDeletedAt:
		return m.OldDeletedAt(ctx)
	case usersubscription.FieldUserID:
		return m.OldUserID(ctx)
	case usersubscription.FieldGroupID:
		return m.OldGroupID(ctx)
	case usersubscription.FieldStartsAt:
		return m.OldStartsAt(ctx)
	case usersubscription.FieldExpiresAt:
		return m.OldExpiresAt(ctx)
	case usersubscription.FieldStatus:
		return m.OldStatus(ctx)
	case usersubscription.FieldDailyWindowStart:
		return m.OldDailyWindowStart(ctx)
	case usersubscription.FieldWeeklyWindowStart:
		return m.OldWeeklyWindowStart(ctx)
	case usersubscription.FieldMonthlyWindowStart:
		return m.OldMonthlyWindowStart(ctx)
	case usersubscription.FieldDailyUsageUsd:
		return m.OldDailyUsageUsd(ctx)
	case usersubscription.FieldWeeklyUsageUsd:
		return m.OldWeeklyUsageUsd(ctx)
	case usersubscription.FieldMonthlyUsageUsd:
		return m.OldMonthlyUsageUsd(ctx)
	case usersubscription.FieldAssignedBy:
		return m.OldAssignedBy(ctx)
	case usersubscription.FieldAssignedAt:
		return m.OldAssignedAt(ctx)
	case usersubscription.FieldNotes:
		return m.OldNotes(ctx)
	}
	return nil, fmt.Errorf("unknown UserSubscription 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 *UserSubscriptionMutation) SetField(name string, value ent.Value) error {
	switch name {
	case usersubscription.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 usersubscription.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 usersubscription.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 usersubscription.FieldUserID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetUserID(v)
		return nil
	case usersubscription.FieldGroupID:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetGroupID(v)
		return nil
	case usersubscription.FieldStartsAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStartsAt(v)
		return nil
	case usersubscription.FieldExpiresAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetExpiresAt(v)
		return nil
	case usersubscription.FieldStatus:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetStatus(v)
		return nil
	case usersubscription.FieldDailyWindowStart:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDailyWindowStart(v)
		return nil
	case usersubscription.FieldWeeklyWindowStart:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWeeklyWindowStart(v)
		return nil
	case usersubscription.FieldMonthlyWindowStart:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMonthlyWindowStart(v)
		return nil
	case usersubscription.FieldDailyUsageUsd:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDailyUsageUsd(v)
		return nil
	case usersubscription.FieldWeeklyUsageUsd:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetWeeklyUsageUsd(v)
		return nil
	case usersubscription.FieldMonthlyUsageUsd:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMonthlyUsageUsd(v)
		return nil
	case usersubscription.FieldAssignedBy:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAssignedBy(v)
		return nil
	case usersubscription.FieldAssignedAt:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAssignedAt(v)
		return nil
	case usersubscription.FieldNotes:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetNotes(v)
		return nil
	}
	return fmt.Errorf("unknown UserSubscription field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserSubscriptionMutation) AddedFields() []string {
	var fields []string
	if m.adddaily_usage_usd != nil {
		fields = append(fields, usersubscription.FieldDailyUsageUsd)
	}
	if m.addweekly_usage_usd != nil {
		fields = append(fields, usersubscription.FieldWeeklyUsageUsd)
	}
	if m.addmonthly_usage_usd != nil {
		fields = append(fields, usersubscription.FieldMonthlyUsageUsd)
	}
	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 *UserSubscriptionMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case usersubscription.FieldDailyUsageUsd:
		return m.AddedDailyUsageUsd()
	case usersubscription.FieldWeeklyUsageUsd:
		return m.AddedWeeklyUsageUsd()
	case usersubscription.FieldMonthlyUsageUsd:
		return m.AddedMonthlyUsageUsd()
	}
	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 *UserSubscriptionMutation) AddField(name string, value ent.Value) error {
	switch name {
	case usersubscription.FieldDailyUsageUsd:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddDailyUsageUsd(v)
		return nil
	case usersubscription.FieldWeeklyUsageUsd:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddWeeklyUsageUsd(v)
		return nil
	case usersubscription.FieldMonthlyUsageUsd:
		v, ok := value.(float64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddMonthlyUsageUsd(v)
		return nil
	}
	return fmt.Errorf("unknown UserSubscription numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserSubscriptionMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(usersubscription.FieldDeletedAt) {
		fields = append(fields, usersubscription.FieldDeletedAt)
	}
	if m.FieldCleared(usersubscription.FieldDailyWindowStart) {
		fields = append(fields, usersubscription.FieldDailyWindowStart)
	}
	if m.FieldCleared(usersubscription.FieldWeeklyWindowStart) {
		fields = append(fields, usersubscription.FieldWeeklyWindowStart)
	}
	if m.FieldCleared(usersubscription.FieldMonthlyWindowStart) {
		fields = append(fields, usersubscription.FieldMonthlyWindowStart)
	}
	if m.FieldCleared(usersubscription.FieldAssignedBy) {
		fields = append(fields, usersubscription.FieldAssignedBy)
	}
	if m.FieldCleared(usersubscription.FieldNotes) {
		fields = append(fields, usersubscription.FieldNotes)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserSubscriptionMutation) 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 *UserSubscriptionMutation) ClearField(name string) error {
	switch name {
	case usersubscription.FieldDeletedAt:
		m.ClearDeletedAt()
		return nil
	case usersubscription.FieldDailyWindowStart:
		m.ClearDailyWindowStart()
		return nil
	case usersubscription.FieldWeeklyWindowStart:
		m.ClearWeeklyWindowStart()
		return nil
	case usersubscription.FieldMonthlyWindowStart:
		m.ClearMonthlyWindowStart()
		return nil
	case usersubscription.FieldAssignedBy:
		m.ClearAssignedBy()
		return nil
	case usersubscription.FieldNotes:
		m.ClearNotes()
		return nil
	}
	return fmt.Errorf("unknown UserSubscription 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 *UserSubscriptionMutation) ResetField(name string) error {
	switch name {
	case usersubscription.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case usersubscription.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	case usersubscription.FieldDeletedAt:
		m.ResetDeletedAt()
		return nil
	case usersubscription.FieldUserID:
		m.ResetUserID()
		return nil
	case usersubscription.FieldGroupID:
		m.ResetGroupID()
		return nil
	case usersubscription.FieldStartsAt:
		m.ResetStartsAt()
		return nil
	case usersubscription.FieldExpiresAt:
		m.ResetExpiresAt()
		return nil
	case usersubscription.FieldStatus:
		m.ResetStatus()
		return nil
	case usersubscription.FieldDailyWindowStart:
		m.ResetDailyWindowStart()
		return nil
	case usersubscription.FieldWeeklyWindowStart:
		m.ResetWeeklyWindowStart()
		return nil
	case usersubscription.FieldMonthlyWindowStart:
		m.ResetMonthlyWindowStart()
		return nil
	case usersubscription.FieldDailyUsageUsd:
		m.ResetDailyUsageUsd()
		return nil
	case usersubscription.FieldWeeklyUsageUsd:
		m.ResetWeeklyUsageUsd()
		return nil
	case usersubscription.FieldMonthlyUsageUsd:
		m.ResetMonthlyUsageUsd()
		return nil
	case usersubscription.FieldAssignedBy:
		m.ResetAssignedBy()
		return nil
	case usersubscription.FieldAssignedAt:
		m.ResetAssignedAt()
		return nil
	case usersubscription.FieldNotes:
		m.ResetNotes()
		return nil
	}
	return fmt.Errorf("unknown UserSubscription field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserSubscriptionMutation) AddedEdges() []string {
	edges := make([]string, 0, 4)
	if m.user != nil {
		edges = append(edges, usersubscription.EdgeUser)
	}
	if m.group != nil {
		edges = append(edges, usersubscription.EdgeGroup)
	}
	if m.assigned_by_user != nil {
		edges = append(edges, usersubscription.EdgeAssignedByUser)
	}
	if m.usage_logs != nil {
		edges = append(edges, usersubscription.EdgeUsageLogs)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserSubscriptionMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case usersubscription.EdgeUser:
		if id := m.user; id != nil {
			return []ent.Value{*id}
		}
	case usersubscription.EdgeGroup:
		if id := m.group; id != nil {
			return []ent.Value{*id}
		}
	case usersubscription.EdgeAssignedByUser:
		if id := m.assigned_by_user; id != nil {
			return []ent.Value{*id}
		}
	case usersubscription.EdgeUsageLogs:
		ids := make([]ent.Value, 0, len(m.usage_logs))
		for id := range m.usage_logs {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserSubscriptionMutation) RemovedEdges() []string {
	edges := make([]string, 0, 4)
	if m.removedusage_logs != nil {
		edges = append(edges, usersubscription.EdgeUsageLogs)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UserSubscriptionMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case usersubscription.EdgeUsageLogs:
		ids := make([]ent.Value, 0, len(m.removedusage_logs))
		for id := range m.removedusage_logs {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserSubscriptionMutation) ClearedEdges() []string {
	edges := make([]string, 0, 4)
	if m.cleareduser {
		edges = append(edges, usersubscription.EdgeUser)
	}
	if m.clearedgroup {
		edges = append(edges, usersubscription.EdgeGroup)
	}
	if m.clearedassigned_by_user {
		edges = append(edges, usersubscription.EdgeAssignedByUser)
	}
	if m.clearedusage_logs {
		edges = append(edges, usersubscription.EdgeUsageLogs)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserSubscriptionMutation) EdgeCleared(name string) bool {
	switch name {
	case usersubscription.EdgeUser:
		return m.cleareduser
	case usersubscription.EdgeGroup:
		return m.clearedgroup
	case usersubscription.EdgeAssignedByUser:
		return m.clearedassigned_by_user
	case usersubscription.EdgeUsageLogs:
		return m.clearedusage_logs
	}
	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 *UserSubscriptionMutation) ClearEdge(name string) error {
	switch name {
	case usersubscription.EdgeUser:
		m.ClearUser()
		return nil
	case usersubscription.EdgeGroup:
		m.ClearGroup()
		return nil
	case usersubscription.EdgeAssignedByUser:
		m.ClearAssignedByUser()
		return nil
	}
	return fmt.Errorf("unknown UserSubscription 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 *UserSubscriptionMutation) ResetEdge(name string) error {
	switch name {
	case usersubscription.EdgeUser:
		m.ResetUser()
		return nil
	case usersubscription.EdgeGroup:
		m.ResetGroup()
		return nil
	case usersubscription.EdgeAssignedByUser:
		m.ResetAssignedByUser()
		return nil
	case usersubscription.EdgeUsageLogs:
		m.ResetUsageLogs()
		return nil
	}
	return fmt.Errorf("unknown UserSubscription edge %s", name)
}
