// 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 query

import (
	"context"

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

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

	"gorm.io/plugin/dbresolver"

	"gadmin/internal/gorm/model"
)

func newZoneActivity(db *gorm.DB, opts ...gen.DOOption) zoneActivity {
	_zoneActivity := zoneActivity{}

	_zoneActivity.zoneActivityDo.UseDB(db, opts...)
	_zoneActivity.zoneActivityDo.UseModel(&model.ZoneActivity{})

	tableName := _zoneActivity.zoneActivityDo.TableName()
	_zoneActivity.ALL = field.NewAsterisk(tableName)
	_zoneActivity.Playerid = field.NewInt64(tableName, "playerid")
	_zoneActivity.Activtiys = field.NewString(tableName, "activtiys")
	_zoneActivity.BonusProperties = field.NewString(tableName, "bonusProperties")
	_zoneActivity.EndLess = field.NewString(tableName, "endLess")
	_zoneActivity.VipBuff = field.NewString(tableName, "vipBuff")
	_zoneActivity.Boss = field.NewString(tableName, "boss")

	_zoneActivity.fillFieldMap()

	return _zoneActivity
}

type zoneActivity struct {
	zoneActivityDo

	ALL             field.Asterisk
	Playerid        field.Int64
	Activtiys       field.String
	BonusProperties field.String
	EndLess         field.String
	VipBuff         field.String
	Boss            field.String

	fieldMap map[string]field.Expr
}

func (z zoneActivity) Table(newTableName string) *zoneActivity {
	z.zoneActivityDo.UseTable(newTableName)
	return z.updateTableName(newTableName)
}

func (z zoneActivity) As(alias string) *zoneActivity {
	z.zoneActivityDo.DO = *(z.zoneActivityDo.As(alias).(*gen.DO))
	return z.updateTableName(alias)
}

func (z *zoneActivity) updateTableName(table string) *zoneActivity {
	z.ALL = field.NewAsterisk(table)
	z.Playerid = field.NewInt64(table, "playerid")
	z.Activtiys = field.NewString(table, "activtiys")
	z.BonusProperties = field.NewString(table, "bonusProperties")
	z.EndLess = field.NewString(table, "endLess")
	z.VipBuff = field.NewString(table, "vipBuff")
	z.Boss = field.NewString(table, "boss")

	z.fillFieldMap()

	return z
}

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

func (z *zoneActivity) fillFieldMap() {
	z.fieldMap = make(map[string]field.Expr, 6)
	z.fieldMap["playerid"] = z.Playerid
	z.fieldMap["activtiys"] = z.Activtiys
	z.fieldMap["bonusProperties"] = z.BonusProperties
	z.fieldMap["endLess"] = z.EndLess
	z.fieldMap["vipBuff"] = z.VipBuff
	z.fieldMap["boss"] = z.Boss
}

func (z zoneActivity) clone(db *gorm.DB) zoneActivity {
	z.zoneActivityDo.ReplaceConnPool(db.Statement.ConnPool)
	return z
}

func (z zoneActivity) replaceDB(db *gorm.DB) zoneActivity {
	z.zoneActivityDo.ReplaceDB(db)
	return z
}

type zoneActivityDo struct{ gen.DO }

func (z zoneActivityDo) Debug() *zoneActivityDo {
	return z.withDO(z.DO.Debug())
}

func (z zoneActivityDo) WithContext(ctx context.Context) *zoneActivityDo {
	return z.withDO(z.DO.WithContext(ctx))
}

func (z zoneActivityDo) ReadDB() *zoneActivityDo {
	return z.Clauses(dbresolver.Read)
}

func (z zoneActivityDo) WriteDB() *zoneActivityDo {
	return z.Clauses(dbresolver.Write)
}

func (z zoneActivityDo) Session(config *gorm.Session) *zoneActivityDo {
	return z.withDO(z.DO.Session(config))
}

