// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.

package dao

import (
	"context"

	"gorm.io/gorm"
	"gorm.io/gorm/clause"
	"gorm.io/gorm/schema"

	"gorm.io/gen"
	"gorm.io/gen/field"

	"gorm.io/plugin/dbresolver"

	"bindbox-game/internal/repository/mysql/model"
)

func newGamePassPackages(db *gorm.DB, opts ...gen.DOOption) gamePassPackages {
	_gamePassPackages := gamePassPackages{}

	_gamePassPackages.gamePassPackagesDo.UseDB(db, opts...)
	_gamePassPackages.gamePassPackagesDo.UseModel(&model.GamePassPackages{})

	tableName := _gamePassPackages.gamePassPackagesDo.TableName()
	_gamePassPackages.ALL = field.NewAsterisk(tableName)
	_gamePassPackages.ID = field.NewInt64(tableName, "id")
	_gamePassPackages.CreatedAt = field.NewTime(tableName, "created_at")
	_gamePassPackages.UpdatedAt = field.NewTime(tableName, "updated_at")
	_gamePassPackages.Name = field.NewString(tableName, "name")
	_gamePassPackages.PassCount = field.NewInt32(tableName, "pass_count")
	_gamePassPackages.Price = field.NewInt64(tableName, "price")
	_gamePassPackages.OriginalPrice = field.NewInt64(tableName, "original_price")
	_gamePassPackages.ActivityID = field.NewInt64(tableName, "activity_id")
	_gamePassPackages.ValidDays = field.NewInt32(tableName, "valid_days")
	_gamePassPackages.SortOrder = field.NewInt32(tableName, "sort_order")
	_gamePassPackages.Status = field.NewInt32(tableName, "status")
	_gamePassPackages.DeletedAt = field.NewField(tableName, "deleted_at")

	_gamePassPackages.fillFieldMap()

	return _gamePassPackages
}

// gamePassPackages 次数卡套餐配置
type gamePassPackages struct {
	gamePassPackagesDo

	ALL           field.Asterisk
	ID            field.Int64  // 主键ID
	CreatedAt     field.Time   // 创建时间
	UpdatedAt     field.Time   // 更新时间
	Name          field.String // 套餐名称，如：10次畅玩卡
	PassCount     field.Int32  // 包含次数
	Price         field.Int64  // 售价（分）
	OriginalPrice field.Int64  // 原价（分），用于展示划线价
	ActivityID    field.Int64  // 限定活动ID，NULL表示全局通用
	ValidDays     field.Int32  // 有效期天数，NULL表示永久有效
	SortOrder     field.Int32  // 排序权重
	Status        field.Int32  // 状态: 1=上架 2=下架
	DeletedAt     field.Field  // 软删除时间

	fieldMap map[string]field.Expr
}

func (g gamePassPackages) Table(newTableName string) *gamePassPackages {
	g.gamePassPackagesDo.UseTable(newTableName)
	return g.updateTableName(newTableName)
}

func (g gamePassPackages) As(alias string) *gamePassPackages {
	g.gamePassPackagesDo.DO = *(g.gamePassPackagesDo.As(alias).(*gen.DO))
	return g.updateTableName(alias)
}

func (g *gamePassPackages) updateTableName(table string) *gamePassPackages {
	g.ALL = field.NewAsterisk(table)
	g.ID = field.NewInt64(table, "id")
	g.CreatedAt = field.NewTime(table, "created_at")
	g.UpdatedAt = field.NewTime(table, "updated_at")
	g.Name = field.NewString(table, "name")
	g.PassCount = field.NewInt32(table, "pass_count")
	g.Price = field.NewInt64(table, "price")
	g.OriginalPrice = field.NewInt64(table, "original_price")
	g.ActivityID = field.NewInt64(table, "activity_id")
	g.ValidDays = field.NewInt32(table, "valid_days")
	g.SortOrder = field.NewInt32(table, "sort_order")
	g.Status = field.NewInt32(table, "status")
	g.DeletedAt = field.NewField(table, "deleted_at")

	g.fillFieldMap()

	return g
}

func (g *gamePassPackages) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
	_f, ok := g.fieldMap[fieldName]
	if !ok || _f == nil {
		return nil, false
	}
	_oe, ok := _f.(field.OrderExpr)
	return _oe, ok
}

