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

	_serverDeployLog.serverDeployLogDo.UseDB(db, opts...)
	_serverDeployLog.serverDeployLogDo.UseModel(&model.ServerDeployLog{})

	tableName := _serverDeployLog.serverDeployLogDo.TableName()
	_serverDeployLog.ALL = field.NewAsterisk(tableName)
	_serverDeployLog.ID = field.NewInt64(tableName, "id")
	_serverDeployLog.AdminID = field.NewInt64(tableName, "admin_id")
	_serverDeployLog.DeployID = field.NewInt64(tableName, "deploy_id")
	_serverDeployLog.TraceID = field.NewString(tableName, "trace_id")
	_serverDeployLog.BatchID = field.NewString(tableName, "batch_id")
	_serverDeployLog.ContainerName = field.NewString(tableName, "container_name")
	_serverDeployLog.Name = field.NewString(tableName, "name")
	_serverDeployLog.PublishType = field.NewInt32(tableName, "publish_type")
	_serverDeployLog.Version = field.NewString(tableName, "version")
	_serverDeployLog.Extra = field.NewString(tableName, "extra")
	_serverDeployLog.LogFile = field.NewString(tableName, "log_file")
	_serverDeployLog.ErrorMsg = field.NewString(tableName, "error_msg")
	_serverDeployLog.Status = field.NewInt32(tableName, "status")
	_serverDeployLog.EndAt = field.NewTime(tableName, "end_at")
	_serverDeployLog.CreatedAt = field.NewTime(tableName, "created_at")

	_serverDeployLog.fillFieldMap()

	return _serverDeployLog
}

type serverDeployLog struct {
	serverDeployLogDo

	ALL           field.Asterisk
	ID            field.Int64
	AdminID       field.Int64  // 操作管理员ID
	DeployID      field.Int64  // 部署ID
	TraceID       field.String // 链路ID
	BatchID       field.String // 批量ID
	ContainerName field.String // 容器名称
	Name          field.String // 应用名称
	PublishType   field.Int32  // 发布类型
	Version       field.String // 版本号
	Extra         field.String // 额外参数
	LogFile       field.String // 日志路径
	ErrorMsg      field.String // 错误提示
	Status        field.Int32  // 部署状态
	EndAt         field.Time   // 部署结束时间
	CreatedAt     field.Time   // 创建时间

	fieldMap map[string]field.Expr
}

func (s serverDeployLog) Table(newTableName string) *serverDeployLog {
	s.serverDeployLogDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

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

func (s *serverDeployLog) updateTableName(table string) *serverDeployLog {
	s.ALL = field.NewAsterisk(table)
	s.ID = field.NewInt64(table, "id")
	s.AdminID = field.NewInt64(table, "admin_id")
	s.DeployID = field.NewInt64(table, "deploy_id")
	s.TraceID = field.NewString(table, "trace_id")
	s.BatchID = field.NewString(table, "batch_id")
	s.ContainerName = field.NewString(table, "container_name")
	s.Name = field.NewString(table, "name")
	s.PublishType = field.NewInt32(table, "publish_type")
	s.Version = field.NewString(table, "version")
	s.Extra = field.NewString(table, "extra")
	s.LogFile = field.NewString(table, "log_file")
	s.ErrorMsg = field.NewString(table, "error_msg")
	s.Status = field.NewInt32(table, "status")
	s.EndAt = field.NewTime(table, "end_at")
	s.CreatedAt = field.NewTime(table, "created_at")

	s.fillFieldMap()

	return s
}

func (s *serverDeployLog) 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 *serverDeployLog) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 15)
	s.fieldMap["id"] = s.ID
	s.fieldMap["admin_id"] = s.AdminID
	s.fieldMap["deploy_id"] = s.DeployID
	s.fieldMap["trace_id"] = s.TraceID
	s.fieldMap["batch_id"] = s.BatchID
	s.fieldMap["container_name"] = s.ContainerName
	s.fieldMap["name"] = s.Name
	s.fieldMap["publish_type"] = s.PublishType
	s.fieldMap["version"] = s.Version
	s.fieldMap["extra"] = s.Extra
	s.fieldMap["log_file"] = s.LogFile
	s.fieldMap["error_msg"] = s.ErrorMsg
	s.fieldMap["status"] = s.Status
	s.fieldMap["end_at"] = s.EndAt
	s.fieldMap["created_at"] = s.CreatedAt
}

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

func (s serverDeployLog) replaceDB(db *gorm.DB) serverDeployLog {
	s.serverDeployLogDo.ReplaceDB(db)
	return s
}

type serverDeployLogDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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