func (m *BeerMutation) 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
}
OldCreatedAt returns the old "created_at" field's value of the Beer entity.
If the Beer object wasn't provided to the builder, the object is fetched from the database.
An error is returned if the mutation operation is not UpdateOne, or the database query fails.
package ent
import (
	"context"
	"fmt"
	"sync"
	"time"
	"github.com/go-kratos/beer-shop/app/catalog/service/internal/biz"
	"github.com/go-kratos/beer-shop/app/catalog/service/internal/data/ent/beer"
	"github.com/go-kratos/beer-shop/app/catalog/service/internal/data/ent/predicate"
	"entgo.io/ent"
)
const (
	OpCreate    = ent.OpCreate
	OpDelete    = ent.OpDelete
	OpDeleteOne = ent.OpDeleteOne
	OpUpdate    = ent.OpUpdate
	OpUpdateOne = ent.OpUpdateOne
	TypeBeer = "Beer"
)
type BeerMutation struct {
	config
	op            Op
	typ           string
	id            *int64
	name          *string
	description   *string
	count         *int64
	addcount      *int64
	price         *int64
	addprice      *int64
	images        *[]biz.Image
	created_at    *time.Time
	updated_at    *time.Time
	clearedFields map[string]struct{}
	done          bool
	oldValue      func(context.Context) (*Beer, error)
	predicates    []predicate.Beer
}
var _ ent.Mutation = (*BeerMutation)(nil)
type beerOption func(*BeerMutation)
func newBeerMutation(c config, op Op, opts ...beerOption) *BeerMutation {
	m := &BeerMutation{
		config:        c,
		op:            op,
		typ:           TypeBeer,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}
func withBeerID(id int64) beerOption {
	return func(m *BeerMutation) {
		var (
			err   error
			once  sync.Once
			value *Beer
		)
		m.oldValue = func(ctx context.Context) (*Beer, error) {
			once.Do(func() {
				if m.done {
					err = fmt.Errorf("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Beer.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}
func withBeer(node *Beer) beerOption {
	return func(m *BeerMutation) {
		m.oldValue = func(context.Context) (*Beer, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}
func (m BeerMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}
func (m BeerMutation) 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 *BeerMutation) SetID(id int64) {
	m.id = &id
}
func (m *BeerMutation) ID() (id int64, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}
func (m *BeerMutation) SetName(s string) {
	m.name = &s
}
func (m *BeerMutation) Name() (r string, exists bool) {
	v := m.name
	if v == nil {
		return
	}
	return *v, true
}
func (m *BeerMutation) 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 *BeerMutation) ResetName() {
	m.name = nil
}
func (m *BeerMutation) SetDescription(s string) {
	m.description = &s
}
func (m *BeerMutation) Description() (r string, exists bool) {
	v := m.description
	if v == nil {
		return
	}
	return *v, true
}
func (m *BeerMutation) OldDescription(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldDescription is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("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
}
func (m *BeerMutation) ResetDescription() {
	m.description = nil
}
func (m *BeerMutation) SetCount(i int64) {
	m.count = &i
	m.addcount = nil
}
func (m *BeerMutation) Count() (r int64, exists bool) {
	v := m.count
	if v == nil {
		return
	}
	return *v, true
}
func (m *BeerMutation) OldCount(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldCount is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldCount requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldCount: %w", err)
	}
	return oldValue.Count, nil
}
func (m *BeerMutation) AddCount(i int64) {
	if m.addcount != nil {
		*m.addcount += i
	} else {
		m.addcount = &i
	}
}
func (m *BeerMutation) AddedCount() (r int64, exists bool) {
	v := m.addcount
	if v == nil {
		return
	}
	return *v, true
}
func (m *BeerMutation) ResetCount() {
	m.count = nil
	m.addcount = nil
}
func (m *BeerMutation) SetPrice(i int64) {
	m.price = &i
	m.addprice = nil
}
func (m *BeerMutation) Price() (r int64, exists bool) {
	v := m.price
	if v == nil {
		return
	}
	return *v, true
}
func (m *BeerMutation) OldPrice(ctx context.Context) (v int64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldPrice is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("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
}
func (m *BeerMutation) AddPrice(i int64) {
	if m.addprice != nil {
		*m.addprice += i
	} else {
		m.addprice = &i
	}
}
func (m *BeerMutation) AddedPrice() (r int64, exists bool) {
	v := m.addprice
	if v == nil {
		return
	}
	return *v, true
}
func (m *BeerMutation) ResetPrice() {
	m.price = nil
	m.addprice = nil
}
func (m *BeerMutation) SetImages(b []biz.Image) {
	m.images = &b
}
func (m *BeerMutation) Images() (r []biz.Image, exists bool) {
	v := m.images
	if v == nil {
		return
	}
	return *v, true
}
func (m *BeerMutation) OldImages(ctx context.Context) (v []biz.Image, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldImages is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldImages requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldImages: %w", err)
	}
	return oldValue.Images, nil
}
func (m *BeerMutation) ResetImages() {
	m.images = nil
}
func (m *BeerMutation) SetCreatedAt(t time.Time) {
	m.created_at = &t
}
func (m *BeerMutation) CreatedAt() (r time.Time, exists bool) {
	v := m.created_at
	if v == nil {
		return
	}
	return *v, true
}