// 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 newActivityCategories(db *gorm.DB, opts ...gen.DOOption) activityCategories {
	_activityCategories := activityCategories{}

	_activityCategories.activityCategoriesDo.UseDB(db, opts...)
	_activityCategories.activityCategoriesDo.UseModel(&model.ActivityCategories{})

	tableName := _activityCategories.activityCategoriesDo.TableName()
	_activityCategories.ALL = field.NewAsterisk(tableName)
	_activityCategories.ID = field.NewInt64(tableName, "id")
	_activityCategories.CreatedAt = field.NewTime(tableName, "created_at")
	_activityCategories.UpdatedAt = field.NewTime(tableName, "updated_at")
	_activityCategories.Name = field.NewString(tableName, "name")
	_activityCategories.ParentID = field.NewInt64(tableName, "parent_id")
	_activityCategories.Status = field.NewInt32(tableName, "status")

	_activityCategories.fillFieldMap()

	return _activityCategories
}

// activityCategories 活动分类
type activityCategories struct {
	activityCategoriesDo

	ALL       field.Asterisk
	ID        field.Int64  // 主键ID
	CreatedAt field.Time   // 创建时间
	UpdatedAt field.Time   // 更新时间
	Name      field.String // 活动分类名称
	ParentID  field.Int64  // 父分类ID（可空）
	Status    field.Int32  // 状态：1启用 2禁用

	fieldMap map[string]field.Expr
}

func (a activityCategories) Table(newTableName string) *activityCategories {
	a.activityCategoriesDo.UseTable(newTableName)
	return a.updateTableName(newTableName)
}

func (a activityCategories) As(alias string) *activityCategories {
	a.activityCategoriesDo.DO = *(a.activityCategoriesDo.As(alias).(*gen.DO))
	return a.updateTableName(alias)
}

func (a *activityCategories) updateTableName(table string) *activityCategories {
	a.ALL = field.NewAsterisk(table)
	a.ID = field.NewInt64(table, "id")
	a.CreatedAt = field.NewTime(table, "created_at")
	a.UpdatedAt = field.NewTime(table, "updated_at")
	a.Name = field.NewString(table, "name")
	a.ParentID = field.NewInt64(table, "parent_id")
	a.Status = field.NewInt32(table, "status")

	a.fillFieldMap()

	return a
}

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

func (a *activityCategories) fillFieldMap() {
	a.fieldMap = make(map[string]field.Expr, 6)
	a.fieldMap["id"] = a.ID
	a.fieldMap["created_at"] = a.CreatedAt
	a.fieldMap["updated_at"] = a.UpdatedAt
	a.fieldMap["name"] = a.Name
	a.fieldMap["parent_id"] = a.ParentID
	a.fieldMap["status"] = a.Status
}

func (a activityCategories) clone(db *gorm.DB) activityCategories {
	a.activityCategoriesDo.ReplaceConnPool(db.Statement.ConnPool)
	return a
}

func (a activityCategories) replaceDB(db *gorm.DB) activityCategories {
	a.activityCategoriesDo.ReplaceDB(db)
	return a
}

type activityCategoriesDo struct{ gen.DO }

func (a activityCategoriesDo) Debug() *activityCategoriesDo {
	return a.withDO(a.DO.Debug())
}

func (a activityCategoriesDo) WithContext(ctx context.Context) *activityCategoriesDo {
	return a.withDO(a.DO.WithContext(ctx))
}

func (a activityCategoriesDo) ReadDB() *activityCategoriesDo {
	return a.Clauses(dbresolver.Read)
}

func (a activityCategoriesDo) WriteDB() *activityCategoriesDo {
	return a.Clauses(dbresolver.Write)
}

func (a activityCategoriesDo) Session(config *gorm.Session) *activityCategoriesDo {
	return a.withDO(a.DO.Session(config))
}

func (a activityCategoriesDo) Clauses(conds ...clause.Expression) *activityCategoriesDo {
	return a.withDO(a.DO.Clauses(conds...))
}

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

func (a activityCategoriesDo) Not(conds ...gen.Condition) *activityCategoriesDo {
	return a.withDO(a.DO.Not(conds...))
}

func (a activityCategoriesDo) Or(conds ...gen.Condition) *activityCategoriesDo {
	return a.withDO(a.DO.Or(conds...))
}

