// 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 query

import (
	"context"

	"gorm.io/gorm"
	"gorm.io/gorm/clause"
	"gorm.io/gorm/schema"

	"gorm.io/gen"
	"gorm.io/gen/field"

	"gorm.io/plugin/dbresolver"

	"gadmin/internal/gorm/model"
)

func newServerDeployStat(db *gorm.DB, opts ...gen.DOOption) serverDeployStat {
	_serverDeployStat := serverDeployStat{}

	_serverDeployStat.serverDeployStatDo.UseDB(db, opts...)
	_serverDeployStat.serverDeployStatDo.UseModel(&model.ServerDeployStat{})

	tableName := _serverDeployStat.serverDeployStatDo.TableName()
	_serverDeployStat.ALL = field.NewAsterisk(tableName)
	_serverDeployStat.ID = field.NewInt64(tableName, "id")
	_serverDeployStat.AdminID = field.NewInt64(tableName, "admin_id")
	_serverDeployStat.BatchID = field.NewString(tableName, "batch_id")
	_serverDeployStat.Total = field.NewInt64(tableName, "total")
	_serverDeployStat.Success = field.NewInt64(tableName, "success")
	_serverDeployStat.Fail = field.NewInt64(tableName, "fail")
	_serverDeployStat.Timeout = field.NewInt64(tableName, "timeout")
	_serverDeployStat.IsNotify = field.NewInt64(tableName, "is_notify")
	_serverDeployStat.NotifyAt = field.NewTime(tableName, "notify_at")
	_serverDeployStat.CreatedAt = field.NewTime(tableName, "created_at")

	_serverDeployStat.fillFieldMap()

	return _serverDeployStat
}

type serverDeployStat struct {
	serverDeployStatDo

	ALL       field.Asterisk
	ID        field.Int64
	AdminID   field.Int64  // 操作管理员ID
	BatchID   field.String // 批量ID
	Total     field.Int64  // 总数
	Success   field.Int64  // 成功
	Fail      field.Int64  // 失败
	Timeout   field.Int64  // 超时
	IsNotify  field.Int64  // 是否通知
	NotifyAt  field.Time   // 通知时间
	CreatedAt field.Time   // 创建时间

	fieldMap map[string]field.Expr
}

func (s serverDeployStat) Table(newTableName string) *serverDeployStat {
	s.serverDeployStatDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

func (s serverDeployStat) As(alias string) *serverDeployStat {
	s.serverDeployStatDo.DO = *(s.serverDeployStatDo.As(alias).(*gen.DO))
	return s.updateTableName(alias)
}

func (s *serverDeployStat) updateTableName(table string) *serverDeployStat {
	s.ALL = field.NewAsterisk(table)
	s.ID = field.NewInt64(table, "id")
	s.AdminID = field.NewInt64(table, "admin_id")
	s.BatchID = field.NewString(table, "batch_id")
	s.Total = field.NewInt64(table, "total")
	s.Success = field.NewInt64(table, "success")
	s.Fail = field.NewInt64(table, "fail")
	s.Timeout = field.NewInt64(table, "timeout")
	s.IsNotify = field.NewInt64(table, "is_notify")
	s.NotifyAt = field.NewTime(table, "notify_at")
	s.CreatedAt = field.NewTime(table, "created_at")

	s.fillFieldMap()

	return s
}

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

func (s *serverDeployStat) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 10)
	s.fieldMap["id"] = s.ID
	s.fieldMap["admin_id"] = s.AdminID
	s.fieldMap["batch_id"] = s.BatchID
	s.fieldMap["total"] = s.Total
	s.fieldMap["success"] = s.Success
	s.fieldMap["fail"] = s.Fail
	s.fieldMap["timeout"] = s.Timeout
	s.fieldMap["is_notify"] = s.IsNotify
	s.fieldMap["notify_at"] = s.NotifyAt
	s.fieldMap["created_at"] = s.CreatedAt
}

func (s serverDeployStat) clone(db *gorm.DB) serverDeployStat {
	s.serverDeployStatDo.ReplaceConnPool(db.Statement.ConnPool)
	return s
}

func (s serverDeployStat) replaceDB(db *gorm.DB) serverDeployStat {
	s.serverDeployStatDo.ReplaceDB(db)
	return s
}

type serverDeployStatDo struct{ gen.DO }

func (s serverDeployStatDo) Debug() *serverDeployStatDo {
	return s.withDO(s.DO.Debug())
}

func (s serverDeployStatDo) WithContext(ctx context.Context) *serverDeployStatDo {
	return s.withDO(s.DO.WithContext(ctx))
}