func (g *gamePassPackages) fillFieldMap() {
	g.fieldMap = make(map[string]field.Expr, 12)
	g.fieldMap["id"] = g.ID
	g.fieldMap["created_at"] = g.CreatedAt
	g.fieldMap["updated_at"] = g.UpdatedAt
	g.fieldMap["name"] = g.Name
	g.fieldMap["pass_count"] = g.PassCount
	g.fieldMap["price"] = g.Price
	g.fieldMap["original_price"] = g.OriginalPrice
	g.fieldMap["activity_id"] = g.ActivityID
	g.fieldMap["valid_days"] = g.ValidDays
	g.fieldMap["sort_order"] = g.SortOrder
	g.fieldMap["status"] = g.Status
	g.fieldMap["deleted_at"] = g.DeletedAt
}

func (g gamePassPackages) clone(db *gorm.DB) gamePassPackages {
	g.gamePassPackagesDo.ReplaceConnPool(db.Statement.ConnPool)
	return g
}

func (g gamePassPackages) replaceDB(db *gorm.DB) gamePassPackages {
	g.gamePassPackagesDo.ReplaceDB(db)
	return g
}

type gamePassPackagesDo struct{ gen.DO }

func (g gamePassPackagesDo) Debug() *gamePassPackagesDo {
	return g.withDO(g.DO.Debug())
}

func (g gamePassPackagesDo) WithContext(ctx context.Context) *gamePassPackagesDo {
	return g.withDO(g.DO.WithContext(ctx))
}

func (g gamePassPackagesDo) ReadDB() *gamePassPackagesDo {
	return g.Clauses(dbresolver.Read)
}

func (g gamePassPackagesDo) WriteDB() *gamePassPackagesDo {
	return g.Clauses(dbresolver.Write)
}

func (g gamePassPackagesDo) Session(config *gorm.Session) *gamePassPackagesDo {
	return g.withDO(g.DO.Session(config))
}

func (g gamePassPackagesDo) Clauses(conds ...clause.Expression) *gamePassPackagesDo {
	return g.withDO(g.DO.Clauses(conds...))
}

func (g gamePassPackagesDo) Returning(value interface{}, columns ...string) *gamePassPackagesDo {
	return g.withDO(g.DO.Returning(value, columns...))
}

func (g gamePassPackagesDo) Not(conds ...gen.Condition) *gamePassPackagesDo {
	return g.withDO(g.DO.Not(conds...))
}

func (g gamePassPackagesDo) Or(conds ...gen.Condition) *gamePassPackagesDo {
	return g.withDO(g.DO.Or(conds...))
}

func (g gamePassPackagesDo) Select(conds ...field.Expr) *gamePassPackagesDo {
	return g.withDO(g.DO.Select(conds...))
}

func (g gamePassPackagesDo) Where(conds ...gen.Condition) *gamePassPackagesDo {
	return g.withDO(g.DO.Where(conds...))
}

func (g gamePassPackagesDo) Order(conds ...field.Expr) *gamePassPackagesDo {
	return g.withDO(g.DO.Order(conds...))
}

func (g gamePassPackagesDo) Distinct(cols ...field.Expr) *gamePassPackagesDo {
	return g.withDO(g.DO.Distinct(cols...))
}

func (g gamePassPackagesDo) Omit(cols ...field.Expr) *gamePassPackagesDo {
	return g.withDO(g.DO.Omit(cols...))
}

func (g gamePassPackagesDo) Join(table schema.Tabler, on ...field.Expr) *gamePassPackagesDo {
	return g.withDO(g.DO.Join(table, on...))
}

func (g gamePassPackagesDo) LeftJoin(table schema.Tabler, on ...field.Expr) *gamePassPackagesDo {
	return g.withDO(g.DO.LeftJoin(table, on...))
}

func (g gamePassPackagesDo) RightJoin(table schema.Tabler, on ...field.Expr) *gamePassPackagesDo {
	return g.withDO(g.DO.RightJoin(table, on...))
}

func (g gamePassPackagesDo) Group(cols ...field.Expr) *gamePassPackagesDo {
	return g.withDO(g.DO.Group(cols...))
}

func (g gamePassPackagesDo) Having(conds ...gen.Condition) *gamePassPackagesDo {
	return g.withDO(g.DO.Having(conds...))
}

