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

	_livestreamActivities.livestreamActivitiesDo.UseDB(db, opts...)
	_livestreamActivities.livestreamActivitiesDo.UseModel(&model.LivestreamActivities{})

	tableName := _livestreamActivities.livestreamActivitiesDo.TableName()
	_livestreamActivities.ALL = field.NewAsterisk(tableName)
	_livestreamActivities.ID = field.NewInt64(tableName, "id")
	_livestreamActivities.Name = field.NewString(tableName, "name")
	_livestreamActivities.StreamerName = field.NewString(tableName, "streamer_name")
	_livestreamActivities.StreamerContact = field.NewString(tableName, "streamer_contact")
	_livestreamActivities.AccessCode = field.NewString(tableName, "access_code")
	_livestreamActivities.DouyinProductID = field.NewString(tableName, "douyin_product_id")
	_livestreamActivities.Status = field.NewInt32(tableName, "status")
	_livestreamActivities.CommitmentAlgo = field.NewString(tableName, "commitment_algo")
	_livestreamActivities.CommitmentSeedMaster = field.NewBytes(tableName, "commitment_seed_master")
	_livestreamActivities.CommitmentSeedHash = field.NewBytes(tableName, "commitment_seed_hash")
	_livestreamActivities.CommitmentStateVersion = field.NewInt32(tableName, "commitment_state_version")
	_livestreamActivities.StartTime = field.NewTime(tableName, "start_time")
	_livestreamActivities.EndTime = field.NewTime(tableName, "end_time")
	_livestreamActivities.CreatedAt = field.NewTime(tableName, "created_at")
	_livestreamActivities.UpdatedAt = field.NewTime(tableName, "updated_at")
	_livestreamActivities.DeletedAt = field.NewField(tableName, "deleted_at")
	_livestreamActivities.TicketPrice = field.NewInt32(tableName, "ticket_price")

	_livestreamActivities.fillFieldMap()

	return _livestreamActivities
}

// livestreamActivities 直播间活动表
type livestreamActivities struct {
	livestreamActivitiesDo

	ALL                    field.Asterisk
	ID                     field.Int64  // 主键ID
	Name                   field.String // 活动名称
	StreamerName           field.String // 主播名称
	StreamerContact        field.String // 主播联系方式
	AccessCode             field.String // 唯一访问码
	DouyinProductID        field.String // 关联抖店商品ID
	Status                 field.Int32  // 状态:1进行中 2已结束
	CommitmentAlgo         field.String // 承诺算法版本
	CommitmentSeedMaster   field.Bytes  // 主种子(32字节)
	CommitmentSeedHash     field.Bytes  // 种子SHA256哈希
	CommitmentStateVersion field.Int32  // 状态版本
	StartTime              field.Time   // 开始时间
	EndTime                field.Time   // 结束时间
	CreatedAt              field.Time   // 创建时间
	UpdatedAt              field.Time   // 更新时间
	DeletedAt              field.Field  // 删除时间
	TicketPrice            field.Int32

	fieldMap map[string]field.Expr
}

func (l livestreamActivities) Table(newTableName string) *livestreamActivities {
	l.livestreamActivitiesDo.UseTable(newTableName)
	return l.updateTableName(newTableName)
}

func (l livestreamActivities) As(alias string) *livestreamActivities {
	l.livestreamActivitiesDo.DO = *(l.livestreamActivitiesDo.As(alias).(*gen.DO))
	return l.updateTableName(alias)
}

func (l *livestreamActivities) updateTableName(table string) *livestreamActivities {
	l.ALL = field.NewAsterisk(table)
	l.ID = field.NewInt64(table, "id")
	l.Name = field.NewString(table, "name")
	l.StreamerName = field.NewString(table, "streamer_name")
	l.StreamerContact = field.NewString(table, "streamer_contact")
	l.AccessCode = field.NewString(table, "access_code")
	l.DouyinProductID = field.NewString(table, "douyin_product_id")
	l.Status = field.NewInt32(table, "status")
	l.CommitmentAlgo = field.NewString(table, "commitment_algo")
	l.CommitmentSeedMaster = field.NewBytes(table, "commitment_seed_master")
	l.CommitmentSeedHash = field.NewBytes(table, "commitment_seed_hash")
	l.CommitmentStateVersion = field.NewInt32(table, "commitment_state_version")
	l.StartTime = field.NewTime(table, "start_time")
	l.EndTime = field.NewTime(table, "end_time")
	l.CreatedAt = field.NewTime(table, "created_at")
	l.UpdatedAt = field.NewTime(table, "updated_at")
	l.DeletedAt = field.NewField(table, "deleted_at")
	l.TicketPrice = field.NewInt32(table, "ticket_price")

	l.fillFieldMap()

	return l
}

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

func (l *livestreamActivities) fillFieldMap() {
	l.fieldMap = make(map[string]field.Expr, 17)
	l.fieldMap["id"] = l.ID
	l.fieldMap["name"] = l.Name
	l.fieldMap["streamer_name"] = l.StreamerName
	l.fieldMap["streamer_contact"] = l.StreamerContact
	l.fieldMap["access_code"] = l.AccessCode
	l.fieldMap["douyin_product_id"] = l.DouyinProductID
	l.fieldMap["status"] = l.Status
	l.fieldMap["commitment_algo"] = l.CommitmentAlgo
	l.fieldMap["commitment_seed_master"] = l.CommitmentSeedMaster
	l.fieldMap["commitment_seed_hash"] = l.CommitmentSeedHash
	l.fieldMap["commitment_state_version"] = l.CommitmentStateVersion
	l.fieldMap["start_time"] = l.StartTime
	l.fieldMap["end_time"] = l.EndTime
	l.fieldMap["created_at"] = l.CreatedAt
	l.fieldMap["updated_at"] = l.UpdatedAt
	l.fieldMap["deleted_at"] = l.DeletedAt
	l.fieldMap["ticket_price"] = l.TicketPrice
}

