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

	_matchingCardTypes.matchingCardTypesDo.UseDB(db, opts...)
	_matchingCardTypes.matchingCardTypesDo.UseModel(&model.MatchingCardTypes{})

	tableName := _matchingCardTypes.matchingCardTypesDo.TableName()
	_matchingCardTypes.ALL = field.NewAsterisk(tableName)
	_matchingCardTypes.ID = field.NewInt64(tableName, "id")
	_matchingCardTypes.Code = field.NewString(tableName, "code")
	_matchingCardTypes.Name = field.NewString(tableName, "name")
	_matchingCardTypes.ImageURL = field.NewString(tableName, "image_url")
	_matchingCardTypes.Quantity = field.NewInt32(tableName, "quantity")
	_matchingCardTypes.Sort = field.NewInt32(tableName, "sort")
	_matchingCardTypes.Status = field.NewInt32(tableName, "status")
	_matchingCardTypes.CreatedAt = field.NewTime(tableName, "created_at")
	_matchingCardTypes.UpdatedAt = field.NewTime(tableName, "updated_at")

	_matchingCardTypes.fillFieldMap()

	return _matchingCardTypes
}

// matchingCardTypes 对对碰卡牌类型配置表
type matchingCardTypes struct {
	matchingCardTypesDo

	ALL       field.Asterisk
	ID        field.Int64
	Code      field.String // 卡牌代码 如 A, B, C
	Name      field.String // 卡牌名称
	ImageURL  field.String // 卡牌图片URL
	Quantity  field.Int32  // 每局游戏该类型卡牌数量
	Sort      field.Int32  // 排序
	Status    field.Int32  // 状态 1启用 0禁用
	CreatedAt field.Time
	UpdatedAt field.Time

	fieldMap map[string]field.Expr
}

func (m matchingCardTypes) Table(newTableName string) *matchingCardTypes {
	m.matchingCardTypesDo.UseTable(newTableName)
	return m.updateTableName(newTableName)
}

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

func (m *matchingCardTypes) updateTableName(table string) *matchingCardTypes {
	m.ALL = field.NewAsterisk(table)
	m.ID = field.NewInt64(table, "id")
	m.Code = field.NewString(table, "code")
	m.Name = field.NewString(table, "name")
	m.ImageURL = field.NewString(table, "image_url")
	m.Quantity = field.NewInt32(table, "quantity")
	m.Sort = field.NewInt32(table, "sort")
	m.Status = field.NewInt32(table, "status")
	m.CreatedAt = field.NewTime(table, "created_at")
	m.UpdatedAt = field.NewTime(table, "updated_at")

	m.fillFieldMap()

	return m
}

func (m *matchingCardTypes) 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 *matchingCardTypes) fillFieldMap() {
	m.fieldMap = make(map[string]field.Expr, 9)
	m.fieldMap["id"] = m.ID
	m.fieldMap["code"] = m.Code
	m.fieldMap["name"] = m.Name
	m.fieldMap["image_url"] = m.ImageURL
	m.fieldMap["quantity"] = m.Quantity
	m.fieldMap["sort"] = m.Sort
	m.fieldMap["status"] = m.Status
	m.fieldMap["created_at"] = m.CreatedAt
	m.fieldMap["updated_at"] = m.UpdatedAt
}

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

func (m matchingCardTypes) replaceDB(db *gorm.DB) matchingCardTypes {
	m.matchingCardTypesDo.ReplaceDB(db)
	return m
}

type matchingCardTypesDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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