func (a activityCategoriesDo) Select(conds ...field.Expr) *activityCategoriesDo {
	return a.withDO(a.DO.Select(conds...))
}

func (a activityCategoriesDo) Where(conds ...gen.Condition) *activityCategoriesDo {
	return a.withDO(a.DO.Where(conds...))
}

func (a activityCategoriesDo) Order(conds ...field.Expr) *activityCategoriesDo {
	return a.withDO(a.DO.Order(conds...))
}

func (a activityCategoriesDo) Distinct(cols ...field.Expr) *activityCategoriesDo {
	return a.withDO(a.DO.Distinct(cols...))
}

func (a activityCategoriesDo) Omit(cols ...field.Expr) *activityCategoriesDo {
	return a.withDO(a.DO.Omit(cols...))
}

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

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

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

func (a activityCategoriesDo) Group(cols ...field.Expr) *activityCategoriesDo {
	return a.withDO(a.DO.Group(cols...))
}

func (a activityCategoriesDo) Having(conds ...gen.Condition) *activityCategoriesDo {
	return a.withDO(a.DO.Having(conds...))
}

func (a activityCategoriesDo) Limit(limit int) *activityCategoriesDo {
	return a.withDO(a.DO.Limit(limit))
}

func (a activityCategoriesDo) Offset(offset int) *activityCategoriesDo {
	return a.withDO(a.DO.Offset(offset))
}

func (a activityCategoriesDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *activityCategoriesDo {
	return a.withDO(a.DO.Scopes(funcs...))
}

func (a activityCategoriesDo) Unscoped() *activityCategoriesDo {
	return a.withDO(a.DO.Unscoped())
}

func (a activityCategoriesDo) Create(values ...*model.ActivityCategories) error {
	if len(values) == 0 {
		return nil
	}
	return a.DO.Create(values)
}

func (a activityCategoriesDo) CreateInBatches(values []*model.ActivityCategories, batchSize int) error {
	return a.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 (a activityCategoriesDo) Save(values ...*model.ActivityCategories) error {
	if len(values) == 0 {
		return nil
	}
	return a.DO.Save(values)
}

func (a activityCategoriesDo) First() (*model.ActivityCategories, error) {
	if result, err := a.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.ActivityCategories), nil
	}
}

func (a activityCategoriesDo) Take() (*model.ActivityCategories, error) {
	if result, err := a.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.ActivityCategories), nil
	}
}

func (a activityCategoriesDo) Last() (*model.ActivityCategories, error) {
	if result, err := a.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.ActivityCategories), nil
	}
}

func (a activityCategoriesDo) Find() ([]*model.ActivityCategories, error) {
	result, err := a.DO.Find()
	return result.([]*model.ActivityCategories), err
}

func (a activityCategoriesDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ActivityCategories, err error) {
	buf := make([]*model.ActivityCategories, 0, batchSize)
	err = a.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 (a activityCategoriesDo) FindInBatches(result *[]*model.ActivityCategories, batchSize int, fc func(tx gen.Dao, batch int) error) error {
	return a.DO.FindInBatches(result, batchSize, fc)
}

func (a activityCategoriesDo) Attrs(attrs ...field.AssignExpr) *activityCategoriesDo {
	return a.withDO(a.DO.Attrs(attrs...))
}

func (a activityCategoriesDo) Assign(attrs ...field.AssignExpr) *activityCategoriesDo {
	return a.withDO(a.DO.Assign(attrs...))
}

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

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

func (a activityCategoriesDo) FirstOrInit() (*model.ActivityCategories, error) {
	if result, err := a.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.ActivityCategories), nil
	}
}

func (a activityCategoriesDo) FirstOrCreate() (*model.ActivityCategories, error) {
	if result, err := a.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.ActivityCategories), nil
	}
}

func (a activityCategoriesDo) FindByPage(offset int, limit int) (result []*model.ActivityCategories, count int64, err error) {
	result, err = a.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 = a.Offset(-1).Limit(-1).Count()
	return
}

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

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

func (a activityCategoriesDo) Scan(result interface{}) (err error) {
	return a.DO.Scan(result)
}

func (a activityCategoriesDo) Delete(models ...*model.ActivityCategories) (result gen.ResultInfo, err error) {
	return a.DO.Delete(models)
}

func (a *activityCategoriesDo) withDO(do gen.Dao) *activityCategoriesDo {
	a.DO = *do.(*gen.DO)
	return a
}