func (l livestreamActivities) clone(db *gorm.DB) livestreamActivities {
	l.livestreamActivitiesDo.ReplaceConnPool(db.Statement.ConnPool)
	return l
}

func (l livestreamActivities) replaceDB(db *gorm.DB) livestreamActivities {
	l.livestreamActivitiesDo.ReplaceDB(db)
	return l
}

type livestreamActivitiesDo struct{ gen.DO }

func (l livestreamActivitiesDo) Debug() *livestreamActivitiesDo {
	return l.withDO(l.DO.Debug())
}

func (l livestreamActivitiesDo) WithContext(ctx context.Context) *livestreamActivitiesDo {
	return l.withDO(l.DO.WithContext(ctx))
}

func (l livestreamActivitiesDo) ReadDB() *livestreamActivitiesDo {
	return l.Clauses(dbresolver.Read)
}

func (l livestreamActivitiesDo) WriteDB() *livestreamActivitiesDo {
	return l.Clauses(dbresolver.Write)
}

func (l livestreamActivitiesDo) Session(config *gorm.Session) *livestreamActivitiesDo {
	return l.withDO(l.DO.Session(config))
}

func (l livestreamActivitiesDo) Clauses(conds ...clause.Expression) *livestreamActivitiesDo {
	return l.withDO(l.DO.Clauses(conds...))
}

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

func (l livestreamActivitiesDo) Not(conds ...gen.Condition) *livestreamActivitiesDo {
	return l.withDO(l.DO.Not(conds...))
}

func (l livestreamActivitiesDo) Or(conds ...gen.Condition) *livestreamActivitiesDo {
	return l.withDO(l.DO.Or(conds...))
}

func (l livestreamActivitiesDo) Select(conds ...field.Expr) *livestreamActivitiesDo {
	return l.withDO(l.DO.Select(conds...))
}

func (l livestreamActivitiesDo) Where(conds ...gen.Condition) *livestreamActivitiesDo {
	return l.withDO(l.DO.Where(conds...))
}

func (l livestreamActivitiesDo) Order(conds ...field.Expr) *livestreamActivitiesDo {
	return l.withDO(l.DO.Order(conds...))
}

func (l livestreamActivitiesDo) Distinct(cols ...field.Expr) *livestreamActivitiesDo {
	return l.withDO(l.DO.Distinct(cols...))
}

func (l livestreamActivitiesDo) Omit(cols ...field.Expr) *livestreamActivitiesDo {
	return l.withDO(l.DO.Omit(cols...))
}

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

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

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

func (l livestreamActivitiesDo) Group(cols ...field.Expr) *livestreamActivitiesDo {
	return l.withDO(l.DO.Group(cols...))
}

func (l livestreamActivitiesDo) Having(conds ...gen.Condition) *livestreamActivitiesDo {
	return l.withDO(l.DO.Having(conds...))
}

func (l livestreamActivitiesDo) Limit(limit int) *livestreamActivitiesDo {
	return l.withDO(l.DO.Limit(limit))
}

func (l livestreamActivitiesDo) Offset(offset int) *livestreamActivitiesDo {
	return l.withDO(l.DO.Offset(offset))
}

func (l livestreamActivitiesDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *livestreamActivitiesDo {
	return l.withDO(l.DO.Scopes(funcs...))
}

func (l livestreamActivitiesDo) Unscoped() *livestreamActivitiesDo {
	return l.withDO(l.DO.Unscoped())
}

func (l livestreamActivitiesDo) Create(values ...*model.LivestreamActivities) error {
	if len(values) == 0 {
		return nil
	}
	return l.DO.Create(values)
}

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

func (l livestreamActivitiesDo) First() (*model.LivestreamActivities, error) {
	if result, err := l.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.LivestreamActivities), nil
	}
}

func (l livestreamActivitiesDo) Take() (*model.LivestreamActivities, error) {
	if result, err := l.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.LivestreamActivities), nil
	}
}

func (l livestreamActivitiesDo) Last() (*model.LivestreamActivities, error) {
	if result, err := l.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.LivestreamActivities), nil
	}
}

func (l livestreamActivitiesDo) Find() ([]*model.LivestreamActivities, error) {
	result, err := l.DO.Find()
	return result.([]*model.LivestreamActivities), err
}

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

func (l livestreamActivitiesDo) Attrs(attrs ...field.AssignExpr) *livestreamActivitiesDo {
	return l.withDO(l.DO.Attrs(attrs...))
}

func (l livestreamActivitiesDo) Assign(attrs ...field.AssignExpr) *livestreamActivitiesDo {
	return l.withDO(l.DO.Assign(attrs...))
}

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

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

func (l livestreamActivitiesDo) FirstOrInit() (*model.LivestreamActivities, error) {
	if result, err := l.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.LivestreamActivities), nil
	}
}

func (l livestreamActivitiesDo) FirstOrCreate() (*model.LivestreamActivities, error) {
	if result, err := l.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.LivestreamActivities), nil
	}
}

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

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

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

func (l livestreamActivitiesDo) Scan(result interface{}) (err error) {
	return l.DO.Scan(result)
}

func (l livestreamActivitiesDo) Delete(models ...*model.LivestreamActivities) (result gen.ResultInfo, err error) {
	return l.DO.Delete(models)
}

func (l *livestreamActivitiesDo) withDO(do gen.Dao) *livestreamActivitiesDo {
	l.DO = *do.(*gen.DO)
	return l
}
