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

	_guildContributeLogs.guildContributeLogsDo.UseDB(db, opts...)
	_guildContributeLogs.guildContributeLogsDo.UseModel(&model.GuildContributeLogs{})

	tableName := _guildContributeLogs.guildContributeLogsDo.TableName()
	_guildContributeLogs.ALL = field.NewAsterisk(tableName)
	_guildContributeLogs.ID = field.NewInt64(tableName, "id")
	_guildContributeLogs.CreatedAt = field.NewTime(tableName, "created_at")
	_guildContributeLogs.GuildID = field.NewInt64(tableName, "guild_id")
	_guildContributeLogs.UserID = field.NewInt64(tableName, "user_id")
	_guildContributeLogs.ActivityID = field.NewInt64(tableName, "activity_id")
	_guildContributeLogs.IssuesID = field.NewInt64(tableName, "issues_id")
	_guildContributeLogs.Action = field.NewString(tableName, "action")
	_guildContributeLogs.Value = field.NewInt64(tableName, "value")
	_guildContributeLogs.ProductID = field.NewInt32(tableName, "product_id")

	_guildContributeLogs.fillFieldMap()

	return _guildContributeLogs
}

// guildContributeLogs 公会贡献流水
type guildContributeLogs struct {
	guildContributeLogsDo

	ALL        field.Asterisk
	ID         field.Int64  // 主键ID
	CreatedAt  field.Time   // 创建时间
	GuildID    field.Int64  // 公会ID（guild_main.id）
	UserID     field.Int64  // 用户ID（user_members.id）
	ActivityID field.Int64  // 活动ID（可空）
	IssuesID   field.Int64  // 活动期ID（可空）
	Action     field.String // 贡献动作（抽奖/购买/分享等）
	Value      field.Int64  // 贡献值（业务自定义）
	ProductID  field.Int32  // 奖品ID (可空)

	fieldMap map[string]field.Expr
}

func (g guildContributeLogs) Table(newTableName string) *guildContributeLogs {
	g.guildContributeLogsDo.UseTable(newTableName)
	return g.updateTableName(newTableName)
}

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

func (g *guildContributeLogs) updateTableName(table string) *guildContributeLogs {
	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.ActivityID = field.NewInt64(table, "activity_id")
	g.IssuesID = field.NewInt64(table, "issues_id")
	g.Action = field.NewString(table, "action")
	g.Value = field.NewInt64(table, "value")
	g.ProductID = field.NewInt32(table, "product_id")

	g.fillFieldMap()

	return g
}

func (g *guildContributeLogs) 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 *guildContributeLogs) fillFieldMap() {
	g.fieldMap = make(map[string]field.Expr, 9)
	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["activity_id"] = g.ActivityID
	g.fieldMap["issues_id"] = g.IssuesID
	g.fieldMap["action"] = g.Action
	g.fieldMap["value"] = g.Value
	g.fieldMap["product_id"] = g.ProductID
}

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

func (g guildContributeLogs) replaceDB(db *gorm.DB) guildContributeLogs {
	g.guildContributeLogsDo.ReplaceDB(db)
	return g
}

type guildContributeLogsDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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