func (z zoneActivityDo) Clauses(conds ...clause.Expression) *zoneActivityDo {
	return z.withDO(z.DO.Clauses(conds...))
}

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

func (z zoneActivityDo) Not(conds ...gen.Condition) *zoneActivityDo {
	return z.withDO(z.DO.Not(conds...))
}

func (z zoneActivityDo) Or(conds ...gen.Condition) *zoneActivityDo {
	return z.withDO(z.DO.Or(conds...))
}

func (z zoneActivityDo) Select(conds ...field.Expr) *zoneActivityDo {
	return z.withDO(z.DO.Select(conds...))
}

func (z zoneActivityDo) Where(conds ...gen.Condition) *zoneActivityDo {
	return z.withDO(z.DO.Where(conds...))
}

func (z zoneActivityDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *zoneActivityDo {
	return z.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}

func (z zoneActivityDo) Order(conds ...field.Expr) *zoneActivityDo {
	return z.withDO(z.DO.Order(conds...))
}

func (z zoneActivityDo) Distinct(cols ...field.Expr) *zoneActivityDo {
	return z.withDO(z.DO.Distinct(cols...))
}

func (z zoneActivityDo) Omit(cols ...field.Expr) *zoneActivityDo {
	return z.withDO(z.DO.Omit(cols...))
}

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

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

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

func (z zoneActivityDo) Group(cols ...field.Expr) *zoneActivityDo {
	return z.withDO(z.DO.Group(cols...))
}

func (z zoneActivityDo) Having(conds ...gen.Condition) *zoneActivityDo {
	return z.withDO(z.DO.Having(conds...))
}

func (z zoneActivityDo) Limit(limit int) *zoneActivityDo {
	return z.withDO(z.DO.Limit(limit))
}

func (z zoneActivityDo) Offset(offset int) *zoneActivityDo {
	return z.withDO(z.DO.Offset(offset))
}

func (z zoneActivityDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *zoneActivityDo {
	return z.withDO(z.DO.Scopes(funcs...))
}

func (z zoneActivityDo) Unscoped() *zoneActivityDo {
	return z.withDO(z.DO.Unscoped())
}

func (z zoneActivityDo) Create(values ...*model.ZoneActivity) error {
	if len(values) == 0 {
		return nil
	}
	return z.DO.Create(values)
}

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

func (z zoneActivityDo) First() (*model.ZoneActivity, error) {
	if result, err := z.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.ZoneActivity), nil
	}
}

func (z zoneActivityDo) Take() (*model.ZoneActivity, error) {
	if result, err := z.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.ZoneActivity), nil
	}
}

func (z zoneActivityDo) Last() (*model.ZoneActivity, error) {
	if result, err := z.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.ZoneActivity), nil
	}
}

func (z zoneActivityDo) Find() ([]*model.ZoneActivity, error) {
	result, err := z.DO.Find()
	return result.([]*model.ZoneActivity), err
}

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

func (z zoneActivityDo) Attrs(attrs ...field.AssignExpr) *zoneActivityDo {
	return z.withDO(z.DO.Attrs(attrs...))
}

func (z zoneActivityDo) Assign(attrs ...field.AssignExpr) *zoneActivityDo {
	return z.withDO(z.DO.Assign(attrs...))
}

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

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

func (z zoneActivityDo) FirstOrInit() (*model.ZoneActivity, error) {
	if result, err := z.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.ZoneActivity), nil
	}
}

func (z zoneActivityDo) FirstOrCreate() (*model.ZoneActivity, error) {
	if result, err := z.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.ZoneActivity), nil
	}
}

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

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

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

func (z zoneActivityDo) Scan(result interface{}) (err error) {
	return z.DO.Scan(result)
}

func (z zoneActivityDo) Delete(models ...*model.ZoneActivity) (result gen.ResultInfo, err error) {
	return z.DO.Delete(models)
}

func (z *zoneActivityDo) withDO(do gen.Dao) *zoneActivityDo {
	z.DO = *do.(*gen.DO)
	return z
}