func (g gamePassPackagesDo) Limit(limit int) *gamePassPackagesDo {
	return g.withDO(g.DO.Limit(limit))
}

func (g gamePassPackagesDo) Offset(offset int) *gamePassPackagesDo {
	return g.withDO(g.DO.Offset(offset))
}

func (g gamePassPackagesDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *gamePassPackagesDo {
	return g.withDO(g.DO.Scopes(funcs...))
}

func (g gamePassPackagesDo) Unscoped() *gamePassPackagesDo {
	return g.withDO(g.DO.Unscoped())
}

func (g gamePassPackagesDo) Create(values ...*model.GamePassPackages) error {
	if len(values) == 0 {
		return nil
	}
	return g.DO.Create(values)
}

func (g gamePassPackagesDo) CreateInBatches(values []*model.GamePassPackages, batchSize int) error {
	return g.DO.CreateInBatches(values, batchSize)
}

// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (g gamePassPackagesDo) Save(values ...*model.GamePassPackages) error {
	if len(values) == 0 {
		return nil
	}
	return g.DO.Save(values)
}

func (g gamePassPackagesDo) First() (*model.GamePassPackages, error) {
	if result, err := g.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.GamePassPackages), nil
	}
}

func (g gamePassPackagesDo) Take() (*model.GamePassPackages, error) {
	if result, err := g.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.GamePassPackages), nil
	}
}

func (g gamePassPackagesDo) Last() (*model.GamePassPackages, error) {
	if result, err := g.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.GamePassPackages), nil
	}
}

func (g gamePassPackagesDo) Find() ([]*model.GamePassPackages, error) {
	result, err := g.DO.Find()
	return result.([]*model.GamePassPackages), err
}

func (g gamePassPackagesDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.GamePassPackages, err error) {
	buf := make([]*model.GamePassPackages, 0, batchSize)
	err = g.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
		defer func() { results = append(results, buf...) }()
		return fc(tx, batch)
	})
	return results, err
}

func (g gamePassPackagesDo) FindInBatches(result *[]*model.GamePassPackages, batchSize int, fc func(tx gen.Dao, batch int) error) error {
	return g.DO.FindInBatches(result, batchSize, fc)
}

func (g gamePassPackagesDo) Attrs(attrs ...field.AssignExpr) *gamePassPackagesDo {
	return g.withDO(g.DO.Attrs(attrs...))
}

func (g gamePassPackagesDo) Assign(attrs ...field.AssignExpr) *gamePassPackagesDo {
	return g.withDO(g.DO.Assign(attrs...))
}

func (g gamePassPackagesDo) Joins(fields ...field.RelationField) *gamePassPackagesDo {
	for _, _f := range fields {
		g = *g.withDO(g.DO.Joins(_f))
	}
	return &g
}

func (g gamePassPackagesDo) Preload(fields ...field.RelationField) *gamePassPackagesDo {
	for _, _f := range fields {
		g = *g.withDO(g.DO.Preload(_f))
	}
	return &g
}

func (g gamePassPackagesDo) FirstOrInit() (*model.GamePassPackages, error) {
	if result, err := g.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.GamePassPackages), nil
	}
}

func (g gamePassPackagesDo) FirstOrCreate() (*model.GamePassPackages, error) {
	if result, err := g.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.GamePassPackages), nil
	}
}

func (g gamePassPackagesDo) FindByPage(offset int, limit int) (result []*model.GamePassPackages, count int64, err error) {
	result, err = g.Offset(offset).Limit(limit).Find()
	if err != nil {
		return
	}

	if size := len(result); 0 < limit && 0 < size && size < limit {
		count = int64(size + offset)
		return
	}

	count, err = g.Offset(-1).Limit(-1).Count()
	return
}

func (g gamePassPackagesDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
	count, err = g.Count()
	if err != nil {
		return
	}

	err = g.Offset(offset).Limit(limit).Scan(result)
	return
}

func (g gamePassPackagesDo) Scan(result interface{}) (err error) {
	return g.DO.Scan(result)
}

func (g gamePassPackagesDo) Delete(models ...*model.GamePassPackages) (result gen.ResultInfo, err error) {
	return g.DO.Delete(models)
}

func (g *gamePassPackagesDo) withDO(do gen.Dao) *gamePassPackagesDo {
	g.DO = *do.(*gen.DO)
	return g
}
