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

	_douyinOrders.douyinOrdersDo.UseDB(db, opts...)
	_douyinOrders.douyinOrdersDo.UseModel(&model.DouyinOrders{})

	tableName := _douyinOrders.douyinOrdersDo.TableName()
	_douyinOrders.ALL = field.NewAsterisk(tableName)
	_douyinOrders.ID = field.NewInt64(tableName, "id")
	_douyinOrders.ShopOrderID = field.NewString(tableName, "shop_order_id")
	_douyinOrders.OrderStatus = field.NewInt32(tableName, "order_status")
	_douyinOrders.DouyinUserID = field.NewString(tableName, "douyin_user_id")
	_douyinOrders.LocalUserID = field.NewString(tableName, "local_user_id")
	_douyinOrders.ActualReceiveAmount = field.NewInt64(tableName, "actual_receive_amount")
	_douyinOrders.PayTypeDesc = field.NewString(tableName, "pay_type_desc")
	_douyinOrders.Remark = field.NewString(tableName, "remark")
	_douyinOrders.UserNickname = field.NewString(tableName, "user_nickname")
	_douyinOrders.RawData = field.NewString(tableName, "raw_data")
	_douyinOrders.CreatedAt = field.NewTime(tableName, "created_at")
	_douyinOrders.UpdatedAt = field.NewTime(tableName, "updated_at")

	_douyinOrders.fillFieldMap()

	return _douyinOrders
}

// douyinOrders 抖店订单表
type douyinOrders struct {
	douyinOrdersDo

	ALL                 field.Asterisk
	ID                  field.Int64
	ShopOrderID         field.String // 抖店订单号
	OrderStatus         field.Int32  // 订单状态: 5=已完成
	DouyinUserID        field.String // 抖店用户ID
	LocalUserID         field.String // 匹配到的本地用户ID
	ActualReceiveAmount field.Int64  // 实收金额(分)
	PayTypeDesc         field.String // 支付方式描述
	Remark              field.String // 备注
	UserNickname        field.String // 抖音昵称
	RawData             field.String // 原始响应数据
	CreatedAt           field.Time
	UpdatedAt           field.Time

	fieldMap map[string]field.Expr
}

func (d douyinOrders) Table(newTableName string) *douyinOrders {
	d.douyinOrdersDo.UseTable(newTableName)
	return d.updateTableName(newTableName)
}

func (d douyinOrders) As(alias string) *douyinOrders {
	d.douyinOrdersDo.DO = *(d.douyinOrdersDo.As(alias).(*gen.DO))
	return d.updateTableName(alias)
}

func (d *douyinOrders) updateTableName(table string) *douyinOrders {
	d.ALL = field.NewAsterisk(table)
	d.ID = field.NewInt64(table, "id")
	d.ShopOrderID = field.NewString(table, "shop_order_id")
	d.OrderStatus = field.NewInt32(table, "order_status")
	d.DouyinUserID = field.NewString(table, "douyin_user_id")
	d.LocalUserID = field.NewString(table, "local_user_id")
	d.ActualReceiveAmount = field.NewInt64(table, "actual_receive_amount")
	d.PayTypeDesc = field.NewString(table, "pay_type_desc")
	d.Remark = field.NewString(table, "remark")
	d.UserNickname = field.NewString(table, "user_nickname")
	d.RawData = field.NewString(table, "raw_data")
	d.CreatedAt = field.NewTime(table, "created_at")
	d.UpdatedAt = field.NewTime(table, "updated_at")

	d.fillFieldMap()

	return d
}

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

func (d *douyinOrders) fillFieldMap() {
	d.fieldMap = make(map[string]field.Expr, 12)
	d.fieldMap["id"] = d.ID
	d.fieldMap["shop_order_id"] = d.ShopOrderID
	d.fieldMap["order_status"] = d.OrderStatus
	d.fieldMap["douyin_user_id"] = d.DouyinUserID
	d.fieldMap["local_user_id"] = d.LocalUserID
	d.fieldMap["actual_receive_amount"] = d.ActualReceiveAmount
	d.fieldMap["pay_type_desc"] = d.PayTypeDesc
	d.fieldMap["remark"] = d.Remark
	d.fieldMap["user_nickname"] = d.UserNickname
	d.fieldMap["raw_data"] = d.RawData
	d.fieldMap["created_at"] = d.CreatedAt
	d.fieldMap["updated_at"] = d.UpdatedAt
}

func (d douyinOrders) clone(db *gorm.DB) douyinOrders {
	d.douyinOrdersDo.ReplaceConnPool(db.Statement.ConnPool)
	return d
}

func (d douyinOrders) replaceDB(db *gorm.DB) douyinOrders {
	d.douyinOrdersDo.ReplaceDB(db)
	return d
}

