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

	_miniProgramAccessToken.miniProgramAccessTokenDo.UseDB(db, opts...)
	_miniProgramAccessToken.miniProgramAccessTokenDo.UseModel(&model.MiniProgramAccessToken{})

	tableName := _miniProgramAccessToken.miniProgramAccessTokenDo.TableName()
	_miniProgramAccessToken.ALL = field.NewAsterisk(tableName)
	_miniProgramAccessToken.ID = field.NewInt32(tableName, "id")
	_miniProgramAccessToken.AppID = field.NewString(tableName, "app_id")
	_miniProgramAccessToken.AccessToken = field.NewString(tableName, "access_token")
	_miniProgramAccessToken.CreatedAt = field.NewTime(tableName, "created_at")
	_miniProgramAccessToken.ExpiredAt = field.NewTime(tableName, "expired_at")

	_miniProgramAccessToken.fillFieldMap()

	return _miniProgramAccessToken
}

// miniProgramAccessToken 小程序 access_token 表
type miniProgramAccessToken struct {
	miniProgramAccessTokenDo

	ALL         field.Asterisk
	ID          field.Int32  // 主键
	AppID       field.String // app_id
	AccessToken field.String // access_token
	CreatedAt   field.Time   // 创建时间
	ExpiredAt   field.Time   // 过期时间

	fieldMap map[string]field.Expr
}

func (m miniProgramAccessToken) Table(newTableName string) *miniProgramAccessToken {
	m.miniProgramAccessTokenDo.UseTable(newTableName)
	return m.updateTableName(newTableName)
}

func (m miniProgramAccessToken) As(alias string) *miniProgramAccessToken {
	m.miniProgramAccessTokenDo.DO = *(m.miniProgramAccessTokenDo.As(alias).(*gen.DO))
	return m.updateTableName(alias)
}

func (m *miniProgramAccessToken) updateTableName(table string) *miniProgramAccessToken {
	m.ALL = field.NewAsterisk(table)
	m.ID = field.NewInt32(table, "id")
	m.AppID = field.NewString(table, "app_id")
	m.AccessToken = field.NewString(table, "access_token")
	m.CreatedAt = field.NewTime(table, "created_at")
	m.ExpiredAt = field.NewTime(table, "expired_at")

	m.fillFieldMap()

	return m
}

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

func (m *miniProgramAccessToken) fillFieldMap() {
	m.fieldMap = make(map[string]field.Expr, 5)
	m.fieldMap["id"] = m.ID
	m.fieldMap["app_id"] = m.AppID
	m.fieldMap["access_token"] = m.AccessToken
	m.fieldMap["created_at"] = m.CreatedAt
	m.fieldMap["expired_at"] = m.ExpiredAt
}

func (m miniProgramAccessToken) clone(db *gorm.DB) miniProgramAccessToken {
	m.miniProgramAccessTokenDo.ReplaceConnPool(db.Statement.ConnPool)
	return m
}

func (m miniProgramAccessToken) replaceDB(db *gorm.DB) miniProgramAccessToken {
	m.miniProgramAccessTokenDo.ReplaceDB(db)
	return m
}

type miniProgramAccessTokenDo struct{ gen.DO }

func (m miniProgramAccessTokenDo) Debug() *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Debug())
}

func (m miniProgramAccessTokenDo) WithContext(ctx context.Context) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.WithContext(ctx))
}

func (m miniProgramAccessTokenDo) ReadDB() *miniProgramAccessTokenDo {
	return m.Clauses(dbresolver.Read)
}

func (m miniProgramAccessTokenDo) WriteDB() *miniProgramAccessTokenDo {
	return m.Clauses(dbresolver.Write)
}

func (m miniProgramAccessTokenDo) Session(config *gorm.Session) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Session(config))
}

func (m miniProgramAccessTokenDo) Clauses(conds ...clause.Expression) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Clauses(conds...))
}

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

func (m miniProgramAccessTokenDo) Not(conds ...gen.Condition) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Not(conds...))
}

func (m miniProgramAccessTokenDo) Or(conds ...gen.Condition) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Or(conds...))
}

func (m miniProgramAccessTokenDo) Select(conds ...field.Expr) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Select(conds...))
}

func (m miniProgramAccessTokenDo) Where(conds ...gen.Condition) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Where(conds...))
}

func (m miniProgramAccessTokenDo) Order(conds ...field.Expr) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Order(conds...))
}

func (m miniProgramAccessTokenDo) Distinct(cols ...field.Expr) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Distinct(cols...))
}

func (m miniProgramAccessTokenDo) Omit(cols ...field.Expr) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Omit(cols...))
}

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

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

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

func (m miniProgramAccessTokenDo) Group(cols ...field.Expr) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Group(cols...))
}

func (m miniProgramAccessTokenDo) Having(conds ...gen.Condition) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Having(conds...))
}

func (m miniProgramAccessTokenDo) Limit(limit int) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Limit(limit))
}

func (m miniProgramAccessTokenDo) Offset(offset int) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Offset(offset))
}

func (m miniProgramAccessTokenDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Scopes(funcs...))
}

func (m miniProgramAccessTokenDo) Unscoped() *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Unscoped())
}

func (m miniProgramAccessTokenDo) Create(values ...*model.MiniProgramAccessToken) error {
	if len(values) == 0 {
		return nil
	}
	return m.DO.Create(values)
}

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

func (m miniProgramAccessTokenDo) First() (*model.MiniProgramAccessToken, error) {
	if result, err := m.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.MiniProgramAccessToken), nil
	}
}

func (m miniProgramAccessTokenDo) Take() (*model.MiniProgramAccessToken, error) {
	if result, err := m.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.MiniProgramAccessToken), nil
	}
}

func (m miniProgramAccessTokenDo) Last() (*model.MiniProgramAccessToken, error) {
	if result, err := m.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.MiniProgramAccessToken), nil
	}
}

func (m miniProgramAccessTokenDo) Find() ([]*model.MiniProgramAccessToken, error) {
	result, err := m.DO.Find()
	return result.([]*model.MiniProgramAccessToken), err
}

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

func (m miniProgramAccessTokenDo) Attrs(attrs ...field.AssignExpr) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Attrs(attrs...))
}

func (m miniProgramAccessTokenDo) Assign(attrs ...field.AssignExpr) *miniProgramAccessTokenDo {
	return m.withDO(m.DO.Assign(attrs...))
}

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

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

func (m miniProgramAccessTokenDo) FirstOrInit() (*model.MiniProgramAccessToken, error) {
	if result, err := m.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.MiniProgramAccessToken), nil
	}
}

func (m miniProgramAccessTokenDo) FirstOrCreate() (*model.MiniProgramAccessToken, error) {
	if result, err := m.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.MiniProgramAccessToken), nil
	}
}

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

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

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

func (m miniProgramAccessTokenDo) Scan(result interface{}) (err error) {
	return m.DO.Scan(result)
}

func (m miniProgramAccessTokenDo) Delete(models ...*model.MiniProgramAccessToken) (result gen.ResultInfo, err error) {
	return m.DO.Delete(models)
}

func (m *miniProgramAccessTokenDo) withDO(do gen.Dao) *miniProgramAccessTokenDo {
	m.DO = *do.(*gen.DO)
	return m
}
