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

	_activityIssues.activityIssuesDo.UseDB(db, opts...)
	_activityIssues.activityIssuesDo.UseModel(&model.ActivityIssues{})

	tableName := _activityIssues.activityIssuesDo.TableName()
	_activityIssues.ALL = field.NewAsterisk(tableName)
	_activityIssues.ID = field.NewInt64(tableName, "id")
	_activityIssues.CreatedAt = field.NewTime(tableName, "created_at")
	_activityIssues.UpdatedAt = field.NewTime(tableName, "updated_at")
	_activityIssues.ActivityID = field.NewInt64(tableName, "activity_id")
	_activityIssues.IssueNumber = field.NewString(tableName, "issue_number")
	_activityIssues.Status = field.NewInt32(tableName, "status")
	_activityIssues.Sort = field.NewInt32(tableName, "sort")
	_activityIssues.DeletedAt = field.NewField(tableName, "deleted_at")

	_activityIssues.fillFieldMap()

	return _activityIssues
}

// activityIssues 活动期
type activityIssues struct {
	activityIssuesDo

	ALL         field.Asterisk
	ID          field.Int64  // 主键ID
	CreatedAt   field.Time   // 创建时间
	UpdatedAt   field.Time   // 更新时间
	ActivityID  field.Int64  // 活动ID（activities.id）
	IssueNumber field.String // 期号（活动内唯一）
	Status      field.Int32  // 状态：1进行中 2已结束 3未开始
	Sort        field.Int32  // 排序
	DeletedAt   field.Field

	fieldMap map[string]field.Expr
}

func (a activityIssues) Table(newTableName string) *activityIssues {
	a.activityIssuesDo.UseTable(newTableName)
	return a.updateTableName(newTableName)
}

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

func (a *activityIssues) updateTableName(table string) *activityIssues {
	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.ActivityID = field.NewInt64(table, "activity_id")
	a.IssueNumber = field.NewString(table, "issue_number")
	a.Status = field.NewInt32(table, "status")
	a.Sort = field.NewInt32(table, "sort")
	a.DeletedAt = field.NewField(table, "deleted_at")

	a.fillFieldMap()

	return a
}

func (a *activityIssues) 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 *activityIssues) fillFieldMap() {
	a.fieldMap = make(map[string]field.Expr, 8)
	a.fieldMap["id"] = a.ID
	a.fieldMap["created_at"] = a.CreatedAt
	a.fieldMap["updated_at"] = a.UpdatedAt
	a.fieldMap["activity_id"] = a.ActivityID
	a.fieldMap["issue_number"] = a.IssueNumber
	a.fieldMap["status"] = a.Status
	a.fieldMap["sort"] = a.Sort
	a.fieldMap["deleted_at"] = a.DeletedAt
}

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

func (a activityIssues) replaceDB(db *gorm.DB) activityIssues {
	a.activityIssuesDo.ReplaceDB(db)
	return a
}

type activityIssuesDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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