type douyinOrdersDo struct{ gen.DO }

func (d douyinOrdersDo) Debug() *douyinOrdersDo {
	return d.withDO(d.DO.Debug())
}

func (d douyinOrdersDo) WithContext(ctx context.Context) *douyinOrdersDo {
	return d.withDO(d.DO.WithContext(ctx))
}

func (d douyinOrdersDo) ReadDB() *douyinOrdersDo {
	return d.Clauses(dbresolver.Read)
}

func (d douyinOrdersDo) WriteDB() *douyinOrdersDo {
	return d.Clauses(dbresolver.Write)
}

func (d douyinOrdersDo) Session(config *gorm.Session) *douyinOrdersDo {
	return d.withDO(d.DO.Session(config))
}

func (d douyinOrdersDo) Clauses(conds ...clause.Expression) *douyinOrdersDo {
	return d.withDO(d.DO.Clauses(conds...))
}

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

func (d douyinOrdersDo) Not(conds ...gen.Condition) *douyinOrdersDo {
	return d.withDO(d.DO.Not(conds...))
}

func (d douyinOrdersDo) Or(conds ...gen.Condition) *douyinOrdersDo {
	return d.withDO(d.DO.Or(conds...))
}

func (d douyinOrdersDo) Select(conds ...field.Expr) *douyinOrdersDo {
	return d.withDO(d.DO.Select(conds...))
}

func (d douyinOrdersDo) Where(conds ...gen.Condition) *douyinOrdersDo {
	return d.withDO(d.DO.Where(conds...))
}

func (d douyinOrdersDo) Order(conds ...field.Expr) *douyinOrdersDo {
	return d.withDO(d.DO.Order(conds...))
}

func (d douyinOrdersDo) Distinct(cols ...field.Expr) *douyinOrdersDo {
	return d.withDO(d.DO.Distinct(cols...))
}

func (d douyinOrdersDo) Omit(cols ...field.Expr) *douyinOrdersDo {
	return d.withDO(d.DO.Omit(cols...))
}

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

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

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

func (d douyinOrdersDo) Group(cols ...field.Expr) *douyinOrdersDo {
	return d.withDO(d.DO.Group(cols...))
}

func (d douyinOrdersDo) Having(conds ...gen.Condition) *douyinOrdersDo {
	return d.withDO(d.DO.Having(conds...))
}

func (d douyinOrdersDo) Limit(limit int) *douyinOrdersDo {
	return d.withDO(d.DO.Limit(limit))
}

func (d douyinOrdersDo) Offset(offset int) *douyinOrdersDo {
	return d.withDO(d.DO.Offset(offset))
}

func (d douyinOrdersDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *douyinOrdersDo {
	return d.withDO(d.DO.Scopes(funcs...))
}

func (d douyinOrdersDo) Unscoped() *douyinOrdersDo {
	return d.withDO(d.DO.Unscoped())
}

func (d douyinOrdersDo) Create(values ...*model.DouyinOrders) error {
	if len(values) == 0 {
		return nil
	}
	return d.DO.Create(values)
}

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

func (d douyinOrdersDo) First() (*model.DouyinOrders, error) {
	if result, err := d.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.DouyinOrders), nil
	}
}

func (d douyinOrdersDo) Take() (*model.DouyinOrders, error) {
	if result, err := d.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.DouyinOrders), nil
	}
}

func (d douyinOrdersDo) Last() (*model.DouyinOrders, error) {
	if result, err := d.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.DouyinOrders), nil
	}
}

func (d douyinOrdersDo) Find() ([]*model.DouyinOrders, error) {
	result, err := d.DO.Find()
	return result.([]*model.DouyinOrders), err
}

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

func (d douyinOrdersDo) Attrs(attrs ...field.AssignExpr) *douyinOrdersDo {
	return d.withDO(d.DO.Attrs(attrs...))
}

func (d douyinOrdersDo) Assign(attrs ...field.AssignExpr) *douyinOrdersDo {
	return d.withDO(d.DO.Assign(attrs...))
}

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

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

func (d douyinOrdersDo) FirstOrInit() (*model.DouyinOrders, error) {
	if result, err := d.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.DouyinOrders), nil
	}
}

func (d douyinOrdersDo) FirstOrCreate() (*model.DouyinOrders, error) {
	if result, err := d.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.DouyinOrders), nil
	}
}

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

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

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

func (d douyinOrdersDo) Scan(result interface{}) (err error) {
	return d.DO.Scan(result)
}

func (d douyinOrdersDo) Delete(models ...*model.DouyinOrders) (result gen.ResultInfo, err error) {
	return d.DO.Delete(models)
}

func (d *douyinOrdersDo) withDO(do gen.Dao) *douyinOrdersDo {
	d.DO = *do.(*gen.DO)
	return d
}
