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

	_guildMembers.guildMembersDo.UseDB(db, opts...)
	_guildMembers.guildMembersDo.UseModel(&model.GuildMembers{})

	tableName := _guildMembers.guildMembersDo.TableName()
	_guildMembers.ALL = field.NewAsterisk(tableName)
	_guildMembers.ID = field.NewInt64(tableName, "id")
	_guildMembers.CreatedAt = field.NewTime(tableName, "created_at")
	_guildMembers.GuildID = field.NewInt64(tableName, "guild_id")
	_guildMembers.UserID = field.NewInt64(tableName, "user_id")
	_guildMembers.Role = field.NewString(tableName, "role")
	_guildMembers.StartTime = field.NewTime(tableName, "start_time")
	_guildMembers.Status = field.NewInt32(tableName, "status")
	_guildMembers.JoinStatus = field.NewInt32(tableName, "join_status")

	_guildMembers.fillFieldMap()

	return _guildMembers
}

// guildMembers 公会成员
type guildMembers struct {
	guildMembersDo

	ALL        field.Asterisk
	ID         field.Int64  // 主键ID
	CreatedAt  field.Time   // 创建时间
	GuildID    field.Int64  // 公会ID（guild_main.id）
	UserID     field.Int64  // 成员用户ID（user_members.id）
	Role       field.String // 角色：owner/admin/member
	StartTime  field.Time   // 加入时间
	Status     field.Int32  // 状态：1正常 2退出
	JoinStatus field.Int32  // 状态：1 拒绝 2 同意

	fieldMap map[string]field.Expr
}

func (g guildMembers) Table(newTableName string) *guildMembers {
	g.guildMembersDo.UseTable(newTableName)
	return g.updateTableName(newTableName)
}

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

func (g *guildMembers) updateTableName(table string) *guildMembers {
	g.ALL = field.NewAsterisk(table)
	g.ID = field.NewInt64(table, "id")
	g.CreatedAt = field.NewTime(table, "created_at")
	g.GuildID = field.NewInt64(table, "guild_id")
	g.UserID = field.NewInt64(table, "user_id")
	g.Role = field.NewString(table, "role")
	g.StartTime = field.NewTime(table, "start_time")
	g.Status = field.NewInt32(table, "status")
	g.JoinStatus = field.NewInt32(table, "join_status")

	g.fillFieldMap()

	return g
}

func (g *guildMembers) 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 *guildMembers) fillFieldMap() {
	g.fieldMap = make(map[string]field.Expr, 8)
	g.fieldMap["id"] = g.ID
	g.fieldMap["created_at"] = g.CreatedAt
	g.fieldMap["guild_id"] = g.GuildID
	g.fieldMap["user_id"] = g.UserID
	g.fieldMap["role"] = g.Role
	g.fieldMap["start_time"] = g.StartTime
	g.fieldMap["status"] = g.Status
	g.fieldMap["join_status"] = g.JoinStatus
}

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

func (g guildMembers) replaceDB(db *gorm.DB) guildMembers {
	g.guildMembersDo.ReplaceDB(db)
	return g
}

type guildMembersDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (g guildMembersDo) CreateInBatches(values []*model.GuildMembers, 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 guildMembersDo) Save(values ...*model.GuildMembers) error {
	if len(values) == 0 {
		return nil
	}
	return g.DO.Save(values)
}

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

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

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

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

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

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

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

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

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

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

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

func (g guildMembersDo) FindByPage(offset int, limit int) (result []*model.GuildMembers, 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 guildMembersDo) 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 guildMembersDo) Scan(result interface{}) (err error) {
	return g.DO.Scan(result)
}

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

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