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

	_auditRollbackLogs.auditRollbackLogsDo.UseDB(db, opts...)
	_auditRollbackLogs.auditRollbackLogsDo.UseModel(&model.AuditRollbackLogs{})

	tableName := _auditRollbackLogs.auditRollbackLogsDo.TableName()
	_auditRollbackLogs.ALL = field.NewAsterisk(tableName)
	_auditRollbackLogs.ID = field.NewInt64(tableName, "id")
	_auditRollbackLogs.CreatedAt = field.NewTime(tableName, "created_at")
	_auditRollbackLogs.OrderID = field.NewInt64(tableName, "order_id")
	_auditRollbackLogs.OrderNo = field.NewString(tableName, "order_no")
	_auditRollbackLogs.UserID = field.NewInt64(tableName, "user_id")
	_auditRollbackLogs.OperatorID = field.NewInt64(tableName, "operator_id")
	_auditRollbackLogs.OperatorName = field.NewString(tableName, "operator_name")
	_auditRollbackLogs.RollbackType = field.NewInt32(tableName, "rollback_type")
	_auditRollbackLogs.BeforeSnapshotID = field.NewInt64(tableName, "before_snapshot_id")
	_auditRollbackLogs.AfterSnapshotID = field.NewInt64(tableName, "after_snapshot_id")
	_auditRollbackLogs.ChangesApplied = field.NewString(tableName, "changes_applied")
	_auditRollbackLogs.Reason = field.NewString(tableName, "reason")
	_auditRollbackLogs.Status = field.NewInt32(tableName, "status")
	_auditRollbackLogs.ErrorMsg = field.NewString(tableName, "error_msg")

	_auditRollbackLogs.fillFieldMap()

	return _auditRollbackLogs
}

// auditRollbackLogs 审计回滚操作日志
type auditRollbackLogs struct {
	auditRollbackLogsDo

	ALL              field.Asterisk
	ID               field.Int64  // 主键ID
	CreatedAt        field.Time   // 创建时间
	OrderID          field.Int64  // 订单ID
	OrderNo          field.String // 订单号
	UserID           field.Int64  // 用户ID
	OperatorID       field.Int64  // 操作人ID(管理员)
	OperatorName     field.String // 操作人名称
	RollbackType     field.Int32  // 回滚类型：1=完整回滚
	BeforeSnapshotID field.Int64  // 回滚前快照ID(消费后快照)
	AfterSnapshotID  field.Int64  // 回滚目标快照ID(消费前快照)
	ChangesApplied   field.String // 实际执行的变更明细
	Reason           field.String // 回滚原因
	Status           field.Int32  // 状态：1=成功 2=失败
	ErrorMsg         field.String // 失败原因

	fieldMap map[string]field.Expr
}

func (a auditRollbackLogs) Table(newTableName string) *auditRollbackLogs {
	a.auditRollbackLogsDo.UseTable(newTableName)
	return a.updateTableName(newTableName)
}

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

func (a *auditRollbackLogs) updateTableName(table string) *auditRollbackLogs {
	a.ALL = field.NewAsterisk(table)
	a.ID = field.NewInt64(table, "id")
	a.CreatedAt = field.NewTime(table, "created_at")
	a.OrderID = field.NewInt64(table, "order_id")
	a.OrderNo = field.NewString(table, "order_no")
	a.UserID = field.NewInt64(table, "user_id")
	a.OperatorID = field.NewInt64(table, "operator_id")
	a.OperatorName = field.NewString(table, "operator_name")
	a.RollbackType = field.NewInt32(table, "rollback_type")
	a.BeforeSnapshotID = field.NewInt64(table, "before_snapshot_id")
	a.AfterSnapshotID = field.NewInt64(table, "after_snapshot_id")
	a.ChangesApplied = field.NewString(table, "changes_applied")
	a.Reason = field.NewString(table, "reason")
	a.Status = field.NewInt32(table, "status")
	a.ErrorMsg = field.NewString(table, "error_msg")

	a.fillFieldMap()

	return a
}

func (a *auditRollbackLogs) 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 *auditRollbackLogs) fillFieldMap() {
	a.fieldMap = make(map[string]field.Expr, 14)
	a.fieldMap["id"] = a.ID
	a.fieldMap["created_at"] = a.CreatedAt
	a.fieldMap["order_id"] = a.OrderID
	a.fieldMap["order_no"] = a.OrderNo
	a.fieldMap["user_id"] = a.UserID
	a.fieldMap["operator_id"] = a.OperatorID
	a.fieldMap["operator_name"] = a.OperatorName
	a.fieldMap["rollback_type"] = a.RollbackType
	a.fieldMap["before_snapshot_id"] = a.BeforeSnapshotID
	a.fieldMap["after_snapshot_id"] = a.AfterSnapshotID
	a.fieldMap["changes_applied"] = a.ChangesApplied
	a.fieldMap["reason"] = a.Reason
	a.fieldMap["status"] = a.Status
	a.fieldMap["error_msg"] = a.ErrorMsg
}

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

func (a auditRollbackLogs) replaceDB(db *gorm.DB) auditRollbackLogs {
	a.auditRollbackLogsDo.ReplaceDB(db)
	return a
}

type auditRollbackLogsDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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