func (cuo *CardUpdateOne) SetUserID(id int64) *CardUpdateOne {
	cuo.mutation.SetUserID(id)
	return cuo
}
SetUserID sets the "user" edge to the User entity by ID.
package ent
import (
	"context"
	"fmt"
	"time"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"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"
)
type CardUpdate struct {
	config
	hooks    []Hook
	mutation *CardMutation
}
func (cu *CardUpdate) Where(ps ...predicate.Card) *CardUpdate {
	cu.mutation.predicates = append(cu.mutation.predicates, ps...)
	return cu
}
func (cu *CardUpdate) SetName(s string) *CardUpdate {
	cu.mutation.SetName(s)
	return cu
}
func (cu *CardUpdate) SetCardNo(s string) *CardUpdate {
	cu.mutation.SetCardNo(s)
	return cu
}
func (cu *CardUpdate) SetCcv(s string) *CardUpdate {
	cu.mutation.SetCcv(s)
	return cu
}
func (cu *CardUpdate) SetExpires(s string) *CardUpdate {
	cu.mutation.SetExpires(s)
	return cu
}
func (cu *CardUpdate) SetCreatedAt(t time.Time) *CardUpdate {
	cu.mutation.SetCreatedAt(t)
	return cu
}
func (cu *CardUpdate) SetNillableCreatedAt(t *time.Time) *CardUpdate {
	if t != nil {
		cu.SetCreatedAt(*t)
	}
	return cu
}
func (cu *CardUpdate) SetUpdatedAt(t time.Time) *CardUpdate {
	cu.mutation.SetUpdatedAt(t)
	return cu
}
func (cu *CardUpdate) SetNillableUpdatedAt(t *time.Time) *CardUpdate {
	if t != nil {
		cu.SetUpdatedAt(*t)
	}
	return cu
}
func (cu *CardUpdate) SetUserID(id int64) *CardUpdate {
	cu.mutation.SetUserID(id)
	return cu
}
func (cu *CardUpdate) SetNillableUserID(id *int64) *CardUpdate {
	if id != nil {
		cu = cu.SetUserID(*id)
	}
	return cu
}
func (cu *CardUpdate) SetUser(u *User) *CardUpdate {
	return cu.SetUserID(u.ID)
}
func (cu *CardUpdate) Mutation() *CardMutation {
	return cu.mutation
}
func (cu *CardUpdate) ClearUser() *CardUpdate {
	cu.mutation.ClearUser()
	return cu
}
func (cu *CardUpdate) Save(ctx context.Context) (int, error) {
	var (
		err      error
		affected int
	)
	if len(cu.hooks) == 0 {
		affected, err = cu.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*CardMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			cu.mutation = mutation
			affected, err = cu.sqlSave(ctx)
			mutation.done = true
			return affected, err
		})
		for i := len(cu.hooks) - 1; i >= 0; i-- {
			mut = cu.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, cu.mutation); err != nil {
			return 0, err
		}
	}
	return affected, err
}
func (cu *CardUpdate) SaveX(ctx context.Context) int {
	affected, err := cu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}
func (cu *CardUpdate) Exec(ctx context.Context) error {
	_, err := cu.Save(ctx)
	return err
}
func (cu *CardUpdate) ExecX(ctx context.Context) {
	if err := cu.Exec(ctx); err != nil {
		panic(err)
	}
}
func (cu *CardUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := &sqlgraph.UpdateSpec{
		Node: &sqlgraph.NodeSpec{
			Table:   card.Table,
			Columns: card.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeInt64,
				Column: card.FieldID,
			},
		},
	}
	if ps := cu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := cu.mutation.Name(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: card.FieldName,
		})
	}
	if value, ok := cu.mutation.CardNo(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: card.FieldCardNo,
		})
	}
	if value, ok := cu.mutation.Ccv(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: card.FieldCcv,
		})
	}
	if value, ok := cu.mutation.Expires(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: card.FieldExpires,
		})
	}
	if value, ok := cu.mutation.CreatedAt(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: card.FieldCreatedAt,
		})
	}
	if value, ok := cu.mutation.UpdatedAt(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeTime,
			Value:  value,
			Column: card.FieldUpdatedAt,
		})
	}
	if cu.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   card.UserTable,
			Columns: []string{card.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt64,
					Column: user.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := cu.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   card.UserTable,
			Columns: []string{card.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt64,
					Column: user.FieldID,
				},
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{card.Label}
		} else if cerr, ok := isSQLConstraintError(err); ok {
			err = cerr
		}
		return 0, err
	}
	return n, nil
}
type CardUpdateOne struct {
	config
	hooks    []Hook
	mutation *CardMutation
}
func (cuo *CardUpdateOne) SetName(s string) *CardUpdateOne {
	cuo.mutation.SetName(s)
	return cuo
}
func (cuo *CardUpdateOne) SetCardNo(s string) *CardUpdateOne {
	cuo.mutation.SetCardNo(s)
	return cuo
}
func (cuo *CardUpdateOne) SetCcv(s string) *CardUpdateOne {
	cuo.mutation.SetCcv(s)
	return cuo
}
func (cuo *CardUpdateOne) SetExpires(s string) *CardUpdateOne {
	cuo.mutation.SetExpires(s)
	return cuo
}
func (cuo *CardUpdateOne) SetCreatedAt(t time.Time) *CardUpdateOne {
	cuo.mutation.SetCreatedAt(t)
	return cuo
}
func (cuo *CardUpdateOne) SetNillableCreatedAt(t *time.Time) *CardUpdateOne {
	if t != nil {
		cuo.SetCreatedAt(*t)
	}
	return cuo
}
func (cuo *CardUpdateOne) SetUpdatedAt(t time.Time) *CardUpdateOne {
	cuo.mutation.SetUpdatedAt(t)
	return cuo
}
func (cuo *CardUpdateOne) SetNillableUpdatedAt(t *time.Time) *CardUpdateOne {
	if t != nil {
		cuo.SetUpdatedAt(*t)
	}
	return cuo
}