func (s serverDeployStatDo) ReadDB() *serverDeployStatDo {
	return s.Clauses(dbresolver.Read)
}

func (s serverDeployStatDo) WriteDB() *serverDeployStatDo {
	return s.Clauses(dbresolver.Write)
}

func (s serverDeployStatDo) Session(config *gorm.Session) *serverDeployStatDo {
	return s.withDO(s.DO.Session(config))
}

func (s serverDeployStatDo) Clauses(conds ...clause.Expression) *serverDeployStatDo {
	return s.withDO(s.DO.Clauses(conds...))
}

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

func (s serverDeployStatDo) Not(conds ...gen.Condition) *serverDeployStatDo {
	return s.withDO(s.DO.Not(conds...))
}

func (s serverDeployStatDo) Or(conds ...gen.Condition) *serverDeployStatDo {
	return s.withDO(s.DO.Or(conds...))
}

func (s serverDeployStatDo) Select(conds ...field.Expr) *serverDeployStatDo {
	return s.withDO(s.DO.Select(conds...))
}

func (s serverDeployStatDo) Where(conds ...gen.Condition) *serverDeployStatDo {
	return s.withDO(s.DO.Where(conds...))
}

func (s serverDeployStatDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *serverDeployStatDo {
	return s.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}

func (s serverDeployStatDo) Order(conds ...field.Expr) *serverDeployStatDo {
	return s.withDO(s.DO.Order(conds...))
}

func (s serverDeployStatDo) Distinct(cols ...field.Expr) *serverDeployStatDo {
	return s.withDO(s.DO.Distinct(cols...))
}

func (s serverDeployStatDo) Omit(cols ...field.Expr) *serverDeployStatDo {
	return s.withDO(s.DO.Omit(cols...))
}

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

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

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

func (s serverDeployStatDo) Group(cols ...field.Expr) *serverDeployStatDo {
	return s.withDO(s.DO.Group(cols...))
}

func (s serverDeployStatDo) Having(conds ...gen.Condition) *serverDeployStatDo {
	return s.withDO(s.DO.Having(conds...))
}

func (s serverDeployStatDo) Limit(limit int) *serverDeployStatDo {
	return s.withDO(s.DO.Limit(limit))
}

func (s serverDeployStatDo) Offset(offset int) *serverDeployStatDo {
	return s.withDO(s.DO.Offset(offset))
}

func (s serverDeployStatDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *serverDeployStatDo {
	return s.withDO(s.DO.Scopes(funcs...))
}

func (s serverDeployStatDo) Unscoped() *serverDeployStatDo {
	return s.withDO(s.DO.Unscoped())
}

func (s serverDeployStatDo) Create(values ...*model.ServerDeployStat) error {
	if len(values) == 0 {
		return nil
	}
	return s.DO.Create(values)
}

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

func (s serverDeployStatDo) First() (*model.ServerDeployStat, error) {
	if result, err := s.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.ServerDeployStat), nil
	}
}

func (s serverDeployStatDo) Take() (*model.ServerDeployStat, error) {
	if result, err := s.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.ServerDeployStat), nil
	}
}

func (s serverDeployStatDo) Last() (*model.ServerDeployStat, error) {
	if result, err := s.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.ServerDeployStat), nil
	}
}

func (s serverDeployStatDo) Find() ([]*model.ServerDeployStat, error) {
	result, err := s.DO.Find()
	return result.([]*model.ServerDeployStat), err
}

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

func (s serverDeployStatDo) Attrs(attrs ...field.AssignExpr) *serverDeployStatDo {
	return s.withDO(s.DO.Attrs(attrs...))
}

func (s serverDeployStatDo) Assign(attrs ...field.AssignExpr) *serverDeployStatDo {
	return s.withDO(s.DO.Assign(attrs...))
}

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

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

func (s serverDeployStatDo) FirstOrInit() (*model.ServerDeployStat, error) {
	if result, err := s.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.ServerDeployStat), nil
	}
}

func (s serverDeployStatDo) FirstOrCreate() (*model.ServerDeployStat, error) {
	if result, err := s.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.ServerDeployStat), nil
	}
}

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

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

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

func (s serverDeployStatDo) Scan(result interface{}) (err error) {
	return s.DO.Scan(result)
}

func (s serverDeployStatDo) Delete(models ...*model.ServerDeployStat) (result gen.ResultInfo, err error) {
	return s.DO.Delete(models)
}

func (s *serverDeployStatDo) withDO(do gen.Dao) *serverDeployStatDo {
	s.DO = *do.(*gen.DO)
	return s
}
