func (m *CardMutation) ResetCreatedAt() {
	m.created_at = nil
}
ResetCreatedAt resets all changes to the "created_at" field.
package ent
import (
	"context"
	"fmt"
	"sync"
	"time"
	"github.com/go-kratos/beer-shop/app/user/service/internal/data/ent/address"
	"github.com/go-kratos/beer-shop/app/user/service/internal/data/ent/card"
	"github.com/go-kratos/beer-shop/app/user/service/internal/data/ent/predicate"
	"github.com/go-kratos/beer-shop/app/user/service/internal/data/ent/user"
	"entgo.io/ent"
)
const (
	OpCreate    = ent.OpCreate
	OpDelete    = ent.OpDelete
	OpDeleteOne = ent.OpDeleteOne
	OpUpdate    = ent.OpUpdate
	OpUpdateOne = ent.OpUpdateOne
	TypeAddress = "Address"
	TypeCard    = "Card"
	TypeUser    = "User"
)
type AddressMutation struct {
	config
	op            Op
	typ           string
	id            *int64
	name          *string
	mobile        *string
	address       *string
	post_code     *string
	created_at    *time.Time
	updated_at    *time.Time
	clearedFields map[string]struct{}
	user          *int64
	cleareduser   bool
	done          bool
	oldValue      func(context.Context) (*Address, error)
	predicates    []predicate.Address
}
var _ ent.Mutation = (*AddressMutation)(nil)
type addressOption func(*AddressMutation)
func newAddressMutation(c config, op Op, opts ...addressOption) *AddressMutation {
	m := &AddressMutation{
		config:        c,
		op:            op,
		typ:           TypeAddress,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}
func withAddressID(id int64) addressOption {
	return func(m *AddressMutation) {
		var (
			err   error
			once  sync.Once
			value *Address
		)
		m.oldValue = func(ctx context.Context) (*Address, error) {
			once.Do(func() {
				if m.done {
					err = fmt.Errorf("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Address.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}
func withAddress(node *Address) addressOption {
	return func(m *AddressMutation) {
		m.oldValue = func(context.Context) (*Address, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}
func (m AddressMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}
func (m AddressMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, fmt.Errorf("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}
func (m *AddressMutation) SetID(id int64) {
	m.id = &id
}
func (m *AddressMutation) ID() (id int64, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}
func (m *AddressMutation) SetName(s string) {
	m.name = &s
}
func (m *AddressMutation) Name() (r string, exists bool) {
	v := m.name
	if v == nil {
		return
	}
	return *v, true
}
func (m *AddressMutation) OldName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("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
}
func (m *AddressMutation) ResetName() {
	m.name = nil
}
func (m *AddressMutation) SetMobile(s string) {
	m.mobile = &s
}
func (m *AddressMutation) Mobile() (r string, exists bool) {
	v := m.mobile
	if v == nil {
		return
	}
	return *v, true
}
func (m *AddressMutation) OldMobile(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldMobile is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldMobile requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldMobile: %w", err)
	}
	return oldValue.Mobile, nil
}
func (m *AddressMutation) ResetMobile() {
	m.mobile = nil
}
func (m *AddressMutation) SetAddress(s string) {
	m.address = &s
}
func (m *AddressMutation) Address() (r string, exists bool) {
	v := m.address
	if v == nil {
		return
	}
	return *v, true
}
func (m *AddressMutation) OldAddress(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldAddress is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldAddress requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAddress: %w", err)
	}
	return oldValue.Address, nil
}
func (m *AddressMutation) ResetAddress() {
	m.address = nil
}
func (m *AddressMutation) SetPostCode(s string) {
	m.post_code = &s
}
func (m *AddressMutation) PostCode() (r string, exists bool) {
	v := m.post_code
	if v == nil {
		return
	}
	return *v, true
}
func (m *AddressMutation) OldPostCode(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldPostCode is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldPostCode requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldPostCode: %w", err)
	}
	return oldValue.PostCode, nil
}
func (m *AddressMutation) ResetPostCode() {
	m.post_code = nil
}
func (m *AddressMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}
func (m *AddressMutation) CreatedAt() (r time.Time, exists bool) {
	v := m.created_at
	if v == nil {
		return
	}
	return *v, true
}
func (m *AddressMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("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
}
func (m *AddressMutation) ResetCreatedAt() {
	m.created_at = nil
}
func (m *AddressMutation) SetUpdatedAt(t time.Time) {
	m.updated_at = &t
}
func (m *AddressMutation) UpdatedAt() (r time.Time, exists bool) {
	v := m.updated_at
	if v == nil {
		return
	}
	return *v, true
}
func (m *AddressMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("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
}
func (m *AddressMutation) ResetUpdatedAt() {
	m.updated_at = nil
}
func (m *AddressMutation) SetUserID(id int64) {
	m.user = &id
}
func (m *AddressMutation) ClearUser() {
	m.cleareduser = true
}
func (m *AddressMutation) UserCleared() bool {
	return m.cleareduser
}
func (m *AddressMutation) UserID() (id int64, exists bool) {
	if m.user != nil {
		return *m.user, true
	}
	return
}
func (m *AddressMutation) UserIDs() (ids []int64) {
	if id := m.user; id != nil {
		ids = append(ids, *id)
	}
	return
}
func (m *AddressMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}
func (m *AddressMutation) Op() Op {
	return m.op
}
func (m *AddressMutation) Type() string {
	return m.typ
}
func (m *AddressMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.name != nil {
		fields = append(fields, address.FieldName)
	}
	if m.mobile != nil {
		fields = append(fields, address.FieldMobile)
	}
	if m.address != nil {
		fields = append(fields, address.FieldAddress)
	}
	if m.post_code != nil {
		fields = append(fields, address.FieldPostCode)
	}
	if m.created_at != nil {
		fields = append(fields, address.FieldCreatedAt)
	}
	if m.updated_at != nil {
		fields = append(fields, address.FieldUpdatedAt)
	}
	return fields
}
func (m *AddressMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case address.FieldName:
		return m.Name()
	case address.FieldMobile:
		return m.Mobile()
	case address.FieldAddress:
		return m.Address()
	case address.FieldPostCode:
		return m.PostCode()
	case address.FieldCreatedAt:
		return m.CreatedAt()
	case address.FieldUpdatedAt:
		return m.UpdatedAt()
	}
	return nil, false
}
func (m *AddressMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case address.FieldName:
		return m.OldName(ctx)
	case address.FieldMobile:
		return m.OldMobile(ctx)
	case address.FieldAddress:
		return m.OldAddress(ctx)
	case address.FieldPostCode:
		return m.OldPostCode(ctx)
	case address.FieldCreatedAt:
		return m.OldCreatedAt(ctx)
	case address.FieldUpdatedAt:
		return m.OldUpdatedAt(ctx)
	}
	return nil, fmt.Errorf("unknown Address field %s", name)
}
func (m *AddressMutation) SetField(name string, value ent.Value) error {
	switch name {
	case address.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case address.FieldMobile:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMobile(v)
		return nil
	case address.FieldAddress:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAddress(v)
		return nil
	case address.FieldPostCode:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetPostCode(v)
		return nil
	case address.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 address.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 Address field %s", name)
}
func (m *AddressMutation) AddedFields() []string {
	return nil
}
func (m *AddressMutation) AddedField(name string) (ent.Value, bool) {
	return nil, false
}
func (m *AddressMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown Address numeric field %s", name)
}
func (m *AddressMutation) ClearedFields() []string {
	return nil
}
func (m *AddressMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}
func (m *AddressMutation) ClearField(name string) error {
	return fmt.Errorf("unknown Address nullable field %s", name)
}
func (m *AddressMutation) ResetField(name string) error {
	switch name {
	case address.FieldName:
		m.ResetName()
		return nil
	case address.FieldMobile:
		m.ResetMobile()
		return nil
	case address.FieldAddress:
		m.ResetAddress()
		return nil
	case address.FieldPostCode:
		m.ResetPostCode()
		return nil
	case address.FieldCreatedAt:
		m.ResetCreatedAt()
		return nil
	case address.FieldUpdatedAt:
		m.ResetUpdatedAt()
		return nil
	}
	return fmt.Errorf("unknown Address field %s", name)
}
func (m *AddressMutation) AddedEdges() []string {
	edges := make([]string, 0, 1)
	if m.user != nil {
		edges = append(edges, address.EdgeUser)
	}
	return edges
}
func (m *AddressMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case address.EdgeUser:
		if id := m.user; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}
func (m *AddressMutation) RemovedEdges() []string {
	edges := make([]string, 0, 1)
	return edges
}
func (m *AddressMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	}
	return nil
}
func (m *AddressMutation) ClearedEdges() []string {
	edges := make([]string, 0, 1)
	if m.cleareduser {
		edges = append(edges, address.EdgeUser)
	}
	return edges
}
func (m *AddressMutation) EdgeCleared(name string) bool {
	switch name {
	case address.EdgeUser:
		return m.cleareduser
	}
	return false
}
func (m *AddressMutation) ClearEdge(name string) error {
	switch name {
	case address.EdgeUser:
		m.ClearUser()
		return nil
	}
	return fmt.Errorf("unknown Address unique edge %s", name)
}
func (m *AddressMutation) ResetEdge(name string) error {
	switch name {
	case address.EdgeUser:
		m.ResetUser()
		return nil
	}
	return fmt.Errorf("unknown Address edge %s", name)
}
type CardMutation struct {
	config
	op            Op
	typ           string
	id            *int64
	name          *string
	card_no       *string
	ccv           *string
	expires       *string
	created_at    *time.Time
	updated_at    *time.Time
	clearedFields map[string]struct{}
	user          *int64
	cleareduser   bool
	done          bool
	oldValue      func(context.Context) (*Card, error)
	predicates    []predicate.Card
}
var _ ent.Mutation = (*CardMutation)(nil)
type cardOption func(*CardMutation)
func newCardMutation(c config, op Op, opts ...cardOption) *CardMutation {
	m := &CardMutation{
		config:        c,
		op:            op,
		typ:           TypeCard,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}
func withCardID(id int64) cardOption {
	return func(m *CardMutation) {
		var (
			err   error
			once  sync.Once
			value *Card
		)
		m.oldValue = func(ctx context.Context) (*Card, error) {
			once.Do(func() {
				if m.done {
					err = fmt.Errorf("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Card.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}
func withCard(node *Card) cardOption {
	return func(m *CardMutation) {
		m.oldValue = func(context.Context) (*Card, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}
func (m CardMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}
func (m CardMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, fmt.Errorf("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}
func (m *CardMutation) SetID(id int64) {
	m.id = &id
}
func (m *CardMutation) ID() (id int64, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}
func (m *CardMutation) SetName(s string) {
	m.name = &s
}
func (m *CardMutation) Name() (r string, exists bool) {
	v := m.name
	if v == nil {
		return
	}
	return *v, true
}
func (m *CardMutation) OldName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("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
}
func (m *CardMutation) ResetName() {
	m.name = nil
}
func (m *CardMutation) SetCardNo(s string) {
	m.card_no = &s
}
func (m *CardMutation) CardNo() (r string, exists bool) {
	v := m.card_no
	if v == nil {
		return
	}
	return *v, true
}
func (m *CardMutation) OldCardNo(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldCardNo is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldCardNo requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCardNo: %w", err)
	}
	return oldValue.CardNo, nil
}
func (m *CardMutation) ResetCardNo() {
	m.card_no = nil
}
func (m *CardMutation) SetCcv(s string) {
	m.ccv = &s
}
func (m *CardMutation) Ccv() (r string, exists bool) {
	v := m.ccv
	if v == nil {
		return
	}
	return *v, true
}
func (m *CardMutation) OldCcv(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldCcv is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldCcv requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCcv: %w", err)
	}
	return oldValue.Ccv, nil
}
func (m *CardMutation) ResetCcv() {
	m.ccv = nil
}
func (m *CardMutation) SetExpires(s string) {
	m.expires = &s
}
func (m *CardMutation) Expires() (r string, exists bool) {
	v := m.expires
	if v == nil {
		return
	}
	return *v, true
}
func (m *CardMutation) OldExpires(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldExpires is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldExpires requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldExpires: %w", err)
	}
	return oldValue.Expires, nil
}
func (m *CardMutation) ResetExpires() {
	m.expires = nil
}
func (m *CardMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}
func (m *CardMutation) CreatedAt() (r time.Time, exists bool) {
	v := m.created_at
	if v == nil {
		return
	}
	return *v, true
}
func (m *CardMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("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
}